[jira] [Commented] (GROOVY-8490) Extend @Newify to support a class name pattern parameter
[ https://issues.apache.org/jira/browse/GROOVY-8490?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16386801#comment-16386801 ] mgroovy commented on GROOVY-8490: - * I would apply the pattern against the name the developer uses in his code, which is least surprise imho * Also, if the user defines an alias, that is evidently what he wants to work with. * In your example Bar() would throw the MME. > Extend @Newify to support a class name pattern parameter > > > Key: GROOVY-8490 > URL: https://issues.apache.org/jira/browse/GROOVY-8490 > Project: Groovy > Issue Type: Improvement > Components: Compiler >Reporter: mgroovy >Priority: Major > > * @Newify should be extended to support a classNamePattern parameter > * All class names inside e.g. a @Newify annotated class that match the given > pattern shall support having its ctor called without the new keyword ("Python > style") > * Example: > {code} > @Newify(classNamePattern=/[A-Z].*/) > class Foo { > // Any class whose name starts with an uppercase letter > // can have its ctors called without new keyword inside Foo > > String s > Integer x > File f > > Foo(String s, File f, Integer x) { > this.s = s > this.f = f > this.x = x > } > > void createFoo(File base) { > // Java style > new Foo(new String('abc'), new File(base,'log'), new Integer(123)) > // new Groovy style > Foo(String('abc'), File(base,'log'), Integer(123)) > } > } > {code} > * The classNamePattern parameter: > ## Is 100% backwards compatible (same as the existing value parameter) > ## Would allow e.g. @Newify(classNamePattern=/[A-Z].*/) to be auto-applied to > all classes in a project (same as e.g. @AutoFinal (GROOVY-8300)) > *** In practice that would typically cover 99.9...% of all classes, since > most projects follow the Java convention of classes being the only callable > entities to start with an uppercase letter > *** The existing value parameter cannot be used that way on a global level, > since it is not practical to explicitly list all project classes > ## Compile time performance wise classNamePattern=/[A-Z].*/ avoids having to > check any (method/field/variable)() call whether it is a class ctor call if > it is lowercase (i.e. again typically in 99.9...% of cases), i.e. the > approach is fast -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (GROOVY-8490) Extend @Newify to support a class name pattern parameter
[ https://issues.apache.org/jira/browse/GROOVY-8490?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16385872#comment-16385872 ] Daniil Ovchinnikov commented on GROOVY-8490: {code} import com.foo.Bar import com.foo.Bar as Baz @Newify(classNamePattern=/Baz/) def usage() { Bar() Baz() } {code} Which one of the invocations should throw MME? In other words, should the pattern be tested against the reference name or the class name? > Extend @Newify to support a class name pattern parameter > > > Key: GROOVY-8490 > URL: https://issues.apache.org/jira/browse/GROOVY-8490 > Project: Groovy > Issue Type: Improvement > Components: Compiler >Reporter: mgroovy >Priority: Major > > * @Newify should be extended to support a classNamePattern parameter > * All class names inside e.g. a @Newify annotated class that match the given > pattern shall support having its ctor called without the new keyword ("Python > style") > * Example: > {code} > @Newify(classNamePattern=/[A-Z].*/) > class Foo { > // Any class whose name starts with an uppercase letter > // can have its ctors called without new keyword inside Foo > > String s > Integer x > File f > > Foo(String s, File f, Integer x) { > this.s = s > this.f = f > this.x = x > } > > void createFoo(File base) { > // Java style > new Foo(new String('abc'), new File(base,'log'), new Integer(123)) > // new Groovy style > Foo(String('abc'), File(base,'log'), Integer(123)) > } > } > {code} > * The classNamePattern parameter: > ## Is 100% backwards compatible (same as the existing value parameter) > ## Would allow e.g. @Newify(classNamePattern=/[A-Z].*/) to be auto-applied to > all classes in a project (same as e.g. @AutoFinal (GROOVY-8300)) > *** In practice that would typically cover 99.9...% of all classes, since > most projects follow the Java convention of classes being the only callable > entities to start with an uppercase letter > *** The existing value parameter cannot be used that way on a global level, > since it is not practical to explicitly list all project classes > ## Compile time performance wise classNamePattern=/[A-Z].*/ avoids having to > check any (method/field/variable)() call whether it is a class ctor call if > it is lowercase (i.e. again typically in 99.9...% of cases), i.e. the > approach is fast -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (GROOVY-8490) Extend @Newify to support a class name pattern parameter
[ https://issues.apache.org/jira/browse/GROOVY-8490?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16385408#comment-16385408 ] mgroovy commented on GROOVY-8490: - Could be combined with > Extend @Newify to support a class name pattern parameter > > > Key: GROOVY-8490 > URL: https://issues.apache.org/jira/browse/GROOVY-8490 > Project: Groovy > Issue Type: Improvement > Components: Compiler >Reporter: mgroovy >Priority: Major > > * @Newify should be extended to support a classNamePattern parameter > * All class names inside e.g. a @Newify annotated class that match the given > pattern shall support having its ctor called without the new keyword ("Python > style") > * Example: > {code} > @Newify(classNamePattern=/[A-Z].*/) > class Foo { > // Any class whose name starts with an uppercase letter > // can have its ctors called without new keyword inside Foo > > String s > Integer x > File f > > Foo(String s, File f, Integer x) { > this.s = s > this.f = f > this.x = x > } > > void createFoo(File base) { > // Java style > new Foo(new String('abc'), new File(base,'log'), new Integer(123)) > // new Groovy style > Foo(String('abc'), File(base,'log'), Integer(123)) > } > } > {code} > * The classNamePattern parameter: > ## Is 100% backwards compatible (same as the existing value parameter) > ## Would allow e.g. @Newify(classNamePattern=/[A-Z].*/) to be auto-applied to > all classes in a project (same as e.g. [#GROOVY-8300]) > *** In practice that would typically cover 99.9...% of all classes, since > most projects follow the Java convention of classes being the only callable > entities to start with an uppercase letter > *** The existing value parameter cannot be used that way on a global level, > since it is not practical to explicitly list all project classes > ## Compile time performance wise classNamePattern=/[A-Z].*/ avoids having to > check any (method/field/variable)() call whether it is a class ctor call if > it is lowercase (i.e. again typically in 99.9...% of cases), i.e. the > approach is fast -- This message was sent by Atlassian JIRA (v7.6.3#76005)