Skip to content

Commit

Permalink
Fix some bugs in completion type filtering
Browse files Browse the repository at this point in the history
- Do prefix filtering first; string comparison should be fast compared
  to more involved operations
- Fix bad implementation of `protected` member classes;
  `getParent()` wasn't the right method to get the parent class of a
  member class
- Impossible classes filtering was wrong, it was checking methods
  instead

Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 authored and mickaelistria committed Feb 2, 2025
1 parent 463716e commit 15d0bf3
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,8 @@ public void complete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sour
if (!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
final Set<String> alreadySuggestedFqn = ConcurrentHashMap.newKeySet();
findTypes(completeAfter, typeMatchRule, null)
.filter(type -> this.pattern.matchesName(this.prefix.toCharArray(),
type.getElementName().toCharArray()))
.filter(type -> filterTypeBasedOnAccess(type, currentPackage, currentTypeBinding))
.filter(type -> {
for (var scrapedBinding : defaultCompletionBindings.all().toList()) {
Expand All @@ -1467,8 +1469,6 @@ public void complete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sour
}
return true;
})
.filter(type -> this.pattern.matchesName(this.prefix.toCharArray(),
type.getElementName().toCharArray()))
.filter(type -> {
return filterBasedOnExtendsOrImplementsInfo(type, extendsOrImplementsInfo);
})
Expand Down Expand Up @@ -1541,11 +1541,11 @@ private boolean filterTypeBasedOnAccess(IType type, String currentPackage, IType
return true;
}
if ((flags & Flags.AccProtected) != 0) {
// protected means `type` is an inner class
if (currentTypeBinding == null) {
// if `protected` is used correctly means `type` is an inner class
if (currentTypeBinding == null || type.getDeclaringType() == null) {
return false;
}
return findInSupers(currentTypeBinding, ((IType)type.getParent()).getKey());
return findInSupers(currentTypeBinding, type.getDeclaringType().getKey());
}
// private inner class
return false;
Expand Down Expand Up @@ -2311,7 +2311,7 @@ private void processMembers(ITypeBinding typeBinding, Bindings scope,
return false;
}
} else {
if (impossibleMethods.contains(binding.getName())) {
if (impossibleClasses.contains(binding.getName())) {
return false;
}
}
Expand Down

0 comments on commit 15d0bf3

Please sign in to comment.