You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/09/13 21:36:25 UTC

[groovy] branch GROOVY_3_0_X updated: LUB: reuse array of interfaces and common interface selection

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

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


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 55902799e0 LUB: reuse array of interfaces and common interface selection
55902799e0 is described below

commit 55902799e0597ff9b9e5065e19d3a765cbdafbac
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Sep 13 16:22:00 2022 -0500

    LUB: reuse array of interfaces and common interface selection
---
 build.bat                                               |  1 +
 .../codehaus/groovy/ast/tools/WideningCategories.java   | 17 +++++++----------
 .../groovy/ast/tools/WideningCategoriesTest.groovy      |  9 ++++++++-
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/build.bat b/build.bat
new file mode 100644
index 0000000000..8dcd28a383
--- /dev/null
+++ b/build.bat
@@ -0,0 +1 @@
+.\gradlew --max-workers 1 --no-build-cache --no-daemon --no-scan %*
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
index a51e1a1337..394027f662 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
@@ -353,18 +353,15 @@ public class WideningCategories {
             if (a.implementsInterface(b)) {
                 return b;
             }
-            // each interface may have one or more "extends", so we must find those
-            // which are common
-            ClassNode[] interfacesFromA = a.getInterfaces();
-            ClassNode[] interfacesFromB = b.getInterfaces();
-            Set<ClassNode> common = new HashSet<>();
-            Collections.addAll(common, interfacesFromA);
-            Set<ClassNode> fromB = new HashSet<>();
-            Collections.addAll(fromB, interfacesFromB);
-            common.retainAll(fromB);
+            if (interfacesImplementedByA == null)
+                interfacesImplementedByA = GeneralUtils.getInterfacesAndSuperInterfaces(a);
+            if (interfacesImplementedByB == null)
+                interfacesImplementedByB = GeneralUtils.getInterfacesAndSuperInterfaces(b);
 
+            // each interface may have one or more "extends", so we must find those which are common
+            List<ClassNode> common = keepLowestCommonInterfaces(interfacesImplementedByA, interfacesImplementedByB);
             if (common.size() == 1) {
-                return common.iterator().next();
+                return common.get(0);
             } else if (common.size() > 1) {
                 return buildTypeWithInterfaces(a, b, common);
             }
diff --git a/src/test/org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy b/src/test/org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy
index 192f6e60a2..765e9bc274 100644
--- a/src/test/org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy
+++ b/src/test/org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy
@@ -127,7 +127,14 @@ final class WideningCategoriesTest extends GenericsTestCase {
         assert lowestUpperBound(b,a) == make(HashSet)
     }
 
-    void testBuildCommonTypeWithTwoInterfacesSharingOneParent() {
+    void testBuildCommonTypeWithTwoInterfacesSharingOneParent0() {
+        ClassNode a = make(Set).plainNodeReference
+        ClassNode b = LIST_TYPE.plainNodeReference
+        assert lowestUpperBound(a,b).toString(false) == 'java.util.Collection <java.lang.Object>'
+        assert lowestUpperBound(b,a).toString(false) == 'java.util.Collection <java.lang.Object>'
+    }
+
+    void testBuildCommonTypeWithTwoInterfacesSharingOneParent1() {
         ClassNode a = make(InterfaceCA)
         ClassNode b = make(InterfaceDA)
         assert lowestUpperBound(a,b) == make(InterfaceA)