Lines 10424-10427
Link Here
|
10424 |
deleteProject("P"); |
10424 |
deleteProject("P"); |
10425 |
} |
10425 |
} |
10426 |
} |
10426 |
} |
|
|
10427 |
|
10428 |
|
10429 |
/** |
10430 |
* @bug 265065: [search] java.lang.ClassCastException while running "Refactor...Extract Class" |
10431 |
* @test Ensure that no CCE occurs while using an OrPattern made of VariablePattern |
10432 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=265065" |
10433 |
*/ |
10434 |
public void testBug265065() throws CoreException { |
10435 |
this.workingCopies = new ICompilationUnit[1]; |
10436 |
this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/MyClass.java", |
10437 |
"public class MyClass {\n" + |
10438 |
" class MyPrivateClass {\n" + |
10439 |
" public String type = TYPE_A;\n" + |
10440 |
" public Object value = null;\n" + |
10441 |
" public MyPrivateClass(String type, Object value) {\n" + |
10442 |
" this.type = type;\n" + |
10443 |
" this.value = value;\n" + |
10444 |
" }\n" + |
10445 |
" }\n" + |
10446 |
"\n" + |
10447 |
" private static final String TYPE_A = \"A\";\n" + |
10448 |
" private static final String TYPE_B = \"B\";\n" + |
10449 |
" private static final String TYPE_C = \"C\";\n" + |
10450 |
"\n" + |
10451 |
" void foo (Object value) {\n" + |
10452 |
" MyPrivateClass mpc = new MyPrivateClass(TYPE_B, value);\n" + |
10453 |
" if (mpc.value == null) {\n" + |
10454 |
" mpc.type = TYPE_C;\n" + |
10455 |
" }\n" + |
10456 |
" }\n" + |
10457 |
"}\n" |
10458 |
); |
10459 |
this.resultCollector.showRule(); |
10460 |
this.resultCollector.showAccess(); |
10461 |
SearchPattern leftPattern = SearchPattern.createPattern("MyClass.MyPrivateClass.value Object", FIELD, ALL_OCCURRENCES, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); |
10462 |
SearchPattern rightPattern = SearchPattern.createPattern("MyClass.MyPrivateClass.type String", FIELD, ALL_OCCURRENCES, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); |
10463 |
new SearchEngine(this.workingCopies).search( |
10464 |
SearchPattern.createOrPattern(leftPattern, rightPattern), |
10465 |
new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, |
10466 |
getJavaSearchWorkingCopiesScope(), |
10467 |
this.resultCollector, |
10468 |
null); |
10469 |
assertSearchResults( |
10470 |
"src/MyClass.java void MyClass.foo(Object) [value] EXACT_MATCH READ ACCESS\n" + |
10471 |
"src/MyClass.java void MyClass.foo(Object) [type] EXACT_MATCH READ ACCESS\n" + |
10472 |
"src/MyClass.java MyClass$MyPrivateClass.type [type] EXACT_MATCH\n" + |
10473 |
"src/MyClass.java MyClass$MyPrivateClass.value [value] EXACT_MATCH\n" + |
10474 |
"src/MyClass.java MyClass$MyPrivateClass(String, Object) [type] EXACT_MATCH WRITE ACCESS\n" + |
10475 |
"src/MyClass.java MyClass$MyPrivateClass(String, Object) [value] EXACT_MATCH WRITE ACCESS" |
10476 |
); |
10477 |
} |
10478 |
public void testBug265065b() throws CoreException { |
10479 |
this.workingCopies = new ICompilationUnit[2]; |
10480 |
this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/pack/Test.java", |
10481 |
"package pack;\n" + |
10482 |
"public class Test {\n" + |
10483 |
" public int field;\n" + |
10484 |
"}\n" |
10485 |
); |
10486 |
this.workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/test/X.java", |
10487 |
"package test;\n" + |
10488 |
"import pack.Test;\n" + |
10489 |
"public class X {\n" + |
10490 |
" void foo(Test t1, Test t2) {\n" + |
10491 |
" t1 = t2;\n" + |
10492 |
" t1.field = t1.field;\n" + |
10493 |
" t2.field = t1.field;\n" + |
10494 |
" }\n" + |
10495 |
"}\n" |
10496 |
); |
10497 |
this.resultCollector.showAccess(); |
10498 |
ILocalVariable localVar1 = selectLocalVariable(this.workingCopies[1], "t1"); |
10499 |
SearchPattern leftPattern = createPattern(localVar1, IJavaSearchConstants.REFERENCES); |
10500 |
ILocalVariable localVar2 = selectLocalVariable(this.workingCopies[1], "t2"); |
10501 |
SearchPattern rightPattern = createPattern(localVar2, IJavaSearchConstants.REFERENCES); |
10502 |
new SearchEngine(this.workingCopies).search( |
10503 |
SearchPattern.createOrPattern(leftPattern, rightPattern), |
10504 |
new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, |
10505 |
getJavaSearchWorkingCopiesScope(), |
10506 |
this.resultCollector, |
10507 |
null); |
10508 |
assertSearchResults( |
10509 |
"src/test/X.java void test.X.foo(Test, Test) [t1] EXACT_MATCH WRITE ACCESS\n" + |
10510 |
"src/test/X.java void test.X.foo(Test, Test) [t2] EXACT_MATCH READ ACCESS\n" + |
10511 |
"src/test/X.java void test.X.foo(Test, Test) [t1] EXACT_MATCH READ ACCESS\n" + |
10512 |
"src/test/X.java void test.X.foo(Test, Test) [t1] EXACT_MATCH READ ACCESS\n" + |
10513 |
"src/test/X.java void test.X.foo(Test, Test) [t2] EXACT_MATCH READ ACCESS\n" + |
10514 |
"src/test/X.java void test.X.foo(Test, Test) [t1] EXACT_MATCH READ ACCESS" |
10515 |
); |
10516 |
} |
10517 |
|
10427 |
} |
10518 |
} |