This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY_5_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_5_0_X by this push:
     new 3144949968 GROOVY-11806: non-static star imports required if any 
unresolved type
3144949968 is described below

commit 314494996849d150614c2651a9304fc84e47c416
Author: Eric Milles <[email protected]>
AuthorDate: Fri Nov 21 12:56:58 2025 -0600

    GROOVY-11806: non-static star imports required if any unresolved type
---
 .../tools/javac/JavaAwareResolveVisitor.java       |  3 +-
 .../groovy/tools/javac/JavaStubGenerator.java      |  7 +++
 .../groovy/tools/stubgenerator/Groovy11806.groovy  | 62 ++++++++++++++++++++++
 .../groovy/tools/stubgenerator/StubTestCase.groovy |  2 +-
 4 files changed, 72 insertions(+), 2 deletions(-)

diff --git 
a/src/main/java/org/codehaus/groovy/tools/javac/JavaAwareResolveVisitor.java 
b/src/main/java/org/codehaus/groovy/tools/javac/JavaAwareResolveVisitor.java
index b7740e8170..729e3cbc93 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaAwareResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaAwareResolveVisitor.java
@@ -49,6 +49,7 @@ public class JavaAwareResolveVisitor extends ResolveVisitor {
 
     @Override
     public void addError(final String error, final ASTNode node) {
-        // do nothing here; leave it to the normal resolving
+        if (error.startsWith("unable to resolve")) // GROOVY-11806
+            getSourceUnit().getAST().putNodeMetaData("require.imports", 
Boolean.TRUE);
     }
 }
diff --git 
a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java 
b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index f5352d9aa0..92f32fcc5b 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -1062,6 +1062,13 @@ public class JavaStubGenerator {
             out.println("import static " + 
ssi.getType().getName().replace('$', '.') + ".*;");
         }
 
+        // GROOVY-11806: non-static star imports are required if any 
unresolved type
+        if 
(Boolean.TRUE.equals(currentModule.getNodeMetaData("require.imports"))) {
+            for (ImportNode si : currentModule.getStarImports()) {
+                out.println("import " + si.getPackageName() + "*;");
+            }
+        }
+
         out.println();
     }
 
diff --git 
a/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/Groovy11806.groovy 
b/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/Groovy11806.groovy
new file mode 100644
index 0000000000..afc4a277a3
--- /dev/null
+++ b/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/Groovy11806.groovy
@@ -0,0 +1,62 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.tools.stubgenerator
+
+import org.codehaus.groovy.control.CompilationFailedException
+
+final class Groovy11806 extends StringSourcesStubTestCase {
+
+    @Override
+    Map<String, String> provideSources() {
+        [
+            'p/A.java': '''
+                package p;
+                public interface A {
+                }
+            ''',
+            /* not given to compiler
+            'p/B.java': '''
+                package p;
+                public interface B {
+                }
+            ''',
+            */
+            'C.groovy': '''
+                import p.*
+                class C implements A {
+                    B m() {
+                    }
+                }
+            ''',
+        ]
+    }
+
+    @Override
+    void verifyStubs() {
+        String source= stubJavaSourceFor('C')
+        assert source.contains('import p.*;')
+    }
+
+    @Override
+    void handleCompilationFailure(CompilationFailedException cfe) {
+        if (!cfe.message.contains('unable to resolve class B')) {
+            super.handleCompilationFailure(cfe)
+        }
+    }
+}
diff --git 
a/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy 
b/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy
index d6cee4c5c5..429696dfec 100644
--- 
a/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy
+++ 
b/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy
@@ -63,7 +63,7 @@ abstract class StubTestCase extends GroovyTestCase {
     protected JavaProjectBuilder qdox = new JavaProjectBuilder()
 
     protected GroovyClassLoader loader
-    protected CompilerConfiguration config = new CompilerConfiguration()
+    protected CompilerConfiguration config
 
     protected boolean debug = false;
     protected boolean delete = true;

Reply via email to