Live template - How does suggestFirstVariableName macro work?
Hi,
I'm building some documentation about Intellij Live Template macros and I came across suggestFirstVariableName() but I haven't been able to figure out how it supposed to work.
In whatever form I define it the resulting suggestion is always an empty string, without any suggestion list.
I looked into the related macro implementation as well but I couldn't figure out what it does exactly.
Can you help me explain how and in what form this macro works? To be more specific I have these questions in mind too:
- what does first refer to? First in what scope, or among what variables, fields, etc.?
- does it have an input parameter? The official documentation suggests it has, but in the edit variables dialog, it suggests it doesn't have one. If it has a parameter what kind of value does it expect?
I'd appreciate some help.
Please sign in to leave a comment.
Hello,
suggestFirstVariableNamemacro is the same asvariableOfType,both suggest variables of the given type available in the context, but the latter one also suggests "standard expressions" if they have a compatible type: "true", "false", "this" and "Outer.this".The arguments can look like
"double"or"java.util.Collection"or other macros, e.g.methodReturnType()which returns the return type of the method where the caret is positioned.Hi Olga,
Alright, that's cool. That makes sense now.
Thanks much. :)
Edit:
I happened to figure out that if the specified type is just the name of the type and not the fully qualified name e.g. "Collection" instead of "java.util.Collection" then the macro will suggest variables with the type that is imported into the given class.