<s> package org . eclipse . jdt . internal . core ; import java . io . * ; import java . net . URI ; import java . text . MessageFormat ; import java . util . * ; import java . util . Map . Entry ; import java . util . zip . ZipException ; import java . util . zip . ZipFile ; import javax . xml . parsers . DocumentBuilder ; import javax . xml . parsers . DocumentBuilderFactory ; import javax . xml . parsers . ParserConfigurationException ; import org . codehaus . jdt . groovy . integration . LanguageSupportFactory ; 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 . eclipse . jdt . core . * ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . core . compiler . CompilationParticipant ; import org . eclipse . jdt . core . compiler . IProblem ; import org . eclipse . jdt . core . formatter . DefaultCodeFormatterConstants ; import org . eclipse . jdt . internal . codeassist . CompletionEngine ; import org . eclipse . jdt . internal . codeassist . SelectionEngine ; import org . eclipse . jdt . internal . compiler . AbstractAnnotationProcessorManager ; import org . eclipse . jdt . internal . compiler . Compiler ; import org . eclipse . jdt . internal . compiler . classfmt . ClassFileConstants ; import org . eclipse . jdt . internal . compiler . env . AccessRestriction ; import org . eclipse . jdt . internal . compiler . impl . CompilerOptions ; import org . eclipse . jdt . internal . compiler . util . HashtableOfObjectToInt ; import org . eclipse . jdt . internal . core . JavaProjectElementInfo . ProjectCache ; import org . eclipse . jdt . internal . core . builder . JavaBuilder ; import org . eclipse . jdt . internal . core . hierarchy . TypeHierarchy ; import org . eclipse . jdt . internal . core . search . AbstractSearchScope ; import org . eclipse . jdt . internal . core . search . BasicSearchEngine ; import org . eclipse . jdt . internal . core . search . IRestrictedAccessTypeRequestor ; import org . eclipse . jdt . internal . core . search . JavaWorkspaceScope ; import org . eclipse . jdt . internal . core . search . indexing . IndexManager ; 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 . Messages ; import org . eclipse . jdt . internal . core . util . Util ; import org . eclipse . jdt . internal . core . util . WeakHashSet ; import org . eclipse . jdt . internal . core . util . WeakHashSetOfCharArray ; import org . eclipse . jdt . internal . core . util . LRUCache . Stats ; import org . eclipse . jdt . internal . formatter . DefaultCodeFormatter ; import org . osgi . service . prefs . BackingStoreException ; import org . w3c . dom . Element ; import org . w3c . dom . Node ; import org . w3c . dom . NodeList ; import org . xml . sax . InputSource ; import org . xml . sax . SAXException ; public class JavaModelManager implements ISaveParticipant , IContentTypeChangeListener { private static final String NON_CHAINING_JARS_CACHE = "" ; private static final String INVALID_ARCHIVES_CACHE = "" ; static class ZipCache { private Map map ; Object owner ; ZipCache ( Object owner ) { this . map = new HashMap ( ) ; this . owner = owner ; } public void flush ( ) { Thread currentThread = Thread . currentThread ( ) ; Iterator iterator = this . map . values ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { try { ZipFile zipFile = ( ZipFile ) iterator . next ( ) ; if ( JavaModelManager . ZIP_ACCESS_VERBOSE ) { System . out . println ( "(" + currentThread + "" + zipFile . getName ( ) ) ; } zipFile . close ( ) ; } catch ( IOException e ) { } } } public ZipFile getCache ( IPath path ) { return ( ZipFile ) this . map . get ( path ) ; } public void setCache ( IPath path , ZipFile zipFile ) { this . map . put ( path , zipFile ) ; } } final JavaModel javaModel = new JavaModel ( ) ; 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 containers = new HashMap ( 5 ) ; public HashMap previousSessionContainers = new HashMap ( 5 ) ; private ThreadLocal containerInitializationInProgress = new ThreadLocal ( ) ; ThreadLocal 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 ; public static final int BATCH_INITIALIZATION_FINISHED = 3 ; public int batchContainerInitializations = NO_BATCH_INITIALIZATION ; public BatchInitializationMonitor batchContainerInitializationsProgress = new BatchInitializationMonitor ( ) ; public Hashtable containerInitializersCache = new Hashtable ( 5 ) ; private ThreadLocal classpathsBeingResolved = new ThreadLocal ( ) ; public JavaWorkspaceScope workspaceScope ; private WeakHashSet stringSymbols = new WeakHashSet ( 5 ) ; private WeakHashSetOfCharArray charArraySymbols = new WeakHashSetOfCharArray ( 5 ) ; private IConfigurationElement annotationProcessorManagerFactory = null ; public Map rootPathToAttachments = new Hashtable ( ) ; public final static String CP_VARIABLE_PREFERENCES_PREFIX = JavaCore . PLUGIN_ID + "" ; public final static String CP_CONTAINER_PREFERENCES_PREFIX = JavaCore . PLUGIN_ID + "" ; public final static String CP_USERLIBRARY_PREFERENCES_PREFIX = JavaCore . PLUGIN_ID + "" ; public final static String CP_ENTRY_IGNORE = "" ; public final static IPath CP_ENTRY_IGNORE_PATH = new Path ( CP_ENTRY_IGNORE ) ; public final static String TRUE = "true" ; private final static int VARIABLES_AND_CONTAINERS_FILE_VERSION = 2 ; public static final String CPVARIABLE_INITIALIZER_EXTPOINT_ID = "" ; public static final String CPCONTAINER_INITIALIZER_EXTPOINT_ID = "" ; public static final String FORMATTER_EXTPOINT_ID = "" ; public static final String COMPILATION_PARTICIPANT_EXTPOINT_ID = "" ; public static final String ANNOTATION_PROCESSOR_MANAGER_EXTPOINT_ID = "" ; private static final String RESOLVE_REFERENCED_LIBRARIES_FOR_CONTAINERS = "" ; public final static IPath VARIABLE_INITIALIZATION_IN_PROGRESS = new Path ( "" ) ; public final static IClasspathContainer CONTAINER_INITIALIZATION_IN_PROGRESS = new IClasspathContainer ( ) { public IClasspathEntry [ ] getClasspathEntries ( ) { return null ; } public String getDescription ( ) { return "" ; } public int getKind ( ) { return 0 ; } public IPath getPath ( ) { return null ; } public String toString ( ) { return getDescription ( ) ; } } ; private static final String BUFFER_MANAGER_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String INDEX_MANAGER_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String INDEX_MANAGER_ADVANCED_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String COMPILER_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String JAVAMODEL_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String JAVAMODELCACHE_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String CP_RESOLVE_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String CP_RESOLVE_ADVANCED_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String CP_RESOLVE_FAILURE_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String ZIP_ACCESS_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String DELTA_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String DELTA_DEBUG_VERBOSE = JavaCore . PLUGIN_ID + "" ; private static final String HIERARCHY_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String POST_ACTION_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String BUILDER_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String BUILDER_STATS_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String COMPLETION_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String RESOLUTION_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String SELECTION_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String SEARCH_DEBUG = JavaCore . PLUGIN_ID + "" ; private static final String SOURCE_MAPPER_DEBUG_VERBOSE = JavaCore . PLUGIN_ID + "" ; private static final String FORMATTER_DEBUG = JavaCore . PLUGIN_ID + "" ; public static final String COMPLETION_PERF = JavaCore . PLUGIN_ID + "" ; public static final String SELECTION_PERF = JavaCore . PLUGIN_ID + "" ; public static final String DELTA_LISTENER_PERF = JavaCore . PLUGIN_ID + "" ; public static final String VARIABLE_INITIALIZER_PERF = JavaCore . PLUGIN_ID + "" ; public static final String CONTAINER_INITIALIZER_PERF = JavaCore . PLUGIN_ID + "" ; public static final String RECONCILE_PERF = JavaCore . PLUGIN_ID + "" ; private final static String INDEXED_SECONDARY_TYPES = "" ; public static boolean PERF_VARIABLE_INITIALIZER = false ; public static boolean PERF_CONTAINER_INITIALIZER = false ; boolean resolveReferencedLibrariesForContainers = false ; public final static ICompilationUnit [ ] NO_WORKING_COPY = new ICompilationUnit [ 0 ] ; 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 ; 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 ; private Object [ ] [ ] registeredParticipants = null ; private HashSet managedMarkerTypes ; public CompilationParticipant [ ] getCompilationParticipants ( IJavaProject project ) { final Object [ ] [ ] participantsPerSource = getRegisteredParticipants ( ) ; if ( participantsPerSource == NO_PARTICIPANTS ) return null ; String sourceLevel = project . getOption ( JavaCore . COMPILER_SOURCE , true ) ; 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 < length ; i ++ ) { if ( participants [ i ] instanceof IConfigurationElement ) { final IConfigurationElement configElement = ( IConfigurationElement ) participants [ i ] ; final int participantIndex = i ; SafeRunner . run ( new ISafeRunnable ( ) { public void handleException ( Throwable exception ) { Util . log ( exception , "" ) ; } public void run ( ) throws Exception { Object executableExtension = configElement . createExecutableExtension ( "class" ) ; for ( int j = sourceLevelIndex ; j < MAX_SOURCE_LEVEL ; j ++ ) participantsPerSource [ j ] [ participantIndex ] = executableExtension ; } } ) ; } CompilationParticipant participant ; if ( ( participants [ i ] instanceof CompilationParticipant ) && ( participant = ( CompilationParticipant ) participants [ 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 ; } public HashSet managedMarkerTypes ( ) { if ( this . managedMarkerTypes == null ) { getRegisteredParticipants ( ) ; } return this . managedMarkerTypes ; } private synchronized Object [ ] [ ] getRegisteredParticipants ( ) { if ( this . registeredParticipants != null ) { return this . registeredParticipants ; } 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 ( ) ; IExtension [ ] extensions = extension . getExtensions ( ) ; for ( int i = 0 ; i < extensions . length ; i ++ ) { IConfigurationElement [ ] configElements = extensions [ i ] . getConfigurationElements ( ) ; for ( int j = 0 ; j < configElements . length ; j ++ ) { final IConfigurationElement configElement = configElements [ j ] ; String elementName = configElement . getName ( ) ; if ( ! ( "" . equals ( elementName ) ) ) { continue ; } if ( TRUE . equals ( configElement . getAttribute ( "" ) ) ) modifyingEnv . add ( configElement ) ; else if ( TRUE . equals ( configElement . getAttribute ( "" ) ) ) creatingProblems . add ( configElement ) ; else others . add ( configElement ) ; IConfigurationElement [ ] managedMarkers = configElement . getChildren ( "" ) ; for ( int k = 0 , length = managedMarkers . length ; k < length ; k ++ ) { IConfigurationElement element = managedMarkers [ k ] ; String markerType = element . getAttribute ( "markerType" ) ; if ( markerType != null ) this . managedMarkerTypes . add ( markerType ) ; } } } int size = modifyingEnv . size ( ) + creatingProblems . size ( ) + others . size ( ) ; if ( size == 0 ) return this . registeredParticipants = NO_PARTICIPANTS ; IConfigurationElement [ ] configElements = new IConfigurationElement [ size ] ; int index = 0 ; index = sortParticipants ( modifyingEnv , configElements , index ) ; index = sortParticipants ( creatingProblems , configElements , index ) ; index = sortParticipants ( others , configElements , index ) ; Object [ ] [ ] result = new Object [ MAX_SOURCE_LEVEL ] [ ] ; int length = configElements . length ; for ( int i = 0 ; i < MAX_SOURCE_LEVEL ; i ++ ) { result [ i ] = new Object [ length ] ; } for ( int i = 0 ; i < length ; i ++ ) { String sourceLevel = configElements [ i ] . getAttribute ( "" ) ; int sourceLevelIndex = indexForSourceLevel ( sourceLevel ) ; for ( int j = sourceLevelIndex ; j < MAX_SOURCE_LEVEL ; j ++ ) { result [ j ] [ i ] = configElements [ i ] ; } } return this . registeredParticipants = result ; } private int indexForSourceLevel ( String sourceLevel ) { if ( sourceLevel == null ) return 0 ; int majVersion = ( int ) ( CompilerOptions . versionToJdkLevel ( sourceLevel ) >>> 16 ) ; switch ( majVersion ) { case ClassFileConstants . MAJOR_VERSION_1_2 : return 1 ; case ClassFileConstants . MAJOR_VERSION_1_3 : return 2 ; case ClassFileConstants . MAJOR_VERSION_1_4 : return 3 ; case ClassFileConstants . MAJOR_VERSION_1_5 : return 4 ; case ClassFileConstants . MAJOR_VERSION_1_6 : return 5 ; case ClassFileConstants . MAJOR_VERSION_1_7 : return 6 ; default : return 0 ; } } private int sortParticipants ( ArrayList group , IConfigurationElement [ ] configElements , int index ) { int size = group . size ( ) ; if ( size == 0 ) return index ; Object [ ] elements = group . toArray ( ) ; Util . sort ( elements , new Util . Comparer ( ) { public int compare ( Object a , Object b ) { if ( a == b ) return 0 ; String id = ( ( IConfigurationElement ) a ) . getAttribute ( "id" ) ; if ( id == null ) return - 1 ; IConfigurationElement [ ] requiredElements = ( ( IConfigurationElement ) b ) . getChildren ( "requires" ) ; for ( int i = 0 , length = requiredElements . length ; i < length ; i ++ ) { IConfigurationElement required = requiredElements [ i ] ; if ( id . equals ( required . getAttribute ( "id" ) ) ) return 1 ; } return - 1 ; } } ) ; for ( int i = 0 ; i < size ; i ++ ) configElements [ index + i ] = ( IConfigurationElement ) elements [ i ] ; return index + size ; } } public final CompilationParticipants compilationParticipants = new CompilationParticipants ( ) ; public ThreadLocal abortOnMissingSource = new ThreadLocal ( ) ; private ExternalFoldersManager externalFoldersManager = ExternalFoldersManager . getExternalFoldersManager ( ) ; public static boolean conflictsWithOutputLocation ( IPath folderPath , JavaProject project ) { try { IPath outputLocation = project . getOutputLocation ( ) ; if ( outputLocation == null ) { return true ; } if ( outputLocation . isPrefixOf ( folderPath ) ) { IClasspathEntry [ ] classpath = project . getResolvedClasspath ( ) ; boolean isOutputUsed = false ; for ( int i = 0 , length = classpath . length ; i < length ; i ++ ) { IClasspathEntry entry = classpath [ i ] ; if ( entry . getEntryKind ( ) == IClasspathEntry . CPE_SOURCE ) { if ( entry . getPath ( ) . equals ( outputLocation ) ) { return false ; } if ( entry . getOutputLocation ( ) == null ) { isOutputUsed = true ; } } } return isOutputUsed ; } return false ; } catch ( JavaModelException e ) { return true ; } } public synchronized IClasspathContainer containerGet ( IJavaProject project , IPath containerPath ) { if ( containerIsInitializationInProgress ( project , containerPath ) ) { return CONTAINER_INITIALIZATION_IN_PROGRESS ; } Map projectContainers = ( Map ) this . containers . 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 . containers . get ( project ) ; if ( projectContainers == null ) return getPreviousSessionContainer ( containerPath , project ) ; IClasspathContainer container = ( IClasspathContainer ) 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 ( ) ; if ( initializations == null ) return false ; HashSet projectInitializations = ( HashSet ) 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 ( ) ; if ( initializations == null ) this . containerInitializationInProgress . set ( initializations = new HashMap ( ) ) ; HashSet projectInitializations = ( HashSet ) initializations . get ( project ) ; if ( projectInitializations == null ) initializations . put ( project , projectInitializations = new HashSet ( ) ) ; projectInitializations . add ( containerPath ) ; } public void containerBeingInitializedPut ( IJavaProject project , IPath containerPath , IClasspathContainer container ) { Map perProjectContainers = ( Map ) this . containersBeingInitialized . get ( ) ; if ( perProjectContainers == null ) this . containersBeingInitialized . set ( perProjectContainers = new HashMap ( ) ) ; HashMap perPathContainers = ( HashMap ) perProjectContainers . get ( project ) ; if ( perPathContainers == null ) perProjectContainers . put ( project , perPathContainers = new HashMap ( ) ) ; perPathContainers . put ( containerPath , container ) ; } public IClasspathContainer containerBeingInitializedGet ( IJavaProject project , IPath containerPath ) { Map perProjectContainers = ( Map ) this . containersBeingInitialized . get ( ) ; if ( perProjectContainers == null ) return null ; HashMap perPathContainers = ( HashMap ) perProjectContainers . get ( project ) ; if ( perPathContainers == null ) return null ; return ( IClasspathContainer ) perPathContainers . get ( containerPath ) ; } public IClasspathContainer containerBeingInitializedRemove ( IJavaProject project , IPath containerPath ) { Map perProjectContainers = ( Map ) this . containersBeingInitialized . get ( ) ; if ( perProjectContainers == null ) return null ; HashMap perPathContainers = ( HashMap ) perProjectContainers . get ( project ) ; if ( perPathContainers == null ) return null ; IClasspathContainer container = ( IClasspathContainer ) perPathContainers . remove ( containerPath ) ; if ( perPathContainers . size ( ) == 0 ) perPathContainers . remove ( project ) ; if ( perProjectContainers . size ( ) == 0 ) this . containersBeingInitialized . set ( null ) ; return container ; } public synchronized void containerPut ( IJavaProject project , IPath containerPath , IClasspathContainer container ) { if ( container == CONTAINER_INITIALIZATION_IN_PROGRESS ) { containerAddInitializationInProgress ( project , containerPath ) ; return ; } else { containerRemoveInitializationInProgress ( project , containerPath ) ; Map projectContainers = ( Map ) this . containers . get ( project ) ; if ( projectContainers == null ) { projectContainers = new HashMap ( 1 ) ; this . containers . put ( project , projectContainers ) ; } if ( container == null ) { projectContainers . remove ( containerPath ) ; } else { projectContainers . put ( containerPath , container ) ; } Map previousContainers = ( Map ) this . previousSessionContainers . get ( project ) ; if ( previousContainers != null ) { previousContainers . remove ( containerPath ) ; } } } public synchronized void containerRemove ( IJavaProject project ) { Map initializations = ( Map ) this . containerInitializationInProgress . get ( ) ; if ( initializations != null ) { initializations . remove ( project ) ; } this . containers . remove ( project ) ; } public boolean containerPutIfInitializingWithSameEntries ( IPath containerPath , IJavaProject [ ] projects , IClasspathContainer [ ] respectiveContainers ) { int projectLength = projects . length ; if ( projectLength != 1 ) return false ; final IClasspathContainer container = respectiveContainers [ 0 ] ; IJavaProject project = projects [ 0 ] ; if ( ! containerIsInitializationInProgress ( project , containerPath ) ) return false ; IClasspathContainer previousContainer = containerGetDefaultToPreviousSession ( project , containerPath ) ; if ( container == null ) { if ( previousContainer == null ) { containerPut ( project , containerPath , null ) ; return true ; } return false ; } final IClasspathEntry [ ] newEntries = container . getClasspathEntries ( ) ; if ( previousContainer == null ) if ( newEntries . length == 0 ) { containerPut ( project , containerPath , container ) ; return true ; } else { if ( CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE ) verbose_missbehaving_container ( containerPath , projects , respectiveContainers , container , newEntries , null ) ; return false ; } final IClasspathEntry [ ] oldEntries = previousContainer . getClasspathEntries ( ) ; if ( oldEntries . length != newEntries . length ) { if ( CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE ) verbose_missbehaving_container ( containerPath , projects , respectiveContainers , container , newEntries , oldEntries ) ; return false ; } for ( int i = 0 , length = newEntries . length ; i < length ; i ++ ) { if ( newEntries [ i ] == null ) { if ( CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE ) verbose_missbehaving_container ( project , containerPath , newEntries ) ; return false ; } if ( ! newEntries [ i ] . equals ( oldEntries [ i ] ) ) { if ( CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE ) verbose_missbehaving_container ( containerPath , projects , respectiveContainers , container , newEntries , oldEntries ) ; return false ; } } containerPut ( project , containerPath , container ) ; return true ; } private void verbose_missbehaving_container ( IPath containerPath , IJavaProject [ ] projects , IClasspathContainer [ ] respectiveContainers , final IClasspathContainer container , final IClasspathEntry [ ] newEntries , final IClasspathEntry [ ] oldEntries ) { Util . verbose ( "" + "" + containerPath + '\n' + "tprojects: {" + org . eclipse . jdt . internal . compiler . util . Util . toString ( projects , new org . eclipse . jdt . internal . compiler . util . Util . Displayable ( ) { public String displayString ( Object o ) { return ( ( IJavaProject ) o ) . getElementName ( ) ; } } ) + "" + org . eclipse . jdt . internal . compiler . util . Util . toString ( respectiveContainers , new org . eclipse . jdt . internal . compiler . util . Util . Displayable ( ) { public String displayString ( Object o ) { StringBuffer buffer = new StringBuffer ( "tt" ) ; if ( o == null ) { buffer . append ( "<null>" ) ; return buffer . toString ( ) ; } buffer . append ( container . getDescription ( ) ) ; buffer . append ( " {n" ) ; if ( oldEntries == null ) { buffer . append ( " ttt" ) ; buffer . append ( "<null>n" ) ; } else { for ( int j = 0 ; j < oldEntries . length ; j ++ ) { buffer . append ( " ttt" ) ; buffer . append ( oldEntries [ j ] ) ; buffer . append ( '\n' ) ; } } buffer . append ( " tt}" ) ; return buffer . toString ( ) ; } } ) + "" + org . eclipse . jdt . internal . compiler . util . Util . toString ( respectiveContainers , new org . eclipse . jdt . internal . compiler . util . Util . Displayable ( ) { public String displayString ( Object o ) { StringBuffer buffer = new StringBuffer ( "tt" ) ; if ( o == null ) { buffer . append ( "<null>" ) ; return buffer . toString ( ) ; } buffer . append ( container . getDescription ( ) ) ; buffer . append ( " {n" ) ; for ( int j = 0 ; j < newEntries . length ; j ++ ) { buffer . append ( " ttt" ) ; buffer . append ( newEntries [ j ] ) ; buffer . append ( '\n' ) ; } buffer . append ( " tt}" ) ; return buffer . toString ( ) ; } } ) + "nt}" ) ; } void verbose_missbehaving_container ( IJavaProject project , IPath containerPath , IClasspathEntry [ ] classpathEntries ) { Util . verbose ( "" + "tproject: " + project . getElementName ( ) + '\n' + "" + containerPath + '\n' + "" + org . eclipse . jdt . internal . compiler . util . Util . toString ( classpathEntries , new org . eclipse . jdt . internal . compiler . util . Util . Displayable ( ) { public String displayString ( Object o ) { StringBuffer buffer = new StringBuffer ( "tt" ) ; if ( o == null ) { buffer . append ( "<null>" ) ; return buffer . toString ( ) ; } buffer . append ( o ) ; return buffer . toString ( ) ; } } ) + "nt}" ) ; } void verbose_missbehaving_container_null_entries ( IJavaProject project , IPath containerPath ) { Util . verbose ( "" + "tproject: " + project . getElementName ( ) + '\n' + "" + containerPath + '\n' + "" ) ; } private void containerRemoveInitializationInProgress ( IJavaProject project , IPath containerPath ) { Map initializations = ( Map ) this . containerInitializationInProgress . get ( ) ; if ( initializations == null ) return ; HashSet projectInitializations = ( HashSet ) initializations . get ( project ) ; if ( projectInitializations == null ) return ; projectInitializations . remove ( containerPath ) ; if ( projectInitializations . size ( ) == 0 ) initializations . remove ( project ) ; if ( initializations . size ( ) == 0 ) this . containerInitializationInProgress . set ( null ) ; } private synchronized void containersReset ( String [ ] containerIDs ) { for ( int i = 0 ; i < containerIDs . length ; i ++ ) { String containerID = containerIDs [ i ] ; Iterator projectIterator = this . containers . values ( ) . iterator ( ) ; while ( projectIterator . hasNext ( ) ) { Map projectContainers = ( Map ) projectIterator . next ( ) ; if ( projectContainers != null ) { Iterator containerIterator = projectContainers . keySet ( ) . iterator ( ) ; while ( containerIterator . hasNext ( ) ) { IPath containerPath = ( IPath ) containerIterator . next ( ) ; if ( containerID . equals ( containerPath . segment ( 0 ) ) ) { projectContainers . put ( containerPath , null ) ; } } } } } } public static IJavaElement create ( IResource resource , IJavaProject 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 ) resource , project ) ; case IResource . FOLDER : return create ( ( IFolder ) resource , project ) ; case IResource . ROOT : return JavaCore . create ( ( IWorkspaceRoot ) resource ) ; default : return null ; } } public static IJavaElement create ( IFile file , IJavaProject 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 ( file , project ) ; if ( org . eclipse . jdt . internal . compiler . util . Util . isClassFileName ( name ) ) return createClassFileFrom ( file , project ) ; return createJarPackageFragmentRootFrom ( file , project ) ; } return null ; } public static IJavaElement create ( IFolder folder , IJavaProject project ) { if ( folder == null ) { return null ; } IJavaElement element ; if ( project == null ) { project = JavaCore . create ( folder . getProject ( ) ) ; element = determineIfOnClasspath ( folder , project ) ; if ( element == null ) { IJavaProject [ ] projects ; try { projects = JavaModelManager . getJavaModelManager ( ) . getJavaModel ( ) . getJavaProjects ( ) ; } catch ( JavaModelException e ) { return null ; } for ( int i = 0 , length = projects . length ; i < length ; i ++ ) { project = projects [ i ] ; element = determineIfOnClasspath ( folder , project ) ; if ( element != null ) break ; } } } else { element = determineIfOnClasspath ( folder , project ) ; } return element ; } public static IClassFile createClassFileFrom ( IFile file , IJavaProject project ) { if ( file == null ) { return null ; } if ( project == null ) { project = JavaCore . create ( file . getProject ( ) ) ; } IPackageFragment pkg = ( IPackageFragment ) determineIfOnClasspath ( file , project ) ; if ( pkg == null ) { PackageFragmentRoot root = ( PackageFragmentRoot ) project . getPackageFragmentRoot ( file . getParent ( ) ) ; pkg = root . getPackageFragment ( CharOperation . NO_STRINGS ) ; } return pkg . getClassFile ( file . getName ( ) ) ; } public static ICompilationUnit createCompilationUnitFrom ( IFile file , IJavaProject project ) { if ( file == null ) return null ; if ( project == null ) { project = JavaCore . create ( file . getProject ( ) ) ; } IPackageFragment pkg = ( IPackageFragment ) determineIfOnClasspath ( file , project ) ; if ( pkg == null ) { PackageFragmentRoot root = ( PackageFragmentRoot ) project . getPackageFragmentRoot ( file . getParent ( ) ) ; pkg = root . getPackageFragment ( CharOperation . NO_STRINGS ) ; if ( VERBOSE ) { System . out . println ( "" + Thread . currentThread ( ) + "): " + file . getFullPath ( ) ) ; } } return pkg . getCompilationUnit ( file . getName ( ) ) ; } public static IPackageFragmentRoot createJarPackageFragmentRootFrom ( IFile file , IJavaProject project ) { if ( file == null ) { return null ; } if ( project == null ) { project = JavaCore . create ( file . getProject ( ) ) ; } IPath resourcePath = file . getFullPath ( ) ; try { IClasspathEntry entry = ( ( JavaProject ) project ) . getClasspathEntryFor ( resourcePath ) ; if ( entry != null ) { return project . getPackageFragmentRoot ( file ) ; } } catch ( JavaModelException e ) { } return null ; } public static IJavaElement determineIfOnClasspath ( IResource resource , IJavaProject project ) { IPath resourcePath = resource . getFullPath ( ) ; boolean isExternal = ExternalFoldersManager . isInternalPathForExternalFolder ( resourcePath ) ; if ( isExternal ) resourcePath = resource . getLocation ( ) ; try { JavaProjectElementInfo projectInfo = ( JavaProjectElementInfo ) getJavaModelManager ( ) . getInfo ( project ) ; 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 ( ) : ( ( JavaProject ) project ) . getResolvedClasspath ( ) ; int length = entries . length ; if ( length > 0 ) { String sourceLevel = project . getOption ( JavaCore . COMPILER_SOURCE , true ) ; String complianceLevel = project . getOption ( JavaCore . COMPILER_COMPLIANCE , true ) ; for ( int i = 0 ; i < length ; i ++ ) { IClasspathEntry entry = entries [ i ] ; if ( entry . getEntryKind ( ) == IClasspathEntry . CPE_PROJECT ) continue ; IPath rootPath = entry . getPath ( ) ; if ( rootPath . equals ( resourcePath ) ) { if ( isJavaLike ) return null ; return project . getPackageFragmentRoot ( resource ) ; } else if ( rootPath . isPrefixOf ( resourcePath ) ) { if ( ! Util . isExcluded ( resource , ( ( ClasspathEntry ) entry ) . fullInclusionPatternChars ( ) , ( ( ClasspathEntry ) entry ) . fullExclusionPatternChars ( ) ) ) { PackageFragmentRoot root = isExternal ? new ExternalPackageFragmentRoot ( rootPath , ( JavaProject ) project ) : ( PackageFragmentRoot ) ( ( JavaProject ) project ) . getFolderPackageFragmentRoot ( rootPath ) ; if ( root == null ) return null ; IPath pkgPath = resourcePath . removeFirstSegments ( rootPath . segmentCount ( ) ) ; if ( resource . getType ( ) == IResource . FILE ) { pkgPath = pkgPath . removeLastSegments ( 1 ) ; } String [ ] pkgName = pkgPath . segments ( ) ; if ( allPkgFragmentsCache != null && allPkgFragmentsCache . containsKey ( pkgName ) ) return root . getPackageFragment ( pkgName ) ; if ( pkgName . length != 0 && JavaConventions . validatePackageName ( Util . packageName ( pkgPath , sourceLevel , complianceLevel ) , sourceLevel , complianceLevel ) . getSeverity ( ) == IStatus . ERROR ) { return null ; } return root . getPackageFragment ( pkgName ) ; } } } } } catch ( JavaModelException npe ) { return null ; } return null ; } private static JavaModelManager MANAGER = new JavaModelManager ( ) ; private JavaModelCache cache ; private ThreadLocal temporaryCache = new ThreadLocal ( ) ; protected HashSet elementsOutOfSynchWithBuffers = new HashSet ( 11 ) ; public DeltaProcessingState deltaState = new DeltaProcessingState ( ) ; public IndexManager indexManager = null ; protected Map perProjectInfos = new HashMap ( 5 ) ; protected Map perWorkingCopyInfos = new HashMap ( 5 ) ; protected WeakHashMap searchScopes = new WeakHashMap ( ) ; public static class PerProjectInfo { private static final int JAVADOC_CACHE_INITIAL_SIZE = 10 ; static final IJavaModelStatus NEED_RESOLUTION = new JavaModelStatus ( ) ; public IProject project ; public Object savedState ; public boolean triedRead ; public IClasspathEntry [ ] rawClasspath ; public IClasspathEntry [ ] referencedEntries ; public IJavaModelStatus rawClasspathStatus ; public int rawTimeStamp = 0 ; public boolean writtingRawClasspath = false ; public IClasspathEntry [ ] resolvedClasspath ; public IJavaModelStatus unresolvedEntryStatus ; public Map rootPathToRawEntries ; public Map rootPathToResolvedEntries ; public IPath outputLocation ; public IEclipsePreferences preferences ; public Hashtable options ; public Hashtable secondaryTypes ; public LRUCache javadocCache ; public PerProjectInfo ( IProject project ) { this . triedRead = false ; this . savedState = null ; this . project = project ; this . javadocCache = new LRUCache ( JAVADOC_CACHE_INITIAL_SIZE ) ; } public synchronized IClasspathEntry [ ] getResolvedClasspath ( ) { if ( this . unresolvedEntryStatus == NEED_RESOLUTION ) 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 ; for ( int i = 0 , length = classpath . length ; i < length ; i ++ ) { IClasspathEntry entry = classpath [ i ] ; if ( entry . getEntryKind ( ) == IClasspathEntry . CPE_LIBRARY ) { IPath path = entry . getPath ( ) ; if ( rootInfos . get ( path ) == null ) { externalTimeStamps . remove ( path ) ; indexManager . removeIndex ( path ) ; } } } } public void rememberExternalLibTimestamps ( ) { IClasspathEntry [ ] classpath = this . resolvedClasspath ; if ( classpath == null ) return ; Map 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 ) { IPath path = entry . getPath ( ) ; if ( externalTimeStamps . get ( path ) == null ) { Object target = JavaModel . getExternalTarget ( path , true ) ; if ( target instanceof File ) { long timestamp = DeltaProcessor . getTimeStamp ( ( java . io . File ) target ) ; externalTimeStamps . put ( path , new Long ( timestamp ) ) ; } } } } } public synchronized ClasspathChange resetResolvedClasspath ( ) { JavaModelManager . getJavaModelManager ( ) . resetClasspathListCache ( ) ; return setResolvedClasspath ( null , null , null , null , this . rawTimeStamp , true ) ; } private ClasspathChange setClasspath ( IClasspathEntry [ ] newRawClasspath , IClasspathEntry [ ] referencedEntries , IPath newOutputLocation , IJavaModelStatus newRawClasspathStatus , IClasspathEntry [ ] newResolvedClasspath , Map newRootPathToRawEntries , Map newRootPathToResolvedEntries , IJavaModelStatus newUnresolvedEntryStatus , boolean addClasspathChange ) { ClasspathChange classpathChange = addClasspathChange ? addClasspathChange ( ) : null ; if ( referencedEntries != null ) this . referencedEntries = referencedEntries ; if ( this . referencedEntries == null ) this . referencedEntries = ClasspathEntry . NO_ENTRIES ; this . rawClasspath = newRawClasspath ; this . outputLocation = newOutputLocation ; this . rawClasspathStatus = newRawClasspathStatus ; this . resolvedClasspath = newResolvedClasspath ; this . rootPathToRawEntries = newRootPathToRawEntries ; this . rootPathToResolvedEntries = newRootPathToResolvedEntries ; this . unresolvedEntryStatus = newUnresolvedEntryStatus ; this . javadocCache = new LRUCache ( JAVADOC_CACHE_INITIAL_SIZE ) ; return classpathChange ; } protected ClasspathChange addClasspathChange ( ) { JavaModelManager manager = JavaModelManager . getJavaModelManager ( ) ; ClasspathChange classpathChange = manager . deltaState . addClasspathChange ( this . project , this . rawClasspath , this . outputLocation , this . resolvedClasspath ) ; return classpathChange ; } public ClasspathChange setRawClasspath ( IClasspathEntry [ ] newRawClasspath , IPath newOutputLocation , IJavaModelStatus newRawClasspathStatus ) { return setRawClasspath ( newRawClasspath , null , newOutputLocation , newRawClasspathStatus ) ; } public synchronized ClasspathChange setRawClasspath ( IClasspathEntry [ ] newRawClasspath , IClasspathEntry [ ] referencedEntries , IPath newOutputLocation , IJavaModelStatus newRawClasspathStatus ) { this . rawTimeStamp ++ ; return setClasspath ( newRawClasspath , referencedEntries , newOutputLocation , newRawClasspathStatus , null , null , null , null , true ) ; } public ClasspathChange setResolvedClasspath ( IClasspathEntry [ ] newResolvedClasspath , Map newRootPathToRawEntries , Map 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 ) { if ( this . rawTimeStamp != timeStamp ) return null ; return setClasspath ( this . rawClasspath , referencedEntries , this . outputLocation , this . rawClasspathStatus , newResolvedClasspath , newRootPathToRawEntries , newRootPathToResolvedEntries , newUnresolvedEntryStatus , addClasspathChange ) ; } public synchronized IClasspathEntry [ ] [ ] readAndCacheClasspath ( JavaProject javaProject ) { IClasspathEntry [ ] [ ] classpath ; IJavaModelStatus status ; try { classpath = javaProject . readFileEntriesWithException ( null ) ; status = JavaModelStatus . VERIFIED_OK ; } catch ( CoreException e ) { classpath = new IClasspathEntry [ ] [ ] { JavaProject . INVALID_CLASSPATH , ClasspathEntry . NO_ENTRIES } ; status = new JavaModelStatus ( IJavaModelStatusConstants . INVALID_CLASSPATH_FILE_FORMAT , Messages . bind ( Messages . classpath_cannotReadClasspathFile , javaProject . getElementName ( ) ) ) ; } catch ( IOException e ) { classpath = new IClasspathEntry [ ] [ ] { JavaProject . INVALID_CLASSPATH , ClasspathEntry . NO_ENTRIES } ; if ( Messages . file_badFormat . equals ( e . getMessage ( ) ) ) status = new JavaModelStatus ( IJavaModelStatusConstants . INVALID_CLASSPATH_FILE_FORMAT , Messages . bind ( Messages . classpath_xmlFormatError , javaProject . getElementName ( ) , Messages . file_badFormat ) ) ; else status = new JavaModelStatus ( IJavaModelStatusConstants . INVALID_CLASSPATH_FILE_FORMAT , Messages . bind ( Messages . classpath_cannotReadClasspathFile , javaProject . getElementName ( ) ) ) ; } catch ( ClasspathEntry . AssertionFailedException e ) { classpath = new IClasspathEntry [ ] [ ] { JavaProject . INVALID_CLASSPATH , ClasspathEntry . NO_ENTRIES } ; status = new JavaModelStatus ( IJavaModelStatusConstants . INVALID_CLASSPATH_FILE_FORMAT , Messages . bind ( Messages . classpath_illegalEntryInClasspathFile , new String [ ] { javaProject . getElementName ( ) , e . getMessage ( ) } ) ) ; } int rawClasspathLength = classpath [ 0 ] . length ; IPath output = null ; if ( rawClasspathLength > 0 ) { IClasspathEntry entry = classpath [ 0 ] [ rawClasspathLength - 1 ] ; if ( entry . getContentKind ( ) == ClasspathEntry . K_OUTPUT ) { output = entry . getPath ( ) ; IClasspathEntry [ ] copy = new IClasspathEntry [ rawClasspathLength - 1 ] ; System . arraycopy ( classpath [ 0 ] , 0 , copy , 0 , copy . length ) ; classpath [ 0 ] = copy ; } } setRawClasspath ( classpath [ 0 ] , classpath [ 1 ] , output , status ) ; return classpath ; } public String toString ( ) { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( "Info for " ) ; buffer . append ( this . project . getFullPath ( ) ) ; buffer . append ( "" ) ; if ( this . rawClasspath == null ) { buffer . append ( " <null>n" ) ; } else { for ( int i = 0 , length = this . rawClasspath . length ; i < length ; i ++ ) { buffer . append ( " " ) ; buffer . append ( this . rawClasspath [ i ] ) ; buffer . append ( '\n' ) ; } } buffer . append ( "" ) ; IClasspathEntry [ ] resolvedCP = this . resolvedClasspath ; if ( resolvedCP == null ) { buffer . append ( " <null>n" ) ; } else { for ( int i = 0 , length = resolvedCP . length ; i < length ; i ++ ) { buffer . append ( " " ) ; buffer . append ( resolvedCP [ i ] ) ; buffer . append ( '\n' ) ; } } buffer . append ( "" ) ; if ( this . unresolvedEntryStatus == NEED_RESOLUTION ) buffer . append ( "" ) ; else buffer . append ( this . unresolvedEntryStatus == null ? "<null>n" : this . unresolvedEntryStatus . toString ( ) ) ; buffer . append ( "" ) ; if ( this . outputLocation == null ) { buffer . append ( "<null>" ) ; } else { buffer . append ( this . outputLocation ) ; } return buffer . toString ( ) ; } public boolean writeAndCacheClasspath ( JavaProject javaProject , final IClasspathEntry [ ] newRawClasspath , IClasspathEntry [ ] newReferencedEntries , final IPath newOutputLocation ) throws JavaModelException { try { this . writtingRawClasspath = true ; if ( newReferencedEntries == null ) newReferencedEntries = this . referencedEntries ; if ( ! javaProject . writeFileEntries ( newRawClasspath , newReferencedEntries , newOutputLocation ) ) { return false ; } setRawClasspath ( newRawClasspath , newReferencedEntries , newOutputLocation , JavaModelStatus . VERIFIED_OK ) ; } finally { this . writtingRawClasspath = false ; } return true ; } public boolean writeAndCacheClasspath ( JavaProject javaProject , final IClasspathEntry [ ] newRawClasspath , final IPath newOutputLocation ) throws JavaModelException { return writeAndCacheClasspath ( javaProject , newRawClasspath , null , newOutputLocation ) ; } } public static class PerWorkingCopyInfo implements IProblemRequestor { int useCount = 0 ; IProblemRequestor problemRequestor ; CompilationUnit workingCopy ; public PerWorkingCopyInfo ( CompilationUnit workingCopy , IProblemRequestor problemRequestor ) { this . workingCopy = workingCopy ; this . problemRequestor = problemRequestor ; } public void acceptProblem ( IProblem problem ) { IProblemRequestor requestor = getProblemRequestor ( ) ; if ( requestor == null ) return ; requestor . acceptProblem ( problem ) ; } public void beginReporting ( ) { IProblemRequestor requestor = getProblemRequestor ( ) ; if ( requestor == null ) return ; requestor . beginReporting ( ) ; } public void endReporting ( ) { IProblemRequestor requestor = getProblemRequestor ( ) ; if ( requestor == null ) return ; requestor . endReporting ( ) ; } public IProblemRequestor getProblemRequestor ( ) { if ( this . problemRequestor == null && this . workingCopy . owner != null ) { return this . workingCopy . owner . getProblemRequestor ( this . workingCopy ) ; } return this . problemRequestor ; } public ICompilationUnit getWorkingCopy ( ) { return this . workingCopy ; } public boolean isActive ( ) { IProblemRequestor requestor = getProblemRequestor ( ) ; return requestor != null && requestor . isActive ( ) ; } public String toString ( ) { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( "Info for " ) ; buffer . append ( ( ( JavaElement ) this . workingCopy ) . toStringWithAncestors ( ) ) ; buffer . append ( "" ) ; buffer . append ( this . useCount ) ; buffer . append ( "" ) ; buffer . append ( this . problemRequestor ) ; if ( this . problemRequestor == null ) { IProblemRequestor requestor = getProblemRequestor ( ) ; buffer . append ( "" ) ; buffer . append ( requestor ) ; } return buffer . toString ( ) ; } } public static boolean VERBOSE = false ; public static boolean CP_RESOLVE_VERBOSE = false ; public static boolean CP_RESOLVE_VERBOSE_ADVANCED = false ; public static boolean CP_RESOLVE_VERBOSE_FAILURE = false ; public static boolean ZIP_ACCESS_VERBOSE = false ; private ThreadLocal zipFiles = new ThreadLocal ( ) ; private UserLibraryManager userLibraryManager ; private Set nonChainingJars ; private Set invalidArchives ; public static class EclipsePreferencesListener implements IEclipsePreferences . IPreferenceChangeListener { public void preferenceChange ( IEclipsePreferences . PreferenceChangeEvent event ) { String propertyName = event . getKey ( ) ; if ( propertyName . startsWith ( JavaCore . PLUGIN_ID ) ) { if ( propertyName . startsWith ( CP_VARIABLE_PREFERENCES_PREFIX ) ) { String varName = propertyName . substring ( CP_VARIABLE_PREFERENCES_PREFIX . length ( ) ) ; JavaModelManager manager = getJavaModelManager ( ) ; if ( manager . variablesWithInitializer . contains ( varName ) ) { String oldValue = ( String ) event . getOldValue ( ) ; if ( oldValue == null ) { manager . variablesWithInitializer . remove ( varName ) ; } else { manager . getInstancePreferences ( ) . put ( varName , oldValue ) ; } } else { String newValue = ( String ) event . getNewValue ( ) ; IPath newPath ; if ( newValue != null && ! ( newValue = newValue . trim ( ) ) . equals ( CP_ENTRY_IGNORE ) ) { newPath = new Path ( newValue ) ; } else { newPath = null ; } try { SetVariablesOperation operation = new SetVariablesOperation ( new String [ ] { varName } , new IPath [ ] { newPath } , false ) ; operation . runOperation ( null ) ; } catch ( JavaModelException e ) { Util . log ( e , "" + varName + " to " + newPath ) ; } } } else if ( propertyName . startsWith ( CP_CONTAINER_PREFERENCES_PREFIX ) ) { recreatePersistedContainer ( propertyName , ( String ) event . getNewValue ( ) , false ) ; } else if ( propertyName . equals ( JavaCore . CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER ) || propertyName . equals ( JavaCore . CORE_JAVA_BUILD_RESOURCE_COPY_FILTER ) || propertyName . equals ( JavaCore . CORE_JAVA_BUILD_DUPLICATE_RESOURCE ) || propertyName . equals ( JavaCore . CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER ) || propertyName . equals ( JavaCore . CORE_JAVA_BUILD_INVALID_CLASSPATH ) || propertyName . equals ( JavaCore . CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS ) || propertyName . equals ( JavaCore . CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS ) || propertyName . equals ( JavaCore . CORE_INCOMPLETE_CLASSPATH ) || propertyName . equals ( JavaCore . CORE_CIRCULAR_CLASSPATH ) || propertyName . equals ( JavaCore . CORE_INCOMPATIBLE_JDK_LEVEL ) || propertyName . equals ( JavaCore . CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE ) ) { JavaModelManager manager = JavaModelManager . getJavaModelManager ( ) ; IJavaModel model = manager . getJavaModel ( ) ; IJavaProject [ ] projects ; try { projects = model . getJavaProjects ( ) ; for ( int i = 0 , pl = projects . length ; i < pl ; i ++ ) { JavaProject javaProject = ( JavaProject ) projects [ i ] ; manager . deltaState . addClasspathValidation ( javaProject ) ; try { javaProject . getProject ( ) . touch ( null ) ; } catch ( CoreException e ) { } } } catch ( JavaModelException e ) { } } else if ( propertyName . startsWith ( CP_USERLIBRARY_PREFERENCES_PREFIX ) ) { String libName = propertyName . substring ( CP_USERLIBRARY_PREFERENCES_PREFIX . length ( ) ) ; UserLibraryManager manager = JavaModelManager . getUserLibraryManager ( ) ; manager . updateUserLibrary ( libName , ( String ) event . getNewValue ( ) ) ; } } try { IJavaProject [ ] projects = JavaModelManager . getJavaModelManager ( ) . getJavaModel ( ) . getJavaProjects ( ) ; for ( int i = 0 , length = projects . length ; i < length ; i ++ ) { ( ( JavaProject ) projects [ i ] ) . resetCaches ( ) ; } } catch ( JavaModelException e ) { } } } EclipsePreferencesListener instancePreferencesListener = new EclipsePreferencesListener ( ) ; IEclipsePreferences . INodeChangeListener instanceNodeListener = new IEclipsePreferences . INodeChangeListener ( ) { public void added ( IEclipsePreferences . NodeChangeEvent event ) { } public void removed ( IEclipsePreferences . NodeChangeEvent event ) { if ( event . getChild ( ) == JavaModelManager . this . preferencesLookup [ PREF_INSTANCE ] ) { JavaModelManager . this . preferencesLookup [ PREF_INSTANCE ] = InstanceScope . INSTANCE . getNode ( JavaCore . PLUGIN_ID ) ; JavaModelManager . this . preferencesLookup [ PREF_INSTANCE ] . addPreferenceChangeListener ( new EclipsePreferencesListener ( ) ) ; } } } ; IEclipsePreferences . INodeChangeListener defaultNodeListener = new IEclipsePreferences . INodeChangeListener ( ) { public void added ( IEclipsePreferences . NodeChangeEvent event ) { } public void removed ( IEclipsePreferences . NodeChangeEvent event ) { if ( event . getChild ( ) == JavaModelManager . this . preferencesLookup [ PREF_DEFAULT ] ) { JavaModelManager . this . preferencesLookup [ PREF_DEFAULT ] = DefaultScope . INSTANCE . getNode ( JavaCore . PLUGIN_ID ) ; } } } ; IEclipsePreferences . IPreferenceChangeListener propertyListener ; IEclipsePreferences . IPreferenceChangeListener resourcesPropertyListener ; private JavaModelManager ( ) { if ( Platform . isRunning ( ) ) { this . indexManager = new IndexManager ( ) ; this . nonChainingJars = loadClasspathListCache ( NON_CHAINING_JARS_CACHE ) ; this . invalidArchives = loadClasspathListCache ( INVALID_ARCHIVES_CACHE ) ; String includeContainerReferencedLib = System . getProperty ( RESOLVE_REFERENCED_LIBRARIES_FOR_CONTAINERS ) ; this . resolveReferencedLibrariesForContainers = TRUE . equalsIgnoreCase ( includeContainerReferencedLib ) ; } } private void addDeprecatedOptions ( Hashtable 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 ) { if ( this . invalidArchives == null ) { this . invalidArchives = Collections . synchronizedSet ( new HashSet ( ) ) ; } if ( this . invalidArchives != null ) { this . invalidArchives . add ( path ) ; } } public void cacheZipFiles ( Object owner ) { ZipCache zipCache = ( ZipCache ) this . zipFiles . get ( ) ; if ( zipCache != null ) { return ; } this . zipFiles . set ( new ZipCache ( owner ) ) ; } public void closeZipFile ( ZipFile zipFile ) { if ( zipFile == null ) return ; if ( this . zipFiles . get ( ) != null ) { return ; } try { if ( JavaModelManager . ZIP_ACCESS_VERBOSE ) { System . out . println ( "(" + Thread . currentThread ( ) + "" + zipFile . getName ( ) ) ; } zipFile . close ( ) ; } catch ( IOException e ) { } } public void configurePluginDebugOptions ( ) { if ( JavaCore . getPlugin ( ) . isDebugging ( ) ) { String option = Platform . getDebugOption ( BUFFER_MANAGER_DEBUG ) ; if ( option != null ) BufferManager . VERBOSE = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( BUILDER_DEBUG ) ; if ( option != null ) JavaBuilder . DEBUG = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( COMPILER_DEBUG ) ; if ( option != null ) Compiler . DEBUG = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( BUILDER_STATS_DEBUG ) ; if ( option != null ) JavaBuilder . SHOW_STATS = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( COMPLETION_DEBUG ) ; if ( option != null ) CompletionEngine . DEBUG = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( CP_RESOLVE_DEBUG ) ; if ( option != null ) JavaModelManager . CP_RESOLVE_VERBOSE = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( CP_RESOLVE_ADVANCED_DEBUG ) ; if ( option != null ) JavaModelManager . CP_RESOLVE_VERBOSE_ADVANCED = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( CP_RESOLVE_FAILURE_DEBUG ) ; if ( option != null ) JavaModelManager . CP_RESOLVE_VERBOSE_FAILURE = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( DELTA_DEBUG ) ; if ( option != null ) DeltaProcessor . DEBUG = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( DELTA_DEBUG_VERBOSE ) ; if ( option != null ) DeltaProcessor . VERBOSE = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( HIERARCHY_DEBUG ) ; if ( option != null ) TypeHierarchy . DEBUG = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( INDEX_MANAGER_DEBUG ) ; if ( option != null ) JobManager . VERBOSE = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( INDEX_MANAGER_ADVANCED_DEBUG ) ; if ( option != null ) IndexManager . DEBUG = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( JAVAMODEL_DEBUG ) ; if ( option != null ) JavaModelManager . VERBOSE = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( JAVAMODELCACHE_DEBUG ) ; if ( option != null ) JavaModelCache . VERBOSE = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( POST_ACTION_DEBUG ) ; if ( option != null ) JavaModelOperation . POST_ACTION_VERBOSE = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( RESOLUTION_DEBUG ) ; if ( option != null ) NameLookup . VERBOSE = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( SEARCH_DEBUG ) ; if ( option != null ) BasicSearchEngine . VERBOSE = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( SELECTION_DEBUG ) ; if ( option != null ) SelectionEngine . DEBUG = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( ZIP_ACCESS_DEBUG ) ; if ( option != null ) JavaModelManager . ZIP_ACCESS_VERBOSE = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( SOURCE_MAPPER_DEBUG_VERBOSE ) ; if ( option != null ) SourceMapper . VERBOSE = option . equalsIgnoreCase ( TRUE ) ; option = Platform . getDebugOption ( FORMATTER_DEBUG ) ; if ( option != null ) DefaultCodeFormatter . DEBUG = option . equalsIgnoreCase ( TRUE ) ; } if ( PerformanceStats . ENABLED ) { CompletionEngine . PERF = PerformanceStats . isEnabled ( COMPLETION_PERF ) ; SelectionEngine . PERF = PerformanceStats . isEnabled ( SELECTION_PERF ) ; DeltaProcessor . PERF = PerformanceStats . isEnabled ( DELTA_LISTENER_PERF ) ; JavaModelManager . PERF_VARIABLE_INITIALIZER = PerformanceStats . isEnabled ( VARIABLE_INITIALIZER_PERF ) ; JavaModelManager . PERF_CONTAINER_INITIALIZER = PerformanceStats . isEnabled ( CONTAINER_INITIALIZER_PERF ) ; ReconcileWorkingCopyOperation . PERF = PerformanceStats . isEnabled ( RECONCILE_PERF ) ; } } public AbstractAnnotationProcessorManager createAnnotationProcessorManager ( ) { synchronized ( this ) { if ( this . annotationProcessorManagerFactory == null ) { IExtensionPoint extension = Platform . getExtensionRegistry ( ) . getExtensionPoint ( JavaCore . PLUGIN_ID , ANNOTATION_PROCESSOR_MANAGER_EXTPOINT_ID ) ; if ( extension == null ) return null ; IExtension [ ] extensions = extension . getExtensions ( ) ; for ( int i = 0 ; i < extensions . length ; i ++ ) { if ( i > 0 ) { Util . log ( null , "" + extensions [ i ] . getUniqueIdentifier ( ) ) ; break ; } IConfigurationElement [ ] configElements = extensions [ i ] . getConfigurationElements ( ) ; for ( int j = 0 ; j < configElements . length ; j ++ ) { final IConfigurationElement configElement = configElements [ j ] ; if ( "" . equals ( configElement . getName ( ) ) ) { this . annotationProcessorManagerFactory = configElement ; break ; } } } } } if ( this . annotationProcessorManagerFactory == null ) { return null ; } final AbstractAnnotationProcessorManager [ ] apm = new AbstractAnnotationProcessorManager [ 1 ] ; apm [ 0 ] = null ; final IConfigurationElement factory = this . annotationProcessorManagerFactory ; SafeRunner . run ( new ISafeRunnable ( ) { public void handleException ( Throwable exception ) { Util . log ( exception , "" ) ; } public void run ( ) throws Exception { Object executableExtension = factory . createExecutableExtension ( "class" ) ; if ( executableExtension instanceof AbstractAnnotationProcessorManager ) { apm [ 0 ] = ( AbstractAnnotationProcessorManager ) executableExtension ; } } } ) ; return apm [ 0 ] ; } public int discardPerWorkingCopyInfo ( CompilationUnit workingCopy ) throws JavaModelException { JavaElementDeltaBuilder deltaBuilder = null ; if ( workingCopy . isPrimary ( ) && workingCopy . hasUnsavedChanges ( ) ) { deltaBuilder = new JavaElementDeltaBuilder ( workingCopy ) ; } PerWorkingCopyInfo info = null ; synchronized ( this . perWorkingCopyInfos ) { WorkingCopyOwner owner = workingCopy . owner ; Map workingCopyToInfos = ( Map ) this . perWorkingCopyInfos . get ( owner ) ; if ( workingCopyToInfos == null ) return - 1 ; info = ( PerWorkingCopyInfo ) workingCopyToInfos . get ( workingCopy ) ; if ( info == null ) return - 1 ; if ( -- info . useCount == 0 ) { workingCopyToInfos . remove ( workingCopy ) ; if ( workingCopyToInfos . isEmpty ( ) ) { this . perWorkingCopyInfos . remove ( owner ) ; } } } if ( info . useCount == 0 ) { removeInfoAndChildren ( workingCopy ) ; workingCopy . closeBuffer ( ) ; if ( deltaBuilder != null ) { deltaBuilder . buildDeltas ( ) ; if ( deltaBuilder . delta != null ) { getDeltaProcessor ( ) . registerJavaModelDelta ( deltaBuilder . delta ) ; } } } return info . useCount ; } public void doneSaving ( ISaveContext context ) { } public void flushZipFiles ( Object owner ) { ZipCache zipCache = ( ZipCache ) this . zipFiles . get ( ) ; if ( zipCache == null ) { return ; } if ( zipCache . owner == owner ) { this . zipFiles . set ( null ) ; zipCache . flush ( ) ; } } public synchronized boolean forceBatchInitializations ( boolean initAfterLoad ) { switch ( this . batchContainerInitializations ) { case NO_BATCH_INITIALIZATION : this . batchContainerInitializations = NEED_BATCH_INITIALIZATION ; return true ; case BATCH_INITIALIZATION_FINISHED : if ( initAfterLoad ) return false ; this . batchContainerInitializations = NEED_BATCH_INITIALIZATION ; return true ; } return false ; } private synchronized boolean batchContainerInitializations ( ) { switch ( this . batchContainerInitializations ) { case NEED_BATCH_INITIALIZATION : this . batchContainerInitializations = BATCH_INITIALIZATION_IN_PROGRESS ; return true ; case BATCH_INITIALIZATION_IN_PROGRESS : return true ; } return false ; } private synchronized void batchInitializationFinished ( ) { this . batchContainerInitializations = BATCH_INITIALIZATION_FINISHED ; } public IClasspathContainer getClasspathContainer ( final IPath containerPath , final IJavaProject project ) throws JavaModelException { IClasspathContainer container = containerGet ( project , containerPath ) ; if ( container == null ) { if ( batchContainerInitializations ( ) ) { try { container = initializeAllContainers ( project , containerPath ) ; } finally { batchInitializationFinished ( ) ; } } else { container = initializeContainer ( project , containerPath ) ; containerBeingInitializedRemove ( project , containerPath ) ; SetContainerOperation operation = new SetContainerOperation ( containerPath , new IJavaProject [ ] { project } , new IClasspathContainer [ ] { container } ) ; operation . runOperation ( null ) ; } } return container ; } 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 ) return referencedEntries ; List pathToReferencedEntries = new ArrayList ( referencedEntries . length ) ; for ( int index = 0 ; index < referencedEntries . length ; index ++ ) { if ( pathToReferencedEntries . contains ( referencedEntries [ index ] . getPath ( ) ) ) continue ; IClasspathEntry persistedEntry = null ; if ( ( persistedEntry = ( IClasspathEntry ) perProjectInfo . rootPathToResolvedEntries . get ( referencedEntries [ index ] . getPath ( ) ) ) != null ) { referencedEntries [ index ] = persistedEntry ; } pathToReferencedEntries . add ( referencedEntries [ index ] . getPath ( ) ) ; } return referencedEntries ; } public DeltaProcessor getDeltaProcessor ( ) { return this . deltaState . getDeltaProcessor ( ) ; } public static DeltaProcessingState getDeltaState ( ) { return MANAGER . deltaState ; } protected HashSet getElementsOutOfSynchWithBuffers ( ) { return this . elementsOutOfSynchWithBuffers ; } public static ExternalFoldersManager getExternalManager ( ) { return MANAGER . externalFoldersManager ; } public static IndexManager getIndexManager ( ) { return MANAGER . indexManager ; } public synchronized Object getInfo ( IJavaElement element ) { HashMap tempCache = ( HashMap ) this . temporaryCache . get ( ) ; if ( tempCache != null ) { Object result = tempCache . get ( element ) ; if ( result != null ) { return result ; } } return this . cache . getInfo ( element ) ; } public synchronized IJavaElement getExistingElement ( IJavaElement element ) { return this . cache . getExistingElement ( element ) ; } public HashSet getExternalWorkingCopyProjects ( ) { synchronized ( this . perWorkingCopyInfos ) { HashSet result = null ; Iterator values = this . perWorkingCopyInfos . values ( ) . iterator ( ) ; while ( values . hasNext ( ) ) { Map ownerCopies = ( Map ) values . next ( ) ; Iterator workingCopies = ownerCopies . keySet ( ) . iterator ( ) ; while ( workingCopies . hasNext ( ) ) { ICompilationUnit workingCopy = ( ICompilationUnit ) workingCopies . next ( ) ; IJavaProject project = workingCopy . getJavaProject ( ) ; if ( project . getElementName ( ) . equals ( ExternalJavaProject . EXTERNAL_PROJECT_NAME ) ) { if ( result == null ) result = new HashSet ( ) ; result . add ( project ) ; } } } return result ; } } public IEclipsePreferences getInstancePreferences ( ) { return this . preferencesLookup [ PREF_INSTANCE ] ; } public Hashtable getDefaultOptions ( ) { Hashtable defaultOptions = new Hashtable ( 10 ) ; IEclipsePreferences defaultPreferences = getDefaultPreferences ( ) ; Iterator iterator = this . optionNames . iterator ( ) ; while ( iterator . hasNext ( ) ) { String propertyName = ( String ) iterator . next ( ) ; String value = defaultPreferences . get ( propertyName , null ) ; if ( value != null ) defaultOptions . put ( propertyName , value ) ; } defaultOptions . put ( JavaCore . CORE_ENCODING , JavaCore . getEncoding ( ) ) ; addDeprecatedOptions ( defaultOptions ) ; return defaultOptions ; } public IEclipsePreferences getDefaultPreferences ( ) { return this . preferencesLookup [ PREF_DEFAULT ] ; } public final JavaModel getJavaModel ( ) { return this . javaModel ; } public final static JavaModelManager getJavaModelManager ( ) { return MANAGER ; } public Object getLastBuiltState ( IProject project , IProgressMonitor monitor ) { if ( ! JavaProject . hasJavaNature ( project ) ) { if ( JavaBuilder . DEBUG ) System . out . println ( project + "" ) ; return null ; } PerProjectInfo info = getPerProjectInfo ( project , true ) ; if ( ! info . triedRead ) { info . triedRead = true ; try { if ( monitor != null ) monitor . subTask ( Messages . bind ( Messages . build_readStateProgress , project . getName ( ) ) ) ; info . savedState = readState ( project ) ; } catch ( CoreException e ) { e . printStackTrace ( ) ; } } return info . savedState ; } public String getOption ( String optionName ) { if ( JavaCore . CORE_ENCODING . equals ( optionName ) ) { return JavaCore . getEncoding ( ) ; } if ( isDeprecatedOption ( optionName ) ) { return JavaCore . ERROR ; } int optionLevel = getOptionLevel ( optionName ) ; if ( optionLevel != UNKNOWN_OPTION ) { IPreferencesService service = Platform . getPreferencesService ( ) ; String value = service . get ( optionName , null , this . preferencesLookup ) ; if ( value == null && optionLevel == DEPRECATED_OPTION ) { String [ ] compatibleOptions = ( String [ ] ) this . deprecatedOptions . get ( optionName ) ; value = service . get ( compatibleOptions [ 0 ] , null , this . preferencesLookup ) ; } return value == null ? null : value . trim ( ) ; } return null ; } public String getOption ( String optionName , boolean inheritJavaCoreOptions , IEclipsePreferences projectPreferences ) { switch ( getOptionLevel ( optionName ) ) { case VALID_OPTION : String javaCoreDefault = inheritJavaCoreOptions ? JavaCore . getOption ( optionName ) : null ; if ( projectPreferences == null ) return javaCoreDefault ; String value = projectPreferences . get ( optionName , javaCoreDefault ) ; return value == null ? null : value . trim ( ) ; case DEPRECATED_OPTION : String oldValue = projectPreferences . get ( optionName , null ) ; if ( oldValue != null ) { return oldValue . trim ( ) ; } String [ ] compatibleOptions = ( String [ ] ) 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 ( ) ; } return null ; } public boolean knowsOption ( String optionName ) { boolean knownOption = this . optionNames . contains ( optionName ) ; if ( ! knownOption ) { knownOption = this . deprecatedOptions . get ( optionName ) != null ; } return knownOption ; } public int getOptionLevel ( String optionName ) { if ( this . optionNames . contains ( optionName ) ) { return VALID_OPTION ; } if ( this . deprecatedOptions . get ( optionName ) != null ) { return DEPRECATED_OPTION ; } return UNKNOWN_OPTION ; } public Hashtable getOptions ( ) { Hashtable cachedOptions ; if ( ( cachedOptions = this . optionsCache ) != null ) { return new Hashtable ( cachedOptions ) ; } if ( ! Platform . isRunning ( ) ) { this . optionsCache = getDefaultOptionsNoInitialization ( ) ; return new Hashtable ( this . optionsCache ) ; } Hashtable options = new Hashtable ( 10 ) ; IPreferencesService service = Platform . getPreferencesService ( ) ; Iterator iterator = this . optionNames . iterator ( ) ; while ( iterator . hasNext ( ) ) { String propertyName = ( String ) iterator . next ( ) ; String propertyValue = service . get ( propertyName , null , this . preferencesLookup ) ; if ( propertyValue != null ) { options . put ( propertyName , propertyValue ) ; } } Iterator deprecatedEntries = this . deprecatedOptions . entrySet ( ) . iterator ( ) ; while ( deprecatedEntries . hasNext ( ) ) { Entry entry = ( Entry ) deprecatedEntries . next ( ) ; String propertyName = ( String ) entry . getKey ( ) ; String propertyValue = service . get ( propertyName , null , this . preferencesLookup ) ; if ( propertyValue != null ) { options . put ( propertyName , propertyValue ) ; String [ ] compatibleOptions = ( String [ ] ) entry . getValue ( ) ; for ( int co = 0 , length = compatibleOptions . length ; co < length ; co ++ ) { String compatibleOption = compatibleOptions [ co ] ; if ( ! options . containsKey ( compatibleOption ) ) options . put ( compatibleOption , propertyValue ) ; } } } options . put ( JavaCore . CORE_ENCODING , JavaCore . getEncoding ( ) ) ; addDeprecatedOptions ( options ) ; Util . fixTaskTags ( options ) ; this . optionsCache = new Hashtable ( options ) ; return options ; } private Hashtable getDefaultOptionsNoInitialization ( ) { Map defaultOptionsMap = new CompilerOptions ( ) . getMap ( ) ; defaultOptionsMap . put ( JavaCore . COMPILER_LOCAL_VARIABLE_ATTR , JavaCore . GENERATE ) ; defaultOptionsMap . put ( JavaCore . COMPILER_CODEGEN_UNUSED_LOCAL , JavaCore . PRESERVE ) ; defaultOptionsMap . put ( JavaCore . COMPILER_TASK_TAGS , JavaCore . DEFAULT_TASK_TAGS ) ; defaultOptionsMap . put ( JavaCore . COMPILER_TASK_PRIORITIES , JavaCore . DEFAULT_TASK_PRIORITIES ) ; defaultOptionsMap . put ( JavaCore . COMPILER_TASK_CASE_SENSITIVE , JavaCore . ENABLED ) ; defaultOptionsMap . put ( JavaCore . COMPILER_DOC_COMMENT_SUPPORT , JavaCore . ENABLED ) ; defaultOptionsMap . put ( JavaCore . COMPILER_PB_FORBIDDEN_REFERENCE , JavaCore . ERROR ) ; defaultOptionsMap . put ( JavaCore . CORE_JAVA_BUILD_RESOURCE_COPY_FILTER , "" ) ; defaultOptionsMap . put ( JavaCore . CORE_JAVA_BUILD_INVALID_CLASSPATH , JavaCore . ABORT ) ; defaultOptionsMap . put ( JavaCore . CORE_JAVA_BUILD_DUPLICATE_RESOURCE , JavaCore . WARNING ) ; defaultOptionsMap . put ( JavaCore . CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER , JavaCore . CLEAN ) ; 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_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE , JavaCore . WARNING ) ; defaultOptionsMap . put ( JavaCore . CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS , JavaCore . ENABLED ) ; defaultOptionsMap . put ( JavaCore . CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS , JavaCore . ENABLED ) ; defaultOptionsMap . putAll ( DefaultCodeFormatterConstants . getEclipseDefaultSettings ( ) ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_VISIBILITY_CHECK , JavaCore . DISABLED ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_DEPRECATION_CHECK , JavaCore . DISABLED ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_IMPLICIT_QUALIFICATION , JavaCore . DISABLED ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_FIELD_PREFIXES , "" ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_STATIC_FIELD_PREFIXES , "" ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_STATIC_FINAL_FIELD_PREFIXES , "" ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_LOCAL_PREFIXES , "" ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_ARGUMENT_PREFIXES , "" ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_FIELD_SUFFIXES , "" ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_STATIC_FIELD_SUFFIXES , "" ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES , "" ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_LOCAL_SUFFIXES , "" ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_ARGUMENT_SUFFIXES , "" ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_FORBIDDEN_REFERENCE_CHECK , JavaCore . ENABLED ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_DISCOURAGED_REFERENCE_CHECK , JavaCore . DISABLED ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_CAMEL_CASE_MATCH , JavaCore . ENABLED ) ; defaultOptionsMap . put ( JavaCore . CODEASSIST_SUGGEST_STATIC_IMPORTS , JavaCore . ENABLED ) ; defaultOptionsMap . put ( JavaCore . TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC , "50" ) ; return new Hashtable ( defaultOptionsMap ) ; } public PerProjectInfo getPerProjectInfo ( IProject project , boolean create ) { synchronized ( this . perProjectInfos ) { PerProjectInfo info = ( PerProjectInfo ) this . perProjectInfos . get ( project ) ; if ( info == null && create ) { info = new PerProjectInfo ( project ) ; this . perProjectInfos . put ( project , info ) ; } return info ; } } public PerProjectInfo getPerProjectInfoCheckExistence ( IProject project ) throws JavaModelException { JavaModelManager . PerProjectInfo info = getPerProjectInfo ( project , false ) ; if ( info == null ) { if ( ! JavaProject . hasJavaNature ( project ) ) { throw ( ( JavaProject ) JavaCore . create ( project ) ) . newNotPresentException ( ) ; } info = getPerProjectInfo ( project , true ) ; } return info ; } public PerWorkingCopyInfo getPerWorkingCopyInfo ( CompilationUnit workingCopy , boolean create , boolean recordUsage , IProblemRequestor problemRequestor ) { synchronized ( this . perWorkingCopyInfos ) { WorkingCopyOwner owner = workingCopy . owner ; Map workingCopyToInfos = ( Map ) this . perWorkingCopyInfos . get ( owner ) ; if ( workingCopyToInfos == null && create ) { workingCopyToInfos = new HashMap ( ) ; this . perWorkingCopyInfos . put ( owner , workingCopyToInfos ) ; } PerWorkingCopyInfo info = workingCopyToInfos == null ? null : ( PerWorkingCopyInfo ) workingCopyToInfos . get ( workingCopy ) ; if ( info == null && create ) { info = new PerWorkingCopyInfo ( workingCopy , problemRequestor ) ; workingCopyToInfos . put ( workingCopy , info ) ; } if ( info != null && recordUsage ) info . useCount ++ ; return info ; } } public IClasspathContainer getPreviousSessionContainer ( IPath containerPath , IJavaProject project ) { Map previousContainerValues = ( Map ) this . previousSessionContainers . get ( project ) ; if ( previousContainerValues != null ) { IClasspathContainer previousContainer = ( IClasspathContainer ) previousContainerValues . get ( containerPath ) ; if ( previousContainer != null ) { if ( JavaModelManager . CP_RESOLVE_VERBOSE_ADVANCED ) verbose_reentering_project_container_access ( containerPath , project , previousContainer ) ; return previousContainer ; } } return null ; } private void verbose_reentering_project_container_access ( IPath containerPath , IJavaProject project , IClasspathContainer previousContainer ) { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( "" ) ; buffer . append ( "tproject: " + project . getElementName ( ) + '\n' ) ; buffer . append ( "" + containerPath + '\n' ) ; buffer . append ( "" ) ; buffer . append ( previousContainer . getDescription ( ) ) ; buffer . append ( " {n" ) ; IClasspathEntry [ ] entries = previousContainer . getClasspathEntries ( ) ; if ( entries != null ) { for ( int j = 0 ; j < entries . length ; j ++ ) { buffer . append ( " tt" ) ; buffer . append ( entries [ j ] ) ; buffer . append ( '\n' ) ; } } buffer . append ( " t}" ) ; Util . verbose ( buffer . toString ( ) ) ; new Exception ( "" ) . printStackTrace ( System . out ) ; } public IPath getPreviousSessionVariable ( String variableName ) { IPath previousPath = ( IPath ) this . previousSessionVariables . get ( variableName ) ; if ( previousPath != null ) { if ( CP_RESOLVE_VERBOSE_ADVANCED ) verbose_reentering_variable_access ( variableName , previousPath ) ; return previousPath ; } return null ; } private void verbose_reentering_variable_access ( String variableName , IPath previousPath ) { Util . verbose ( "" + "tvariable: " + variableName + '\n' + "" + previousPath ) ; new Exception ( "" ) . printStackTrace ( System . out ) ; } public HashMap getTemporaryCache ( ) { HashMap result = ( HashMap ) this . temporaryCache . get ( ) ; if ( result == null ) { result = new HashMap ( ) ; this . temporaryCache . set ( result ) ; } return result ; } private File getVariableAndContainersFile ( ) { return JavaCore . getPlugin ( ) . getStateLocation ( ) . append ( "" ) . toFile ( ) ; } public static String [ ] getRegisteredVariableNames ( ) { Plugin jdtCorePlugin = JavaCore . getPlugin ( ) ; if ( jdtCorePlugin == null ) return null ; ArrayList variableList = new ArrayList ( 5 ) ; IExtensionPoint extension = Platform . getExtensionRegistry ( ) . getExtensionPoint ( JavaCore . PLUGIN_ID , JavaModelManager . CPVARIABLE_INITIALIZER_EXTPOINT_ID ) ; if ( extension != null ) { IExtension [ ] extensions = extension . getExtensions ( ) ; for ( int i = 0 ; i < extensions . length ; i ++ ) { IConfigurationElement [ ] configElements = extensions [ i ] . getConfigurationElements ( ) ; for ( int j = 0 ; j < configElements . length ; j ++ ) { String varAttribute = configElements [ j ] . getAttribute ( "variable" ) ; if ( varAttribute != null ) variableList . add ( varAttribute ) ; } } } String [ ] variableNames = new String [ variableList . size ( ) ] ; variableList . toArray ( variableNames ) ; return variableNames ; } public static String [ ] getRegisteredContainerIDs ( ) { Plugin jdtCorePlugin = JavaCore . getPlugin ( ) ; if ( jdtCorePlugin == null ) return null ; ArrayList containerIDList = new ArrayList ( 5 ) ; IExtensionPoint extension = Platform . getExtensionRegistry ( ) . getExtensionPoint ( JavaCore . PLUGIN_ID , JavaModelManager . CPCONTAINER_INITIALIZER_EXTPOINT_ID ) ; if ( extension != null ) { IExtension [ ] extensions = extension . getExtensions ( ) ; for ( int i = 0 ; i < extensions . length ; i ++ ) { IConfigurationElement [ ] configElements = extensions [ i ] . getConfigurationElements ( ) ; for ( int j = 0 ; j < configElements . length ; j ++ ) { String idAttribute = configElements [ j ] . getAttribute ( "id" ) ; if ( idAttribute != null ) containerIDList . add ( idAttribute ) ; } } } String [ ] containerIDs = new String [ containerIDList . size ( ) ] ; containerIDList . toArray ( containerIDs ) ; return containerIDs ; } public IClasspathEntry resolveVariableEntry ( IClasspathEntry entry , boolean usePreviousSession ) { if ( entry . getEntryKind ( ) != IClasspathEntry . CPE_VARIABLE ) return entry ; IPath resolvedPath = getResolvedVariablePath ( entry . getPath ( ) , usePreviousSession ) ; if ( resolvedPath == null ) return null ; resolvedPath = ClasspathEntry . resolveDotDot ( null , resolvedPath ) ; Object target = JavaModel . getTarget ( resolvedPath , false ) ; if ( target == null ) return null ; if ( target instanceof IResource ) { IResource resolvedResource = ( IResource ) target ; switch ( resolvedResource . getType ( ) ) { case IResource . PROJECT : return JavaCore . newProjectEntry ( resolvedPath , entry . getAccessRules ( ) , entry . combineAccessRules ( ) , entry . getExtraAttributes ( ) , entry . isExported ( ) ) ; case IResource . FILE : return JavaCore . newLibraryEntry ( resolvedPath , getResolvedVariablePath ( entry . getSourceAttachmentPath ( ) , usePreviousSession ) , getResolvedVariablePath ( entry . getSourceAttachmentRootPath ( ) , usePreviousSession ) , entry . getAccessRules ( ) , entry . getExtraAttributes ( ) , entry . isExported ( ) ) ; case IResource . FOLDER : return JavaCore . newLibraryEntry ( resolvedPath , getResolvedVariablePath ( entry . getSourceAttachmentPath ( ) , usePreviousSession ) , getResolvedVariablePath ( entry . getSourceAttachmentRootPath ( ) , usePreviousSession ) , entry . getAccessRules ( ) , entry . getExtraAttributes ( ) , entry . isExported ( ) ) ; } } if ( target instanceof File ) { File externalFile = JavaModel . getFile ( target ) ; if ( externalFile != null ) { return JavaCore . newLibraryEntry ( resolvedPath , getResolvedVariablePath ( entry . getSourceAttachmentPath ( ) , usePreviousSession ) , getResolvedVariablePath ( entry . getSourceAttachmentRootPath ( ) , usePreviousSession ) , entry . getAccessRules ( ) , entry . getExtraAttributes ( ) , entry . isExported ( ) ) ; } else { if ( resolvedPath . isAbsolute ( ) ) { return JavaCore . newLibraryEntry ( resolvedPath , getResolvedVariablePath ( entry . getSourceAttachmentPath ( ) , usePreviousSession ) , getResolvedVariablePath ( entry . getSourceAttachmentRootPath ( ) , usePreviousSession ) , entry . getAccessRules ( ) , entry . getExtraAttributes ( ) , entry . isExported ( ) ) ; } } } return null ; } public IPath getResolvedVariablePath ( IPath variablePath , boolean usePreviousSession ) { if ( variablePath == null ) return null ; int count = variablePath . segmentCount ( ) ; if ( count == 0 ) return null ; String variableName = variablePath . segment ( 0 ) ; IPath resolvedPath = usePreviousSession ? getPreviousSessionVariable ( variableName ) : JavaCore . getClasspathVariable ( variableName ) ; if ( resolvedPath == null ) return null ; if ( count > 1 ) { resolvedPath = resolvedPath . append ( variablePath . removeFirstSegments ( 1 ) ) ; } return resolvedPath ; } private File getSerializationFile ( IProject project ) { if ( ! project . exists ( ) ) return null ; IPath workingLocation = project . getWorkingLocation ( JavaCore . PLUGIN_ID ) ; return workingLocation . append ( "state.dat" ) . toFile ( ) ; } public static UserLibraryManager getUserLibraryManager ( ) { if ( MANAGER . userLibraryManager == null ) { UserLibraryManager libraryManager = new UserLibraryManager ( ) ; synchronized ( MANAGER ) { if ( MANAGER . userLibraryManager == null ) { MANAGER . userLibraryManager = libraryManager ; } } } return MANAGER . userLibraryManager ; } public ICompilationUnit [ ] getWorkingCopies ( WorkingCopyOwner owner , boolean addPrimary ) { synchronized ( this . perWorkingCopyInfos ) { ICompilationUnit [ ] primaryWCs = addPrimary && owner != DefaultWorkingCopyOwner . PRIMARY ? getWorkingCopies ( DefaultWorkingCopyOwner . PRIMARY , false ) : null ; Map workingCopyToInfos = ( Map ) this . perWorkingCopyInfos . get ( owner ) ; if ( workingCopyToInfos == null ) return primaryWCs ; int primaryLength = primaryWCs == null ? 0 : primaryWCs . length ; int size = workingCopyToInfos . size ( ) ; ICompilationUnit [ ] result = new ICompilationUnit [ primaryLength + size ] ; int index = 0 ; if ( primaryWCs != null ) { for ( int i = 0 ; i < primaryLength ; i ++ ) { ICompilationUnit primaryWorkingCopy = primaryWCs [ i ] ; ICompilationUnit workingCopy = LanguageSupportFactory . newCompilationUnit ( ( PackageFragment ) primaryWorkingCopy . getParent ( ) , primaryWorkingCopy . getElementName ( ) , owner ) ; if ( ! workingCopyToInfos . containsKey ( workingCopy ) ) result [ index ++ ] = primaryWorkingCopy ; } if ( index != primaryLength ) System . arraycopy ( result , 0 , result = new ICompilationUnit [ index + size ] , 0 , index ) ; } Iterator iterator = workingCopyToInfos . values ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { result [ index ++ ] = ( ( JavaModelManager . PerWorkingCopyInfo ) iterator . next ( ) ) . getWorkingCopy ( ) ; } return result ; } } public JavaWorkspaceScope getWorkspaceScope ( ) { if ( this . workspaceScope == null ) { this . workspaceScope = new JavaWorkspaceScope ( ) ; } return this . workspaceScope ; } public void verifyArchiveContent ( IPath path ) throws CoreException { if ( isInvalidArchive ( path ) ) { throw new CoreException ( new Status ( IStatus . ERROR , JavaCore . PLUGIN_ID , - 1 , Messages . status_IOException , new ZipException ( ) ) ) ; } ZipFile file = getZipFile ( path ) ; closeZipFile ( file ) ; } public ZipFile getZipFile ( IPath path ) throws CoreException { if ( isInvalidArchive ( path ) ) throw new CoreException ( new Status ( IStatus . ERROR , JavaCore . PLUGIN_ID , - 1 , Messages . status_IOException , new ZipException ( ) ) ) ; ZipCache zipCache ; ZipFile zipFile ; if ( ( zipCache = ( ZipCache ) this . zipFiles . get ( ) ) != null && ( zipFile = zipCache . getCache ( path ) ) != null ) { return zipFile ; } File localFile = null ; IWorkspaceRoot root = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ; IResource file = root . findMember ( path ) ; if ( file != null ) { URI location ; if ( file . getType ( ) != IResource . FILE || ( location = file . getLocationURI ( ) ) == null ) { throw new CoreException ( new Status ( IStatus . ERROR , JavaCore . PLUGIN_ID , - 1 , Messages . bind ( Messages . file_notFound , path . toString ( ) ) , null ) ) ; } localFile = Util . toLocalFile ( location , null ) ; if ( localFile == null ) throw new CoreException ( new Status ( IStatus . ERROR , JavaCore . PLUGIN_ID , - 1 , Messages . bind ( Messages . file_notFound , path . toString ( ) ) , null ) ) ; } else { localFile = path . toFile ( ) ; } try { if ( ZIP_ACCESS_VERBOSE ) { System . out . println ( "(" + Thread . currentThread ( ) + "" + localFile ) ; } zipFile = new ZipFile ( localFile ) ; if ( zipCache != null ) { zipCache . setCache ( path , zipFile ) ; } return zipFile ; } catch ( IOException e ) { addInvalidArchive ( path ) ; throw new CoreException ( new Status ( IStatus . ERROR , JavaCore . PLUGIN_ID , - 1 , Messages . status_IOException , e ) ) ; } } public boolean hasTemporaryCache ( ) { return this . temporaryCache . get ( ) != null ; } private IClasspathContainer initializeAllContainers ( IJavaProject javaProjectToInit , IPath containerToInit ) throws JavaModelException { if ( CP_RESOLVE_VERBOSE_ADVANCED ) verbose_batching_containers_initialization ( javaProjectToInit , containerToInit ) ; final HashMap 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 ) ; IClasspathEntry [ ] rawClasspath = javaProject . getRawClasspath ( ) ; for ( int j = 0 , length2 = rawClasspath . length ; j < length2 ; j ++ ) { IClasspathEntry entry = rawClasspath [ j ] ; IPath path = entry . getPath ( ) ; if ( entry . getEntryKind ( ) == IClasspathEntry . CPE_CONTAINER && containerGet ( javaProject , path ) == null ) { if ( paths == null ) { paths = new HashSet ( ) ; allContainerPaths . put ( javaProject , paths ) ; } paths . add ( path ) ; } } } if ( javaProjectToInit != null ) { HashSet containerPaths = ( HashSet ) allContainerPaths . get ( javaProjectToInit ) ; if ( containerPaths == null ) { containerPaths = new HashSet ( ) ; allContainerPaths . put ( javaProjectToInit , containerPaths ) ; } containerPaths . add ( containerToInit ) ; } boolean ok = false ; try { IWorkspaceRunnable runnable = new IWorkspaceRunnable ( ) { public void run ( IProgressMonitor monitor ) throws CoreException { try { Set entrySet = allContainerPaths . entrySet ( ) ; int length = entrySet . size ( ) ; if ( monitor != null ) monitor . beginTask ( "" , length ) ; Map . Entry [ ] entries = new Map . Entry [ length ] ; 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 ( ) ; if ( pathSet == null ) continue ; int length2 = pathSet . size ( ) ; IPath [ ] paths = new IPath [ length2 ] ; pathSet . toArray ( paths ) ; for ( int j = 0 ; j < length2 ; j ++ ) { IPath path = paths [ j ] ; initializeContainer ( javaProject , path ) ; IClasspathContainer container = containerBeingInitializedGet ( javaProject , path ) ; if ( container != null ) { containerPut ( javaProject , path , container ) ; } } if ( monitor != null ) monitor . worked ( 1 ) ; } Map perProjectContainers = ( Map ) JavaModelManager . this . containersBeingInitialized . get ( ) ; if ( perProjectContainers != null ) { Iterator 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 ( ) ; while ( containersIterator . hasNext ( ) ) { Map . Entry containerEntry = ( Map . Entry ) containersIterator . next ( ) ; IPath containerPath = ( IPath ) containerEntry . getKey ( ) ; IClasspathContainer container = ( IClasspathContainer ) containerEntry . getValue ( ) ; SetContainerOperation operation = new SetContainerOperation ( containerPath , new IJavaProject [ ] { project } , new IClasspathContainer [ ] { container } ) ; operation . runOperation ( monitor ) ; } } JavaModelManager . this . containersBeingInitialized . set ( null ) ; } } finally { if ( monitor != null ) monitor . done ( ) ; } } } ; IProgressMonitor monitor = this . batchContainerInitializationsProgress ; IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; if ( workspace . isTreeLocked ( ) ) runnable . run ( monitor ) ; else workspace . run ( runnable , null , IWorkspace . AVOID_UPDATE , monitor ) ; ok = true ; } catch ( CoreException e ) { Util . log ( e , "" ) ; } finally { if ( ! ok ) { this . containerInitializationInProgress . set ( null ) ; } } return containerGet ( javaProjectToInit , containerToInit ) ; } private void verbose_batching_containers_initialization ( IJavaProject javaProjectToInit , IPath containerToInit ) { Util . verbose ( "" + "" + ( javaProjectToInit == null ? "null" : javaProjectToInit . getElementName ( ) ) + '\n' + "" + containerToInit ) ; } IClasspathContainer initializeContainer ( IJavaProject project , IPath containerPath ) throws JavaModelException { IProgressMonitor monitor = this . batchContainerInitializationsProgress ; if ( monitor != null && monitor . isCanceled ( ) ) throw new OperationCanceledException ( ) ; IClasspathContainer container = null ; final ClasspathContainerInitializer initializer = JavaCore . getClasspathContainerInitializer ( containerPath . segment ( 0 ) ) ; if ( initializer != null ) { if ( CP_RESOLVE_VERBOSE ) verbose_triggering_container_initialization ( project , containerPath , initializer ) ; if ( CP_RESOLVE_VERBOSE_ADVANCED ) verbose_triggering_container_initialization_invocation_trace ( ) ; PerformanceStats stats = null ; if ( JavaModelManager . PERF_CONTAINER_INITIALIZER ) { stats = PerformanceStats . getStats ( JavaModelManager . CONTAINER_INITIALIZER_PERF , this ) ; stats . startRun ( containerPath + " of " + project . getPath ( ) ) ; } containerPut ( project , containerPath , CONTAINER_INITIALIZATION_IN_PROGRESS ) ; boolean ok = false ; try { if ( monitor != null ) monitor . subTask ( Messages . bind ( Messages . javamodel_configuring , initializer . getDescription ( containerPath , project ) ) ) ; initializer . initialize ( containerPath , project ) ; if ( monitor != null ) monitor . subTask ( "" ) ; container = containerBeingInitializedGet ( project , containerPath ) ; if ( container == null && containerGet ( project , containerPath ) == CONTAINER_INITIALIZATION_IN_PROGRESS ) { container = initializer . getFailureContainer ( containerPath , project ) ; if ( container == null ) { if ( CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE ) verbose_container_null_failure_container ( project , containerPath , initializer ) ; return null ; } if ( CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE ) verbose_container_using_failure_container ( project , containerPath , initializer ) ; containerPut ( project , containerPath , container ) ; } ok = true ; } catch ( CoreException e ) { if ( e instanceof JavaModelException ) { throw ( JavaModelException ) e ; } else { throw new JavaModelException ( e ) ; } } catch ( RuntimeException e ) { if ( JavaModelManager . CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE ) e . printStackTrace ( ) ; throw e ; } catch ( Error e ) { if ( JavaModelManager . CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE ) e . printStackTrace ( ) ; throw e ; } finally { if ( JavaModelManager . PERF_CONTAINER_INITIALIZER ) { stats . endRun ( ) ; } if ( ! ok ) { containerRemoveInitializationInProgress ( project , containerPath ) ; if ( CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE ) verbose_container_initialization_failed ( project , containerPath , container , initializer ) ; } } if ( CP_RESOLVE_VERBOSE_ADVANCED ) verbose_container_value_after_initialization ( project , containerPath , container ) ; } else { container = ( new ClasspathContainerInitializer ( ) { public void initialize ( IPath path , IJavaProject javaProject ) throws CoreException { } } ) . getFailureContainer ( containerPath , project ) ; if ( CP_RESOLVE_VERBOSE_ADVANCED || CP_RESOLVE_VERBOSE_FAILURE ) verbose_no_container_initializer_found ( project , containerPath ) ; } return container ; } private void verbose_no_container_initializer_found ( IJavaProject project , IPath containerPath ) { Util . verbose ( "" + "tproject: " + project . getElementName ( ) + '\n' + "" + containerPath ) ; } private void verbose_container_value_after_initialization ( IJavaProject project , IPath containerPath , IClasspathContainer container ) { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( "" ) ; buffer . append ( "tproject: " + project . getElementName ( ) + '\n' ) ; buffer . append ( "" + containerPath + '\n' ) ; if ( container != null ) { buffer . append ( "tcontainer: " + container . getDescription ( ) + " {n" ) ; IClasspathEntry [ ] entries = container . getClasspathEntries ( ) ; if ( entries != null ) { for ( int i = 0 ; i < entries . length ; i ++ ) { buffer . append ( "tt" + entries [ i ] + '\n' ) ; } } buffer . append ( "t}" ) ; } else { buffer . append ( "" ) ; } Util . verbose ( buffer . toString ( ) ) ; } private void verbose_container_initialization_failed ( IJavaProject project , IPath containerPath , IClasspathContainer container , ClasspathContainerInitializer initializer ) { if ( container == CONTAINER_INITIALIZATION_IN_PROGRESS ) { Util . verbose ( "" + "tproject: " + project . getElementName ( ) + '\n' + "" + containerPath + '\n' + "" + initializer ) ; } else { Util . verbose ( "" + "tproject: " + project . getElementName ( ) + '\n' + "" + containerPath + '\n' + "" + initializer ) ; } } private void verbose_container_null_failure_container ( IJavaProject project , IPath containerPath , ClasspathContainerInitializer initializer ) { Util . verbose ( "" + "tproject: " + project . getElementName ( ) + '\n' + "" + containerPath + '\n' + "" + initializer ) ; } private void verbose_container_using_failure_container ( IJavaProject project , IPath containerPath , ClasspathContainerInitializer initializer ) { Util . verbose ( "" + "tproject: " + project . getElementName ( ) + '\n' + "" + containerPath + '\n' + "" + initializer ) ; } private void verbose_triggering_container_initialization ( IJavaProject project , IPath containerPath , ClasspathContainerInitializer initializer ) { Util . verbose ( "" + "tproject: " + project . getElementName ( ) + '\n' + "" + containerPath + '\n' + "" + initializer ) ; } private void verbose_triggering_container_initialization_invocation_trace ( ) { Util . verbose ( "" + "" ) ; new Exception ( "" ) . printStackTrace ( System . out ) ; } public void initializePreferences ( ) { this . preferencesLookup [ PREF_INSTANCE ] = InstanceScope . INSTANCE . getNode ( JavaCore . PLUGIN_ID ) ; this . preferencesLookup [ PREF_DEFAULT ] = DefaultScope . INSTANCE . getNode ( JavaCore . PLUGIN_ID ) ; this . instanceNodeListener = new IEclipsePreferences . INodeChangeListener ( ) { public void added ( IEclipsePreferences . NodeChangeEvent event ) { } public void removed ( IEclipsePreferences . NodeChangeEvent event ) { if ( event . getChild ( ) == JavaModelManager . this . preferencesLookup [ PREF_INSTANCE ] ) { JavaModelManager . this . preferencesLookup [ PREF_INSTANCE ] = InstanceScope . INSTANCE . getNode ( JavaCore . PLUGIN_ID ) ; JavaModelManager . this . preferencesLookup [ PREF_INSTANCE ] . addPreferenceChangeListener ( new EclipsePreferencesListener ( ) ) ; } } } ; ( ( IEclipsePreferences ) this . preferencesLookup [ PREF_INSTANCE ] . parent ( ) ) . addNodeChangeListener ( this . instanceNodeListener ) ; this . preferencesLookup [ PREF_INSTANCE ] . addPreferenceChangeListener ( this . instancePreferencesListener = new EclipsePreferencesListener ( ) ) ; this . defaultNodeListener = new IEclipsePreferences . INodeChangeListener ( ) { public void added ( IEclipsePreferences . NodeChangeEvent event ) { } public void removed ( IEclipsePreferences . NodeChangeEvent event ) { if ( event . getChild ( ) == JavaModelManager . this . preferencesLookup [ PREF_DEFAULT ] ) { JavaModelManager . this . preferencesLookup [ PREF_DEFAULT ] = DefaultScope . INSTANCE . getNode ( JavaCore . PLUGIN_ID ) ; } } } ; ( ( IEclipsePreferences ) this . preferencesLookup [ PREF_DEFAULT ] . parent ( ) ) . addNodeChangeListener ( this . defaultNodeListener ) ; } public synchronized char [ ] intern ( char [ ] array ) { return this . charArraySymbols . add ( array ) ; } public synchronized String intern ( String s ) { return ( String ) this . stringSymbols . add ( new String ( s ) ) ; } private HashSet getClasspathBeingResolved ( ) { HashSet result = ( HashSet ) this . classpathsBeingResolved . get ( ) ; if ( result == null ) { result = new HashSet ( ) ; this . classpathsBeingResolved . set ( result ) ; } return result ; } public boolean isClasspathBeingResolved ( IJavaProject project ) { return getClasspathBeingResolved ( ) . contains ( project ) ; } private boolean isDeprecatedOption ( String optionName ) { 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 boolean isInvalidArchive ( IPath path ) { return this . invalidArchives != null && this . invalidArchives . contains ( path ) ; } public void setClasspathBeingResolved ( IJavaProject project , boolean classpathIsResolved ) { if ( classpathIsResolved ) { getClasspathBeingResolved ( ) . add ( project ) ; } else { getClasspathBeingResolved ( ) . remove ( project ) ; } } private Set loadClasspathListCache ( String cacheName ) { Set pathCache = new HashSet ( ) ; File cacheFile = getClasspathListFile ( cacheName ) ; DataInputStream in = null ; try { in = new DataInputStream ( new BufferedInputStream ( new FileInputStream ( cacheFile ) ) ) ; int size = in . readInt ( ) ; while ( size -- > 0 ) { String path = in . readUTF ( ) ; pathCache . add ( Path . fromPortableString ( path ) ) ; } } catch ( IOException e ) { if ( cacheFile . exists ( ) ) Util . log ( e , "" ) ; } finally { if ( in != null ) { try { in . close ( ) ; } catch ( IOException e ) { } } } return Collections . synchronizedSet ( pathCache ) ; } private File getClasspathListFile ( String fileName ) { return JavaCore . getPlugin ( ) . getStateLocation ( ) . append ( fileName ) . toFile ( ) ; } private Set getNonChainingJarsCache ( ) throws CoreException { if ( this . nonChainingJars != null && this . nonChainingJars . size ( ) > 0 ) { return this . nonChainingJars ; } Set result = new HashSet ( ) ; IJavaProject [ ] projects = getJavaModel ( ) . getJavaProjects ( ) ; for ( int i = 0 , length = projects . length ; i < length ; i ++ ) { IJavaProject javaProject = projects [ i ] ; IClasspathEntry [ ] classpath = ( ( JavaProject ) javaProject ) . getResolvedClasspath ( ) ; for ( int j = 0 , length2 = classpath . length ; j < length2 ; j ++ ) { IClasspathEntry entry = classpath [ j ] ; IPath path ; if ( entry . getEntryKind ( ) == IClasspathEntry . CPE_LIBRARY && ! result . contains ( path = entry . getPath ( ) ) && ClasspathEntry . resolvedChainedLibraries ( path ) . length == 0 ) { result . add ( path ) ; } } } this . nonChainingJars = Collections . synchronizedSet ( result ) ; return this . nonChainingJars ; } private Set getClasspathListCache ( String cacheName ) throws CoreException { if ( cacheName == NON_CHAINING_JARS_CACHE ) return getNonChainingJarsCache ( ) ; else if ( cacheName == INVALID_ARCHIVES_CACHE ) return this . invalidArchives ; else return null ; } public void loadVariablesAndContainers ( ) throws CoreException { QualifiedName qName = new QualifiedName ( JavaCore . PLUGIN_ID , "variables" ) ; String xmlString = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getPersistentProperty ( qName ) ; try { if ( xmlString != null ) { StringReader reader = new StringReader ( xmlString ) ; Element cpElement ; try { DocumentBuilder parser = DocumentBuilderFactory . newInstance ( ) . newDocumentBuilder ( ) ; cpElement = parser . parse ( new InputSource ( reader ) ) . getDocumentElement ( ) ; } catch ( SAXException e ) { return ; } catch ( ParserConfigurationException e ) { return ; } finally { reader . close ( ) ; } if ( cpElement == null ) return ; if ( ! cpElement . getNodeName ( ) . equalsIgnoreCase ( "variables" ) ) { return ; } NodeList list = cpElement . getChildNodes ( ) ; int length = list . getLength ( ) ; for ( int i = 0 ; i < length ; ++ i ) { Node node = list . item ( i ) ; short type = node . getNodeType ( ) ; if ( type == Node . ELEMENT_NODE ) { Element element = ( Element ) node ; if ( element . getNodeName ( ) . equalsIgnoreCase ( "variable" ) ) { variablePut ( element . getAttribute ( "name" ) , new Path ( element . getAttribute ( "path" ) ) ) ; } } } } } catch ( IOException e ) { } finally { if ( xmlString != null ) { ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . setPersistentProperty ( qName , null ) ; } } loadVariablesAndContainers ( getDefaultPreferences ( ) ) ; loadVariablesAndContainers ( getInstancePreferences ( ) ) ; File file = getVariableAndContainersFile ( ) ; DataInputStream in = null ; try { in = new DataInputStream ( new BufferedInputStream ( new FileInputStream ( file ) ) ) ; switch ( in . readInt ( ) ) { case 2 : new VariablesAndContainersLoadHelper ( in ) . load ( ) ; break ; case 1 : int size = in . readInt ( ) ; while ( size -- > 0 ) { String varName = in . readUTF ( ) ; String pathString = in . readUTF ( ) ; if ( CP_ENTRY_IGNORE . equals ( pathString ) ) continue ; IPath varPath = Path . fromPortableString ( pathString ) ; this . variables . put ( varName , varPath ) ; this . previousSessionVariables . put ( varName , varPath ) ; } IJavaModel model = getJavaModel ( ) ; int projectSize = in . readInt ( ) ; while ( projectSize -- > 0 ) { String projectName = in . readUTF ( ) ; IJavaProject project = model . getJavaProject ( projectName ) ; int containerSize = in . readInt ( ) ; while ( containerSize -- > 0 ) { IPath containerPath = Path . fromPortableString ( in . readUTF ( ) ) ; int length = in . readInt ( ) ; byte [ ] containerString = new byte [ length ] ; in . readFully ( containerString ) ; recreatePersistedContainer ( project , containerPath , new String ( containerString ) , true ) ; } } break ; } } catch ( IOException e ) { if ( file . exists ( ) ) Util . log ( e , "" ) ; } catch ( RuntimeException e ) { if ( file . exists ( ) ) Util . log ( e , "" ) ; } finally { if ( in != null ) { try { in . close ( ) ; } catch ( IOException e ) { } } } String [ ] registeredVariables = getRegisteredVariableNames ( ) ; for ( int i = 0 ; i < registeredVariables . length ; i ++ ) { String varName = registeredVariables [ i ] ; this . variables . put ( varName , null ) ; } containersReset ( getRegisteredContainerIDs ( ) ) ; } private void loadVariablesAndContainers ( IEclipsePreferences preferences ) { try { String [ ] propertyNames = preferences . keys ( ) ; int variablePrefixLength = CP_VARIABLE_PREFERENCES_PREFIX . length ( ) ; for ( int i = 0 ; i < propertyNames . length ; i ++ ) { String propertyName = propertyNames [ i ] ; if ( propertyName . startsWith ( CP_VARIABLE_PREFERENCES_PREFIX ) ) { String varName = propertyName . substring ( variablePrefixLength ) ; String propertyValue = preferences . get ( propertyName , null ) ; if ( propertyValue != null ) { String pathString = propertyValue . trim ( ) ; if ( CP_ENTRY_IGNORE . equals ( pathString ) ) { preferences . remove ( propertyName ) ; continue ; } IPath varPath = new Path ( pathString ) ; this . variables . put ( varName , varPath ) ; this . previousSessionVariables . put ( varName , varPath ) ; } } else if ( propertyName . startsWith ( CP_CONTAINER_PREFERENCES_PREFIX ) ) { String propertyValue = preferences . get ( propertyName , null ) ; if ( propertyValue != null ) { preferences . remove ( propertyName ) ; recreatePersistedContainer ( propertyName , propertyValue , true ) ; } } } } catch ( BackingStoreException e1 ) { } } private static final class PersistedClasspathContainer implements IClasspathContainer { private final IPath containerPath ; private final IClasspathEntry [ ] entries ; private final IJavaProject project ; PersistedClasspathContainer ( IJavaProject project , IPath containerPath , IClasspathEntry [ ] entries ) { super ( ) ; this . containerPath = containerPath ; this . entries = entries ; this . project = project ; } public IClasspathEntry [ ] getClasspathEntries ( ) { return this . entries ; } public String getDescription ( ) { return "" + this . containerPath + "" + this . project . getElementName ( ) + "]]" ; } public int getKind ( ) { return 0 ; } public IPath getPath ( ) { return this . containerPath ; } public String toString ( ) { return getDescription ( ) ; } } private final class VariablesAndContainersLoadHelper { private static final int ARRAY_INCREMENT = 200 ; private IClasspathEntry [ ] allClasspathEntries ; private int allClasspathEntryCount ; private final Map allPaths ; private String [ ] allStrings ; private int allStringsCount ; private final DataInputStream in ; VariablesAndContainersLoadHelper ( DataInputStream in ) { super ( ) ; this . allClasspathEntries = null ; this . allClasspathEntryCount = 0 ; this . allPaths = new HashMap ( ) ; this . allStrings = null ; this . allStringsCount = 0 ; this . in = in ; } void load ( ) throws IOException { loadProjects ( getJavaModel ( ) ) ; loadVariables ( ) ; } private IAccessRule loadAccessRule ( ) throws IOException { int problemId = loadInt ( ) ; IPath pattern = loadPath ( ) ; return new ClasspathAccessRule ( pattern . toString ( ) . toCharArray ( ) , problemId ) ; } private IAccessRule [ ] loadAccessRules ( ) throws IOException { int count = loadInt ( ) ; if ( count == 0 ) return ClasspathEntry . NO_ACCESS_RULES ; IAccessRule [ ] rules = new IAccessRule [ count ] ; for ( int i = 0 ; i < count ; ++ i ) rules [ i ] = loadAccessRule ( ) ; return rules ; } private IClasspathAttribute loadAttribute ( ) throws IOException { String name = loadString ( ) ; String value = loadString ( ) ; return new ClasspathAttribute ( name , value ) ; } private IClasspathAttribute [ ] loadAttributes ( ) throws IOException { int count = loadInt ( ) ; if ( count == 0 ) return ClasspathEntry . NO_EXTRA_ATTRIBUTES ; IClasspathAttribute [ ] attributes = new IClasspathAttribute [ count ] ; for ( int i = 0 ; i < count ; ++ i ) attributes [ i ] = loadAttribute ( ) ; return attributes ; } private boolean loadBoolean ( ) throws IOException { return this . in . readBoolean ( ) ; } private IClasspathEntry [ ] loadClasspathEntries ( ) throws IOException { int count = loadInt ( ) ; IClasspathEntry [ ] entries = new IClasspathEntry [ count ] ; for ( int i = 0 ; i < count ; ++ i ) entries [ i ] = loadClasspathEntry ( ) ; return entries ; } private IClasspathEntry loadClasspathEntry ( ) throws IOException { int id = loadInt ( ) ; if ( id < 0 || id > this . allClasspathEntryCount ) throw new IOException ( "" ) ; if ( id < this . allClasspathEntryCount ) return this . allClasspathEntries [ id ] ; int contentKind = loadInt ( ) ; int entryKind = loadInt ( ) ; IPath path = loadPath ( ) ; IPath [ ] inclusionPatterns = loadPaths ( ) ; IPath [ ] exclusionPatterns = loadPaths ( ) ; IPath sourceAttachmentPath = loadPath ( ) ; IPath sourceAttachmentRootPath = loadPath ( ) ; IPath specificOutputLocation = loadPath ( ) ; boolean isExported = loadBoolean ( ) ; IAccessRule [ ] accessRules = loadAccessRules ( ) ; boolean combineAccessRules = loadBoolean ( ) ; IClasspathAttribute [ ] extraAttributes = loadAttributes ( ) ; IClasspathEntry entry = new ClasspathEntry ( contentKind , entryKind , path , inclusionPatterns , exclusionPatterns , sourceAttachmentPath , sourceAttachmentRootPath , specificOutputLocation , isExported , accessRules , combineAccessRules , extraAttributes ) ; IClasspathEntry [ ] array = this . allClasspathEntries ; if ( array == null || id == array . length ) { array = new IClasspathEntry [ id + ARRAY_INCREMENT ] ; if ( id != 0 ) System . arraycopy ( this . allClasspathEntries , 0 , array , 0 , id ) ; this . allClasspathEntries = array ; } array [ id ] = entry ; this . allClasspathEntryCount = id + 1 ; return entry ; } private void loadContainers ( IJavaProject project ) throws IOException { boolean projectIsAccessible = project . getProject ( ) . isAccessible ( ) ; int count = loadInt ( ) ; for ( int i = 0 ; i < count ; ++ i ) { IPath path = loadPath ( ) ; IClasspathEntry [ ] entries = loadClasspathEntries ( ) ; if ( ! projectIsAccessible ) continue ; IClasspathContainer container = new PersistedClasspathContainer ( project , path , entries ) ; containerPut ( project , path , container ) ; Map oldContainers = ( Map ) JavaModelManager . this . previousSessionContainers . get ( project ) ; if ( oldContainers == null ) { oldContainers = new HashMap ( ) ; JavaModelManager . this . previousSessionContainers . put ( project , oldContainers ) ; } oldContainers . put ( path , container ) ; } } private int loadInt ( ) throws IOException { return this . in . readInt ( ) ; } private IPath loadPath ( ) throws IOException { if ( loadBoolean ( ) ) return null ; String portableString = loadString ( ) ; IPath path = ( IPath ) this . allPaths . get ( portableString ) ; if ( path == null ) { path = Path . fromPortableString ( portableString ) ; this . allPaths . put ( portableString , path ) ; } return path ; } private IPath [ ] loadPaths ( ) throws IOException { int count = loadInt ( ) ; IPath [ ] pathArray = new IPath [ count ] ; for ( int i = 0 ; i < count ; ++ i ) pathArray [ i ] = loadPath ( ) ; return pathArray ; } private void loadProjects ( IJavaModel model ) throws IOException { int count = loadInt ( ) ; for ( int i = 0 ; i < count ; ++ i ) { String projectName = loadString ( ) ; loadContainers ( model . getJavaProject ( projectName ) ) ; } } private String loadString ( ) throws IOException { int id = loadInt ( ) ; if ( id < 0 || id > this . allStringsCount ) throw new IOException ( "" ) ; if ( id < this . allStringsCount ) return this . allStrings [ id ] ; String string = this . in . readUTF ( ) ; String [ ] array = this . allStrings ; if ( array == null || id == array . length ) { array = new String [ id + ARRAY_INCREMENT ] ; if ( id != 0 ) System . arraycopy ( this . allStrings , 0 , array , 0 , id ) ; this . allStrings = array ; } array [ id ] = string ; this . allStringsCount = id + 1 ; return string ; } private void loadVariables ( ) throws IOException { int size = loadInt ( ) ; Map loadedVars = new HashMap ( size ) ; for ( int i = 0 ; i < size ; ++ i ) { String varName = loadString ( ) ; IPath varPath = loadPath ( ) ; if ( varPath != null ) loadedVars . put ( varName , varPath ) ; } JavaModelManager . this . previousSessionVariables . putAll ( loadedVars ) ; JavaModelManager . this . variables . putAll ( loadedVars ) ; } } protected synchronized Object peekAtInfo ( IJavaElement element ) { HashMap tempCache = ( HashMap ) this . temporaryCache . get ( ) ; if ( tempCache != null ) { Object result = tempCache . get ( element ) ; if ( result != null ) { return result ; } } return this . cache . peekAtInfo ( element ) ; } public void prepareToSave ( ISaveContext context ) { } protected synchronized void putInfos ( IJavaElement openedElement , Map newElements ) { Object existingInfo = this . cache . peekAtInfo ( openedElement ) ; if ( openedElement instanceof IParent ) { closeChildren ( existingInfo ) ; } for ( Iterator it = newElements . entrySet ( ) . iterator ( ) ; it . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) it . next ( ) ; IJavaElement element = ( IJavaElement ) entry . getKey ( ) ; if ( element instanceof JarPackageFragmentRoot ) { Object info = entry . getValue ( ) ; it . remove ( ) ; this . cache . putInfo ( element , info ) ; } } Iterator iterator = newElements . entrySet ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) iterator . next ( ) ; this . cache . putInfo ( ( IJavaElement ) entry . getKey ( ) , entry . getValue ( ) ) ; } } private void closeChildren ( Object info ) { if ( info instanceof JavaElementInfo ) { IJavaElement [ ] children = ( ( JavaElementInfo ) info ) . getChildren ( ) ; for ( int i = 0 , size = children . length ; i < size ; ++ i ) { JavaElement child = ( JavaElement ) children [ i ] ; try { child . close ( ) ; } catch ( JavaModelException e ) { } } } } protected synchronized void putJarTypeInfo ( IJavaElement type , Object info ) { this . cache . jarTypeCache . put ( type , info ) ; } protected Object readState ( IProject project ) throws CoreException { File file = getSerializationFile ( project ) ; if ( file != null && file . exists ( ) ) { try { DataInputStream in = new DataInputStream ( new BufferedInputStream ( new FileInputStream ( file ) ) ) ; try { String pluginID = in . readUTF ( ) ; if ( ! pluginID . equals ( JavaCore . PLUGIN_ID ) ) throw new IOException ( Messages . build_wrongFileFormat ) ; String kind = in . readUTF ( ) ; if ( ! kind . equals ( "STATE" ) ) throw new IOException ( Messages . build_wrongFileFormat ) ; if ( in . readBoolean ( ) ) return JavaBuilder . readState ( project , in ) ; if ( JavaBuilder . DEBUG ) System . out . println ( "" + project . getName ( ) ) ; } finally { in . close ( ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; throw new CoreException ( new Status ( IStatus . ERROR , JavaCore . PLUGIN_ID , Platform . PLUGIN_ERROR , "" + project . getName ( ) , e ) ) ; } } else if ( JavaBuilder . DEBUG ) { if ( file == null ) System . out . println ( "" + project ) ; else System . out . println ( "" + file . getPath ( ) + "" ) ; } return null ; } public static void recreatePersistedContainer ( String propertyName , String containerString , boolean addToContainerValues ) { int containerPrefixLength = CP_CONTAINER_PREFERENCES_PREFIX . length ( ) ; int index = propertyName . indexOf ( '|' , containerPrefixLength ) ; if ( containerString != null ) containerString = containerString . trim ( ) ; if ( index > 0 ) { String projectName = propertyName . substring ( containerPrefixLength , index ) . trim ( ) ; IJavaProject project = getJavaModelManager ( ) . getJavaModel ( ) . getJavaProject ( projectName ) ; IPath containerPath = new Path ( propertyName . substring ( index + 1 ) . trim ( ) ) ; recreatePersistedContainer ( project , containerPath , containerString , addToContainerValues ) ; } } private static void recreatePersistedContainer ( final IJavaProject project , final IPath containerPath , String containerString , boolean addToContainerValues ) { if ( ! project . getProject ( ) . isAccessible ( ) ) return ; if ( containerString == null ) { getJavaModelManager ( ) . containerPut ( project , containerPath , null ) ; } else { IClasspathEntry [ ] entries ; try { entries = ( ( JavaProject ) project ) . decodeClasspath ( containerString , null ) [ 0 ] ; } catch ( IOException e ) { Util . log ( e , "" + containerString ) ; entries = JavaProject . INVALID_CLASSPATH ; } if ( entries != JavaProject . INVALID_CLASSPATH ) { final IClasspathEntry [ ] containerEntries = entries ; IClasspathContainer container = new IClasspathContainer ( ) { public IClasspathEntry [ ] getClasspathEntries ( ) { return containerEntries ; } public String getDescription ( ) { return "" + containerPath + "" + project . getElementName ( ) + "]" ; } public int getKind ( ) { return 0 ; } public IPath getPath ( ) { return containerPath ; } public String toString ( ) { return getDescription ( ) ; } } ; if ( addToContainerValues ) { getJavaModelManager ( ) . containerPut ( project , containerPath , container ) ; } Map projectContainers = ( Map ) getJavaModelManager ( ) . previousSessionContainers . get ( project ) ; if ( projectContainers == null ) { projectContainers = new HashMap ( 1 ) ; getJavaModelManager ( ) . previousSessionContainers . put ( project , projectContainers ) ; } projectContainers . put ( containerPath , container ) ; } } } public void rememberScope ( AbstractSearchScope scope ) { this . searchScopes . put ( scope , null ) ; } public synchronized Object removeInfoAndChildren ( JavaElement element ) throws JavaModelException { Object info = this . cache . peekAtInfo ( element ) ; if ( info != null ) { boolean wasVerbose = false ; try { if ( JavaModelCache . VERBOSE ) { String elementType ; switch ( element . getElementType ( ) ) { case IJavaElement . JAVA_PROJECT : elementType = "project" ; break ; case IJavaElement . PACKAGE_FRAGMENT_ROOT : elementType = "root" ; break ; case IJavaElement . PACKAGE_FRAGMENT : elementType = "package" ; break ; case IJavaElement . CLASS_FILE : elementType = "class file" ; break ; case IJavaElement . COMPILATION_UNIT : elementType = "" ; break ; default : elementType = "element" ; } System . out . println ( Thread . currentThread ( ) + " CLOSING " + elementType + " " + element . toStringWithAncestors ( ) ) ; wasVerbose = true ; JavaModelCache . VERBOSE = false ; } element . closing ( info ) ; if ( element instanceof IParent ) { closeChildren ( info ) ; } this . cache . removeInfo ( element ) ; if ( wasVerbose ) { System . out . println ( this . cache . toStringFillingRation ( "-> " ) ) ; } } finally { JavaModelCache . VERBOSE = wasVerbose ; } return info ; } return null ; } public void removePerProjectInfo ( JavaProject javaProject , boolean removeExtJarInfo ) { synchronized ( this . perProjectInfos ) { IProject project = javaProject . getProject ( ) ; PerProjectInfo info = ( PerProjectInfo ) this . perProjectInfos . get ( project ) ; if ( info != null ) { this . perProjectInfos . remove ( project ) ; if ( removeExtJarInfo ) { info . forgetExternalTimestampsAndIndexes ( ) ; } } } resetClasspathListCache ( ) ; } public void resetProjectOptions ( JavaProject javaProject ) { synchronized ( this . perProjectInfos ) { IProject project = javaProject . getProject ( ) ; PerProjectInfo info = ( PerProjectInfo ) this . perProjectInfos . get ( project ) ; if ( info != null ) { info . options = null ; } } } public void resetProjectPreferences ( JavaProject javaProject ) { synchronized ( this . perProjectInfos ) { IProject project = javaProject . getProject ( ) ; PerProjectInfo info = ( PerProjectInfo ) this . perProjectInfos . get ( project ) ; if ( info != null ) { info . preferences = null ; } } } public static final void doNotUse ( ) { MANAGER . deltaState . doNotUse ( ) ; MANAGER = new JavaModelManager ( ) ; } protected synchronized void resetJarTypeCache ( ) { this . cache . resetJarTypeCache ( ) ; } public void resetClasspathListCache ( ) { if ( this . nonChainingJars != null ) this . nonChainingJars . clear ( ) ; if ( this . invalidArchives != null ) this . invalidArchives . clear ( ) ; } public void resetTemporaryCache ( ) { this . temporaryCache . set ( null ) ; } public void rollback ( ISaveContext context ) { } private void saveState ( PerProjectInfo info , ISaveContext context ) throws CoreException { if ( context . getKind ( ) == ISaveContext . SNAPSHOT ) return ; if ( info . triedRead ) saveBuiltState ( info ) ; } private void saveBuiltState ( PerProjectInfo info ) throws CoreException { if ( JavaBuilder . DEBUG ) System . out . println ( Messages . bind ( Messages . build_saveStateProgress , info . project . getName ( ) ) ) ; File file = getSerializationFile ( info . project ) ; if ( file == null ) return ; long t = System . currentTimeMillis ( ) ; try { DataOutputStream out = new DataOutputStream ( new BufferedOutputStream ( new FileOutputStream ( file ) ) ) ; try { out . writeUTF ( JavaCore . PLUGIN_ID ) ; out . writeUTF ( "STATE" ) ; if ( info . savedState == null ) { out . writeBoolean ( false ) ; } else { out . writeBoolean ( true ) ; JavaBuilder . writeState ( info . savedState , out ) ; } } finally { out . close ( ) ; } } catch ( RuntimeException e ) { try { file . delete ( ) ; } catch ( SecurityException se ) { } throw new CoreException ( new Status ( IStatus . ERROR , JavaCore . PLUGIN_ID , Platform . PLUGIN_ERROR , Messages . bind ( Messages . build_cannotSaveState , info . project . getName ( ) ) , e ) ) ; } catch ( IOException e ) { try { file . delete ( ) ; } catch ( SecurityException se ) { } throw new CoreException ( new Status ( IStatus . ERROR , JavaCore . PLUGIN_ID , Platform . PLUGIN_ERROR , Messages . bind ( Messages . build_cannotSaveState , info . project . getName ( ) ) , e ) ) ; } if ( JavaBuilder . DEBUG ) { t = System . currentTimeMillis ( ) - t ; System . out . println ( Messages . bind ( Messages . build_saveStateComplete , String . valueOf ( t ) ) ) ; } } private void saveClasspathListCache ( String cacheName ) throws CoreException { File file = getClasspathListFile ( cacheName ) ; DataOutputStream out = null ; try { out = new DataOutputStream ( new BufferedOutputStream ( new FileOutputStream ( file ) ) ) ; Set pathCache = getClasspathListCache ( cacheName ) ; synchronized ( pathCache ) { out . writeInt ( pathCache . size ( ) ) ; Iterator entries = pathCache . iterator ( ) ; while ( entries . hasNext ( ) ) { IPath path = ( IPath ) entries . next ( ) ; out . writeUTF ( path . toPortableString ( ) ) ; } } } catch ( IOException e ) { IStatus status = new Status ( IStatus . ERROR , JavaCore . PLUGIN_ID , IStatus . ERROR , "" , e ) ; throw new CoreException ( status ) ; } finally { if ( out != null ) { try { out . close ( ) ; } catch ( IOException e ) { } } } } private void saveVariablesAndContainers ( ISaveContext context ) throws CoreException { File file = getVariableAndContainersFile ( ) ; DataOutputStream out = null ; try { out = new DataOutputStream ( new BufferedOutputStream ( new FileOutputStream ( file ) ) ) ; out . writeInt ( VARIABLES_AND_CONTAINERS_FILE_VERSION ) ; new VariablesAndContainersSaveHelper ( out ) . save ( context ) ; } catch ( IOException e ) { IStatus status = new Status ( IStatus . ERROR , JavaCore . PLUGIN_ID , IStatus . ERROR , "" , e ) ; throw new CoreException ( status ) ; } finally { if ( out != null ) { try { out . close ( ) ; } catch ( IOException e ) { } } } } private final class VariablesAndContainersSaveHelper { private final HashtableOfObjectToInt classpathEntryIds ; private final DataOutputStream out ; private final HashtableOfObjectToInt stringIds ; VariablesAndContainersSaveHelper ( DataOutputStream out ) { super ( ) ; this . classpathEntryIds = new HashtableOfObjectToInt ( ) ; this . out = out ; this . stringIds = new HashtableOfObjectToInt ( ) ; } void save ( ISaveContext context ) throws IOException , JavaModelException { saveProjects ( getJavaModel ( ) . getJavaProjects ( ) ) ; HashMap varsToSave = null ; Iterator iterator = JavaModelManager . this . variables . entrySet ( ) . iterator ( ) ; IEclipsePreferences defaultPreferences = getDefaultPreferences ( ) ; while ( iterator . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) iterator . next ( ) ; String varName = ( String ) entry . getKey ( ) ; if ( defaultPreferences . get ( CP_VARIABLE_PREFERENCES_PREFIX + varName , null ) != null || CP_ENTRY_IGNORE_PATH . equals ( entry . getValue ( ) ) ) { if ( varsToSave == null ) varsToSave = new HashMap ( JavaModelManager . this . variables ) ; varsToSave . remove ( varName ) ; } } saveVariables ( varsToSave != null ? varsToSave : JavaModelManager . this . variables ) ; } private void saveAccessRule ( ClasspathAccessRule rule ) throws IOException { saveInt ( rule . problemId ) ; savePath ( rule . getPattern ( ) ) ; } private void saveAccessRules ( IAccessRule [ ] rules ) throws IOException { int count = rules == null ? 0 : rules . length ; saveInt ( count ) ; for ( int i = 0 ; i < count ; ++ i ) saveAccessRule ( ( ClasspathAccessRule ) rules [ i ] ) ; } private void saveAttribute ( IClasspathAttribute attribute ) throws IOException { saveString ( attribute . getName ( ) ) ; saveString ( attribute . getValue ( ) ) ; } private void saveAttributes ( IClasspathAttribute [ ] attributes ) throws IOException { int count = attributes == null ? 0 : attributes . length ; saveInt ( count ) ; for ( int i = 0 ; i < count ; ++ i ) saveAttribute ( attributes [ i ] ) ; } private void saveClasspathEntries ( IClasspathEntry [ ] entries ) throws IOException { int count = entries == null ? 0 : entries . length ; saveInt ( count ) ; for ( int i = 0 ; i < count ; ++ i ) saveClasspathEntry ( entries [ i ] ) ; } private void saveClasspathEntry ( IClasspathEntry entry ) throws IOException { if ( saveNewId ( entry , this . classpathEntryIds ) ) { saveInt ( entry . getContentKind ( ) ) ; saveInt ( entry . getEntryKind ( ) ) ; savePath ( entry . getPath ( ) ) ; savePaths ( entry . getInclusionPatterns ( ) ) ; savePaths ( entry . getExclusionPatterns ( ) ) ; savePath ( entry . getSourceAttachmentPath ( ) ) ; savePath ( entry . getSourceAttachmentRootPath ( ) ) ; savePath ( entry . getOutputLocation ( ) ) ; this . out . writeBoolean ( entry . isExported ( ) ) ; saveAccessRules ( entry . getAccessRules ( ) ) ; this . out . writeBoolean ( entry . combineAccessRules ( ) ) ; saveAttributes ( entry . getExtraAttributes ( ) ) ; } } private void saveContainers ( IJavaProject project , Map 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 ( ) ; IClasspathEntry [ ] cpEntries = null ; if ( container == null ) { container = getPreviousSessionContainer ( path , project ) ; } if ( container != null ) cpEntries = container . getClasspathEntries ( ) ; savePath ( path ) ; saveClasspathEntries ( cpEntries ) ; } } private void saveInt ( int value ) throws IOException { this . out . writeInt ( value ) ; } private boolean saveNewId ( Object key , HashtableOfObjectToInt map ) throws IOException { int id = map . get ( key ) ; if ( id == - 1 ) { int newId = map . size ( ) ; map . put ( key , newId ) ; saveInt ( newId ) ; return true ; } else { saveInt ( id ) ; return false ; } } private void savePath ( IPath path ) throws IOException { if ( path == null ) { this . out . writeBoolean ( true ) ; } else { this . out . writeBoolean ( false ) ; saveString ( path . toPortableString ( ) ) ; } } private void savePaths ( IPath [ ] paths ) throws IOException { int count = paths == null ? 0 : paths . length ; saveInt ( count ) ; for ( int i = 0 ; i < count ; ++ i ) savePath ( paths [ i ] ) ; } private void saveProjects ( IJavaProject [ ] projects ) throws IOException , JavaModelException { int count = projects . length ; saveInt ( count ) ; for ( int i = 0 ; i < count ; ++ i ) { IJavaProject project = projects [ i ] ; saveString ( project . getElementName ( ) ) ; Map containerMap = ( Map ) JavaModelManager . this . containers . get ( project ) ; if ( containerMap == null ) { containerMap = Collections . EMPTY_MAP ; } else { containerMap = new HashMap ( containerMap ) ; } saveContainers ( project , containerMap ) ; } } private void saveString ( String string ) throws IOException { if ( saveNewId ( string , this . stringIds ) ) this . out . writeUTF ( string ) ; } private void saveVariables ( Map 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 ( ) ; saveString ( varName ) ; savePath ( varPath ) ; } } } private void traceVariableAndContainers ( String action , long start ) { Long delta = new Long ( System . currentTimeMillis ( ) - start ) ; Long length = new Long ( getVariableAndContainersFile ( ) . length ( ) ) ; String pattern = "" ; String message = MessageFormat . format ( pattern , new Object [ ] { action , length , delta } ) ; System . out . println ( message ) ; } public void saving ( ISaveContext context ) throws CoreException { long start = - 1 ; if ( VERBOSE ) start = System . currentTimeMillis ( ) ; saveVariablesAndContainers ( context ) ; if ( VERBOSE ) traceVariableAndContainers ( "Saved" , start ) ; switch ( context . getKind ( ) ) { case ISaveContext . FULL_SAVE : { saveClasspathListCache ( NON_CHAINING_JARS_CACHE ) ; saveClasspathListCache ( INVALID_ARCHIVES_CACHE ) ; context . needDelta ( ) ; IndexManager manager = this . indexManager ; if ( manager != null && this . workspaceScope != null ) { manager . cleanUpIndexes ( ) ; } } case ISaveContext . SNAPSHOT : { this . externalFoldersManager . cleanUp ( null ) ; } } IProject savedProject = context . getProject ( ) ; if ( savedProject != null ) { if ( ! JavaProject . hasJavaNature ( savedProject ) ) return ; PerProjectInfo info = getPerProjectInfo ( savedProject , true ) ; saveState ( info , context ) ; return ; } ArrayList vStats = null ; ArrayList values = null ; synchronized ( this . perProjectInfos ) { values = new ArrayList ( this . perProjectInfos . values ( ) ) ; } Iterator iterator = values . iterator ( ) ; while ( iterator . hasNext ( ) ) { try { PerProjectInfo info = ( PerProjectInfo ) iterator . next ( ) ; saveState ( info , context ) ; } catch ( CoreException e ) { if ( vStats == null ) vStats = new ArrayList ( ) ; vStats . add ( e . getStatus ( ) ) ; } } if ( vStats != null ) { IStatus [ ] stats = new IStatus [ vStats . size ( ) ] ; vStats . toArray ( stats ) ; throw new CoreException ( new MultiStatus ( JavaCore . PLUGIN_ID , IStatus . ERROR , stats , Messages . build_cannotSaveStates , null ) ) ; } this . deltaState . saveExternalLibTimeStamps ( ) ; } public void secondaryTypeAdding ( String path , char [ ] typeName , char [ ] packageName ) { if ( VERBOSE ) { StringBuffer buffer = new StringBuffer ( "" ) ; buffer . append ( path ) ; buffer . append ( ',' ) ; buffer . append ( '[' ) ; buffer . append ( new String ( packageName ) ) ; buffer . append ( '.' ) ; buffer . append ( new String ( typeName ) ) ; buffer . append ( ']' ) ; buffer . append ( ')' ) ; Util . verbose ( buffer . toString ( ) ) ; } 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 ) { IProject project = resource . getProject ( ) ; try { PerProjectInfo projectInfo = getPerProjectInfoCheckExistence ( project ) ; HashMap indexedSecondaryTypes = null ; if ( projectInfo . secondaryTypes == null ) { projectInfo . secondaryTypes = new Hashtable ( 3 ) ; indexedSecondaryTypes = new HashMap ( 3 ) ; projectInfo . secondaryTypes . put ( INDEXED_SECONDARY_TYPES , indexedSecondaryTypes ) ; } else { indexedSecondaryTypes = ( HashMap ) projectInfo . secondaryTypes . get ( INDEXED_SECONDARY_TYPES ) ; if ( indexedSecondaryTypes == null ) { indexedSecondaryTypes = new HashMap ( 3 ) ; projectInfo . secondaryTypes . put ( INDEXED_SECONDARY_TYPES , indexedSecondaryTypes ) ; } } HashMap allTypes = ( HashMap ) indexedSecondaryTypes . get ( resource ) ; if ( allTypes == null ) { allTypes = new HashMap ( 3 ) ; indexedSecondaryTypes . put ( resource , allTypes ) ; } ICompilationUnit unit = JavaModelManager . createCompilationUnitFrom ( ( IFile ) resource , null ) ; if ( unit != null ) { String typeString = new String ( typeName ) ; IType type = unit . getType ( typeString ) ; String packageString = type . getPackageFragment ( ) . getElementName ( ) ; HashMap packageTypes = ( HashMap ) allTypes . get ( packageString ) ; if ( packageTypes == null ) { packageTypes = new HashMap ( 3 ) ; allTypes . put ( packageString , packageTypes ) ; } packageTypes . put ( typeString , type ) ; } if ( VERBOSE ) { Util . verbose ( "" ) ; Iterator entries = indexedSecondaryTypes . entrySet ( ) . iterator ( ) ; while ( entries . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; IFile file = ( IFile ) entry . getKey ( ) ; Util . verbose ( "tt+ " + file . getFullPath ( ) + ':' + entry . getValue ( ) ) ; } } } catch ( JavaModelException jme ) { } } } } public Map secondaryTypes ( IJavaProject project , boolean waitForIndexes , IProgressMonitor monitor ) throws JavaModelException { if ( VERBOSE ) { StringBuffer buffer = new StringBuffer ( "" ) ; buffer . append ( project . getElementName ( ) ) ; buffer . append ( ',' ) ; buffer . append ( waitForIndexes ) ; buffer . append ( ')' ) ; Util . verbose ( buffer . toString ( ) ) ; } final PerProjectInfo projectInfo = getPerProjectInfoCheckExistence ( project . getProject ( ) ) ; Map indexingSecondaryCache = projectInfo . secondaryTypes == null ? null : ( Map ) projectInfo . secondaryTypes . get ( INDEXED_SECONDARY_TYPES ) ; if ( projectInfo . secondaryTypes != null && indexingSecondaryCache == null ) { return projectInfo . secondaryTypes ; } if ( projectInfo . secondaryTypes == null ) { return secondaryTypesSearching ( project , waitForIndexes , monitor , projectInfo ) ; } boolean indexing = this . indexManager . awaitingJobsCount ( ) > 0 ; if ( indexing ) { if ( ! waitForIndexes ) { return projectInfo . secondaryTypes ; } while ( this . indexManager . awaitingJobsCount ( ) > 0 ) { if ( monitor != null && monitor . isCanceled ( ) ) { return projectInfo . secondaryTypes ; } try { Thread . sleep ( 10 ) ; } catch ( InterruptedException e ) { return projectInfo . secondaryTypes ; } } } return secondaryTypesMerging ( projectInfo . secondaryTypes ) ; } private Hashtable secondaryTypesMerging ( Hashtable secondaryTypes ) { if ( VERBOSE ) { Util . verbose ( "" ) ; Util . verbose ( "" ) ; Iterator entries = secondaryTypes . entrySet ( ) . iterator ( ) ; while ( entries . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; String packName = ( String ) entry . getKey ( ) ; Util . verbose ( "tt+ " + packName + ':' + entry . getValue ( ) ) ; } } HashMap indexedSecondaryTypes = ( HashMap ) secondaryTypes . remove ( INDEXED_SECONDARY_TYPES ) ; if ( indexedSecondaryTypes == null ) { return secondaryTypes ; } Iterator entries = indexedSecondaryTypes . entrySet ( ) . iterator ( ) ; while ( entries . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; IFile file = ( IFile ) entry . getKey ( ) ; secondaryTypesRemoving ( secondaryTypes , file ) ; HashMap fileSecondaryTypes = ( HashMap ) entry . getValue ( ) ; Iterator 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 ) ; if ( cachedTypes == null ) { secondaryTypes . put ( packageName , entry2 . getValue ( ) ) ; } else { HashMap types = ( HashMap ) entry2 . getValue ( ) ; Iterator entries3 = types . entrySet ( ) . iterator ( ) ; while ( entries3 . hasNext ( ) ) { Map . Entry entry3 = ( Map . Entry ) entries3 . next ( ) ; String typeName = ( String ) entry3 . getKey ( ) ; cachedTypes . put ( typeName , entry3 . getValue ( ) ) ; } } } } if ( VERBOSE ) { Util . verbose ( "" ) ; entries = secondaryTypes . entrySet ( ) . iterator ( ) ; while ( entries . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; String packName = ( String ) entry . getKey ( ) ; Util . verbose ( "tt+ " + packName + ':' + entry . getValue ( ) ) ; } } return secondaryTypes ; } private Map secondaryTypesSearching ( IJavaProject project , boolean waitForIndexes , IProgressMonitor monitor , final PerProjectInfo projectInfo ) throws JavaModelException { if ( VERBOSE || BasicSearchEngine . VERBOSE ) { StringBuffer buffer = new StringBuffer ( "" ) ; buffer . append ( project . getElementName ( ) ) ; buffer . append ( ',' ) ; buffer . append ( waitForIndexes ) ; buffer . append ( ')' ) ; Util . verbose ( buffer . toString ( ) ) ; } final Hashtable secondaryTypes = new Hashtable ( 3 ) ; IRestrictedAccessTypeRequestor nameRequestor = new IRestrictedAccessTypeRequestor ( ) { public void acceptType ( int modifiers , char [ ] packageName , char [ ] simpleTypeName , char [ ] [ ] enclosingTypeNames , String path , AccessRestriction access ) { String key = packageName == null ? "" : new String ( packageName ) ; HashMap types = ( HashMap ) secondaryTypes . get ( key ) ; if ( types == null ) types = new HashMap ( 3 ) ; types . put ( new String ( simpleTypeName ) , path ) ; secondaryTypes . put ( key , types ) ; } } ; IPackageFragmentRoot [ ] allRoots = project . getAllPackageFragmentRoots ( ) ; int length = allRoots . length , size = 0 ; IPackageFragmentRoot [ ] allSourceFolders = new IPackageFragmentRoot [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { if ( allRoots [ i ] . getKind ( ) == IPackageFragmentRoot . K_SOURCE ) { allSourceFolders [ size ++ ] = allRoots [ i ] ; } } if ( size < length ) { System . arraycopy ( allSourceFolders , 0 , allSourceFolders = new IPackageFragmentRoot [ size ] , 0 , size ) ; } new BasicSearchEngine ( ) . searchAllSecondaryTypeNames ( allSourceFolders , nameRequestor , waitForIndexes , monitor ) ; Iterator packages = secondaryTypes . values ( ) . iterator ( ) ; while ( packages . hasNext ( ) ) { HashMap types = ( HashMap ) packages . next ( ) ; 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 ( ) ; 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 ) ; IType type = unit . getType ( typeName ) ; types . put ( typeName , type ) ; } else { names . remove ( ) ; } } } if ( projectInfo . secondaryTypes == null || projectInfo . secondaryTypes . get ( INDEXED_SECONDARY_TYPES ) != null ) { projectInfo . secondaryTypes = secondaryTypes ; if ( VERBOSE || BasicSearchEngine . VERBOSE ) { System . out . print ( Thread . currentThread ( ) + "" ) ; System . out . println ( ) ; Iterator entries = secondaryTypes . entrySet ( ) . iterator ( ) ; while ( entries . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; String qualifiedName = ( String ) entry . getKey ( ) ; Util . verbose ( "tt- " + qualifiedName + '-' + entry . getValue ( ) ) ; } } } return projectInfo . secondaryTypes ; } public void secondaryTypesRemoving ( IFile file , boolean cleanIndexCache ) { if ( VERBOSE ) { StringBuffer buffer = new StringBuffer ( "" ) ; buffer . append ( file . getName ( ) ) ; buffer . append ( ')' ) ; Util . verbose ( buffer . toString ( ) ) ; } if ( file != null ) { PerProjectInfo projectInfo = getPerProjectInfo ( file . getProject ( ) , false ) ; if ( projectInfo != null && projectInfo . secondaryTypes != null ) { if ( VERBOSE ) { Util . verbose ( "" + file . getProject ( ) . getName ( ) ) ; } secondaryTypesRemoving ( projectInfo . secondaryTypes , file ) ; HashMap indexingCache = ( HashMap ) projectInfo . secondaryTypes . get ( INDEXED_SECONDARY_TYPES ) ; if ( ! cleanIndexCache ) { if ( indexingCache == null ) { projectInfo . secondaryTypes . put ( INDEXED_SECONDARY_TYPES , new HashMap ( ) ) ; } return ; } if ( indexingCache != null ) { Set keys = indexingCache . keySet ( ) ; int filesSize = keys . size ( ) , filesCount = 0 ; IFile [ ] removed = null ; Iterator cachedFiles = keys . iterator ( ) ; while ( cachedFiles . hasNext ( ) ) { IFile cachedFile = ( IFile ) cachedFiles . next ( ) ; if ( file . equals ( cachedFile ) ) { if ( removed == null ) removed = new IFile [ filesSize ] ; filesSize -- ; removed [ filesCount ++ ] = cachedFile ; } } if ( removed != null ) { for ( int i = 0 ; i < filesCount ; i ++ ) { indexingCache . remove ( removed [ i ] ) ; } } } } } } private void secondaryTypesRemoving ( Hashtable secondaryTypesMap , IFile file ) { if ( VERBOSE ) { StringBuffer buffer = new StringBuffer ( "" ) ; Iterator entries = secondaryTypesMap . entrySet ( ) . iterator ( ) ; while ( entries . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; String qualifiedName = ( String ) entry . getKey ( ) ; buffer . append ( qualifiedName + ':' + entry . getValue ( ) ) ; } buffer . append ( ',' ) ; buffer . append ( file . getFullPath ( ) ) ; buffer . append ( ')' ) ; Util . verbose ( buffer . toString ( ) ) ; } Set packageEntries = secondaryTypesMap . entrySet ( ) ; int packagesSize = packageEntries . size ( ) , removedPackagesCount = 0 ; String [ ] removedPackages = null ; Iterator packages = packageEntries . iterator ( ) ; while ( packages . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) packages . next ( ) ; String packName = ( String ) entry . getKey ( ) ; if ( packName != INDEXED_SECONDARY_TYPES ) { 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 ] ) ; } } 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 ++ ) { secondaryTypesMap . remove ( removedPackages [ i ] ) ; } } if ( VERBOSE ) { Util . verbose ( "" ) ; Iterator entries = secondaryTypesMap . entrySet ( ) . iterator ( ) ; while ( entries . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) entries . next ( ) ; String qualifiedName = ( String ) entry . getKey ( ) ; Util . verbose ( "tt+ " + qualifiedName + ':' + entry . getValue ( ) ) ; } } } protected void setBuildOrder ( String [ ] javaBuildOrder ) throws JavaModelException { if ( ! JavaCore . COMPUTE . equals ( JavaCore . getOption ( JavaCore . CORE_JAVA_BUILD_ORDER ) ) ) return ; if ( javaBuildOrder == null || javaBuildOrder . length <= 1 ) return ; IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; IWorkspaceDescription description = workspace . getDescription ( ) ; String [ ] wksBuildOrder = description . getBuildOrder ( ) ; String [ ] newOrder ; if ( wksBuildOrder == null ) { newOrder = javaBuildOrder ; } else { int javaCount = javaBuildOrder . length ; HashMap newSet = new HashMap ( javaCount ) ; for ( int i = 0 ; i < javaCount ; i ++ ) { newSet . put ( javaBuildOrder [ i ] , javaBuildOrder [ i ] ) ; } int removed = 0 ; int oldCount = wksBuildOrder . length ; for ( int i = 0 ; i < oldCount ; i ++ ) { if ( newSet . containsKey ( wksBuildOrder [ i ] ) ) { wksBuildOrder [ i ] = null ; removed ++ ; } } newOrder = new String [ oldCount - removed + javaCount ] ; System . arraycopy ( javaBuildOrder , 0 , newOrder , 0 , javaCount ) ; int index = javaCount ; for ( int i = 0 ; i < oldCount ; i ++ ) { if ( wksBuildOrder [ i ] != null ) { newOrder [ index ++ ] = wksBuildOrder [ i ] ; } } } description . setBuildOrder ( newOrder ) ; try { workspace . setDescription ( description ) ; } catch ( CoreException e ) { throw new JavaModelException ( e ) ; } } public void setLastBuiltState ( IProject project , Object state ) { if ( JavaProject . hasJavaNature ( project ) ) { PerProjectInfo info = getPerProjectInfo ( project , true ) ; info . triedRead = true ; info . savedState = state ; } if ( state == null ) { try { File file = getSerializationFile ( project ) ; if ( file != null && file . exists ( ) ) file . delete ( ) ; } catch ( SecurityException se ) { } } } public boolean storePreference ( String optionName , String optionValue , IEclipsePreferences eclipsePreferences ) { int optionLevel = this . getOptionLevel ( optionName ) ; if ( optionLevel == UNKNOWN_OPTION ) return false ; switch ( optionLevel ) { case JavaModelManager . VALID_OPTION : if ( optionValue == null ) { eclipsePreferences . remove ( optionName ) ; } else { eclipsePreferences . put ( optionName , optionValue ) ; } break ; case JavaModelManager . DEPRECATED_OPTION : eclipsePreferences . remove ( optionName ) ; String [ ] compatibleOptions = ( String [ ] ) this . deprecatedOptions . get ( optionName ) ; for ( int co = 0 , length = compatibleOptions . length ; co < length ; co ++ ) { if ( optionValue == null ) { eclipsePreferences . remove ( compatibleOptions [ co ] ) ; } else { eclipsePreferences . put ( compatibleOptions [ co ] , optionValue ) ; } } break ; default : return false ; } return true ; } public void setOptions ( Hashtable newOptions ) { Hashtable cachedValue = newOptions == null ? null : new Hashtable ( newOptions ) ; IEclipsePreferences defaultPreferences = getDefaultPreferences ( ) ; IEclipsePreferences instancePreferences = getInstancePreferences ( ) ; if ( newOptions == null ) { try { instancePreferences . clear ( ) ; } catch ( BackingStoreException e ) { } } else { Enumeration keys = newOptions . keys ( ) ; while ( keys . hasMoreElements ( ) ) { String key = ( String ) keys . nextElement ( ) ; int optionLevel = getOptionLevel ( key ) ; if ( optionLevel == UNKNOWN_OPTION ) continue ; if ( key . equals ( JavaCore . CORE_ENCODING ) ) { if ( cachedValue != null ) { cachedValue . put ( key , JavaCore . getEncoding ( ) ) ; } continue ; } String value = ( String ) newOptions . get ( key ) ; String defaultValue = defaultPreferences . get ( key , null ) ; if ( defaultValue != null && defaultValue . equals ( value ) ) { value = null ; } storePreference ( key , value , instancePreferences ) ; } try { instancePreferences . flush ( ) ; } catch ( BackingStoreException e ) { } } Util . fixTaskTags ( cachedValue ) ; this . optionsCache = cachedValue ; } public void startup ( ) throws CoreException { try { configurePluginDebugOptions ( ) ; this . cache = new JavaModelCache ( ) ; JavaCore . getPlugin ( ) . getStateLocation ( ) ; initializePreferences ( ) ; this . propertyListener = new IEclipsePreferences . IPreferenceChangeListener ( ) { public void preferenceChange ( PreferenceChangeEvent event ) { JavaModelManager . this . optionsCache = null ; } } ; InstanceScope . INSTANCE . getNode ( JavaCore . PLUGIN_ID ) . addPreferenceChangeListener ( this . propertyListener ) ; this . resourcesPropertyListener = new IEclipsePreferences . IPreferenceChangeListener ( ) { public void preferenceChange ( PreferenceChangeEvent event ) { if ( ResourcesPlugin . PREF_ENCODING . equals ( event . getKey ( ) ) ) { JavaModelManager . this . optionsCache = null ; } } } ; String resourcesPluginId = ResourcesPlugin . getPlugin ( ) . getBundle ( ) . getSymbolicName ( ) ; InstanceScope . INSTANCE . getNode ( resourcesPluginId ) . addPreferenceChangeListener ( this . resourcesPropertyListener ) ; Platform . getContentTypeManager ( ) . addContentTypeChangeListener ( this ) ; long start = - 1 ; if ( VERBOSE ) start = System . currentTimeMillis ( ) ; loadVariablesAndContainers ( ) ; if ( VERBOSE ) traceVariableAndContainers ( "Loaded" , start ) ; this . deltaState . initializeRootsWithPreviousSession ( ) ; final IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; workspace . addResourceChangeListener ( this . deltaState , IResourceChangeEvent . PRE_BUILD | IResourceChangeEvent . POST_BUILD | IResourceChangeEvent . POST_CHANGE | IResourceChangeEvent . PRE_DELETE | IResourceChangeEvent . PRE_CLOSE | IResourceChangeEvent . PRE_REFRESH ) ; startIndexing ( ) ; Job processSavedState = new Job ( Messages . savedState_jobName ) { protected IStatus run ( IProgressMonitor monitor ) { try { workspace . run ( new IWorkspaceRunnable ( ) { public void run ( IProgressMonitor progress ) throws CoreException { ISavedState savedState = workspace . addSaveParticipant ( JavaCore . PLUGIN_ID , JavaModelManager . this ) ; if ( savedState != null ) { JavaModelManager . this . deltaState . getDeltaProcessor ( ) . overridenEventType = IResourceChangeEvent . POST_CHANGE ; savedState . processResourceChangeEvents ( JavaModelManager . this . deltaState ) ; } } } , monitor ) ; } catch ( CoreException e ) { return e . getStatus ( ) ; } return Status . OK_STATUS ; } } ; processSavedState . setSystem ( true ) ; processSavedState . setPriority ( Job . SHORT ) ; processSavedState . schedule ( ) ; } catch ( RuntimeException e ) { shutdown ( ) ; throw e ; } } private void startIndexing ( ) { if ( this . indexManager != null ) this . indexManager . reset ( ) ; } public void shutdown ( ) { IEclipsePreferences preferences = InstanceScope . INSTANCE . getNode ( JavaCore . PLUGIN_ID ) ; try { preferences . flush ( ) ; } catch ( BackingStoreException e ) { Util . log ( e , "" ) ; } IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; workspace . removeResourceChangeListener ( this . deltaState ) ; workspace . removeSaveParticipant ( JavaCore . PLUGIN_ID ) ; Platform . getContentTypeManager ( ) . removeContentTypeChangeListener ( this ) ; if ( this . indexManager != null ) { this . indexManager . shutdown ( ) ; } preferences . removePreferenceChangeListener ( this . propertyListener ) ; ( ( IEclipsePreferences ) this . preferencesLookup [ PREF_DEFAULT ] . parent ( ) ) . removeNodeChangeListener ( this . defaultNodeListener ) ; this . preferencesLookup [ PREF_DEFAULT ] = null ; ( ( IEclipsePreferences ) this . preferencesLookup [ PREF_INSTANCE ] . parent ( ) ) . removeNodeChangeListener ( this . instanceNodeListener ) ; this . preferencesLookup [ PREF_INSTANCE ] . removePreferenceChangeListener ( this . instancePreferencesListener ) ; this . preferencesLookup [ PREF_INSTANCE ] = null ; String resourcesPluginId = ResourcesPlugin . getPlugin ( ) . getBundle ( ) . getSymbolicName ( ) ; InstanceScope . INSTANCE . getNode ( resourcesPluginId ) . removePreferenceChangeListener ( this . resourcesPropertyListener ) ; try { Job . getJobManager ( ) . join ( JavaCore . PLUGIN_ID , null ) ; } catch ( InterruptedException e ) { } } public synchronized IPath variableGet ( String variableName ) { HashSet initializations = variableInitializationInProgress ( ) ; if ( initializations . contains ( variableName ) ) { return VARIABLE_INITIALIZATION_IN_PROGRESS ; } return ( IPath ) this . variables . get ( variableName ) ; } private synchronized IPath variableGetDefaultToPreviousSession ( String variableName ) { IPath variablePath = ( IPath ) this . variables . get ( variableName ) ; if ( variablePath == null ) return getPreviousSessionVariable ( variableName ) ; return variablePath ; } private HashSet variableInitializationInProgress ( ) { HashSet initializations = ( HashSet ) this . variableInitializationInProgress . get ( ) ; if ( initializations == null ) { initializations = new HashSet ( ) ; this . variableInitializationInProgress . set ( initializations ) ; } return initializations ; } public synchronized String [ ] variableNames ( ) { int length = this . variables . size ( ) ; String [ ] result = new String [ length ] ; Iterator vars = this . variables . keySet ( ) . iterator ( ) ; int index = 0 ; while ( vars . hasNext ( ) ) { result [ index ++ ] = ( String ) vars . next ( ) ; } return result ; } public synchronized void variablePut ( String variableName , IPath variablePath ) { HashSet initializations = variableInitializationInProgress ( ) ; if ( variablePath == VARIABLE_INITIALIZATION_IN_PROGRESS ) { initializations . add ( variableName ) ; return ; } else { initializations . remove ( variableName ) ; if ( variablePath == null ) { this . variables . put ( variableName , CP_ENTRY_IGNORE_PATH ) ; this . variablesWithInitializer . remove ( variableName ) ; this . deprecatedVariables . remove ( variableName ) ; } else { this . variables . put ( variableName , variablePath ) ; } this . previousSessionVariables . remove ( variableName ) ; } } public void variablePreferencesPut ( String variableName , IPath variablePath ) { String variableKey = CP_VARIABLE_PREFERENCES_PREFIX + variableName ; if ( variablePath == null ) { getInstancePreferences ( ) . remove ( variableKey ) ; } else { getInstancePreferences ( ) . put ( variableKey , variablePath . toString ( ) ) ; } try { getInstancePreferences ( ) . flush ( ) ; } catch ( BackingStoreException e ) { } } public boolean variablePutIfInitializingWithSameValue ( String [ ] variableNames , IPath [ ] variablePaths ) { if ( variableNames . length != 1 ) return false ; String variableName = variableNames [ 0 ] ; IPath oldPath = variableGetDefaultToPreviousSession ( variableName ) ; if ( oldPath == null ) return false ; IPath newPath = variablePaths [ 0 ] ; if ( ! oldPath . equals ( newPath ) ) return false ; variablePut ( variableName , newPath ) ; return true ; } public void contentTypeChanged ( ContentTypeChangeEvent event ) { Util . resetJavaLikeExtensions ( ) ; IJavaProject [ ] projects ; try { projects = JavaModelManager . getJavaModelManager ( ) . getJavaModel ( ) . getJavaProjects ( ) ; } catch ( JavaModelException e ) { return ; } for ( int i = 0 , length = projects . length ; i < length ; i ++ ) { IJavaProject project = projects [ i ] ; final PerProjectInfo projectInfo = getPerProjectInfo ( project . getProject ( ) , false ) ; if ( projectInfo != null ) { projectInfo . secondaryTypes = null ; } } } public synchronized String cacheToString ( String prefix ) { return this . cache . toStringFillingRation ( prefix ) ; } public Stats debugNewOpenableCacheStats ( ) { return this . cache . openableCache . new Stats ( ) ; } public int getOpenableCacheSize ( ) { return this . cache . openableCache . getSpaceLimit ( ) ; } } </s>