intention actions with placeholder

Hi everybody!

I have a doubt.

I have in my custom language an element wich has parameters like this Person(name="Loren", surname="Ipsum").
When I'm writing it, I wish that the IDE assist me putting all the parameter names available and the placeholders for the values. Like this: Person(name=[], surname=[]), where the squares are the placeholder.
I guess that these could be with an intention action, but I don't know how to create it with place holder.

Maybe It could be with live templates, but guess they are size fixed, so I cannot put variable size of placeholders.

Any idea??


Comment actions Permalink

I probably don't really understand what you mean by

but guess they are size fixed

but the rest smells like LiveTemplates would be a good idea. Remember that you even can give initial values to place holders. In my language, I have for instance a live template "nst" which is defined like this

    <template name="nst" description="Nest[func, expr, n]" toReformat="true"
              value="Nest[$FUNC$, $EXPR$, $COUNT$]$END$">
        <variable name="FUNC" expression="" defaultValue="&quot;func&quot;" alwaysStopAt="true" />
        <variable name="EXPR" expression="" defaultValue="&quot;expr&quot;" alwaysStopAt="true" />
        <variable name="COUNT" expression="" defaultValue="&quot;n&quot;" alwaysStopAt="true" />
            <option name="Mathematica" value="true"/>

Once it is expanded it looks like

where all 3 positions func, expr, and n are placeholders and can be visited by pressing tab.


Comment actions Permalink

I've never used live templates, but my problem is that I want just a template to init any object. That is:

Person A(name = "Loren", surname = "Impsum")

Person B(name = "Loren", surname = "Impsum", birthday="1950-10-10")

Dog Z(breed = "dalmata", name = "Pongo")

So, I can parametrize much type of objects, and each object has diferent parameters.

I cannot create a xml template for each one because I dont know these functions in advance. Something cool could be create the template "on-live", on the moment of the call.

I hope have explained better.


Comment actions Permalink

I'm also looking for a way to add those "red rectangle" placeholders, and came across two solutions:

Build a live template dynamically, then invoke it, as described here:

Template template = new TemplateImpl("", "this is my template text with var = $__Variable0$ and other var = $__Variable1$", "");
template.addVariable(anExpression0); template.addVariable(anExpression1);
TemplateManager.getInstance(editor).startTemplate(editor, template);

Or add placeholders by yourself in the editor:

TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.LIVE_TEMPLATE_ATTRIBUTES); RangeHighlighter segmentHighlighter = myEditor.getMarkupModel()       .addRangeHighlighter(start, end, HighlighterLayer.LAST + 1, attributes, HighlighterTargetArea.EXACT_RANGE);

Which is what live templates do under the hood.


Please sign in to leave a comment.