diff options
author | Andrey Loskutov | 2018-03-11 18:42:34 +0000 |
---|---|---|
committer | Andrey Loskutov | 2018-03-11 21:13:39 +0000 |
commit | 6eebbbec51d95b3167d6dae7bf909a0c2e8a23e2 (patch) | |
tree | 6b14a16b50a9d779dfc0858714c61a79465c75a7 | |
parent | 5063a3b3b0f4591017b42136112f685ccc4edd02 (diff) | |
download | eclipse.jdt.core-6eebbbec51d95b3167d6dae7bf909a0c2e8a23e2.tar.gz eclipse.jdt.core-6eebbbec51d95b3167d6dae7bf909a0c2e8a23e2.tar.xz eclipse.jdt.core-6eebbbec51d95b3167d6dae7bf909a0c2e8a23e2.zip |
Bug 532290 - Generify JavaModelManagerI20180311-2000
Except few cases simple type inferring, one place required a more
complex refactoring.
JMM maintained (for some obscure reasons) a temporary entry in the
PerProjectInfo.secondaryTypes map (with the key INDEXED_SECONDARY_TYPES)
containing ... another map with different type bounds, being used during
search. Instead of maintaining an incompatible entry within the
PerProjectInfo.secondaryTypes map we replace here it with a new field
PerProjectInfo.indexingSecondaryCache.
Change-Id: Ie7cc7a9e64e03624c8fad464208ebcdd86800000
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
4 files changed, 392 insertions, 398 deletions
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessingState.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessingState.java index 46926dff6e..0029b3cb44 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessingState.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessingState.java @@ -23,6 +23,7 @@ import java.util.*; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; import org.eclipse.jdt.core.*; +import org.eclipse.jdt.internal.core.DeltaProcessor.RootInfo; import org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo; import org.eclipse.jdt.internal.core.nd.indexer.Indexer; import org.eclipse.jdt.internal.core.nd.indexer.IndexerEvent; @@ -61,20 +62,20 @@ public class DeltaProcessingState implements IResourceChangeListener, Indexer.Li } /* A table from IPath (from a classpath entry) to DeltaProcessor.RootInfo */ - public HashMap roots = new HashMap(); + public HashMap<IPath, List<RootInfo>> roots = new HashMap<>(); /* A table from IPath (from a classpath entry) to ArrayList of DeltaProcessor.RootInfo * Used when an IPath corresponds to more than one root */ - public HashMap otherRoots = new HashMap(); + public HashMap<IPath, List<RootInfo>> otherRoots = new HashMap<>(); /* A table from IPath (from a classpath entry) to DeltaProcessor.RootInfo * from the last time the delta processor was invoked. */ - public HashMap oldRoots = new HashMap(); + public HashMap<IPath, List<RootInfo>> oldRoots = new HashMap<>(); /* A table from IPath (from a classpath entry) to ArrayList of DeltaProcessor.RootInfo * from the last time the delta processor was invoked. * Used when an IPath corresponds to more than one root */ - public HashMap oldOtherRoots = new HashMap(); + public HashMap<IPath, List<RootInfo>> oldOtherRoots = new HashMap<>(); /* A table from IPath (a source attachment path from a classpath entry) to IPath (a root path) */ public HashMap sourceAttachments = new HashMap(); @@ -89,7 +90,7 @@ public class DeltaProcessingState implements IResourceChangeListener, Indexer.Li private Set initializingThreads = Collections.synchronizedSet(new HashSet()); /* A table from file system absoulte path (String) to timestamp (Long) */ - public Hashtable externalTimeStamps; + public Hashtable<IPath, Long> externalTimeStamps; /* * Map from IProject to ClasspathChange @@ -487,9 +488,9 @@ public class DeltaProcessingState implements IResourceChangeListener, Indexer.Li } - public Hashtable getExternalLibTimeStamps() { + public Hashtable<IPath, Long> getExternalLibTimeStamps() { if (this.externalTimeStamps == null) { - Hashtable timeStamps = new Hashtable(); + Hashtable<IPath, Long> timeStamps = new Hashtable<>(); File timestampsFile = getTimeStampsFile(); DataInputStream in = null; try { diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java index 74cbf5c8d5..3393181657 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java @@ -41,6 +41,7 @@ import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -110,6 +111,7 @@ import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.IParent; import org.eclipse.jdt.core.IProblemRequestor; import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.ITypeRoot; import org.eclipse.jdt.core.JavaConventions; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; @@ -129,6 +131,7 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt; import org.eclipse.jdt.internal.compiler.util.JRTUtil; import org.eclipse.jdt.internal.compiler.util.ObjectVector; +import org.eclipse.jdt.internal.core.DeltaProcessor.RootInfo; import org.eclipse.jdt.internal.core.JavaProjectElementInfo.ProjectCache; import org.eclipse.jdt.internal.core.builder.JavaBuilder; import org.eclipse.jdt.internal.core.dom.SourceRangeVerifier; @@ -149,7 +152,6 @@ import org.eclipse.jdt.internal.core.search.processing.IJob; import org.eclipse.jdt.internal.core.search.processing.JobManager; import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject; import org.eclipse.jdt.internal.core.util.LRUCache; -import org.eclipse.jdt.internal.core.util.LRUCache.Stats; import org.eclipse.jdt.internal.core.util.Messages; import org.eclipse.jdt.internal.core.util.Util; import org.eclipse.jdt.internal.core.util.WeakHashSet; @@ -174,7 +176,6 @@ import org.xml.sax.SAXException; * The single instance of <code>JavaModelManager</code> is available from * the static method <code>JavaModelManager.getJavaModelManager()</code>. */ -@SuppressWarnings({ "rawtypes", "unchecked" }) public class JavaModelManager implements ISaveParticipant, IContentTypeChangeListener { private static ServiceRegistration<DebugOptionsListener> DEBUG_REGISTRATION; private static final String NON_CHAINING_JARS_CACHE = "nonChainingJarsCache"; //$NON-NLS-1$ @@ -242,21 +243,21 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis /** * Classpath variables pool */ - public HashMap variables = new HashMap(5); - public HashSet variablesWithInitializer = new HashSet(5); - public HashMap deprecatedVariables = new HashMap(5); - public HashSet readOnlyVariables = new HashSet(5); - public HashMap previousSessionVariables = new HashMap(5); - private ThreadLocal variableInitializationInProgress = new ThreadLocal(); + public HashMap<String, IPath> variables = new HashMap<>(5); + public HashSet<String> variablesWithInitializer = new HashSet<>(5); + public HashMap<String, String> deprecatedVariables = new HashMap<>(5); + public HashSet<String> readOnlyVariables = new HashSet<>(5); + public HashMap<String, IPath> previousSessionVariables = new HashMap<>(5); + private ThreadLocal<Set<String>> variableInitializationInProgress = new ThreadLocal<>(); /** * Classpath containers pool */ - public HashMap containers = new HashMap(5); - public HashMap previousSessionContainers = new HashMap(5); - private ThreadLocal containerInitializationInProgress = new ThreadLocal(); - ThreadLocal containersBeingInitialized = new ThreadLocal(); - + public HashMap<IJavaProject, Map<IPath, IClasspathContainer>> containers = new HashMap<>(5); + public HashMap<IJavaProject, Map<IPath, IClasspathContainer>> previousSessionContainers = new HashMap<>(5); + private ThreadLocal<Map<IJavaProject, Set<IPath>>> containerInitializationInProgress = new ThreadLocal<>(); + ThreadLocal<Map<IJavaProject, Map<IPath, IClasspathContainer>>> containersBeingInitialized = new ThreadLocal<>(); + public static final int NO_BATCH_INITIALIZATION = 0; public static final int NEED_BATCH_INITIALIZATION = 1; public static final int BATCH_INITIALIZATION_IN_PROGRESS = 2; @@ -264,12 +265,12 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public int batchContainerInitializations = NO_BATCH_INITIALIZATION; public BatchInitializationMonitor batchContainerInitializationsProgress = new BatchInitializationMonitor(); - public Hashtable containerInitializersCache = new Hashtable(5); + public Hashtable<String, ClasspathContainerInitializer> containerInitializersCache = new Hashtable<>(5); /* * A HashSet that contains the IJavaProject whose classpath is being resolved. */ - private ThreadLocal classpathsBeingResolved = new ThreadLocal(); + private ThreadLocal<Set<IJavaProject>> classpathsBeingResolved = new ThreadLocal<>(); /* * The unique workspace scope @@ -291,7 +292,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis /* * Map from a package fragment root's path to a source attachment property (source path + ATTACHMENT_PROPERTY_DELIMITER + source root path) */ - public Map rootPathToAttachments = new Hashtable(); + public Map<IPath, String> rootPathToAttachments = new Hashtable<>(); public final static String CP_VARIABLE_PREFERENCES_PREFIX = JavaCore.PLUGIN_ID+".classpathVariable."; //$NON-NLS-1$ public final static String CP_CONTAINER_PREFERENCES_PREFIX = JavaCore.PLUGIN_ID+".classpathContainer."; //$NON-NLS-1$ @@ -331,7 +332,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * Name of the JVM parameter to specify whether or not referenced JAR should be resolved for container libraries. */ private static final String RESOLVE_REFERENCED_LIBRARIES_FOR_CONTAINERS = "resolveReferencedLibrariesForContainers"; //$NON-NLS-1$ - + /** * Name of the JVM parameter to specify how many compilation units must be handled at once by the builder. * The default value is represented by <code>AbstractImageBuilder#MAX_AT_ONCE</code>. @@ -402,8 +403,6 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public static final String CONTAINER_INITIALIZER_PERF = JavaCore.PLUGIN_ID + "/perf/containerinitializer" ; //$NON-NLS-1$ public static final String RECONCILE_PERF = JavaCore.PLUGIN_ID + "/perf/reconcile" ; //$NON-NLS-1$ - private final static String INDEXED_SECONDARY_TYPES = "#@*_indexing secondary cache_*@#"; //$NON-NLS-1$ - public static boolean PERF_VARIABLE_INITIALIZER = false; public static boolean PERF_CONTAINER_INITIALIZER = false; // Non-static, which will give it a chance to retain the default when and if JavaModelManager is restarted. @@ -415,9 +414,9 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis private final static int UNKNOWN_OPTION = 0; private final static int DEPRECATED_OPTION = 1; private final static int VALID_OPTION = 2; - HashSet optionNames = new HashSet(20); - Map deprecatedOptions = new HashMap(); - Hashtable optionsCache; + HashSet<String> optionNames = new HashSet<>(20); + Map<String, String[]> deprecatedOptions = new HashMap<>(); + Hashtable<String, String> optionsCache; // Preferences public final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2]; @@ -436,7 +435,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * it contains CompilationParticipants. */ private Object[][] registeredParticipants = null; - private HashSet managedMarkerTypes; + private HashSet<String> managedMarkerTypes; public CompilationParticipant[] getCompilationParticipants(IJavaProject project) { final Object[][] participantsPerSource = getRegisteredParticipants(); @@ -476,7 +475,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis return result; } - public HashSet managedMarkerTypes() { + public HashSet<String> managedMarkerTypes() { if (this.managedMarkerTypes == null) { // force extension points to be read getRegisteredParticipants(); @@ -488,13 +487,13 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis if (this.registeredParticipants != null) { return this.registeredParticipants; } - this.managedMarkerTypes = new HashSet(); + this.managedMarkerTypes = new HashSet<>(); IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(JavaCore.PLUGIN_ID, COMPILATION_PARTICIPANT_EXTPOINT_ID); if (extension == null) return this.registeredParticipants = NO_PARTICIPANTS; - final ArrayList modifyingEnv = new ArrayList(); - final ArrayList creatingProblems = new ArrayList(); - final ArrayList others = new ArrayList(); + final ArrayList<IConfigurationElement> modifyingEnv = new ArrayList<>(); + final ArrayList<IConfigurationElement> creatingProblems = new ArrayList<>(); + final ArrayList<IConfigurationElement> others = new ArrayList<>(); IExtension[] extensions = extension.getExtensions(); // for all extensions of this point... for(int i = 0; i < extensions.length; i++) { @@ -586,7 +585,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } } - private int sortParticipants(ArrayList group, IConfigurationElement[] configElements, int index) { + private int sortParticipants(ArrayList<IConfigurationElement> group, IConfigurationElement[] configElements, int index) { int size = group.size(); if (size == 0) return index; Object[] elements = group.toArray(); @@ -614,7 +613,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public final CompilationParticipants compilationParticipants = new CompilationParticipants(); /* whether an AbortCompilationUnit should be thrown when the source of a compilation unit cannot be retrieved */ - public ThreadLocal<Boolean> abortOnMissingSource = new ThreadLocal(); + public ThreadLocal<Boolean> abortOnMissingSource = new ThreadLocal<>(); private ExternalFoldersManager externalFoldersManager = ExternalFoldersManager.getExternalFoldersManager(); @@ -660,74 +659,74 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis return CONTAINER_INITIALIZATION_IN_PROGRESS; } - Map projectContainers = (Map)this.containers.get(project); + Map<IPath, IClasspathContainer> projectContainers = this.containers.get(project); if (projectContainers == null){ return null; } - IClasspathContainer container = (IClasspathContainer)projectContainers.get(containerPath); + IClasspathContainer container = projectContainers.get(containerPath); return container; } public synchronized IClasspathContainer containerGetDefaultToPreviousSession(IJavaProject project, IPath containerPath) { - Map projectContainers = (Map)this.containers.get(project); + Map<IPath, IClasspathContainer> projectContainers = this.containers.get(project); if (projectContainers == null) return getPreviousSessionContainer(containerPath, project); - IClasspathContainer container = (IClasspathContainer)projectContainers.get(containerPath); + IClasspathContainer container = projectContainers.get(containerPath); if (container == null) return getPreviousSessionContainer(containerPath, project); return container; } private boolean containerIsInitializationInProgress(IJavaProject project, IPath containerPath) { - Map initializations = (Map)this.containerInitializationInProgress.get(); + Map<IJavaProject, Set<IPath>> initializations = this.containerInitializationInProgress.get(); if (initializations == null) return false; - HashSet projectInitializations = (HashSet) initializations.get(project); + Set<IPath> projectInitializations = initializations.get(project); if (projectInitializations == null) return false; return projectInitializations.contains(containerPath); } private void containerAddInitializationInProgress(IJavaProject project, IPath containerPath) { - Map initializations = (Map)this.containerInitializationInProgress.get(); + Map<IJavaProject, Set<IPath>> initializations = this.containerInitializationInProgress.get(); if (initializations == null) - this.containerInitializationInProgress.set(initializations = new HashMap()); - HashSet projectInitializations = (HashSet) initializations.get(project); + this.containerInitializationInProgress.set(initializations = new HashMap<>()); + Set<IPath> projectInitializations = initializations.get(project); if (projectInitializations == null) - initializations.put(project, projectInitializations = new HashSet()); + initializations.put(project, projectInitializations = new HashSet<>()); projectInitializations.add(containerPath); } - + public void containerBeingInitializedPut(IJavaProject project, IPath containerPath, IClasspathContainer container) { - Map perProjectContainers = (Map)this.containersBeingInitialized.get(); + Map<IJavaProject, Map<IPath, IClasspathContainer>> perProjectContainers = this.containersBeingInitialized.get(); if (perProjectContainers == null) - this.containersBeingInitialized.set(perProjectContainers = new HashMap()); - HashMap perPathContainers = (HashMap) perProjectContainers.get(project); + this.containersBeingInitialized.set(perProjectContainers = new HashMap<>()); + Map<IPath, IClasspathContainer> perPathContainers = perProjectContainers.get(project); if (perPathContainers == null) - perProjectContainers.put(project, perPathContainers = new HashMap()); + perProjectContainers.put(project, perPathContainers = new HashMap<>()); perPathContainers.put(containerPath, container); } public IClasspathContainer containerBeingInitializedGet(IJavaProject project, IPath containerPath) { - Map perProjectContainers = (Map)this.containersBeingInitialized.get(); + Map<IJavaProject, Map<IPath, IClasspathContainer>> perProjectContainers = this.containersBeingInitialized.get(); if (perProjectContainers == null) return null; - HashMap perPathContainers = (HashMap) perProjectContainers.get(project); + Map<IPath, IClasspathContainer> perPathContainers = perProjectContainers.get(project); if (perPathContainers == null) return null; - return (IClasspathContainer) perPathContainers.get(containerPath); + return perPathContainers.get(containerPath); } public IClasspathContainer containerBeingInitializedRemove(IJavaProject project, IPath containerPath) { - Map perProjectContainers = (Map)this.containersBeingInitialized.get(); + Map<IJavaProject, Map<IPath, IClasspathContainer>> perProjectContainers = this.containersBeingInitialized.get(); if (perProjectContainers == null) return null; - HashMap perPathContainers = (HashMap) perProjectContainers.get(project); + Map<IPath, IClasspathContainer> perPathContainers = perProjectContainers.get(project); if (perPathContainers == null) return null; - IClasspathContainer container = (IClasspathContainer) perPathContainers.remove(containerPath); + IClasspathContainer container = perPathContainers.remove(containerPath); if (perPathContainers.size() == 0) - perPathContainers.remove(project); + perProjectContainers.remove(project); if (perProjectContainers.size() == 0) this.containersBeingInitialized.set(null); return container; @@ -744,9 +743,9 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } else { containerRemoveInitializationInProgress(project, containerPath); - Map projectContainers = (Map)this.containers.get(project); + Map<IPath, IClasspathContainer> projectContainers = this.containers.get(project); if (projectContainers == null){ - projectContainers = new HashMap(1); + projectContainers = new HashMap<>(1); this.containers.put(project, projectContainers); } @@ -756,7 +755,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis projectContainers.put(containerPath, container); } // discard obsoleted information about previous session - Map previousContainers = (Map)this.previousSessionContainers.get(project); + Map<IPath, IClasspathContainer> previousContainers = this.previousSessionContainers.get(project); if (previousContainers != null){ previousContainers.remove(containerPath); } @@ -768,7 +767,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * The given project is being removed. Remove all containers for this project from the cache. */ public synchronized void containerRemove(IJavaProject project) { - Map initializations = (Map) this.containerInitializationInProgress.get(); + Map<IJavaProject, Set<IPath>> initializations = this.containerInitializationInProgress.get(); if (initializations != null) { initializations.remove(project); } @@ -927,10 +926,10 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } private void containerRemoveInitializationInProgress(IJavaProject project, IPath containerPath) { - Map initializations = (Map)this.containerInitializationInProgress.get(); + Map<IJavaProject, Set<IPath>> initializations = this.containerInitializationInProgress.get(); if (initializations == null) return; - HashSet projectInitializations = (HashSet) initializations.get(project); + Set<IPath> projectInitializations = initializations.get(project); if (projectInitializations == null) return; projectInitializations.remove(containerPath); @@ -943,13 +942,13 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis private synchronized void containersReset(String[] containerIDs) { for (int i = 0; i < containerIDs.length; i++) { String containerID = containerIDs[i]; - Iterator projectIterator = this.containers.values().iterator(); + Iterator<Map<IPath, IClasspathContainer>> projectIterator = this.containers.values().iterator(); while (projectIterator.hasNext()){ - Map projectContainers = (Map) projectIterator.next(); + Map<IPath, IClasspathContainer> projectContainers = projectIterator.next(); if (projectContainers != null){ - Iterator containerIterator = projectContainers.keySet().iterator(); + Iterator<IPath> containerIterator = projectContainers.keySet().iterator(); while (containerIterator.hasNext()){ - IPath containerPath = (IPath)containerIterator.next(); + IPath containerPath = containerIterator.next(); if (containerID.equals(containerPath.segment(0))) { // registered container projectContainers.put(containerPath, null); // reset container value, but leave entry in Map } @@ -1175,7 +1174,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) continue; IPath rootPath = entry.getPath(); if (rootPath.equals(resourcePath)) { - if (isJavaLike) + if (isJavaLike) return null; return project.getPackageFragmentRoot(resource); } else if (rootPath.isPrefixOf(resourcePath)) { @@ -1233,7 +1232,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis /** * Set of elements which are out of sync with their buffers. */ - protected HashSet<Openable> elementsOutOfSynchWithBuffers = new HashSet(11); + protected HashSet<Openable> elementsOutOfSynchWithBuffers = new HashSet<>(11); /** * Holds the state used for delta processing. @@ -1246,18 +1245,18 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * Table from IProject to PerProjectInfo. * NOTE: this object itself is used as a lock to synchronize creation/removal of per project infos */ - protected Map perProjectInfos = new HashMap(5); + protected Map<IProject, PerProjectInfo> perProjectInfos = new HashMap<>(5); /** * Table from WorkingCopyOwner to a table of ICompilationUnit (working copy handle) to PerWorkingCopyInfo. * NOTE: this object itself is used as a lock to synchronize creation/removal of per working copy infos */ - protected Map perWorkingCopyInfos = new HashMap(5); + protected HashMap<WorkingCopyOwner, Map<CompilationUnit, PerWorkingCopyInfo>> perWorkingCopyInfos = new HashMap<>(5); /** * A weak set of the known search scopes. */ - protected WeakHashMap searchScopes = new WeakHashMap(); + protected WeakHashMap<AbstractSearchScope, ?> searchScopes = new WeakHashMap<>(); public static class PerProjectInfo { private static final int JAVADOC_CACHE_INITIAL_SIZE = 10; @@ -1274,14 +1273,20 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public boolean writtingRawClasspath = false; public IClasspathEntry[] resolvedClasspath; public IJavaModelStatus unresolvedEntryStatus; - public Map rootPathToRawEntries; // reverse map from a package fragment root's path to the raw entry - public Map rootPathToResolvedEntries; // map from a package fragment root's path to the resolved entry + public Map<IPath, IClasspathEntry> rootPathToRawEntries; // reverse map from a package fragment root's path to the raw entry + public Map<IPath, IClasspathEntry> rootPathToResolvedEntries; // map from a package fragment root's path to the resolved entry public IPath outputLocation; public Map<IPath, ObjectVector> jrtRoots; // A map between a JRT file system (as a string) and the package fragment roots found in it. public IEclipsePreferences preferences; - public Hashtable options; - public Hashtable secondaryTypes; + public Hashtable<String, String> options; + public Hashtable<String, Map<String, IType>> secondaryTypes; + /** + * The temporary structure used while indexing, previously known as INDEXED_SECONDARY_TYPES entry + */ + volatile Map<IFile, Map<String, Map<String, IType>>> indexingSecondaryCache; + + // NB: PackageFragment#getAttachedJavadoc uses this map differently // and stores String data, not JavadocContents as values public LRUCache<IJavaElement, Object> javadocCache; @@ -1299,14 +1304,14 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis return null; return this.resolvedClasspath; } - + public void forgetExternalTimestampsAndIndexes() { IClasspathEntry[] classpath = this.resolvedClasspath; if (classpath == null) return; JavaModelManager manager = JavaModelManager.getJavaModelManager(); IndexManager indexManager = manager.indexManager; - Map externalTimeStamps = manager.deltaState.getExternalLibTimeStamps(); - HashMap rootInfos = JavaModelManager.getDeltaState().otherRoots; + Hashtable<IPath, Long> externalTimeStamps = manager.deltaState.getExternalLibTimeStamps(); + HashMap<IPath, List<RootInfo>> rootInfos = JavaModelManager.getDeltaState().otherRoots; for (int i = 0, length = classpath.length; i < length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { @@ -1322,7 +1327,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public void rememberExternalLibTimestamps() { IClasspathEntry[] classpath = this.resolvedClasspath; if (classpath == null) return; - Map externalTimeStamps = JavaModelManager.getJavaModelManager().deltaState.getExternalLibTimeStamps(); + Map<IPath, Long> externalTimeStamps = JavaModelManager.getJavaModelManager().deltaState.getExternalLibTimeStamps(); for (int i = 0, length = classpath.length; i < length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { @@ -1341,17 +1346,17 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public synchronized ClasspathChange resetResolvedClasspath() { // clear non-chaining jars cache and invalid jars cache JavaModelManager.getJavaModelManager().resetClasspathListCache(); - + // null out resolved information return setResolvedClasspath(null, null, null, null, this.rawTimeStamp, true/*add classpath change*/); } - private ClasspathChange setClasspath(IClasspathEntry[] newRawClasspath, IClasspathEntry[] referencedEntries, IPath newOutputLocation, IJavaModelStatus newRawClasspathStatus, IClasspathEntry[] newResolvedClasspath, Map newRootPathToRawEntries, Map newRootPathToResolvedEntries, IJavaModelStatus newUnresolvedEntryStatus, boolean addClasspathChange) { + private ClasspathChange setClasspath(IClasspathEntry[] newRawClasspath, IClasspathEntry[] referencedEntries, IPath newOutputLocation, IJavaModelStatus newRawClasspathStatus, IClasspathEntry[] newResolvedClasspath, Map<IPath, IClasspathEntry> newRootPathToRawEntries, Map<IPath, IClasspathEntry> newRootPathToResolvedEntries, IJavaModelStatus newUnresolvedEntryStatus, boolean addClasspathChange) { if (DEBUG_CLASSPATH) { System.out.println("Setting resolved classpath for " + this.project.getFullPath()); //$NON-NLS-1$ if (newResolvedClasspath == null) { System.out.println("New classpath = null"); //$NON-NLS-1$ - } else { + } else { for (IClasspathEntry next : newResolvedClasspath) { System.out.println(" " + next); //$NON-NLS-1$ } @@ -1368,7 +1373,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis this.rootPathToRawEntries = newRootPathToRawEntries; this.rootPathToResolvedEntries = newRootPathToResolvedEntries; this.unresolvedEntryStatus = newUnresolvedEntryStatus; - this.javadocCache = new LRUCache(JAVADOC_CACHE_INITIAL_SIZE); + this.javadocCache = new LRUCache<>(JAVADOC_CACHE_INITIAL_SIZE); return classpathChange; } @@ -1389,11 +1394,11 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis return setClasspath(newRawClasspath, referencedEntries, newOutputLocation, newRawClasspathStatus, null/*resolved classpath*/, null/*root to raw map*/, null/*root to resolved map*/, null/*unresolved status*/, true/*add classpath change*/); } - public ClasspathChange setResolvedClasspath(IClasspathEntry[] newResolvedClasspath, Map newRootPathToRawEntries, Map newRootPathToResolvedEntries, IJavaModelStatus newUnresolvedEntryStatus, int timeStamp, boolean addClasspathChange) { + public ClasspathChange setResolvedClasspath(IClasspathEntry[] newResolvedClasspath, Map<IPath, IClasspathEntry> newRootPathToRawEntries, Map<IPath, IClasspathEntry> newRootPathToResolvedEntries, IJavaModelStatus newUnresolvedEntryStatus, int timeStamp, boolean addClasspathChange) { return setResolvedClasspath(newResolvedClasspath, null, newRootPathToRawEntries, newRootPathToResolvedEntries, newUnresolvedEntryStatus, timeStamp, addClasspathChange); } - - public synchronized ClasspathChange setResolvedClasspath(IClasspathEntry[] newResolvedClasspath, IClasspathEntry[] referencedEntries, Map newRootPathToRawEntries, Map newRootPathToResolvedEntries, IJavaModelStatus newUnresolvedEntryStatus, int timeStamp, boolean addClasspathChange) { + + public synchronized ClasspathChange setResolvedClasspath(IClasspathEntry[] newResolvedClasspath, IClasspathEntry[] referencedEntries, Map<IPath, IClasspathEntry> newRootPathToRawEntries, Map<IPath, IClasspathEntry> newRootPathToResolvedEntries, IJavaModelStatus newUnresolvedEntryStatus, int timeStamp, boolean addClasspathChange) { if (this.rawTimeStamp != timeStamp) return null; return setClasspath(this.rawClasspath, referencedEntries, this.outputLocation, this.rawClasspathStatus, newResolvedClasspath, newRootPathToRawEntries, newRootPathToResolvedEntries, newUnresolvedEntryStatus, addClasspathChange); @@ -1407,9 +1412,9 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis /** * Reads the classpath and caches the entries. Returns a two-dimensional array, where the number of elements in the row is fixed to 2. * The first element is an array of raw classpath entries and the second element is an array of referenced entries that may have been stored - * by the client earlier. See {@link IJavaProject#getReferencedClasspathEntries()} for more details. - * - */ + * by the client earlier. See {@link IJavaProject#getReferencedClasspathEntries()} for more details. + * + */ public synchronized IClasspathEntry[][] readAndCacheClasspath(JavaProject javaProject) { // read file entries and update status IClasspathEntry[][] classpath; @@ -1503,14 +1508,14 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } public boolean writeAndCacheClasspath( - JavaProject javaProject, - final IClasspathEntry[] newRawClasspath, + JavaProject javaProject, + final IClasspathEntry[] newRawClasspath, IClasspathEntry[] newReferencedEntries, final IPath newOutputLocation) throws JavaModelException { try { this.writtingRawClasspath = true; if (newReferencedEntries == null) newReferencedEntries = this.referencedEntries; - + // write .classpath if (!javaProject.writeFileEntries(newRawClasspath, newReferencedEntries, newOutputLocation)) { return false; @@ -1522,7 +1527,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } return true; } - + public boolean writeAndCacheClasspath(JavaProject javaProject, final IClasspathEntry[] newRawClasspath, final IPath newOutputLocation) throws JavaModelException { return writeAndCacheClasspath(javaProject, newRawClasspath, null, newOutputLocation); } @@ -1595,12 +1600,12 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public static boolean CP_RESOLVE_VERBOSE_FAILURE = false; public static boolean ZIP_ACCESS_VERBOSE = false; public static boolean JRT_ACCESS_VERBOSE = false; - + /** * A cache of opened zip files per thread. * (for a given thread, the object value is a HashMap from IPath to java.io.ZipFile) */ - private ThreadLocal zipFiles = new ThreadLocal(); + private ThreadLocal<ZipCache> zipFiles = new ThreadLocal<>(); private UserLibraryManager userLibraryManager; @@ -1608,7 +1613,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis /* * A set of IPaths for jars that are known to not contain a chaining (through MANIFEST.MF) to another library */ - private Set nonChainingJars; + private Set<IPath> nonChainingJars; // The amount of time from when an invalid archive is first sensed until that state is considered stale. private static long INVALID_ARCHIVE_TTL_MILLISECONDS = 2 * 60 * 1000; @@ -1634,20 +1639,20 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * A map of IPaths for jars that are known to be invalid (such as not being in a valid/known format), to an eviction timestamp. * Synchronize on invalidArchivesMutex before accessing. */ - private final Map<IPath, InvalidArchiveInfo> invalidArchives = new HashMap<IPath, InvalidArchiveInfo>(); + private final Map<IPath, InvalidArchiveInfo> invalidArchives = new HashMap<>(); private final Object invalidArchivesMutex = new Object(); /* * A set of IPaths for files that are known to be external to the workspace. * Need not be referenced by the classpath. */ - private Set externalFiles; + private Set<IPath> externalFiles; /* * A set of IPaths for files that do not exist on the file system but are assumed to be * external archives (rather than external folders). */ - private Set assumedExternalFiles; + private Set<IPath> assumedExternalFiles; /** * Update the classpath variable cache @@ -1794,16 +1799,16 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis /** * @deprecated */ - private void addDeprecatedOptions(Hashtable options) { + private void addDeprecatedOptions(Hashtable<String, String> options) { options.put(JavaCore.COMPILER_PB_INVALID_IMPORT, JavaCore.ERROR); options.put(JavaCore.COMPILER_PB_UNREACHABLE_CODE, JavaCore.ERROR); } - + public void addNonChainingJar(IPath path) { if (this.nonChainingJars != null) this.nonChainingJars.add(path); } - + public void addInvalidArchive(IPath path, ArchiveValidity reason) { if (DEBUG_INVALID_ARCHIVES) { System.out.println("Invalid JAR cache: adding " + path + ", reason: " + reason); //$NON-NLS-1$//$NON-NLS-2$ @@ -1820,7 +1825,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public void addExternalFile(IPath path) { // unlikely to be null if (this.externalFiles == null) { - this.externalFiles = Collections.synchronizedSet(new HashSet()); + this.externalFiles = Collections.synchronizedSet(new HashSet<IPath>()); } if(this.externalFiles != null) { this.externalFiles.add(path); @@ -1832,7 +1837,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * Ignores if there are already clients. */ public void cacheZipFiles(Object owner) { - ZipCache zipCache = (ZipCache) this.zipFiles.get(); + ZipCache zipCache = this.zipFiles.get(); if (zipCache != null) { return; } @@ -1861,7 +1866,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public static void registerDebugOptionsListener(BundleContext context) { // register debug options listener - Hashtable<String, String> properties = new Hashtable<String, String>(2); + Hashtable<String, String> properties = new Hashtable<>(2); properties.put(DebugOptions.LISTENER_SYMBOLICNAME, JavaCore.PLUGIN_ID); DEBUG_REGISTRATION = context.registerService(DebugOptionsListener.class, new DebugOptionsListener() { @Override @@ -1906,7 +1911,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis Indexer.DEBUG_SELFTEST = debug && options.getBooleanOption(INDEX_INDEXER_SELFTEST, false); Indexer.DEBUG_LOG_SIZE_MB = debug ? options.getIntegerOption(INDEX_INDEXER_LOG_SIZE_MEGS, 0) : 0; Nd.sDEBUG_LOCKS = debug && options.getBooleanOption(INDEX_LOCKS_DEBUG, false); - + // configure performance options if(PerformanceStats.ENABLED) { CompletionEngine.PERF = PerformanceStats.isEnabled(COMPLETION_PERF); @@ -1998,10 +2003,10 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis PerWorkingCopyInfo info = null; synchronized(this.perWorkingCopyInfos) { WorkingCopyOwner owner = workingCopy.owner; - Map workingCopyToInfos = (Map)this.perWorkingCopyInfos.get(owner); + Map<CompilationUnit, PerWorkingCopyInfo> workingCopyToInfos = this.perWorkingCopyInfos.get(owner); if (workingCopyToInfos == null) return -1; - info = (PerWorkingCopyInfo)workingCopyToInfos.get(workingCopy); + info = workingCopyToInfos.get(workingCopy); if (info == null) return -1; if (--info.useCount == 0) { @@ -2041,7 +2046,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * Flushes ZipFiles cache if there are no more clients. */ public void flushZipFiles(Object owner) { - ZipCache zipCache = (ZipCache)this.zipFiles.get(); + ZipCache zipCache = this.zipFiles.get(); if (zipCache == null) { if (JavaModelManager.ZIP_ACCESS_VERBOSE) { System.out.println("(" + Thread.currentThread() + ") [JavaModelManager.flushZipFiles(String)] NOT found cache for " + owner); //$NON-NLS-1$ //$NON-NLS-2$ @@ -2119,16 +2124,16 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } public IClasspathEntry[] getReferencedClasspathEntries(IClasspathEntry libraryEntry, IJavaProject project) { - + IClasspathEntry[] referencedEntries = ((ClasspathEntry)libraryEntry).resolvedChainedLibraries(); - + if (project == null) return referencedEntries; - + PerProjectInfo perProjectInfo = getPerProjectInfo(project.getProject(), false); - if(perProjectInfo == null) + if(perProjectInfo == null) return referencedEntries; - + LinkedHashSet<IPath> pathToReferencedEntries = new LinkedHashSet<>(referencedEntries.length); for (int index = 0; index < referencedEntries.length; index++) { @@ -2136,7 +2141,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis continue; IClasspathEntry persistedEntry = null; - if ((persistedEntry = (IClasspathEntry)perProjectInfo.rootPathToResolvedEntries.get(referencedEntries[index].getPath())) != null) { + if ((persistedEntry = perProjectInfo.rootPathToResolvedEntries.get(referencedEntries[index].getPath())) != null) { // TODO: reconsider this - may want to copy the values instead of reference assignment? referencedEntries[index] = persistedEntry; } @@ -2144,7 +2149,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } return referencedEntries; } - + public DeltaProcessor getDeltaProcessor() { return this.deltaState.getDeltaProcessor(); } @@ -2189,19 +2194,19 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis return this.cache.getExistingElement(element); } - public HashSet getExternalWorkingCopyProjects() { + public HashSet<IJavaProject> getExternalWorkingCopyProjects() { synchronized (this.perWorkingCopyInfos) { - HashSet result = null; - Iterator values = this.perWorkingCopyInfos.values().iterator(); + HashSet<IJavaProject> result = null; + Iterator<Map<CompilationUnit, PerWorkingCopyInfo>> values = this.perWorkingCopyInfos.values().iterator(); while (values.hasNext()) { - Map ownerCopies = (Map) values.next(); - Iterator workingCopies = ownerCopies.keySet().iterator(); + Map<CompilationUnit, PerWorkingCopyInfo> ownerCopies = values.next(); + Iterator<CompilationUnit> workingCopies = ownerCopies.keySet().iterator(); while (workingCopies.hasNext()) { - ICompilationUnit workingCopy = (ICompilationUnit) workingCopies.next(); + ICompilationUnit workingCopy = workingCopies.next(); IJavaProject project = workingCopy.getJavaProject(); if (project.getElementName().equals(ExternalJavaProject.EXTERNAL_PROJECT_NAME)) { if (result == null) - result = new HashSet(); + result = new HashSet<>(); result.add(project); } } @@ -2218,18 +2223,18 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } // If modified, also modify the method getDefaultOptionsNoInitialization() - public Hashtable getDefaultOptions(){ + public Hashtable<String, String> getDefaultOptions(){ - Hashtable defaultOptions = new Hashtable(10); + Hashtable<String, String> defaultOptions = new Hashtable<>(10); // see JavaCorePreferenceInitializer#initializeDefaultPluginPreferences() for changing default settings // If modified, also modify the method getDefaultOptionsNoInitialization() IEclipsePreferences defaultPreferences = getDefaultPreferences(); // initialize preferences to their default - Iterator iterator = this.optionNames.iterator(); + Iterator<String> iterator = this.optionNames.iterator(); while (iterator.hasNext()) { - String propertyName = (String) iterator.next(); + String propertyName = iterator.next(); String value = defaultPreferences.get(propertyName, null); if (value != null) defaultOptions.put(propertyName, value); } @@ -2303,7 +2308,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis String value = service.get(optionName, null, this.preferencesLookup); if (value == null && optionLevel == DEPRECATED_OPTION) { // May be a deprecated option, retrieve the new value in compatible options - String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName); + String[] compatibleOptions = this.deprecatedOptions.get(optionName); value = service.get(compatibleOptions[0], null, this.preferencesLookup); } return value==null ? null : value.trim(); @@ -2336,7 +2341,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis return oldValue.trim(); } // Get the new compatible value - String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName); + String[] compatibleOptions = this.deprecatedOptions.get(optionName); String newDefault = inheritJavaCoreOptions ? JavaCore.getOption(compatibleOptions[0]) : null; String newValue = projectPreferences.get(compatibleOptions[0], newDefault); return newValue == null ? null : newValue.trim(); @@ -2346,7 +2351,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis /** * Returns whether an option name is known or not. - * + * * @param optionName The name of the option * @return <code>true</code> when the option name is either * {@link #VALID_OPTION valid} or {@link #DEPRECATED_OPTION deprecated}, @@ -2362,7 +2367,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis /** * Returns the level of the given option. - * + * * @param optionName The name of the option * @return The level of the option as an int which may have the following * values: @@ -2382,25 +2387,25 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis return UNKNOWN_OPTION; } - public Hashtable getOptions() { + public Hashtable<String, String> getOptions() { // return cached options if already computed - Hashtable cachedOptions; // use a local variable to avoid race condition (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=256329 ) + Hashtable<String, String> cachedOptions; // use a local variable to avoid race condition (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=256329 ) if ((cachedOptions = this.optionsCache) != null) { - return new Hashtable(cachedOptions); + return new Hashtable<>(cachedOptions); } if (!Platform.isRunning()) { this.optionsCache = getDefaultOptionsNoInitialization(); - return new Hashtable(this.optionsCache); + return new Hashtable<>(this.optionsCache); } // init - Hashtable options = new Hashtable(10); + Hashtable<String, String> options = new Hashtable<>(10); IPreferencesService service = Platform.getPreferencesService(); // set options using preferences service lookup - Iterator iterator = this.optionNames.iterator(); + Iterator<String> iterator = this.optionNames.iterator(); while (iterator.hasNext()) { - String propertyName = (String) iterator.next(); + String propertyName = iterator.next(); String propertyValue = service.get(propertyName, null, this.preferencesLookup); if (propertyValue != null) { options.put(propertyName, propertyValue); @@ -2408,14 +2413,14 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } // set deprecated options using preferences service lookup - Iterator deprecatedEntries = this.deprecatedOptions.entrySet().iterator(); + Iterator<Entry<String, String[]>> deprecatedEntries = this.deprecatedOptions.entrySet().iterator(); while (deprecatedEntries.hasNext()) { - Entry entry = (Entry) deprecatedEntries.next(); - String propertyName = (String) entry.getKey(); + Entry<String, String[]> entry = deprecatedEntries.next(); + String propertyName = entry.getKey(); String propertyValue = service.get(propertyName, null, this.preferencesLookup); if (propertyValue != null) { options.put(propertyName, propertyValue); - String[] compatibleOptions = (String[]) entry.getValue(); + String[] compatibleOptions = entry.getValue(); for (int co=0, length=compatibleOptions.length; co < length; co++) { String compatibleOption = compatibleOptions[co]; if (!options.containsKey(compatibleOption)) @@ -2432,13 +2437,13 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis Util.fixTaskTags(options); // store built map in cache - this.optionsCache = new Hashtable(options); + this.optionsCache = new Hashtable<>(options); // return built map return options; } // Do not modify without modifying getDefaultOptions() - private Hashtable getDefaultOptionsNoInitialization() { + private Hashtable<String, String> getDefaultOptionsNoInitialization() { Map<String, String> defaultOptionsMap = new CompilerOptions().getMap(); // compiler defaults // Override some compiler defaults @@ -2460,7 +2465,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis defaultOptionsMap.put(JavaCore.CORE_JAVA_BUILD_ORDER, JavaCore.IGNORE); defaultOptionsMap.put(JavaCore.CORE_INCOMPLETE_CLASSPATH, JavaCore.ERROR); defaultOptionsMap.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.ERROR); - defaultOptionsMap.put(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, JavaCore.IGNORE); + defaultOptionsMap.put(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, JavaCore.IGNORE); defaultOptionsMap.put(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.ERROR); defaultOptionsMap.put(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS, JavaCore.ENABLED); defaultOptionsMap.put(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, JavaCore.ENABLED); @@ -2491,7 +2496,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis // Time out for parameter names defaultOptionsMap.put(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, "50"); //$NON-NLS-1$ - return new Hashtable(defaultOptionsMap); + return new Hashtable<>(defaultOptionsMap); } /* @@ -2499,7 +2504,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis */ public PerProjectInfo getPerProjectInfo(IProject project, boolean create) { synchronized(this.perProjectInfos) { // use the perProjectInfo collection as its own lock - PerProjectInfo info= (PerProjectInfo) this.perProjectInfos.get(project); + PerProjectInfo info= this.perProjectInfos.get(project); if (info == null && create) { info= new PerProjectInfo(project); this.perProjectInfos.put(project, info); @@ -2533,13 +2538,13 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public PerWorkingCopyInfo getPerWorkingCopyInfo(CompilationUnit workingCopy,boolean create, boolean recordUsage, IProblemRequestor problemRequestor) { synchronized(this.perWorkingCopyInfos) { // use the perWorkingCopyInfo collection as its own lock WorkingCopyOwner owner = workingCopy.owner; - Map workingCopyToInfos = (Map)this.perWorkingCopyInfos.get(owner); + Map<CompilationUnit, PerWorkingCopyInfo> workingCopyToInfos = this.perWorkingCopyInfos.get(owner); if (workingCopyToInfos == null && create) { - workingCopyToInfos = new HashMap(); + workingCopyToInfos = new HashMap<>(); this.perWorkingCopyInfos.put(owner, workingCopyToInfos); } - PerWorkingCopyInfo info = workingCopyToInfos == null ? null : (PerWorkingCopyInfo) workingCopyToInfos.get(workingCopy); + PerWorkingCopyInfo info = workingCopyToInfos == null ? null : workingCopyToInfos.get(workingCopy); if (info == null && create) { info= new PerWorkingCopyInfo(workingCopy, problemRequestor); workingCopyToInfos.put(workingCopy, info); @@ -2555,9 +2560,9 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * As such it should not be stored into container caches. */ public IClasspathContainer getPreviousSessionContainer(IPath containerPath, IJavaProject project) { - Map previousContainerValues = (Map)this.previousSessionContainers.get(project); + Map<IPath, IClasspathContainer> previousContainerValues = this.previousSessionContainers.get(project); if (previousContainerValues != null){ - IClasspathContainer previousContainer = (IClasspathContainer)previousContainerValues.get(containerPath); + IClasspathContainer previousContainer = previousContainerValues.get(containerPath); if (previousContainer != null) { if (JavaModelManager.CP_RESOLVE_VERBOSE_ADVANCED) verbose_reentering_project_container_access(containerPath, project, previousContainer); @@ -2592,7 +2597,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * Returns a persisted container from previous session if any */ public IPath getPreviousSessionVariable(String variableName) { - IPath previousPath = (IPath)this.previousSessionVariables.get(variableName); + IPath previousPath = this.previousSessionVariables.get(variableName); if (previousPath != null){ if (CP_RESOLVE_VERBOSE_ADVANCED) verbose_reentering_variable_access(variableName, previousPath); @@ -2634,7 +2639,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis Plugin jdtCorePlugin = JavaCore.getPlugin(); if (jdtCorePlugin == null) return null; - ArrayList variableList = new ArrayList(5); + ArrayList<String> variableList = new ArrayList<>(5); IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(JavaCore.PLUGIN_ID, JavaModelManager.CPVARIABLE_INITIALIZER_EXTPOINT_ID); if (extension != null) { IExtension[] extensions = extension.getExtensions(); @@ -2659,7 +2664,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis Plugin jdtCorePlugin = JavaCore.getPlugin(); if (jdtCorePlugin == null) return null; - ArrayList containerIDList = new ArrayList(5); + ArrayList<String> containerIDList = new ArrayList<>(5); IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(JavaCore.PLUGIN_ID, JavaModelManager.CPCONTAINER_INITIALIZER_EXTPOINT_ID); if (extension != null) { IExtension[] extensions = extension.getExtensions(); @@ -2814,7 +2819,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis ICompilationUnit[] primaryWCs = addPrimary && owner != DefaultWorkingCopyOwner.PRIMARY ? getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, false) : null; - Map workingCopyToInfos = (Map)this.perWorkingCopyInfos.get(owner); + Map<CompilationUnit, PerWorkingCopyInfo> workingCopyToInfos = this.perWorkingCopyInfos.get(owner); if (workingCopyToInfos == null) return primaryWCs; int primaryLength = primaryWCs == null ? 0 : primaryWCs.length; int size = workingCopyToInfos.size(); // note size is > 0 otherwise pathToPerWorkingCopyInfos would be null @@ -2830,9 +2835,9 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis if (index != primaryLength) System.arraycopy(result, 0, result = new ICompilationUnit[index+size], 0, index); } - Iterator iterator = workingCopyToInfos.values().iterator(); + Iterator<PerWorkingCopyInfo> iterator = workingCopyToInfos.values().iterator(); while(iterator.hasNext()) { - result[index++] = ((JavaModelManager.PerWorkingCopyInfo)iterator.next()).getWorkingCopy(); + result[index++] = iterator.next().getWorkingCopy(); } return result; } @@ -2880,7 +2885,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis ZipFile file = getZipFile(path); closeZipFile(file); } - + /** * Returns the open ZipFile at the given path. If the ZipFile * does not yet exist, it is created, opened, and added to the cache @@ -2903,7 +2908,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * For use in the JDT unit tests only. Used for testing error handling. Causes an * {@link IOException} to be thrown in {@link #getZipFile} whenever it attempts to * read a zip file. - * + * * @noreference This field is not intended to be referenced by clients. */ public static boolean throwIoExceptionsInGetZipFile = false; @@ -2914,7 +2919,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } ZipCache zipCache; ZipFile zipFile; - if ((zipCache = (ZipCache)this.zipFiles.get()) != null + if ((zipCache = this.zipFiles.get()) != null && (zipFile = zipCache.getCache(path)) != null) { return zipFile; } @@ -2933,8 +2938,8 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } return zipFile; } catch (IOException e) { - ArchiveValidity reason; - + ArchiveValidity reason; + if (e instanceof ZipException) { reason = ArchiveValidity.BAD_FORMAT; } else if (e instanceof FileNotFoundException) { @@ -2997,13 +3002,13 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis verbose_batching_containers_initialization(javaProjectToInit, containerToInit); // collect all container paths - final HashMap allContainerPaths = new HashMap(); + final HashMap<IJavaProject, Set<IPath>> allContainerPaths = new HashMap<>(); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i = 0, length = projects.length; i < length; i++) { IProject project = projects[i]; if (!JavaProject.hasJavaNature(project)) continue; IJavaProject javaProject = new JavaProject(project, getJavaModel()); - HashSet paths = (HashSet) allContainerPaths.get(javaProject); + Set<IPath> paths = allContainerPaths.get(javaProject); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); for (int j = 0, length2 = rawClasspath.length; j < length2; j++) { IClasspathEntry entry = rawClasspath[j]; @@ -3011,7 +3016,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && containerGet(javaProject, path) == null) { if (paths == null) { - paths = new HashSet(); + paths = new HashSet<>(); allContainerPaths.put(javaProject, paths); } paths.add(path); @@ -3031,9 +3036,9 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } // TODO (frederic) remove following block when JDT/UI dummy project will be thrown away... if (javaProjectToInit != null) { - HashSet containerPaths = (HashSet) allContainerPaths.get(javaProjectToInit); + Set<IPath> containerPaths = allContainerPaths.get(javaProjectToInit); if (containerPaths == null) { - containerPaths = new HashSet(); + containerPaths = new HashSet<>(); allContainerPaths.put(javaProjectToInit, containerPaths); } containerPaths.add(containerToInit); @@ -3051,16 +3056,14 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public void run(IProgressMonitor monitor) throws CoreException { try { // Collect all containers - Set entrySet = allContainerPaths.entrySet(); + Set<Entry<IJavaProject, Set<IPath>>> entrySet = allContainerPaths.entrySet(); int length = entrySet.size(); if (monitor != null) monitor.beginTask("", length); //$NON-NLS-1$ - Map.Entry[] entries = new Map.Entry[length]; // clone as the following will have a side effect - entrySet.toArray(entries); - for (int i = 0; i < length; i++) { - Map.Entry entry = entries[i]; - IJavaProject javaProject = (IJavaProject) entry.getKey(); - HashSet pathSet = (HashSet) entry.getValue(); + Set<Entry<IJavaProject, Set<IPath>>> entries = new HashSet<>(entrySet); // clone as the following will have a side effect + for (Entry<IJavaProject, Set<IPath>> entry : entries) { + IJavaProject javaProject = entry.getKey(); + Set<IPath> pathSet = entry.getValue(); if (pathSet == null) continue; int length2 = pathSet.size(); IPath[] paths = new IPath[length2]; @@ -3076,20 +3079,20 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis if (monitor != null) monitor.worked(1); } - + // Set all containers - Map perProjectContainers = (Map) JavaModelManager.this.containersBeingInitialized.get(); + Map<IJavaProject, Map<IPath, IClasspathContainer>> perProjectContainers = JavaModelManager.this.containersBeingInitialized.get(); if (perProjectContainers != null) { - Iterator entriesIterator = perProjectContainers.entrySet().iterator(); + Iterator<Entry<IJavaProject, Map<IPath, IClasspathContainer>>> entriesIterator = perProjectContainers.entrySet().iterator(); while (entriesIterator.hasNext()) { - Map.Entry entry = (Map.Entry) entriesIterator.next(); - IJavaProject project = (IJavaProject) entry.getKey(); - HashMap perPathContainers = (HashMap) entry.getValue(); - Iterator containersIterator = perPathContainers.entrySet().iterator(); + Entry<IJavaProject, Map<IPath, IClasspathContainer>> entry = entriesIterator.next(); + IJavaProject project = entry.getKey(); + Map<IPath, IClasspathContainer> perPathContainers = entry.getValue(); + Iterator<Entry<IPath, IClasspathContainer>> containersIterator = perPathContainers.entrySet().iterator(); while (containersIterator.hasNext()) { - Map.Entry containerEntry = (Map.Entry) containersIterator.next(); - IPath containerPath = (IPath) containerEntry.getKey(); - IClasspathContainer container = (IClasspathContainer) containerEntry.getValue(); + Entry<IPath, IClasspathContainer> containerEntry = containersIterator.next(); + IPath containerPath = containerEntry.getKey(); + IClasspathContainer container = containerEntry.getValue(); SetContainerOperation operation = new SetContainerOperation(containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {container}); operation.runOperation(monitor); } @@ -3386,10 +3389,10 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis touchJob.schedule(); } - private HashSet getClasspathBeingResolved() { - HashSet result = (HashSet) this.classpathsBeingResolved.get(); + private Set<IJavaProject> getClasspathBeingResolved() { + Set<IJavaProject> result = this.classpathsBeingResolved.get(); if (result == null) { - result = new HashSet(); + result = new HashSet<>(); this.classpathsBeingResolved.set(result); } return result; @@ -3406,11 +3409,11 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis return JavaCore.COMPILER_PB_INVALID_IMPORT.equals(optionName) || JavaCore.COMPILER_PB_UNREACHABLE_CODE.equals(optionName); } - + public boolean isNonChainingJar(IPath path) { return this.nonChainingJars != null && this.nonChainingJars.contains(path); } - + public ArchiveValidity getArchiveValidity(IPath path) { InvalidArchiveInfo invalidArchiveInfo; synchronized (this.invalidArchivesMutex) { @@ -3508,9 +3511,9 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis getClasspathBeingResolved().remove(project); } } - - private Set loadClasspathListCache(String cacheName) { - Set pathCache = new HashSet(); + + private Set<IPath> loadClasspathListCache(String cacheName) { + Set<IPath> pathCache = new HashSet<>(); File cacheFile = getClasspathListFile(cacheName); DataInputStream in = null; try { @@ -3534,18 +3537,18 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } return Collections.synchronizedSet(pathCache); } - + private File getClasspathListFile(String fileName) { - return JavaCore.getPlugin().getStateLocation().append(fileName).toFile(); + return JavaCore.getPlugin().getStateLocation().append(fileName).toFile(); } - - private Set getNonChainingJarsCache() throws CoreException { - // Even if there is one entry in the cache, just return it. It may not be + + private Set<IPath> getNonChainingJarsCache() throws CoreException { + // Even if there is one entry in the cache, just return it. It may not be // the complete cache, but avoid going through all the projects to populate the cache. if (this.nonChainingJars != null && this.nonChainingJars.size() > 0) { return this.nonChainingJars; } - Set result = new HashSet(); + Set<IPath> result = new HashSet<>(); IJavaProject[] projects = getJavaModel().getJavaProjects(); for (int i = 0, length = projects.length; i < length; i++) { IJavaProject javaProject = projects[i]; @@ -3553,7 +3556,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis for (int j = 0, length2 = classpath.length; j < length2; j++) { IClasspathEntry entry = classpath[j]; IPath path; - if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY + if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && !result.contains(path = entry.getPath()) && ClasspathEntry.resolvedChainedLibraries(path).length == 0) { result.add(path); @@ -3563,9 +3566,9 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis this.nonChainingJars = Collections.synchronizedSet(result); return this.nonChainingJars; } - - private Set getClasspathListCache(String cacheName) throws CoreException { - if (cacheName == NON_CHAINING_JARS_CACHE) + + private Set<IPath> getClasspathListCache(String cacheName) throws CoreException { + if (cacheName == NON_CHAINING_JARS_CACHE) return getNonChainingJarsCache(); else if (cacheName == EXTERNAL_FILES_CACHE) return this.externalFiles; @@ -3574,7 +3577,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis else return null; } - + public void loadVariablesAndContainers() throws CoreException { // backward compatibility, consider persistent property QualifiedName qName = new QualifiedName(JavaCore.PLUGIN_ID, "variables"); //$NON-NLS-1$ @@ -3783,7 +3786,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis private IClasspathEntry[] allClasspathEntries; private int allClasspathEntryCount; - private final Map allPaths; // String -> IPath + private final Map<String, IPath> allPaths; private String[] allStrings; private int allStringsCount; @@ -3794,7 +3797,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis super(); this.allClasspathEntries = null; this.allClasspathEntryCount = 0; - this.allPaths = new HashMap(); + this.allPaths = new HashMap<>(); this.allStrings = null; this.allStringsCount = 0; this.in = in; @@ -3921,10 +3924,10 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis containerPut(project, path, container); - Map oldContainers = (Map) JavaModelManager.this.previousSessionContainers.get(project); + Map<IPath, IClasspathContainer> oldContainers = JavaModelManager.this.previousSessionContainers.get(project); if (oldContainers == null) { - oldContainers = new HashMap(); + oldContainers = new HashMap<>(); JavaModelManager.this.previousSessionContainers.put(project, oldContainers); } @@ -3941,7 +3944,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis return null; String portableString = loadString(); - IPath path = (IPath) this.allPaths.get(portableString); + IPath path = this.allPaths.get(portableString); if (path == null) { path = Path.fromPortableString(portableString); @@ -4000,7 +4003,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis private void loadVariables() throws IOException { int size = loadInt(); - Map loadedVars = new HashMap(size); + Map<String, IPath> loadedVars = new HashMap<>(size); for (int i = 0; i < size; ++i) { String varName = loadString(); @@ -4020,7 +4023,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * disturbing the cache ordering. */ protected synchronized Object peekAtInfo(IJavaElement element) { - HashMap tempCache = this.temporaryCache.get(); + HashMap<IJavaElement, Object> tempCache = this.temporaryCache.get(); if (tempCache != null) { Object result = tempCache.get(element); if (result != null) { @@ -4039,19 +4042,19 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } /* * Puts the infos in the given map (keys are IJavaElements and values are JavaElementInfos) - * in the Java model cache in an atomic way if the info is not already present in the cache. + * in the Java model cache in an atomic way if the info is not already present in the cache. * If the info is already present in the cache, it depends upon the forceAdd parameter. - * If forceAdd is false it just returns the existing info and if true, this element and it's children are closed and then + * If forceAdd is false it just returns the existing info and if true, this element and it's children are closed and then * this particular info is added to the cache. */ protected synchronized Object putInfos(IJavaElement openedElement, Object newInfo, boolean forceAdd, Map<IJavaElement, Object> newElements) { // remove existing children as the are replaced with the new children contained in newElements Object existingInfo = this.cache.peekAtInfo(openedElement); if (existingInfo != null && !forceAdd) { - // If forceAdd is false, then it could mean that the particular element - // wasn't in cache at that point of time, but would have got added through + // If forceAdd is false, then it could mean that the particular element + // wasn't in cache at that point of time, but would have got added through // another thread. In that case, removing the children could remove it's own - // children. So, we should not remove the children but return the already existing + // children. So, we should not remove the children but return the already existing // info. // https://bugs.eclipse.org/bugs/show_bug.cgi?id=372687 return existingInfo; @@ -4197,9 +4200,9 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis if (addToContainerValues) { getJavaModelManager().containerPut(project, containerPath, container); } - Map projectContainers = (Map)getJavaModelManager().previousSessionContainers.get(project); + Map<IPath, IClasspathContainer> projectContainers = getJavaModelManager().previousSessionContainers.get(project); if (projectContainers == null){ - projectContainers = new HashMap(1); + projectContainers = new HashMap<>(1); getJavaModelManager().previousSessionContainers.put(project, projectContainers); } projectContainers.put(containerPath, container); @@ -4255,7 +4258,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public void removePerProjectInfo(JavaProject javaProject, boolean removeExtJarInfo) { synchronized(this.perProjectInfos) { // use the perProjectInfo collection as its own lock IProject project = javaProject.getProject(); - PerProjectInfo info= (PerProjectInfo) this.perProjectInfos.get(project); + PerProjectInfo info= this.perProjectInfos.get(project); if (info != null) { this.perProjectInfos.remove(project); if (removeExtJarInfo) { @@ -4272,7 +4275,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public void resetProjectOptions(JavaProject javaProject) { synchronized(this.perProjectInfos) { // use the perProjectInfo collection as its own lock IProject project = javaProject.getProject(); - PerProjectInfo info= (PerProjectInfo) this.perProjectInfos.get(project); + PerProjectInfo info= this.perProjectInfos.get(project); if (info != null) { info.options = null; } @@ -4285,7 +4288,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public void resetProjectPreferences(JavaProject javaProject) { synchronized(this.perProjectInfos) { // use the perProjectInfo collection as its own lock IProject project = javaProject.getProject(); - PerProjectInfo info= (PerProjectInfo) this.perProjectInfos.get(project); + PerProjectInfo info= this.perProjectInfos.get(project); if (info != null) { info.preferences = null; } @@ -4304,9 +4307,9 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis protected synchronized void resetJarTypeCache() { this.cache.resetJarTypeCache(); } - + public void resetClasspathListCache() { - if (this.nonChainingJars != null) + if (this.nonChainingJars != null) this.nonChainingJars.clear(); if (DEBUG_INVALID_ARCHIVES) { synchronized(this.invalidArchivesMutex) { @@ -4401,12 +4404,12 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis DataOutputStream out = null; try { out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); - Set pathCache = getClasspathListCache(cacheName); + Set<IPath> pathCache = getClasspathListCache(cacheName); synchronized (pathCache) { out.writeInt(pathCache.size()); - Iterator entries = pathCache.iterator(); + Iterator<IPath> entries = pathCache.iterator(); while (entries.hasNext()) { - IPath path = (IPath) entries.next(); + IPath path = entries.next(); out.writeUTF(path.toPortableString()); } } @@ -4423,7 +4426,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } } } - + private void saveVariablesAndContainers(ISaveContext context) throws CoreException { File file = getVariableAndContainersFile(); DataOutputStream out = null; @@ -4461,17 +4464,17 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis void save(ISaveContext context) throws IOException, JavaModelException { saveProjects(getJavaModel().getJavaProjects()); // remove variables that should not be saved - HashMap varsToSave = null; - Iterator iterator = JavaModelManager.this.variables.entrySet().iterator(); + HashMap<String, IPath> varsToSave = null; + Iterator<Entry<String, IPath>> iterator = JavaModelManager.this.variables.entrySet().iterator(); IEclipsePreferences defaultPreferences = getDefaultPreferences(); while (iterator.hasNext()) { - Map.Entry entry = (Map.Entry) iterator.next(); - String varName = (String) entry.getKey(); + Entry<String, IPath> entry = iterator.next(); + String varName = entry.getKey(); if (defaultPreferences.get(CP_VARIABLE_PREFERENCES_PREFIX + varName, null) != null // don't save classpath variables from the default preferences as there is no delta if they are removed || CP_ENTRY_IGNORE_PATH.equals(entry.getValue())) { if (varsToSave == null) - varsToSave = new HashMap(JavaModelManager.this.variables); + varsToSave = new HashMap<>(JavaModelManager.this.variables); varsToSave.remove(varName); } } @@ -4533,14 +4536,14 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } } - private void saveContainers(IJavaProject project, Map containerMap) + private void saveContainers(IJavaProject project, Map<IPath, IClasspathContainer> containerMap) throws IOException { saveInt(containerMap.size()); - for (Iterator i = containerMap.entrySet().iterator(); i.hasNext();) { - Entry entry = (Entry) i.next(); - IPath path = (IPath) entry.getKey(); - IClasspathContainer container = (IClasspathContainer) entry.getValue(); + for (Iterator<Entry<IPath, IClasspathContainer>> i = containerMap.entrySet().iterator(); i.hasNext();) { + Entry<IPath, IClasspathContainer> entry = i.next(); + IPath path = entry.getKey(); + IClasspathContainer container = entry.getValue(); IClasspathEntry[] cpEntries = null; if (container == null) { @@ -4608,14 +4611,14 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis saveString(project.getElementName()); - Map containerMap = (Map) JavaModelManager.this.containers.get(project); + Map<IPath, IClasspathContainer> containerMap = JavaModelManager.this.containers.get(project); if (containerMap == null) { containerMap = Collections.EMPTY_MAP; } else { // clone while iterating // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59638) - containerMap = new HashMap(containerMap); + containerMap = new HashMap<>(containerMap); } saveContainers(project, containerMap); @@ -4627,13 +4630,13 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis this.out.writeUTF(string); } - private void saveVariables(Map map) throws IOException { + private void saveVariables(Map<String, IPath> map) throws IOException { saveInt(map.size()); - for (Iterator i = map.entrySet().iterator(); i.hasNext();) { - Entry entry = (Entry) i.next(); - String varName = (String) entry.getKey(); - IPath varPath = (IPath) entry.getValue(); + for (Iterator<Entry<String, IPath>> i = map.entrySet().iterator(); i.hasNext();) { + Entry<String, IPath> entry = i.next(); + String varName = entry.getKey(); + IPath varPath = entry.getValue(); saveString(varName); savePath(varPath); @@ -4663,7 +4666,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis // save variable and container values on snapshot/full save saveVariablesAndContainers(context); - + if (VERBOSE) traceVariableAndContainers("Saved", start); //$NON-NLS-1$ @@ -4673,10 +4676,10 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis saveClasspathListCache(NON_CHAINING_JARS_CACHE); saveClasspathListCache(EXTERNAL_FILES_CACHE); saveClasspathListCache(ASSUMED_EXTERNAL_FILES_CACHE); - + // will need delta since this save (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658) context.needDelta(); - + // clean up indexes on workspace full save // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=52347) IndexManager manager = this.indexManager; @@ -4702,19 +4705,19 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis return; } - ArrayList vStats= null; // lazy initialized - ArrayList values = null; + ArrayList<IStatus> vStats= null; // lazy initialized + ArrayList<PerProjectInfo> values = null; synchronized(this.perProjectInfos) { - values = new ArrayList(this.perProjectInfos.values()); + values = new ArrayList<>(this.perProjectInfos.values()); } - Iterator iterator = values.iterator(); + Iterator<PerProjectInfo> iterator = values.iterator(); while (iterator.hasNext()) { try { - PerProjectInfo info = (PerProjectInfo) iterator.next(); + PerProjectInfo info = iterator.next(); saveState(info, context); } catch (CoreException e) { if (vStats == null) - vStats= new ArrayList(); + vStats= new ArrayList<>(); vStats.add(e.getStatus()); } } @@ -4735,10 +4738,6 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * Current secondary types cache is not modified as we want to wait that indexing * was finished before taking new secondary types into account. * - * Indexing cache is a specific entry in secondary types cache which key is - * {@link #INDEXED_SECONDARY_TYPES } and value a map with same structure than - * secondary types cache itself. - * * @see #secondaryTypes(IJavaProject, boolean, IProgressMonitor) */ public void secondaryTypeAdding(String path, char[] typeName, char[] packageName) { @@ -4756,29 +4755,29 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } IWorkspaceRoot wRoot = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = wRoot.findMember(path); - if (resource != null) { - if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(path) && resource.getType() == IResource.FILE) { + if (resource instanceof IFile) { + if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(path)) { IProject project = resource.getProject(); try { PerProjectInfo projectInfo = getPerProjectInfoCheckExistence(project); // Get or create map to cache secondary types while indexing (can be not synchronized as indexing insure a non-concurrent usage) - HashMap indexedSecondaryTypes = null; + Map<IFile, Map<String, Map<String, IType>>> indexedSecondaryTypes; if (projectInfo.secondaryTypes == null) { - projectInfo.secondaryTypes = new Hashtable(3); - indexedSecondaryTypes = new HashMap(3); - projectInfo.secondaryTypes.put(INDEXED_SECONDARY_TYPES, indexedSecondaryTypes); + projectInfo.secondaryTypes = new Hashtable<>(3); + indexedSecondaryTypes = new HashMap<>(3); + projectInfo.indexingSecondaryCache = indexedSecondaryTypes; } else { - indexedSecondaryTypes = (HashMap) projectInfo.secondaryTypes.get(INDEXED_SECONDARY_TYPES); + indexedSecondaryTypes = projectInfo.indexingSecondaryCache; if (indexedSecondaryTypes == null) { - indexedSecondaryTypes = new HashMap(3); - projectInfo.secondaryTypes.put(INDEXED_SECONDARY_TYPES, indexedSecondaryTypes); + indexedSecondaryTypes = new HashMap<>(3); + projectInfo.indexingSecondaryCache = indexedSecondaryTypes; } } // Store the secondary type in temporary cache (these are just handles => no problem to create it now...) - HashMap allTypes = (HashMap) indexedSecondaryTypes.get(resource); + Map<String, Map<String, IType>> allTypes = indexedSecondaryTypes.get(resource); if (allTypes == null) { - allTypes = new HashMap(3); - indexedSecondaryTypes.put(resource, allTypes); + allTypes = new HashMap<>(3); + indexedSecondaryTypes.put((IFile) resource, allTypes); } ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom((IFile)resource, null); if (unit != null) { @@ -4788,19 +4787,19 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis // use package fragment name instead of parameter as it may be invalid... // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=186781 String packageString = type.getPackageFragment().getElementName(); - HashMap packageTypes = (HashMap) allTypes.get(packageString); + Map<String, IType> packageTypes = allTypes.get(packageString); if (packageTypes == null) { - packageTypes = new HashMap(3); + packageTypes = new HashMap<>(3); allTypes.put(packageString, packageTypes); } packageTypes.put(typeString, type); } if (VERBOSE) { Util.verbose(" - indexing cache:"); //$NON-NLS-1$ - Iterator entries = indexedSecondaryTypes.entrySet().iterator(); + Iterator<Entry<IFile, Map<String, Map<String, IType>>>> entries = indexedSecondaryTypes.entrySet().iterator(); while (entries.hasNext()) { - Map.Entry entry = (Map.Entry) entries.next(); - IFile file = (IFile) entry.getKey(); + Entry<IFile, Map<String, Map<String, IType>>> entry = entries.next(); + IFile file = entry.getKey(); Util.verbose(" + "+file.getFullPath()+':'+ entry.getValue()); //$NON-NLS-1$ } } @@ -4826,17 +4825,14 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * </ul> * Hashtable was used to protect callers from possible concurrent access. * </p> - * Note that this map may have a specific entry which key is {@link #INDEXED_SECONDARY_TYPES } - * and value is a map containing all secondary types created during indexing. - * When this key is in cache and indexing is finished, returned map is merged - * with the value of this special key. If indexing is not finished and caller does + * Note, if indexing is not finished and caller does * not wait for the end of indexing, returned map is the current secondary * types cache content which may be invalid... * * @param project Project we want get secondary types from * @return HashMap Table of secondary type names->path for given project */ - public Map secondaryTypes(IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor) throws JavaModelException { + public Map<String, Map<String, IType>> secondaryTypes(IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor) throws JavaModelException { if (VERBOSE) { StringBuffer buffer = new StringBuffer("JavaModelManager.secondaryTypes("); //$NON-NLS-1$ buffer.append(project.getElementName()); @@ -4848,7 +4844,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis // Return cache if not empty and there's no new secondary types created during indexing final PerProjectInfo projectInfo = getPerProjectInfoCheckExistence(project.getProject()); - Map indexingSecondaryCache = projectInfo.secondaryTypes == null ? null : (Map) projectInfo.secondaryTypes.get(INDEXED_SECONDARY_TYPES); + Map<IFile, Map<String, Map<String, IType>>> indexingSecondaryCache = projectInfo.secondaryTypes == null ? null : projectInfo.indexingSecondaryCache; if (projectInfo.secondaryTypes != null && indexingSecondaryCache == null) { return projectInfo.secondaryTypes; } @@ -4894,7 +4890,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public String getJobFamily() { return ""; //$NON-NLS-1$ } - + }, IJob.WaitUntilReady, monitor); } catch (OperationCanceledException oce) { return projectInfo.secondaryTypes; @@ -4902,55 +4898,57 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } // Indexing is finished => merge caches and return result - return secondaryTypesMerging(projectInfo.secondaryTypes); + return secondaryTypesMerging(projectInfo); } /* * Return secondary types cache merged with new secondary types created while indexing * Note that merge result is directly stored in given parameter map. */ - private Hashtable secondaryTypesMerging(Hashtable secondaryTypes) { + private Map<String, Map<String, IType>> secondaryTypesMerging(PerProjectInfo projectInfo) { + Map<String, Map<String, IType>> secondaryTypes = projectInfo.secondaryTypes; if (VERBOSE) { Util.verbose("JavaModelManager.getSecondaryTypesMerged()"); //$NON-NLS-1$ Util.verbose(" - current cache to merge:"); //$NON-NLS-1$ - Iterator entries = secondaryTypes.entrySet().iterator(); + Iterator<Entry<String, Map<String, IType>>> entries = secondaryTypes.entrySet().iterator(); while (entries.hasNext()) { - Map.Entry entry = (Map.Entry) entries.next(); - String packName = (String) entry.getKey(); + Entry<String, Map<String, IType>> entry = entries.next(); + String packName = entry.getKey(); Util.verbose(" + "+packName+':'+ entry.getValue() ); //$NON-NLS-1$ } } // Return current cache if there's no indexing cache (double check, this should not happen) - HashMap indexedSecondaryTypes = (HashMap) secondaryTypes.remove(INDEXED_SECONDARY_TYPES); + Map<IFile, Map<String, Map<String, IType>>> indexedSecondaryTypes = projectInfo.indexingSecondaryCache; + projectInfo.indexingSecondaryCache = null; if (indexedSecondaryTypes == null) { return secondaryTypes; } // Merge indexing cache in secondary types one - Iterator entries = indexedSecondaryTypes.entrySet().iterator(); + Iterator<Entry<IFile, Map<String, Map<String, IType>>>> entries = indexedSecondaryTypes.entrySet().iterator(); while (entries.hasNext()) { - Map.Entry entry = (Map.Entry) entries.next(); - IFile file = (IFile) entry.getKey(); + Entry<IFile, Map<String, Map<String, IType>>> entry = entries.next(); + IFile file = entry.getKey(); // Remove all secondary types of indexed file from cache secondaryTypesRemoving(secondaryTypes, file); // Add all indexing file secondary types in given secondary types cache - HashMap fileSecondaryTypes = (HashMap) entry.getValue(); - Iterator entries2 = fileSecondaryTypes.entrySet().iterator(); + Map<String, Map<String, IType>> fileSecondaryTypes = entry.getValue(); + Iterator<Entry<String, Map<String, IType>>> entries2 = fileSecondaryTypes.entrySet().iterator(); while (entries2.hasNext()) { - Map.Entry entry2 = (Map.Entry) entries2.next(); - String packageName = (String) entry2.getKey(); - HashMap cachedTypes = (HashMap) secondaryTypes.get(packageName); + Entry<String, Map<String, IType>> entry2 = entries2.next(); + String packageName = entry2.getKey(); + Map<String, IType> cachedTypes = secondaryTypes.get(packageName); if (cachedTypes == null) { secondaryTypes.put(packageName, entry2.getValue()); } else { - HashMap types = (HashMap) entry2.getValue(); - Iterator entries3 = types.entrySet().iterator(); + Map<String, IType> types = entry2.getValue(); + Iterator<Entry<String, IType>> entries3 = types.entrySet().iterator(); while (entries3.hasNext()) { - Map.Entry entry3 = (Map.Entry) entries3.next(); - String typeName = (String) entry3.getKey(); + Entry<String, IType> entry3 = entries3.next(); + String typeName = entry3.getKey(); cachedTypes.put(typeName, entry3.getValue()); } } @@ -4958,10 +4956,10 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } if (VERBOSE) { Util.verbose(" - secondary types cache merged:"); //$NON-NLS-1$ - entries = secondaryTypes.entrySet().iterator(); + Iterator<Entry<String, Map<String, IType>>> entries2 = secondaryTypes.entrySet().iterator(); while (entries.hasNext()) { - Map.Entry entry = (Map.Entry) entries.next(); - String packName = (String) entry.getKey(); + Entry<String, Map<String, IType>> entry = entries2.next(); + String packName = entry.getKey(); Util.verbose(" + "+packName+':'+ entry.getValue()); //$NON-NLS-1$ } } @@ -4972,7 +4970,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * Perform search request to get all secondary types of a given project. * If not waiting for indexes and indexing is running, will return types found in current built indexes... */ - private Map secondaryTypesSearching(IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor, final PerProjectInfo projectInfo) throws JavaModelException { + private static Map<String, Map<String, IType>> secondaryTypesSearching(IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor, final PerProjectInfo projectInfo) throws JavaModelException { if (VERBOSE || BasicSearchEngine.VERBOSE) { StringBuffer buffer = new StringBuffer("JavaModelManager.secondaryTypesSearch("); //$NON-NLS-1$ buffer.append(project.getElementName()); @@ -4982,15 +4980,15 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis Util.verbose(buffer.toString()); } - final Hashtable secondaryTypes = new Hashtable(3); + final Hashtable<String, Map<String, String>> secondaryTypesSearch = new Hashtable<>(3); IRestrictedAccessTypeRequestor nameRequestor = new IRestrictedAccessTypeRequestor() { @Override public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) { String key = packageName==null ? "" : new String(packageName); //$NON-NLS-1$ - HashMap types = (HashMap) secondaryTypes.get(key); - if (types == null) types = new HashMap(3); + Map<String, String> types = secondaryTypesSearch.get(key); + if (types == null) types = new HashMap<>(3); types.put(new String(simpleTypeName), path); - secondaryTypes.put(key, types); + secondaryTypesSearch.put(key, types); } }; @@ -5011,16 +5009,14 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis new BasicSearchEngine().searchAllSecondaryTypeNames(allSourceFolders, nameRequestor, waitForIndexes, monitor); // Build types from paths - Iterator packages = secondaryTypes.values().iterator(); - while (packages.hasNext()) { - HashMap types = (HashMap) packages.next(); - HashMap tempTypes = new HashMap(types.size()); - Iterator names = types.entrySet().iterator(); - while (names.hasNext()) { - Map.Entry entry = (Map.Entry) names.next(); - String typeName = (String) entry.getKey(); - String path = (String) entry.getValue(); - names.remove(); + final Hashtable<String, Map<String, IType>> secondaryTypes = new Hashtable<>(secondaryTypesSearch.size()); + for (Entry<String, Map<String, String>> packageEntry : secondaryTypesSearch.entrySet()) { + String packageName = packageEntry.getKey(); + Map<String, String> types = packageEntry.getValue(); + Map<String, IType> tempTypes = new HashMap<>(types.size()); + for (Entry<String, String> entry : types.entrySet()) { + String typeName = entry.getKey(); + String path = entry.getValue(); if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(path)) { IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)); ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, null); @@ -5028,19 +5024,19 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis tempTypes.put(typeName, type); } } - types.putAll(tempTypes); + secondaryTypes.put(packageName, tempTypes); } // Store result in per project info cache if still null or there's still an indexing cache (may have been set by another thread...) - if (projectInfo.secondaryTypes == null || projectInfo.secondaryTypes.get(INDEXED_SECONDARY_TYPES) != null) { + if (projectInfo.secondaryTypes == null || projectInfo.indexingSecondaryCache != null) { projectInfo.secondaryTypes = secondaryTypes; if (VERBOSE || BasicSearchEngine.VERBOSE) { System.out.print(Thread.currentThread() + " -> secondary paths stored in cache: "); //$NON-NLS-1$ System.out.println(); - Iterator entries = secondaryTypes.entrySet().iterator(); + Iterator<Entry<String, Map<String, IType>>> entries = secondaryTypes.entrySet().iterator(); while (entries.hasNext()) { - Map.Entry entry = (Map.Entry) entries.next(); - String qualifiedName = (String) entry.getKey(); + Entry<String, Map<String, IType>> entry = entries.next(); + String qualifiedName = entry.getKey(); Util.verbose(" - "+qualifiedName+'-'+ entry.getValue()); //$NON-NLS-1$ } } @@ -5074,22 +5070,22 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis secondaryTypesRemoving(projectInfo.secondaryTypes, file); // Clean indexing cache if necessary - HashMap indexingCache = (HashMap) projectInfo.secondaryTypes.get(INDEXED_SECONDARY_TYPES); + Map<IFile, Map<String, Map<String, IType>>> indexingCache = projectInfo.indexingSecondaryCache; if (!cleanIndexCache) { if (indexingCache == null) { // Need to signify that secondary types indexing will happen before any request happens // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=152841 - projectInfo.secondaryTypes.put(INDEXED_SECONDARY_TYPES, new HashMap()); + projectInfo.indexingSecondaryCache = new HashMap<>(); } return; } if (indexingCache != null) { - Set keys = indexingCache.keySet(); + Set<IFile> keys = indexingCache.keySet(); int filesSize = keys.size(), filesCount = 0; IFile[] removed = null; - Iterator cachedFiles = keys.iterator(); + Iterator<IFile> cachedFiles = keys.iterator(); while (cachedFiles.hasNext()) { - IFile cachedFile = (IFile) cachedFiles.next(); + IFile cachedFile = cachedFiles.next(); if (file.equals(cachedFile)) { if (removed == null) removed = new IFile[filesSize]; filesSize--; @@ -5110,13 +5106,13 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * Remove from a given cache map all secondary types belonging to a given file. * Note that there can have several secondary types per file... */ - private void secondaryTypesRemoving(Hashtable secondaryTypesMap, IFile file) { + private void secondaryTypesRemoving(Map<String, Map<String, IType>> secondaryTypesMap, IFile file) { if (VERBOSE) { StringBuffer buffer = new StringBuffer("JavaModelManager.removeSecondaryTypesFromMap("); //$NON-NLS-1$ - Iterator entries = secondaryTypesMap.entrySet().iterator(); + Iterator<Entry<String, Map<String, IType>>> entries = secondaryTypesMap.entrySet().iterator(); while (entries.hasNext()) { - Map.Entry entry = (Map.Entry) entries.next(); - String qualifiedName = (String) entry.getKey(); + Entry<String, Map<String, IType>> entry = entries.next(); + String qualifiedName = entry.getKey(); buffer.append(qualifiedName+':'+ entry.getValue()); } buffer.append(','); @@ -5124,40 +5120,38 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis buffer.append(')'); Util.verbose(buffer.toString()); } - Set packageEntries = secondaryTypesMap.entrySet(); + Set<Entry<String, Map<String, IType>>> packageEntries = secondaryTypesMap.entrySet(); int packagesSize = packageEntries.size(), removedPackagesCount = 0; String[] removedPackages = null; - Iterator packages = packageEntries.iterator(); + Iterator<Entry<String, Map<String, IType>>> packages = packageEntries.iterator(); while (packages.hasNext()) { - Map.Entry entry = (Map.Entry) packages.next(); - String packName = (String) entry.getKey(); - if (packName != INDEXED_SECONDARY_TYPES) { // skip indexing cache entry if present (!= is intentional) - HashMap types = (HashMap) entry.getValue(); - Set nameEntries = types.entrySet(); - int namesSize = nameEntries.size(), removedNamesCount = 0; - String[] removedNames = null; - Iterator names = nameEntries.iterator(); - while (names.hasNext()) { - Map.Entry entry2 = (Map.Entry) names.next(); - String typeName = (String) entry2.getKey(); - JavaElement type = (JavaElement) entry2.getValue(); - if (file.equals(type.resource())) { - if (removedNames == null) removedNames = new String[namesSize]; - namesSize--; - removedNames[removedNamesCount++] = typeName; - } - } - if (removedNames != null) { - for (int i=0; i<removedNamesCount; i++) { - types.remove(removedNames[i]); - } + Entry<String, Map<String, IType>> entry = packages.next(); + String packName = entry.getKey(); + Map<String, IType> types = entry.getValue(); + Set<Entry<String, IType>> nameEntries = types.entrySet(); + int namesSize = nameEntries.size(), removedNamesCount = 0; + String[] removedNames = null; + Iterator<Entry<String, IType>> names = nameEntries.iterator(); + while (names.hasNext()) { + Entry<String, IType> entry2 = names.next(); + String typeName = entry2.getKey(); + JavaElement type = (JavaElement) entry2.getValue(); + if (file.equals(type.resource())) { + if (removedNames == null) removedNames = new String[namesSize]; + namesSize--; + removedNames[removedNamesCount++] = typeName; } - if (types.size() == 0) { - if (removedPackages == null) removedPackages = new String[packagesSize]; - packagesSize--; - removedPackages[removedPackagesCount++] = packName; + } + if (removedNames != null) { + for (int i=0; i<removedNamesCount; i++) { + types.remove(removedNames[i]); } } + if (types.size() == 0) { + if (removedPackages == null) removedPackages = new String[packagesSize]; + packagesSize--; + removedPackages[removedPackagesCount++] = packName; + } } if (removedPackages != null) { for (int i=0; i<removedPackagesCount; i++) { @@ -5166,10 +5160,10 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } if (VERBOSE) { Util.verbose(" - new secondary types map:"); //$NON-NLS-1$ - Iterator entries = secondaryTypesMap.entrySet().iterator(); + Iterator<Entry<String, Map<String, IType>>> entries = secondaryTypesMap.entrySet().iterator(); while (entries.hasNext()) { - Map.Entry entry = (Map.Entry) entries.next(); - String qualifiedName = (String) entry.getKey(); + Entry<String, Map<String, IType>> entry = entries.next(); + String qualifiedName = entry.getKey(); Util.verbose(" + "+qualifiedName+':'+ entry.getValue()); //$NON-NLS-1$ } } @@ -5197,7 +5191,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } else { // remove projects which are already mentionned in java builder order int javaCount = javaBuildOrder.length; - HashMap newSet = new HashMap(javaCount); // create a set for fast check + HashMap<String, String> newSet = new HashMap<>(javaCount); // create a set for fast check for (int i = 0; i < javaCount; i++){ newSet.put(javaBuildOrder[i], javaBuildOrder[i]); } @@ -5262,10 +5256,10 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis * @return <code>true</code> if the preferences have been changed, * <code>false</code> otherwise. */ - public boolean storePreference(String optionName, String optionValue, IEclipsePreferences eclipsePreferences, Map otherOptions) { + public boolean storePreference(String optionName, String optionValue, IEclipsePreferences eclipsePreferences, Map<String, String> otherOptions) { int optionLevel = this.getOptionLevel(optionName); if (optionLevel == UNKNOWN_OPTION) return false; // unrecognized option - + // Store option value switch (optionLevel) { case JavaModelManager.VALID_OPTION: @@ -5278,7 +5272,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis case JavaModelManager.DEPRECATED_OPTION: // Try to migrate deprecated option eclipsePreferences.remove(optionName); // get rid off old preference - String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName); + String[] compatibleOptions = this.deprecatedOptions.get(optionName); for (int co=0, length=compatibleOptions.length; co < length; co++) { if (otherOptions != null && otherOptions.containsKey(compatibleOptions[co])) continue; // don't overwrite explicit value of otherOptions at compatibleOptions[co] @@ -5295,8 +5289,8 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis return true; } - public void setOptions(Hashtable newOptions) { - Hashtable cachedValue = newOptions == null ? null : new Hashtable(newOptions); + public void setOptions(Hashtable<String, String> newOptions) { + Hashtable<String, String> cachedValue = newOptions == null ? null : new Hashtable<>(newOptions); IEclipsePreferences defaultPreferences = getDefaultPreferences(); IEclipsePreferences instancePreferences = getInstancePreferences(); @@ -5307,9 +5301,9 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis // ignore } } else { - Enumeration keys = newOptions.keys(); + Enumeration<String> keys = newOptions.keys(); while (keys.hasMoreElements()){ - String key = (String)keys.nextElement(); + String key = keys.nextElement(); int optionLevel = getOptionLevel(key); if (optionLevel == UNKNOWN_OPTION) continue; // unrecognized option if (key.equals(JavaCore.CORE_ENCODING)) { @@ -5318,7 +5312,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } continue; // skipped, contributed by resource prefs } - String value = (String) newOptions.get(key); + String value = newOptions.get(key); String defaultValue = defaultPreferences.get(key, null); // Store value in preferences if (defaultValue != null && defaultValue.equals(value)) { @@ -5357,7 +5351,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis } }; InstanceScope.INSTANCE.getNode(JavaCore.PLUGIN_ID).addPreferenceChangeListener(this.propertyListener); - + // listen for encoding changes (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=255501 ) this.resourcesPropertyListener = new IEclipsePreferences.IPreferenceChangeListener() { @Override @@ -5395,7 +5389,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis | IResourceChangeEvent.PRE_REFRESH); Indexer.getInstance().addListener(this.deltaState); - + // listen to resource changes affecting external annotations ExternalAnnotationTracker.start(workspace); @@ -5496,15 +5490,15 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public synchronized IPath variableGet(String variableName){ // check initialization in progress first - HashSet initializations = variableInitializationInProgress(); + Set<String> initializations = variableInitializationInProgress(); if (initializations.contains(variableName)) { return VARIABLE_INITIALIZATION_IN_PROGRESS; } - return (IPath)this.variables.get(variableName); + return this.variables.get(variableName); } private synchronized IPath variableGetDefaultToPreviousSession(String variableName){ - IPath variablePath = (IPath)this.variables.get(variableName); + IPath variablePath = this.variables.get(variableName); if (variablePath == null) return getPreviousSessionVariable(variableName); return variablePath; @@ -5513,10 +5507,10 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis /* * Returns the set of variable names that are being initialized in the current thread. */ - private HashSet variableInitializationInProgress() { - HashSet initializations = (HashSet)this.variableInitializationInProgress.get(); + private Set<String> variableInitializationInProgress() { + Set<String> initializations = this.variableInitializationInProgress.get(); if (initializations == null) { - initializations = new HashSet(); + initializations = new HashSet<>(); this.variableInitializationInProgress.set(initializations); } return initializations; @@ -5525,10 +5519,10 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public synchronized String[] variableNames(){ int length = this.variables.size(); String[] result = new String[length]; - Iterator vars = this.variables.keySet().iterator(); + Iterator<String> vars = this.variables.keySet().iterator(); int index = 0; while (vars.hasNext()) { - result[index++] = (String) vars.next(); + result[index++] = vars.next(); } return result; } @@ -5536,7 +5530,7 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public synchronized void variablePut(String variableName, IPath variablePath){ // set/unset the initialization in progress - HashSet initializations = variableInitializationInProgress(); + Set<String> initializations = variableInitializationInProgress(); if (variablePath == VARIABLE_INITIALIZATION_IN_PROGRESS) { initializations.add(variableName); @@ -5615,11 +5609,11 @@ public class JavaModelManager implements ISaveParticipant, IContentTypeChangeLis public synchronized String cacheToString(String prefix) { return this.cache.toStringFillingRation(prefix); } - - public Stats debugNewOpenableCacheStats() { + + public ElementCache<ITypeRoot>.Stats debugNewOpenableCacheStats() { return this.cache.openableCache.new Stats(); } - + public int getOpenableCacheSize() { return this.cache.openableCache.getSpaceLimit(); } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java index 869c672811..2025d30eb8 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java @@ -670,11 +670,11 @@ public class NameLookup implements SuffixConstants { JavaModelManager manager = JavaModelManager.getJavaModelManager(); try { IJavaProject javaProject = project; - Map secondaryTypePaths = manager.secondaryTypes(javaProject, waitForIndexes, monitor); + Map<String, Map<String, IType>> secondaryTypePaths = manager.secondaryTypes(javaProject, waitForIndexes, monitor); if (secondaryTypePaths.size() > 0) { - Map types = (Map) secondaryTypePaths.get(packageName==null?"":packageName); //$NON-NLS-1$ + Map<String, IType> types = secondaryTypePaths.get(packageName==null?"":packageName); //$NON-NLS-1$ if (types != null && types.size() > 0) { - IType type = (IType) types.get(typeName); + IType type = types.get(typeName); if (type != null) { if (JavaModelManager.VERBOSE) { Util.verbose("NameLookup FIND SECONDARY TYPES:"); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java index dd4b7295c1..6db062c721 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java @@ -31,7 +31,6 @@ import org.eclipse.jdt.internal.core.builder.ClasspathLocation; import org.eclipse.jdt.internal.core.util.ResourceCompilationUnit; import org.eclipse.jdt.internal.core.util.Util; -@SuppressWarnings("rawtypes") public class ClasspathSourceDirectory extends ClasspathLocation implements IModulePathEntry { IContainer sourceFolder; @@ -77,13 +76,13 @@ SimpleLookupTable directoryTable(String qualifiedPackageName) { } // look for secondary types, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=382778 IJavaProject project = JavaCore.create(container.getProject()); - Map secondaryTypePaths = JavaModelManager.getJavaModelManager().secondaryTypes(project, false, null); + Map<String, Map<String, IType>> secondaryTypePaths = JavaModelManager.getJavaModelManager().secondaryTypes(project, false, null); if (secondaryTypePaths.size() > 0) { - Map typesInPackage = (Map) secondaryTypePaths.get(qualifiedPackageName.replace('/', '.')); + Map<String, IType> typesInPackage = secondaryTypePaths.get(qualifiedPackageName.replace('/', '.')); if (typesInPackage != null && typesInPackage.size() > 0) { - for (Iterator j = typesInPackage.keySet().iterator(); j.hasNext();) { - String secondaryTypeName = (String) j.next(); - IType secondaryType = (IType) typesInPackage.get(secondaryTypeName); + for (Iterator<String> j = typesInPackage.keySet().iterator(); j.hasNext();) { + String secondaryTypeName = j.next(); + IType secondaryType = typesInPackage.get(secondaryTypeName); IJavaElement parent = secondaryType.getParent(); String fullPath = parent.getResource().getFullPath().toString(); if (!org.eclipse.jdt.internal.compiler.util.Util.isExcluded(fullPath.toCharArray(), this.fulInclusionPatternChars, this.fullExclusionPatternChars, false/*not a folder path*/)) { @@ -120,7 +119,7 @@ public NameEnvironmentAnswer findClass(String sourceFileWithoutExtension, String if (dirTable != null && dirTable.elementSize > 0) { IFile file = (IFile) dirTable.get(sourceFileWithoutExtension); if (file != null) { - return new NameEnvironmentAnswer(new ResourceCompilationUnit(file, + return new NameEnvironmentAnswer(new ResourceCompilationUnit(file, this.module == null ? null : this.module.name()), null /* no access restriction */); } } |