[ 
https://issues.apache.org/jira/browse/GROOVY-8797?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16616450#comment-16616450
 ] 

Eric Milles commented on GROOVY-8797:
-------------------------------------

One use case for this is:
{code:groovy}
class C {
  static Object getFoo() {}
  static boolean isBar() {}
  static void setBaz(to) {}
  static void main(args) {
    foo
    bar // compiler error without property fix: "Apparent variable 'bar' was 
found in a static scope but doesn't refer to a local variable, static field or 
class."
    baz = null
  }
}
{code}

Here is my new version of {{getPropertyName}}:
{code:java}
    private static String getPropertyName(MethodNode m) {
        String name = m.getName();
        /* GRECLIPSE edit
        if (!(name.startsWith("set") || name.startsWith("get"))) return null;
        String pname = name.substring(3);
        if (pname.length() == 0) return null;
        pname = java.beans.Introspector.decapitalize(pname);

        if (name.startsWith("get") && (m.getReturnType() == 
ClassHelper.VOID_TYPE || m.getParameters().length != 0)) {
            return null;
        }
        if (name.startsWith("set") && m.getParameters().length != 1) {
            return null;
        }
        return pname;
        */
        if (name.startsWith("set") || name.startsWith("get") || 
name.startsWith("is")) {
            String pname = decapitalize(name.substring(name.startsWith("is") ? 
2 : 3));
            if (!pname.isEmpty()) {
                if (name.startsWith("set")) {
                    if (m.getParameters().length == 1) {
                        return pname;
                    }
                } else if (m.getParameters().length == 0 && 
!ClassHelper.VOID_TYPE.equals(m.getReturnType())) {
                    if (name.startsWith("get") || 
ClassHelper.boolean_TYPE.equals(m.getReturnType())) {
                        return pname;
                    }
                }
            }
        }
        return null;
    }
{code}

> VariableScopeVisitor.getPropertyName does not check for "isser" style method
> ----------------------------------------------------------------------------
>
>                 Key: GROOVY-8797
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8797
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.15, 3.0.0-alpha-3, 2.5.2
>            Reporter: Eric Milles
>            Priority: Minor
>
> Consider the following:
> {code:groovy}
> class C {
>   Object getFoo() {}
>   boolean isBar() {}
>   void setBaz(val) {}
>   void method() {
>     foo
>     bar
>     baz
>   }
> }
> {code}
> {{VariableScopeVisitor}} returns a {{PropertyNode}} from {{findClassMember}} 
> for {{foo}} and {{baz}}.  However, the {{bar}} reference is seen as a 
> {{MethodNode}}.  {{VariableScopeVisitor.getPropertyName}} only checks for 
> "get" and "set".  Could it check for "is" and {{boolean}} return?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to