|
28 | 28 | import java.util.Queue; |
29 | 29 | import java.util.Set; |
30 | 30 | import java.util.concurrent.ConcurrentHashMap; |
| 31 | +import java.util.function.Function; |
31 | 32 | import java.util.function.Predicate; |
32 | 33 | import java.util.stream.Collectors; |
33 | 34 | import java.util.stream.Stream; |
|
133 | 134 | import org.eclipse.jdt.core.dom.VariableDeclarationStatement; |
134 | 135 | import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; |
135 | 136 | import org.eclipse.jdt.core.search.IJavaSearchConstants; |
| 137 | +import org.eclipse.jdt.core.search.IJavaSearchScope; |
136 | 138 | import org.eclipse.jdt.core.search.SearchEngine; |
137 | 139 | import org.eclipse.jdt.core.search.SearchPattern; |
138 | 140 | import org.eclipse.jdt.core.search.TypeNameMatch; |
@@ -1598,7 +1600,7 @@ public void acceptTypeNameMatch(TypeNameMatch match) { |
1598 | 1600 | builder.append(Signature.C_GENERIC_END); |
1599 | 1601 | } |
1600 | 1602 | for (IType matchedType : types) { |
1601 | | - processMembers(matchedType) |
| 1603 | + processMembers(matchedType, searchEngine, scope) |
1602 | 1604 | .map(member -> { |
1603 | 1605 | StringBuilder declaringSignature = new StringBuilder(); |
1604 | 1606 | declaringSignature.append(member.getDeclarationSignature()); |
@@ -2536,18 +2538,46 @@ private void processMembers(ITypeBinding typeBinding, Bindings scope, |
2536 | 2538 | } |
2537 | 2539 | } |
2538 | 2540 |
|
2539 | | - private Stream<CompletionProposal> processMembers(IType type) { |
| 2541 | + private Stream<CompletionProposal> processMembers(IType type, SearchEngine searchEngine, IJavaSearchScope scope) { |
2540 | 2542 | IJavaElement[] children; |
2541 | 2543 | try { |
2542 | 2544 | children = type.getChildren(); |
2543 | 2545 | } catch (JavaModelException ex) { |
2544 | 2546 | ILog.get().error(ex.getMessage(), ex); |
2545 | 2547 | children = new IJavaElement[0]; |
2546 | 2548 | } |
2547 | | - return Arrays.stream(children) |
| 2549 | + Stream<CompletionProposal> current = Arrays.stream(children) |
2548 | 2550 | .filter(element -> element.getElementType() == IJavaElement.FIELD || element.getElementType() == IJavaElement.METHOD) |
2549 | 2551 | .filter(this::isVisible) |
2550 | 2552 | .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())); |
2551 | 2581 | } |
2552 | 2582 |
|
2553 | 2583 | private String getSignature(IMethodBinding method) { |
@@ -3048,12 +3078,20 @@ private CompletionProposal toProposal(IJavaElement element) { |
3048 | 3078 | if (element instanceof IField field) { |
3049 | 3079 | res = createProposal(CompletionProposal.FIELD_REF); |
3050 | 3080 | 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 | + } |
3051 | 3086 | res.setCompletion(field.getElementName().toCharArray()); |
3052 | 3087 | 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); |
3057 | 3095 | } |
3058 | 3096 | if (element instanceof IMethod method) { |
3059 | 3097 | res = createProposal(CompletionProposal.METHOD_REF); |
|
0 commit comments