Skip to main content

IntelliJ Postfix Completions

IntelliJ's postfix completions were announced in 2014 but remain relatively unknown. Postfix code completion helps reduce backward caret jumps as you write code. You use it as if you're auto-completing a method name, but with the name of a postfix template. While live templates can insert complete code blocks, postfix completions work on existing expressions to transform them.

Postfix completion example

Here are a few postfix completions I've added for Java. They are available for download here.

Rethrow checked exception as runtime exception

Rethrow completion

Before: $EXPR$.rethrow

After: throw new RuntimeException($EXPR$);

Applicable type: java.lang.Exception

Rethrow configuration

Adapt a collection with Eclipse Collections

Adapt completion

Before: $EXPR$.adapt

After: org.eclipse.collections.impl.list.mutable.ListAdapter.adapt($EXPR$)

Applicable type: java.util.List

Adapt configuration

In addition to ListAdapter, I have equivalent rules for SetAdapter, MapAdapter, and ArrayAdapter. Since each applies to a specific type, it's not a problem for all 4 to share the same key "adapt".

Comments

Leave a comment on Medium