Lines 21186-21189
Link Here
|
21186 |
"AClass[TYPE_REF]{AClass, test, Ltest.AClass;, null, null, 27}", |
21186 |
"AClass[TYPE_REF]{AClass, test, Ltest.AClass;, null, null, 27}", |
21187 |
requestor.getResults()); |
21187 |
requestor.getResults()); |
21188 |
} |
21188 |
} |
|
|
21189 |
|
21190 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=261534 |
21191 |
// To verify that autocast works correctly even when instanceof expression |
21192 |
// and completion node are in the same binary expression, related by && |
21193 |
public void testBug261534a() throws JavaModelException { |
21194 |
this.workingCopies = new ICompilationUnit[1]; |
21195 |
this.workingCopies[0] = getWorkingCopy( |
21196 |
"/Completion/src/test/CompletionAfterInstanceOf.java", |
21197 |
"package test;" + |
21198 |
"class MyString {\n" + |
21199 |
" public String toWelcome() {\n" + |
21200 |
" return \"welcome\";\n" + |
21201 |
" }\n" + |
21202 |
"}\n" + |
21203 |
"public class CompletionAfterInstanceOf {\n" + |
21204 |
" void foo() {\n" + |
21205 |
" Object chars= null;\n" + |
21206 |
" if (chars instanceof MyString && chars.to) {\n" + |
21207 |
" }\n" + |
21208 |
" }\n" + |
21209 |
"}\n"); |
21210 |
|
21211 |
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, true, true, true, true, true); |
21212 |
requestor.allowAllRequiredProposals(); |
21213 |
String str = this.workingCopies[0].getSource(); |
21214 |
String completeBehind = "chars instanceof MyString && chars.to"; |
21215 |
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
21216 |
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); |
21217 |
|
21218 |
int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; |
21219 |
int start1 = str.lastIndexOf("to") + "".length(); |
21220 |
int end1 = start1 + "to".length(); |
21221 |
int start2 = str.lastIndexOf("chars.to"); |
21222 |
int end2 = start2 + "chars.to".length(); |
21223 |
int start3 = str.lastIndexOf("chars."); |
21224 |
int end3 = start3 + "chars".length(); |
21225 |
|
21226 |
assertResults( |
21227 |
"toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, null, null, toString, null, replace[" + start1 + ", " + end1 + "], token[" + start1 + ", " + end1 +"], " + relevance1 + "}\n" + |
21228 |
"toWelcome[METHOD_REF_WITH_CASTED_RECEIVER]{((MyString)chars).toWelcome(), Ltest.MyString;, ()Ljava.lang.String;, Ltest.MyString;, null, null, toWelcome, null, replace[" + start2 +", " + end2 + "], token[" + start1 + ", " + end1 + "], receiver[" + start3 + ", " + end3 + "], " + relevance1 + "}", |
21229 |
requestor.getResults()); |
21230 |
} |
21231 |
|
21232 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=261534 |
21233 |
// Negative test - To verify that proposals from casted receiver are not obtained |
21234 |
// when completion node is in an OR_OR_Expression along with an instanceof exp. |
21235 |
public void testBug261534b() throws JavaModelException { |
21236 |
this.workingCopies = new ICompilationUnit[1]; |
21237 |
this.workingCopies[0] = getWorkingCopy( |
21238 |
"/Completion/src/test/CompletionAfterInstanceOf.java", |
21239 |
"package test;" + |
21240 |
"class MyString {\n" + |
21241 |
" public String toWelcome() {\n" + |
21242 |
" return \"welcome\";\n" + |
21243 |
" }\n" + |
21244 |
"}\n" + |
21245 |
"public class CompletionAfterInstanceOf {\n" + |
21246 |
" void foo() {\n" + |
21247 |
" Object chars= null;\n" + |
21248 |
" if (chars instanceof MyString || chars.to) {\n" + |
21249 |
" }\n" + |
21250 |
" }\n" + |
21251 |
"}\n"); |
21252 |
|
21253 |
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, true, true, true, true, true); |
21254 |
requestor.allowAllRequiredProposals(); |
21255 |
String str = this.workingCopies[0].getSource(); |
21256 |
String completeBehind = "chars instanceof MyString || chars.to"; |
21257 |
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
21258 |
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); |
21259 |
|
21260 |
int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; |
21261 |
int start1 = str.lastIndexOf("to") + "".length(); |
21262 |
int end1 = start1 + "to".length(); |
21263 |
|
21264 |
assertResults( |
21265 |
"toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, null, null, toString, null, replace[" + start1 + ", " + end1 + "], token[" + start1 + ", " + end1 +"], " + relevance1 + "}", |
21266 |
requestor.getResults()); |
21267 |
} |
21189 |
} |
21268 |
} |