<s> package org . eclipse . jdt . internal . core . hierarchy ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Iterator ; import java . util . Map ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . SubProgressMonitor ; import org . eclipse . jdt . core . IClassFile ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaProject ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . internal . core . JavaModelManager ; import org . eclipse . jdt . internal . core . JavaProject ; import org . eclipse . jdt . internal . core . Openable ; import org . eclipse . jdt . internal . core . SearchableEnvironment ; public class RegionBasedHierarchyBuilder extends HierarchyBuilder { public RegionBasedHierarchyBuilder ( TypeHierarchy hierarchy ) throws JavaModelException { super ( hierarchy ) ; } public void build ( boolean computeSubtypes ) { JavaModelManager manager = JavaModelManager . getJavaModelManager ( ) ; try { manager . cacheZipFiles ( this ) ; if ( this . hierarchy . focusType == null || computeSubtypes ) { IProgressMonitor typeInRegionMonitor = this . hierarchy . progressMonitor == null ? null : new SubProgressMonitor ( this . hierarchy . progressMonitor , 30 ) ; HashMap allOpenablesInRegion = determineOpenablesInRegion ( typeInRegionMonitor ) ; this . hierarchy . initialize ( allOpenablesInRegion . size ( ) ) ; IProgressMonitor buildMonitor = this . hierarchy . progressMonitor == null ? null : new SubProgressMonitor ( this . hierarchy . progressMonitor , 70 ) ; createTypeHierarchyBasedOnRegion ( allOpenablesInRegion , buildMonitor ) ; ( ( RegionBasedTypeHierarchy ) this . hierarchy ) . pruneDeadBranches ( ) ; } else { this . hierarchy . initialize ( 1 ) ; buildSupertypes ( ) ; } } finally { manager . flushZipFiles ( this ) ; } } private void createTypeHierarchyBasedOnRegion ( HashMap allOpenablesInRegion , IProgressMonitor monitor ) { try { int size = allOpenablesInRegion . size ( ) ; if ( monitor != null ) monitor . beginTask ( "" , size * 2 ) ; this . infoToHandle = new HashMap ( size ) ; Iterator javaProjects = allOpenablesInRegion . entrySet ( ) . iterator ( ) ; while ( javaProjects . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) javaProjects . next ( ) ; JavaProject project = ( JavaProject ) entry . getKey ( ) ; ArrayList allOpenables = ( ArrayList ) entry . getValue ( ) ; Openable [ ] openables = new Openable [ allOpenables . size ( ) ] ; allOpenables . toArray ( openables ) ; try { SearchableEnvironment searchableEnvironment = project . newSearchableNameEnvironment ( this . hierarchy . workingCopies ) ; this . nameLookup = searchableEnvironment . nameLookup ; this . hierarchyResolver . resolve ( openables , null , monitor ) ; } catch ( JavaModelException e ) { } } } finally { if ( monitor != null ) monitor . done ( ) ; } } private HashMap determineOpenablesInRegion ( IProgressMonitor monitor ) { try { HashMap allOpenables = new HashMap ( ) ; IJavaElement [ ] roots = ( ( RegionBasedTypeHierarchy ) this . hierarchy ) . region . getElements ( ) ; int length = roots . length ; if ( monitor != null ) monitor . beginTask ( "" , length ) ; for ( int i = 0 ; i < length ; i ++ ) { IJavaElement root = roots [ i ] ; IJavaProject javaProject = root . getJavaProject ( ) ; ArrayList openables = ( ArrayList ) allOpenables . get ( javaProject ) ; if ( openables == null ) { openables = new ArrayList ( ) ; allOpenables . put ( javaProject , openables ) ; } switch ( root . getElementType ( ) ) { case IJavaElement . JAVA_PROJECT : injectAllOpenablesForJavaProject ( ( IJavaProject ) root , openables ) ; break ; case IJavaElement . PACKAGE_FRAGMENT_ROOT : injectAllOpenablesForPackageFragmentRoot ( ( IPackageFragmentRoot ) root , openables ) ; break ; case IJavaElement . PACKAGE_FRAGMENT : injectAllOpenablesForPackageFragment ( ( IPackageFragment ) root , openables ) ; break ; case IJavaElement . CLASS_FILE : case IJavaElement . COMPILATION_UNIT : openables . add ( root ) ; break ; case IJavaElement . TYPE : IType type = ( IType ) root ; if ( type . isBinary ( ) ) { openables . add ( type . getClassFile ( ) ) ; } else { openables . add ( type . getCompilationUnit ( ) ) ; } break ; default : break ; } worked ( monitor , 1 ) ; } return allOpenables ; } finally { if ( monitor != null ) monitor . done ( ) ; } } private void injectAllOpenablesForJavaProject ( IJavaProject project , ArrayList openables ) { try { IPackageFragmentRoot [ ] devPathRoots = ( ( JavaProject ) project ) . getPackageFragmentRoots ( ) ; if ( devPathRoots == null ) { return ; } for ( int j = 0 ; j < devPathRoots . length ; j ++ ) { IPackageFragmentRoot root = devPathRoots [ j ] ; injectAllOpenablesForPackageFragmentRoot ( root , openables ) ; } } catch ( JavaModelException e ) { } } private void injectAllOpenablesForPackageFragment ( IPackageFragment packFrag , ArrayList openables ) { try { IPackageFragmentRoot root = ( IPackageFragmentRoot ) packFrag . getParent ( ) ; int kind = root . getKind ( ) ; if ( kind != 0 ) { boolean isSourcePackageFragment = ( kind == IPackageFragmentRoot . K_SOURCE ) ; if ( isSourcePackageFragment ) { ICompilationUnit [ ] cus = packFrag . getCompilationUnits ( ) ; for ( int i = 0 , length = cus . length ; i < length ; i ++ ) { openables . add ( cus [ i ] ) ; } } else { IClassFile [ ] classFiles = packFrag . getClassFiles ( ) ; for ( int i = 0 , length = classFiles . length ; i < length ; i ++ ) { openables . add ( classFiles [ i ] ) ; } } } } catch ( JavaModelException e ) { } } private void injectAllOpenablesForPackageFragmentRoot ( IPackageFragmentRoot root , ArrayList openables ) { try { IJavaElement [ ] packFrags = root . getChildren ( ) ; for ( int k = 0 ; k < packFrags . length ; k ++ ) { IPackageFragment packFrag = ( IPackageFragment ) packFrags [ k ] ; injectAllOpenablesForPackageFragment ( packFrag , openables ) ; } } catch ( JavaModelException e ) { return ; } } } </s>