Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 266870

Summary: [encapsulate field] refactoring causes compilation error with generic methods
Product: [Eclipse Project] JDT Reporter: Jan Wloka <jan.wloka>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r
Version: 3.4.1   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard: stalebug

Description Jan Wloka CLA 2009-03-03 10:43:14 EST
Build ID: M20080911-1700

Steps To Reproduce:
The bug can be reproduced with the following example. Perform the "Encapsulate Field..." refactoring on field "elements".

public class Foo {
	static Collection<Boolean> elements;
	static {
		elements = Factory.make();
		elements.add(true);
		elements.add(false);
	}
}
class Factory {
	static <T> Collection<T> make() {
		return new HashSet<T>();
	}
}

The refactoring transforms the assignment in the static initializer block as follows
static {
    setElements(Factory.make());
   ...
}

The compiler complains about the type of the actual parameter of method setElements(). 




More information:
I guess type inference for generics in too complicated here, so that the correct transformation should result in: 
static {
    setElements(Factory.<Boolean>make());
   ...
}

I suppose to resolve the issue class AccessAnalyzer should instead of simply copying the right-hand side of a field assignment whenever 
    - it is a method invocation
    - of a static and parameterized method
    - with no specified type arguments
copy the method invocation and add all type arguments of the method's return type to it.
Comment 1 Frederic Fusier CLA 2009-03-03 10:54:09 EST
Move to JDT/UI
Comment 2 Markus Keller CLA 2009-03-04 08:27:50 EST
Whether explicit method type arguments are necessary can be determined using Invocations.isResolvedTypeInferredFromExpectedType(Expression).
Comment 3 Eclipse Genie CLA 2020-04-14 20:04:28 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.