Help with a simple live template?

I'm trying to make a live template for creating a variable. I don't like
Introduce Variable refactoring much because the dialog gets in my way. I
created the template:

$TYPE$ $NAME$ = $VAL$;

The variables are:
Name | Expression | Default value
$VAL$ | |
$TYPE$ | rightSideType() | java.lang.Object
$NAME$ | suggestVariableName() | var

This looks fine to me. I expect it to start out with:
Object var = |;
then I type the expression and hit Enter, and it becomes:
String |var| = ""; // the || represents selection
then I type a variable name, and I hit enter, and it's done:
String str = "";

However, instead, it doesn't suggest anything, and no defaults are used.
So it starts out:
= |;
and I type an expression:
| = "";
and so on, without any completion or inference.

Does someone know what I'm doing wrong, or how to fix this live template
to do what I want it to do?

2 comments
Comment actions Permalink

No, it works fine. It starts with the type. So fo example type 'S'
and den Ctrl-Space. Select "String" from the popup and press tab. Now
you can select the variable name. Press tab again and fill in the value.

Keith Lea schrieb:

I'm trying to make a live template for creating a variable. I don't like
Introduce Variable refactoring much because the dialog gets in my way. I
created the template:

$TYPE$ $NAME$ = $VAL$;

The variables are:
Name | Expression | Default value
$VAL$ | |
$TYPE$ | rightSideType() | java.lang.Object
$NAME$ | suggestVariableName() | var

This looks fine to me. I expect it to start out with:
Object var = |;
then I type the expression and hit Enter, and it becomes:
String |var| = ""; // the || represents selection
then I type a variable name, and I hit enter, and it's done:
String str = "";

However, instead, it doesn't suggest anything, and no defaults are used.
So it starts out:
= |;
and I type an expression:
| = "";
and so on, without any completion or inference.

Does someone know what I'm doing wrong, or how to fix this live template
to do what I want it to do?

0
Comment actions Permalink

I don't want to type the type. I want it to be inferred from the type of
the RHS.

Sven Steiniger wrote:

No, it works fine. It starts with the type. So fo example type 'S'
and den Ctrl-Space. Select "String" from the popup and press tab. Now
you can select the variable name. Press tab again and fill in the value.

Keith Lea schrieb:

>> I'm trying to make a live template for creating a variable. I don't
>> like Introduce Variable refactoring much because the dialog gets in my
>> way. I created the template:
>>
>> $TYPE$ $NAME$ = $VAL$;
>>
>> The variables are:
>> Name | Expression | Default value
>> $VAL$ | |
>> $TYPE$ | rightSideType() | java.lang.Object
>> $NAME$ | suggestVariableName() | var
>>
>> This looks fine to me. I expect it to start out with:
>> Object var = |;
>> then I type the expression and hit Enter, and it becomes:
>> String |var| = ""; // the || represents selection
>> then I type a variable name, and I hit enter, and it's done:
>> String str = "";
>>
>> However, instead, it doesn't suggest anything, and no defaults are
>> used. So it starts out:
>> = |;
>> and I type an expression:
>> | = "";
>> and so on, without any completion or inference.
>>
>> Does someone know what I'm doing wrong, or how to fix this live
>> template to do what I want it to do?

0

Please sign in to leave a comment.