Live template help needed

I have a class that I use everywhere called MyConstants. It is pretty
much just a container for a bunch of public static final longs and to
save typing, I created a live template. I want to be able to type
"mc, then dammit! insert
MyConstants.?

I think it usually fails because the MyConstants class hasn't been
imported yet, or something like that.

I'm about to define a macro and bind it to a keystroke instead, but that
seems like overkill. Any advice?

Cory

4 comments

What does your live template look like? Did you use a fully qualified name?

Bas

Cory R wrote:

I have a class that I use everywhere called MyConstants. It is pretty
much just a container for a bunch of public static final longs and to
save typing, I created a live template. I want to be able to type
"mc<tab>" and have it insert "MyConstants.".

It doesn't usually work. Is there some way to tell IDEA that no matter
what the current parse state, If I type mc<tab>, then dammit! insert
MyConstants.?

I think it usually fails because the MyConstants class hasn't been
imported yet, or something like that.

I'm about to define a macro and bind it to a keystroke instead, but that
seems like overkill. Any advice?

Cory

0

Should it really matter? I just want some chunk of text to be generated
when I type mc. Am I expecting the live template facility to do
something that it isn't designed to do? If the block of text it spits
out doesn't make sense to the parser, it should feel free to underline
it with a red squiggle. Why should it ever block the template expansion?

Cory

Bas Leijdekkers wrote:

What does your live template look like? Did you use a fully qualified name?

Bas

Cory R wrote:

>> I have a class that I use everywhere called MyConstants. It is pretty
>> much just a container for a bunch of public static final longs and to
>> save typing, I created a live template. I want to be able to type
>> "mc Cory

0

>>>
>>> It doesn't usually work. Is there some way to tell IDEA that no
>>> matter what the current parse state, If I type mc

I have several live templates like that (Dates, Strings, Numbers, Arrays,
...) and they have always worked.

The two differences I see are that (as Bas suggested) I use the full qualified
class names in the live template and use space instead of tab as the activation
key.



0

Carlos Costa e Silva wrote:
>>>>
>>>> It doesn't usually work. Is there some way to tell IDEA that no
>>>> matter what the current parse state, If I type mc


I have several live templates like that (Dates, Strings, Numbers,
Arrays, ...) and they have always worked.
The two differences I see are that (as Bas suggested) I use the full
qualified class names in the live template and use space instead of tab
as the activation key.


Changing the activation key to space seems to work better. Thanks for
the tip. If that fails, I'll put add the package name to MyConstants.

Thanks,
Cory

0

Please sign in to leave a comment.