Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thomaseizinger/6f8419cc13974cbebc67 to your computer and use it in GitHub Desktop.
Save thomaseizinger/6f8419cc13974cbebc67 to your computer and use it in GitHub Desktop.
A live template for IntelliJ IDEA to insert and encapsulate a list in Java. Paste the snippet into live template group under ~/.IntelliJIdeaXX/config/templates/
<template name="inslist" value="private java.util.List&lt;$T$&gt; $ts$ = new $listType$&lt;$T$&gt;();&#10;&#10;public java.util.List&lt;$T$&gt; get$Ts$() {&#10; return java.util.Collections.unmodifiableList($ts$);&#10;}&#10;&#10;private void set$Ts$(List&lt;$T$&gt; $ts$) {&#10; this.$ts$ = $ts$;&#10;}&#10;&#10;public void add$T$($T$ $t$) {&#10; this.$ts$.add($t$);&#10;}&#10;&#10;public void remove$T$($T$ $t$) {&#10; this.$ts$.remove($t$);&#10;}" description="Insert and encapsulate a list" toReformat="false" toShortenFQNames="true">
<variable name="T" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="listType" expression="subtypes()" defaultValue="" alwaysStopAt="true" />
<variable name="Ts" expression="capitalize(ts)" defaultValue="" alwaysStopAt="false" />
<variable name="t" expression="suggestVariableName()" defaultValue="" alwaysStopAt="false" />
<variable name="ts" expression="suggestVariableName()" defaultValue="" alwaysStopAt="false" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment