You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2017/06/19 06:08:33 UTC

[1/2] groovy git commit: GROOVY-8226: JSR308 initial plumbing tweaks (closes #560, side effect: closes #546)

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 5e6c850fb -> 2d1391d71


GROOVY-8226: JSR308 initial plumbing tweaks (closes #560, side effect: closes #546)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 2d1391d71875dde983ed71bf7b7b1bccd3fc7899
Parents: a0b4e85
Author: paulk <pa...@asert.com.au>
Authored: Mon Jun 12 20:10:50 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Jun 19 16:05:57 2017 +1000

----------------------------------------------------------------------
 .../org/codehaus/groovy/ast/AnnotationNode.java | 15 ++++++-----
 .../groovy/ast/decompiled/Annotations.java      |  4 +--
 .../org/codehaus/groovy/vmplugin/VMPlugin.java  |  5 ++--
 .../org/codehaus/groovy/vmplugin/v5/Java5.java  |  8 +++++-
 .../org/codehaus/groovy/vmplugin/vm8/Java8.java | 12 +++++++++
 src/test/gls/annotations/AnnotationTest.groovy  | 26 ++++++++++++++++++++
 6 files changed, 59 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/2d1391d7/src/main/org/codehaus/groovy/ast/AnnotationNode.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/AnnotationNode.java b/src/main/org/codehaus/groovy/ast/AnnotationNode.java
index e00f977..c493299 100644
--- a/src/main/org/codehaus/groovy/ast/AnnotationNode.java
+++ b/src/main/org/codehaus/groovy/ast/AnnotationNode.java
@@ -25,12 +25,8 @@ import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
-
 /**
  * Represents an annotation which can be attached to interfaces, classes, methods and fields.
- * 
- * @author <a href="mailto:jstrachan@protique.com">James Strachan</a>
- * @author <a href='mailto:the[dot]mindstorm[at]gmail[dot]com'>Alex Popescu</a>
  */
 public class AnnotationNode extends ASTNode {
     public static final int CONSTRUCTOR_TARGET = 1 << 1;
@@ -40,10 +36,13 @@ public class AnnotationNode extends ASTNode {
     public static final int LOCAL_VARIABLE_TARGET = 1 << 5;
     public static final int ANNOTATION_TARGET = 1 << 6;
     public static final int PACKAGE_TARGET = 1 << 7;
+    public static final int TYPE_PARAMETER_TARGET = 1 << 8;
+    public static final int TYPE_USE_TARGET = 1 << 9;
     public static final int TYPE_TARGET = 1 + ANNOTATION_TARGET;    //GROOVY-7151
     private static final int ALL_TARGETS = TYPE_TARGET | CONSTRUCTOR_TARGET | METHOD_TARGET
-        | FIELD_TARGET | PARAMETER_TARGET | LOCAL_VARIABLE_TARGET | ANNOTATION_TARGET | PACKAGE_TARGET;
-    
+            | FIELD_TARGET | PARAMETER_TARGET | LOCAL_VARIABLE_TARGET | ANNOTATION_TARGET
+            | PACKAGE_TARGET | TYPE_PARAMETER_TARGET | TYPE_USE_TARGET;
+
     private final ClassNode classNode;
     private Map<String, Expression> members;
     private boolean runtimeRetention= false, sourceRetention= false, classRetention = false;
@@ -179,6 +178,10 @@ public class AnnotationNode extends ASTNode {
                 return "ANNOTATION";
             case PACKAGE_TARGET:
                 return "PACKAGE";
+            case TYPE_PARAMETER_TARGET:
+                return "TYPE_PARAMETER";
+            case TYPE_USE_TARGET:
+                return "TYPE_USE";
             default:
                 return "unknown target";
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/2d1391d7/src/main/org/codehaus/groovy/ast/decompiled/Annotations.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/decompiled/Annotations.java b/src/main/org/codehaus/groovy/ast/decompiled/Annotations.java
index ce64070..15c0a22 100644
--- a/src/main/org/codehaus/groovy/ast/decompiled/Annotations.java
+++ b/src/main/org/codehaus/groovy/ast/decompiled/Annotations.java
@@ -21,6 +21,7 @@ package org.codehaus.groovy.ast.decompiled;
 import org.codehaus.groovy.ast.AnnotationNode;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.expr.*;
+import org.codehaus.groovy.vmplugin.VMPluginFactory;
 import org.codehaus.groovy.vmplugin.v5.Java5;
 import org.objectweb.asm.Type;
 
@@ -97,9 +98,8 @@ class Annotations {
             synchronized (initLock) {
                 if (!lazyInitDone) {
                     for (AnnotationNode annotation : getClassNode().getAnnotations()) {
-                        Java5.configureAnnotationFromDefinition(annotation, this);
+                        VMPluginFactory.getPlugin().configureAnnotationNodeFromDefinition(annotation, this);
                     }
-
                     lazyInitDone = true;
                 }
             }

http://git-wip-us.apache.org/repos/asf/groovy/blob/2d1391d7/src/main/org/codehaus/groovy/vmplugin/VMPlugin.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/vmplugin/VMPlugin.java b/src/main/org/codehaus/groovy/vmplugin/VMPlugin.java
index 3ca6bdd..d139307 100644
--- a/src/main/org/codehaus/groovy/vmplugin/VMPlugin.java
+++ b/src/main/org/codehaus/groovy/vmplugin/VMPlugin.java
@@ -32,6 +32,7 @@ public interface VMPlugin {
     void setAdditionalClassInformation(ClassNode c);
     Class[] getPluginDefaultGroovyMethods();
     Class[] getPluginStaticGroovyMethods();
+    void configureAnnotationNodeFromDefinition(AnnotationNode definition, AnnotationNode root);
     void configureAnnotation(AnnotationNode an);
     void configureClassNode(CompileUnit compileUnit, ClassNode classNode);
     void invalidateCallSites();
@@ -54,8 +55,8 @@ public interface VMPlugin {
     Object invokeHandle(Object handle, Object[] args) throws Throwable;
 
     /**
-     * Gives the version the plguin is made for
-     * @return 5 for jdk5, 6 for jdk6, 7 for jdk7 or higher
+     * Gives the version the plugin is made for
+     * @return 5 for jdk5, 6 for jdk6, 7 for jdk7, 8 for jdk8 or higher
      */
     int getVersion();
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/2d1391d7/src/main/org/codehaus/groovy/vmplugin/v5/Java5.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/vmplugin/v5/Java5.java b/src/main/org/codehaus/groovy/vmplugin/v5/Java5.java
index 4e9359b..8e4fe7f 100644
--- a/src/main/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -36,6 +36,7 @@ import org.codehaus.groovy.ast.expr.ListExpression;
 import org.codehaus.groovy.ast.expr.PropertyExpression;
 import org.codehaus.groovy.ast.stmt.ReturnStatement;
 import org.codehaus.groovy.vmplugin.VMPlugin;
+import org.codehaus.groovy.vmplugin.VMPluginFactory;
 
 import java.lang.annotation.Annotation;
 import java.lang.annotation.ElementType;
@@ -211,7 +212,12 @@ public class Java5 implements VMPlugin {
         }
     }
 
+    @Deprecated
     public static void configureAnnotationFromDefinition(AnnotationNode definition, AnnotationNode root) {
+        VMPluginFactory.getPlugin().configureAnnotationNodeFromDefinition(definition, root);
+    }
+
+    public void configureAnnotationNodeFromDefinition(AnnotationNode definition, AnnotationNode root) {
         ClassNode type = definition.getClassNode();
         if ("java.lang.annotation.Retention".equals(type.getName())) {
             Expression exp = definition.getMember("value");
@@ -318,7 +324,7 @@ public class Java5 implements VMPlugin {
         }
     }
 
-    private static int getElementCode(ElementType value) {
+    protected int getElementCode(ElementType value) {
         switch (value) {
             case TYPE:
                 return AnnotationNode.TYPE_TARGET;

http://git-wip-us.apache.org/repos/asf/groovy/blob/2d1391d7/src/main/org/codehaus/groovy/vmplugin/vm8/Java8.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/vmplugin/vm8/Java8.java b/src/main/org/codehaus/groovy/vmplugin/vm8/Java8.java
index 905af38..4656af1 100644
--- a/src/main/org/codehaus/groovy/vmplugin/vm8/Java8.java
+++ b/src/main/org/codehaus/groovy/vmplugin/vm8/Java8.java
@@ -18,8 +18,10 @@
  */
 package org.codehaus.groovy.vmplugin.vm8;
 
+import org.codehaus.groovy.ast.AnnotationNode;
 import org.codehaus.groovy.vmplugin.v7.Java7;
 
+import java.lang.annotation.ElementType;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -51,4 +53,14 @@ public class Java8 extends Java7 {
         return 8;
     }
 
+    @Override
+    protected int getElementCode(ElementType value) {
+        switch (value) {
+            case TYPE_PARAMETER:
+                return AnnotationNode.TYPE_PARAMETER_TARGET;
+            case TYPE_USE:
+                return AnnotationNode.TYPE_USE_TARGET;
+        }
+        return super.getElementCode(value);
+    }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/2d1391d7/src/test/gls/annotations/AnnotationTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/annotations/AnnotationTest.groovy b/src/test/gls/annotations/AnnotationTest.groovy
index a63e0bd..80e4242 100644
--- a/src/test/gls/annotations/AnnotationTest.groovy
+++ b/src/test/gls/annotations/AnnotationTest.groovy
@@ -678,6 +678,32 @@ class AnnotationTest extends CompilableTestSupport {
         '''
     }
 
+    // GROOVY-8226
+    void testAnnotationOnParameterType() {
+        assertScript '''
+            import java.lang.annotation.*
+            import static java.lang.annotation.ElementType.*
+            import static java.lang.annotation.RetentionPolicy.*
+
+            @Target([PARAMETER, FIELD, METHOD, ANNOTATION_TYPE, TYPE_USE])
+            @Retention(RUNTIME)
+            public @interface NonNull { }
+
+            class Foo {
+              @NonNull public Integer foo
+              @NonNull public Integer bar(@NonNull String baz) {}
+            }
+
+            def expected = '@NonNull()'
+            def foo = Foo.getField('foo')
+            assert foo.annotations[0].toString() == expected
+            def bar = Foo.getMethod('bar', String)
+            assert bar.annotations[0].toString() == expected
+            def baz = bar.parameters[0]
+            assert baz.annotations[0].toString() == expected
+        '''
+    }
+
     //Parametrized tests in Spock would allow to make it much more readable
     private static String codeWithMetaAnnotationWithTarget(String targetElementTypeName) {
         """


[2/2] groovy git commit: trivial refactor

Posted by pa...@apache.org.
trivial refactor


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

Branch: refs/heads/GROOVY_2_6_X
Commit: a0b4e850c18e16b488ee3cdb2d42bbd4dd9b8b54
Parents: 5e6c850
Author: paulk <pa...@asert.com.au>
Authored: Sun Jun 18 20:30:56 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Jun 19 16:05:57 2017 +1000

----------------------------------------------------------------------
 src/main/groovy/transform/AutoExternalize.groovy | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/a0b4e850/src/main/groovy/transform/AutoExternalize.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/AutoExternalize.groovy b/src/main/groovy/transform/AutoExternalize.groovy
index f8e59ff..d1356b9 100644
--- a/src/main/groovy/transform/AutoExternalize.groovy
+++ b/src/main/groovy/transform/AutoExternalize.groovy
@@ -16,7 +16,7 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package groovy.transform;
+package groovy.transform
 
 /**
  * Class annotation used to assist in the creation of {@code Externalizable} classes.
@@ -60,7 +60,6 @@ package groovy.transform;
  * <p>
  * The {@code @AutoExternalize} transform is implemented as a combination of the {@code @ExternalizeMethods} and {@code @ExternalizeVerifier} transforms.
  *
- * @author Paul King
  * @since 1.8.0
  */
 @AnnotationCollector([ExternalizeMethods, ExternalizeVerifier])