Lines 33-38
Link Here
|
33 |
import org.eclipse.jdt.core.ICompilationUnit; |
33 |
import org.eclipse.jdt.core.ICompilationUnit; |
34 |
import org.eclipse.jdt.core.IJavaProject; |
34 |
import org.eclipse.jdt.core.IJavaProject; |
35 |
import org.eclipse.jdt.core.JavaCore; |
35 |
import org.eclipse.jdt.core.JavaCore; |
|
|
36 |
import org.eclipse.jdt.core.tests.util.Util; |
36 |
import org.eclipse.jdt.internal.codeassist.RelevanceConstants; |
37 |
import org.eclipse.jdt.internal.codeassist.RelevanceConstants; |
37 |
import org.eclipse.jdt.internal.core.JavaModelManager; |
38 |
import org.eclipse.jdt.internal.core.JavaModelManager; |
38 |
|
39 |
|
Lines 2338-2341
Link Here
|
2338 |
deleteResource(new File(jarName)); |
2339 |
deleteResource(new File(jarName)); |
2339 |
} |
2340 |
} |
2340 |
} |
2341 |
} |
|
|
2342 |
public void testBug237469a() throws Exception { |
2343 |
String externalJar1 = Util.getOutputDirectory() + File.separator + "bug237469a.jar"; //$NON-NLS-1$ |
2344 |
String externalJar2 = Util.getOutputDirectory() + File.separator + "bug237469b.jar"; //$NON-NLS-1$ |
2345 |
|
2346 |
try { |
2347 |
// create variable |
2348 |
// JavaCore.setClasspathVariables( |
2349 |
// new String[] {"JCL_LIB", "JCL_SRC", "JCL_SRCROOT"}, |
2350 |
// new IPath[] {getExternalJCLPath(), getExternalJCLSourcePath(), getExternalJCLRootSourcePath()}, |
2351 |
// null); |
2352 |
|
2353 |
|
2354 |
// create external jar 1 |
2355 |
Util.createJar( |
2356 |
new String[] { |
2357 |
"test/IProject.java", //$NON-NLS-1$ |
2358 |
"package test;\n" + //$NON-NLS-1$ |
2359 |
"public class IProject {\n" + //$NON-NLS-1$ |
2360 |
"}" //$NON-NLS-1$ |
2361 |
}, |
2362 |
new HashMap(), |
2363 |
externalJar1); |
2364 |
|
2365 |
// create external jar 2 |
2366 |
Util.createJar( |
2367 |
new String[] { |
2368 |
"test/IJavaProject.java", //$NON-NLS-1$ |
2369 |
"package test;\n" + //$NON-NLS-1$ |
2370 |
"import test.IProject;\n" + //$NON-NLS-1$ |
2371 |
"public class IJavaProject {\n" + //$NON-NLS-1$ |
2372 |
" IProject project = null;\n" + //$NON-NLS-1$ |
2373 |
"}" //$NON-NLS-1$ |
2374 |
}, |
2375 |
null, |
2376 |
new HashMap(), |
2377 |
new String[]{externalJar1}, |
2378 |
externalJar2); |
2379 |
|
2380 |
// create P1 |
2381 |
this.createJavaProject( |
2382 |
"PS1", |
2383 |
new String[]{"src"}, |
2384 |
new String[]{"JCL_LIB", externalJar1, externalJar2}, |
2385 |
"bin"); |
2386 |
|
2387 |
this.createFolder("/PS1/src/test"); |
2388 |
this.createFile( |
2389 |
"/PS1/src/test/Y.java", |
2390 |
"package test;\n"+ |
2391 |
"import test.IProject;\n"+ |
2392 |
"import test.IJavaProject;\n"+ |
2393 |
"public class Y {\n"+ |
2394 |
" IProject project;\n"+ |
2395 |
" IJavaProject javaProject;\n"+ |
2396 |
"}"); |
2397 |
|
2398 |
// create P2 |
2399 |
this.createJavaProject( |
2400 |
"PS2", |
2401 |
new String[]{"src"}, |
2402 |
new String[]{"JCL_LIB", externalJar2}, |
2403 |
new String[]{"/PS1"}, |
2404 |
"bin"); |
2405 |
|
2406 |
this.createFolder("/PS2/src/test"); |
2407 |
this.createFile( |
2408 |
"/PS2/src/test/X.java", |
2409 |
"package test;\n"+ |
2410 |
"public class X extends test.Y {\n"+ |
2411 |
" private Object initializer;\n"+ |
2412 |
" public void foo() {\n"+ |
2413 |
" initializer\n"+ |
2414 |
" }\n"+ |
2415 |
"}"); |
2416 |
|
2417 |
waitUntilIndexesReady(); |
2418 |
|
2419 |
// do completion |
2420 |
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(); |
2421 |
ICompilationUnit cu= getCompilationUnit("PS2", "src", "test", "X.java"); |
2422 |
|
2423 |
String str = cu.getSource(); |
2424 |
String completeBehind = "initializer"; |
2425 |
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
2426 |
cu.codeComplete(cursorLocation, requestor); |
2427 |
|
2428 |
assertResults( |
2429 |
"initializer[FIELD_REF]{initializer, Ltest.X;, Ljava.lang.Object;, initializer, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_UNQUALIFIED + R_NON_RESTRICTED) + "}", |
2430 |
requestor.getResults()); |
2431 |
} finally { |
2432 |
this.deleteProject("PS1"); |
2433 |
this.deleteProject("PS2"); |
2434 |
this.deleteFile(externalJar1); |
2435 |
this.deleteFile(externalJar2); |
2436 |
} |
2437 |
} |
2438 |
public void testBug237469b() throws Exception { |
2439 |
String externalJar1 = Util.getOutputDirectory() + File.separator + "bug237469a.jar"; //$NON-NLS-1$ |
2440 |
String externalJar2 = Util.getOutputDirectory() + File.separator + "bug237469b.jar"; //$NON-NLS-1$ |
2441 |
|
2442 |
try { |
2443 |
// create variable |
2444 |
// JavaCore.setClasspathVariables( |
2445 |
// new String[] {"JCL_LIB", "JCL_SRC", "JCL_SRCROOT"}, |
2446 |
// new IPath[] {getExternalJCLPath(), getExternalJCLSourcePath(), getExternalJCLRootSourcePath()}, |
2447 |
// null); |
2448 |
|
2449 |
|
2450 |
// create external jar 1 |
2451 |
Util.createJar( |
2452 |
new String[] { |
2453 |
"test/IProject.java", //$NON-NLS-1$ |
2454 |
"package test;\n" + //$NON-NLS-1$ |
2455 |
"public class IProject {\n" + //$NON-NLS-1$ |
2456 |
"}" //$NON-NLS-1$ |
2457 |
}, |
2458 |
new HashMap(), |
2459 |
externalJar1); |
2460 |
|
2461 |
// create external jar 2 |
2462 |
Util.createJar( |
2463 |
new String[] { |
2464 |
"test/IJavaProject.java", //$NON-NLS-1$ |
2465 |
"package test;\n" + //$NON-NLS-1$ |
2466 |
"import test.IProject;\n" + //$NON-NLS-1$ |
2467 |
"public class IJavaProject {\n" + //$NON-NLS-1$ |
2468 |
" IProject project = null;\n" + //$NON-NLS-1$ |
2469 |
"}" //$NON-NLS-1$ |
2470 |
}, |
2471 |
null, |
2472 |
new HashMap(), |
2473 |
new String[]{externalJar1}, |
2474 |
externalJar2); |
2475 |
|
2476 |
// create P1 |
2477 |
this.createJavaProject( |
2478 |
"PS1", |
2479 |
new String[]{"src"}, |
2480 |
new String[]{"JCL_LIB", externalJar1, externalJar2}, |
2481 |
"bin"); |
2482 |
|
2483 |
this.createFolder("/PS1/src/test"); |
2484 |
this.createFile( |
2485 |
"/PS1/src/test/Y.java", |
2486 |
"package test;\n"+ |
2487 |
"import test.IProject;\n"+ |
2488 |
"import test.IJavaProject;\n"+ |
2489 |
"public class Y {\n"+ |
2490 |
" IProject project;\n"+ |
2491 |
" IJavaProject javaProject;\n"+ |
2492 |
"}"); |
2493 |
|
2494 |
// create P2 |
2495 |
this.createJavaProject( |
2496 |
"PS2", |
2497 |
new String[]{"src"}, |
2498 |
new String[]{"JCL_LIB", externalJar2}, |
2499 |
new String[]{"/PS1"}, |
2500 |
"bin"); |
2501 |
|
2502 |
this.createFolder("/PS2/src/test"); |
2503 |
this.createFile( |
2504 |
"/PS2/src/test/X.java", |
2505 |
"package test;\n"+ |
2506 |
"public class X extends test.Y {\n"+ |
2507 |
" private X initializer;\n"+ |
2508 |
" public void foo() {\n"+ |
2509 |
" Object o; o.equals\n"+ |
2510 |
" }\n"+ |
2511 |
"}"); |
2512 |
|
2513 |
waitUntilIndexesReady(); |
2514 |
|
2515 |
// do completion |
2516 |
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(false, false, false, false); |
2517 |
requestor.setRequireExtendedContext(true); |
2518 |
requestor.setComputeEnclosingElement(false); |
2519 |
requestor.setComputeVisibleElements(true); |
2520 |
requestor.setAssignableType("Ltest/X;"); |
2521 |
|
2522 |
ICompilationUnit cu= getCompilationUnit("PS2", "src", "test", "X.java"); |
2523 |
|
2524 |
String str = cu.getSource(); |
2525 |
String completeBehind = "equals"; |
2526 |
|
2527 |
int tokenStart = str.lastIndexOf(completeBehind); |
2528 |
int tokenEnd = tokenStart + completeBehind.length() - 1; |
2529 |
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
2530 |
cu.codeComplete(cursorLocation, requestor); |
2531 |
|
2532 |
assertResults( |
2533 |
"completion offset="+(cursorLocation)+"\n" + |
2534 |
"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" + |
2535 |
"completion token=\"equals\"\n" + |
2536 |
"completion token kind=TOKEN_KIND_NAME\n" + |
2537 |
"expectedTypesSignatures=null\n" + |
2538 |
"expectedTypesKeys=null\n"+ |
2539 |
"completion token location=UNKNOWN\n"+ |
2540 |
"visibleElements={\n" + |
2541 |
" initializer {key=Ltest/X;.initializer)Ltest/X;} [in X [in X.java [in test [in src [in PS2]]]]],\n" + |
2542 |
"}", |
2543 |
requestor.getContext()); |
2544 |
} finally { |
2545 |
this.deleteProject("PS1"); |
2546 |
this.deleteProject("PS2"); |
2547 |
this.deleteFile(externalJar1); |
2548 |
this.deleteFile(externalJar2); |
2549 |
} |
2550 |
} |
2341 |
} |
2551 |
} |