groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject groovy git commit: GROOVY-8360: Nested enum types should have the static class modifier (closes #619)
Date Sat, 04 Nov 2017 17:20:33 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 9b10d057a -> 42986d65c


GROOVY-8360: Nested enum types should have the static class modifier (closes #619)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/42986d65
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/42986d65
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/42986d65

Branch: refs/heads/GROOVY_2_6_X
Commit: 42986d65cd4747eae07d15632f143f052bcb9ee4
Parents: 9b10d05
Author: Shil Sinha <shil.sinha@gmail.com>
Authored: Thu Oct 19 18:37:23 2017 -0400
Committer: Shil Sinha <shils@apache.org>
Committed: Sat Nov 4 13:13:10 2017 -0400

----------------------------------------------------------------------
 .../org/codehaus/groovy/antlr/EnumHelper.java   |  1 +
 src/test/gls/enums/EnumTest.groovy              | 74 ++++++++++++++++++++
 2 files changed, 75 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/42986d65/src/main/org/codehaus/groovy/antlr/EnumHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/antlr/EnumHelper.java b/src/main/org/codehaus/groovy/antlr/EnumHelper.java
index 63942f7..6f5fc3e 100644
--- a/src/main/org/codehaus/groovy/antlr/EnumHelper.java
+++ b/src/main/org/codehaus/groovy/antlr/EnumHelper.java
@@ -39,6 +39,7 @@ public class EnumHelper {
             enumClass = new ClassNode(name,modifiers,null,interfaces,MixinNode.EMPTY_ARRAY);
         } else {
             name = outerClass.getName() + "$" + name;
+            modifiers |= Opcodes.ACC_STATIC;
             enumClass = new InnerClassNode(outerClass,name,modifiers,null,interfaces,MixinNode.EMPTY_ARRAY);
         }
         

http://git-wip-us.apache.org/repos/asf/groovy/blob/42986d65/src/test/gls/enums/EnumTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/enums/EnumTest.groovy b/src/test/gls/enums/EnumTest.groovy
index a0a4d8c..e883ed1 100644
--- a/src/test/gls/enums/EnumTest.groovy
+++ b/src/test/gls/enums/EnumTest.groovy
@@ -603,6 +603,80 @@ class EnumTest extends CompilableTestSupport {
             assert Foo.getAnnotations().size() == 1
           '''
     }
+
+    void testNestedEnumHasStaticModifier_GROOVY_8360() {
+        assertScript '''
+            class Foo {
+                enum Bar {
+                    X('x'), Y
+                    String s
+                    Bar(String s) { this.s = s }
+                    Bar() {}
+                }
+            }            
+            assert java.lang.reflect.Modifier.isStatic(Foo.Bar.modifiers)
+            assert Foo.Bar.X.s == 'x'
+        '''
+    }
+
+    void testEnumWithinInnerClassHasStaticModifier_GROOVY_8360() {
+        assertScript '''
+            class Foo {
+                class Baz {
+                    enum Bar {
+                        X('x'), Y                                                       
                
+                        String s                                                        
                                       
+                        Bar(String s) { this.s = s }
+                        Bar() {}                                                
+                    }                
+                }
+            }            
+            assert java.lang.reflect.Modifier.isStatic(Foo.Baz.Bar.modifiers)
+            assert Foo.Baz.Bar.X.s == 'x'
+        '''
+    }
+
+    void testNestedEnumHasStaticModifierSC_GROOVY_8360() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            class Foo {
+                enum Bar {
+                    X('x'), Y
+                    String s
+                    Bar(String s) { this.s = s }
+                    Bar() {}
+                }
+            }          
+            @groovy.transform.CompileStatic
+            void test() {
+                assert java.lang.reflect.Modifier.isStatic(Foo.Bar.getModifiers())
+                assert Foo.Bar.X.s == 'x'
+            }
+            test()
+        '''
+    }
+
+    void testEnumWithinInnerClassHasStaticModifierSC_GROOVY_8360() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            class Foo {
+                class Baz {
+                    enum Bar {
+                        X('x'), Y                                                       
                
+                        String s                                                        
                                       
+                        Bar(String s) { this.s = s }
+                        Bar() {}                                                
+                    }                
+                }
+            }
+            @groovy.transform.CompileStatic
+            void test() {
+                assert java.lang.reflect.Modifier.isStatic(Foo.Baz.Bar.getModifiers())
+                assert Foo.Baz.Bar.X.s == 'x'            
+            }
+            test()                       
+        '''
+    }
 }
 
 enum UsCoin {


Mime
View raw message