Skip to content

Wrong detection of field vs setter access within closure #366

@mauromol

Description

@mauromol

This was (part of) the old GRECLIPSE-1766

Consider the following code:

package o 

class O { 
	String foo 
	
	void setFoo(String foo) { 
		println "setter called: $foo" 
		this.foo = foo // (A)  
	} 
	
	void doSomething() { 
		println 'setting foo to "foo"' 
		foo = 'foo' // (B)  
		println 'setting foo to "bar"' 
		def c = { foo = 'bar' } // (C)  
		c() 
	} 
	
	static void main(String[] args) { 
		O o = new O() 
		println 'invoking doSomething()' 
		o.doSomething() 
		println 'setting foo to "foobar"' 
		o.foo = 'foobar' // (D)  
	} 
} 

In (A) and (B) the foo field is accessed directly and Greclipse correctly detects this (by colouring it accordingly, by showing this fact when you hover over foo and/or press F2 and by providing the correct navigation with F3).
In (C) and (D), instead, the foo field is accessed through its setter. While in (D) Greclipse correctly determines that (i.e.: it uses a different colour, F2 and F3 work correctly), in (C) Greclipse thinks that foo is accessed directly, but this is not the case, as you can test by running the main method.

This might appear a trivial problem, but it can be very useful for the developer to distinguish between the two cases, especially (as an example) when foo is annotated with @Bindable: in (C) and (D) listeners will be invoked, in (A) and (B) they won't.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions