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/01/24 03:15:01 UTC

[groovy] branch GROOVY_4_0_X updated (71e84d4 -> eb2c9e3)

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

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


    from 71e84d4  GROOVY-10463: Add equals() and hashCode() methods to ImportNode (fix hashCode caching)
     new 7aa6df6  GROOVY-10434: ClassNode isSealed() refactoring (additional test)
     new 51729be  GROOVY-10434: ClassNode isSealed() refactoring (additional test)
     new eb2c9e3  GROOVY-8433: Category transform implies static methods

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../groovy/classgen/InnerClassVisitor.java         |  5 +++-
 src/spec/test/metaprogramming/CategoryTest.groovy  | 20 +++++++++++++++
 .../groovy/transform/SealedTransformTest.groovy    | 30 ++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)

[groovy] 02/03: GROOVY-10434: ClassNode isSealed() refactoring (additional test)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 51729bee8fd7cf7312e9ca3891c5fbf70c873129
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Jan 22 22:07:47 2022 +1000

    GROOVY-10434: ClassNode isSealed() refactoring (additional test)
---
 .../groovy/transform/SealedTransformTest.groovy       | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/test/org/codehaus/groovy/transform/SealedTransformTest.groovy b/src/test/org/codehaus/groovy/transform/SealedTransformTest.groovy
index 939c155..d838cda 100644
--- a/src/test/org/codehaus/groovy/transform/SealedTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/SealedTransformTest.groovy
@@ -235,7 +235,7 @@ class SealedTransformTest {
     }
 
     @Test
-    void testClassNodeIsSealed() {
+    void testClassNodeIsSealedExplicitSubclasses() {
         assertScript '''
             import groovy.transform.*
             import org.codehaus.groovy.control.CompilePhase
@@ -244,7 +244,22 @@ class SealedTransformTest {
                 assert node.isSealed()
             })
             sealed class Foo permits Bar {}
-            final class Bar {}
+            final class Bar extends Foo {}
+            new Foo()
+        '''
+    }
+
+    @Test
+    void testClassNodeIsSealedImplicitSubclasses() {
+        assertScript '''
+            import groovy.transform.*
+            import org.codehaus.groovy.control.CompilePhase
+            @ASTTest(phase = CompilePhase.CANONICALIZATION, value = {
+                assert node.permittedSubclasses*.name == ['Bar']
+                assert node.isSealed()
+            })
+            sealed class Foo {}
+            final class Bar extends Foo {}
             new Foo()
         '''
     }

[groovy] 01/03: GROOVY-10434: ClassNode isSealed() refactoring (additional test)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7aa6df692f61baed80f39e8dfb649284b638b1a1
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Jan 22 14:13:59 2022 +1000

    GROOVY-10434: ClassNode isSealed() refactoring (additional test)
---
 .../codehaus/groovy/transform/SealedTransformTest.groovy  | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/test/org/codehaus/groovy/transform/SealedTransformTest.groovy b/src/test/org/codehaus/groovy/transform/SealedTransformTest.groovy
index 7e23073..939c155 100644
--- a/src/test/org/codehaus/groovy/transform/SealedTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/SealedTransformTest.groovy
@@ -233,4 +233,19 @@ class SealedTransformTest {
             sealed class Other permits Other { }
         ''').message.contains(expected)
     }
+
+    @Test
+    void testClassNodeIsSealed() {
+        assertScript '''
+            import groovy.transform.*
+            import org.codehaus.groovy.control.CompilePhase
+            @ASTTest(phase = CompilePhase.SEMANTIC_ANALYSIS, value = {
+                assert node.permittedSubclasses*.name == ['Bar']
+                assert node.isSealed()
+            })
+            sealed class Foo permits Bar {}
+            final class Bar {}
+            new Foo()
+        '''
+    }
 }

[groovy] 03/03: GROOVY-8433: Category transform implies static methods

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit eb2c9e3e2188257f9d02057b34d6a35747bf6287
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Jan 23 11:14:03 2022 -0600

    GROOVY-8433: Category transform implies static methods
---
 .../codehaus/groovy/classgen/InnerClassVisitor.java  |  5 ++++-
 src/spec/test/metaprogramming/CategoryTest.groovy    | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/InnerClassVisitor.java b/src/main/java/org/codehaus/groovy/classgen/InnerClassVisitor.java
index 8fd2cd4..3855d95 100644
--- a/src/main/java/org/codehaus/groovy/classgen/InnerClassVisitor.java
+++ b/src/main/java/org/codehaus/groovy/classgen/InnerClassVisitor.java
@@ -227,7 +227,7 @@ public class InnerClassVisitor extends InnerClassVisitorHelper {
         innerClass.addConstructor(ACC_SYNTHETIC, parameters.toArray(Parameter.EMPTY_ARRAY), ClassNode.EMPTY_ARRAY, block);
     }
 
-    private boolean isStatic(InnerClassNode innerClass, VariableScope scope, ConstructorCallExpression call) {
+    private boolean isStatic(final ClassNode innerClass, final VariableScope scope, final ConstructorCallExpression call) {
         boolean isStatic = innerClass.isStaticClass();
         if (!isStatic) {
             if (currentMethod != null) {
@@ -255,6 +255,9 @@ public class InnerClassVisitor extends InnerClassVisitorHelper {
                 isStatic = currentField.isStatic();
             }
         }
+        // GROOVY-8433: Category transform implies static method
+        isStatic = isStatic || innerClass.getOuterClass().getAnnotations().stream()
+            .anyMatch(a -> a.getClassNode().getName().equals("groovy.lang.Category"));
         return isStatic;
     }
 
diff --git a/src/spec/test/metaprogramming/CategoryTest.groovy b/src/spec/test/metaprogramming/CategoryTest.groovy
index 16bd7b0..1d528c6 100644
--- a/src/spec/test/metaprogramming/CategoryTest.groovy
+++ b/src/spec/test/metaprogramming/CategoryTest.groovy
@@ -56,4 +56,24 @@ class CategoryTest extends GroovyTestCase {
             // end::time_category_anno[]
         '''
     }
+
+    // GROOVY-8433
+    void testCategoryAnnotationAndAIC() {
+        assertScript '''
+            @Category(Number)
+            class NumberCategory {
+                def m() {
+                    String variable = 'works'
+                    new Object() { // "Cannot cast object '1' with class 'java.lang.Integer' to class 'NumberCategory'" due to implicit "this"
+                        String toString() { variable }
+                    }
+                }
+            }
+
+            use (NumberCategory) {
+                String result = 1.m()
+                assert result == 'works'
+            }
+        '''
+    }
 }