diff --git a/org.eclipse.jdt.core.tests.javac/projects/multiOut/.gitignore b/org.eclipse.jdt.core.tests.javac/projects/multiOut/.gitignore new file mode 100644 index 00000000000..f5ec0bda2d7 --- /dev/null +++ b/org.eclipse.jdt.core.tests.javac/projects/multiOut/.gitignore @@ -0,0 +1,2 @@ +bin +bin2 diff --git a/org.eclipse.jdt.core.tests.javac/projects/multiOut/bin/B.class b/org.eclipse.jdt.core.tests.javac/projects/multiOut/bin/B.class deleted file mode 100644 index 80ad36574e7..00000000000 Binary files a/org.eclipse.jdt.core.tests.javac/projects/multiOut/bin/B.class and /dev/null differ diff --git a/org.eclipse.jdt.core.tests.javac/projects/multiOut/bin2/A.class b/org.eclipse.jdt.core.tests.javac/projects/multiOut/bin2/A.class deleted file mode 100644 index a39a8cf3e71..00000000000 Binary files a/org.eclipse.jdt.core.tests.javac/projects/multiOut/bin2/A.class and /dev/null differ diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java index afff831f588..22a2a9573e2 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java @@ -1375,7 +1375,7 @@ private CompletionProposal toProposal(IBinding binding, String completion) { binding instanceof IMethodBinding methodBinding ? methodBinding.getReturnType() : binding instanceof IVariableBinding variableBinding ? variableBinding.getType() : this.toComplete.getAST().resolveWellKnownType(Object.class.getName())) + - RelevanceConstants.R_UNQUALIFIED + // TODO: add logic + computeRelevanceForQualification(false) + // TODO: is this always false? CompletionEngine.computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE) //no access restriction for class field //RelevanceConstants.R_NON_INHERITED // TODO: when is this active? ); @@ -1460,12 +1460,30 @@ private CompletionProposal toProposal(IType type) { } else if (this.toComplete instanceof MarkerAnnotation) { res.setTokenRange(this.offset, this.offset); } + boolean nodeInImports = DOMCompletionUtil.findParent(this.toComplete, new int[] { ASTNode.IMPORT_DECLARATION }) != null; + boolean fromCurrentCU = this.modelUnit.equals(type.getCompilationUnit()); + boolean typeIsImported = false; + boolean inSamePackage = false; + try { + typeIsImported = Stream.of(this.modelUnit.getImports()).anyMatch(id -> { + return id.getElementName().equals(type.getFullyQualifiedName()); + }); + IPackageDeclaration[] packageDecls = this.modelUnit.getPackageDeclarations(); + if (packageDecls != null && packageDecls.length > 0) { + inSamePackage = this.modelUnit.getPackageDeclarations()[0].getElementName().equals(type.getPackageFragment().getElementName()); + } else { + inSamePackage = type.getPackageFragment().getElementName().isEmpty(); + } + } catch (JavaModelException e) { + // there are sensible default set if accessing the model fails + } res.completionEngine = this.nestedEngine; res.nameLookup = this.nameEnvironment.nameLookup; int relevance = RelevanceConstants.R_DEFAULT + RelevanceConstants.R_RESOLVED + RelevanceConstants.R_INTERESTING - + RelevanceConstants.R_NON_RESTRICTED; + + RelevanceConstants.R_NON_RESTRICTED + + computeRelevanceForQualification(!nodeInImports && !fromCurrentCU && !inSamePackage && !typeIsImported); relevance += computeRelevanceForCaseMatching(this.prefix.toCharArray(), simpleName, this.assistOptions); try { if (type.isAnnotation()) { @@ -2059,6 +2077,17 @@ private CompletionProposal createLambdaExpressionProposal(IMethodBinding method) return res; } + private int computeRelevanceForQualification(boolean prefixRequired) { + boolean insideQualifiedReference = !this.prefix.equals(this.qualifiedPrefix); + if (!prefixRequired && !insideQualifiedReference) { + return RelevanceConstants.R_UNQUALIFIED; + } + if (prefixRequired && insideQualifiedReference) { + return RelevanceConstants.R_QUALIFIED; + } + return 0; + } + /** * Sets the replace and token ranges of the completion based on the contents of the buffer. *