<s> package org . eclipse . jdt . internal . core . hierarchy ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import org . codehaus . jdt . groovy . integration . LanguageSupportFactory ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . OperationCanceledException ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . compiler . CompilationResult ; import org . eclipse . jdt . internal . compiler . DefaultErrorHandlingPolicies ; import org . eclipse . jdt . internal . compiler . IErrorHandlingPolicy ; import org . eclipse . jdt . internal . compiler . IProblemFactory ; import org . eclipse . jdt . internal . compiler . ast . ASTNode ; import org . eclipse . jdt . internal . compiler . ast . CompilationUnitDeclaration ; import org . eclipse . jdt . internal . compiler . ast . QualifiedAllocationExpression ; import org . eclipse . jdt . internal . compiler . ast . TypeDeclaration ; import org . eclipse . jdt . internal . compiler . ast . TypeReference ; import org . eclipse . jdt . internal . compiler . env . AccessRestriction ; import org . eclipse . jdt . internal . compiler . env . IBinaryType ; import org . eclipse . jdt . internal . compiler . env . ICompilationUnit ; import org . eclipse . jdt . internal . compiler . env . IGenericType ; import org . eclipse . jdt . internal . compiler . env . INameEnvironment ; import org . eclipse . jdt . internal . compiler . env . ISourceType ; import org . eclipse . jdt . internal . compiler . impl . CompilerOptions ; import org . eclipse . jdt . internal . compiler . impl . ITypeRequestor ; import org . eclipse . jdt . internal . compiler . lookup . BinaryTypeBinding ; import org . eclipse . jdt . internal . compiler . lookup . ClassScope ; import org . eclipse . jdt . internal . compiler . lookup . LocalTypeBinding ; import org . eclipse . jdt . internal . compiler . lookup . LookupEnvironment ; import org . eclipse . jdt . internal . compiler . lookup . PackageBinding ; import org . eclipse . jdt . internal . compiler . lookup . ProblemReasons ; import org . eclipse . jdt . internal . compiler . lookup . ReferenceBinding ; import org . eclipse . jdt . internal . compiler . lookup . SourceTypeBinding ; import org . eclipse . jdt . internal . compiler . lookup . TagBits ; import org . eclipse . jdt . internal . compiler . lookup . TypeBinding ; import org . eclipse . jdt . internal . compiler . lookup . TypeConstants ; import org . eclipse . jdt . internal . compiler . lookup . TypeIds ; import org . eclipse . jdt . internal . compiler . parser . Parser ; import org . eclipse . jdt . internal . compiler . parser . SourceTypeConverter ; import org . eclipse . jdt . internal . compiler . problem . AbortCompilation ; import org . eclipse . jdt . internal . compiler . problem . DefaultProblemFactory ; import org . eclipse . jdt . internal . compiler . problem . ProblemReporter ; import org . eclipse . jdt . internal . compiler . util . Messages ; import org . eclipse . jdt . internal . core . ClassFile ; import org . eclipse . jdt . internal . core . CompilationUnit ; import org . eclipse . jdt . internal . core . JavaElement ; import org . eclipse . jdt . internal . core . JavaModelManager ; import org . eclipse . jdt . internal . core . Member ; import org . eclipse . jdt . internal . core . Openable ; import org . eclipse . jdt . internal . core . SourceTypeElementInfo ; import org . eclipse . jdt . internal . core . util . ASTNodeFinder ; import org . eclipse . jdt . internal . core . util . HandleFactory ; public class HierarchyResolver implements ITypeRequestor { private ReferenceBinding focusType ; private boolean superTypesOnly ; private boolean hasMissingSuperClass ; LookupEnvironment lookupEnvironment ; private CompilerOptions options ; HierarchyBuilder builder ; private ReferenceBinding [ ] typeBindings ; private int typeIndex ; private IGenericType [ ] typeModels ; private static final CompilationUnitDeclaration FakeUnit ; static { IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies . exitAfterAllProblems ( ) ; ProblemReporter problemReporter = new ProblemReporter ( policy , new CompilerOptions ( ) , new DefaultProblemFactory ( ) ) ; CompilationResult result = new CompilationResult ( CharOperation . NO_CHAR , 0 , 0 , 0 ) ; FakeUnit = new CompilationUnitDeclaration ( problemReporter , result , 0 ) ; } public HierarchyResolver ( INameEnvironment nameEnvironment , Map settings , HierarchyBuilder builder , IProblemFactory problemFactory ) { this . options = new CompilerOptions ( settings ) ; IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies . exitAfterAllProblems ( ) ; ProblemReporter problemReporter = new ProblemReporter ( policy , this . options , problemFactory ) ; setEnvironment ( new LookupEnvironment ( this , this . options , problemReporter , nameEnvironment ) , builder ) ; } public HierarchyResolver ( LookupEnvironment lookupEnvironment , HierarchyBuilder builder ) { setEnvironment ( lookupEnvironment , builder ) ; } public void accept ( IBinaryType binaryType , PackageBinding packageBinding , AccessRestriction accessRestriction ) { IProgressMonitor progressMonitor = this . builder . hierarchy . progressMonitor ; if ( progressMonitor != null && progressMonitor . isCanceled ( ) ) throw new OperationCanceledException ( ) ; BinaryTypeBinding typeBinding = this . lookupEnvironment . createBinaryTypeFrom ( binaryType , packageBinding , accessRestriction ) ; try { this . remember ( binaryType , typeBinding ) ; } catch ( AbortCompilation e ) { } } public void accept ( ICompilationUnit sourceUnit , AccessRestriction accessRestriction ) { this . lookupEnvironment . problemReporter . abortDueToInternalError ( new StringBuffer ( Messages . accept_cannot ) . append ( sourceUnit . getFileName ( ) ) . toString ( ) ) ; } public void accept ( ISourceType [ ] sourceTypes , PackageBinding packageBinding , AccessRestriction accessRestriction ) { IProgressMonitor progressMonitor = this . builder . hierarchy . progressMonitor ; if ( progressMonitor != null && progressMonitor . isCanceled ( ) ) throw new OperationCanceledException ( ) ; ISourceType sourceType = sourceTypes [ 0 ] ; while ( sourceType . getEnclosingType ( ) != null ) sourceType = sourceType . getEnclosingType ( ) ; CompilationResult result = new CompilationResult ( sourceType . getFileName ( ) , 1 , 1 , this . options . maxProblemsPerUnit ) ; CompilationUnitDeclaration unit = SourceTypeConverter . buildCompilationUnit ( new ISourceType [ ] { sourceType } , SourceTypeConverter . MEMBER_TYPE , this . lookupEnvironment . problemReporter , result ) ; if ( unit != null ) { try { this . lookupEnvironment . buildTypeBindings ( unit , accessRestriction ) ; org . eclipse . jdt . core . ICompilationUnit cu = ( ( SourceTypeElementInfo ) sourceType ) . getHandle ( ) . getCompilationUnit ( ) ; rememberAllTypes ( unit , cu , false ) ; this . lookupEnvironment . completeTypeBindings ( unit , true ) ; } catch ( AbortCompilation e ) { } } } private IType findSuperClass ( IGenericType type , ReferenceBinding typeBinding ) { ReferenceBinding superBinding = typeBinding . superclass ( ) ; if ( superBinding != null ) { superBinding = ( ReferenceBinding ) superBinding . erasure ( ) ; if ( typeBinding . isHierarchyInconsistent ( ) ) { if ( superBinding . problemId ( ) == ProblemReasons . NotFound ) { this . hasMissingSuperClass = true ; this . builder . hierarchy . missingTypes . add ( new String ( superBinding . sourceName ) ) ; return null ; } else if ( ( superBinding . id == TypeIds . T_JavaLangObject ) ) { char [ ] superclassName ; char separator ; if ( type instanceof IBinaryType ) { superclassName = ( ( IBinaryType ) type ) . getSuperclassName ( ) ; separator = '/' ; } else if ( type instanceof ISourceType ) { superclassName = ( ( ISourceType ) type ) . getSuperclassName ( ) ; separator = '.' ; } else if ( type instanceof HierarchyType ) { superclassName = ( ( HierarchyType ) type ) . superclassName ; separator = '.' ; } else { return null ; } if ( superclassName != null ) { int lastSeparator = CharOperation . lastIndexOf ( separator , superclassName ) ; char [ ] simpleName = lastSeparator == - 1 ? superclassName : CharOperation . subarray ( superclassName , lastSeparator + 1 , superclassName . length ) ; if ( ! CharOperation . equals ( simpleName , TypeConstants . OBJECT ) ) { this . hasMissingSuperClass = true ; this . builder . hierarchy . missingTypes . add ( new String ( simpleName ) ) ; return null ; } } } } for ( int t = this . typeIndex ; t >= 0 ; t -- ) { if ( this . typeBindings [ t ] == superBinding ) { return this . builder . getHandle ( this . typeModels [ t ] , superBinding ) ; } } } return null ; } private IType [ ] findSuperInterfaces ( IGenericType type , ReferenceBinding typeBinding ) { char [ ] [ ] superInterfaceNames ; char separator ; if ( type instanceof IBinaryType ) { superInterfaceNames = ( ( IBinaryType ) type ) . getInterfaceNames ( ) ; separator = '/' ; } else if ( type instanceof ISourceType ) { ISourceType sourceType = ( ISourceType ) type ; if ( sourceType . getName ( ) . length == 0 ) { if ( typeBinding . superInterfaces ( ) != null && typeBinding . superInterfaces ( ) . length > 0 ) { superInterfaceNames = new char [ ] [ ] { sourceType . getSuperclassName ( ) } ; } else { superInterfaceNames = sourceType . getInterfaceNames ( ) ; } } else { if ( TypeDeclaration . kind ( sourceType . getModifiers ( ) ) == TypeDeclaration . ANNOTATION_TYPE_DECL ) superInterfaceNames = new char [ ] [ ] { TypeConstants . CharArray_JAVA_LANG_ANNOTATION_ANNOTATION } ; else superInterfaceNames = sourceType . getInterfaceNames ( ) ; } separator = '.' ; } else if ( type instanceof HierarchyType ) { HierarchyType hierarchyType = ( HierarchyType ) type ; if ( hierarchyType . name . length == 0 ) { if ( typeBinding . superInterfaces ( ) != null && typeBinding . superInterfaces ( ) . length > 0 ) { superInterfaceNames = new char [ ] [ ] { hierarchyType . superclassName } ; } else { superInterfaceNames = hierarchyType . superInterfaceNames ; } } else { superInterfaceNames = hierarchyType . superInterfaceNames ; } separator = '.' ; } else { return null ; } ReferenceBinding [ ] interfaceBindings = typeBinding . superInterfaces ( ) ; int bindingIndex = 0 ; int bindingLength = interfaceBindings == null ? 0 : interfaceBindings . length ; int length = superInterfaceNames == null ? 0 : superInterfaceNames . length ; IType [ ] superinterfaces = new IType [ length ] ; int index = 0 ; next : for ( int i = 0 ; i < length ; i ++ ) { char [ ] superInterfaceName = superInterfaceNames [ i ] ; int end = superInterfaceName . length ; int genericStart = CharOperation . indexOf ( Signature . C_GENERIC_START , superInterfaceName ) ; if ( genericStart != - 1 ) end = genericStart ; int lastSeparator = CharOperation . lastIndexOf ( separator , superInterfaceName , 0 , end ) ; int start = lastSeparator + 1 ; int lastDollar = CharOperation . lastIndexOf ( '$' , superInterfaceName , start ) ; if ( lastDollar != - 1 ) start = lastDollar + 1 ; char [ ] simpleName = CharOperation . subarray ( superInterfaceName , start , end ) ; if ( bindingIndex < bindingLength ) { ReferenceBinding interfaceBinding = ( ReferenceBinding ) interfaceBindings [ bindingIndex ] . erasure ( ) ; if ( CharOperation . equals ( simpleName , interfaceBinding . sourceName ) ) { bindingIndex ++ ; for ( int t = this . typeIndex ; t >= 0 ; t -- ) { if ( this . typeBindings [ t ] == interfaceBinding ) { IType handle = this . builder . getHandle ( this . typeModels [ t ] , interfaceBinding ) ; if ( handle != null ) { superinterfaces [ index ++ ] = handle ; continue next ; } } } } } this . builder . hierarchy . missingTypes . add ( new String ( simpleName ) ) ; } if ( index != length ) System . arraycopy ( superinterfaces , 0 , superinterfaces = new IType [ index ] , 0 , index ) ; return superinterfaces ; } private void fixSupertypeBindings ( ) { for ( int current = this . typeIndex ; current >= 0 ; current -- ) { ReferenceBinding typeBinding = this . typeBindings [ current ] ; if ( ( typeBinding . tagBits & TagBits . HierarchyHasProblems ) == 0 ) continue ; if ( typeBinding instanceof SourceTypeBinding ) { if ( typeBinding instanceof LocalTypeBinding ) { LocalTypeBinding localTypeBinding = ( LocalTypeBinding ) typeBinding ; QualifiedAllocationExpression allocationExpression = localTypeBinding . scope . referenceContext . allocation ; TypeReference type ; if ( allocationExpression != null && ( type = allocationExpression . type ) != null && type . resolvedType != null ) { localTypeBinding . superclass = ( ReferenceBinding ) type . resolvedType ; continue ; } } ClassScope scope = ( ( SourceTypeBinding ) typeBinding ) . scope ; if ( scope != null ) { TypeDeclaration typeDeclaration = scope . referenceContext ; TypeReference superclassRef = typeDeclaration == null ? null : typeDeclaration . superclass ; TypeBinding superclass = superclassRef == null ? null : superclassRef . resolvedType ; if ( superclass != null ) { superclass = superclass . closestMatch ( ) ; } if ( superclass instanceof ReferenceBinding ) { if ( ! ( subTypeOfType ( ( ReferenceBinding ) superclass , typeBinding ) ) ) { ( ( SourceTypeBinding ) typeBinding ) . superclass = ( ReferenceBinding ) superclass ; } } TypeReference [ ] superInterfaces = typeDeclaration == null ? null : typeDeclaration . superInterfaces ; int length ; ReferenceBinding [ ] interfaceBindings = typeBinding . superInterfaces ( ) ; if ( superInterfaces != null && ( length = superInterfaces . length ) > ( interfaceBindings == null ? 0 : interfaceBindings . length ) ) { interfaceBindings = new ReferenceBinding [ length ] ; int index = 0 ; for ( int i = 0 ; i < length ; i ++ ) { TypeBinding superInterface = superInterfaces [ i ] . resolvedType ; if ( superInterface != null ) { superInterface = superInterface . closestMatch ( ) ; } if ( superInterface instanceof ReferenceBinding ) { if ( ! ( subTypeOfType ( ( ReferenceBinding ) superInterface , typeBinding ) ) ) { interfaceBindings [ index ++ ] = ( ReferenceBinding ) superInterface ; } } } if ( index < length ) System . arraycopy ( interfaceBindings , 0 , interfaceBindings = new ReferenceBinding [ index ] , 0 , index ) ; ( ( SourceTypeBinding ) typeBinding ) . superInterfaces = interfaceBindings ; } } } else if ( typeBinding instanceof BinaryTypeBinding ) { try { typeBinding . superclass ( ) ; } catch ( AbortCompilation e ) { ( ( BinaryTypeBinding ) typeBinding ) . tagBits &= ~ TagBits . HasUnresolvedSuperclass ; this . builder . hierarchy . missingTypes . add ( new String ( typeBinding . superclass ( ) . sourceName ( ) ) ) ; this . hasMissingSuperClass = true ; } try { typeBinding . superInterfaces ( ) ; } catch ( AbortCompilation e ) { ( ( BinaryTypeBinding ) typeBinding ) . tagBits &= ~ TagBits . HasUnresolvedSuperinterfaces ; } } } } private void remember ( IGenericType suppliedType , ReferenceBinding typeBinding ) { if ( typeBinding == null ) return ; if ( ++ this . typeIndex == this . typeModels . length ) { System . arraycopy ( this . typeModels , 0 , this . typeModels = new IGenericType [ this . typeIndex * 2 ] , 0 , this . typeIndex ) ; System . arraycopy ( this . typeBindings , 0 , this . typeBindings = new ReferenceBinding [ this . typeIndex * 2 ] , 0 , this . typeIndex ) ; } this . typeModels [ this . typeIndex ] = suppliedType ; this . typeBindings [ this . typeIndex ] = typeBinding ; } private void remember ( IType type , ReferenceBinding typeBinding ) { if ( ( ( CompilationUnit ) type . getCompilationUnit ( ) ) . isOpen ( ) ) { try { IGenericType genericType = ( IGenericType ) ( ( JavaElement ) type ) . getElementInfo ( ) ; remember ( genericType , typeBinding ) ; } catch ( JavaModelException e ) { return ; } } else { if ( typeBinding == null ) return ; TypeDeclaration typeDeclaration = ( ( SourceTypeBinding ) typeBinding ) . scope . referenceType ( ) ; char [ ] superclassName = null ; TypeReference superclass ; if ( ( typeDeclaration . bits & ASTNode . IsAnonymousType ) != 0 ) { superclass = typeDeclaration . allocation . type ; } else { superclass = typeDeclaration . superclass ; } if ( superclass != null ) { char [ ] [ ] typeName = superclass . getTypeName ( ) ; superclassName = typeName == null ? null : typeName [ typeName . length - 1 ] ; } char [ ] [ ] superInterfaceNames = null ; TypeReference [ ] superInterfaces = typeDeclaration . superInterfaces ; if ( superInterfaces != null ) { int length = superInterfaces . length ; superInterfaceNames = new char [ length ] [ ] ; for ( int i = 0 ; i < length ; i ++ ) { TypeReference superInterface = superInterfaces [ i ] ; char [ ] [ ] typeName = superInterface . getTypeName ( ) ; superInterfaceNames [ i ] = typeName [ typeName . length - 1 ] ; } } HierarchyType hierarchyType = new HierarchyType ( type , typeDeclaration . name , typeDeclaration . binding . modifiers , superclassName , superInterfaceNames ) ; remember ( hierarchyType , typeDeclaration . binding ) ; } } private void rememberAllTypes ( CompilationUnitDeclaration parsedUnit , org . eclipse . jdt . core . ICompilationUnit cu , boolean includeLocalTypes ) { TypeDeclaration [ ] types = parsedUnit . types ; if ( types != null ) { for ( int i = 0 , length = types . length ; i < length ; i ++ ) { TypeDeclaration type = types [ i ] ; rememberWithMemberTypes ( type , cu . getType ( new String ( type . name ) ) ) ; } } if ( includeLocalTypes && parsedUnit . localTypes != null ) { HandleFactory factory = new HandleFactory ( ) ; HashSet existingElements = new HashSet ( parsedUnit . localTypeCount ) ; HashMap knownScopes = new HashMap ( parsedUnit . localTypeCount ) ; for ( int i = 0 ; i < parsedUnit . localTypeCount ; i ++ ) { LocalTypeBinding localType = parsedUnit . localTypes [ i ] ; ClassScope classScope = localType . scope ; TypeDeclaration typeDecl = classScope . referenceType ( ) ; IType typeHandle = ( IType ) factory . createElement ( classScope , cu , existingElements , knownScopes ) ; rememberWithMemberTypes ( typeDecl , typeHandle ) ; } } } private void rememberWithMemberTypes ( TypeDeclaration typeDecl , IType typeHandle ) { remember ( typeHandle , typeDecl . binding ) ; TypeDeclaration [ ] memberTypes = typeDecl . memberTypes ; if ( memberTypes != null ) { for ( int i = 0 , length = memberTypes . length ; i < length ; i ++ ) { TypeDeclaration memberType = memberTypes [ i ] ; rememberWithMemberTypes ( memberType , typeHandle . getType ( new String ( memberType . name ) ) ) ; } } } private void reportHierarchy ( IType focus , TypeDeclaration focusLocalType , ReferenceBinding binaryTypeBinding ) { if ( focus != null ) { if ( binaryTypeBinding != null ) { this . focusType = binaryTypeBinding ; } else { if ( focusLocalType != null ) { this . focusType = focusLocalType . binding ; } else { char [ ] fullyQualifiedName = focus . getFullyQualifiedName ( ) . toCharArray ( ) ; setFocusType ( CharOperation . splitOn ( '.' , fullyQualifiedName ) ) ; } } } fixSupertypeBindings ( ) ; int objectIndex = - 1 ; IProgressMonitor progressMonitor = this . builder . hierarchy . progressMonitor ; for ( int current = this . typeIndex ; current >= 0 ; current -- ) { if ( progressMonitor != null && progressMonitor . isCanceled ( ) ) throw new OperationCanceledException ( ) ; ReferenceBinding typeBinding = this . typeBindings [ current ] ; if ( typeBinding . id == TypeIds . T_JavaLangObject ) { objectIndex = current ; continue ; } IGenericType suppliedType = this . typeModels [ current ] ; if ( ! subOrSuperOfFocus ( typeBinding ) ) { continue ; } IType superclass ; if ( typeBinding . isInterface ( ) ) { superclass = null ; } else { superclass = findSuperClass ( suppliedType , typeBinding ) ; } IType [ ] superinterfaces = findSuperInterfaces ( suppliedType , typeBinding ) ; this . builder . connect ( suppliedType , this . builder . getHandle ( suppliedType , typeBinding ) , superclass , superinterfaces ) ; } if ( objectIndex > - 1 && ( ! this . hasMissingSuperClass || this . focusType == null ) ) { IGenericType objectType = this . typeModels [ objectIndex ] ; this . builder . connect ( objectType , this . builder . getHandle ( objectType , this . typeBindings [ objectIndex ] ) , null , null ) ; } } private void reset ( ) { this . lookupEnvironment . reset ( ) ; this . focusType = null ; this . superTypesOnly = false ; this . typeIndex = - 1 ; this . typeModels = new IGenericType [ 5 ] ; this . typeBindings = new ReferenceBinding [ 5 ] ; } public void resolve ( IGenericType suppliedType ) { try { if ( suppliedType . isBinaryType ( ) ) { BinaryTypeBinding binaryTypeBinding = this . lookupEnvironment . cacheBinaryType ( ( IBinaryType ) suppliedType , false , null ) ; remember ( suppliedType , binaryTypeBinding ) ; int startIndex = this . typeIndex ; for ( int i = startIndex ; i <= this . typeIndex ; i ++ ) { IGenericType igType = this . typeModels [ i ] ; if ( igType != null && igType . isBinaryType ( ) ) { CompilationUnitDeclaration previousUnitBeingCompleted = this . lookupEnvironment . unitBeingCompleted ; try { if ( previousUnitBeingCompleted == null ) { this . lookupEnvironment . unitBeingCompleted = FakeUnit ; } ReferenceBinding typeBinding = this . typeBindings [ i ] ; typeBinding . superclass ( ) ; typeBinding . superInterfaces ( ) ; } catch ( AbortCompilation e ) { } finally { this . lookupEnvironment . unitBeingCompleted = previousUnitBeingCompleted ; } } } this . superTypesOnly = true ; reportHierarchy ( this . builder . getType ( ) , null , binaryTypeBinding ) ; } else { org . eclipse . jdt . core . ICompilationUnit cu = ( ( SourceTypeElementInfo ) suppliedType ) . getHandle ( ) . getCompilationUnit ( ) ; HashSet localTypes = new HashSet ( ) ; localTypes . add ( cu . getPath ( ) . toString ( ) ) ; this . superTypesOnly = true ; resolve ( new Openable [ ] { ( Openable ) cu } , localTypes , null ) ; } } catch ( AbortCompilation e ) { } finally { reset ( ) ; } } public void resolve ( Openable [ ] openables , HashSet localTypes , IProgressMonitor monitor ) { try { int openablesLength = openables . length ; CompilationUnitDeclaration [ ] parsedUnits = new CompilationUnitDeclaration [ openablesLength ] ; boolean [ ] hasLocalType = new boolean [ openablesLength ] ; org . eclipse . jdt . core . ICompilationUnit [ ] cus = new org . eclipse . jdt . core . ICompilationUnit [ openablesLength ] ; int unitsIndex = 0 ; CompilationUnitDeclaration focusUnit = null ; ReferenceBinding focusBinaryBinding = null ; IType focus = this . builder . getType ( ) ; Openable focusOpenable = null ; if ( focus != null ) { if ( focus . isBinary ( ) ) { focusOpenable = ( Openable ) focus . getClassFile ( ) ; } else { focusOpenable = ( Openable ) focus . getCompilationUnit ( ) ; } } Parser parser = LanguageSupportFactory . getParser ( this , this . lookupEnvironment . globalOptions , this . lookupEnvironment . problemReporter , true , 1 ) ; for ( int i = 0 ; i < openablesLength ; i ++ ) { Openable openable = openables [ i ] ; if ( openable instanceof org . eclipse . jdt . core . ICompilationUnit ) { org . eclipse . jdt . core . ICompilationUnit cu = ( org . eclipse . jdt . core . ICompilationUnit ) openable ; boolean containsLocalType = false ; if ( localTypes == null ) { containsLocalType = true ; } else { IPath path = cu . getPath ( ) ; containsLocalType = localTypes . contains ( path . toString ( ) ) ; } CompilationUnitDeclaration parsedUnit = null ; if ( cu . isOpen ( ) ) { CompilationResult result = new CompilationResult ( ( ICompilationUnit ) cu , i , openablesLength , this . options . maxProblemsPerUnit ) ; SourceTypeElementInfo [ ] typeInfos = null ; try { IType [ ] topLevelTypes = cu . getTypes ( ) ; int topLevelLength = topLevelTypes . length ; if ( topLevelLength == 0 ) continue ; typeInfos = new SourceTypeElementInfo [ topLevelLength ] ; for ( int j = 0 ; j < topLevelLength ; j ++ ) { IType topLevelType = topLevelTypes [ j ] ; typeInfos [ j ] = ( SourceTypeElementInfo ) ( ( JavaElement ) topLevelType ) . getElementInfo ( ) ; } } catch ( JavaModelException e ) { } int flags = ! containsLocalType ? SourceTypeConverter . MEMBER_TYPE : SourceTypeConverter . FIELD_AND_METHOD | SourceTypeConverter . MEMBER_TYPE | SourceTypeConverter . LOCAL_TYPE ; parsedUnit = SourceTypeConverter . buildCompilationUnit ( typeInfos , flags , this . lookupEnvironment . problemReporter , result ) ; if ( containsLocalType ) parsedUnit . bits |= ASTNode . HasAllMethodBodies ; } else { IFile file = ( IFile ) cu . getResource ( ) ; ICompilationUnit sourceUnit = this . builder . createCompilationUnitFromPath ( openable , file ) ; CompilationResult unitResult = new CompilationResult ( sourceUnit , i , openablesLength , this . options . maxProblemsPerUnit ) ; parsedUnit = parser . dietParse ( sourceUnit , unitResult ) ; } if ( parsedUnit != null ) { hasLocalType [ unitsIndex ] = containsLocalType ; cus [ unitsIndex ] = cu ; parsedUnits [ unitsIndex ++ ] = parsedUnit ; try { this . lookupEnvironment . buildTypeBindings ( parsedUnit , null ) ; if ( openable . equals ( focusOpenable ) ) { focusUnit = parsedUnit ; } } catch ( AbortCompilation e ) { } } } else { ClassFile classFile = ( ClassFile ) openable ; IBinaryType binaryType = ( IBinaryType ) JavaModelManager . getJavaModelManager ( ) . getInfo ( classFile . getType ( ) ) ; if ( binaryType == null ) { if ( classFile . getPackageFragmentRoot ( ) . isArchive ( ) ) { binaryType = this . builder . createInfoFromClassFileInJar ( classFile ) ; } else { IResource file = classFile . resource ( ) ; binaryType = this . builder . createInfoFromClassFile ( classFile , file ) ; } } if ( binaryType != null ) { try { BinaryTypeBinding binaryTypeBinding = this . lookupEnvironment . cacheBinaryType ( binaryType , false , null ) ; remember ( binaryType , binaryTypeBinding ) ; if ( openable . equals ( focusOpenable ) ) { focusBinaryBinding = binaryTypeBinding ; } } catch ( AbortCompilation e ) { } } } } TypeDeclaration focusLocalType = null ; if ( focus != null && focusBinaryBinding == null && focusUnit != null && ( ( Member ) focus ) . getOuterMostLocalContext ( ) != null ) { focusLocalType = new ASTNodeFinder ( focusUnit ) . findType ( focus ) ; } for ( int i = 0 ; i <= this . typeIndex ; i ++ ) { IGenericType suppliedType = this . typeModels [ i ] ; if ( suppliedType != null && suppliedType . isBinaryType ( ) ) { CompilationUnitDeclaration previousUnitBeingCompleted = this . lookupEnvironment . unitBeingCompleted ; try { if ( previousUnitBeingCompleted == null ) { this . lookupEnvironment . unitBeingCompleted = FakeUnit ; } ReferenceBinding typeBinding = this . typeBindings [ i ] ; typeBinding . superclass ( ) ; typeBinding . superInterfaces ( ) ; } catch ( AbortCompilation e ) { } finally { this . lookupEnvironment . unitBeingCompleted = previousUnitBeingCompleted ; } } } for ( int i = 0 ; i < unitsIndex ; i ++ ) { CompilationUnitDeclaration parsedUnit = parsedUnits [ i ] ; if ( parsedUnit != null ) { try { if ( hasLocalType [ i ] ) { if ( monitor != null && monitor . isCanceled ( ) ) throw new OperationCanceledException ( ) ; parser . getMethodBodies ( parsedUnit ) ; } } catch ( AbortCompilation e ) { hasLocalType [ i ] = false ; } } } try { this . lookupEnvironment . completeTypeBindings ( parsedUnits , hasLocalType , unitsIndex ) ; for ( int i = 0 ; i < unitsIndex ; i ++ ) { CompilationUnitDeclaration parsedUnit = parsedUnits [ i ] ; if ( parsedUnit != null && ! parsedUnit . hasErrors ( ) ) { boolean containsLocalType = hasLocalType [ i ] ; if ( containsLocalType ) { if ( monitor != null && monitor . isCanceled ( ) ) throw new OperationCanceledException ( ) ; parsedUnit . scope . faultInTypes ( ) ; parsedUnit . resolve ( ) ; } rememberAllTypes ( parsedUnit , cus [ i ] , containsLocalType ) ; } } } catch ( AbortCompilation e ) { } worked ( monitor , 1 ) ; if ( focusBinaryBinding == null && focus != null && focus . isBinary ( ) ) { char [ ] fullyQualifiedName = focus . getFullyQualifiedName ( ) . toCharArray ( ) ; focusBinaryBinding = this . lookupEnvironment . getCachedType ( CharOperation . splitOn ( '.' , fullyQualifiedName ) ) ; if ( focusBinaryBinding == null ) return ; } reportHierarchy ( focus , focusLocalType , focusBinaryBinding ) ; } catch ( ClassCastException e ) { } catch ( AbortCompilation e ) { if ( TypeHierarchy . DEBUG ) e . printStackTrace ( ) ; } finally { reset ( ) ; } } private void setEnvironment ( LookupEnvironment lookupEnvironment , HierarchyBuilder builder ) { this . lookupEnvironment = lookupEnvironment ; this . builder = builder ; this . typeIndex = - 1 ; this . typeModels = new IGenericType [ 5 ] ; this . typeBindings = new ReferenceBinding [ 5 ] ; } public ReferenceBinding setFocusType ( char [ ] [ ] compoundName ) { if ( compoundName == null || this . lookupEnvironment == null ) return null ; this . focusType = this . lookupEnvironment . getCachedType ( compoundName ) ; if ( this . focusType == null ) { this . focusType = this . lookupEnvironment . askForType ( compoundName ) ; if ( this . focusType == null ) { int length = compoundName . length ; char [ ] typeName = compoundName [ length - 1 ] ; int firstDollar = CharOperation . indexOf ( '$' , typeName ) ; if ( firstDollar != - 1 ) { compoundName [ length - 1 ] = CharOperation . subarray ( typeName , 0 , firstDollar ) ; this . focusType = this . lookupEnvironment . askForType ( compoundName ) ; if ( this . focusType != null ) { char [ ] [ ] memberTypeNames = CharOperation . splitOn ( '$' , typeName , firstDollar + 1 , typeName . length ) ; for ( int i = 0 ; i < memberTypeNames . length ; i ++ ) { this . focusType = this . focusType . getMemberType ( memberTypeNames [ i ] ) ; } } } } } return this . focusType ; } public boolean subOrSuperOfFocus ( ReferenceBinding typeBinding ) { if ( this . focusType == null ) return true ; try { if ( subTypeOfType ( this . focusType , typeBinding ) ) return true ; if ( ! this . superTypesOnly && subTypeOfType ( typeBinding , this . focusType ) ) return true ; } catch ( AbortCompilation e ) { } return false ; } private boolean subTypeOfType ( ReferenceBinding subType , ReferenceBinding typeBinding ) { if ( typeBinding == null || subType == null ) return false ; if ( subType == typeBinding ) return true ; ReferenceBinding superclass = subType . superclass ( ) ; if ( superclass != null ) superclass = ( ReferenceBinding ) superclass . erasure ( ) ; if ( subTypeOfType ( superclass , typeBinding ) ) return true ; ReferenceBinding [ ] superInterfaces = subType . superInterfaces ( ) ; if ( superInterfaces != null ) { for ( int i = 0 , length = superInterfaces . length ; i < length ; i ++ ) { ReferenceBinding superInterface = ( ReferenceBinding ) superInterfaces [ i ] . erasure ( ) ; if ( subTypeOfType ( superInterface , typeBinding ) ) return true ; } } return false ; } protected void worked ( IProgressMonitor monitor , int work ) { if ( monitor != null ) { if ( monitor . isCanceled ( ) ) { throw new OperationCanceledException ( ) ; } else { monitor . worked ( work ) ; } } } } </s>