You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2022/05/03 00:45:50 UTC

[groovy] 02/04: new test cases showing the problem with star imports and static imports

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

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

commit ee1847e53cb1e21c00c16a19a0206e2f4ab2869b
Author: Stephane Talbot <St...@univ-savoie.fr>
AuthorDate: Sat Apr 23 23:40:22 2022 +0200

    new test cases showing the problem with star imports and static imports
---
 .../groovy/tools/groovydoc/GroovyDocToolTest.java  | 84 +++++++++++++++++++++-
 .../testfiles/groovy_10593/a/StaticList.java       |  6 ++
 .../testfiles/groovy_10593/b/TestStar.groovy       |  5 ++
 .../testfiles/groovy_10593/b/TestStar.java         |  5 ++
 .../testfiles/groovy_10593/b/TestStatic.groovy     |  5 ++
 .../testfiles/groovy_10593/b/TestStatic.java       |  5 ++
 6 files changed, 109 insertions(+), 1 deletion(-)

diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
index 6147ed0de1..1443fe7c5a 100644
--- a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
@@ -766,7 +766,7 @@ public class GroovyDocToolTest extends GroovyTestCase {
         final MockOutputTool output = new MockOutputTool();
         htmlTool.renderToOutput(output, MOCK_DIR);
         final String testAdapterDoc = output.getText(MOCK_DIR + "/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/Test.html");
- 
+
         // Test should etends a.List
         final Matcher extendedClass = Pattern.compile("extends\\s+<a[^>]*href='[^']*(((java/util/)|(a/))List)\\.html'[^>]*>List</a>").matcher(testAdapterDoc);
         
@@ -795,6 +795,88 @@ public class GroovyDocToolTest extends GroovyTestCase {
         assertEquals("Classes from imported packages should shadow classes from default packages", "a/List", extendedClass.group(1));
     }
 
+    public void testGroovyExtendsStarImportedClassWithNameWhichExistInDefaultPackages() throws Exception {
+        // Groovy interface b.TestStar imports a.* and extends List.
+        // List should be recognized as a.List and not java.util.List 
+        htmlTool.add(Arrays.asList(
+                "org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/a/List.java",
+                "org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStar.groovy"
+        ));
+
+        final MockOutputTool output = new MockOutputTool();
+        htmlTool.renderToOutput(output, MOCK_DIR);
+        final String testAdapterDoc = output.getText(MOCK_DIR + "/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStar.html");
+
+        // TestStar should etends a.List
+        final Matcher extendedClass = Pattern.compile("extends\\s+<a[^>]*href='[^']*(((java/util/)|(a/))List)\\.html'[^>]*>List</a>").matcher(testAdapterDoc);
+        
+        assertTrue("TestStar interface should extends List", extendedClass.find());
+
+        assertEquals("Classes from imported packages should shadow classes from default packages", "a/List", extendedClass.group(1));
+    }
+
+    public void testJavaExtendsStarImportedClassWithNameWhichExistInDefaultPackages() throws Exception {
+        // Java interface b.TestStar imports a.* and extends List.
+        // List should be recognized as a.List and not java.util.List 
+        htmlTool.add(Arrays.asList(
+                "org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/a/List.java",
+                "org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStar.java"
+        ));
+
+        final MockOutputTool output = new MockOutputTool();
+        htmlTool.renderToOutput(output, MOCK_DIR);
+        final String testAdapterDoc = output.getText(MOCK_DIR + "/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStar.html");
+
+        // TestStar should etends a.List
+        final Matcher extendedClass = Pattern.compile("extends\\s+<a[^>]*href='[^']*(((java/util/)|(a/))List)\\.html'[^>]*>List</a>").matcher(testAdapterDoc);
+        
+        assertTrue("TestStar interface should extends List", extendedClass.find());
+
+        assertEquals("Classes from imported packages should shadow classes from default packages", "a/List", extendedClass.group(1));
+    }
+
+    public void testGroovyExtendsStaticImportedClassWithNameWhichExistInDefaultPackages() throws Exception {
+        // Groovy interface b.TestStatic imports a.StaticList.List and extends List.
+        // List should be recognized as a.StaticList.List and not java.util.List 
+        htmlTool.add(Arrays.asList(
+                "org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/a/StaticList.java",
+                "org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStatic.groovy"
+        ));
+
+        final MockOutputTool output = new MockOutputTool();
+        htmlTool.renderToOutput(output, MOCK_DIR);
+        final String testAdapterDoc = output.getText(MOCK_DIR + "/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStatic.html");
+
+        // TestStatic should etends a.StaticList.List
+        final Matcher extendedClass = Pattern.compile("extends\\s+<a[^>]*href='[^']*(((java/util/)|(a/StaticList\\.))List)\\.html'[^>]*>((StaticList\\.)?List)</a>").matcher(testAdapterDoc);
+        
+        assertTrue("TestStatic interface should extends List", extendedClass.find());
+
+        assertEquals("Classes from imported packages should shadow classes from default packages", "a/StaticList.List", extendedClass.group(1));
+        assertEquals("Classes from imported packages should shadow classes from default packages", "StaticList.List", extendedClass.group(5));
+    }
+
+    public void testJavaExtendsStaticImportedClassWithNameWhichExistInDefaultPackages() throws Exception {
+        // Java interface b.TestStatic imports a.StaticList.List and extends List.
+        // List should be recognized as a.StaticList.List and not java.util.List 
+        htmlTool.add(Arrays.asList(
+                "org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/a/StaticList.java",
+                "org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStatic.java"
+        ));
+
+        final MockOutputTool output = new MockOutputTool();
+        htmlTool.renderToOutput(output, MOCK_DIR);
+        final String testAdapterDoc = output.getText(MOCK_DIR + "/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStatic.html");
+
+        // TestStatic should etends a.StaticList.List".
+        final Matcher extendedClass = Pattern.compile("extends\\s+<a[^>]*href='[^']*(((java/util/)|(a/StaticList\\.))List)\\.html'[^>]*>((StaticList\\.)?List)</a>").matcher(testAdapterDoc);
+        
+        assertTrue("TestStatic interface should extends List", extendedClass.find());
+
+        assertEquals("Classes from imported packages should shadow classes from default packages", "a/StaticList.List", extendedClass.group(1));
+        assertEquals("Classes from imported packages should shadow classes from default packages", "StaticList.List", extendedClass.group(5));
+    }
+
     public void testClassDeclarationHeader() throws Exception {
         final String base = "org/codehaus/groovy/tools/groovydoc/testfiles";
         htmlTool.add(Arrays.asList(
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/a/StaticList.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/a/StaticList.java
new file mode 100644
index 0000000000..49938d5ebe
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/a/StaticList.java
@@ -0,0 +1,6 @@
+package org.codehaus.groovy.tools.groovydoc.testfiles.groovy_10593.a;
+
+public interface StaticList {
+    public static interface List {}
+    public static interface ListAlias {}
+}
\ No newline at end of file
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStar.groovy b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStar.groovy
new file mode 100644
index 0000000000..5ee0c9900d
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStar.groovy
@@ -0,0 +1,5 @@
+package org.codehaus.groovy.tools.groovydoc.testfiles.groovy_10593.b;
+
+import org.codehaus.groovy.tools.groovydoc.testfiles.groovy_10593.a.*;
+
+public interface TestStar extends List {}
\ No newline at end of file
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStar.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStar.java
new file mode 100644
index 0000000000..5ee0c9900d
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStar.java
@@ -0,0 +1,5 @@
+package org.codehaus.groovy.tools.groovydoc.testfiles.groovy_10593.b;
+
+import org.codehaus.groovy.tools.groovydoc.testfiles.groovy_10593.a.*;
+
+public interface TestStar extends List {}
\ No newline at end of file
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStatic.groovy b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStatic.groovy
new file mode 100644
index 0000000000..916c93ea8a
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStatic.groovy
@@ -0,0 +1,5 @@
+package org.codehaus.groovy.tools.groovydoc.testfiles.groovy_10593.b;
+
+import org.codehaus.groovy.tools.groovydoc.testfiles.groovy_10593.a.StaticList.List as List;
+
+public interface TestStatic extends List {}
\ No newline at end of file
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStatic.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStatic.java
new file mode 100644
index 0000000000..45d2f8d5c0
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/groovy_10593/b/TestStatic.java
@@ -0,0 +1,5 @@
+package org.codehaus.groovy.tools.groovydoc.testfiles.groovy_10593.b;
+
+import org.codehaus.groovy.tools.groovydoc.testfiles.groovy_10593.a.StaticList.List;
+
+public interface TestStatic extends List {}
\ No newline at end of file