groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject groovy git commit: GROOVY-7747: Generated Java stub for enum with abstract method is invalid (closes #254)
Date Sat, 06 Feb 2016 06:36:55 GMT
Repository: groovy
Updated Branches:
  refs/heads/master d336ef560 -> 40507e0b8


GROOVY-7747: Generated Java stub for enum with abstract method is invalid (closes #254)


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

Branch: refs/heads/master
Commit: 40507e0b8cb0e0e6b7d2fa9b921e9f01df4d0c0f
Parents: d336ef5
Author: paulk <paulk@asert.com.au>
Authored: Fri Feb 5 21:07:05 2016 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Sat Feb 6 10:14:28 2016 +1000

----------------------------------------------------------------------
 .../groovy/tools/javac/JavaStubGenerator.java   |  8 +--
 .../tools/stubgenerator/Groovy7747Bug.groovy    | 63 ++++++++++++++++++++
 2 files changed, 67 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/40507e0b/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index 198052d..7c32ea4 100644
--- a/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -207,12 +207,12 @@ public class JavaStubGenerator {
             currentModule = classNode.getModule();
 
             boolean isInterface = isInterfaceOrTrait(classNode);
-            boolean isEnum = (classNode.getModifiers() & Opcodes.ACC_ENUM) != 0;
+            boolean isEnum = classNode.isEnum();
             boolean isAnnotationDefinition = classNode.isAnnotationDefinition();
             printAnnotations(out, classNode);
             printModifiers(out, classNode.getModifiers()
                     & ~(isInterface ? Opcodes.ACC_ABSTRACT : 0)
-                    & ~(isEnum ? Opcodes.ACC_FINAL : 0));
+                    & ~(isEnum ? Opcodes.ACC_FINAL | Opcodes.ACC_ABSTRACT : 0));
 
             if (isInterface) {
                 if (isAnnotationDefinition) {
@@ -609,7 +609,7 @@ public class JavaStubGenerator {
             if (isDefaultTraitImpl(methodNode)) {
                 modifiers ^= Opcodes.ACC_ABSTRACT;
             }
-            printModifiers(out, modifiers);
+            printModifiers(out, modifiers & ~(clazz.isEnum() ? Opcodes.ACC_ABSTRACT :
0));
         }
 
         printGenericsBounds(out, methodNode.getGenericsTypes());
@@ -633,7 +633,7 @@ public class JavaStubGenerator {
 
         if (Traits.isTrait(clazz)) {
             out.println(";");
-        } else if (isAbstract(methodNode)) {
+        } else if (isAbstract(methodNode) && !clazz.isEnum()) {
             if (clazz.isAnnotationDefinition() && methodNode.hasAnnotationDefault())
{
                 Statement fs = methodNode.getFirstStatement();
                 if (fs instanceof ExpressionStatement) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/40507e0b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy7747Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy7747Bug.groovy b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy7747Bug.groovy
new file mode 100644
index 0000000..7c551b9
--- /dev/null
+++ b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy7747Bug.groovy
@@ -0,0 +1,63 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.tools.stubgenerator
+
+/**
+ * Test that enums with an abstract method are compiled successfully.
+ */
+class Groovy7747Bug extends StringSourcesStubTestCase {
+
+    Map<String, String> provideSources() {
+        [
+                'Main.java' : '''
+                  import enums.EnumWithAbstractMethod;
+                  public class Main {
+                    public static void main(String[] args) {
+                      System.out.println(EnumWithAbstractMethod.values());
+                      System.out.println(EnumWithAbstractMethod.ONE.getInt());
+                    }
+                  }
+                ''',
+                'enums/EnumWithAbstractMethod.groovy' : '''
+                  package enums
+                  enum EnumWithAbstractMethod {
+                    ONE {
+                      @Override
+                      int getInt() {
+                        return 1
+                      }
+                    },
+                    TWO {
+                      @Override
+                      int getInt() {
+                        return 2
+                      }
+                    }
+                    abstract int getInt()
+                  }
+                '''
+        ]
+    }
+
+    void verifyStubs() {
+        def stubSource = stubJavaSourceFor('enums.EnumWithAbstractMethod')
+        assert stubSource.contains('enum EnumWithAbstractMethod')
+        assert !stubSource.matches('abstract.*enum')
+    }
+}


Mime
View raw message