Quantcast

[1/2] groovy git commit: GROOVY-8156: Compile error when ListenerList annotation exists (closes #524)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[1/2] groovy git commit: GROOVY-8156: Compile error when ListenerList annotation exists (closes #524)

jwagenleitner-2
Repository: groovy
Updated Branches:
  refs/heads/master 1ffe1a7d6 -> aa16cbf05


GROOVY-8156: Compile error when ListenerList annotation exists (closes #524)


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

Branch: refs/heads/master
Commit: 3e80a4fcd185d0f99fa7b4125355ded66f28f7e6
Parents: 1ffe1a7
Author: John Wagenleitner <[hidden email]>
Authored: Fri Apr 14 13:33:59 2017 -0700
Committer: John Wagenleitner <[hidden email]>
Committed: Wed Apr 19 21:10:06 2017 -0700

----------------------------------------------------------------------
 .../beans/ListenerListASTTransformation.groovy  |  3 +--
 .../groovy/beans/ListenerListASTTest.groovy     | 27 ++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/3e80a4fc/src/main/groovy/beans/ListenerListASTTransformation.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/beans/ListenerListASTTransformation.groovy b/src/main/groovy/beans/ListenerListASTTransformation.groovy
index 4591346..2e8b664 100644
--- a/src/main/groovy/beans/ListenerListASTTransformation.groovy
+++ b/src/main/groovy/beans/ListenerListASTTransformation.groovy
@@ -18,7 +18,6 @@
  */
 package groovy.beans
 
-import org.codehaus.groovy.ast.tools.GenericsUtils
 import org.codehaus.groovy.control.CompilePhase
 import org.codehaus.groovy.control.SourceUnit
 import org.codehaus.groovy.control.messages.SyntaxErrorMessage
@@ -353,7 +352,7 @@ class ListenerListASTTransformation implements ASTTransformation, Opcodes {
 
         def params = method.parameters.collect {
             def paramType = ClassHelper.getWrapper(it.type)
-            def cn = GenericsUtils.makeClassSafe(paramType.typeClass)
+            def cn = paramType.plainNodeReference
             cn.setRedirect(paramType)
             new Parameter(cn, it.name)
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/3e80a4fc/src/test/groovy/beans/ListenerListASTTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/beans/ListenerListASTTest.groovy b/src/test/groovy/beans/ListenerListASTTest.groovy
index 3952231..dae62aa 100644
--- a/src/test/groovy/beans/ListenerListASTTest.groovy
+++ b/src/test/groovy/beans/ListenerListASTTest.groovy
@@ -384,4 +384,31 @@ class ListenerListASTTest extends GroovyTestCase {
                 assert C.class.getMethod('getObjects')
             """)
         }
+
+    // GROOVY-8156
+    void testListenerListWithEventClassInSameCompilationUnit() {
+        assertScript '''
+            class Event {}
+
+            class EventListener {
+                Event event
+                void doSomething(Event e) {
+                    event = e
+                }
+            }
+
+            class EventHandler {
+                @groovy.beans.ListenerList
+                List<EventListener> listeners
+            }
+
+            def listener = new EventListener()
+            def eh = new EventHandler()
+            eh.addEventListener(listener)
+            def testEvent = new Event()
+            eh.fireDoSomething(testEvent)
+
+            assert listener.event.is(testEvent)
+        '''
+    }
 }

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[2/2] groovy git commit: cleanup now that jdk7 is baseline (closes #523)

jwagenleitner-2
cleanup now that jdk7 is baseline (closes #523)


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

Branch: refs/heads/master
Commit: aa16cbf05673cbc048a20b94d9483793a17d339b
Parents: 3e80a4f
Author: John Wagenleitner <[hidden email]>
Authored: Tue Apr 11 19:43:14 2017 -0700
Committer: John Wagenleitner <[hidden email]>
Committed: Wed Apr 19 21:10:07 2017 -0700

----------------------------------------------------------------------
 gradle/indy.gradle                              |  9 +---
 .../groovy/classgen/asm/WriterController.java   | 31 +++-----------
 .../asm/sc/StaticTypesWriterController.java     | 35 ++--------------
 .../reflection/GroovyClassValueFactory.java     | 44 +++++---------------
 .../transform/ASTTransformationVisitor.java     | 18 +-------
 5 files changed, 22 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/aa16cbf0/gradle/indy.gradle
----------------------------------------------------------------------
diff --git a/gradle/indy.gradle b/gradle/indy.gradle
index acfdf97..75b7422 100644
--- a/gradle/indy.gradle
+++ b/gradle/indy.gradle
@@ -21,14 +21,7 @@
 // with regards to invoke dynamic support (indy)
 
 rootProject.ext.indyCapable = {
-    boolean capable = true
-    try {
-        Class.forName('java.lang.invoke.MethodHandle')
-    } catch (e) {
-        capable = false
-    }
-
-    capable && !rootProject.hasProperty('skipIndy')
+    !rootProject.hasProperty('skipIndy')
 }
 
 rootProject.ext.useIndy = {

http://git-wip-us.apache.org/repos/asf/groovy/blob/aa16cbf0/src/main/org/codehaus/groovy/classgen/asm/WriterController.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/WriterController.java b/src/main/org/codehaus/groovy/classgen/asm/WriterController.java
index 6856c07..e8c5b61 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/WriterController.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/WriterController.java
@@ -18,8 +18,6 @@
  */
 package org.codehaus.groovy.classgen.asm;
 
-import groovy.lang.GroovyRuntimeException;
-import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -32,6 +30,9 @@ import org.codehaus.groovy.ast.InterfaceHelperClassNode;
 import org.codehaus.groovy.ast.MethodNode;
 import org.codehaus.groovy.classgen.AsmClassGenerator;
 import org.codehaus.groovy.classgen.GeneratorContext;
+import org.codehaus.groovy.classgen.asm.indy.IndyBinHelper;
+import org.codehaus.groovy.classgen.asm.indy.IndyCallSiteWriter;
+import org.codehaus.groovy.classgen.asm.indy.InvokeDynamicWriter;
 import org.codehaus.groovy.control.CompilerConfiguration;
 import org.codehaus.groovy.control.SourceUnit;
 import org.objectweb.asm.ClassVisitor;
@@ -40,22 +41,6 @@ import org.objectweb.asm.Opcodes;
 
 public class WriterController {
 
-    private static Constructor indyWriter, indyCallSiteWriter, indyBinHelper;
-    static {
-        try {
-            ClassLoader cl = WriterController.class.getClassLoader();
-            Class indyClass = cl.loadClass("org.codehaus.groovy.classgen.asm.indy.InvokeDynamicWriter");
-            indyWriter = indyClass.getConstructor(WriterController.class);
-            indyClass = cl.loadClass("org.codehaus.groovy.classgen.asm.indy.IndyCallSiteWriter");
-            indyCallSiteWriter = indyClass.getConstructor(WriterController.class);
-            indyClass = cl.loadClass("org.codehaus.groovy.classgen.asm.indy.IndyBinHelper");
-            indyBinHelper = indyClass.getConstructor(WriterController.class);
-        } catch (Exception e) {
-            indyWriter = null;
-            indyCallSiteWriter = null;
-            indyBinHelper = null;
-        }
-    }
     private AsmClassGenerator acg;
     private MethodVisitor methodVisitor;
     private CompileStack compileStack;
@@ -107,13 +92,9 @@ public class WriterController {
         bytecodeVersion = chooseBytecodeVersion(invokedynamic, config.getTargetBytecode());
 
         if (invokedynamic) {
-            try {
-                this.invocationWriter = (InvocationWriter) indyWriter.newInstance(this);
-                this.callSiteWriter = (CallSiteWriter) indyCallSiteWriter.newInstance(this);
-                this.binaryExpHelper = (BinaryExpressionHelper) indyBinHelper.newInstance(this);
-            } catch (Exception e) {
-                throw new GroovyRuntimeException("Cannot use invokedynamic, indy module was excluded from this build.");
-            }
+            this.invocationWriter = new InvokeDynamicWriter(this);
+            this.callSiteWriter = new IndyCallSiteWriter(this);
+            this.binaryExpHelper = new IndyBinHelper(this);
         } else {
             this.callSiteWriter = new CallSiteWriter(this);
             this.invocationWriter = new InvocationWriter(this);

http://git-wip-us.apache.org/repos/asf/groovy/blob/aa16cbf0/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesWriterController.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesWriterController.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesWriterController.java
index 577676f..04c06f2 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesWriterController.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesWriterController.java
@@ -22,14 +22,13 @@ import org.codehaus.groovy.ast.*;
 import org.codehaus.groovy.classgen.AsmClassGenerator;
 import org.codehaus.groovy.classgen.GeneratorContext;
 import org.codehaus.groovy.classgen.asm.*;
+import org.codehaus.groovy.classgen.asm.indy.sc.IndyStaticTypesMultiTypeDispatcher;
 import org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys;
 import org.codehaus.groovy.transform.sc.StaticCompilationVisitor;
 import org.codehaus.groovy.transform.stc.StaticTypesMarker;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.Opcodes;
 
-import java.lang.reflect.Constructor;
-
 
 /**
  * An alternative {@link org.codehaus.groovy.classgen.asm.WriterController} which handles static types and method
@@ -40,17 +39,6 @@ import java.lang.reflect.Constructor;
  */
 public class StaticTypesWriterController extends DelegatingController {
 
-    private static final Constructor indyBinHelper;
-    static {
-        Constructor ctor = null;
-        try {
-            ClassLoader cl = WriterController.class.getClassLoader();
-            Class clazz = cl.loadClass("org.codehaus.groovy.classgen.asm.indy.sc.IndyStaticTypesMultiTypeDispatcher");
-            ctor = clazz.getConstructor(WriterController.class);
-        } catch (Exception any) {}
-        indyBinHelper = ctor;
-    }
-
     protected boolean isInStaticallyCheckedMethod;
     private StaticTypesCallSiteWriter callSiteWriter;
     private StaticTypesStatementWriter statementWriter;
@@ -74,18 +62,9 @@ public class StaticTypesWriterController extends DelegatingController {
         this.invocationWriter = new StaticInvocationWriter(this);
         this.closureWriter = new StaticTypesClosureWriter(this);
         this.unaryExpressionHelper = new StaticTypesUnaryExpressionHelper(this);
-        boolean useIndy = getBytecodeVersion()>Opcodes.V1_6 && indyBinHelper!=null;
-
-        boolean binHelperSet = false;
-        if (useIndy) {
-            try {
-                this.binaryExprHelper = (BinaryExpressionMultiTypeDispatcher) indyBinHelper.newInstance(this);
-                binHelperSet = true;
-            } catch (Exception any) {}
-        }
-        if (!binHelperSet) {
-            this.binaryExprHelper = new StaticTypesBinaryExpressionMultiTypeDispatcher(this);
-        }
+        this.binaryExprHelper = (getBytecodeVersion() > Opcodes.V1_6)
+                ? new IndyStaticTypesMultiTypeDispatcher(this)
+                : new StaticTypesBinaryExpressionMultiTypeDispatcher(this);
     }
 
     @Override
@@ -104,12 +83,6 @@ public class StaticTypesWriterController extends DelegatingController {
         isInStaticallyCheckedMethod = mn != null && (
                 StaticCompilationVisitor.isStaticallyCompiled(node)
                         || classNode.implementsInterface(ClassHelper.GENERATED_CLOSURE_Type)&&classNode.getNodeMetaData(StaticCompilationMetadataKeys.STATIC_COMPILE_NODE)!=null);
-
-/*      if (isInStaticallyCheckedMethod) {
-            System.out.println("Entering statically compiled method: "+mn.getDeclaringClass()+"#"+mn);
-        } else if (mn!=null) {
-            System.out.println("Entering dynamically compiled method: "+mn.getDeclaringClass()+"#"+mn);
-        }*/
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/groovy/blob/aa16cbf0/src/main/org/codehaus/groovy/reflection/GroovyClassValueFactory.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/reflection/GroovyClassValueFactory.java b/src/main/org/codehaus/groovy/reflection/GroovyClassValueFactory.java
index f3d55e1..c367791 100644
--- a/src/main/org/codehaus/groovy/reflection/GroovyClassValueFactory.java
+++ b/src/main/org/codehaus/groovy/reflection/GroovyClassValueFactory.java
@@ -19,48 +19,24 @@
 package org.codehaus.groovy.reflection;
 
 import org.codehaus.groovy.reflection.GroovyClassValue.ComputeValue;
-
-import java.lang.reflect.Constructor;
+import org.codehaus.groovy.reflection.v7.GroovyClassValueJava7;
 
 class GroovyClassValueFactory {
  /**
  * This flag is introduced as a (hopefully) temporary workaround for a JVM bug, that is to say that using
  * ClassValue prevents the classes and classloaders from being unloaded.
  * See https://bugs.openjdk.java.net/browse/JDK-8136353
- * This issue does not exist on IBM Java (J9) so use ClassValue by default on that JVM.
+ * This issue does not exist on IBM Java (J9) so use ClassValue by default on that JVM.
  */
- private static final boolean USE_CLASSVALUE = Boolean.valueOf(System.getProperty("groovy.use.classvalue", "IBM J9 VM".equals(System.getProperty("java.vm.name"))?"true":"false"));
-
- private static final Constructor groovyClassValueConstructor;
-
+ private static final boolean USE_CLASSVALUE;
  static {
- Class groovyClassValueClass;
- if (USE_CLASSVALUE) {
- try {
- Class.forName("java.lang.ClassValue");
- try {
- groovyClassValueClass = Class.forName("org.codehaus.groovy.reflection.v7.GroovyClassValueJava7");
- } catch (Exception e) {
- throw new RuntimeException(e); // this should never happen, but if it does, let it propagate and be fatal
- }
- } catch (ClassNotFoundException e) {
- groovyClassValueClass = GroovyClassValuePreJava7.class;
- }
- } else {
- groovyClassValueClass = GroovyClassValuePreJava7.class;
- }
- try{
- groovyClassValueConstructor = groovyClassValueClass.getConstructor(ComputeValue.class);
- }catch(Exception e){
- throw new RuntimeException(e); // this should never happen, but if it does, let it propagate and be fatal
- }
- }
+        String isJ9 = "IBM J9 VM".equals(System.getProperty("java.vm.name")) ? "true" : "false";
+        USE_CLASSVALUE = Boolean.valueOf(System.getProperty("groovy.use.classvalue", isJ9));
+    }
 
- public static <T> GroovyClassValue<T> createGroovyClassValue(ComputeValue<T> computeValue){
- try {
- return (GroovyClassValue<T>) groovyClassValueConstructor.newInstance(computeValue);
- } catch (Exception e) {
- throw new RuntimeException(e); // this should never happen, but if it does, let it propagate and be fatal
- }
+ public static <T> GroovyClassValue<T> createGroovyClassValue(ComputeValue<T> computeValue) {
+ return (USE_CLASSVALUE)
+                ? new GroovyClassValueJava7<>(computeValue)
+                : new GroovyClassValuePreJava7<>(computeValue);
  }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/aa16cbf0/src/main/org/codehaus/groovy/transform/ASTTransformationVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/ASTTransformationVisitor.java b/src/main/org/codehaus/groovy/transform/ASTTransformationVisitor.java
index bf1f6d3..a3ea7a0 100644
--- a/src/main/org/codehaus/groovy/transform/ASTTransformationVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/ASTTransformationVisitor.java
@@ -256,23 +256,7 @@ public final class ASTTransformationVisitor extends ClassCodeVisitorSupport {
                 "IO Exception attempting to load global transforms:" + e.getMessage(),
                 null));
         }
-        try {
-            Class.forName("java.lang.annotation.Annotation"); // test for 1.5 JVM
-        } catch (Exception e) {
-            // we failed, notify the user
-            StringBuilder sb = new StringBuilder();
-            sb.append("Global ASTTransformations are not enabled in retro builds of groovy.\n");
-            sb.append("The following transformations will be ignored:");
-            for (Map.Entry<String, URL> entry : transformNames.entrySet()) {
-                sb.append('\t');
-                sb.append(entry.getKey());
-                sb.append('\n');
-            }
-            compilationUnit.getErrorCollector().addWarning(new WarningMessage(
-                WarningMessage.POSSIBLE_ERRORS, sb.toString(), null, null));
-            return;
-        }
-        
+
         // record the transforms found in the first scan, so that in the 2nd scan, phase operations
         // can be added for only for new transforms that have come in
         if(isFirstScan) {

Loading...