Community
Participate
Working Groups
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.
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.
InternalCompletionContext is received from JDT Core via JavaContentAssistInvocationContext.getCoreContext(). Moving the bug to JDT Core.
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.
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.
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.
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>();
Bug tracker is moved to https://github.com/eclipse-jdt/eclipse.jdt.core/issues