diff --git a/src/main/java/org/openrewrite/java/template/internal/ImportDetector.java b/src/main/java/org/openrewrite/java/template/internal/ImportDetector.java index 5d8fea1..70d5fb2 100644 --- a/src/main/java/org/openrewrite/java/template/internal/ImportDetector.java +++ b/src/main/java/org/openrewrite/java/template/internal/ImportDetector.java @@ -61,7 +61,7 @@ public void scan(JCTree tree) { if (tree.type == null || !(tree.type.tsym instanceof Symbol.ClassSymbol)) { return; } - if (((JCIdent) tree).sym.getKind() == ElementKind.CLASS) { + if (((JCIdent) tree).sym.getKind() == ElementKind.CLASS || ((JCIdent) tree).sym.getKind() == ElementKind.INTERFACE) { imports.add(tree.type.tsym); } else if (((JCIdent) tree).sym.getKind() == ElementKind.FIELD) { imports.add(((JCIdent) tree).sym); @@ -72,6 +72,10 @@ public void scan(JCTree tree) { && ((JCFieldAccess) tree).selected instanceof JCIdent && ((JCIdent) ((JCFieldAccess) tree).selected).sym instanceof Symbol.ClassSymbol) { imports.add(((JCIdent) ((JCFieldAccess) tree).selected).sym); + } else if (tree instanceof JCFieldAccess && ((JCFieldAccess) tree).sym instanceof Symbol.MethodSymbol + && ((JCFieldAccess) tree).selected instanceof JCIdent + && ((JCIdent) ((JCFieldAccess) tree).selected).sym instanceof Symbol.ClassSymbol) { + imports.add(((JCIdent) ((JCFieldAccess) tree).selected).sym); } else if (tree instanceof JCFieldAccess && ((JCFieldAccess) tree).sym instanceof Symbol.ClassSymbol && ((JCFieldAccess) tree).selected instanceof JCIdent && ((JCIdent) ((JCFieldAccess) tree).selected).sym instanceof Symbol.ClassSymbol