Create Live Template from a specific context
已回答
Hello,
I read a lot of documentation and blogs to create a new live template. But each time the template is not applicable on a specific type.
I want to create a live template as iter, new, var, ... that is usable from a var Collection (as iter template), or a instance (as new template).
Example:
MyClass.new -> new MyClass()
myCollection.iter -> for (Object item:myCollection){ ... }
new MyClass().var -> MyClass myClass = new MyClass ()
I tried to duplicate "iter" template and select "statement" context as defined is "iter" template. But I don't see my template on a new collection.
How to do this kind of live template ?
Best
Jérôme
请先登录再写评论。
Hello Jérôme,
Mentioned feature is a postfix completion, not live template. Could you please clarify what you are going to archive?
Thank you for you answer. So I tried to create my custom postfix to write this kind of code:
Before
After
I wrote this posfix:
But i wanted to have a similar behaviour of var postfix completion. It means that Intellij suggests me a variable name. I don't find documentation to do that. I try to use $VAR:suggestVariableName()$ as Live template function but it doesn't work.
Ideally I would like to import a library with this command, but that is not mandatory.
Thank you for your help.
Best
Demanghon Jérôme
Jérôme,
Currently it's not possible to add name suggestion to template. It's done on code level. Feel free to create request for this feature on YouTrack: https://youtrack.jetbrains.com/issues/IDEA