@@ -92,19 +92,17 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct
92
92
requestType .ifPresent (requestMethod -> maybeRemoveImport ("org.springframework.web.bind.annotation.RequestMethod." + requestMethod ));
93
93
94
94
// Remove the argument
95
- if (requestMethodArg . isPresent () && methodArgumentHasSingleType (requestMethodArg .get ()) && resolvedRequestMappingAnnotationClassName != null ) {
95
+ if (methodArgumentHasSingleType (requestMethodArg .get ())) {
96
96
if (a .getArguments () != null ) {
97
97
a = a .withArguments (ListUtils .map (a .getArguments (), arg -> requestMethodArg .get ().equals (arg ) ? null : arg ));
98
98
}
99
99
}
100
100
101
101
// Change the Annotation Type
102
- if (resolvedRequestMappingAnnotationClassName != null ) {
103
- maybeAddImport ("org.springframework.web.bind.annotation." + resolvedRequestMappingAnnotationClassName );
104
- a = (J .Annotation ) new ChangeType ("org.springframework.web.bind.annotation.RequestMapping" ,
105
- "org.springframework.web.bind.annotation." + resolvedRequestMappingAnnotationClassName , false )
106
- .getVisitor ().visit (a , ctx , getCursor ());
107
- }
102
+ maybeAddImport ("org.springframework.web.bind.annotation." + resolvedRequestMappingAnnotationClassName );
103
+ a = (J .Annotation ) new ChangeType ("org.springframework.web.bind.annotation.RequestMapping" ,
104
+ "org.springframework.web.bind.annotation." + resolvedRequestMappingAnnotationClassName , false )
105
+ .getVisitor ().visit (a , ctx , getCursor ());
108
106
109
107
// if there is only one remaining argument now, and it is "path" or "value", then we can drop the key name
110
108
if (a != null && a .getArguments () != null && a .getArguments ().size () == 1 ) {
@@ -142,15 +140,23 @@ private boolean methodArgumentHasSingleType(J.Assignment assignment) {
142
140
return newArray .getInitializer () != null && newArray .getInitializer ().size () == 1 ;
143
141
}
144
142
143
+ @ Nullable
145
144
private String requestMethodType (@ Nullable J .Assignment assignment ) {
145
+ if (assignment == null ) {
146
+ return null ;
147
+ }
146
148
if (assignment .getAssignment () instanceof J .Identifier ) {
147
149
return ((J .Identifier ) assignment .getAssignment ()).getSimpleName ();
148
150
} else if (assignment .getAssignment () instanceof J .FieldAccess ) {
149
151
return ((J .FieldAccess ) assignment .getAssignment ()).getSimpleName ();
150
152
} else if (methodArgumentHasSingleType (assignment )) {
151
- J .NewArray newArray = (J .NewArray ) assignment .getAssignment ();
152
- assert newArray .getInitializer () != null ;
153
- return ((J .FieldAccess ) newArray .getInitializer ().get (0 )).getSimpleName ();
153
+ if (assignment .getAssignment () instanceof J .NewArray ) {
154
+ J .NewArray newArray = (J .NewArray ) assignment .getAssignment ();
155
+ assert newArray .getInitializer () != null ;
156
+ return ((J .FieldAccess ) newArray .getInitializer ().get (0 )).getSimpleName ();
157
+ } else if (assignment .getAssignment () instanceof J .Identifier ) {
158
+ return ((J .Identifier ) assignment .getAssignment ()).getSimpleName ();
159
+ }
154
160
}
155
161
return null ;
156
162
}
0 commit comments