Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I name a variable automatically by its type in a live template?

Using dagger, Im injecting fields a lot - so I created a live template for declaring an injected variable:

@Inject
lateinit var $var$: $TYPE$

In Java, a similar live template would automatically fill in repository as I specified the type to be Repository.

In Kotlin, however - it does not. But Im sure its possible?

like image 548
zoltish Avatar asked Jan 31 '26 11:01

zoltish


2 Answers

Figured it out! Posting a screenshot as I think that explains it the best.

Live template variables

like image 198
zoltish Avatar answered Feb 03 '26 00:02

zoltish


I have a slight variation on this that uses smart completion. The key thing that evaded me at first was making sure you re-order the variables so the TYPE is before the VAR. Otherwise the type will be empty. Spring Live Template Variables

like image 40
Nate Good Avatar answered Feb 02 '26 23:02

Nate Good



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!