groovy-eclipse icon indicating copy to clipboard operation
groovy-eclipse copied to clipboard

Fully qualified type name inserted in private final field declaration instead of import + simple name (disregarding workspace preference)

Open mauromol opened this issue 6 years ago • 5 comments

Variation of #866.

Consider this class:

package test50

class Test50 {
	
	String foo
	
	private final TreeNode|
}

Invoke code assist at "|" and choose javax.swing.tree.TreeNode. Once again, the fully qualified name is inserted instead of the import declaration.

mauromol avatar Apr 16 '19 10:04 mauromol

Different path through the parser. I'll see what I can do...

eric-milles avatar Apr 16 '19 15:04 eric-milles

The trouble is, Groovy considers this a complete field declaration:

@groovy.transform.ToString(includeFields=true)
class C {
  protected field
}

def cee = new C(field: 'value')

println cee​

http://docs.groovy-lang.org/latest/html/documentation/#fields

eric-milles avatar Apr 16 '19 15:04 eric-milles

But isn't "final" some kind of reserved word?

mauromol avatar Apr 16 '19 15:04 mauromol

The type is optional. So the parser interprets "private final TreeNode" as a field named "TreeNode" of type Object.

eric-milles avatar Apr 16 '19 15:04 eric-milles

I keep on hitting this problem. The presence of private (even without final) is sufficient to trigger it. I understand the cause (the parser interprets "private TreeNode" as a field named "TreeNode"), but once content assist is triggered and confirmed, why should it ignore the option to insert the import statement instead of the FQN? After all, if the insertion is performed, in some way the tools is recognizing TreeNode as a type at that time...

mauromol avatar Aug 23 '19 10:08 mauromol