Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2013 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation Theodora Yeung (tyeung@bea.com) - ensure that JarPackageFragmentRoot make it into cache before its contents (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=102422) Stephan Herrmann - Contribution for Bug 346010 - [model] strange initialization dependency in OptionTests Terry Parker <tparker@google.com> - DeltaProcessor misses state changes in archive files, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=357425 /
  
  package org.eclipse.jdt.internal.core;
  
  import java.io.*;
  import java.net.URI;
  import java.util.*;
  
  
  import  org.eclipse.core.resources.*;
  import  org.eclipse.core.runtime.*;
  import  org.eclipse.core.runtime.content.IContentTypeManager.ContentTypeChangeEvent;
  import  org.eclipse.core.runtime.content.IContentTypeManager.IContentTypeChangeListener;
  import  org.eclipse.core.runtime.jobs.Job;
  import  org.eclipse.core.runtime.preferences.DefaultScope;
  import  org.eclipse.core.runtime.preferences.IEclipsePreferences;
  import  org.eclipse.core.runtime.preferences.IPreferencesService;
  import  org.eclipse.core.runtime.preferences.InstanceScope;
  import  org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
  import  org.osgi.service.prefs.BackingStoreException;
  import org.w3c.dom.Node;
The JavaModelManager manages instances of IJavaModel. IElementChangedListeners register with the JavaModelManager, and receive ElementChangedEvents for all IJavaModels.

The single instance of JavaModelManager is available from the static method JavaModelManager.getJavaModelManager().

  
  public class JavaModelManager implements ISaveParticipant, IContentTypeChangeListener {
  
  	private static final String NON_CHAINING_JARS_CACHE = "nonChainingJarsCache"//$NON-NLS-1$
  	private static final String INVALID_ARCHIVES_CACHE = "invalidArchivesCache";  //$NON-NLS-1$
  
Define a zip cache object.
  
  	static class ZipCache {
  		private Map map;
  
  		ZipCache(Object owner) {
 			this. = new HashMap();
 			this. = owner;
 		}
 
 		public void flush() {
 			Thread currentThread = Thread.currentThread();
 			Iterator iterator = this..values().iterator();
 			while (iterator.hasNext()) {
 				try {
 					ZipFile zipFile = (ZipFile)iterator.next();
 						..println("(" + currentThread + ") [JavaModelManager.flushZipFiles()] Closing ZipFile on " +zipFile.getName()); //$NON-NLS-1$//$NON-NLS-2$
 					}
 					zipFile.close();
 				} catch (IOException e) {
 					// problem occured closing zip file: cannot do much more
 				}
 			}
 		}
 
 		public ZipFile getCache(IPath path) {
 			return (ZipFilethis..get(path);
 		}
 
 		public void setCache(IPath pathZipFile zipFile) {
 			this..put(pathzipFile);
 		}
 	}
Unique handle onto the JavaModel
 
 	final JavaModel javaModel = new JavaModel();

Classpath variables pool
 
 	public HashMap variables = new HashMap(5);
 	public HashMap deprecatedVariables = new HashMap(5);
 	public HashSet readOnlyVariables = new HashSet(5);
Classpath containers pool
 
 	public HashMap containers = new HashMap(5);
 	
 	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;
 	public static final int BATCH_INITIALIZATION_FINISHED = 3;
 
 
 	/*
 	 * A HashSet that contains the IJavaProject whose classpath is being resolved.
 	 */
 
 	/*
 	 * The unique workspace scope
 	 */
 
 	/*
 	 * Pools of symbols used in the Java model.
 	 * Used as a replacement for String#intern() that could prevent garbage collection of strings on some VMs.
 	 */
 	private WeakHashSet stringSymbols = new WeakHashSet(5);
 
 	/*
 	 * Extension used to construct Java 6 annotation processor managers
 	 */
 	private IConfigurationElement annotationProcessorManagerFactory = null;
 
 	/*
 	 * 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 final static String CP_VARIABLE_PREFERENCES_PREFIX = .+".classpathVariable."//$NON-NLS-1$
 	public final static String CP_CONTAINER_PREFERENCES_PREFIX = .+".classpathContainer."//$NON-NLS-1$
 	public final static String CP_USERLIBRARY_PREFERENCES_PREFIX = .+".userLibrary."//$NON-NLS-1$
 	public final static String CP_ENTRY_IGNORE = "##<cp entry ignore>##"//$NON-NLS-1$
 	public final static IPath CP_ENTRY_IGNORE_PATH = new Path();
 	public final static String TRUE = "true"//$NON-NLS-1$
 
 	private final static int VARIABLES_AND_CONTAINERS_FILE_VERSION = 2;

Name of the extension point for contributing classpath variable initializers
 
 	public static final String CPVARIABLE_INITIALIZER_EXTPOINT_ID = "classpathVariableInitializer" ; //$NON-NLS-1$
 
Name of the extension point for contributing classpath container initializers
 
 	public static final String CPCONTAINER_INITIALIZER_EXTPOINT_ID = "classpathContainerInitializer" ; //$NON-NLS-1$
 
Name of the extension point for contributing a source code formatter
 
 	public static final String FORMATTER_EXTPOINT_ID = "codeFormatter" ; //$NON-NLS-1$
 
Name of the extension point for contributing a compilation participant
 
 	public static final String COMPILATION_PARTICIPANT_EXTPOINT_ID = "compilationParticipant" ; //$NON-NLS-1$
 
Name of the extension point for contributing the Java 6 annotation processor manager
 
 	public static final String ANNOTATION_PROCESSOR_MANAGER_EXTPOINT_ID = "annotationProcessorManager" ;  //$NON-NLS-1$
 
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 AbstractImageBuilder#MAX_AT_ONCE.
 
 	public static final String MAX_COMPILED_UNITS_AT_ONCE = "maxCompiledUnitsAtOnce"//$NON-NLS-1$
 
Special value used for recognizing ongoing initialization and breaking initialization cycles
 
 	public final static IPath VARIABLE_INITIALIZATION_IN_PROGRESS = new Path("Variable Initialization In Progress"); //$NON-NLS-1$
 		public IClasspathEntry[] getClasspathEntries() { return null; }
 		public String getDescription() { return "Container Initialization In Progress"; } //$NON-NLS-1$
 		public int getKind() { return 0; }
 		public IPath getPath() { return null; }
 		public String toString() { return getDescription(); }
 	};
 
 	private static final String BUFFER_MANAGER_DEBUG = . + "/debug/buffermanager" ; //$NON-NLS-1$
 	private static final String INDEX_MANAGER_DEBUG = . + "/debug/indexmanager" ; //$NON-NLS-1$
 	private static final String INDEX_MANAGER_ADVANCED_DEBUG = . + "/debug/indexmanager/advanced" ; //$NON-NLS-1$
 	private static final String COMPILER_DEBUG = . + "/debug/compiler" ; //$NON-NLS-1$
 	private static final String JAVAMODEL_DEBUG = . + "/debug/javamodel" ; //$NON-NLS-1$
 	private static final String JAVAMODELCACHE_DEBUG = . + "/debug/javamodel/cache" ; //$NON-NLS-1$
 	private static final String CP_RESOLVE_DEBUG = . + "/debug/cpresolution" ; //$NON-NLS-1$
 	private static final String CP_RESOLVE_ADVANCED_DEBUG = . + "/debug/cpresolution/advanced" ; //$NON-NLS-1$
 	private static final String CP_RESOLVE_FAILURE_DEBUG = . + "/debug/cpresolution/failure" ; //$NON-NLS-1$
 	private static final String ZIP_ACCESS_DEBUG = . + "/debug/zipaccess" ; //$NON-NLS-1$
 	private static final String DELTA_DEBUG =. + "/debug/javadelta" ; //$NON-NLS-1$
 	private static final String DELTA_DEBUG_VERBOSE =. + "/debug/javadelta/verbose" ; //$NON-NLS-1$
 	private static final String DOM_AST_DEBUG = . + "/debug/dom/ast" ; //$NON-NLS-1$
 	private static final String DOM_AST_DEBUG_THROW = . + "/debug/dom/ast/throw" ; //$NON-NLS-1$
 	private static final String DOM_REWRITE_DEBUG = . + "/debug/dom/rewrite" ; //$NON-NLS-1$
 	private static final String HIERARCHY_DEBUG = . + "/debug/hierarchy" ; //$NON-NLS-1$
 	private static final String POST_ACTION_DEBUG = . + "/debug/postaction" ; //$NON-NLS-1$
 	private static final String BUILDER_DEBUG = . + "/debug/builder" ; //$NON-NLS-1$
 	private static final String BUILDER_STATS_DEBUG = . + "/debug/builder/stats" ; //$NON-NLS-1$
 	private static final String COMPLETION_DEBUG = . + "/debug/completion" ; //$NON-NLS-1$
 	private static final String RESOLUTION_DEBUG = . + "/debug/resolution" ; //$NON-NLS-1$
 	private static final String SELECTION_DEBUG = . + "/debug/selection" ; //$NON-NLS-1$
 	private static final String SEARCH_DEBUG = . + "/debug/search" ; //$NON-NLS-1$
 	private static final String SOURCE_MAPPER_DEBUG_VERBOSE = . + "/debug/sourcemapper" ; //$NON-NLS-1$
 	private static final String FORMATTER_DEBUG = . + "/debug/formatter" ; //$NON-NLS-1$
 
 	public static final String COMPLETION_PERF = . + "/perf/completion" ; //$NON-NLS-1$
 	public static final String SELECTION_PERF = . + "/perf/selection" ; //$NON-NLS-1$
 	public static final String DELTA_LISTENER_PERF = . + "/perf/javadeltalistener" ; //$NON-NLS-1$
 	public static final String VARIABLE_INITIALIZER_PERF = . + "/perf/variableinitializer" ; //$NON-NLS-1$
 	public static final String CONTAINER_INITIALIZER_PERF = . + "/perf/containerinitializer" ; //$NON-NLS-1$
 	public static final String RECONCILE_PERF = . + "/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.
 
 	public final static ICompilationUnit[] NO_WORKING_COPY = new ICompilationUnit[0];
 
 	// Options
 	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);
 
 	// Preferences
 	public final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2];
 	static final int PREF_INSTANCE = 0;
 	static final int PREF_DEFAULT = 1;
 
 	static final Object[][] NO_PARTICIPANTS = new Object[0][];
 
 	public static class CompilationParticipants {
 
 		private final static int MAX_SOURCE_LEVEL = 7; // 1.1 to 1.7
 
 		/*
 		 * The registered compilation participants (a table from int (source level) to Object[])
 		 * The Object array contains first IConfigurationElements when not resolved yet, then
 		 * it contains CompilationParticipants.
 		 */
 		private Object[][] registeredParticipants = null;
 
 			final Object[][] participantsPerSource = getRegisteredParticipants();
 			if (participantsPerSource == )
 				return null;
 			String sourceLevel = project.getOption(.true/*inherit options*/);
 			final int sourceLevelIndex = indexForSourceLevel(sourceLevel);
 			final Object[] participants = participantsPerSource[sourceLevelIndex];
 			int length = participants.length;
 			CompilationParticipant[] result = new CompilationParticipant[length];
 			int index = 0;
 			for (int i = 0; i < lengthi++) {
 				if (participants[iinstanceof IConfigurationElement) {
 					final IConfigurationElement configElement = (IConfigurationElement) participants[i];
 					final int participantIndex = i;
 					SafeRunner.run(new ISafeRunnable() {
 						public void handleException(Throwable exception) {
 							Util.log(exception"Exception occurred while creating compilation participant"); //$NON-NLS-1$
 						}
 						public void run() throws Exception {
 							Object executableExtension = configElement.createExecutableExtension("class"); //$NON-NLS-1$
 							for (int j = sourceLevelIndexj < j++)
 								participantsPerSource[j][participantIndex] = executableExtension;
 						}
 					});
 				}
 				CompilationParticipant participant;
 				if ((participants[iinstanceof CompilationParticipant) && (participant = (CompilationParticipantparticipants[i]).isActive(project))
 					result[index++] = participant;
 			}
 			if (index == 0)
 				return null;
 			if (index < length)
 				System.arraycopy(result, 0, result = new CompilationParticipant[index], 0, index);
 			return result;
 		}
 
 			if (this. == null) {
 				// force extension points to be read
 			}
 			return this.;
 		}
 
 		private synchronized Object[][] getRegisteredParticipants() {
 			if (this. != null) {
 				return this.;
 			}
 			this. = new HashSet();
 			IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(.);
 			if (extension == null)
 			final ArrayList modifyingEnv = new ArrayList();
 			final ArrayList creatingProblems = new ArrayList();
 			final ArrayList others = new ArrayList();
 			IExtension[] extensions = extension.getExtensions();
 			// for all extensions of this point...
 			for(int i = 0; i < extensions.length; i++) {
 				IConfigurationElement[] configElements = extensions[i].getConfigurationElements();
 				// for all config elements named "compilationParticipant"
 				for(int j = 0; j < configElements.length; j++) {
 					final IConfigurationElement configElement = configElements[j];
 					String elementName =configElement.getName();
 					if (!("compilationParticipant".equals(elementName))) { //$NON-NLS-1$
 						continue;
 					}
 					// add config element in the group it belongs to
 					if (.equals(configElement.getAttribute("modifiesEnvironment"))) //$NON-NLS-1$
 						modifyingEnv.add(configElement);
 					else if (.equals(configElement.getAttribute("createsProblems"))) //$NON-NLS-1$
 						creatingProblems.add(configElement);
 					else
 						others.add(configElement);
 					// add managed marker types
 					IConfigurationElement[] managedMarkers = configElement.getChildren("managedMarker"); //$NON-NLS-1$
 					for (int k = 0, length = managedMarkers.length; k < lengthk++) {
 						IConfigurationElement element = managedMarkers[k];
 						String markerType = element.getAttribute("markerType"); //$NON-NLS-1$
 						if (markerType != null)
 							this..add(markerType);
 					}
 				}
 			}
 			int size = modifyingEnv.size() + creatingProblems.size() + others.size();
 			if (size == 0)
 
 			// sort config elements in each group
 			IConfigurationElement[] configElements = new IConfigurationElement[size];
 			int index = 0;
 			index = sortParticipants(modifyingEnvconfigElementsindex);
 			index = sortParticipants(creatingProblemsconfigElementsindex);
 			index = sortParticipants(othersconfigElementsindex);
 
 			// create result table
 			Object[][] result = new Object[][];
 			int length = configElements.length;
 			for (int i = 0; i < i++) {
 				result[i] = new Object[length];
 			}
 			for (int i = 0; i < lengthi++) {
 				String sourceLevel = configElements[i].getAttribute("requiredSourceLevel"); //$NON-NLS-1$
 				int sourceLevelIndex = indexForSourceLevel(sourceLevel);
 				for (int j = sourceLevelIndexj < j++) {
 					result[j][i] = configElements[i];
 				}
 			}
 			return this. = result;
 		}
 
 		/*
 		 * 1.1 -> 0
 		 * 1.2 -> 1
 		 * ...
 		 * 1.6 -> 5
 		 * 1.7 -> 6
 		 * null -> 0
 		 */
 		private int indexForSourceLevel(String sourceLevel) {
 			if (sourceLevel == nullreturn 0;
 			int majVersion = (int) (CompilerOptions.versionToJdkLevel(sourceLevel) >>> 16);
 			switch (majVersion) {
 					return 1;
 					return 2;
 					return 3;
 					return 4;
 					return 5;
 					return 6;
 				default:
 					// all other cases including ClassFileConstants.MAJOR_VERSION_1_1
 					return 0;
 			}
 		}
 
 		private int sortParticipants(ArrayList group, IConfigurationElement[] configElementsint index) {
 			int size = group.size();
 			if (size == 0) return index;
 			Object[] elements = group.toArray();
 			Util.sort(elementsnew Util.Comparer() {
 				public int compare(Object aObject b) {
 					if (a == breturn 0;
 					String id = ((IConfigurationElement) a).getAttribute("id"); //$NON-NLS-1$
 					if (id == nullreturn -1;
 					IConfigurationElement[] requiredElements = ((IConfigurationElement) b).getChildren("requires"); //$NON-NLS-1$
 					for (int i = 0, length = requiredElements.length; i < lengthi++) {
 						IConfigurationElement required = requiredElements[i];
 						if (id.equals(required.getAttribute("id"))) //$NON-NLS-1$
 							return 1;
 					}
 					return -1;
 				}
 			});
 			for (int i = 0; i < sizei++)
 				configElements[index+i] = (IConfigurationElement) elements[i];
 			return index + size;
 		}
 	}
 
 
 	/* whether an AbortCompilationUnit should be thrown when the source of a compilation unit cannot be retrieved */
 
Returns whether the given full path (for a package) conflicts with the output location of the given project.
 
 	public static boolean conflictsWithOutputLocation(IPath folderPathJavaProject project) {
 		try {
 			IPath outputLocation = project.getOutputLocation();
 			if (outputLocation == null) {
 				// in doubt, there is a conflict
 				return true;
 			}
 			if (outputLocation.isPrefixOf(folderPath)) {
 				// only allow nesting in project's output if there is a corresponding source folder
 				// or if the project's output is not used (in other words, if all source folders have their custom output)
 				IClasspathEntry[] classpath = project.getResolvedClasspath();
 				boolean isOutputUsed = false;
 				for (int i = 0, length = classpath.lengthi < lengthi++) {
 					IClasspathEntry entry = classpath[i];
 					if (entry.getEntryKind() == .) {
 						if (entry.getPath().equals(outputLocation)) {
 							return false;
 						}
 						if (entry.getOutputLocation() == null) {
 							isOutputUsed = true;
 						}
 					}
 				}
 				return isOutputUsed;
 			}
 			return false;
 		} catch (JavaModelException e) {
 			// in doubt, there is a conflict
 			return true;
 		}
 	}
 
 	public synchronized IClasspathContainer containerGet(IJavaProject project, IPath containerPath) {
 		// check initialization in progress first
 		if (containerIsInitializationInProgress(projectcontainerPath)) {
 		}
 
 		Map projectContainers = (Map)this..get(project);
 		if (projectContainers == null){
 			return null;
 		}
 		IClasspathContainer container = (IClasspathContainer)projectContainers.get(containerPath);
 		return container;
 	}
 
 	public synchronized IClasspathContainer containerGetDefaultToPreviousSession(IJavaProject project, IPath containerPath) {
 		Map projectContainers = (Map)this..get(project);
 		if (projectContainers == null)
 			return getPreviousSessionContainer(containerPathproject);
 		IClasspathContainer container = (IClasspathContainer)projectContainers.get(containerPath);
 		if (container == null)
 			return getPreviousSessionContainer(containerPathproject);
 		return container;
 	}
 
 	private boolean containerIsInitializationInProgress(IJavaProject project, IPath containerPath) {
 		Map initializations = (Map)this..get();
 		if (initializations == null)
 			return false;
 		HashSet projectInitializations = (HashSetinitializations.get(project);
 		if (projectInitializations == null)
 			return false;
 		return projectInitializations.contains(containerPath);
 	}
 
 	private void containerAddInitializationInProgress(IJavaProject project, IPath containerPath) {
 		Map initializations = (Map)this..get();
 		if (initializations == null)
 			this..set(initializations = new HashMap());
 		HashSet projectInitializations = (HashSetinitializations.get(project);
 		if (projectInitializations == null)
 			initializations.put(projectprojectInitializations = new HashSet());
 		projectInitializations.add(containerPath);
 	}
 	
 	public void containerBeingInitializedPut(IJavaProject project, IPath containerPathIClasspathContainer container) {
 		Map perProjectContainers = (Map)this..get();
 		if (perProjectContainers == null)
 			this..set(perProjectContainers = new HashMap());
 		HashMap perPathContainers = (HashMapperProjectContainers.get(project);
 		if (perPathContainers == null)
 			perProjectContainers.put(projectperPathContainers = new HashMap());
 		perPathContainers.put(containerPathcontainer);
 	}
 
 	public IClasspathContainer containerBeingInitializedGet(IJavaProject project, IPath containerPath) {
 		Map perProjectContainers = (Map)this..get();
 		if (perProjectContainers == null)
 			return null;
 		HashMap perPathContainers = (HashMapperProjectContainers.get(project);
 		if (perPathContainers == null)
 			return null;
 		return (IClasspathContainerperPathContainers.get(containerPath);
 	}
 
 	public IClasspathContainer containerBeingInitializedRemove(IJavaProject project, IPath containerPath) {
 		Map perProjectContainers = (Map)this..get();
 		if (perProjectContainers == null)
 			return null;
 		HashMap perPathContainers = (HashMapperProjectContainers.get(project);
 		if (perPathContainers == null)
 			return null;
 		IClasspathContainer container = (IClasspathContainerperPathContainers.remove(containerPath);
 		if (perPathContainers.size() == 0)
 			perPathContainers.remove(project);
 		if (perProjectContainers.size() == 0)
 		return container;
 	}
 
 	public synchronized void containerPut(IJavaProject project, IPath containerPathIClasspathContainer container){
 
 		// set/unset the initialization in progress
 		if (container == ) {
 			containerAddInitializationInProgress(projectcontainerPath);
 
 			// do not write out intermediate initialization value
 			return;
 		} else {
 			containerRemoveInitializationInProgress(projectcontainerPath);
 
 			Map projectContainers = (Map)this..get(project);
  			if (projectContainers == null){
 				projectContainers = new HashMap(1);
 				this..put(projectprojectContainers);
 			}
 
 			if (container == null) {
 				projectContainers.remove(containerPath);
 			} else {
   				projectContainers.put(containerPathcontainer);
 			}
 			// discard obsoleted information about previous session
 			Map previousContainers = (Map)this..get(project);
 			if (previousContainers != null){
 				previousContainers.remove(containerPath);
 			}
 		}
 		// container values are persisted in preferences during save operations, see #saving(ISaveContext)
 	}
 
 	/*
 	 * The given project is being removed. Remove all containers for this project from the cache.
 	 */
 	public synchronized void containerRemove(IJavaProject project) {
 		Map initializations = (Mapthis..get();
 		if (initializations != null) {
 			initializations.remove(project);
 		}
 		this..remove(project);
 	}
 
 	public boolean containerPutIfInitializingWithSameEntries(IPath containerPathIJavaProject[] projectsIClasspathContainer[] respectiveContainers) {
 		int projectLength = projects.length;
 		if (projectLength != 1)
 			return false;
 		final IClasspathContainer container = respectiveContainers[0];
 		IJavaProject project = projects[0];
 		// optimize only if initializing, otherwise we are in a regular setContainer(...) call
 		if (!containerIsInitializationInProgress(projectcontainerPath))
 			return false;
 		IClasspathContainer previousContainer = containerGetDefaultToPreviousSession(projectcontainerPath);
 		if (container == null) {
 			if (previousContainer == null) {
 				containerPut(projectcontainerPathnull);
 				return true;
 			}
 			return false;
 		}
 		final IClasspathEntry[] newEntries = container.getClasspathEntries();
 		if (previousContainer == null)
 			if (newEntries.length == 0) {
 				containerPut(projectcontainerPathcontainer);
 				return true;
 			} else {
 					verbose_missbehaving_container(containerPathprojectsrespectiveContainerscontainernewEntriesnull/*no old entries*/);
 				return false;
 			}
 		final IClasspathEntry[] oldEntries = previousContainer.getClasspathEntries();
 		if (oldEntries.length != newEntries.length) {
 				verbose_missbehaving_container(containerPathprojectsrespectiveContainerscontainernewEntriesoldEntries);
 			return false;
 		}
 		for (int i = 0, length = newEntries.lengthi < lengthi++) {
 			if (newEntries[i] == null) {
 					verbose_missbehaving_container(projectcontainerPathnewEntries);
 				return false;
 			}
 			if (!newEntries[i].equals(oldEntries[i])) {
 					verbose_missbehaving_container(containerPathprojectsrespectiveContainerscontainernewEntriesoldEntries);
 				return false;
 			}
 		}
 		containerPut(projectcontainerPathcontainer);
 		return true;
 	}
 
 			IPath containerPath,
 			IJavaProject[] projects,
 			IClasspathContainer[] respectiveContainers,
 			final IClasspathContainer container,
 			final IClasspathEntry[] newEntries,
 			final IClasspathEntry[] oldEntries) {
 		Util.verbose(
 			"CPContainer SET  - missbehaving container\n" + //$NON-NLS-1$
 			"	container path: " + containerPath + '\n' + //$NON-NLS-1$
 			"	projects: {" +//$NON-NLS-1$
 			org.eclipse.jdt.internal.compiler.util.Util.toString(
 				projects,
 					public String displayString(Object o) { return ((IJavaProjecto).getElementName(); }
 				}) +
 			"}\n	values on previous session: {\n"  +//$NON-NLS-1$
 			org.eclipse.jdt.internal.compiler.util.Util.toString(
 				respectiveContainers,
 					public String displayString(Object o) {
 						StringBuffer buffer = new StringBuffer("		"); //$NON-NLS-1$
 						if (o == null) {
 							buffer.append("<null>"); //$NON-NLS-1$
 							return buffer.toString();
 						}
 						buffer.append(container.getDescription());
 						buffer.append(" {\n"); //$NON-NLS-1$
 						if (oldEntries == null) {
 							buffer.append(" 			"); //$NON-NLS-1$
 							buffer.append("<null>\n"); //$NON-NLS-1$
 						} else {
 							for (int j = 0; j < oldEntries.lengthj++){
 								buffer.append(" 			"); //$NON-NLS-1$
 								buffer.append(oldEntries[j]);
 								buffer.append('\n');
 							}
 						}
 						buffer.append(" 		}"); //$NON-NLS-1$
 						return buffer.toString();
 					}
 				}) +
 			"}\n	new values: {\n"  +//$NON-NLS-1$
 			org.eclipse.jdt.internal.compiler.util.Util.toString(
 				respectiveContainers,
 					public String displayString(Object o) {
 						StringBuffer buffer = new StringBuffer("		"); //$NON-NLS-1$
 						if (o == null) {
 							buffer.append("<null>"); //$NON-NLS-1$
 							return buffer.toString();
 						}
 						buffer.append(container.getDescription());
 						buffer.append(" {\n"); //$NON-NLS-1$
 						for (int j = 0; j < newEntries.lengthj++){
 							buffer.append(" 			"); //$NON-NLS-1$
 							buffer.append(newEntries[j]);
 							buffer.append('\n');
 						}
 						buffer.append(" 		}"); //$NON-NLS-1$
 						return buffer.toString();
 					}
 				}) +
 			"\n	}"); //$NON-NLS-1$
 	}
 
 	void verbose_missbehaving_container(IJavaProject project, IPath containerPathIClasspathEntry[] classpathEntries) {
 		Util.verbose(
 			"CPContainer GET - missbehaving container (returning null classpath entry)\n" + //$NON-NLS-1$
 			"	project: " + project.getElementName() + '\n' + //$NON-NLS-1$
 			"	container path: " + containerPath + '\n' + //$NON-NLS-1$
 			"	classpath entries: {\n" + //$NON-NLS-1$
 			org.eclipse.jdt.internal.compiler.util.Util.toString(
 				classpathEntries,
 					public String displayString(Object o) {
 						StringBuffer buffer = new StringBuffer("		"); //$NON-NLS-1$
 						if (o == null) {
 							buffer.append("<null>"); //$NON-NLS-1$
 							return buffer.toString();
 						}
 						buffer.append(o);
 						return buffer.toString();
 					}
 				}) +
 			"\n	}" //$NON-NLS-1$
 		);
 	}
 
 	void verbose_missbehaving_container_null_entries(IJavaProject project, IPath containerPath) {
 		Util.verbose(
 			"CPContainer GET - missbehaving container (returning null as classpath entries)\n" + //$NON-NLS-1$
 			"	project: " + project.getElementName() + '\n' + //$NON-NLS-1$
 			"	container path: " + containerPath + '\n' + //$NON-NLS-1$
 			"	classpath entries: <null>" //$NON-NLS-1$
 		);
 	}
 
 	private void containerRemoveInitializationInProgress(IJavaProject project, IPath containerPath) {
 		Map initializations = (Map)this..get();
 		if (initializations == null)
 			return;
 		HashSet projectInitializations = (HashSetinitializations.get(project);
 		if (projectInitializations == null)
 			return;
 		projectInitializations.remove(containerPath);
 		if (projectInitializations.size() == 0)
 			initializations.remove(project);
 		if (initializations.size() == 0)
 	}
 
 	private synchronized void containersReset(String[] containerIDs) {
 		for (int i = 0; i < containerIDs.lengthi++) {
 			String containerID = containerIDs[i];
 			Iterator projectIterator = this..values().iterator();
 			while (projectIterator.hasNext()){
 				Map projectContainers = (MapprojectIterator.next();
 				if (projectContainers != null){
 					Iterator containerIterator = projectContainers.keySet().iterator();
 					while (containerIterator.hasNext()){
 						IPath containerPath = (IPath)containerIterator.next();
 						if (containerID.equals(containerPath.segment(0))) { // registered container
 							projectContainers.put(containerPathnull); // reset container value, but leave entry in Map
 						}
 					}
 				}
 			}
 		}
 	}

Returns the Java element corresponding to the given resource, or null if unable to associate the given resource with a Java element.

The resource must be one of:

  • a project - the element returned is the corresponding IJavaProject
  • a .java file - the element returned is the corresponding ICompilationUnit
  • a .class file - the element returned is the corresponding IClassFile
  • a ZIP archive (e.g. a .jar, a .zip file, etc.) - the element returned is the corresponding IPackageFragmentRoot
  • a folder - the element returned is the corresponding IPackageFragmentRoot or IPackageFragment
  • the workspace root resource - the element returned is the IJavaModel

Creating a Java element has the side effect of creating and opening all of the element's parents if they are not yet open.

 
 	public static IJavaElement create(IResource resourceIJavaProject project) {
 		if (resource == null) {
 			return null;
 		}
 		int type = resource.getType();
 		switch (type) {
 			case IResource.PROJECT :
 				return JavaCore.create((IProject) resource);
 			case IResource.FILE :
 				return create((IFile) resourceproject);
 			case IResource.FOLDER :
 				return create((IFolder) resourceproject);
 			case IResource.ROOT :
 				return JavaCore.create((IWorkspaceRoot) resource);
 			default :
 				return null;
 		}
 	}

Returns the Java element corresponding to the given file, its project being the given project. Returns null if unable to associate the given file with a Java element.

The file must be one of:

  • a .java file - the element returned is the corresponding ICompilationUnit
  • a .class file - the element returned is the corresponding IClassFile
  • a ZIP archive (e.g. a .jar, a .zip file, etc.) - the element returned is the corresponding IPackageFragmentRoot

Creating a Java element has the side effect of creating and opening all of the element's parents if they are not yet open.

 
 	public static IJavaElement create(IFile fileIJavaProject project) {
 		if (file == null) {
 			return null;
 		}
 		if (project == null) {
 			project = JavaCore.create(file.getProject());
 		}
 
 		if (file.getFileExtension() != null) {
 			String name = file.getName();
 			if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(name))
 				return createCompilationUnitFrom(fileproject);
 			if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(name))
 				return createClassFileFrom(fileproject);
 			return createJarPackageFragmentRootFrom(fileproject);
 		}
 		return null;
 	}

Returns the package fragment or package fragment root corresponding to the given folder, its parent or great parent being the given project. or null if unable to associate the given folder with a Java element.

Note that a package fragment root is returned rather than a default package.

Creating a Java element has the side effect of creating and opening all of the element's parents if they are not yet open.

 
 	public static IJavaElement create(IFolder folderIJavaProject project) {
 		if (folder == null) {
 			return null;
 		}
 		IJavaElement element;
 		if (project == null) {
 			project = JavaCore.create(folder.getProject());
 			element = determineIfOnClasspath(folderproject);
 			if (element == null) {
 				// walk all projects and find one that have the given folder on its classpath
 				IJavaProject[] projects;
 				try {
 					projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
 				} catch (JavaModelException e) {
 					return null;
 				}
 				for (int i = 0, length = projects.lengthi < lengthi++) {
 					project = projects[i];
 					element = determineIfOnClasspath(folderproject);
 					if (element != null)
 						break;
 				}
 			}
 		} else {
 			element = determineIfOnClasspath(folderproject);
 		}
 		return element;
 	}

Creates and returns a class file element for the given .class file, its project being the given project. Returns null if unable to recognize the class file.
 
 	public static IClassFile createClassFileFrom(IFile fileIJavaProject project ) {
 		if (file == null) {
 			return null;
 		}
 		if (project == null) {
 			project = JavaCore.create(file.getProject());
 		}
 		if (pkg == null) {
 			// fix for 1FVS7WE
 			// not on classpath - make the root its folder, and a default package
 			PackageFragmentRoot root = (PackageFragmentRootproject.getPackageFragmentRoot(file.getParent());
 		}
 		return pkg.getClassFile(file.getName());
 	}

Creates and returns a compilation unit element for the given .java file, its project being the given project. Returns null if unable to recognize the compilation unit.
 
 	public static ICompilationUnit createCompilationUnitFrom(IFile fileIJavaProject project) {
 
 		if (file == nullreturn null;
 
 		if (project == null) {
 			project = JavaCore.create(file.getProject());
 		}
 		if (pkg == null) {
 			// not on classpath - make the root its folder, and a default package
 			PackageFragmentRoot root = (PackageFragmentRootproject.getPackageFragmentRoot(file.getParent());
 
 			if (){
 				..println("WARNING : creating unit element outside classpath ("+ Thread.currentThread()+"): " + file.getFullPath()); //$NON-NLS-1$//$NON-NLS-2$
 			}
 		}
 		return pkg.getCompilationUnit(file.getName());
 	}

Creates and returns a handle for the given JAR file, its project being the given project. The Java model associated with the JAR's project may be created as a side effect. Returns null if unable to create a JAR package fragment root. (for example, if the JAR file represents a non-Java resource)
 
 	public static IPackageFragmentRoot createJarPackageFragmentRootFrom(IFile fileIJavaProject project) {
 		if (file == null) {
 			return null;
 		}
 		if (project == null) {
 			project = JavaCore.create(file.getProject());
 		}
 
 		// Create a jar package fragment root only if on the classpath
 		IPath resourcePath = file.getFullPath();
 		try {
 			IClasspathEntry entry = ((JavaProject)project).getClasspathEntryFor(resourcePath);
 			if (entry != null) {
 				return project.getPackageFragmentRoot(file);
 			}
catch (JavaModelException e) {
			// project doesn't exist: return null
		return null;
	}

Returns the package fragment root represented by the resource, or the package fragment the given resource is located in, or null if the given resource is not on the classpath of the given project.
	public static IJavaElement determineIfOnClasspath(IResource resourceIJavaProject project) {
		IPath resourcePath = resource.getFullPath();
		boolean isExternal = ExternalFoldersManager.isInternalPathForExternalFolder(resourcePath);
		if (isExternal)
			resourcePath = resource.getLocation();
		try {
			ProjectCache projectCache = projectInfo == null ? null : projectInfo.projectCache;
			HashtableOfArrayToObject allPkgFragmentsCache = projectCache == null ? null : projectCache.allPkgFragmentsCache;
			boolean isJavaLike = org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourcePath.lastSegment());
			IClasspathEntry[] entries = isJavaLike ? project.getRawClasspath() // JAVA file can only live inside SRC folder (on the raw path)
			int lengthentries.length;
			if (length > 0) {
				String sourceLevel = project.getOption(.true);
				String complianceLevel = project.getOption(.true);
				for (int i = 0; i < lengthi++) {
					IClasspathEntry entry = entries[i];
					if (entry.getEntryKind() == .continue;
					IPath rootPath = entry.getPath();
					if (rootPath.equals(resourcePath)) {
						if (isJavaLike
							return null;
						return project.getPackageFragmentRoot(resource);
else if (rootPath.isPrefixOf(resourcePath)) {
						// allow creation of package fragment if it contains a .java file that is included
							// given we have a resource child of the root, it cannot be a JAR pkg root
								isExternal ?
									new ExternalPackageFragmentRoot(rootPath, (JavaProjectproject) :
							if (root == nullreturn null;
							IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount());
							if (resource.getType() == IResource.FILE) {
								// if the resource is a file, then remove the last segment which
								// is the file name in the package
								pkgPath = pkgPath.removeLastSegments(1);
							String[] pkgName = pkgPath.segments();
							// if package name is in the cache, then it has already been validated
							// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=133141)
							if (allPkgFragmentsCache != null && allPkgFragmentsCache.containsKey(pkgName))
								return root.getPackageFragment(pkgName);
							if (pkgName.length != 0 && JavaConventions.validatePackageName(Util.packageName(pkgPathsourceLevelcomplianceLevel), sourceLevelcomplianceLevel).getSeverity() == IStatus.ERROR) {
								return null;
							return root.getPackageFragment(pkgName);
catch (JavaModelException npe) {
			return null;
		return null;
	}

The singleton manager
	private static JavaModelManager MANAGERnew JavaModelManager();

Infos cache.
	/*
	 * Temporary cache of newly opened elements
	 */
Set of elements which are out of sync with their buffers.
Holds the state used for delta processing.
	public IndexManager indexManager = null;

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);

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);

A weak set of the known search scopes.
	protected WeakHashMap searchScopes = new WeakHashMap();
	public static class PerProjectInfo {
		private static final int JAVADOC_CACHE_INITIAL_SIZE = 10;
		public IProject project;
		public boolean triedRead;
		public int rawTimeStamp = 0;
		public boolean writtingRawClasspath = false;
		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 IPath outputLocation;
		public IEclipsePreferences preferences;
		public PerProjectInfo(IProject project) {
			this. = false;
			this. = null;
			this. = project;
		public synchronized IClasspathEntry[] getResolvedClasspath() {
				return null;
			return this.;
			IClasspathEntry[] classpath = this.;
			if (classpath == nullreturn;
			JavaModelManager manager = JavaModelManager.getJavaModelManager();
			IndexManager indexManager = manager.indexManager;
			Map externalTimeStamps = manager.deltaState.getExternalLibTimeStamps();
			HashMap rootInfos = JavaModelManager.getDeltaState().;
			for (int i = 0, length = classpath.lengthi < lengthi++) {
				IClasspathEntry entry = classpath[i];
					IPath path = entry.getPath();
					if (rootInfos.get(path) == null) {
						externalTimeStamps.remove(