Postfix Completion

Compatible with: IntelliJ IDEA MPS Android Studio
Dec 17, 2013
3 180
The basic idea is to prevent caret jumps backward while typing code, let you start with the some expression, explore some APIs, think about what you are going to do and after finish with statement of some type.

Available templates:

  • .if – checks boolean expression to be true – if (expr)
  • .else – checks boolean expression to be false – if (!expr)
  • .var – initialize new variable with expression – T x = expr;
  • .null – checks nullable expression to be null – if (expr == null)
  • .notnull – checks expression to be non-null – if (expr != null)
  • .not – negates value of inner boolean expression – !expr
  • .for – iterates over collection – for (T item : collection)
  • .while – uses expression as loop condition – while (expr)
  • .arg – helps surround argument with invocation – method(expr)
  • .cast – surrounds expression with cast – (SomeType) expr
  • .new – produces instantiation expression for type – new T()
  • .fori – surrounds with loop – for (int i = 0; i < expr.length; i++)
  • .forr – reverse loop – for (int i = expr.length - 1; i >= 0; i--)
  • .field – introduces field for expression – _field = expr;
  • .par – surrounds outer expression with parentheses – (expr)
  • .return – returns value from containing method – return expr;
  • .switch – switch over integral/enum/string values – switch (expr)
  • .throw – throws exception of 'Throwable' type – throw new Exception();
  • .assert – creates assertion from boolean expression – assert expr;
  • .synchronized – produces synchronized block – synchronized (expr)
  • .instanceof – surrounds expression with instanceof – expr instanceof SomeType ? ((SomeType) expr). : null

Other features:

  • Template expansion by [Tab] key in editor (like live templates)
  • Support for IDEA chained code completion ( => new SomeType())
  • Works inside code fragments, like evaluate expression debugger window
  • Settings page to disable/enable particular postfix templates

Recent change notes

Version 0.8-beta
API redesigned. Templates work like native live-templates now, that is more consistently.
New instanceof template.
Added abilities to configure expanding key and to disable particular templates directly from completion list (Alt+Enter).

Version 0.7.6-beta
Braces insertion in .if, .else, .null and .notnull.

Version 0.7.5-beta
Settings page to disable/enable particular templates. Better .cast template.

Version 0.7-beta
New templates: .switch, .throw, .assert and .synchronized.

Version 0.6-beta
Fixes, new templates: .field, .par and .return.

Version 0.5-beta
Various fixes for completion with over literals.
New .fori and .forr templates iteration with index.