creating local variables
Closed this issue · 2 comments
brandon1024 commented
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.
brandon1024 commented
If it's not too difficult, we should try and restore the cursor position afterwards.
brandon1024 commented
done!