|
86 | 86 | import org.eclipse.jdt.core.dom.ContinueStatement; |
87 | 87 | import org.eclipse.jdt.core.dom.DoStatement; |
88 | 88 | import org.eclipse.jdt.core.dom.EnhancedForStatement; |
| 89 | +import org.eclipse.jdt.core.dom.EnumConstantDeclaration; |
89 | 90 | import org.eclipse.jdt.core.dom.EnumDeclaration; |
90 | 91 | import org.eclipse.jdt.core.dom.Expression; |
91 | 92 | import org.eclipse.jdt.core.dom.ExpressionMethodReference; |
@@ -282,17 +283,7 @@ public Stream<CompletionProposal> toProposals() { |
282 | 283 | public Stream<CompletionProposal> toProposals(boolean expectedOnly) { |
283 | 284 |
|
284 | 285 | // Needed to tell if `this` should be used |
285 | | - List<ITypeBinding> parentTypeBinding = new ArrayList<>(); |
286 | | - ASTNode cursor = DOMCompletionEngine.this.toComplete; |
287 | | - while (DOMCompletionUtils.findParentTypeDeclaration(cursor) != null) { |
288 | | - ASTNode parentTypeDeclaration = DOMCompletionUtils.findParentTypeDeclaration(cursor); |
289 | | - if (parentTypeDeclaration instanceof AbstractTypeDeclaration typeDecl) { |
290 | | - parentTypeBinding.add(typeDecl.resolveBinding()); |
291 | | - } else { |
292 | | - parentTypeBinding.add(((AnonymousClassDeclaration)parentTypeDeclaration).resolveBinding()); |
293 | | - } |
294 | | - cursor = parentTypeDeclaration.getParent(); |
295 | | - } |
| 286 | + List<ITypeBinding> parentTypeBinding = DOMCompletionUtils.getParentTypeDeclarations(DOMCompletionEngine.this.toComplete); |
296 | 287 |
|
297 | 288 | return all() // |
298 | 289 | .filter(binding -> pattern.matchesName(prefix.toCharArray(), binding.getName().toCharArray())) // |
@@ -743,6 +734,7 @@ public void complete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sour |
743 | 734 | || simpleName.getParent() instanceof ContinueStatement |
744 | 735 | || simpleName.getParent() instanceof MarkerAnnotation |
745 | 736 | || simpleName.getParent() instanceof AnnotationTypeMemberDeclaration |
| 737 | + || simpleName.getParent() instanceof EnumConstantDeclaration |
746 | 738 | || ((simpleName.getLocationInParent() == SwitchCase.EXPRESSIONS2_PROPERTY || simpleName.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) && simpleName.getParent() instanceof SwitchCase)) { |
747 | 739 | if (!this.toComplete.getLocationInParent().getId().equals(QualifiedName.QUALIFIER_PROPERTY.getId())) { |
748 | 740 | context = this.toComplete.getParent(); |
@@ -956,6 +948,8 @@ public void complete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sour |
956 | 948 | case SwitchCase _: |
957 | 949 | completeSwitchCase(); |
958 | 950 | break; |
| 951 | + case EnumConstantDeclaration _: |
| 952 | + completeEnumConstantDeclaration(); |
959 | 953 | default: |
960 | 954 | // Fall back to default completion strategy (accessible bindings + type search) |
961 | 955 | } |
@@ -1084,6 +1078,10 @@ public void complete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sour |
1084 | 1078 | } |
1085 | 1079 | } |
1086 | 1080 |
|
| 1081 | + private void completeEnumConstantDeclaration() { |
| 1082 | + this.suggestDefaultCompletions = false; |
| 1083 | + } |
| 1084 | + |
1087 | 1085 | private void completeSwitchCase() { |
1088 | 1086 | // find the enum if there is one |
1089 | 1087 | ITypeBinding firstEnumType = null; |
@@ -2194,16 +2192,23 @@ private void completeQualifiedName(QualifiedName qualifiedName) throws JavaModel |
2194 | 2192 | } |
2195 | 2193 | if (!(this.toComplete instanceof Type)) { |
2196 | 2194 | ASTNode parentTypeDeclaration = DOMCompletionUtils.findParentTypeDeclaration(qualifiedName); |
| 2195 | + List<ITypeBinding> parentTypeDeclarations = DOMCompletionUtils.getParentTypeDeclarations(this.toComplete); |
2197 | 2196 | MethodDeclaration methodDecl = (MethodDeclaration)DOMCompletionUtils.findParent(this.toComplete, new int[] { ASTNode.METHOD_DECLARATION }); |
2198 | 2197 | if (parentTypeDeclaration != null && methodDecl != null && (methodDecl.getModifiers() & Flags.AccStatic) == 0) { |
2199 | 2198 | if (completionContext.getCurrentTypeBinding().isSubTypeCompatible(qualifierTypeBinding)) { |
2200 | | - if (!isFailedMatch(this.prefix.toCharArray(), Keywords.THIS)) { |
| 2199 | + if (parentTypeDeclarations.stream().anyMatch(parent -> parent.getKey().equals(qualifierTypeBinding.getKey())) |
| 2200 | + && !isFailedMatch(this.prefix.toCharArray(), Keywords.THIS)) { |
2201 | 2201 | CompletionProposal res = createKeywordProposal(Keywords.THIS, startPos, endPos); |
2202 | 2202 | res.setRelevance(res.getRelevance() + RelevanceConstants.R_NON_INHERITED); |
2203 | 2203 | this.requestor.accept(res); |
2204 | 2204 | } |
2205 | | - if (!isFailedMatch(this.prefix.toCharArray(), Keywords.SUPER)) { |
2206 | | - this.requestor.accept(createKeywordProposal(Keywords.SUPER, startPos, endPos)); |
| 2205 | + if ((!completionContext.getCurrentTypeBinding().isInterface() || !completionContext.getCurrentTypeBinding().getKey().equals(qualifierTypeBinding.getKey())) |
| 2206 | + && !isFailedMatch(this.prefix.toCharArray(), Keywords.SUPER)) { |
| 2207 | + CompletionProposal res = createKeywordProposal(Keywords.SUPER, startPos, endPos); |
| 2208 | + if (!completionContext.getCurrentTypeBinding().getKey().equals(qualifierTypeBinding.getKey())) { |
| 2209 | + res.setRelevance(res.getRelevance() + RelevanceConstants.R_NON_INHERITED); |
| 2210 | + } |
| 2211 | + this.requestor.accept(res); |
2207 | 2212 | } |
2208 | 2213 | } |
2209 | 2214 | if (!isFailedMatch(this.prefix.toCharArray(), Keywords.CLASS)) { |
|
0 commit comments