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:27:35 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X bbe1373ad -> ba3e3f4fa


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/ba3e3f4f
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/ba3e3f4f
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/ba3e3f4f

Branch: refs/heads/GROOVY_2_5_X
Commit: ba3e3f4fa85eb46ede38de4524acd3b26008771c
Parents: bbe1373
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:21:28 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/ba3e3f4f/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/ba3e3f4f/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