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

Eric Milles edited comment on GROOVY-8797 at 9/15/18 8:50 PM:
--------------------------------------------------------------

Also, {{findClassMember}} could set the correct type of the property, set the 
declaring class of the property, and indicate the fact that there isn't really 
a field.
{code:java}
    private Variable findClassMember(ClassNode cn, String name) {
        if (cn == null) return null;
        if (cn.isScript()) {
            return new DynamicVariable(name, false);
        }

        for (FieldNode fn : cn.getFields()) {
            if (fn.getName().equals(name)) return fn;
        }

        for (MethodNode mn : cn.getMethods()) {
            String pName = getPropertyName(mn);
            // GRECLIPSE edit
            //if (pName != null && pName.equals(name))
            //    return new PropertyNode(pName, mn.getModifiers(), 
ClassHelper.OBJECT_TYPE, cn, null, null, null);
            if (name.equals(pName)) {
                PropertyNode property = new PropertyNode(name, 
mn.getModifiers(), getPropertyType(mn), cn, null, null, null);
                property.getField().setHasNoRealSourcePosition(true); 
property.getField().setSynthetic(true);
                property.getField().setDeclaringClass(cn);
                property.setDeclaringClass(cn);
                return property;
            }
            // GRECLIPSE end
        }
        ...
    }

    private static String getPropertyName(MethodNode m) {
        ...
    }

    // GRECLIPSE add
    private static ClassNode getPropertyType(MethodNode m) {
        if (ClassHelper.VOID_TYPE.equals(m.getReturnType())) {
            return m.getParameters()[0].getType();
        }
        return m.getReturnType();
    }
    // GRECLIPSE end
{code}


was (Author: emilles):
Also, {{findClassMember}} could set the correct type of the property, set the 
declaring class of the property, and indicate the fact that there isn't really 
a field.
{code:java}
    private Variable findClassMember(ClassNode cn, String name) {
        if (cn == null) return null;
        if (cn.isScript()) {
            return new DynamicVariable(name, false);
        }

        for (FieldNode fn : cn.getFields()) {
            if (fn.getName().equals(name)) return fn;
        }

        for (MethodNode mn : cn.getMethods()) {
            String pName = getPropertyName(mn);
            // GRECLIPSE edit
            //if (pName != null && pName.equals(name))
            //    return new PropertyNode(pName, mn.getModifiers(), 
ClassHelper.OBJECT_TYPE, cn, null, null, null);
            if (name.equals(pName)) {
                PropertyNode property = new PropertyNode(name, 
mn.getModifiers(), getPropertyType(mn), cn, null, null, null);
                property.getField().setDeclaringClass(cn);
                property.getField().setSynthetic(true);
                property.setDeclaringClass(cn);
                return property;
            }
            // GRECLIPSE end
        }
        ...
    }

    private static String getPropertyName(MethodNode m) {
        ...
    }

    // GRECLIPSE add
    private static ClassNode getPropertyType(MethodNode m) {
        if (ClassHelper.VOID_TYPE.equals(m.getReturnType())) {
            return m.getParameters()[0].getType();
        }
        return m.getReturnType();
    }
    // GRECLIPSE end
{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