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 2018/04/25 23:54:07 UTC

groovy git commit: GROOVY-8559: CLONE - Add @Repeatable java8 annotation support (jdk7 compatibility)

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 3fb321d63 -> 3e21f8b60


GROOVY-8559: CLONE - Add @Repeatable java8 annotation support (jdk7 compatibility)


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

Branch: refs/heads/GROOVY_2_5_X
Commit: 3e21f8b60dcff498d41445c814b7f9c53c089532
Parents: 3fb321d
Author: Paul King <pa...@asert.com.au>
Authored: Thu Apr 26 09:53:47 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Thu Apr 26 09:53:47 2018 +1000

----------------------------------------------------------------------
 src/test/gls/annotations/AnnotationTest.groovy  | 39 ------------
 src/test/gls/annotations/Require.java           | 32 ----------
 src/test/gls/annotations/Requires.java          | 30 ---------
 subprojects/tests-vm8/build.gradle              |  7 +++
 .../tests-vm8/src/main/java/vm8/Require.java    | 32 ++++++++++
 .../tests-vm8/src/main/java/vm8/Requires.java   | 30 +++++++++
 .../gls/annotations/vm8/AnnotationTest.groovy   | 66 ++++++++++++++++++++
 7 files changed, 135 insertions(+), 101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/3e21f8b6/src/test/gls/annotations/AnnotationTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/annotations/AnnotationTest.groovy b/src/test/gls/annotations/AnnotationTest.groovy
index 689048d..504f0e8 100644
--- a/src/test/gls/annotations/AnnotationTest.groovy
+++ b/src/test/gls/annotations/AnnotationTest.groovy
@@ -753,45 +753,6 @@ class AnnotationTest extends CompilableTestSupport {
         '''
     }
 
-    void testAnnotationWithRepeatableSupportedPrecompiledJava() {
-        assertScript '''
-            import java.lang.annotation.*
-            import gls.annotations.*
-
-            class MyClass {
-                // TODO confirm the JDK9 behavior is what we expect
-                private static final List<String> expected = [
-                    '@gls.annotations.Requires(value=[@gls.annotations.Require(value=val1), @gls.annotations.Require(value=val2)])',    // JDK5-8
-                    '@gls.annotations.Requires(value={@gls.annotations.Require(value="val1"), @gls.annotations.Require(value="val2")})' // JDK9
-                ]
-
-                // control
-                @Requires([@Require("val1"), @Require("val2")])
-                String method1() { 'method1' }
-
-                // duplicate candidate for auto collection
-                @Require(value = "val1")
-                @Require(value = "val2")
-                String method2() { 'method2' }
-
-                static void main(String... args) {
-                    MyClass myc = new MyClass()
-                    assert 'method1' == myc.method1()
-                    assert 'method2' == myc.method2()
-                    assert expected.contains(checkAnnos(myc, "method1"))
-                    assert expected.contains(checkAnnos(myc, "method2"))
-                }
-
-                private static String checkAnnos(MyClass myc, String name) {
-                    def m = myc.getClass().getMethod(name)
-                    List annos = m.getAnnotations()
-                    assert annos.size() == 1
-                    annos[0].toString()
-                }
-            }
-        '''
-    }
-
     //Parametrized tests in Spock would allow to make it much more readable
     private static String codeWithMetaAnnotationWithTarget(String targetElementTypeName) {
         """

http://git-wip-us.apache.org/repos/asf/groovy/blob/3e21f8b6/src/test/gls/annotations/Require.java
----------------------------------------------------------------------
diff --git a/src/test/gls/annotations/Require.java b/src/test/gls/annotations/Require.java
deleted file mode 100644
index 7d51cf2..0000000
--- a/src/test/gls/annotations/Require.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- *  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 gls.annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Repeatable;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-@Repeatable(Requires.class)
-public @interface Require {
-    String value() default "";
-}

http://git-wip-us.apache.org/repos/asf/groovy/blob/3e21f8b6/src/test/gls/annotations/Requires.java
----------------------------------------------------------------------
diff --git a/src/test/gls/annotations/Requires.java b/src/test/gls/annotations/Requires.java
deleted file mode 100644
index b828a59..0000000
--- a/src/test/gls/annotations/Requires.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *  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 gls.annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface Requires {
-    Require[] value();
-}

http://git-wip-us.apache.org/repos/asf/groovy/blob/3e21f8b6/subprojects/tests-vm8/build.gradle
----------------------------------------------------------------------
diff --git a/subprojects/tests-vm8/build.gradle b/subprojects/tests-vm8/build.gradle
index 9569173..f5c054c 100644
--- a/subprojects/tests-vm8/build.gradle
+++ b/subprojects/tests-vm8/build.gradle
@@ -32,6 +32,13 @@ tasks.withType(GroovyCompile) {
 }
 
 sourceSets {
+    main {
+        java {
+            if (!JavaVersion.current().isJava8Compatible()) {
+                exclude '**/vm8/*'
+            }
+        }
+    }
     test {
         java {
             if (!JavaVersion.current().isJava8Compatible()) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/3e21f8b6/subprojects/tests-vm8/src/main/java/vm8/Require.java
----------------------------------------------------------------------
diff --git a/subprojects/tests-vm8/src/main/java/vm8/Require.java b/subprojects/tests-vm8/src/main/java/vm8/Require.java
new file mode 100644
index 0000000..455c3f8
--- /dev/null
+++ b/subprojects/tests-vm8/src/main/java/vm8/Require.java
@@ -0,0 +1,32 @@
+/*
+ *  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 vm8;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Repeatable;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.METHOD})
+@Repeatable(Requires.class)
+public @interface Require {
+    String value() default "";
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/3e21f8b6/subprojects/tests-vm8/src/main/java/vm8/Requires.java
----------------------------------------------------------------------
diff --git a/subprojects/tests-vm8/src/main/java/vm8/Requires.java b/subprojects/tests-vm8/src/main/java/vm8/Requires.java
new file mode 100644
index 0000000..cb5904a
--- /dev/null
+++ b/subprojects/tests-vm8/src/main/java/vm8/Requires.java
@@ -0,0 +1,30 @@
+/*
+ *  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 vm8;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.METHOD})
+public @interface Requires {
+    Require[] value();
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/3e21f8b6/subprojects/tests-vm8/src/test/groovy/gls/annotations/vm8/AnnotationTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/tests-vm8/src/test/groovy/gls/annotations/vm8/AnnotationTest.groovy b/subprojects/tests-vm8/src/test/groovy/gls/annotations/vm8/AnnotationTest.groovy
new file mode 100644
index 0000000..8d99d61
--- /dev/null
+++ b/subprojects/tests-vm8/src/test/groovy/gls/annotations/vm8/AnnotationTest.groovy
@@ -0,0 +1,66 @@
+/*
+ *  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 gls.annotations.vm8
+
+import gls.CompilableTestSupport
+
+/**
+ * Tests various properties of annotation definitions.
+ */
+class AnnotationTest extends CompilableTestSupport {
+
+    void testAnnotationWithRepeatableSupportedPrecompiledJava() {
+        assertScript '''
+            import java.lang.annotation.*
+            import vm8.*
+
+            class MyClass {
+                // TODO confirm the JDK9 behavior is what we expect
+                private static final List<String> expected = [
+                    '@Requires(value=[@Require(value=val1), @Require(value=val2)])',    // JDK5-8
+                    '@Requires(value={@Require(value="val1"), @Require(value="val2")})' // JDK9
+                ]
+
+                // control
+                @Requires([@Require("val1"), @Require("val2")])
+                String method1() { 'method1' }
+
+                // duplicate candidate for auto collection
+                @Require(value = "val1")
+                @Require(value = "val2")
+                String method2() { 'method2' }
+
+                static void main(String... args) {
+                    MyClass myc = new MyClass()
+                    assert 'method1' == myc.method1()
+                    assert 'method2' == myc.method2()
+                    assert expected.contains(checkAnnos(myc, "method1"))
+                    assert expected.contains(checkAnnos(myc, "method2"))
+                }
+
+                private static String checkAnnos(MyClass myc, String name) {
+                    def m = myc.getClass().getMethod(name)
+                    List annos = m.getAnnotations()
+                    assert annos.size() == 1
+                    annos[0].toString()
+                }
+            }
+        '''
+    }
+}