35
35
import org .eclipse .core .internal .events .ILifecycleListener ;
36
36
import org .eclipse .core .internal .events .LifecycleEvent ;
37
37
import org .eclipse .core .internal .utils .Cache ;
38
+ import org .eclipse .core .internal .utils .Cache .Entry ;
38
39
import org .eclipse .core .internal .utils .Messages ;
39
40
import org .eclipse .core .internal .utils .Policy ;
40
41
import org .eclipse .core .internal .watson .ElementTreeIterator ;
@@ -235,7 +236,7 @@ public long skip(long n) throws IOException {
235
236
236
237
private static final String PT_CONTENTTYPES = "contentTypes" ; //$NON-NLS-1$
237
238
238
- private Cache cache ;
239
+ private final Cache < IPath , IContentDescription > cache = new Cache <>() ;
239
240
240
241
private volatile byte cacheState ;
241
242
@@ -269,7 +270,7 @@ synchronized void doFlushCache(final IProgressMonitor monitor, Set<IPath> toClea
269
270
try {
270
271
setCacheState (FLUSHING_CACHE );
271
272
// flush the MRU cache
272
- cache .discardAll ();
273
+ cache .clear ();
273
274
SubMonitor subMonitor = SubMonitor .convert (monitor );
274
275
if (toClean .isEmpty ()) {
275
276
// no project was added, must be a global flush
@@ -317,10 +318,6 @@ private void clearContentFlags(IPath root, final IProgressMonitor monitor) {
317
318
Policy .debug ("Content type cache for " + root + " flushed in " + (System .currentTimeMillis () - flushStart ) + " ms" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
318
319
}
319
320
320
- Cache getCache () {
321
- return cache ;
322
- }
323
-
324
321
/** Public so tests can examine it. */
325
322
public byte getCacheState () {
326
323
if (cacheState != 0 ) {
@@ -364,7 +361,7 @@ public IContentDescription getDescriptionFor(File file, ResourceInfo info, boole
364
361
if (getCacheState () == INVALID_CACHE ) {
365
362
// discard the cache, so it can be used before the flush job starts
366
363
setCacheState (ABOUT_TO_FLUSH );
367
- cache .discardAll ();
364
+ cache .clear ();
368
365
// the cache is not good, flush it
369
366
flushJob .schedule (1000 );
370
367
}
@@ -390,10 +387,10 @@ public IContentDescription getDescriptionFor(File file, ResourceInfo info, boole
390
387
if (inSync ) {
391
388
// tries to get a description from the cache
392
389
synchronized (this ) {
393
- Cache . Entry entry = cache .getEntry (file .getFullPath ());
390
+ Entry < IContentDescription > entry = cache .getEntry (file .getFullPath ());
394
391
if (entry != null && entry .getTimestamp () == getTimestamp (info ))
395
392
// there was a description in the cache, and it was up to date
396
- return ( IContentDescription ) entry .getCached ();
393
+ return entry .getCached ();
397
394
}
398
395
}
399
396
@@ -403,10 +400,10 @@ public IContentDescription getDescriptionFor(File file, ResourceInfo info, boole
403
400
404
401
synchronized (this ) {
405
402
// tries to get a description from the cache
406
- Cache . Entry entry = cache .getEntry (file .getFullPath ());
403
+ Entry < IContentDescription > entry = cache .getEntry (file .getFullPath ());
407
404
if (entry != null && inSync && entry .getTimestamp () == getTimestamp (info ))
408
405
// there was a description in the cache, and it was up to date
409
- return ( IContentDescription ) entry .getCached ();
406
+ return entry .getCached ();
410
407
411
408
if (getCacheState () != ABOUT_TO_FLUSH ) {
412
409
// we are going to add an entry to the cache or update the resource info - remember that
@@ -427,14 +424,7 @@ public IContentDescription getDescriptionFor(File file, ResourceInfo info, boole
427
424
}
428
425
}
429
426
// we actually got a description filled by a describer (or a default description for a non-obvious type)
430
- if (entry == null )
431
- // there was no entry before - create one
432
- entry = cache .addEntry (file .getFullPath (), newDescription , getTimestamp (info ));
433
- else {
434
- // just update the existing entry
435
- entry .setTimestamp (getTimestamp (info ));
436
- entry .setCached (newDescription );
437
- }
427
+ entry = cache .addEntry (file .getFullPath (), newDescription , getTimestamp (info ));
438
428
return newDescription ;
439
429
}
440
430
}
@@ -470,7 +460,7 @@ public synchronized void invalidateCache(boolean flush, IProject project) {
470
460
try {
471
461
// discard the cache, so it can be used before the flush job starts
472
462
setCacheState (ABOUT_TO_FLUSH );
473
- cache .discardAll ();
463
+ cache .clear ();
474
464
} catch (CoreException e ) {
475
465
Policy .log (e .getStatus ());
476
466
}
@@ -579,16 +569,14 @@ public void shutdown(IProgressMonitor monitor) throws CoreException {
579
569
IExtensionRegistry registry = Platform .getExtensionRegistry ();
580
570
if (registry != null )
581
571
registry .removeRegistryChangeListener (this );
582
- cache .dispose ();
583
- cache = null ;
572
+ cache .clear ();
584
573
flushJob .cancel ();
585
574
flushJob = null ;
586
575
projectContentTypes = null ;
587
576
}
588
577
589
578
@ Override
590
579
public void startup (IProgressMonitor monitor ) throws CoreException {
591
- cache = new Cache (100 , 1000 , 0.1 );
592
580
projectContentTypes = new ProjectContentTypes (workspace );
593
581
getCacheState ();
594
582
if (cacheState == FLUSHING_CACHE || cacheState == ABOUT_TO_FLUSH )
0 commit comments