[4/5] groovy git commit: GROOVY-8440: Groovy's @Immutable annotation should be re-vamped to be a meta-annotation (additional refactoring to remove dup and plumb in pre/post conditions)
GROOVY-8440: Groovy's @Immutable annotation should be re-vamped to be a meta-annotation (additional refactoring to remove dup and plumb in pre/post conditions) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/5237bbe5 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/5237bbe5 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/5237bbe5 Branch: refs/heads/GROOVY_2_6_X Commit: 5237bbe578cc7a34997981c2ff38218df61270f7 Parents: 8cd0820 Author: paulkAuthored: Wed Jan 31 11:19:57 2018 +1000 Committer: paulk Committed: Wed Jan 31 22:40:32 2018 +1000 -- .../groovy/classgen/EnumCompletionVisitor.java | 8 +- .../transform/ImmutableASTTransformation.java | 136 --- .../MapConstructorASTTransformation.java| 25 ++-- .../TupleConstructorASTTransformation.java | 75 +- 4 files changed, 141 insertions(+), 103 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/5237bbe5/src/main/java/org/codehaus/groovy/classgen/EnumCompletionVisitor.java -- diff --git a/src/main/java/org/codehaus/groovy/classgen/EnumCompletionVisitor.java b/src/main/java/org/codehaus/groovy/classgen/EnumCompletionVisitor.java index 30c6fab..7cc5375 100644 --- a/src/main/java/org/codehaus/groovy/classgen/EnumCompletionVisitor.java +++ b/src/main/java/org/codehaus/groovy/classgen/EnumCompletionVisitor.java @@ -82,7 +82,7 @@ public class EnumCompletionVisitor extends ClassCodeVisitorSupport { ClassNode sn = enumClass.getSuperClass(); List sctors = new ArrayList(sn.getDeclaredConstructors()); if (sctors.isEmpty()) { -addMapConstructors(enumClass, false); +addMapConstructors(enumClass); } else { for (ConstructorNode constructorNode : sctors) { ConstructorNode init = new ConstructorNode(Opcodes.ACC_PUBLIC, constructorNode.getParameters(), ClassNode.EMPTY_ARRAY, new BlockStatement()); @@ -90,7 +90,7 @@ public class EnumCompletionVisitor extends ClassCodeVisitorSupport { } } } else { -addMapConstructors(enumClass, false); +addMapConstructors(enumClass); } } @@ -143,8 +143,8 @@ public class EnumCompletionVisitor extends ClassCodeVisitorSupport { } } -public static void addMapConstructors(ClassNode enumClass, boolean hasNoArg) { -TupleConstructorASTTransformation.addMapConstructors(enumClass, hasNoArg, "One of the enum constants for enum " + enumClass.getName() + +private static void addMapConstructors(ClassNode enumClass) { +TupleConstructorASTTransformation.addMapConstructors(enumClass, false, "One of the enum constants for enum " + enumClass.getName() + " was initialized with null. Please use a non-null value or define your own constructor."); } http://git-wip-us.apache.org/repos/asf/groovy/blob/5237bbe5/src/main/java/org/codehaus/groovy/transform/ImmutableASTTransformation.java -- diff --git a/src/main/java/org/codehaus/groovy/transform/ImmutableASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/ImmutableASTTransformation.java index 5536783..0d271ed 100644 --- a/src/main/java/org/codehaus/groovy/transform/ImmutableASTTransformation.java +++ b/src/main/java/org/codehaus/groovy/transform/ImmutableASTTransformation.java @@ -75,7 +75,6 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.callX; import static org.codehaus.groovy.ast.tools.GeneralUtils.castX; import static org.codehaus.groovy.ast.tools.GeneralUtils.classList2args; import static org.codehaus.groovy.ast.tools.GeneralUtils.constX; -import static org.codehaus.groovy.ast.tools.GeneralUtils.createConstructorStatementDefault; import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX; import static org.codehaus.groovy.ast.tools.GeneralUtils.declS; import static org.codehaus.groovy.ast.tools.GeneralUtils.eqX; @@ -95,6 +94,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.neX; import static org.codehaus.groovy.ast.tools.GeneralUtils.notX; import static org.codehaus.groovy.ast.tools.GeneralUtils.orX; import static org.codehaus.groovy.ast.tools.GeneralUtils.params; +import static org.codehaus.groovy.ast.tools.GeneralUtils.propX; import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS; import static org.codehaus.groovy.ast.tools.GeneralUtils.safeExpression; import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt; @@ -138,6 +138,7 @@ public class ImmutableASTTransformation extends AbstractASTTransformation
[2/5] groovy git commit: GROOVY-8440: Groovy's @Immutable annotation should be re-vamped to be a meta-annotation (additional refactoring to remove dup and plumb in pre/post conditions)
GROOVY-8440: Groovy's @Immutable annotation should be re-vamped to be a meta-annotation (additional refactoring to remove dup and plumb in pre/post conditions) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/8cd0820f Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8cd0820f Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8cd0820f Branch: refs/heads/GROOVY_2_6_X Commit: 8cd0820f988db59a668daf71af0cf07ade15e8c8 Parents: 4be8c77 Author: paulkAuthored: Mon Jan 29 23:57:26 2018 +1000 Committer: paulk Committed: Wed Jan 31 22:40:31 2018 +1000 -- .../groovy/groovy/transform/Immutable.groovy| 4 +- .../groovy/groovy/transform/MapConstructor.java | 5 - .../groovy/transform/TupleConstructor.java | 7 -- .../codehaus/groovy/ast/tools/GeneralUtils.java | 17 +++ .../transform/ImmutableASTTransformation.java | 107 +-- .../MapConstructorASTTransformation.java| 69 +++- .../TupleConstructorASTTransformation.java | 25 +++-- 7 files changed, 127 insertions(+), 107 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/8cd0820f/src/main/groovy/groovy/transform/Immutable.groovy -- diff --git a/src/main/groovy/groovy/transform/Immutable.groovy b/src/main/groovy/groovy/transform/Immutable.groovy index e59342b..3fa518a 100644 --- a/src/main/groovy/groovy/transform/Immutable.groovy +++ b/src/main/groovy/groovy/transform/Immutable.groovy @@ -174,8 +174,8 @@ package groovy.transform @ToString(cache = true, includeSuperProperties = true) @EqualsAndHashCode(cache = true) @ImmutableBase -@TupleConstructor(makeImmutable = true, defaults = false) -@MapConstructor(makeImmutable = true, noArg = true, includeSuperProperties = true) +@TupleConstructor(defaults = false) +@MapConstructor(noArg = true, includeSuperProperties = true) @KnownImmutable @AnnotationCollector(mode=AnnotationCollectorMode.PREFER_EXPLICIT_MERGED) @interface Immutable { } http://git-wip-us.apache.org/repos/asf/groovy/blob/8cd0820f/src/main/groovy/groovy/transform/MapConstructor.java -- diff --git a/src/main/groovy/groovy/transform/MapConstructor.java b/src/main/groovy/groovy/transform/MapConstructor.java index 55dee78..d4d5657 100644 --- a/src/main/groovy/groovy/transform/MapConstructor.java +++ b/src/main/groovy/groovy/transform/MapConstructor.java @@ -96,11 +96,6 @@ public @interface MapConstructor { boolean includeFields() default false; /** - * Whether immutable pre-cautions (defensive copying, cloning, etc.) should be applied to incoming/outgoing properties. - */ -boolean makeImmutable() default false; - -/** * Include properties in the constructor. */ boolean includeProperties() default true; http://git-wip-us.apache.org/repos/asf/groovy/blob/8cd0820f/src/main/groovy/groovy/transform/TupleConstructor.java -- diff --git a/src/main/groovy/groovy/transform/TupleConstructor.java b/src/main/groovy/groovy/transform/TupleConstructor.java index bad5518..eb7cb6e 100644 --- a/src/main/groovy/groovy/transform/TupleConstructor.java +++ b/src/main/groovy/groovy/transform/TupleConstructor.java @@ -232,13 +232,6 @@ public @interface TupleConstructor { boolean force() default false; /** - * Whether immutable pre-cautions (defensive copying, cloning, etc.) should be applied to incoming/outgoing properties. - * - * @since 2.5.0 - */ -boolean makeImmutable() default false; - -/** * Used to set whether default value processing is enabled (the default) or disabled. * * By default, every constructor parameter is given a default value. This value will http://git-wip-us.apache.org/repos/asf/groovy/blob/8cd0820f/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java -- diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java index 4c55515..8c949e7 100644 --- a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java +++ b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java @@ -42,6 +42,7 @@ import org.codehaus.groovy.ast.expr.ConstructorCallExpression; import org.codehaus.groovy.ast.expr.DeclarationExpression; import org.codehaus.groovy.ast.expr.Expression; import org.codehaus.groovy.ast.expr.FieldExpression; +import org.codehaus.groovy.ast.expr.ListExpression; import org.codehaus.groovy.ast.expr.MethodCallExpression; import
[5/5] groovy git commit: GROOVY-8465: @ToString should support the includeSuperFields annotation attribute
GROOVY-8465: @ToString should support the includeSuperFields annotation attribute Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/6e533451 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/6e533451 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/6e533451 Branch: refs/heads/GROOVY_2_6_X Commit: 6e533451e645977191da34c7f9bbadb3ae1b07fd Parents: 5237bbe Author: paulkAuthored: Wed Jan 31 22:35:56 2018 +1000 Committer: paulk Committed: Wed Jan 31 22:40:33 2018 +1000 -- .../groovy/groovy/transform/MapConstructor.java | 18 --- src/main/groovy/groovy/transform/ToString.java | 26 --- .../groovy/transform/TupleConstructor.java | 22 + .../codehaus/groovy/ast/tools/GeneralUtils.java | 25 ++ .../MapConstructorASTTransformation.java| 4 +- .../transform/ToStringASTTransformation.java| 49 .../TupleConstructorASTTransformation.java | 4 +- .../transform/ToStringTransformTest.groovy | 4 +- 8 files changed, 95 insertions(+), 57 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/6e533451/src/main/groovy/groovy/transform/MapConstructor.java -- diff --git a/src/main/groovy/groovy/transform/MapConstructor.java b/src/main/groovy/groovy/transform/MapConstructor.java index d4d5657..eb1e069 100644 --- a/src/main/groovy/groovy/transform/MapConstructor.java +++ b/src/main/groovy/groovy/transform/MapConstructor.java @@ -27,7 +27,7 @@ import java.lang.annotation.Target; /** * Class annotation used to assist in the creation of map constructors in classes. - * If the class is also annotated with {@code @KnownImmutable}, then the generated + * If the class is also annotated with {@code @ImmutableBase}, then the generated * constructor will contain additional code needed for immutable classes. * * It allows you to write classes in this shortened form: @@ -91,22 +91,26 @@ public @interface MapConstructor { String[] includes() default {Undefined.STRING}; /** - * Include fields in the constructor. + * Include properties in the constructor. */ -boolean includeFields() default false; +boolean includeProperties() default true; /** - * Include properties in the constructor. + * Include fields in the constructor. Fields come after any properties. */ -boolean includeProperties() default true; +boolean includeFields() default false; /** * Include properties from super classes in the constructor. + * Groovy properties, JavaBean properties and fields (in that order) from superclasses come before + * the members from a subclass (unless 'includes' is used to determine the order). */ boolean includeSuperProperties() default false; /** * Include fields from super classes in the constructor. + * Groovy properties, JavaBean properties and fields (in that order) from superclasses come before + * the members from a subclass (unless 'includes' is used to determine the order). */ boolean includeSuperFields() default false; @@ -114,11 +118,13 @@ public @interface MapConstructor { * Whether to include all properties (as per the JavaBean spec) in the generated constructor. * When true, Groovy treats any explicitly created setXxx() methods as property setters as per the JavaBean * specification. + * JavaBean properties come after any Groovy properties but before any fields for a given class + * (unless 'includes' is used to determine the order). */ boolean allProperties() default false; /** - * By default, properties are set directly using their respective field. + * By default, Groovy properties are set directly using their respective field. * By setting {@code useSetters=true} then a writable property will be set using its setter. * If turning on this flag we recommend that setters that might be called are * made null-safe wrt the parameter. http://git-wip-us.apache.org/repos/asf/groovy/blob/6e533451/src/main/groovy/groovy/transform/ToString.java -- diff --git a/src/main/groovy/groovy/transform/ToString.java b/src/main/groovy/groovy/transform/ToString.java index 25fccab..979d333 100644 --- a/src/main/groovy/groovy/transform/ToString.java +++ b/src/main/groovy/groovy/transform/ToString.java @@ -283,22 +283,32 @@ public @interface ToString { boolean includeSuper() default false; /** - * Whether to include super properties in the generated toString. - * @since 2.4.0 - */ -boolean includeSuperProperties()
[3/5] groovy git commit: MapConstructor should have an includeSuperFields annotation attribute plus some refactoring
MapConstructor should have an includeSuperFields annotation attribute plus some refactoring Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/4be8c777 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/4be8c777 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/4be8c777 Branch: refs/heads/GROOVY_2_6_X Commit: 4be8c777537b8775eb82f840c9ae1e8d31f43f34 Parents: 3ad9a0e Author: paulkAuthored: Sun Jan 28 17:00:13 2018 +1000 Committer: paulk Committed: Wed Jan 31 22:40:31 2018 +1000 -- .../groovy/groovy/transform/MapConstructor.java | 5 ++ .../java/org/codehaus/groovy/ast/FieldNode.java | 7 +++ .../codehaus/groovy/ast/tools/GeneralUtils.java | 21 +--- .../MapConstructorASTTransformation.java| 54 +--- .../TupleConstructorASTTransformation.java | 4 +- 5 files changed, 52 insertions(+), 39 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/4be8c777/src/main/groovy/groovy/transform/MapConstructor.java -- diff --git a/src/main/groovy/groovy/transform/MapConstructor.java b/src/main/groovy/groovy/transform/MapConstructor.java index ccd127a..55dee78 100644 --- a/src/main/groovy/groovy/transform/MapConstructor.java +++ b/src/main/groovy/groovy/transform/MapConstructor.java @@ -111,6 +111,11 @@ public @interface MapConstructor { boolean includeSuperProperties() default false; /** + * Include fields from super classes in the constructor. + */ +boolean includeSuperFields() default false; + +/** * Whether to include all properties (as per the JavaBean spec) in the generated constructor. * When true, Groovy treats any explicitly created setXxx() methods as property setters as per the JavaBean * specification. http://git-wip-us.apache.org/repos/asf/groovy/blob/4be8c777/src/main/java/org/codehaus/groovy/ast/FieldNode.java -- diff --git a/src/main/java/org/codehaus/groovy/ast/FieldNode.java b/src/main/java/org/codehaus/groovy/ast/FieldNode.java index d38f4f4..33e15c3 100644 --- a/src/main/java/org/codehaus/groovy/ast/FieldNode.java +++ b/src/main/java/org/codehaus/groovy/ast/FieldNode.java @@ -143,6 +143,13 @@ public class FieldNode extends AnnotatedNode implements Opcodes, Variable, Groov return (modifiers & ACC_PROTECTED) != 0; } + /** + * @return true if the field is private + */ +public boolean isPrivate() { +return (modifiers & ACC_PRIVATE) != 0; +} + /** * @param owner The owner to set. */ http://git-wip-us.apache.org/repos/asf/groovy/blob/4be8c777/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java -- diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java index 807ea7d..4c55515 100644 --- a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java +++ b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java @@ -466,16 +466,16 @@ public class GeneralUtils { return result; } -public static List getAllProperties(Set names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses) { -return getAllProperties(names, cNode, cNode, includeProperties, includeFields, allProperties, traverseSuperClasses); +public static List getAllProperties(Set names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses, boolean skipReadonly) { +return getAllProperties(names, cNode, cNode, includeProperties, includeFields, allProperties, traverseSuperClasses, skipReadonly); } -private static List getAllProperties(Set names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses) { +public static List getAllProperties(Set names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses, boolean skipReadonly) { final List result; if (cNode == ClassHelper.OBJECT_TYPE || !traverseSuperClasses) { result = new ArrayList(); } else { -result = getAllProperties(names, origType, cNode.getSuperClass(), includeProperties, includeFields, allProperties, true); +result = getAllProperties(names, origType, cNode.getSuperClass(), includeProperties, includeFields, allProperties, true, skipReadonly); }
[5/5] groovy git commit: GROOVY-8465: @ToString should support the includeSuperFields annotation attribute
GROOVY-8465: @ToString should support the includeSuperFields annotation attribute Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/e9d8dffc Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/e9d8dffc Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/e9d8dffc Branch: refs/heads/GROOVY_2_5_X Commit: e9d8dffca03c81502dd979df6c57915aa0d0ac4c Parents: 990c271 Author: paulkAuthored: Wed Jan 31 22:35:56 2018 +1000 Committer: paulk Committed: Wed Jan 31 22:41:30 2018 +1000 -- .../groovy/groovy/transform/MapConstructor.java | 18 --- src/main/groovy/groovy/transform/ToString.java | 26 --- .../groovy/transform/TupleConstructor.java | 22 + .../codehaus/groovy/ast/tools/GeneralUtils.java | 25 ++ .../MapConstructorASTTransformation.java| 4 +- .../transform/ToStringASTTransformation.java| 49 .../TupleConstructorASTTransformation.java | 4 +- .../transform/ToStringTransformTest.groovy | 4 +- 8 files changed, 95 insertions(+), 57 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/e9d8dffc/src/main/groovy/groovy/transform/MapConstructor.java -- diff --git a/src/main/groovy/groovy/transform/MapConstructor.java b/src/main/groovy/groovy/transform/MapConstructor.java index d4d5657..eb1e069 100644 --- a/src/main/groovy/groovy/transform/MapConstructor.java +++ b/src/main/groovy/groovy/transform/MapConstructor.java @@ -27,7 +27,7 @@ import java.lang.annotation.Target; /** * Class annotation used to assist in the creation of map constructors in classes. - * If the class is also annotated with {@code @KnownImmutable}, then the generated + * If the class is also annotated with {@code @ImmutableBase}, then the generated * constructor will contain additional code needed for immutable classes. * * It allows you to write classes in this shortened form: @@ -91,22 +91,26 @@ public @interface MapConstructor { String[] includes() default {Undefined.STRING}; /** - * Include fields in the constructor. + * Include properties in the constructor. */ -boolean includeFields() default false; +boolean includeProperties() default true; /** - * Include properties in the constructor. + * Include fields in the constructor. Fields come after any properties. */ -boolean includeProperties() default true; +boolean includeFields() default false; /** * Include properties from super classes in the constructor. + * Groovy properties, JavaBean properties and fields (in that order) from superclasses come before + * the members from a subclass (unless 'includes' is used to determine the order). */ boolean includeSuperProperties() default false; /** * Include fields from super classes in the constructor. + * Groovy properties, JavaBean properties and fields (in that order) from superclasses come before + * the members from a subclass (unless 'includes' is used to determine the order). */ boolean includeSuperFields() default false; @@ -114,11 +118,13 @@ public @interface MapConstructor { * Whether to include all properties (as per the JavaBean spec) in the generated constructor. * When true, Groovy treats any explicitly created setXxx() methods as property setters as per the JavaBean * specification. + * JavaBean properties come after any Groovy properties but before any fields for a given class + * (unless 'includes' is used to determine the order). */ boolean allProperties() default false; /** - * By default, properties are set directly using their respective field. + * By default, Groovy properties are set directly using their respective field. * By setting {@code useSetters=true} then a writable property will be set using its setter. * If turning on this flag we recommend that setters that might be called are * made null-safe wrt the parameter. http://git-wip-us.apache.org/repos/asf/groovy/blob/e9d8dffc/src/main/groovy/groovy/transform/ToString.java -- diff --git a/src/main/groovy/groovy/transform/ToString.java b/src/main/groovy/groovy/transform/ToString.java index 968e7f0..49930d2 100644 --- a/src/main/groovy/groovy/transform/ToString.java +++ b/src/main/groovy/groovy/transform/ToString.java @@ -283,22 +283,32 @@ public @interface ToString { boolean includeSuper() default false; /** - * Whether to include super properties in the generated toString. - * @since 2.4.0 - */ -boolean includeSuperProperties()
[2/5] groovy git commit: GROOVY-8440: Groovy's @Immutable annotation should be re-vamped to be a meta-annotation (additional refactoring to remove dup and plumb in pre/post conditions)
GROOVY-8440: Groovy's @Immutable annotation should be re-vamped to be a meta-annotation (additional refactoring to remove dup and plumb in pre/post conditions) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/9186fdad Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/9186fdad Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/9186fdad Branch: refs/heads/GROOVY_2_5_X Commit: 9186fdad24ce759a40fd584ea6b12bf8f4b87b9b Parents: f7fe332 Author: paulkAuthored: Mon Jan 29 23:57:26 2018 +1000 Committer: paulk Committed: Wed Jan 31 22:41:28 2018 +1000 -- .../groovy/groovy/transform/Immutable.groovy| 4 +- .../groovy/groovy/transform/MapConstructor.java | 5 - .../groovy/transform/TupleConstructor.java | 7 -- .../codehaus/groovy/ast/tools/GeneralUtils.java | 17 +++ .../transform/ImmutableASTTransformation.java | 107 +-- .../MapConstructorASTTransformation.java| 69 +++- .../TupleConstructorASTTransformation.java | 25 +++-- 7 files changed, 127 insertions(+), 107 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/9186fdad/src/main/groovy/groovy/transform/Immutable.groovy -- diff --git a/src/main/groovy/groovy/transform/Immutable.groovy b/src/main/groovy/groovy/transform/Immutable.groovy index e59342b..3fa518a 100644 --- a/src/main/groovy/groovy/transform/Immutable.groovy +++ b/src/main/groovy/groovy/transform/Immutable.groovy @@ -174,8 +174,8 @@ package groovy.transform @ToString(cache = true, includeSuperProperties = true) @EqualsAndHashCode(cache = true) @ImmutableBase -@TupleConstructor(makeImmutable = true, defaults = false) -@MapConstructor(makeImmutable = true, noArg = true, includeSuperProperties = true) +@TupleConstructor(defaults = false) +@MapConstructor(noArg = true, includeSuperProperties = true) @KnownImmutable @AnnotationCollector(mode=AnnotationCollectorMode.PREFER_EXPLICIT_MERGED) @interface Immutable { } http://git-wip-us.apache.org/repos/asf/groovy/blob/9186fdad/src/main/groovy/groovy/transform/MapConstructor.java -- diff --git a/src/main/groovy/groovy/transform/MapConstructor.java b/src/main/groovy/groovy/transform/MapConstructor.java index 55dee78..d4d5657 100644 --- a/src/main/groovy/groovy/transform/MapConstructor.java +++ b/src/main/groovy/groovy/transform/MapConstructor.java @@ -96,11 +96,6 @@ public @interface MapConstructor { boolean includeFields() default false; /** - * Whether immutable pre-cautions (defensive copying, cloning, etc.) should be applied to incoming/outgoing properties. - */ -boolean makeImmutable() default false; - -/** * Include properties in the constructor. */ boolean includeProperties() default true; http://git-wip-us.apache.org/repos/asf/groovy/blob/9186fdad/src/main/groovy/groovy/transform/TupleConstructor.java -- diff --git a/src/main/groovy/groovy/transform/TupleConstructor.java b/src/main/groovy/groovy/transform/TupleConstructor.java index bad5518..eb7cb6e 100644 --- a/src/main/groovy/groovy/transform/TupleConstructor.java +++ b/src/main/groovy/groovy/transform/TupleConstructor.java @@ -232,13 +232,6 @@ public @interface TupleConstructor { boolean force() default false; /** - * Whether immutable pre-cautions (defensive copying, cloning, etc.) should be applied to incoming/outgoing properties. - * - * @since 2.5.0 - */ -boolean makeImmutable() default false; - -/** * Used to set whether default value processing is enabled (the default) or disabled. * * By default, every constructor parameter is given a default value. This value will http://git-wip-us.apache.org/repos/asf/groovy/blob/9186fdad/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java -- diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java index 13a2957..b81e2e8 100644 --- a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java +++ b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java @@ -42,6 +42,7 @@ import org.codehaus.groovy.ast.expr.ConstructorCallExpression; import org.codehaus.groovy.ast.expr.DeclarationExpression; import org.codehaus.groovy.ast.expr.Expression; import org.codehaus.groovy.ast.expr.FieldExpression; +import org.codehaus.groovy.ast.expr.ListExpression; import org.codehaus.groovy.ast.expr.MethodCallExpression; import
[1/5] groovy git commit: minor refactor: prepare to remove some duplicated code
Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 07bcbcf43 -> e9d8dffca minor refactor: prepare to remove some duplicated code Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/19b011e4 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/19b011e4 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/19b011e4 Branch: refs/heads/GROOVY_2_5_X Commit: 19b011e460f9255b0627d75d1a23f427ac19f5e5 Parents: 07bcbcf Author: paulkAuthored: Thu Jan 25 21:13:01 2018 +1000 Committer: paulk Committed: Wed Jan 31 22:41:27 2018 +1000 -- .../codehaus/groovy/ast/tools/GeneralUtils.java | 8 ++-- .../TupleConstructorASTTransformation.java | 48 ++-- 2 files changed, 28 insertions(+), 28 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/19b011e4/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java -- diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java index 84196e3..986a439 100644 --- a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java +++ b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java @@ -463,16 +463,16 @@ public class GeneralUtils { return result; } -public static List getAllFields(Set names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses) { -return getAllFields(names, cNode, cNode, includeProperties, includeFields, allProperties, traverseSuperClasses); +public static List getAllProperties(Set names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses) { +return getAllProperties(names, cNode, cNode, includeProperties, includeFields, allProperties, traverseSuperClasses); } -private static List getAllFields(Set names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses) { +private static List getAllProperties(Set names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses) { final List result; if (cNode == ClassHelper.OBJECT_TYPE || !traverseSuperClasses) { result = new ArrayList(); } else { -result = getAllFields(names, origType, cNode.getSuperClass(), includeProperties, includeFields, allProperties, true); +result = getAllProperties(names, origType, cNode.getSuperClass(), includeProperties, includeFields, allProperties, true); } if (includeProperties) { for (PropertyNode pNode : cNode.getProperties()) { http://git-wip-us.apache.org/repos/asf/groovy/blob/19b011e4/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java -- diff --git a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java index c253d93..2815cb1 100644 --- a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java +++ b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java @@ -61,7 +61,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.constX; import static org.codehaus.groovy.ast.tools.GeneralUtils.copyStatementsWithSuperAdjustment; import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX; import static org.codehaus.groovy.ast.tools.GeneralUtils.equalsNullX; -import static org.codehaus.groovy.ast.tools.GeneralUtils.getAllFields; +import static org.codehaus.groovy.ast.tools.GeneralUtils.getAllProperties; import static org.codehaus.groovy.ast.tools.GeneralUtils.getSetterName; import static org.codehaus.groovy.ast.tools.GeneralUtils.ifElseS; import static org.codehaus.groovy.ast.tools.GeneralUtils.ifS; @@ -136,18 +136,9 @@ public class TupleConstructorASTTransformation extends AbstractASTTransformation return; } -// TODO remove duplication between various paths below -List list = ImmutableASTTransformation.getProperties(cNode, includeSuperProperties, allProperties); -boolean specialHashMapCase = ImmutableASTTransformation.isSpecialHashMapCase(list); -if (makeImmutable) { -if (!specialHashMapCase) { -ImmutableASTTransformation.createConstructorOrdered(cNode, list); -} -
[3/5] groovy git commit: MapConstructor should have an includeSuperFields annotation attribute plus some refactoring
MapConstructor should have an includeSuperFields annotation attribute plus some refactoring Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/f7fe332c Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f7fe332c Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f7fe332c Branch: refs/heads/GROOVY_2_5_X Commit: f7fe332c19e1f63e09505634ec2a603070a1a535 Parents: 19b011e Author: paulkAuthored: Sun Jan 28 17:00:13 2018 +1000 Committer: paulk Committed: Wed Jan 31 22:41:28 2018 +1000 -- .../groovy/groovy/transform/MapConstructor.java | 5 ++ .../java/org/codehaus/groovy/ast/FieldNode.java | 7 +++ .../codehaus/groovy/ast/tools/GeneralUtils.java | 21 +--- .../MapConstructorASTTransformation.java| 54 +--- .../TupleConstructorASTTransformation.java | 4 +- 5 files changed, 52 insertions(+), 39 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/f7fe332c/src/main/groovy/groovy/transform/MapConstructor.java -- diff --git a/src/main/groovy/groovy/transform/MapConstructor.java b/src/main/groovy/groovy/transform/MapConstructor.java index ccd127a..55dee78 100644 --- a/src/main/groovy/groovy/transform/MapConstructor.java +++ b/src/main/groovy/groovy/transform/MapConstructor.java @@ -111,6 +111,11 @@ public @interface MapConstructor { boolean includeSuperProperties() default false; /** + * Include fields from super classes in the constructor. + */ +boolean includeSuperFields() default false; + +/** * Whether to include all properties (as per the JavaBean spec) in the generated constructor. * When true, Groovy treats any explicitly created setXxx() methods as property setters as per the JavaBean * specification. http://git-wip-us.apache.org/repos/asf/groovy/blob/f7fe332c/src/main/java/org/codehaus/groovy/ast/FieldNode.java -- diff --git a/src/main/java/org/codehaus/groovy/ast/FieldNode.java b/src/main/java/org/codehaus/groovy/ast/FieldNode.java index cd7ef80..70068ff 100644 --- a/src/main/java/org/codehaus/groovy/ast/FieldNode.java +++ b/src/main/java/org/codehaus/groovy/ast/FieldNode.java @@ -141,6 +141,13 @@ public class FieldNode extends AnnotatedNode implements Opcodes, Variable { return (modifiers & ACC_PROTECTED) != 0; } + /** + * @return true if the field is private + */ +public boolean isPrivate() { +return (modifiers & ACC_PRIVATE) != 0; +} + /** * @param owner The owner to set. */ http://git-wip-us.apache.org/repos/asf/groovy/blob/f7fe332c/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java -- diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java index 986a439..13a2957 100644 --- a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java +++ b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java @@ -463,16 +463,16 @@ public class GeneralUtils { return result; } -public static List getAllProperties(Set names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses) { -return getAllProperties(names, cNode, cNode, includeProperties, includeFields, allProperties, traverseSuperClasses); +public static List getAllProperties(Set names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses, boolean skipReadonly) { +return getAllProperties(names, cNode, cNode, includeProperties, includeFields, allProperties, traverseSuperClasses, skipReadonly); } -private static List getAllProperties(Set names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses) { +public static List getAllProperties(Set names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses, boolean skipReadonly) { final List result; if (cNode == ClassHelper.OBJECT_TYPE || !traverseSuperClasses) { result = new ArrayList(); } else { -result = getAllProperties(names, origType, cNode.getSuperClass(), includeProperties, includeFields, allProperties, true); +result = getAllProperties(names, origType, cNode.getSuperClass(), includeProperties, includeFields, allProperties, true, skipReadonly); }
[4/5] groovy git commit: GROOVY-8440: Groovy's @Immutable annotation should be re-vamped to be a meta-annotation (additional refactoring to remove dup and plumb in pre/post conditions)
GROOVY-8440: Groovy's @Immutable annotation should be re-vamped to be a meta-annotation (additional refactoring to remove dup and plumb in pre/post conditions) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/990c2711 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/990c2711 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/990c2711 Branch: refs/heads/GROOVY_2_5_X Commit: 990c27115332a0525ca67f45ae34f5b20fb21a3f Parents: 9186fda Author: paulkAuthored: Wed Jan 31 11:19:57 2018 +1000 Committer: paulk Committed: Wed Jan 31 22:41:29 2018 +1000 -- .../groovy/classgen/EnumCompletionVisitor.java | 8 +- .../transform/ImmutableASTTransformation.java | 136 --- .../MapConstructorASTTransformation.java| 25 ++-- .../TupleConstructorASTTransformation.java | 75 +- 4 files changed, 141 insertions(+), 103 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/990c2711/src/main/java/org/codehaus/groovy/classgen/EnumCompletionVisitor.java -- diff --git a/src/main/java/org/codehaus/groovy/classgen/EnumCompletionVisitor.java b/src/main/java/org/codehaus/groovy/classgen/EnumCompletionVisitor.java index 30c6fab..7cc5375 100644 --- a/src/main/java/org/codehaus/groovy/classgen/EnumCompletionVisitor.java +++ b/src/main/java/org/codehaus/groovy/classgen/EnumCompletionVisitor.java @@ -82,7 +82,7 @@ public class EnumCompletionVisitor extends ClassCodeVisitorSupport { ClassNode sn = enumClass.getSuperClass(); List sctors = new ArrayList(sn.getDeclaredConstructors()); if (sctors.isEmpty()) { -addMapConstructors(enumClass, false); +addMapConstructors(enumClass); } else { for (ConstructorNode constructorNode : sctors) { ConstructorNode init = new ConstructorNode(Opcodes.ACC_PUBLIC, constructorNode.getParameters(), ClassNode.EMPTY_ARRAY, new BlockStatement()); @@ -90,7 +90,7 @@ public class EnumCompletionVisitor extends ClassCodeVisitorSupport { } } } else { -addMapConstructors(enumClass, false); +addMapConstructors(enumClass); } } @@ -143,8 +143,8 @@ public class EnumCompletionVisitor extends ClassCodeVisitorSupport { } } -public static void addMapConstructors(ClassNode enumClass, boolean hasNoArg) { -TupleConstructorASTTransformation.addMapConstructors(enumClass, hasNoArg, "One of the enum constants for enum " + enumClass.getName() + +private static void addMapConstructors(ClassNode enumClass) { +TupleConstructorASTTransformation.addMapConstructors(enumClass, false, "One of the enum constants for enum " + enumClass.getName() + " was initialized with null. Please use a non-null value or define your own constructor."); } http://git-wip-us.apache.org/repos/asf/groovy/blob/990c2711/src/main/java/org/codehaus/groovy/transform/ImmutableASTTransformation.java -- diff --git a/src/main/java/org/codehaus/groovy/transform/ImmutableASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/ImmutableASTTransformation.java index 5536783..0d271ed 100644 --- a/src/main/java/org/codehaus/groovy/transform/ImmutableASTTransformation.java +++ b/src/main/java/org/codehaus/groovy/transform/ImmutableASTTransformation.java @@ -75,7 +75,6 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.callX; import static org.codehaus.groovy.ast.tools.GeneralUtils.castX; import static org.codehaus.groovy.ast.tools.GeneralUtils.classList2args; import static org.codehaus.groovy.ast.tools.GeneralUtils.constX; -import static org.codehaus.groovy.ast.tools.GeneralUtils.createConstructorStatementDefault; import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX; import static org.codehaus.groovy.ast.tools.GeneralUtils.declS; import static org.codehaus.groovy.ast.tools.GeneralUtils.eqX; @@ -95,6 +94,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.neX; import static org.codehaus.groovy.ast.tools.GeneralUtils.notX; import static org.codehaus.groovy.ast.tools.GeneralUtils.orX; import static org.codehaus.groovy.ast.tools.GeneralUtils.params; +import static org.codehaus.groovy.ast.tools.GeneralUtils.propX; import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS; import static org.codehaus.groovy.ast.tools.GeneralUtils.safeExpression; import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt; @@ -138,6 +138,7 @@ public class ImmutableASTTransformation extends AbstractASTTransformation
groovy git commit: GROOVY-8465: @ToString should support the includeSuperFields annotation attribute
Repository: groovy Updated Branches: refs/heads/master 534620ddc -> d9e6f8aaa GROOVY-8465: @ToString should support the includeSuperFields annotation attribute Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d9e6f8aa Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d9e6f8aa Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d9e6f8aa Branch: refs/heads/master Commit: d9e6f8aaad6926ff51fd7e69c194e253b9157b3f Parents: 534620d Author: paulkAuthored: Wed Jan 31 22:35:56 2018 +1000 Committer: paulk Committed: Wed Jan 31 22:36:16 2018 +1000 -- .../groovy/groovy/transform/MapConstructor.java | 18 --- src/main/groovy/groovy/transform/ToString.java | 26 --- .../groovy/transform/TupleConstructor.java | 22 + .../codehaus/groovy/ast/tools/GeneralUtils.java | 25 ++ .../MapConstructorASTTransformation.java| 4 +- .../transform/ToStringASTTransformation.java| 49 .../TupleConstructorASTTransformation.java | 4 +- .../transform/ToStringTransformTest.groovy | 4 +- 8 files changed, 95 insertions(+), 57 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/d9e6f8aa/src/main/groovy/groovy/transform/MapConstructor.java -- diff --git a/src/main/groovy/groovy/transform/MapConstructor.java b/src/main/groovy/groovy/transform/MapConstructor.java index d4d5657..eb1e069 100644 --- a/src/main/groovy/groovy/transform/MapConstructor.java +++ b/src/main/groovy/groovy/transform/MapConstructor.java @@ -27,7 +27,7 @@ import java.lang.annotation.Target; /** * Class annotation used to assist in the creation of map constructors in classes. - * If the class is also annotated with {@code @KnownImmutable}, then the generated + * If the class is also annotated with {@code @ImmutableBase}, then the generated * constructor will contain additional code needed for immutable classes. * * It allows you to write classes in this shortened form: @@ -91,22 +91,26 @@ public @interface MapConstructor { String[] includes() default {Undefined.STRING}; /** - * Include fields in the constructor. + * Include properties in the constructor. */ -boolean includeFields() default false; +boolean includeProperties() default true; /** - * Include properties in the constructor. + * Include fields in the constructor. Fields come after any properties. */ -boolean includeProperties() default true; +boolean includeFields() default false; /** * Include properties from super classes in the constructor. + * Groovy properties, JavaBean properties and fields (in that order) from superclasses come before + * the members from a subclass (unless 'includes' is used to determine the order). */ boolean includeSuperProperties() default false; /** * Include fields from super classes in the constructor. + * Groovy properties, JavaBean properties and fields (in that order) from superclasses come before + * the members from a subclass (unless 'includes' is used to determine the order). */ boolean includeSuperFields() default false; @@ -114,11 +118,13 @@ public @interface MapConstructor { * Whether to include all properties (as per the JavaBean spec) in the generated constructor. * When true, Groovy treats any explicitly created setXxx() methods as property setters as per the JavaBean * specification. + * JavaBean properties come after any Groovy properties but before any fields for a given class + * (unless 'includes' is used to determine the order). */ boolean allProperties() default false; /** - * By default, properties are set directly using their respective field. + * By default, Groovy properties are set directly using their respective field. * By setting {@code useSetters=true} then a writable property will be set using its setter. * If turning on this flag we recommend that setters that might be called are * made null-safe wrt the parameter. http://git-wip-us.apache.org/repos/asf/groovy/blob/d9e6f8aa/src/main/groovy/groovy/transform/ToString.java -- diff --git a/src/main/groovy/groovy/transform/ToString.java b/src/main/groovy/groovy/transform/ToString.java index 25fccab..979d333 100644 --- a/src/main/groovy/groovy/transform/ToString.java +++ b/src/main/groovy/groovy/transform/ToString.java @@ -283,22 +283,32 @@ public @interface ToString { boolean includeSuper() default false; /** - * Whether to include super properties in the generated
[1/5] groovy git commit: minor refactor: prepare to remove some duplicated code
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X addd312aa -> 6e533451e minor refactor: prepare to remove some duplicated code Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/3ad9a0ea Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3ad9a0ea Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3ad9a0ea Branch: refs/heads/GROOVY_2_6_X Commit: 3ad9a0ea7bbeba122095713adc2da215d2c7b3d7 Parents: addd312 Author: paulkAuthored: Thu Jan 25 21:13:01 2018 +1000 Committer: paulk Committed: Wed Jan 31 22:40:30 2018 +1000 -- .../codehaus/groovy/ast/tools/GeneralUtils.java | 8 ++-- .../TupleConstructorASTTransformation.java | 48 ++-- 2 files changed, 28 insertions(+), 28 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/3ad9a0ea/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java -- diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java index b61ae64..807ea7d 100644 --- a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java +++ b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java @@ -466,16 +466,16 @@ public class GeneralUtils { return result; } -public static List getAllFields(Set names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses) { -return getAllFields(names, cNode, cNode, includeProperties, includeFields, allProperties, traverseSuperClasses); +public static List getAllProperties(Set names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses) { +return getAllProperties(names, cNode, cNode, includeProperties, includeFields, allProperties, traverseSuperClasses); } -private static List getAllFields(Set names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses) { +private static List getAllProperties(Set names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses) { final List result; if (cNode == ClassHelper.OBJECT_TYPE || !traverseSuperClasses) { result = new ArrayList(); } else { -result = getAllFields(names, origType, cNode.getSuperClass(), includeProperties, includeFields, allProperties, true); +result = getAllProperties(names, origType, cNode.getSuperClass(), includeProperties, includeFields, allProperties, true); } if (includeProperties) { for (PropertyNode pNode : cNode.getProperties()) { http://git-wip-us.apache.org/repos/asf/groovy/blob/3ad9a0ea/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java -- diff --git a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java index 179ba1a..7cefac6 100644 --- a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java +++ b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java @@ -61,7 +61,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.constX; import static org.codehaus.groovy.ast.tools.GeneralUtils.copyStatementsWithSuperAdjustment; import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX; import static org.codehaus.groovy.ast.tools.GeneralUtils.equalsNullX; -import static org.codehaus.groovy.ast.tools.GeneralUtils.getAllFields; +import static org.codehaus.groovy.ast.tools.GeneralUtils.getAllProperties; import static org.codehaus.groovy.ast.tools.GeneralUtils.getSetterName; import static org.codehaus.groovy.ast.tools.GeneralUtils.ifElseS; import static org.codehaus.groovy.ast.tools.GeneralUtils.ifS; @@ -136,18 +136,9 @@ public class TupleConstructorASTTransformation extends AbstractASTTransformation return; } -// TODO remove duplication between various paths below -List list = ImmutableASTTransformation.getProperties(cNode, includeSuperProperties, allProperties); -boolean specialHashMapCase = ImmutableASTTransformation.isSpecialHashMapCase(list); -if (makeImmutable) { -if (!specialHashMapCase) { -ImmutableASTTransformation.createConstructorOrdered(cNode, list); -} -
[1/2] groovy git commit: Remove `Lambda` class
Repository: groovy Updated Branches: refs/heads/native-lambda 2823724cd -> dbcac60f6 Remove `Lambda` class Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/552e0103 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/552e0103 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/552e0103 Branch: refs/heads/native-lambda Commit: 552e01039aaad874a1409f4029df132817c7b0bb Parents: 2823724 Author: sunlanAuthored: Wed Jan 31 16:35:37 2018 +0800 Committer: sunlan Committed: Wed Jan 31 16:35:37 2018 +0800 -- src/main/groovy/groovy/lang/Lambda.java | 79 .../org/codehaus/groovy/ast/ClassHelper.java| 7 +- .../asm/sc/StaticTypesLambdaWriter.java | 45 +-- 3 files changed, 22 insertions(+), 109 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/552e0103/src/main/groovy/groovy/lang/Lambda.java -- diff --git a/src/main/groovy/groovy/lang/Lambda.java b/src/main/groovy/groovy/lang/Lambda.java deleted file mode 100644 index 6cf2a63..000 --- a/src/main/groovy/groovy/lang/Lambda.java +++ /dev/null @@ -1,79 +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 groovy.lang; - -import org.apache.groovy.internal.util.UncheckedThrow; -import org.codehaus.groovy.GroovyBugError; -import org.codehaus.groovy.runtime.InvokerInvocationException; - -import static org.codehaus.groovy.classgen.asm.sc.StaticTypesLambdaWriter.SAM_NAME; - -/** - * Represents any lambda object in Groovy. - * - * @since 3.0.0 - */ -public abstract class Lambda extends Closure { -private Object lambdaObject; - -public Lambda(Object owner, Object thisObject) { -super(owner, thisObject); -} - -/** - * Constructor used when the "this" object for the Lambda is null. - * This is rarely the case in normal Groovy usage. - * - * @param owner the Lambda owner - */ -public Lambda(Object owner) { -super(owner); -} - -@Override -public V call(Object... args) { -String methodName; -try { -methodName = (String) this.getClass().getField(SAM_NAME).get(lambdaObject); -} catch (IllegalAccessException e) { -throw new GroovyBugError("Failed to access field " + SAM_NAME + " of " + this.getClass(), e); -} catch (NoSuchFieldException e) { -throw new GroovyBugError("Failed to find field " + SAM_NAME + " in " + this.getClass(), e); -} - -try { -return (V) getMetaClass().invokeMethod(lambdaObject, methodName, args); -} catch (InvokerInvocationException e) { -UncheckedThrow.rethrow(e.getCause()); -return null; // unreachable statement -} catch (Exception e) { -return (V) throwRuntimeException(e); -} -} - -public Object getLambdaObject() { -return lambdaObject; -} - -public void setLambdaObject(Object lambdaObject) { -this.lambdaObject = lambdaObject; -} - -} http://git-wip-us.apache.org/repos/asf/groovy/blob/552e0103/src/main/java/org/codehaus/groovy/ast/ClassHelper.java -- diff --git a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java index ed984ce..5f5fc3f 100644 --- a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java +++ b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java @@ -24,7 +24,6 @@ import groovy.lang.GString; import groovy.lang.GroovyInterceptable; import groovy.lang.GroovyObject; import groovy.lang.GroovyObjectSupport; -import groovy.lang.Lambda; import groovy.lang.MetaClass; import groovy.lang.Range; import groovy.lang.Reference; @@ -60,7 +59,7 @@ public class ClassHelper { private static final Class[] classes = new Class[]{ Object.class, Boolean.TYPE,
[2/2] groovy git commit: Remove unnecessary check of `FunctionalInterface`
Remove unnecessary check of `FunctionalInterface` Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/dbcac60f Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/dbcac60f Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/dbcac60f Branch: refs/heads/native-lambda Commit: dbcac60f64f921cd5e8ee02c4af126c9a6d8b883 Parents: 552e010 Author: sunlanAuthored: Wed Jan 31 16:38:43 2018 +0800 Committer: sunlan Committed: Wed Jan 31 16:38:43 2018 +0800 -- src/main/java/org/codehaus/groovy/ast/ClassHelper.java | 4 .../java/org/codehaus/groovy/classgen/asm/InvocationWriter.java | 2 +- .../codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java | 2 +- .../codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/dbcac60f/src/main/java/org/codehaus/groovy/ast/ClassHelper.java -- diff --git a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java index 5f5fc3f..93658d7 100644 --- a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java +++ b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java @@ -395,10 +395,6 @@ public class ClassHelper { return findSAM(type) != null; } -public static boolean isFunctionInterface(ClassNode type) { -return type.isInterface() && !type.getAnnotations(FunctionalInterface_Type).isEmpty() && isSAMType(type); -} - /** * Returns the single abstract method of a class node, if it is a SAM type, or null otherwise. * http://git-wip-us.apache.org/repos/asf/groovy/blob/dbcac60f/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java -- diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java index bfb9f7d..bc56b5a 100644 --- a/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java +++ b/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java @@ -494,7 +494,7 @@ public class InvocationWriter { return false; } -if (ClassHelper.isFunctionInterface(objectExpression.getType())) { +if (ClassHelper.isSAMType(objectExpression.getType())) { return true; } http://git-wip-us.apache.org/repos/asf/groovy/blob/dbcac60f/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java -- diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java index 35d2269..a1a797c 100644 --- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java +++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java @@ -96,7 +96,7 @@ public class StaticTypesLambdaWriter extends LambdaWriter { public void writeLambda(LambdaExpression expression) { ClassNode lambdaType = getLambdaType(expression); -if (!ClassHelper.isFunctionInterface(lambdaType.redirect())) { +if (!ClassHelper.isSAMType(lambdaType.redirect())) { // if the parameter type is not real FunctionInterface, generate the default bytecode, which is actually a closure super.writeLambda(expression); return; http://git-wip-us.apache.org/repos/asf/groovy/blob/dbcac60f/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java -- diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 2e4dc2e..dcb3ab6 100644 --- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -4119,7 +4119,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { collectAllInterfaceMethodsByName(receiver, name, methods); methods.addAll(OBJECT_TYPE.getMethods(name)); -if (ClassHelper.isFunctionInterface(receiver)) { +if (ClassHelper.isSAMType(receiver)) { MethodNode sam = ClassHelper.findSAM(receiver); MethodNode callMethodNode = new MethodNode("call", sam.getModifiers(), sam.getReturnType(),
groovy git commit: Make `CorrectAccessedVariableVisitor` extends `CodeVisitorSupport`
Repository: groovy Updated Branches: refs/heads/native-lambda dbcac60f6 -> 37dc84543 Make `CorrectAccessedVariableVisitor` extends `CodeVisitorSupport` Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/37dc8454 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/37dc8454 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/37dc8454 Branch: refs/heads/native-lambda Commit: 37dc8454315615d8f02609d50c0a5ce935e36cab Parents: dbcac60 Author: sunlanAuthored: Wed Jan 31 17:17:10 2018 +0800 Committer: sunlan Committed: Wed Jan 31 17:17:10 2018 +0800 -- .../groovy/classgen/asm/ClosureWriter.java | 10 + .../asm/sc/StaticTypesLambdaWriter.java | 17 +++- src/test/groovy/transform/stc/LambdaTest.groovy | 44 3 files changed, 61 insertions(+), 10 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/37dc8454/src/main/java/org/codehaus/groovy/classgen/asm/ClosureWriter.java -- diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/ClosureWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/ClosureWriter.java index 343b714..7c44599 100644 --- a/src/main/java/org/codehaus/groovy/classgen/asm/ClosureWriter.java +++ b/src/main/java/org/codehaus/groovy/classgen/asm/ClosureWriter.java @@ -19,9 +19,9 @@ package org.codehaus.groovy.classgen.asm; import org.codehaus.groovy.GroovyBugError; -import org.codehaus.groovy.ast.ClassCodeVisitorSupport; import org.codehaus.groovy.ast.ClassHelper; import org.codehaus.groovy.ast.ClassNode; +import org.codehaus.groovy.ast.CodeVisitorSupport; import org.codehaus.groovy.ast.ConstructorNode; import org.codehaus.groovy.ast.FieldNode; import org.codehaus.groovy.ast.InnerClassNode; @@ -44,7 +44,6 @@ import org.codehaus.groovy.ast.stmt.ExpressionStatement; import org.codehaus.groovy.ast.stmt.ReturnStatement; import org.codehaus.groovy.classgen.AsmClassGenerator; import org.codehaus.groovy.classgen.Verifier; -import org.codehaus.groovy.control.SourceUnit; import org.objectweb.asm.MethodVisitor; import java.util.HashMap; @@ -332,7 +331,7 @@ public class ClosureWriter { + controller.getContext().getNextClosureInnerName(outerClass, classNode, methodNode); } -protected static class CorrectAccessedVariableVisitor extends ClassCodeVisitorSupport { +protected static class CorrectAccessedVariableVisitor extends CodeVisitorSupport { private InnerClassNode icn; public CorrectAccessedVariableVisitor(InnerClassNode icn) { @@ -350,11 +349,6 @@ public class ClosureWriter { expression.setAccessedVariable(fn); } } - -@Override -protected SourceUnit getSourceUnit() { -return null; -} } private static void correctAccessedVariable(final InnerClassNode closureClass, ClosureExpression ce) { http://git-wip-us.apache.org/repos/asf/groovy/blob/37dc8454/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java -- diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java index a1a797c..60f8f7d 100644 --- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java +++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java @@ -20,6 +20,7 @@ package org.codehaus.groovy.classgen.asm.sc; import org.codehaus.groovy.GroovyBugError; +import org.codehaus.groovy.ast.ClassCodeVisitorSupport; import org.codehaus.groovy.ast.ClassHelper; import org.codehaus.groovy.ast.ClassNode; import org.codehaus.groovy.ast.ConstructorNode; @@ -39,6 +40,7 @@ import org.codehaus.groovy.classgen.asm.LambdaWriter; import org.codehaus.groovy.classgen.asm.OperandStack; import org.codehaus.groovy.classgen.asm.WriterController; import org.codehaus.groovy.classgen.asm.WriterControllerFactory; +import org.codehaus.groovy.control.SourceUnit; import org.codehaus.groovy.transform.stc.StaticTypesMarker; import org.objectweb.asm.Handle; import org.objectweb.asm.MethodVisitor; @@ -410,15 +412,21 @@ java.lang.ArrayIndexOutOfBoundsException: size==0 return staticTypesClosureWriter.createClosureClass(expression, mods); } -private static final class TransformationVisitor extends CorrectAccessedVariableVisitor { +private static final class TransformationVisitor extends ClassCodeVisitorSupport { +private CorrectAccessedVariableVisitor correctAccessedVariableVisitor; private Parameter enclosingThisParameter;
groovy git commit: Remove the unnecessary method `getClassVisitor`
Repository: groovy Updated Branches: refs/heads/native-lambda 9f51d3b3e -> 91448dd1e Remove the unnecessary method `getClassVisitor` Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/91448dd1 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/91448dd1 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/91448dd1 Branch: refs/heads/native-lambda Commit: 91448dd1e9ded947543eb6f415ba2b3cb727e774 Parents: 9f51d3b Author: sunlanAuthored: Wed Jan 31 18:28:53 2018 +0800 Committer: sunlan Committed: Wed Jan 31 18:28:53 2018 +0800 -- src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java | 3 --- 1 file changed, 3 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/91448dd1/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java -- diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java index 7721260..f658c72 100644 --- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java +++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java @@ -2181,7 +2181,4 @@ public class AsmClassGenerator extends ClassGenerator { return innerClasses.add(innerClass); } -public ClassVisitor getClassVisitor() { -return cv; -} }
groovy git commit: Refine STC of `call` method
Repository: groovy Updated Branches: refs/heads/native-lambda 37dc84543 -> 9f51d3b3e Refine STC of `call` method Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/9f51d3b3 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/9f51d3b3 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/9f51d3b3 Branch: refs/heads/native-lambda Commit: 9f51d3b3efa0c891b3bfba6ac23e684597caf6d3 Parents: 37dc845 Author: sunlanAuthored: Wed Jan 31 17:47:02 2018 +0800 Committer: sunlan Committed: Wed Jan 31 17:47:02 2018 +0800 -- .../transform/stc/StaticTypeCheckingVisitor.java| 16 +--- 1 file changed, 9 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/9f51d3b3/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java -- diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index dcb3ab6..e9ccffd 100644 --- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -281,13 +281,15 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { public static final MethodNode CLOSURE_CALL_ONE_ARG; public static final MethodNode CLOSURE_CALL_VARGS; +public static final String CALL = "call"; + static { // Cache closure call methods -CLOSURE_CALL_NO_ARG = CLOSURE_TYPE.getDeclaredMethod("call", Parameter.EMPTY_ARRAY); -CLOSURE_CALL_ONE_ARG = CLOSURE_TYPE.getDeclaredMethod("call", new Parameter[]{ +CLOSURE_CALL_NO_ARG = CLOSURE_TYPE.getDeclaredMethod(CALL, Parameter.EMPTY_ARRAY); +CLOSURE_CALL_ONE_ARG = CLOSURE_TYPE.getDeclaredMethod(CALL, new Parameter[]{ new Parameter(OBJECT_TYPE, "arg") }); -CLOSURE_CALL_VARGS = CLOSURE_TYPE.getDeclaredMethod("call", new Parameter[]{ +CLOSURE_CALL_VARGS = CLOSURE_TYPE.getDeclaredMethod(CALL, new Parameter[]{ new Parameter(OBJECT_TYPE.makeArray(), "args") }); } @@ -3404,7 +3406,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { } protected boolean isClosureCall(final String name, final Expression objectExpression, final Expression arguments) { -if (objectExpression instanceof ClosureExpression && ("call".equals(name)||"doCall".equals(name))) return true; +if (objectExpression instanceof ClosureExpression && (CALL.equals(name)||"doCall".equals(name))) return true; if (objectExpression == VariableExpression.THIS_EXPRESSION) { FieldNode fieldNode = typeCheckingContext.getEnclosingClassNode().getDeclaredField(name); if (fieldNode != null) { @@ -3414,7 +3416,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { } } } else { -if (!"call".equals(name) && !"doCall".equals(name)) return false; +if (!CALL.equals(name) && !"doCall".equals(name)) return false; } return (getType(objectExpression).equals(CLOSURE_TYPE)); } @@ -4119,9 +4121,9 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { collectAllInterfaceMethodsByName(receiver, name, methods); methods.addAll(OBJECT_TYPE.getMethods(name)); -if (ClassHelper.isSAMType(receiver)) { +if (CALL.equals(name) && ClassHelper.isSAMType(receiver)) { MethodNode sam = ClassHelper.findSAM(receiver); -MethodNode callMethodNode = new MethodNode("call", sam.getModifiers(), sam.getReturnType(), sam.getParameters(), sam.getExceptions(), sam.getCode()); +MethodNode callMethodNode = new MethodNode(CALL, sam.getModifiers(), sam.getReturnType(), sam.getParameters(), sam.getExceptions(), sam.getCode()); callMethodNode.setDeclaringClass(sam.getDeclaringClass()); callMethodNode.setSourcePosition(sam);