Some IDEs are able to automatically insert local variables. Implementing a feature like this could be extremely difficult, given we don't know anything about the result of the method call. However, we can take a dumb approach that inserts a simple var (or final var) assignment at the beginning of the line.
For example, consider the following:
class Example {
void method() {
get(); // <- cursor is here
}
Object get() {
return new Object();
}
}
The plugin should expose a command that inserts var or final var at the beginning of the line, placing the cursor where the variable name would go.
class Example {
void method() {
final var <cursor> = get();
}
Object get() {
return new Object();
}
}
We should also expose configuration to enable or disable final declarations.
Some IDEs are able to automatically insert local variables. Implementing a feature like this could be extremely difficult, given we don't know anything about the result of the method call. However, we can take a dumb approach that inserts a simple
var
(orfinal var
) assignment at the beginning of the line.For example, consider the following:
The plugin should expose a command that inserts
var
orfinal var
at the beginning of the line, placing the cursor where the variable name would go.We should also expose configuration to enable or disable
final
declarations.