groovy git commit: GROOVY-7956: Provide an AST transformation which improves named parameter support (doco and support changing visibility)
Repository: groovy Updated Branches: refs/heads/master 965bd6ee3 -> 0110400db GROOVY-7956: Provide an AST transformation which improves named parameter support (doco and support changing visibility) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/0110400d Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/0110400d Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/0110400d Branch: refs/heads/master Commit: 0110400dbb637e19755c39e21a3cfd74e777b872 Parents: 965bd6e Author: paulkAuthored: Wed Feb 21 18:18:17 2018 +1000 Committer: paulk Committed: Wed Feb 21 18:19:51 2018 +1000 -- .../groovy/groovy/transform/NamedVariant.java | 63 +++ .../groovy/transform/VisibilityOptions.java | 43 .../groovy/transform/options/Visibility.java| 27 + .../groovy/ast/tools/VisibilityUtils.java | 110 +++ .../NamedVariantASTTransformation.java | 6 +- .../transform/NamedVariantTransformTest.groovy | 32 +++--- 6 files changed, 265 insertions(+), 16 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/0110400d/src/main/groovy/groovy/transform/NamedVariant.java -- diff --git a/src/main/groovy/groovy/transform/NamedVariant.java b/src/main/groovy/groovy/transform/NamedVariant.java index 8db0529..2a10470 100644 --- a/src/main/groovy/groovy/transform/NamedVariant.java +++ b/src/main/groovy/groovy/transform/NamedVariant.java @@ -26,9 +26,72 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Allows construction of a named-arg equivalent method or constructor. + * The method or constructor will have at least a first argument of type + * {@code Map} and may have more arguments. As such, it can be called + * using Groovy's named-arg syntax. The original method/constructor is retained + * and is called by the generated method/constructor. + * + * One benefit of this approach is the potential for improved type checking. + * The annotated "tuple" method/constructor can be type rich and will be checked + * as such during normal compilation. The generated method/constructor using + * the map argument will be named-argument friendly but the map also hides + * type information. The generated method however contains no business logic + * so the chance of errors is minimal. + * + * Any arguments identified as named arguments will be supplied as + * part of the map. Any additional arguments are supplied in the normal + * tuple style. + * + * Named arguments are identified in one of three ways: + * + * Use one or more {@code @NamedParam} annotations to explicitly identify such arguments + * Use one or more {@code @NamedDelegate} annotations to explicitly identify such arguments as + * delegate arguments + * If no arguments with {@code @NamedParam} or {@code @NamedDelegate} annotations are found the + * first argument is assumed to be an implicit named delegate + * + * Named arguments will be supplied via the map with their property name (configurable via + * annotation attributes within {@code @NamedParam}) being the key and value being the argument value. + * For named delegates, any properties of the delegate can become map keys. Duplicate keys across + * delegates or named parameters are not allowed. Delegate arguments must be + * compatible with Groovy's {@code as} cast operation from a {@code Map}. + * + * Here is an example using the implicit delegate approach. + * + * import groovy.transform.* + * + * {@code @ToString(includeNames=true, includeFields=true)} + * class Color { + * Integer r, g, b + * } + * + * {@code @NamedVariant} + * String foo(Color shade) { + * shade + * } + * + * def result = foo(g: 12, b: 42, r: 12) + * assert result.toString() == 'Color(r:12, g:12, b:42)' + * + * The generated method will be something like this: + * + * String foo(Map args) { + * return foo(args as Color) + * } + * + * The generated method/constructor retains the visibility and return type of the original + * but the {@code @VisibilityOptions} annotation can be added to the visibility. You could have the + * annotated method/constructor private for instance but have the generated one be public. + */ @Incubating @Retention(RetentionPolicy.SOURCE) @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) @GroovyASTTransformationClass("org.codehaus.groovy.transform.NamedVariantASTTransformation") public @interface NamedVariant { +/** + * If specified, must match the "id" attribute in the VisibilityOptions annotation. + */ +String visibilityId() default Undefined.STRING; } \ No newline
groovy git commit: GROOVY-7956: Provide an AST transformation which improves named parameter support (doco and support changing visibility)
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X 5ad98acc2 -> 17d3feb31 GROOVY-7956: Provide an AST transformation which improves named parameter support (doco and support changing visibility) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/17d3feb3 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/17d3feb3 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/17d3feb3 Branch: refs/heads/GROOVY_2_6_X Commit: 17d3feb3180d570113883281d3c513bebae3cfbb Parents: 5ad98ac Author: paulkAuthored: Wed Feb 21 18:18:17 2018 +1000 Committer: paulk Committed: Wed Feb 21 18:19:17 2018 +1000 -- .../groovy/groovy/transform/NamedVariant.java | 63 +++ .../groovy/transform/VisibilityOptions.java | 43 .../groovy/transform/options/Visibility.java| 27 + .../groovy/ast/tools/VisibilityUtils.java | 110 +++ .../NamedVariantASTTransformation.java | 6 +- .../transform/NamedVariantTransformTest.groovy | 32 +++--- 6 files changed, 265 insertions(+), 16 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/17d3feb3/src/main/groovy/groovy/transform/NamedVariant.java -- diff --git a/src/main/groovy/groovy/transform/NamedVariant.java b/src/main/groovy/groovy/transform/NamedVariant.java index 8db0529..2a10470 100644 --- a/src/main/groovy/groovy/transform/NamedVariant.java +++ b/src/main/groovy/groovy/transform/NamedVariant.java @@ -26,9 +26,72 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Allows construction of a named-arg equivalent method or constructor. + * The method or constructor will have at least a first argument of type + * {@code Map} and may have more arguments. As such, it can be called + * using Groovy's named-arg syntax. The original method/constructor is retained + * and is called by the generated method/constructor. + * + * One benefit of this approach is the potential for improved type checking. + * The annotated "tuple" method/constructor can be type rich and will be checked + * as such during normal compilation. The generated method/constructor using + * the map argument will be named-argument friendly but the map also hides + * type information. The generated method however contains no business logic + * so the chance of errors is minimal. + * + * Any arguments identified as named arguments will be supplied as + * part of the map. Any additional arguments are supplied in the normal + * tuple style. + * + * Named arguments are identified in one of three ways: + * + * Use one or more {@code @NamedParam} annotations to explicitly identify such arguments + * Use one or more {@code @NamedDelegate} annotations to explicitly identify such arguments as + * delegate arguments + * If no arguments with {@code @NamedParam} or {@code @NamedDelegate} annotations are found the + * first argument is assumed to be an implicit named delegate + * + * Named arguments will be supplied via the map with their property name (configurable via + * annotation attributes within {@code @NamedParam}) being the key and value being the argument value. + * For named delegates, any properties of the delegate can become map keys. Duplicate keys across + * delegates or named parameters are not allowed. Delegate arguments must be + * compatible with Groovy's {@code as} cast operation from a {@code Map}. + * + * Here is an example using the implicit delegate approach. + * + * import groovy.transform.* + * + * {@code @ToString(includeNames=true, includeFields=true)} + * class Color { + * Integer r, g, b + * } + * + * {@code @NamedVariant} + * String foo(Color shade) { + * shade + * } + * + * def result = foo(g: 12, b: 42, r: 12) + * assert result.toString() == 'Color(r:12, g:12, b:42)' + * + * The generated method will be something like this: + * + * String foo(Map args) { + * return foo(args as Color) + * } + * + * The generated method/constructor retains the visibility and return type of the original + * but the {@code @VisibilityOptions} annotation can be added to the visibility. You could have the + * annotated method/constructor private for instance but have the generated one be public. + */ @Incubating @Retention(RetentionPolicy.SOURCE) @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) @GroovyASTTransformationClass("org.codehaus.groovy.transform.NamedVariantASTTransformation") public @interface NamedVariant { +/** + * If specified, must match the "id" attribute in the VisibilityOptions annotation. + */ +String visibilityId() default Undefined.STRING; } \
groovy git commit: GROOVY-7956: Provide an AST transformation which improves named parameter support (doco and support changing visibility)
Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X d11d56425 -> 488f42dd1 GROOVY-7956: Provide an AST transformation which improves named parameter support (doco and support changing visibility) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/488f42dd Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/488f42dd Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/488f42dd Branch: refs/heads/GROOVY_2_5_X Commit: 488f42dd182c530a1f8762b6191277c7ec184727 Parents: d11d564 Author: paulkAuthored: Wed Feb 21 18:18:17 2018 +1000 Committer: paulk Committed: Wed Feb 21 18:18:17 2018 +1000 -- .../groovy/groovy/transform/NamedVariant.java | 63 +++ .../groovy/transform/VisibilityOptions.java | 43 .../groovy/transform/options/Visibility.java| 27 + .../groovy/ast/tools/VisibilityUtils.java | 110 +++ .../NamedVariantASTTransformation.java | 6 +- .../transform/NamedVariantTransformTest.groovy | 32 +++--- 6 files changed, 265 insertions(+), 16 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/488f42dd/src/main/groovy/groovy/transform/NamedVariant.java -- diff --git a/src/main/groovy/groovy/transform/NamedVariant.java b/src/main/groovy/groovy/transform/NamedVariant.java index 8db0529..2a10470 100644 --- a/src/main/groovy/groovy/transform/NamedVariant.java +++ b/src/main/groovy/groovy/transform/NamedVariant.java @@ -26,9 +26,72 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Allows construction of a named-arg equivalent method or constructor. + * The method or constructor will have at least a first argument of type + * {@code Map} and may have more arguments. As such, it can be called + * using Groovy's named-arg syntax. The original method/constructor is retained + * and is called by the generated method/constructor. + * + * One benefit of this approach is the potential for improved type checking. + * The annotated "tuple" method/constructor can be type rich and will be checked + * as such during normal compilation. The generated method/constructor using + * the map argument will be named-argument friendly but the map also hides + * type information. The generated method however contains no business logic + * so the chance of errors is minimal. + * + * Any arguments identified as named arguments will be supplied as + * part of the map. Any additional arguments are supplied in the normal + * tuple style. + * + * Named arguments are identified in one of three ways: + * + * Use one or more {@code @NamedParam} annotations to explicitly identify such arguments + * Use one or more {@code @NamedDelegate} annotations to explicitly identify such arguments as + * delegate arguments + * If no arguments with {@code @NamedParam} or {@code @NamedDelegate} annotations are found the + * first argument is assumed to be an implicit named delegate + * + * Named arguments will be supplied via the map with their property name (configurable via + * annotation attributes within {@code @NamedParam}) being the key and value being the argument value. + * For named delegates, any properties of the delegate can become map keys. Duplicate keys across + * delegates or named parameters are not allowed. Delegate arguments must be + * compatible with Groovy's {@code as} cast operation from a {@code Map}. + * + * Here is an example using the implicit delegate approach. + * + * import groovy.transform.* + * + * {@code @ToString(includeNames=true, includeFields=true)} + * class Color { + * Integer r, g, b + * } + * + * {@code @NamedVariant} + * String foo(Color shade) { + * shade + * } + * + * def result = foo(g: 12, b: 42, r: 12) + * assert result.toString() == 'Color(r:12, g:12, b:42)' + * + * The generated method will be something like this: + * + * String foo(Map args) { + * return foo(args as Color) + * } + * + * The generated method/constructor retains the visibility and return type of the original + * but the {@code @VisibilityOptions} annotation can be added to the visibility. You could have the + * annotated method/constructor private for instance but have the generated one be public. + */ @Incubating @Retention(RetentionPolicy.SOURCE) @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) @GroovyASTTransformationClass("org.codehaus.groovy.transform.NamedVariantASTTransformation") public @interface NamedVariant { +/** + * If specified, must match the "id" attribute in the VisibilityOptions annotation. + */ +String visibilityId() default Undefined.STRING; } \
groovy git commit: GROOVY-7956: Provide an AST transformation which improves named parameter support (JDK 7 compatibility)
Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X c7ea252c7 -> 19565fcf0 GROOVY-7956: Provide an AST transformation which improves named parameter support (JDK 7 compatibility) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/19565fcf Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/19565fcf Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/19565fcf Branch: refs/heads/GROOVY_2_5_X Commit: 19565fcf0ddb8e1186a1d248a5a12f70508ff6cf Parents: c7ea252 Author: paulkAuthored: Tue Feb 20 13:30:58 2018 +1000 Committer: paulk Committed: Tue Feb 20 13:31:46 2018 +1000 -- src/main/groovy/groovy/transform/NamedParam.java | 2 -- 1 file changed, 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/19565fcf/src/main/groovy/groovy/transform/NamedParam.java -- diff --git a/src/main/groovy/groovy/transform/NamedParam.java b/src/main/groovy/groovy/transform/NamedParam.java index 856e3e2..661397e 100644 --- a/src/main/groovy/groovy/transform/NamedParam.java +++ b/src/main/groovy/groovy/transform/NamedParam.java @@ -19,14 +19,12 @@ package groovy.transform; 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.PARAMETER) -@Repeatable(NamedParams.class) public @interface NamedParam { String value(); Class type() default Object.class;
groovy git commit: GROOVY-7956: Provide an AST transformation which improves named parameter support (JDK 7 compatibility)
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X 4e6f3cc71 -> 7262d023e GROOVY-7956: Provide an AST transformation which improves named parameter support (JDK 7 compatibility) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7262d023 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7262d023 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7262d023 Branch: refs/heads/GROOVY_2_6_X Commit: 7262d023ee445b233d22312b7513b5761b0f64d8 Parents: 4e6f3cc Author: paulkAuthored: Tue Feb 20 13:30:58 2018 +1000 Committer: paulk Committed: Tue Feb 20 13:30:58 2018 +1000 -- src/main/groovy/groovy/transform/NamedParam.java | 2 -- 1 file changed, 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/7262d023/src/main/groovy/groovy/transform/NamedParam.java -- diff --git a/src/main/groovy/groovy/transform/NamedParam.java b/src/main/groovy/groovy/transform/NamedParam.java index 856e3e2..661397e 100644 --- a/src/main/groovy/groovy/transform/NamedParam.java +++ b/src/main/groovy/groovy/transform/NamedParam.java @@ -19,14 +19,12 @@ package groovy.transform; 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.PARAMETER) -@Repeatable(NamedParams.class) public @interface NamedParam { String value(); Class type() default Object.class;
groovy git commit: GROOVY-7956: Provide an AST transformation which improves named parameter support
Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X ab7d39a17 -> c7ea252c7 GROOVY-7956: Provide an AST transformation which improves named parameter support Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/c7ea252c Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/c7ea252c Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/c7ea252c Branch: refs/heads/GROOVY_2_5_X Commit: c7ea252c7804fe252182e4d837f9f4b2264a0c1f Parents: ab7d39a Author: paulkAuthored: Tue Feb 20 10:09:59 2018 +1000 Committer: paulk Committed: Tue Feb 20 12:34:02 2018 +1000 -- .../groovy/groovy/transform/NamedDelegate.java | 29 +++ .../groovy/groovy/transform/NamedParam.java | 34 +++ .../groovy/groovy/transform/NamedParams.java| 30 +++ .../groovy/groovy/transform/NamedVariant.java | 34 +++ .../codehaus/groovy/ast/tools/GeneralUtils.java | 4 + .../transform/AbstractASTTransformation.java| 4 +- .../NamedVariantASTTransformation.java | 223 +++ .../transform/NamedVariantTransformTest.groovy | 124 +++ 8 files changed, 480 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/c7ea252c/src/main/groovy/groovy/transform/NamedDelegate.java -- diff --git a/src/main/groovy/groovy/transform/NamedDelegate.java b/src/main/groovy/groovy/transform/NamedDelegate.java new file mode 100644 index 000..baf54ff --- /dev/null +++ b/src/main/groovy/groovy/transform/NamedDelegate.java @@ -0,0 +1,29 @@ +/* + * 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 groovy.transform; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.PARAMETER) +public @interface NamedDelegate { +} http://git-wip-us.apache.org/repos/asf/groovy/blob/c7ea252c/src/main/groovy/groovy/transform/NamedParam.java -- diff --git a/src/main/groovy/groovy/transform/NamedParam.java b/src/main/groovy/groovy/transform/NamedParam.java new file mode 100644 index 000..856e3e2 --- /dev/null +++ b/src/main/groovy/groovy/transform/NamedParam.java @@ -0,0 +1,34 @@ +/* + * 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 groovy.transform; + +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.PARAMETER) +@Repeatable(NamedParams.class) +public @interface NamedParam { +String value(); +Class type() default Object.class; +boolean required() default false; +} http://git-wip-us.apache.org/repos/asf/groovy/blob/c7ea252c/src/main/groovy/groovy/transform/NamedParams.java -- diff --git a/src/main/groovy/groovy/transform/NamedParams.java b/src/main/groovy/groovy/transform/NamedParams.java new
groovy git commit: GROOVY-7956: Provide an AST transformation which improves named parameter support
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X 77dde9ced -> 4e6f3cc71 GROOVY-7956: Provide an AST transformation which improves named parameter support Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/4e6f3cc7 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/4e6f3cc7 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/4e6f3cc7 Branch: refs/heads/GROOVY_2_6_X Commit: 4e6f3cc71c725ec781bce607ca7f2640c0c3193b Parents: 77dde9c Author: paulkAuthored: Tue Feb 20 10:09:59 2018 +1000 Committer: paulk Committed: Tue Feb 20 12:33:07 2018 +1000 -- .../groovy/groovy/transform/NamedDelegate.java | 29 +++ .../groovy/groovy/transform/NamedParam.java | 34 +++ .../groovy/groovy/transform/NamedParams.java| 30 +++ .../groovy/groovy/transform/NamedVariant.java | 34 +++ .../codehaus/groovy/ast/tools/GeneralUtils.java | 4 + .../transform/AbstractASTTransformation.java| 4 +- .../NamedVariantASTTransformation.java | 223 +++ .../transform/NamedVariantTransformTest.groovy | 124 +++ 8 files changed, 480 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/4e6f3cc7/src/main/groovy/groovy/transform/NamedDelegate.java -- diff --git a/src/main/groovy/groovy/transform/NamedDelegate.java b/src/main/groovy/groovy/transform/NamedDelegate.java new file mode 100644 index 000..baf54ff --- /dev/null +++ b/src/main/groovy/groovy/transform/NamedDelegate.java @@ -0,0 +1,29 @@ +/* + * 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 groovy.transform; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.PARAMETER) +public @interface NamedDelegate { +} http://git-wip-us.apache.org/repos/asf/groovy/blob/4e6f3cc7/src/main/groovy/groovy/transform/NamedParam.java -- diff --git a/src/main/groovy/groovy/transform/NamedParam.java b/src/main/groovy/groovy/transform/NamedParam.java new file mode 100644 index 000..856e3e2 --- /dev/null +++ b/src/main/groovy/groovy/transform/NamedParam.java @@ -0,0 +1,34 @@ +/* + * 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 groovy.transform; + +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.PARAMETER) +@Repeatable(NamedParams.class) +public @interface NamedParam { +String value(); +Class type() default Object.class; +boolean required() default false; +} http://git-wip-us.apache.org/repos/asf/groovy/blob/4e6f3cc7/src/main/groovy/groovy/transform/NamedParams.java -- diff --git a/src/main/groovy/groovy/transform/NamedParams.java b/src/main/groovy/groovy/transform/NamedParams.java new
groovy git commit: GROOVY-7956: Provide an AST transformation which improves named parameter support
Repository: groovy Updated Branches: refs/heads/master fc01573ff -> 43f2c8e47 GROOVY-7956: Provide an AST transformation which improves named parameter support Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/43f2c8e4 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/43f2c8e4 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/43f2c8e4 Branch: refs/heads/master Commit: 43f2c8e47b2072e2c0e42097c4462180af30efdb Parents: fc01573 Author: paulkAuthored: Tue Feb 20 10:09:59 2018 +1000 Committer: paulk Committed: Tue Feb 20 11:17:23 2018 +1000 -- .../groovy/groovy/transform/NamedDelegate.java | 29 +++ .../groovy/groovy/transform/NamedParam.java | 34 +++ .../groovy/groovy/transform/NamedParams.java| 30 +++ .../groovy/groovy/transform/NamedVariant.java | 34 +++ .../codehaus/groovy/ast/tools/GeneralUtils.java | 4 + .../transform/AbstractASTTransformation.java| 4 +- .../NamedVariantASTTransformation.java | 223 +++ .../transform/NamedVariantTransformTest.groovy | 124 +++ 8 files changed, 480 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/43f2c8e4/src/main/groovy/groovy/transform/NamedDelegate.java -- diff --git a/src/main/groovy/groovy/transform/NamedDelegate.java b/src/main/groovy/groovy/transform/NamedDelegate.java new file mode 100644 index 000..baf54ff --- /dev/null +++ b/src/main/groovy/groovy/transform/NamedDelegate.java @@ -0,0 +1,29 @@ +/* + * 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 groovy.transform; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.PARAMETER) +public @interface NamedDelegate { +} http://git-wip-us.apache.org/repos/asf/groovy/blob/43f2c8e4/src/main/groovy/groovy/transform/NamedParam.java -- diff --git a/src/main/groovy/groovy/transform/NamedParam.java b/src/main/groovy/groovy/transform/NamedParam.java new file mode 100644 index 000..856e3e2 --- /dev/null +++ b/src/main/groovy/groovy/transform/NamedParam.java @@ -0,0 +1,34 @@ +/* + * 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 groovy.transform; + +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.PARAMETER) +@Repeatable(NamedParams.class) +public @interface NamedParam { +String value(); +Class type() default Object.class; +boolean required() default false; +} http://git-wip-us.apache.org/repos/asf/groovy/blob/43f2c8e4/src/main/groovy/groovy/transform/NamedParams.java -- diff --git a/src/main/groovy/groovy/transform/NamedParams.java b/src/main/groovy/groovy/transform/NamedParams.java new file mode