Java refactoring and Source Actions
Visual Studio Code provides many options to refactor your source code as well as Source Actions to generate code and fix issues while you're coding. To access them, click on the light bulb 💡 whenever you see it. Or right-click the editor view and pick Source Action....
List of Supported Code Actions
- Refactoring
- Assign to variable
- Convert anonymous to nested class
- Convert to anonymous class creation
- Convert to enhanced for loop
- Convert to lambda expression
- Convert to static import
- Extract refactorings
- Inline refactorings
- Invert boolean
- Move
- Rename
- Type change
- Source Actions
- Other Code Actions supported
Refactoring
The goal of the Java program refactoring is to make system-wide code changes without affecting behavior of the program. The Java Language Support for VS Code provides many easily accessible refactoring options.
Invoke refactoring
Refactoring commands are available from the context menu of the editor. Select the element you want to refactor, right-click to open the context menu, and choose Refactor...:

Then you will see all the available refactoring options.
Assign to variable
Assigns an expression to a local variable or a field.
Example
Before
Arrays.asList("apple", "lemon", "banana");
After
List<String> fruits = Arrays.asList("apple", "lemon", "banana");
It can also be used to assign a parameter to a new field for unused parameter(s) in a constructor.
Convert anonymous to nested class
Converts an anonymous inner class to a member class.
Example
Let's convert the anonymous class Interface(){...} to a member of the class Clazz.
Before
public class Clazz {
public Interface method() {
final boolean isValid = true;
return new Interface() {
public boolean isValid() {
return isValid;