From c16e27c50374cb62862e5fd55b140f77c5939338 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Fri, 12 May 2023 22:25:26 +0200 Subject: [PATCH] Yet more import detection improvements Issue: #5 --- .../openrewrite/java/template/internal/ImportDetector.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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