<s> package org . eclipse . jdt . internal . core ; import java . util . HashMap ; import java . util . Map ; import org . eclipse . core . resources . IContainer ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; import org . eclipse . jdt . core . * ; import org . eclipse . jdt . internal . core . util . HashSetOfArray ; import org . eclipse . jdt . internal . core . util . Util ; import org . eclipse . jdt . internal . core . util . HashtableOfArrayToObject ; class JavaProjectElementInfo extends OpenableElementInfo { static final IPackageFragmentRoot [ ] NO_ROOTS = new IPackageFragmentRoot [ 0 ] ; static class ProjectCache { ProjectCache ( IPackageFragmentRoot [ ] allPkgFragmentRootsCache , Map rootToResolvedEntries , Map pkgFragmentsCaches ) { this . allPkgFragmentRootsCache = allPkgFragmentRootsCache ; this . rootToResolvedEntries = rootToResolvedEntries ; this . pkgFragmentsCaches = pkgFragmentsCaches ; } public IPackageFragmentRoot [ ] allPkgFragmentRootsCache ; public HashtableOfArrayToObject allPkgFragmentsCache ; public Map pkgFragmentsCaches ; public Map rootToResolvedEntries ; } private Object [ ] nonJavaResources ; ProjectCache projectCache ; static void addSuperPackageNames ( String [ ] pkgName , HashtableOfArrayToObject packageFragments ) { for ( int i = pkgName . length - 1 ; i > 0 ; i -- ) { if ( packageFragments . getKey ( pkgName , i ) == null ) { System . arraycopy ( pkgName , 0 , pkgName = new String [ i ] , 0 , i ) ; packageFragments . put ( pkgName , NO_ROOTS ) ; } } } public JavaProjectElementInfo ( ) { this . nonJavaResources = null ; } private Object [ ] computeNonJavaResources ( JavaProject project ) { IPath projectPath = project . getProject ( ) . getFullPath ( ) ; boolean srcIsProject = false ; boolean binIsProject = false ; char [ ] [ ] inclusionPatterns = null ; char [ ] [ ] exclusionPatterns = null ; IPath projectOutput = null ; boolean isClasspathResolved = true ; try { IClasspathEntry entry = project . getClasspathEntryFor ( projectPath ) ; if ( entry != null ) { srcIsProject = true ; inclusionPatterns = ( ( ClasspathEntry ) entry ) . fullInclusionPatternChars ( ) ; exclusionPatterns = ( ( ClasspathEntry ) entry ) . fullExclusionPatternChars ( ) ; } projectOutput = project . getOutputLocation ( ) ; binIsProject = projectPath . equals ( projectOutput ) ; } catch ( JavaModelException e ) { isClasspathResolved = false ; } Object [ ] resources = new IResource [ 5 ] ; int resourcesCounter = 0 ; try { IResource [ ] members = ( ( IContainer ) project . getResource ( ) ) . members ( ) ; int length = members . length ; if ( length > 0 ) { String sourceLevel = project . getOption ( JavaCore . COMPILER_SOURCE , true ) ; String complianceLevel = project . getOption ( JavaCore . COMPILER_COMPLIANCE , true ) ; IClasspathEntry [ ] classpath = project . getResolvedClasspath ( ) ; for ( int i = 0 ; i < length ; i ++ ) { IResource res = members [ i ] ; switch ( res . getType ( ) ) { case IResource . FILE : IPath resFullPath = res . getFullPath ( ) ; String resName = res . getName ( ) ; if ( isClasspathResolved && isClasspathEntryOrOutputLocation ( resFullPath , res . getLocation ( ) , classpath , projectOutput ) ) { break ; } if ( srcIsProject && Util . isValidCompilationUnitName ( resName , sourceLevel , complianceLevel ) && ! Util . isExcluded ( res , inclusionPatterns , exclusionPatterns ) ) { break ; } if ( binIsProject && Util . isValidClassFileName ( resName , sourceLevel , complianceLevel ) ) { break ; } if ( resources . length == resourcesCounter ) { System . arraycopy ( resources , 0 , ( resources = new IResource [ resourcesCounter * 2 ] ) , 0 , resourcesCounter ) ; } resources [ resourcesCounter ++ ] = res ; break ; case IResource . FOLDER : resFullPath = res . getFullPath ( ) ; if ( ( srcIsProject && ! Util . isExcluded ( res , inclusionPatterns , exclusionPatterns ) && Util . isValidFolderNameForPackage ( res . getName ( ) , sourceLevel , complianceLevel ) ) || ( isClasspathResolved && isClasspathEntryOrOutputLocation ( resFullPath , res . getLocation ( ) , classpath , projectOutput ) ) ) { break ; } if ( resources . length == resourcesCounter ) { System . arraycopy ( resources , 0 , ( resources = new IResource [ resourcesCounter * 2 ] ) , 0 , resourcesCounter ) ; } resources [ resourcesCounter ++ ] = res ; } } } if ( resources . length != resourcesCounter ) { System . arraycopy ( resources , 0 , ( resources = new IResource [ resourcesCounter ] ) , 0 , resourcesCounter ) ; } } catch ( CoreException e ) { resources = NO_NON_JAVA_RESOURCES ; resourcesCounter = 0 ; } return resources ; } ProjectCache getProjectCache ( JavaProject project ) { ProjectCache cache = this . projectCache ; if ( cache == null ) { IPackageFragmentRoot [ ] roots ; Map reverseMap = new HashMap ( 3 ) ; try { roots = project . getAllPackageFragmentRoots ( reverseMap ) ; } catch ( JavaModelException e ) { roots = new IPackageFragmentRoot [ 0 ] ; reverseMap . clear ( ) ; } HashMap rootInfos = JavaModelManager . getJavaModelManager ( ) . deltaState . roots ; HashMap pkgFragmentsCaches = new HashMap ( ) ; int length = roots . length ; JavaModelManager manager = JavaModelManager . getJavaModelManager ( ) ; for ( int i = 0 ; i < length ; i ++ ) { IPackageFragmentRoot root = roots [ i ] ; DeltaProcessor . RootInfo rootInfo = ( DeltaProcessor . RootInfo ) rootInfos . get ( root . getPath ( ) ) ; if ( rootInfo == null || rootInfo . project . equals ( project ) ) { roots [ i ] = root = ( IPackageFragmentRoot ) manager . getExistingElement ( root ) ; HashSetOfArray fragmentsCache = new HashSetOfArray ( ) ; initializePackageNames ( root , fragmentsCache ) ; pkgFragmentsCaches . put ( root , fragmentsCache ) ; } } cache = new ProjectCache ( roots , reverseMap , pkgFragmentsCaches ) ; this . projectCache = cache ; } return cache ; } Object [ ] getNonJavaResources ( JavaProject project ) { if ( this . nonJavaResources == null ) { this . nonJavaResources = computeNonJavaResources ( project ) ; } return this . nonJavaResources ; } private void initializePackageNames ( IPackageFragmentRoot root , HashSetOfArray fragmentsCache ) { IJavaElement [ ] frags = null ; try { if ( ! root . isOpen ( ) ) { PackageFragmentRootInfo info = root . isArchive ( ) ? new JarPackageFragmentRootInfo ( ) : new PackageFragmentRootInfo ( ) ; ( ( PackageFragmentRoot ) root ) . computeChildren ( info , ( ( JavaElement ) root ) . resource ( ) ) ; frags = info . children ; } else frags = root . getChildren ( ) ; } catch ( JavaModelException e ) { return ; } for ( int j = 0 , length = frags . length ; j < length ; j ++ ) { fragmentsCache . add ( ( ( PackageFragment ) frags [ j ] ) . names ) ; } } private boolean isClasspathEntryOrOutputLocation ( IPath path , IPath location , IClasspathEntry [ ] resolvedClasspath , IPath projectOutput ) { if ( projectOutput . equals ( path ) ) return true ; for ( int i = 0 , length = resolvedClasspath . length ; i < length ; i ++ ) { IClasspathEntry entry = resolvedClasspath [ i ] ; IPath entryPath ; if ( ( entryPath = entry . getPath ( ) ) . equals ( path ) || entryPath . equals ( location ) ) { return true ; } IPath output ; if ( ( output = entry . getOutputLocation ( ) ) != null && output . equals ( path ) ) { return true ; } } return false ; } NameLookup newNameLookup ( JavaProject project , ICompilationUnit [ ] workingCopies ) { ProjectCache cache = getProjectCache ( project ) ; HashtableOfArrayToObject allPkgFragmentsCache = cache . allPkgFragmentsCache ; if ( allPkgFragmentsCache == null ) { HashMap rootInfos = JavaModelManager . getJavaModelManager ( ) . deltaState . roots ; IPackageFragmentRoot [ ] allRoots = cache . allPkgFragmentRootsCache ; int length = allRoots . length ; allPkgFragmentsCache = new HashtableOfArrayToObject ( ) ; for ( int i = 0 ; i < length ; i ++ ) { IPackageFragmentRoot root = allRoots [ i ] ; DeltaProcessor . RootInfo rootInfo = ( DeltaProcessor . RootInfo ) rootInfos . get ( root . getPath ( ) ) ; JavaProject rootProject = rootInfo == null ? project : rootInfo . project ; HashSetOfArray fragmentsCache ; if ( rootProject . equals ( project ) ) { fragmentsCache = ( HashSetOfArray ) cache . pkgFragmentsCaches . get ( root ) ; } else { ProjectCache rootProjectCache ; try { rootProjectCache = rootProject . getProjectCache ( ) ; } catch ( JavaModelException e ) { continue ; } fragmentsCache = ( HashSetOfArray ) rootProjectCache . pkgFragmentsCaches . get ( root ) ; } if ( fragmentsCache == null ) { fragmentsCache = new HashSetOfArray ( ) ; initializePackageNames ( root , fragmentsCache ) ; } Object [ ] [ ] set = fragmentsCache . set ; for ( int j = 0 , length2 = set . length ; j < length2 ; j ++ ) { String [ ] pkgName = ( String [ ] ) set [ j ] ; if ( pkgName == null ) continue ; Object existing = allPkgFragmentsCache . get ( pkgName ) ; if ( existing == null || existing == NO_ROOTS ) { allPkgFragmentsCache . put ( pkgName , root ) ; addSuperPackageNames ( pkgName , allPkgFragmentsCache ) ; } else { if ( existing instanceof PackageFragmentRoot ) { allPkgFragmentsCache . put ( pkgName , new IPackageFragmentRoot [ ] { ( PackageFragmentRoot ) existing , root } ) ; } else { IPackageFragmentRoot [ ] roots = ( IPackageFragmentRoot [ ] ) existing ; int rootLength = roots . length ; System . arraycopy ( roots , 0 , roots = new IPackageFragmentRoot [ rootLength + 1 ] , 0 , rootLength ) ; roots [ rootLength ] = root ; allPkgFragmentsCache . put ( pkgName , roots ) ; } } } } cache . allPkgFragmentsCache = allPkgFragmentsCache ; } return new NameLookup ( cache . allPkgFragmentRootsCache , cache . allPkgFragmentsCache , workingCopies , cache . rootToResolvedEntries ) ; } void resetCaches ( ) { this . projectCache = null ; } void setNonJavaResources ( Object [ ] resources ) { this . nonJavaResources = resources ; } } </s>