View | Details | Raw Unified | Return to bug 118823 | Differences between
and this patch

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/indexing/InternalSearchDocument.java (-2 / +2 lines)
Lines 30-37 Link Here
30
				if (length > 1 && key[length-2] == IIndexConstants.SEPARATOR && key[length-1] == IIndexConstants.SECONDARY_SUFFIX ) {
30
				if (length > 1 && key[length-2] == IIndexConstants.SEPARATOR && key[length-1] == IIndexConstants.SECONDARY_SUFFIX ) {
31
					// This is a key of a secondary type => reset java model manager secondary types cache for document path project
31
					// This is a key of a secondary type => reset java model manager secondary types cache for document path project
32
					JavaModelManager manager = JavaModelManager.getJavaModelManager();
32
					JavaModelManager manager = JavaModelManager.getJavaModelManager();
33
					manager.resetSecondaryTypesCache(getPath());
33
//					manager.resetSecondaryTypesCache(getPath());
34
//					manager.addSecondaryType(getPath(), key);
34
					manager.addSecondaryType(getPath(), key);
35
				}
35
				}
36
			}
36
			}
37
		}
37
		}
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-52 / +210 lines)
Lines 169-175 Link Here
169
	
169
	
170
	private static final String ENABLE_NEW_FORMATTER = JavaCore.PLUGIN_ID + "/formatter/enable_new" ; //$NON-NLS-1$
170
	private static final String ENABLE_NEW_FORMATTER = JavaCore.PLUGIN_ID + "/formatter/enable_new" ; //$NON-NLS-1$
171
171
172
	private final static String DIRTY_CACHE = "***dirty***"; //$NON-NLS-1$
172
	private final static String INDEXING_CACHE = "#@*indexing*@#"; //$NON-NLS-1$
173
	private final static HashMap NO_SECONDARY_TYPES = new HashMap(0);
173
	private final static HashMap NO_SECONDARY_TYPES = new HashMap(0);
174
174
175
	public static boolean PERF_VARIABLE_INITIALIZER = false;
175
	public static boolean PERF_VARIABLE_INITIALIZER = false;
Lines 1463-1470 Link Here
1463
			}
1463
			}
1464
		}
1464
		}
1465
1465
1466
		// Return cache if not empty and not dirty
1466
		// Return cache if not empty and there's indexing cache
1467
		if (projectInfo.secondaryTypes != null && projectInfo.secondaryTypes.get(DIRTY_CACHE) == null) {
1467
		if (projectInfo.secondaryTypes != null && projectInfo.secondaryTypes.get(INDEXING_CACHE) == null) {
1468
			return projectInfo.secondaryTypes;
1468
			return projectInfo.secondaryTypes;
1469
		}
1469
		}
1470
		
1470
		
Lines 1473-1479 Link Here
1473
			if (projectInfo.secondaryTypes == null) {
1473
			if (projectInfo.secondaryTypes == null) {
1474
				return NO_SECONDARY_TYPES; // cache is not initialized return empty one
1474
				return NO_SECONDARY_TYPES; // cache is not initialized return empty one
1475
			}
1475
			}
1476
			return projectInfo.secondaryTypes; // cache is dirty => return current one...
1476
			return projectInfo.secondaryTypes; // there's an indexing cache => return current one...
1477
		}
1478
1479
		// If cache not null, then return it merged with indexing cache
1480
		if (projectInfo.secondaryTypes != null) {
1481
			return getSecondaryTypesMerged(projectInfo.secondaryTypes);
1477
		}
1482
		}
1478
1483
1479
		// Init variables for search
1484
		// Init variables for search
Lines 1503-1517 Link Here
1503
1508
1504
		// Search all secondary types on scope
1509
		// Search all secondary types on scope
1505
		new BasicSearchEngine().searchAllSecondaryTypeNames(allSourceFolders, nameRequestor, monitor);
1510
		new BasicSearchEngine().searchAllSecondaryTypeNames(allSourceFolders, nameRequestor, monitor);
1506
		if (VERBOSE) {
1507
			System.out.print(Thread.currentThread() + "	-> secondary paths: ");  //$NON-NLS-1$
1508
			System.out.println();
1509
			Iterator keys = secondaryTypes.keySet().iterator();
1510
			while (keys.hasNext()) {
1511
				String qualifiedName = (String) keys.next();
1512
				Util.verbose("		- "+qualifiedName+'-'+secondaryTypes.get(qualifiedName) ); //$NON-NLS-1$
1513
			}
1514
		}
1515
1511
1516
		// Build types from paths
1512
		// Build types from paths
1517
		Iterator packages = secondaryTypes.keySet().iterator();
1513
		Iterator packages = secondaryTypes.keySet().iterator();
Lines 1531-1542 Link Here
1531
			}
1527
			}
1532
		}
1528
		}
1533
1529
1534
		// Store result in per project info cache if still null or dirty (may have been set by another thread...)
1530
		// Store result in per project info cache if still null or there's still an indexing cache (may have been set by another thread...)
1535
		if (projectInfo.secondaryTypes == null || projectInfo.secondaryTypes.get(DIRTY_CACHE) != null) {
1531
		if (projectInfo.secondaryTypes == null || projectInfo.secondaryTypes.get(INDEXING_CACHE) != null) {
1536
			projectInfo.secondaryTypes = secondaryTypes;
1532
			projectInfo.secondaryTypes = secondaryTypes;
1533
			if (VERBOSE) {
1534
				System.out.print(Thread.currentThread() + "	-> secondary paths stored in cache: ");  //$NON-NLS-1$
1535
				System.out.println();
1536
				Iterator keys = secondaryTypes.keySet().iterator();
1537
				while (keys.hasNext()) {
1538
					String qualifiedName = (String) keys.next();
1539
					Util.verbose("		- "+qualifiedName+'-'+secondaryTypes.get(qualifiedName) ); //$NON-NLS-1$
1540
				}
1541
			}
1537
		}
1542
		}
1538
		return projectInfo.secondaryTypes;
1543
		return projectInfo.secondaryTypes;
1539
	}
1544
	}
1545
	
1546
	/*
1547
	 * Return secondary types cache merged with cached done while indexing was runnning.
1548
	 * Note that result of merged is directly  stored in given parameter map.
1549
	 */
1550
	private HashMap getSecondaryTypesMerged(HashMap secondaryTypes) {
1551
		if (VERBOSE) {
1552
			Util.verbose("JavaModelManager.getSecondaryTypesMerged()"); //$NON-NLS-1$
1553
			Util.verbose("	- current cache to merge:"); //$NON-NLS-1$
1554
			Iterator keys = secondaryTypes.keySet().iterator();
1555
			while (keys.hasNext()) {
1556
				String packName = (String) keys.next();
1557
				Util.verbose("		+ "+packName+':'+secondaryTypes.get(packName) ); //$NON-NLS-1$
1558
			}
1559
		}
1560
1561
		// Return current cache if there's no indexing cache
1562
		HashMap indexingCache = (HashMap) secondaryTypes.remove(INDEXING_CACHE);
1563
		if (indexingCache == null) {
1564
			return secondaryTypes;
1565
		}
1566
1567
		// Merge indexing cache in secondary types one
1568
		Iterator indexedFiles = indexingCache.keySet().iterator();
1569
		while (indexedFiles.hasNext()) {
1570
			IFile indexedFile = (IFile) indexedFiles.next();
1571
	
1572
			// Remove all secondary types of indexed file from cache
1573
			removeFromSecondaryTypesMap(secondaryTypes, indexedFile);
1574
			
1575
			// Add all indexing file secondary types in given secondary types cache
1576
			HashMap allIndexedTypes = (HashMap) indexingCache.get(indexedFile);
1577
			Iterator indexedPackages = allIndexedTypes.keySet().iterator();
1578
			while (indexedPackages.hasNext()) {
1579
				String indexedPackage = (String) indexedPackages.next();
1580
				HashMap types = (HashMap) secondaryTypes.get(indexedPackage);
1581
				if (types == null) {
1582
					secondaryTypes.put(indexedPackage, allIndexedTypes.get(indexedPackage));
1583
				} else {
1584
					HashMap indexedTypes = (HashMap) allIndexedTypes.get(indexedPackage);
1585
					Iterator indexedTypeNames = indexedTypes.keySet().iterator();
1586
					while (indexedTypeNames.hasNext()) {
1587
						String indexedTypeName = (String) indexedTypeNames.next();
1588
						types.put(indexedTypeName, indexedTypes.get(indexedTypeName));
1589
					}
1590
				}
1591
			}
1592
		}
1593
		if (VERBOSE) {
1594
			Util.verbose("	- secondary types cache merged:"); //$NON-NLS-1$
1595
			Iterator keys = secondaryTypes.keySet().iterator();
1596
			while (keys.hasNext()) {
1597
				String packName = (String) keys.next();
1598
				Util.verbose("		+ "+packName+':'+secondaryTypes.get(packName) ); //$NON-NLS-1$
1599
			}
1600
		}
1601
		return secondaryTypes;
1602
	}
1540
1603
1541
	/**
1604
	/**
1542
	 * Returns the temporary cache for newly opened elements for the current thread.
1605
	 * Returns the temporary cache for newly opened elements for the current thread.
Lines 2401-2409 Link Here
2401
	 * 
2464
	 * 
2402
	 * @param file File to remove
2465
	 * @param file File to remove
2403
	 */
2466
	 */
2404
	public void removeFromSecondaryTypesCache(IFile file) {
2467
	public void removeFromSecondaryTypesCache(IFile file, boolean cleanIndexCache) {
2405
		if (VERBOSE) {
2468
		if (VERBOSE) {
2406
			StringBuffer buffer = new StringBuffer("JavaModelManager.removeSecondaryTypePaths("); //$NON-NLS-1$
2469
			StringBuffer buffer = new StringBuffer("JavaModelManager.removeFromSecondaryTypesCache("); //$NON-NLS-1$
2407
			buffer.append(file.getName());
2470
			buffer.append(file.getName());
2408
			buffer.append(')');
2471
			buffer.append(')');
2409
			Util.verbose(buffer.toString());
2472
			Util.verbose(buffer.toString());
Lines 2414-2456 Link Here
2414
				if (VERBOSE) {
2477
				if (VERBOSE) {
2415
					Util.verbose("-> remove file from cache of project: "+file.getProject().getName()); //$NON-NLS-1$
2478
					Util.verbose("-> remove file from cache of project: "+file.getProject().getName()); //$NON-NLS-1$
2416
				}
2479
				}
2417
				Iterator packages = projectInfo.secondaryTypes.keySet().iterator();
2480
2418
				while (packages.hasNext()) {
2481
				// Clean current cache
2419
					String packName = (String) packages.next();
2482
				removeFromSecondaryTypesMap(projectInfo.secondaryTypes, file);
2420
					Object object = projectInfo.secondaryTypes.get(packName);
2483
				
2421
					if (object instanceof HashMap) {
2484
				// Clean indexing cache if necessary
2422
						HashMap types = (HashMap) object;
2485
				if (!cleanIndexCache) return;
2423
						Iterator names = types.keySet().iterator();
2486
				HashMap indexingCache = (HashMap) projectInfo.secondaryTypes.get(INDEXING_CACHE);
2424
						while (names.hasNext()) {
2487
				if (indexingCache != null) {
2425
							String typeName = (String) names.next();
2488
					Set keys = indexingCache.keySet();
2426
							IType type = (IType) types.get(typeName);
2489
					int filesSize = keys.size(), filesCount = 0;
2427
							if (file.equals(type.getResource())) {
2490
					IFile[] removed = null;
2428
								types.remove(typeName);
2491
					Iterator cachedFiles = keys.iterator();
2429
								if (types.size() == 0) {
2492
					while (cachedFiles.hasNext()) {
2430
									projectInfo.secondaryTypes.remove(packName);
2493
						IFile cachedFile = (IFile) cachedFiles.next();
2431
								}
2494
						if (file.equals(cachedFile)) {
2432
								return;
2495
							if (removed == null) removed = new IFile[filesSize];
2433
							}
2496
							filesSize--;
2497
							removed[filesCount++] = cachedFile;
2434
						}
2498
						}
2435
					}
2499
					}
2500
					for (int i=0; i<filesCount; i++) {
2501
						indexingCache.remove(removed[i]);
2502
					}
2436
				}
2503
				}
2437
			}
2504
			}
2438
		}
2505
		}
2439
	}
2506
	}
2507
	private void removeFromSecondaryTypesMap(HashMap secondaryTypesMap, IFile file) {
2508
		if (VERBOSE) {
2509
			StringBuffer buffer = new StringBuffer("JavaModelManager.removeSecondaryTypesFromMap("); //$NON-NLS-1$
2510
			Iterator keys = secondaryTypesMap.keySet().iterator();
2511
			while (keys.hasNext()) {
2512
				String qualifiedName = (String) keys.next();
2513
				buffer.append(qualifiedName+':'+secondaryTypesMap.get(qualifiedName));
2514
			}
2515
			buffer.append(',');
2516
			buffer.append(file.getFullPath());
2517
			buffer.append(')');
2518
			Util.verbose(buffer.toString());
2519
		}
2520
		Set packageKeys = secondaryTypesMap.keySet();
2521
		int packagesSize = packageKeys.size(), removedPackagesCount = 0;
2522
		String[] removedPackages = null;
2523
		Iterator packages = packageKeys.iterator();
2524
		while (packages.hasNext()) {
2525
			String packName = (String) packages.next();
2526
			if (packName != INDEXING_CACHE) { // != is intentional!
2527
				HashMap types = (HashMap) secondaryTypesMap.get(packName);
2528
				Set nameKeys = types.keySet();
2529
				int namesSize = nameKeys.size(), removedNamesCount = 0;
2530
				String[] removedNames = null;
2531
				Iterator names = nameKeys.iterator();
2532
				while (names.hasNext()) {
2533
					String typeName = (String) names.next();
2534
					IType type = (IType) types.get(typeName);
2535
					if (file.equals(type.getResource())) {
2536
						if (removedNames == null) removedNames = new String[namesSize];
2537
						namesSize--;
2538
						removedNames[removedNamesCount++] = typeName;
2539
					}
2540
				}
2541
				for (int i=0; i<removedNamesCount; i++) {
2542
					types.remove(removedNames[i]);
2543
				}
2544
				if (types.size() == 0) {
2545
					if (removedPackages == null) removedPackages = new String[packagesSize];
2546
					packagesSize--;
2547
					removedPackages[removedPackagesCount++] = packName;
2548
				}
2549
			}
2550
		}
2551
		for (int i=0; i<removedPackagesCount; i++) {
2552
			secondaryTypesMap.remove(removedPackages[i]);
2553
		}
2554
		if (VERBOSE) {
2555
			Util.verbose("	- new secondary types map:"); //$NON-NLS-1$
2556
			Iterator keys = secondaryTypesMap.keySet().iterator();
2557
			while (keys.hasNext()) {
2558
				String qualifiedName = (String) keys.next();
2559
				Util.verbose("		+ "+qualifiedName+':'+secondaryTypesMap.get(qualifiedName) ); //$NON-NLS-1$
2560
			}
2561
		}
2562
	}
2440
2563
2441
	/**
2564
	/**
2442
	 * Reset secondary types cache for a project got from given path.
2565
	 * Add a secondary type in temporary indexing cache for a project got from given path.
2443
	 * If secondary types cache already exist, do not reset it now to avoid
2444
	 * cache desynchronization (this reset is done in indexing thread...).
2445
	 * Instead flag the cache as dirty to store the fact that current cache
2446
	 * should be recomputed when indexing will be ended.
2447
	 * 
2566
	 * 
2448
	 * @param path Path of file containing a secondary type
2567
	 * Current secondary types cache is not modified as we want to wait that indexing
2568
	 * was finished before taking new secondary types into account.
2569
	 * 
2570
	 * Indexing cache is a specific entry in secondary types cache which key is
2571
	 * {@link #INDEXING_CACHE } and value a map with same structure than
2572
	 * secondary types cache itself.
2573
	 * 
2574
	 * @see #getSecondaryTypes(IJavaProject, boolean, IProgressMonitor)
2449
	 */
2575
	 */
2450
	public void resetSecondaryTypesCache(String path) {
2576
	public void addSecondaryType(String path, char[] key) {
2451
		if (VERBOSE) {
2577
		if (VERBOSE) {
2452
			StringBuffer buffer = new StringBuffer("JavaModelManager.resetSecondaryTypePaths("); //$NON-NLS-1$
2578
			StringBuffer buffer = new StringBuffer("JavaModelManager.addSecondaryType("); //$NON-NLS-1$
2453
			buffer.append(path);
2579
			buffer.append(path);
2580
			buffer.append(',');
2581
			buffer.append('[');
2582
			buffer.append(new String(key));
2583
			buffer.append(']');
2454
			buffer.append(')');
2584
			buffer.append(')');
2455
			Util.verbose(buffer.toString());
2585
			Util.verbose(buffer.toString());
2456
		}
2586
		}
Lines 2459-2475 Link Here
2459
		if (resource != null) {
2589
		if (resource != null) {
2460
			PerProjectInfo projectInfo = getPerProjectInfo(resource.getProject(), false);
2590
			PerProjectInfo projectInfo = getPerProjectInfo(resource.getProject(), false);
2461
			if (projectInfo != null) {
2591
			if (projectInfo != null) {
2462
				if (VERBOSE) {
2592
				// Get or create map for indexing cache
2463
					Util.verbose("-> reset cache for project: "+resource.getProject().getName()); //$NON-NLS-1$
2593
				HashMap indexingCache = null;
2594
				if (projectInfo.secondaryTypes == null) {
2595
					projectInfo.secondaryTypes = new HashMap(3);
2596
					indexingCache = new HashMap(3);
2597
					projectInfo.secondaryTypes.put(INDEXING_CACHE, indexingCache);
2598
				} else {
2599
					indexingCache = (HashMap) projectInfo.secondaryTypes.get(INDEXING_CACHE);
2600
					if (indexingCache == null) {
2601
						indexingCache = new HashMap(3);
2602
						projectInfo.secondaryTypes.put(INDEXING_CACHE, indexingCache);
2603
					}
2604
				}
2605
				// Store secondary type in indexing cache
2606
				if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(path) && resource.getType() == IResource.FILE) {
2607
					HashMap allTypes = (HashMap) indexingCache.get(resource);
2608
					if (allTypes == null) {
2609
						allTypes = new HashMap(3);
2610
						indexingCache.put(resource, allTypes);
2611
					}
2612
					ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom((IFile)resource, null);
2613
					if (unit != null) {
2614
						char[][] names = CharOperation.splitOn('/', key);
2615
						String typeName = new String(names[0]);
2616
						String packName = new String(names[1]);
2617
						HashMap packageTypes = (HashMap) allTypes.get(packName);
2618
						if (packageTypes == null) {
2619
							packageTypes = new HashMap(3);
2620
							allTypes.put(packName, packageTypes);
2621
						}
2622
						packageTypes.put(typeName, unit.getType(typeName));
2623
					}
2464
				}
2624
				}
2465
				if (projectInfo.secondaryTypes != null) {
2625
				if (VERBOSE) {
2466
					Object dirty = projectInfo.secondaryTypes.get(DIRTY_CACHE);
2626
					Util.verbose("	- indexing cache:"); //$NON-NLS-1$
2467
					if (dirty == null) {
2627
					Iterator keys = indexingCache.keySet().iterator();
2468
						projectInfo.secondaryTypes.put(DIRTY_CACHE, resource);
2628
					while (keys.hasNext()) {
2469
					} else {
2629
						IFile file = (IFile) keys.next();
2470
						HashSet resources = (dirty instanceof HashSet) ? (HashSet) dirty : new HashSet(3);
2630
						Util.verbose("		+ "+file.getFullPath()+':'+indexingCache.get(file) ); //$NON-NLS-1$
2471
						resources.add(resource);
2472
						projectInfo.secondaryTypes.put(DIRTY_CACHE, resource);
2473
					}
2631
					}
2474
				}
2632
				}
2475
			}
2633
			}
(-)model/org/eclipse/jdt/internal/core/DeltaProcessor.java (-1 / +2 lines)
Lines 2398-2407 Link Here
2398
							break;
2398
							break;
2399
					case IResourceDelta.ADDED :
2399
					case IResourceDelta.ADDED :
2400
						indexManager.addSource(file, file.getProject().getFullPath());
2400
						indexManager.addSource(file, file.getProject().getFullPath());
2401
						this.manager.removeFromSecondaryTypesCache(file, false);
2401
						break;
2402
						break;
2402
					case IResourceDelta.REMOVED :
2403
					case IResourceDelta.REMOVED :
2403
						indexManager.remove(Util.relativePath(file.getFullPath(), 1/*remove project segment*/), file.getProject().getFullPath());
2404
						indexManager.remove(Util.relativePath(file.getFullPath(), 1/*remove project segment*/), file.getProject().getFullPath());
2404
						this.manager.removeFromSecondaryTypesCache(file);
2405
						this.manager.removeFromSecondaryTypesCache(file, true);
2405
						break;
2406
						break;
2406
				}
2407
				}
2407
		}
2408
		}
(-)src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java (-8 / +74 lines)
Lines 104-110 Link Here
104
	assertProblems(message, expected, this.problemRequestor);
104
	assertProblems(message, expected, this.problemRequestor);
105
}
105
}
106
// Expect no error as soon as indexing is finished
106
// Expect no error as soon as indexing is finished
107
protected void assertNoProblem(char[] source) throws InterruptedException, JavaModelException {
107
protected void assertNoProblem(char[] source, ICompilationUnit unit) throws InterruptedException, JavaModelException {
108
	IndexManager indexManager = JavaModelManager.getJavaModelManager().getIndexManager();
108
	IndexManager indexManager = JavaModelManager.getJavaModelManager().getIndexManager();
109
	if (this.problemRequestor.problemCount > 0) {
109
	if (this.problemRequestor.problemCount > 0) {
110
		// If errors then wait for indexes to finish
110
		// If errors then wait for indexes to finish
Lines 113-119 Link Here
113
		}
113
		}
114
		// Reconcile again to see if error goes away
114
		// Reconcile again to see if error goes away
115
		this.problemRequestor.initialize(source);
115
		this.problemRequestor.initialize(source);
116
		this.workingCopy.reconcile(AST.JLS3, true, null, null);
116
		unit.reconcile(AST.JLS3, true, null, null);
117
		if (this.problemRequestor.problemCount > 0) {
117
		if (this.problemRequestor.problemCount > 0) {
118
			assertEquals("Working copy should NOT have any problem!", "", this.problemRequestor.problems.toString());
118
			assertEquals("Working copy should NOT have any problem!", "", this.problemRequestor.problems.toString());
119
		}
119
		}
Lines 2499-2505 Link Here
2499
/**
2499
/**
2500
 * Bug 36032:[plan] JavaProject.findType() fails to find second type in source file
2500
 * Bug 36032:[plan] JavaProject.findType() fails to find second type in source file
2501
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=36032"
2501
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=36032"
2502
 *
2503
 */
2502
 */
2504
public void testBug36032a() throws CoreException, InterruptedException {
2503
public void testBug36032a() throws CoreException, InterruptedException {
2505
	try {
2504
	try {
Lines 2526-2532 Link Here
2526
		this.workingCopy = getCompilationUnit("/P/Test.java").getWorkingCopy(new WorkingCopyOwner() {}, problemRequestor, null);
2525
		this.workingCopy = getCompilationUnit("/P/Test.java").getWorkingCopy(new WorkingCopyOwner() {}, problemRequestor, null);
2527
		this.workingCopy.getBuffer().setContents(source);
2526
		this.workingCopy.getBuffer().setContents(source);
2528
		this.workingCopy.reconcile(AST.JLS3, true, null, null);
2527
		this.workingCopy.reconcile(AST.JLS3, true, null, null);
2529
		assertNoProblem(sourceChars);
2528
		assertNoProblem(sourceChars, this.workingCopy);
2530
2529
2531
		// Add new secondary type
2530
		// Add new secondary type
2532
		this.createFile(
2531
		this.createFile(
Lines 2546-2552 Link Here
2546
		this.problemRequestor.initialize(sourceChars);
2545
		this.problemRequestor.initialize(sourceChars);
2547
		this.workingCopy.getBuffer().setContents(source);
2546
		this.workingCopy.getBuffer().setContents(source);
2548
		this.workingCopy.reconcile(AST.JLS3, true, null, null);
2547
		this.workingCopy.reconcile(AST.JLS3, true, null, null);
2549
		assertNoProblem(sourceChars);
2548
		assertNoProblem(sourceChars, this.workingCopy);
2550
	} finally {
2549
	} finally {
2551
		deleteProject("P");
2550
		deleteProject("P");
2552
	}
2551
	}
Lines 2581-2587 Link Here
2581
		this.workingCopy = getCompilationUnit("/P/Test.java").getWorkingCopy(new WorkingCopyOwner() {}, this.problemRequestor, null);
2580
		this.workingCopy = getCompilationUnit("/P/Test.java").getWorkingCopy(new WorkingCopyOwner() {}, this.problemRequestor, null);
2582
		this.workingCopy.getBuffer().setContents(source);
2581
		this.workingCopy.getBuffer().setContents(source);
2583
		this.workingCopy.reconcile(AST.JLS3, true, null, null);
2582
		this.workingCopy.reconcile(AST.JLS3, true, null, null);
2584
		assertNoProblem(sourceChars);
2583
		assertNoProblem(sourceChars, this.workingCopy);
2585
2584
2586
		// Delete secondary type => should get a problem
2585
		// Delete secondary type => should get a problem
2587
		waitUntilIndexesReady();
2586
		waitUntilIndexesReady();
Lines 2609-2615 Link Here
2609
		this.problemRequestor.initialize(sourceChars);
2608
		this.problemRequestor.initialize(sourceChars);
2610
		this.workingCopy.getBuffer().setContents(source);
2609
		this.workingCopy.getBuffer().setContents(source);
2611
		this.workingCopy.reconcile(AST.JLS3, true, null, null);
2610
		this.workingCopy.reconcile(AST.JLS3, true, null, null);
2612
		assertNoProblem(sourceChars);
2611
		assertNoProblem(sourceChars, this.workingCopy);
2613
	} finally {
2612
	} finally {
2614
		deleteProject("P");
2613
		deleteProject("P");
2615
	}
2614
	}
Lines 2656-2665 Link Here
2656
		this.workingCopy = getCompilationUnit("/P2/test/Test2.java").getWorkingCopy(new WorkingCopyOwner() {}, this.problemRequestor, null);
2655
		this.workingCopy = getCompilationUnit("/P2/test/Test2.java").getWorkingCopy(new WorkingCopyOwner() {}, this.problemRequestor, null);
2657
		this.workingCopy.getBuffer().setContents(source);
2656
		this.workingCopy.getBuffer().setContents(source);
2658
		this.workingCopy.reconcile(AST.JLS3, true, null, null);
2657
		this.workingCopy.reconcile(AST.JLS3, true, null, null);
2659
		assertNoProblem(sourceChars);
2658
		assertNoProblem(sourceChars, this.workingCopy);
2660
	} finally {
2659
	} finally {
2661
		deleteProject("P1");
2660
		deleteProject("P1");
2662
		deleteProject("P2");
2661
		deleteProject("P2");
2663
	}
2662
	}
2664
}
2663
}
2664
/**
2665
 * Bug 118823: [model] Secondary types cache not reset while removing _all_ secondary types from CU
2666
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=118823"
2667
 */
2668
public void testBug118823a() throws CoreException, InterruptedException {
2669
	try {
2670
		// Resources creation
2671
		createJavaProject("P", new String[] {""}, new String[] {"JCL_LIB"}, "bin");
2672
		String[] sources = {
2673
			"/P/Test.java",
2674
			"public class Test {}\n" + 
2675
			"class Secondary{}\n",
2676
			"/P/A.java",
2677
			"class X {\n" +
2678
			"	Secondary s;\n" +
2679
			"}\n"
2680
		};
2681
		int length = sources.length / 2;
2682
		this.workingCopies = new ICompilationUnit[length];
2683
		this.wcOwner = new WorkingCopyOwner() {};
2684
		for (int i=0; i<length; i++) {
2685
			createFile(sources[i*2], sources[i*2+1]);
2686
		}
2687
		
2688
		// Get working copies and reconcile
2689
		for (int i=0; i<length; i++) {
2690
			this.workingCopies[i]= getCompilationUnit(sources[i*2]).getWorkingCopy(this.wcOwner, this.problemRequestor, null);
2691
			char[] sourceChars = sources[2*i+1].toCharArray();
2692
			this.problemRequestor.initialize(sourceChars);
2693
			this.workingCopies[i].getBuffer().setContents(sources[2*i+1]);
2694
			this.workingCopies[i].reconcile(AST.JLS3, true, null, null);
2695
			assertNoProblem(sourceChars, this.workingCopies[i]);
2696
		}
2697
2698
		// Remove secondary type declaration from cu => should get a problem
2699
		String source = "public class Test {}\n";
2700
		char[] sourceChars = source.toCharArray();
2701
		this.problemRequestor.initialize(sourceChars);
2702
		this.workingCopies[0].getBuffer().setContents(source);
2703
		this.workingCopies[0].reconcile(AST.JLS3, true, null, null);
2704
		assertNoProblem(sourceChars, this.workingCopies[0]);
2705
		sourceChars = sources[3].toCharArray();
2706
		this.problemRequestor.initialize(sourceChars);
2707
		this.workingCopies[1].getBuffer().setContents(sources[3]);
2708
		this.workingCopies[1].reconcile(AST.JLS3, true, null, null);
2709
		assertEquals("Working copy should not find secondary type 'Secondary'!", 1, this.problemRequestor.problemCount);
2710
		assertProblems("Working copy should have problem!",
2711
			"----------\n" +
2712
			"1. ERROR in /P/A.java (at line 2)\n" +
2713
			"	Secondary s;\n" +
2714
			"	^^^^^^^^^\n" +
2715
			"Secondary cannot be resolved to a type\n" +
2716
			"----------\n"
2717
		);
2718
2719
		// Put back secondary type declaration from cu => problem should go away
2720
		for (int i=0; i<length; i++) {
2721
			sourceChars = sources[2*i+1].toCharArray();
2722
			this.problemRequestor.initialize(sourceChars);
2723
			this.workingCopies[i].getBuffer().setContents(sources[2*i+1]);
2724
			this.workingCopies[i].reconcile(AST.JLS3, true, null, null);
2725
			assertNoProblem(sourceChars, this.workingCopies[i]);
2726
		}
2727
	} finally {
2728
		deleteProject("P");
2729
	}
2730
}
2665
}
2731
}
(-)src/org/eclipse/jdt/core/tests/model/ClassNameTests.java (-1 / +43 lines)
Lines 34-40 Link Here
34
static {
34
static {
35
//	org.eclipse.jdt.internal.core.NameLookup.VERBOSE = true;
35
//	org.eclipse.jdt.internal.core.NameLookup.VERBOSE = true;
36
//	TESTS_NAMES = new String[] { "testFindSecondaryType_Bug72179" };
36
//	TESTS_NAMES = new String[] { "testFindSecondaryType_Bug72179" };
37
//	TESTS_PREFIX = "testReconcile";
37
//	TESTS_PREFIX = "testBug118823";
38
}
38
}
39
public static Test suite() {
39
public static Test suite() {
40
	Test suite = buildTestSuite(ClassNameTests.class);
40
	Test suite = buildTestSuite(ClassNameTests.class);
Lines 1166-1169 Link Here
1166
public void testFindSecondaryType_Unknown03() throws JavaModelException, CoreException {
1166
public void testFindSecondaryType_Unknown03() throws JavaModelException, CoreException {
1167
	assertTypeUnknown("org.eclipse.jdt.core.test.Unknown");
1167
	assertTypeUnknown("org.eclipse.jdt.core.test.Unknown");
1168
}
1168
}
1169
/**
1170
 * Bug 118823: [model] Secondary types cache not reset while removing _all_ secondary types from CU
1171
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=118823"
1172
 */
1173
public void testBug118823() throws JavaModelException, CoreException {
1174
	try {
1175
		// Create resources
1176
		IJavaProject javaProject = createJavaProject("P", new String[] {""}, "");
1177
		createFile(
1178
			"/P/Test.java", 
1179
			"public class Test {}\n" +
1180
			"class Secondary{}\n"
1181
		);
1182
		createFile(
1183
			"/P/X.java", 
1184
			"public class X {\n" +
1185
			"	Secondary s;\n" +
1186
			"}\n"
1187
		);
1188
1189
		// Verify that secondary is found
1190
		IType type = javaProject.findType("", "Secondary", new NullProgressMonitor());
1191
		assertTrue("type 'Secondry' should exist!", type != null && type.exists());
1192
		assertEquals("Expected type 'Secondary' NOT found!",
1193
			"class Secondary [in Test.java [in <default> [in <project root> [in P]]]]",
1194
			type.toString()
1195
		);
1196
1197
		// Delete file and recreate it without secondary
1198
		deleteFile("/P/Test.java");
1199
		createFile(
1200
			"/P/Test.java", 
1201
			"public class X {}\n"
1202
		);
1203
		
1204
		// Verify that secondary is NOT found
1205
		type = javaProject.findType("", "Secondary", new NullProgressMonitor());
1206
		assertTrue("type 'Secondary' should NOT exist!", type == null);
1207
	} finally {
1208
		deleteProject("P");
1209
	}
1210
}
1169
}
1211
}

Return to bug 118823