@@ -97,14 +97,19 @@ public JavaSourceFile visitJavaSourceFile(JavaSourceFile cu, ExecutionContext ct
97
97
public J .VariableDeclarations .NamedVariable visitVariable (J .VariableDeclarations .NamedVariable variable , ExecutionContext ctx ) {
98
98
Cursor parentScope = getCursorToParentScope (getCursor ());
99
99
100
- // Does support renaming private fields in a J.ClassDeclaration.
101
- if ((parentScope .getParent () != null && parentScope .getParent ().getValue () instanceof J .ClassDeclaration && variable .getVariableType ().hasFlags (Flag .Private ) &&
102
- //do not rename constants
103
- !(variable .getVariableType ().hasFlags (Flag .Static , Flag .Final )) &&
104
- // Does not apply for instance variables of inner classes
105
- !((J .ClassDeclaration ) parentScope .getParent ().getValue ()).getType ().getFullyQualifiedName ().contains ("$" ) &&
106
- // Name does not match camelCase pattern.
107
- !LOWER_CAMEL .matches (variable .getSimpleName ()))) {
100
+ // Does support renaming fields in a J.ClassDeclaration.
101
+ // We must have a variable type to make safe changes.
102
+ // Only make changes to private fields that are not constants.
103
+ // Does not apply for instance variables of inner classes
104
+ // Only make a change if the variable does not conform to lower camelcase format.
105
+ if (parentScope .getParent () != null
106
+ && parentScope .getParent ().getValue () instanceof J .ClassDeclaration
107
+ && variable .getVariableType () != null
108
+ && variable .getVariableType ().hasFlags (Flag .Private )
109
+ && !(variable .getVariableType ().hasFlags (Flag .Static , Flag .Final ))
110
+ && !((J .ClassDeclaration ) parentScope .getParent ().getValue ()).getType ().getFullyQualifiedName ().contains ("$" )
111
+ && !LOWER_CAMEL .matches (variable .getSimpleName ())) {
112
+
108
113
String toName = LOWER_CAMEL .format (variable .getSimpleName ());
109
114
((Map <J .VariableDeclarations .NamedVariable , String >) getCursor ().getNearestMessage ("RENAME_VARIABLES_KEY" )).put (variable , toName );
110
115
} else {
0 commit comments