You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by mgroovy <gi...@git.apache.org> on 2018/04/17 21:18:32 UTC

[GitHub] groovy pull request #686: @Newify table name pattern support

GitHub user mgroovy opened a pull request:

    https://github.com/apache/groovy/pull/686

    @Newify table name pattern support

    Added class name pattern parameter support to `@Newify` annotation (e.g. `@Newify(pattern=/[A-Z].*/)`) that allows users to define the classes with newify support through the pattern in addition to the existing class list parameter.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/mgroovy/groovy mgroovy_newify_pattern

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/686.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #686
    
----
commit d0775888e1162d3378fedfb7ecf38797c82aa197
Author: mgroovy <31...@...>
Date:   2018-04-10T22:36:28Z

    @Newify: classNamePattern support for imported and inner classes

commit 9dad89ddeda8766e25e8bc62c9bf5a06fd4ffe00
Author: mgroovy <31...@...>
Date:   2018-04-10T22:36:28Z

    @Newify: classNamePattern support for imported and inner classes

commit 9eeaf2b976f61e45e12570304fade3b01d1a7b61
Author: mgroovy <31...@...>
Date:   2018-04-11T01:14:40Z

    Merge branch 'mgroovy_newify_pattern' of https://github.com/mgroovy/groovy into mgroovy_newify_pattern

commit 66431efbe748781d9d86f79454c40918e941f937
Author: mgroovy <31...@...>
Date:   2018-04-14T12:04:29Z

    @Newify: classNamePattern support for imported and inner classes - all cases working, when explicitely passing outer class this argument to non-static inner class ctors

commit 382586875fa824bd6a495e6b7754aad4bba56b87
Author: mgroovy <31...@...>
Date:   2018-04-17T00:22:42Z

    @Newify classNamePattern: supporting all cases (imported/inner/global) + documentation with too-lenient pattern warning [NewifyTransformBlackBoxTest]

commit 9f06e2d7ddedce93659d89149c0a2522635d62fa
Author: mgroovy <31...@...>
Date:   2018-04-17T20:47:45Z

    Merge branch 'master' of https://github.com/apache/groovy into mgroovy_newify_pattern
    
    merǵed with Groovy master

----


---

[GitHub] groovy pull request #686: @Newify table name pattern support

Posted by mgroovy <gi...@git.apache.org>.
Github user mgroovy commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/686#discussion_r182729445
  
    --- Diff: src/main/java/org/codehaus/groovy/transform/NewifyASTTransformation.java ---
    @@ -196,39 +322,10 @@ private boolean shouldTransform(DeclarationExpression exp) {
         }
     
         private boolean hasClassesToNewify() {
    -        return classesToNewify != null && !classesToNewify.getExpressions().isEmpty();
    +        return (classesToNewify != null && !classesToNewify.getExpressions().isEmpty()) || (classNamePattern != null); // 2018-04-07 TODO: Check if classNamePattern != null can be made more "early out"
    --- End diff --
    
    This TODO refers to e.g. an edge case optimization to defer the class name Pattern compilation to the point where is actually accessed. I don't expect this to make sense (also I am now checking against the class name pattern before checking against the class name list, since I expect this to be faster in practice), so I have not implemented it. Should probaly not be a TODO any more, but at most a regular comment, I can change this and redo the PR if you want. 


---

[GitHub] groovy pull request #686: @Newify table name pattern support

Posted by mgroovy <gi...@git.apache.org>.
Github user mgroovy commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/686#discussion_r182731442
  
    --- Diff: src/main/java/org/codehaus/groovy/transform/NewifyASTTransformation.java ---
    @@ -286,31 +372,106 @@ private static boolean isNewMethodStyle(MethodCallExpression mce) {
                     && ((ConstantExpression) meth).getValue().equals("new"));
         }
     
    -    private Expression transformMethodCall(MethodCallExpression mce, Expression args) {
    +    private Expression transformMethodCall(MethodCallExpression mce, Expression argsExp) {
             ClassNode classType;
    +
             if (isNewMethodStyle(mce)) {
                 classType = mce.getObjectExpression().getType();
    -        } else {
    +        }
    +        else {
                 classType = findMatchingCandidateClass(mce);
             }
    +        
             if (classType != null) {
    -            return new ConstructorCallExpression(classType, args);
    +            Expression argsToUse = argsExp;
    +            //if(classType.getOuterClass() != null && !classType.isStaticClass()) {
    +            if(classType.getOuterClass() != null && ((classType.getModifiers() & org.objectweb.asm.Opcodes.ACC_STATIC) == 0)) {
    +                if(!(argsExp instanceof ArgumentListExpression)) {
    +                    addError("Non-static inner constructor arguments must be an argument list expression; pass 'this' pointer explicitely as first constructor argument otherwise.", mce);
    +                    return mce; // TODO: Expected behavior to return  the untransformed method call here ?
    --- End diff --
    
    This is the first Groovy extension I am doing on my own, and I took this code part from existing Groovy code, and wanted to make sure somebody more experienced had a look at this. If you say this code is fine, then the TODO can be removed (see above comment).


---

[GitHub] groovy pull request #686: @Newify table name pattern support

Posted by mgroovy <gi...@git.apache.org>.
Github user mgroovy closed the pull request at:

    https://github.com/apache/groovy/pull/686


---

[GitHub] groovy pull request #686: @Newify table name pattern support

Posted by danielsun1106 <gi...@git.apache.org>.
Github user danielsun1106 commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/686#discussion_r182659937
  
    --- Diff: src/main/java/org/codehaus/groovy/transform/NewifyASTTransformation.java ---
    @@ -286,31 +372,106 @@ private static boolean isNewMethodStyle(MethodCallExpression mce) {
                     && ((ConstantExpression) meth).getValue().equals("new"));
         }
     
    -    private Expression transformMethodCall(MethodCallExpression mce, Expression args) {
    +    private Expression transformMethodCall(MethodCallExpression mce, Expression argsExp) {
             ClassNode classType;
    +
             if (isNewMethodStyle(mce)) {
                 classType = mce.getObjectExpression().getType();
    -        } else {
    +        }
    +        else {
                 classType = findMatchingCandidateClass(mce);
             }
    +        
             if (classType != null) {
    -            return new ConstructorCallExpression(classType, args);
    +            Expression argsToUse = argsExp;
    +            //if(classType.getOuterClass() != null && !classType.isStaticClass()) {
    +            if(classType.getOuterClass() != null && ((classType.getModifiers() & org.objectweb.asm.Opcodes.ACC_STATIC) == 0)) {
    +                if(!(argsExp instanceof ArgumentListExpression)) {
    +                    addError("Non-static inner constructor arguments must be an argument list expression; pass 'this' pointer explicitely as first constructor argument otherwise.", mce);
    +                    return mce; // TODO: Expected behavior to return  the untransformed method call here ?
    --- End diff --
    
    Similarly, I see `TODO` here, are you going to refine it later? ;-)


---

[GitHub] groovy pull request #686: @Newify table name pattern support

Posted by danielsun1106 <gi...@git.apache.org>.
Github user danielsun1106 commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/686#discussion_r182659807
  
    --- Diff: src/main/java/org/codehaus/groovy/transform/NewifyASTTransformation.java ---
    @@ -196,39 +322,10 @@ private boolean shouldTransform(DeclarationExpression exp) {
         }
     
         private boolean hasClassesToNewify() {
    -        return classesToNewify != null && !classesToNewify.getExpressions().isEmpty();
    +        return (classesToNewify != null && !classesToNewify.getExpressions().isEmpty()) || (classNamePattern != null); // 2018-04-07 TODO: Check if classNamePattern != null can be made more "early out"
    --- End diff --
    
    I see `TODO` here, are you going to refine it later?


---