Repository: groovy Updated Branches: refs/heads/master 9e64c6aaa -> d00f60155
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/d00f6015 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d00f6015 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d00f6015 Branch: refs/heads/master Commit: d00f60155ce71131ec1969e07dde3bf4d8c65460 Parents: 9e64c6a Author: Shil Sinha <[email protected]> Authored: Thu Oct 19 18:37:23 2017 -0400 Committer: Shil Sinha <[email protected]> Committed: Sat Nov 4 12:12:03 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/d00f6015/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/d00f6015/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 {
