We are using SonarQube Server for a big java application. (IDE = Eclipse + SonarLint plugin). Rule Private fields only used as local variables in methods should become local variables is violated in about 6000 cases. Is there an automatic method of refactoring this issue?
Example:
Actual situation:
public class A {
private JLabel lblText;
...
public void foo() {
lblText = new JLabel();
lblText.setText("Text");
mainPanel.addComponent(lblText, 2, 1);
...
}
...
}
After refactor:
public class A {
...
public void foo() {
JLabel lblText = new JLabel();
lblText.setText("Text");
mainPanel.addComponent(lblText, 2, 1);
...
}
...
}
Can I achieve this automatically? It would take a huge amount of time to do 6000 cases manually.