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 |
} |