Skip to content

Commit

Permalink
Use ImportService in ReplaceAnnotation
Browse files Browse the repository at this point in the history
Using `ImportService#shortenFullyQualifiedTypeReferencesIn()` rather than directly `ShortenFullyQualifiedTypeReferences` has the advantage that it will allow a language-specific implementation to be used (e.g. for Kotlin), whenever the source file being modified is not a Java source.
  • Loading branch information
knutwannheden committed Jun 4, 2024
1 parent 0a0a864 commit 1b4f9f1
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import lombok.Value;
import org.openrewrite.*;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.service.ImportService;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaCoordinates;
import org.openrewrite.java.tree.TypeUtils;
Expand Down Expand Up @@ -91,7 +92,7 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct
maybeRemoveImport(TypeUtils.asFullyQualified(a.getType()));
JavaCoordinates replaceCoordinate = a.getCoordinates().replace();
a = replacement.apply(getCursor(), replaceCoordinate);
doAfterVisit(ShortenFullyQualifiedTypeReferences.modifyOnly(a));
doAfterVisit(service(ImportService.class).shortenFullyQualifiedTypeReferencesIn(a));
return a;
}
}
Expand Down

0 comments on commit 1b4f9f1

Please sign in to comment.