Skip to content

Commit

Permalink
* Code completion support for instance of type pattern
Browse files Browse the repository at this point in the history
* Fixes #92
  • Loading branch information
srikanth-sankaran committed Mar 5, 2024
1 parent ca70935 commit c4ec545
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -683,4 +683,26 @@ public void testGH1100() throws JavaModelException {
requestor.getResults());

}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/92
// [Patterns] Suggest identifier completion for obj instanceof Dog
public void testIssue92() throws JavaModelException {
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy(
"/Completion/src/Dog.java",
"public class Dog {\n" +
" public static void main(String[] args) {\n" +
" Object o = null;\n" +
" if (o instanceof Dog )\n" +
" }\n" +
"}\n");
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
requestor.allowAllRequiredProposals();
String str = this.workingCopies[0].getSource();
String completeBehind = "Dog ";
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
assertResults("dog[VARIABLE_DECLARATION]{dog, null, LDog;, dog, null, 48}",
requestor.getResults());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public void resolve(BlockScope scope) {
throw new CompletionNodeFound(this, scope);
}

@Override
public void resolve(BlockScope scope, boolean isPatternVariable) {
super.resolve(scope, isPatternVariable);
throw new CompletionNodeFound(this, scope);
}

@Override
public StringBuilder printAsExpression(int indent, StringBuilder output) {
printIndent(indent, output);
Expand Down

0 comments on commit c4ec545

Please sign in to comment.