You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by jw...@apache.org on 2017/04/20 04:09:10 UTC

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

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 3aa2a0380 -> cddbe169e


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

Branch: refs/heads/GROOVY_2_5_X
Commit: b057b41408f1b2e386ef5a8dc6722274e02b0fd3
Parents: 3aa2a03
Author: John Wagenleitner <jw...@apache.org>
Authored: Fri Apr 14 13:33:59 2017 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Wed Apr 19 21:05:34 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/b057b414/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/b057b414/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)
+        '''
+    }
 }


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

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

Branch: refs/heads/GROOVY_2_5_X
Commit: cddbe169e6216d32f159515b232cf3cd624b9816
Parents: b057b41
Author: John Wagenleitner <jw...@apache.org>
Authored: Tue Apr 11 19:43:14 2017 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Wed Apr 19 21:06:14 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/cddbe169/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/cddbe169/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/cddbe169/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/cddbe169/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/cddbe169/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) {