Bug 552884 - [content assist] Generic constructor invocation proposal doesn't use diamond operator
Summary: [content assist] Generic constructor invocation proposal doesn't use diamond ...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.14   Edit
Hardware: PC Windows NT
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-10 06:39 EST by Mateusz Matela CLA
Modified: 2024-05-10 13:16 EDT (History)
4 users (show)

See Also:


Attachments
quickfix screenshot (71.29 KB, image/jpeg)
2024-05-10 13:06 EDT, Alexander Krivchenko CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mateusz Matela CLA 2019-11-10 06:39:46 EST
Using latest build I20191109-1800, a new workspace, everything by default, a new Java 8 project with this code:

import java.util.ArrayList;
public class Test {
	private ArrayList<Integer> aa = new Array
}

Hitting Ctrl+Space after Array and using the first proposal results in

	private ArrayList<Integer> aa = new ArrayList<Integer>()

Expected result:

	private ArrayList<Integer> aa = new ArrayList<>()

In some installation/workspace instances it works as expected, but I couldn't determine if it depends on configuration or version or something else.

It's quite annoying because it's a frequently used construct.

If there is a setting for this, the default should be changed.
Comment 1 Gayan Perera CLA 2021-01-10 14:48:13 EST
The problems lies in org.eclipse.jdt.internal.codeassist.InternalCompletionProposal.canUseDiamond(CompletionContext)

The InternalCompletionContext we receive here doesn't have a extended context which result it not using the diamond operator.
Comment 2 Noopur Gupta CLA 2021-01-11 02:13:51 EST
InternalCompletionContext is received from JDT Core via JavaContentAssistInvocationContext.getCoreContext(). 

Moving the bug to JDT Core.
Comment 3 Gayan Perera CLA 2021-01-12 17:13:24 EST
This is fixed in 4.19 at least. I didn't checked in 4.18. I got this problem because of my own completion requester. 

The reason with my own computer was that i call context.getCoreContext(), but at that time the core context is not initialized and therefore a dummy one get init from org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext.computeKeywordsAndContext()

This doesn't has a extended context in it. The workaround i had to take was to do this before i call the getCoreContext.

		CompletionProposalCollector collector = new CompletionProposalCollector(ctx.getCompilationUnit(), true);
		collector.setRequireExtendedContext(true);
		collector.setInvocationContext(ctx);
		ICompilationUnit cu = ctx.getCompilationUnit();
		int offset = ctx.getInvocationOffset();
		try {
			cu.codeComplete(offset, collector, new NullProgressMonitor());
		} catch (JavaModelException e) {
			// try to continue
		}


I not sure adding this to multiple custom computers and how it will effect the completion performance.

Please let me know if this is something we should fix.
Comment 4 Eclipse Genie CLA 2023-02-07 20:23:48 EST
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.

If you have further information on the current state of the bug, please add it. 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.
Comment 5 Alexander Krivchenko CLA 2024-05-09 07:10:15 EDT
The problem is still there.

Version: 2024-03 (4.31.0)
Build id: 20240307-1437

Java17 project doesn't use diamond operator with auto completion.
Comment 6 Alexander Krivchenko CLA 2024-05-10 13:06:19 EDT
Created attachment 289395 [details]
quickfix screenshot

If it matters, Eclipse quickfix also don't use the diamond operator.

List<Integer> list = new ArrayList();

fixed by Eclipse as:
List<Integer> list = new ArrayList<Integer>();
Comment 7 Andrey Loskutov CLA 2024-05-10 13:16:44 EDT
Bug tracker is moved to
https://github.com/eclipse-jdt/eclipse.jdt.core/issues