@@ -92,21 +92,21 @@ public J visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ct
92
92
}
93
93
94
94
@ Override
95
- public J visitImport (J .Import import_ , ExecutionContext ctx ) {
96
- String currentFqcn = currentFqcn (import_ );
95
+ public J visitImport (J .Import anImport , ExecutionContext ctx ) {
96
+ String currentFqcn = currentFqcn (anImport );
97
97
if (isV1Import (currentFqcn )) {
98
98
JavaType .ShallowClass originalType = JavaType .ShallowClass .build (currentFqcn );
99
99
String v2Equivalent = getV2Equivalent (currentFqcn );
100
100
101
101
JavaType targetType = JavaType .buildType (v2Equivalent );
102
102
103
103
oldTypeToNewType .put (currentFqcn , Pair .of (originalType , targetType ));
104
- if (import_ .getAlias () != null ) {
105
- importAlias = import_ .getAlias ();
104
+ if (anImport .getAlias () != null ) {
105
+ importAlias = anImport .getAlias ();
106
106
}
107
107
}
108
108
109
- return import_ ;
109
+ return anImport ;
110
110
}
111
111
112
112
@ Override
@@ -144,14 +144,14 @@ public J postVisit(J tree, ExecutionContext ctx) {
144
144
J .MethodDeclaration method = (J .MethodDeclaration ) currentTree ;
145
145
JavaType .Method mt = updateType (method .getMethodType ());
146
146
currentTree = method .withMethodType (mt )
147
- .withName (method .getName ().withType (mt ));
147
+ .withName (method .getName ().withType (mt ));
148
148
149
149
} else if (currentTree instanceof J .MethodInvocation ) {
150
150
151
151
J .MethodInvocation method = (J .MethodInvocation ) currentTree ;
152
152
JavaType .Method mt = updateType (method .getMethodType ());
153
153
currentTree = method .withMethodType (mt )
154
- .withName (method .getName ().withType (mt ));
154
+ .withName (method .getName ().withType (mt ));
155
155
156
156
} else if (currentTree instanceof J .NewClass ) {
157
157
@@ -184,12 +184,17 @@ private J postVisitSourceFile(JavaSourceFile tree, ExecutionContext ctx, J curre
184
184
JavaType maybeType = anImport .getQualid ().getType ();
185
185
if (maybeType instanceof JavaType .FullyQualified ) {
186
186
JavaType .FullyQualified type = (JavaType .FullyQualified ) maybeType ;
187
- if (originalType .getFullyQualifiedName ().equals (type .getFullyQualifiedName ())) {
187
+ String fullyQualifiedName = originalType .getFullyQualifiedName ();
188
+ if (fullyQualifiedName .equals (type .getFullyQualifiedName ())) {
189
+ sourceFile = (JavaSourceFile ) new RemoveImport <ExecutionContext >(fullyQualifiedName )
190
+ .visit (sourceFile , ctx , getCursor ().getParentOrThrow ());
191
+ } else if (originalType .getOwningClass () != null &&
192
+ originalType .getOwningClass ().getFullyQualifiedName ()
193
+ .equals (type .getFullyQualifiedName ())) {
188
194
sourceFile =
189
- (JavaSourceFile ) new RemoveImport <ExecutionContext >(originalType .getFullyQualifiedName ()).visit (sourceFile , ctx , getCursor ().getParentOrThrow ());
190
- } else if (originalType .getOwningClass () != null && originalType .getOwningClass ().getFullyQualifiedName ().equals (type .getFullyQualifiedName ())) {
191
- sourceFile =
192
- (JavaSourceFile ) new RemoveImport <ExecutionContext >(originalType .getOwningClass ().getFullyQualifiedName ()).visit (sourceFile , ctx , getCursor ().getParentOrThrow ());
195
+ (JavaSourceFile ) new RemoveImport <ExecutionContext >(
196
+ originalType .getOwningClass ().getFullyQualifiedName ())
197
+ .visit (sourceFile , ctx , getCursor ().getParentOrThrow ());
193
198
}
194
199
}
195
200
}
@@ -207,7 +212,9 @@ private J postVisitSourceFile(JavaSourceFile tree, ExecutionContext ctx, J curre
207
212
}
208
213
209
214
if (sourceFile != null ) {
210
- sourceFile = sourceFile .withImports (ListUtils .map (sourceFile .getImports (), i -> visitAndCast (i , ctx , super ::visitImport )));
215
+ sourceFile = sourceFile .withImports (
216
+ ListUtils .map (sourceFile .getImports (), i -> visitAndCast (i , ctx ,
217
+ super ::visitImport )));
211
218
}
212
219
213
220
currentTree = sourceFile ;
@@ -222,8 +229,9 @@ public J visitFieldAccess(J.FieldAccess fieldAccess, ExecutionContext ctx) {
222
229
JavaType targetType = entry .right ();
223
230
if (fieldAccess .isFullyQualifiedClassReference (originalType .getFullyQualifiedName ())) {
224
231
if (targetType instanceof JavaType .FullyQualified ) {
225
- return updateOuterClassTypes (TypeTree .build (((JavaType .FullyQualified ) targetType ).getFullyQualifiedName ())
226
- .withPrefix (fieldAccess .getPrefix ()), targetType );
232
+ return updateOuterClassTypes (
233
+ TypeTree .build (((JavaType .FullyQualified ) targetType ).getFullyQualifiedName ())
234
+ .withPrefix (fieldAccess .getPrefix ()), targetType );
227
235
}
228
236
} else {
229
237
StringBuilder maybeClass = new StringBuilder ();
@@ -465,9 +473,9 @@ private static boolean isV1Import(String currentFqcn) {
465
473
return false ;
466
474
}
467
475
468
- private static String currentFqcn (J .Import import_ ) {
476
+ private static String currentFqcn (J .Import anImport ) {
469
477
JavaType .FullyQualified currentFqcn =
470
- TypeUtils .asFullyQualified (Optional .ofNullable (import_ .getQualid ()).map (J .FieldAccess ::getType ).orElse (null ));
478
+ TypeUtils .asFullyQualified (Optional .ofNullable (anImport .getQualid ()).map (J .FieldAccess ::getType ).orElse (null ));
471
479
String curFqn = currentFqcn != null ? currentFqcn .getFullyQualifiedName () : null ;
472
480
return curFqn ;
473
481
}
0 commit comments