Postfix Code Completion in IntelliJ IDEA 13.1 EAP
A lot of people tend to think these days completion is a regular feature for every IDE. Well, that is not exactly the case. IntelliJ IDEA has already demonstrated that there is no such thing as a regular feature.
Take code completion, for example. IntelliJ IDEA never stops evolving in this area, and to prove it once more, today we are proud to introduce Postfix code completion, a new kind of completion which will hopefully extend your productivity even more.
Postfix code completion helps reduce backward caret jumps as you write code. It lets you transform an already typed expression to another one based on the postfix you added, the type of expression and its context. For example, the “.if” postfix applied to a boolean expression wraps it with an if statement. Likewise the “.notnull” triggers a surround template checking the expression for the null value.
Notice that the postfix completion suggestions are shown as part of the basic completion. In case you’d like to see the whole list of postfix completions applicable in the context, use the Ctrl + J shortcut (Cmd + J for OS X).
To see all the postfix templates and change their settings (for example, to disable the templates you don’t need), go to Settings → Editor → Postfix Templates.
Note that some of the templates have aliases (i.e. alternative postfix names). For instance, the exclamation mark will have the same effect as “.not”. Just enter “!” after an expression and press Tab to negate it. The IDE may ask you which expression you meant, if there is more than one.
Many thanks for the original idea and the initial implementation of this feature to our .NET colleagues.
As always, we welcome your feedback on our discussion forum and your bug reports in the issue tracker.
Develop with Pleasure!
Tomek says:
March 4, 2014Such a nice feature. Like it very much!
Hendrik says:
March 4, 2014This is the kind of feature I always wanted but was never able to express it – great! I would love to see this in AppCode!
Allen~m says:
February 3, 2017Just hacking through myself but I think a use is “field [answer] entries”: of PyCharm.edu
Allen~m says:
February 3, 2017Pardon . . I meant: PyCharm EDU as’ app/ interface
Dave Hulbert says:
March 4, 2014Will this be coming to PhpStorm?
Alexander Zolotov says:
March 4, 2014It is language-specific feature and at the moment it is implemented for Java only. You can request it for PHP in the issue tracker.
Eugene OZ says:
March 4, 2014http://youtrack.jetbrains.com/issue/WI-22350
Vilis says:
March 4, 2014It seems more like a feature for a programming language than IDE.
Petr says:
March 4, 2014It looks really great.
A quick note for those stuck with Eclipse: Use ‘Surround With’ (Alt+Shift+Z). You have to define your own templates if you want to be as productive as the examples here (there are only a few predefined), but the result is very similar.
Konrad Machlowski says:
March 4, 2014It seems to me that it works only with Java.
Is there a plan to enable this for AS3/Flex development env?
Darren Bishop says:
March 19, 2014+1, another feature that seems to be attached to a language unnecessarily
Oliver says:
March 20, 2014+1
moks says:
March 21, 2014+1
charles says:
November 11, 2017well, it sucks that I can’t use it from Groovy , Java’s close cousin
Tim says:
March 4, 2014Thanks for reminding me why I’ll never use Java again.
Only in a language as verbose, inflexible, and inconsistent as Java could such a feature exist.
controlflow says:
March 4, 2014Actually, this feature was designed first for the languages with ‘statements’ (a lot of imperative languages has separation of expression and statements).
Statements are important part of the language, but because of the syntax, they are force you to think of exact kind of the statement you need (if/while/for/just expression) before writing next line of code. This plugin is designed to let you start with the expression, explore the apis with code completion, think about what you wanna do next and at the end of expression you can simply surround expression into statement kind you need, without backward caret jumps.
Jura Gorohovsky says:
March 4, 2014Tim, the feature was borrowed directly form ReSharper.Postfix, a plug-in to ReSharper (which is turn a plug-in to Visual Studio), and was originally written to support C#.
Not sure if you have ever used C# but does your comment mean that you’ll never use it from now on?
Daniel says:
March 6, 2014“as Java could such a feature exist”
It has lived without such a feature for 24 years so far. Objective C is totally worse than Java. I hope to see this feature in AppCode very soon.
Rob says:
March 7, 2014Central casting had to dispatch the usual Java’s too much trouble troll. Thanks for your contribution here.
For my own part, I want to say this is FANTASTIC! Thanks!
foobra says:
March 4, 2014what’s difference between this and postfix code completion plugin?
Alexander Zolotov says:
March 4, 2014Postfix code completion plugin had been merged into idea-community repo and won’t be supported separately.
controlflow says:
March 4, 2014Actually, it is postfix plugin itself. It became part of the product.
Plugin is no longer in development.
Anthony Accioly says:
March 6, 2014Not related to postfix code completion. But how have you managed to have IntelliJ auto-complete (or copy) the word
registered
after:new RuntimeException("Already r");
?Alexander Zolotov says:
March 6, 2014It is ‘cyclic expand word’ action.
Darren Bishop says:
March 19, 2014Amazeballs
Dmytro Danylyk says:
March 19, 2014Any way I can add my own Postfix Templates?
Andrey Cheptsov says:
March 19, 2014Which one you’d like to add?
Denis Tulskiy says:
March 20, 2014string format would be nice
“%d – %d”.format would turn into
String.format(“%d – %d”, )
Stefan says:
March 21, 2014System.out.println() would be useful
Callum Macrae says:
March 25, 2014That already exists (if live templates are enabled). Type “sout” and press tab.
Sean Patrick Floyd says:
March 27, 2014Oh, many different ones. especially with Guava
.optional -> wraps an expression in an Optional
.or -> wraps with Objects.firstNonNull()
.cnn -> wraps with Preconditions.checkNotNull()
etc.
Per Salomonsen says:
April 2, 2014.tc -> try { expr } catch (…) {}
.tf -> try { expr } finally {}
.tcf -> try { expr } catch (…) {} finally {}
..comes to mind.
ben says:
June 16, 2014It would be nice to have a template for Android debug logs:
Log.d(TAG, “%STRING%”);
Pavel Alexeev says:
March 19, 2014It does not work to me on Linux. Is it require any settings? All templates enabled as I see.
Daniel Gornstein says:
March 19, 2014Love it! Would love to see this for JS as well!!
Swen Thümmler says:
March 20, 2014Will it be possible to modify the templates? I’d rathe have (null != object) over (object != null) in my code…
norill says:
August 9, 2018this idiom is largely obsolete. it’s purpose is to protect from accidental if(a = null), but there is no way compliator would let it through in java
Benjamin Weiss says:
March 20, 2014Having the possibility to add my own postfix completion items just like Live Templates would be great.
Sethuraman says:
March 20, 2014Adding your own Postfix templates would be of real help
Every user would have his own templates to add. The one suggested already is .format.
Another could be .int which would give Integer.parseInt(“”)
Like that you could add as many as you want. It could be another group in live templates. Instead of creating surround with templates, postfix is easier and more intuitive.
Mark says:
March 20, 2014Would be nice to add “new”:
SomeClass.new
to resolve to
new SomeClass(
Android Studio 0.5.0リリース | フリーソフト/無料ソフト startnews24 says:
April 8, 2014[…] Postfix code completion: https://blog.jetbrains.com/idea/2014/03/postfix-completion/ […]
Thierry Lévèque says:
April 28, 2014Yes, being able to modify or add template would be great!
I would love to add thing like StringUtils.isBlank() or things like that…
Benjamin W. says:
May 7, 2014Is it possible to define custom postfix-completion templates?
Cheers!
Andrey Cheptsov says:
May 21, 2014not yet, but we thinking of it. what kind of templates you would add once it’s possible?
Diane says:
May 29, 2014For me, it would be great to be able to change for example sout to sysout + Ctrl-space to match eclipse autocompletion shortcuts.
Aleksander.w1992 says:
August 17, 2014I’d like to spot that defining own live templates (those with “$SELECTION$) can partially replace defining own postfix templates. You just define your own template and press ctrl+alt+j instead of ctrl+j (crtl+alt+t is very similar).
Maybe keeping keeping ctrl+j for default postfix templates and crtl+alt+j for user’s be a good idea as action is very similar?
Personally I use on a regular basis StringUtils template:
if(org.apache.commons.lang.StringUtils.$METHOD_NAME$($SELECTION$)){
$END$
}
And StringUtils.isBlank as a little more hardcoded:
if(org.apache.commons.lang.StringUtils.isBlank($SELECTION$)){
$END$
}
Sergey Ignatov says:
May 21, 2014Please watch/vote: http://youtrack.jetbrains.com/issue/IDEA-122443
Bruce says:
May 17, 2014what’s the difference with live templates?
Andrey Cheptsov says:
May 21, 2014regular live templates neither affect or depend on the code before the caret
IntelliJ postfix completion | Yair's Tweaks & Tricks says:
August 27, 2014[…] https://blog.jetbrains.com/idea/2014/03/postfix-completion/ […]
My Favourite IntelliJ IDEA Features | Voxxed says:
December 12, 2014[…] this awesome post in IntelliJ Blog for additional information about Postfix […]
Damian says:
March 17, 2015My loved feature ! but what about postfix completion for scala ?
Maksim Sobolevskiy says:
October 8, 2015Here you are, Damian! https://blog.jetbrains.com/scala/2015/10/02/intellij-idea-15-eap-adds-postfix-code-completion-for-scala/
Damian says:
August 8, 2017Thank you so much, please let me know, if there is a possibility to add this feature to groovy ?
Kinz says:
August 20, 2015Very nice feature! I usually use the .for, .fori postfix and never wrote any for-loop now.
But, we really really need a way to config custom postfix completion like live template.
Use Android Studio Like a Pro! - Intellectsoft Blog says:
October 12, 2018[…] Documentation on Postfix operations […]