Skip to content

Instantly share code, notes, and snippets.

@thecarlhall
Created September 30, 2015 01:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecarlhall/eb7c489a767888262daf to your computer and use it in GitHub Desktop.
Save thecarlhall/eb7c489a767888262daf to your computer and use it in GitHub Desktop.
Intellij Live Template for create a fluent "with" method for a Java class variable.
<templateSet group="Java">
<template name="with" value="public $CLASS_NAME$ with$NAME$($VAR_TYPE$ $VAR_NAME$) {&#10; this.$VAR_NAME$ = $VAR_NAME$;&#10; return this;&#10;}&#10;$END$" description="Fluent getter" toReformat="false" toShortenFQNames="true">
<variable name="CLASS_NAME" expression="className()" defaultValue="" alwaysStopAt="false" />
<variable name="NAME" expression="" defaultValue="&quot;Name&quot;" alwaysStopAt="true" />
<variable name="VAR_NAME" expression="decapitalize(NAME)" defaultValue="$NAME" alwaysStopAt="false" />
<variable name="VAR_TYPE" expression="typeOfVariable(VAR_NAME)" defaultValue="$VAR_NAME" alwaysStopAt="false" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_STATEMENT" value="true" />
<option name="JAVA_EXPRESSION" value="true" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_COMMENT" value="true" />
<option name="JAVA_STRING" value="true" />
<option name="COMPLETION" value="true" />
</context>
</template>
</templateSet>
@thecarlhall
Copy link
Author

  • Make a directory for your work. cd into that directory.
  • Export your "Live Templates from Intellij Export settings... to settings.jar in the work directory and unzip it.
  • Edit Java.xml to include the above template block. Do not remove anything. Save.
  • Zip up the file again with zip -r settings.jar . and import into Intellij.

@3363686
Copy link

3363686 commented Nov 22, 2015

Do you know what does <option name="COMPLETION" mean?
It is set to False in all templates*.xml files, and there is no interface elements to change its value...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment