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

Bug 349045

Summary: [1.7][extract local] Extract Local Variable must expand diamond type argument
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: UIAssignee: Raksha Vasisht <raksha.vasisht>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, markus.kell.r
Version: 3.7Flags: markus.kell.r: review+
Target Milestone: 3.7.1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Patch
none
Patch + tests none

Description Markus Keller CLA 2011-06-10 10:47:35 EDT
BETA_JAVA7

Extract Local Variable must expand the diamond type argument here:

	List<Integer> m() {
		return new ArrayList<>();
	}

Extract Method correctly uses ArrayList<Integer> as return type but Extract Local Variable produces an erroneous variable type:

		ArrayList<> arrayList = new ArrayList<>();
		return arrayList;
Comment 1 Raksha Vasisht CLA 2011-06-14 02:49:46 EDT
Created attachment 197940 [details]
Patch

Proposed fix.

Markus, could you pls review? I will add the tests if the fix is ok.
Comment 2 Markus Keller CLA 2011-06-21 08:22:09 EDT
The fix is at the right spot, but the typeBinding could theoretically be null (though I couldn't come up with an example that actually fails).

Nevertheless, the added check would better be this, so that in weird situations with non-compiling code, the user just gets the type from the CIC node:

    && (typeBinding == null || typeBinding.getTypeArguments().length == 0)

If you agree with this, please go ahead and release with the test(s) in ExtractTempTests17.
Comment 3 Raksha Vasisht CLA 2011-06-27 18:04:07 EDT
Created attachment 198693 [details]
Patch + tests

Patch with the null check + tests.
Comment 4 Raksha Vasisht CLA 2011-06-27 18:20:31 EDT
(In reply to comment #3)
> Created attachment 198693 [details] [diff]
> Patch + tests
> 
> Patch with the null check + tests.

Committed to HEAD.
Comment 5 Raksha Vasisht CLA 2011-06-27 18:21:49 EDT
> Committed to HEAD.

Oops,  I mean to BETA_JAVA7 branch.
Comment 6 Jay Arthanareeswaran CLA 2011-07-20 05:13:56 EDT
Verified.