This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new b1360f4 GROOVY-7510: stubgen: skip over `import static
pack.Type.propertyName`
b1360f4 is described below
commit b1360f4a953ff295b7ee0454e1f1ecd522375e31
Author: Eric Milles <[email protected]>
AuthorDate: Mon Oct 25 18:01:26 2021 -0500
GROOVY-7510: stubgen: skip over `import static pack.Type.propertyName`
---
.../groovy/tools/javac/JavaStubGenerator.java | 33 ++++++------
.../groovy/tools/stubgenerator/Groovy7510.groovy | 59 ++++++++++++++++++++++
2 files changed, 74 insertions(+), 18 deletions(-)
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 d8abb06..7bb06d0 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -1013,35 +1013,32 @@ public class JavaStubGenerator {
}
private static void printImports(PrintWriter out, ClassNode classNode) {
- List<String> imports = new ArrayList<String>();
+ List<String> imports = new ArrayList<>();
+ ModuleNode module = classNode.getModule();
- ModuleNode moduleNode = classNode.getModule();
- for (ImportNode importNode : moduleNode.getStarImports()) {
- imports.add(importNode.getPackageName());
+ for (ImportNode imp : module.getImports()) {
+ if (imp.getAlias() == null) imports.add(imp.getType().getName());
}
- for (ImportNode imp : moduleNode.getImports()) {
- if (imp.getAlias() == null)
- imports.add(imp.getType().getName());
+ for (ImportNode imp : module.getStarImports()) {
+ imports.add(imp.getPackageName());
}
- imports.addAll(Arrays.asList(ResolveVisitor.DEFAULT_IMPORTS));
+ Collections.addAll(imports, ResolveVisitor.DEFAULT_IMPORTS);
- for (Map.Entry<String, ImportNode> entry :
moduleNode.getStaticImports().entrySet()) {
- if (entry.getKey().equals(entry.getValue().getFieldName()))
- imports.add("static
"+entry.getValue().getType().getName()+"."+entry.getKey());
+ for (Map.Entry<String, ImportNode> entry :
module.getStaticImports().entrySet()) {
+ String memberName = entry.getKey();
+ if (memberName.equals(entry.getValue().getFieldName())
+ && !Character.isLowerCase(memberName.charAt(0))) //
GROOVY-7510
+ imports.add("static " + entry.getValue().getType().getName() +
"." + memberName);
}
- for (Map.Entry<String, ImportNode> entry :
moduleNode.getStaticStarImports().entrySet()) {
- imports.add("static "+entry.getValue().getType().getName()+".");
+ for (Map.Entry<String, ImportNode> entry :
module.getStaticStarImports().entrySet()) {
+ imports.add("static " + entry.getValue().getType().getName() +
".");
}
for (String imp : imports) {
- String s = ("import " +
- imp +
- ((imp.charAt(imp.length() - 1) == '.') ? "*;" : ";"))
- .replace('$', '.');
- out.println(s);
+ out.println("import " + imp.replace('$', '.') + (imp.endsWith(".")
? "*;" : ";"));
}
out.println();
}
diff --git a/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy7510.groovy
b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy7510.groovy
new file mode 100644
index 0000000..df35918
--- /dev/null
+++ b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy7510.groovy
@@ -0,0 +1,59 @@
+/*
+ * 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
+
+final class Groovy7510 extends StringSourcesStubTestCase {
+
+ @Override
+ Map<String, String> provideSources() {
+ [
+ 'p/A.groovy': '''
+ package p
+ class A {
+ static String aString
+ }
+ ''',
+
+ 'p/B.groovy': '''
+ package p
+ import static p.A.aString
+ class B {
+ String returnAString() {
+ return aString
+ }
+ }
+ ''',
+
+ 'p/C.java': '''
+ package p;
+ public class C {
+ public static void main(String[] args) {
+ new B().returnAString();
+ }
+ }
+ '''
+ ]
+ }
+
+ @Override
+ void verifyStubs() {
+ String stub = stubJavaSourceFor('p.B')
+ assert !stub.contains('import static p.A.aString')
+ }
+}