Skip to content

Commit

Permalink
completion returns no results with pattern matching
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza committed Mar 6, 2024
1 parent d767ba2 commit 015c32e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,12 @@ public void complete(ICompilationUnit sourceUnit, int completionPosition, int po
trace("COMPLETION - Parent Node : " + this.parser.assistNodeParent); //$NON-NLS-1$
}
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2106
int oldModifiers = 0;
if (e.qualifiedBinding instanceof LocalVariableBinding binding) {
oldModifiers = binding.modifiers;
binding.modifiers &= ~ExtraCompilerModifiers.AccOutOfFlowScope;
}
this.lookupEnvironment.unitBeingCompleted = parsedUnit; // better resilient to further error reporting
contextAccepted =
complete(
Expand All @@ -2355,6 +2361,9 @@ public void complete(ICompilationUnit sourceUnit, int completionPosition, int po
e.qualifiedBinding,
e.scope,
e.insideTypeAnnotation);
if (e.qualifiedBinding instanceof LocalVariableBinding binding) {
binding.modifiers = oldModifiers;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ protected TypeBinding getTypeBinding(Scope scope) {
Binding binding = scope.parent.getTypeOrPackage(this.tokens); // step up from the ClassScope
if (!binding.isValidBinding()) {
scope.problemReporter().invalidType(this, (TypeBinding) binding);

LocalVariableBinding localVariableBinding;
if (scope instanceof BlockScope blockScope) {
localVariableBinding = blockScope.findVariable(this.tokens[0], null);
} else {
localVariableBinding = null;
}
if (binding.problemId() == ProblemReasons.NotFound) {
throw new CompletionNodeFound(this, binding, scope);
throw new CompletionNodeFound(this, (localVariableBinding == null ? binding : localVariableBinding), scope);
}

throw new CompletionNodeFound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
import org.eclipse.jdt.internal.compiler.parser.RecoveredModule;
import org.eclipse.jdt.internal.compiler.parser.RecoveredPackageVisibilityStatement;
import org.eclipse.jdt.internal.compiler.parser.RecoveredProvidesStatement;
import org.eclipse.jdt.internal.compiler.parser.RecoveredStatement;
import org.eclipse.jdt.internal.compiler.parser.RecoveredType;
import org.eclipse.jdt.internal.compiler.parser.RecoveredUnit;
import org.eclipse.jdt.internal.compiler.parser.Scanner;
Expand Down Expand Up @@ -755,19 +756,44 @@ protected void attachOrphanCompletionNode(){
}
}
}
if (this.astPtr > -1 && this.astStack[this.astPtr] instanceof LocalDeclaration) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939
if (this.astPtr > -1 && this.astStack[this.astPtr] instanceof LocalDeclaration local) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939
// To take care of: if (a instance of X) int i = a.|
LocalDeclaration local = (LocalDeclaration) this.astStack[this.astPtr];
if (local.initialization == this.assistNode) {
if (local.initialization == this.assistNode || local.type == this.assistNode) {
Statement enclosing = buildMoreCompletionEnclosingContext(local);
if (enclosing instanceof IfStatement) {
if (this.currentElement instanceof RecoveredBlock) {
if (this.currentElement instanceof RecoveredBlock recoveredBlock) {
// RecoveredLocalVariable must be removed from its parent because the IfStatement will be added instead
RecoveredBlock recoveredBlock = (RecoveredBlock) this.currentElement;
recoveredBlock.statements[--recoveredBlock.statementCount] = null;
this.currentElement = this.currentElement.add(enclosing, 0);
}
}
} else if (this.astPtr > 0) {
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2106
int index = this.astPtr - 1;
while (index >= 0) {
if (this.astStack[index] instanceof LocalDeclaration local2) {
if (local2.initialization == this.assistNode || local2.type == this.assistNode) {
Statement enclosing = buildMoreCompletionEnclosingContext(local2);
if (enclosing instanceof IfStatement) {
if (this.currentElement instanceof RecoveredBlock recoveredBlock) {
for (int i = 0; i < recoveredBlock.statementCount; i++) {
RecoveredStatement rs = recoveredBlock.statements[i];
if (rs instanceof RecoveredLocalVariable rlv) {
if (rlv.localDeclaration == local2) {
RecoveredStatement statement = new RecoveredStatement(enclosing,
recoveredBlock, 0);
recoveredBlock.statements[i] = statement;
index = -1;
break;
}
}
}
}
}
}
}
index = index - 1;
}
}
}
}
Expand Down

0 comments on commit 015c32e

Please sign in to comment.