Skip to content

Commit

Permalink
In type completion, filter by unique FQN
Browse files Browse the repository at this point in the history
Should fix 6 cases without regressions,
because one of the projects used to test completion
has two classes called `SuperClass` in the
default package.

Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 committed Jan 31, 2025
1 parent 40594bf commit 21e71c9
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Optional;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -94,6 +95,7 @@
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.MethodRef;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
import org.eclipse.jdt.core.dom.ModuleDeclaration;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.NormalAnnotation;
Expand Down Expand Up @@ -126,7 +128,6 @@
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.SearchEngine;
Expand Down Expand Up @@ -1452,6 +1453,7 @@ public void complete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sour
? IJavaSearchConstants.ANNOTATION_TYPE
: IJavaSearchConstants.TYPE;
if (!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
final Set<String> alreadySuggestedFqn = ConcurrentHashMap.newKeySet();
findTypes(completeAfter, typeMatchRule, null)
.filter(type -> filterTypeBasedOnAccess(type, currentPackage, currentTypeBinding))
.filter(type -> {
Expand All @@ -1469,6 +1471,13 @@ public void complete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sour
.filter(type -> {
return filterBasedOnExtendsOrImplementsInfo(type, extendsOrImplementsInfo);
})
.filter(type -> {
if (alreadySuggestedFqn.contains(type.getFullyQualifiedName())) {
return false;
}
alreadySuggestedFqn.add(type.getFullyQualifiedName());
return true;
})
.map(this::toProposal).forEach(this.requestor::accept);
}
}
Expand Down

0 comments on commit 21e71c9

Please sign in to comment.