Skip to content

Commit 52ccc79

Browse files
committed
Fix more CompletionWithMissingTypeTests
1 parent da5e877 commit 52ccc79

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Queue;
2929
import java.util.Set;
3030
import java.util.concurrent.ConcurrentHashMap;
31+
import java.util.function.Function;
3132
import java.util.function.Predicate;
3233
import java.util.stream.Collectors;
3334
import java.util.stream.Stream;
@@ -133,6 +134,7 @@
133134
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
134135
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
135136
import org.eclipse.jdt.core.search.IJavaSearchConstants;
137+
import org.eclipse.jdt.core.search.IJavaSearchScope;
136138
import org.eclipse.jdt.core.search.SearchEngine;
137139
import org.eclipse.jdt.core.search.SearchPattern;
138140
import org.eclipse.jdt.core.search.TypeNameMatch;
@@ -1598,7 +1600,7 @@ public void acceptTypeNameMatch(TypeNameMatch match) {
15981600
builder.append(Signature.C_GENERIC_END);
15991601
}
16001602
for (IType matchedType : types) {
1601-
processMembers(matchedType)
1603+
processMembers(matchedType, searchEngine, scope)
16021604
.map(member -> {
16031605
StringBuilder declaringSignature = new StringBuilder();
16041606
declaringSignature.append(member.getDeclarationSignature());
@@ -2536,18 +2538,46 @@ private void processMembers(ITypeBinding typeBinding, Bindings scope,
25362538
}
25372539
}
25382540

2539-
private Stream<CompletionProposal> processMembers(IType type) {
2541+
private Stream<CompletionProposal> processMembers(IType type, SearchEngine searchEngine, IJavaSearchScope scope) {
25402542
IJavaElement[] children;
25412543
try {
25422544
children = type.getChildren();
25432545
} catch (JavaModelException ex) {
25442546
ILog.get().error(ex.getMessage(), ex);
25452547
children = new IJavaElement[0];
25462548
}
2547-
return Arrays.stream(children)
2549+
Stream<CompletionProposal> current = Arrays.stream(children)
25482550
.filter(element -> element.getElementType() == IJavaElement.FIELD || element.getElementType() == IJavaElement.METHOD)
25492551
.filter(this::isVisible)
25502552
.map(this::toProposal);
2553+
List<String> superTypes = new ArrayList<>();
2554+
try {
2555+
superTypes.add(type.getSuperclassName());
2556+
superTypes.addAll(Arrays.asList(type.getSuperInterfaceNames()));
2557+
} catch (JavaModelException ex) {
2558+
ILog.get().error(ex.getMessage(), ex);
2559+
}
2560+
return Stream.concat(current, superTypes.stream()
2561+
.filter(Objects::nonNull)
2562+
.map(typeName -> {
2563+
int index = typeName.lastIndexOf('.');
2564+
char[] packageName = index >= 0 ? typeName.substring(0, index).toCharArray() : null;
2565+
char[] simpleName = index >= 0 ? typeName.substring(index + 1, typeName.length()).toCharArray() : typeName.toCharArray();
2566+
List<IType> types = new ArrayList<>();
2567+
try {
2568+
searchEngine.searchAllTypeNames(packageName, SearchPattern.R_EXACT_MATCH, simpleName, SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.TYPE, scope, new TypeNameMatchRequestor() {
2569+
@Override
2570+
public void acceptTypeNameMatch(TypeNameMatch match) {
2571+
types.add(match.getType());
2572+
}
2573+
}, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
2574+
} catch (JavaModelException ex) {
2575+
ILog.get().error(ex.getMessage(), ex);
2576+
}
2577+
return types;
2578+
}).flatMap(List::stream)
2579+
.map(t -> processMembers(t, searchEngine, scope))
2580+
.flatMap(Function.identity()));
25512581
}
25522582

25532583
private String getSignature(IMethodBinding method) {
@@ -3048,12 +3078,20 @@ private CompletionProposal toProposal(IJavaElement element) {
30483078
if (element instanceof IField field) {
30493079
res = createProposal(CompletionProposal.FIELD_REF);
30503080
res.setName(field.getElementName().toCharArray());
3081+
try {
3082+
res.setSignature(field.getTypeSignature().toCharArray());
3083+
} catch (JavaModelException ex) {
3084+
ILog.get().error(ex.getMessage(), ex);
3085+
}
30513086
res.setCompletion(field.getElementName().toCharArray());
30523087
setRange(res);
3053-
res.setRelevance(RelevanceConstants.R_DEFAULT +
3054-
RelevanceConstants.R_RESOLVED +
3055-
RelevanceConstants.R_INTERESTING +
3056-
RelevanceConstants.R_NON_RESTRICTED);
3088+
res.setRelevance(RelevanceConstants.R_DEFAULT +
3089+
RelevanceConstants.R_RESOLVED +
3090+
RelevanceConstants.R_INTERESTING +
3091+
RelevanceConstants.R_CASE +
3092+
RelevanceConstants.R_NON_STATIC +
3093+
RelevanceConstants.R_NON_RESTRICTED +
3094+
RelevanceConstants.R_NO_PROBLEMS);
30573095
}
30583096
if (element instanceof IMethod method) {
30593097
res = createProposal(CompletionProposal.METHOD_REF);

0 commit comments

Comments
 (0)