From 7315a92d686ac564a44f13f8ae7f3ecda3e70f79 Mon Sep 17 00:00:00 2001 From: Gayan Perera Date: Thu, 15 Feb 2024 19:58:14 +0100 Subject: [PATCH] add a new test for for-loop scenario. --- .../core/tests/model/CompletionTests14.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests14.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests14.java index 21deff0d905..0d14b8063db 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests14.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests14.java @@ -983,6 +983,7 @@ public void testBugGH1095_2() throws Exception { "implementMe[METHOD_DECLARATION]{public void implementMe(), LBaseInterface;, ()V, implementMe, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_ABSTRACT_METHOD + R_UNQUALIFIED + R_NON_RESTRICTED) + "}", requestor.getResults()); } + public void testGH1561_CompletionInIfConditionInsideASwitchStatement() throws JavaModelException { this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/Completion/src/SwitchIf.java", @@ -1093,4 +1094,36 @@ private void foo(Type input) { + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}", requestor.getResults()); } + + public void testGH1561_CompletionInForInsideASwitchStatement() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/Completion/src/SwitchIf.java", + """ + public class SwitchIf { + final String name = "test"; + enum Type { A } + private void foo(Type input) { + switch (input) { + case A: + for (int i = 0; nam) + break; + } + } + private boolean nameContains(String name) { + return false; + } + } + """); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, true, true, false); + String str = this.workingCopies[0].getSource(); + String completeBehind = "for (int i = 0; nam"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + assertResults("name[FIELD_REF]{name, LSwitchIf;, Ljava.lang.String;, null, null, name, null, [156, 159], " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" + + "nameContains[METHOD_REF]{nameContains(), LSwitchIf;, (Ljava.lang.String;)Z, null, null, nameContains, (name), [156, 159], " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + + R_EXACT_EXPECTED_TYPE) + + "}", requestor.getResults()); + } }