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

Bug 579588

Summary: [completion] wrong setting of relevance for created type proposal
Product: [Eclipse Project] JDT Reporter: Jeff Johnston <jjohnstn>
Component: UIAssignee: Jeff Johnston <jjohnstn>
Status: VERIFIED FIXED QA Contact: Jeff Johnston <jjohnstn>
Severity: normal    
Priority: P3 CC: kalyan_prasad
Version: 4.23   
Target Milestone: 4.24 M2   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/192524
https://bugs.eclipse.org/bugs/show_bug.cgi?id=578815
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=567c1546ee76fbbd4a50ee6b0de8e046a19356fe
Whiteboard:

Description Jeff Johnston CLA 2022-04-05 19:31:59 EDT
In JavaTypeCompletionProposalComputer.computeCompletionProposals() a loop figures out the minimum relevance of all the existing proposals.  It is done using getRelevance() calls.  If a type proposal is created, the relevance used is such to be lower than the minimum relevance calculated earlier.  It creates either a TYPE_REF proposal that is wrapped in either a LazyGenericTypeProposal or a LazyJavaTypeCompletionProposal.  The problem is that the initial relevance set gets massaged on first access which involves multiplying by 16 and adding a constant.  The minimum relevance value has already been massaged but when we use it to set the TYPE_REF proposal, the lazy classes will massage the value on first reference which will multiply by 16 and then add a constant to make a value that is no longer below the minimum value and can end up showing up as the first entry for the end-user.  The relevance must be set in the lazy classes directly so no further massaging is done.

For the following:

package tests;

public interface CompletionSubClass1 {

}

-------------------------------------------------

package tests;

public class CompletionSubClass2 implements CompletionSubClass1 {

}

-------------------------------------------------

package tests;

public class CompletionClass {

	public void foo() {
		CompletionSubClass1 k = new <== completion here
	}
}


When completion occurs, it puts a type proposal first which is not the most relevant as there are constructor completions in the list which should be offered first.
Comment 1 Eclipse Genie CLA 2022-04-05 19:37:10 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/192524
Comment 3 Jeff Johnston CLA 2022-05-04 18:15:04 EDT
Verified for 4.24 M2 using I20220504 build