<s> package org . eclipse . jdt . internal . core . search ; import org . eclipse . core . runtime . Path ; import org . eclipse . jdt . core . IAccessRule ; 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 . core . compiler . CharOperation ; import org . eclipse . jdt . core . compiler . IProblem ; import org . eclipse . jdt . core . search . IJavaSearchScope ; import org . eclipse . jdt . core . search . TypeNameMatchRequestor ; import org . eclipse . jdt . core . search . TypeNameRequestor ; 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 . core . Openable ; import org . eclipse . jdt . internal . core . PackageFragmentRoot ; import org . eclipse . jdt . internal . core . util . HandleFactory ; import org . eclipse . jdt . internal . core . util . HashtableOfArrayToObject ; public class TypeNameMatchRequestorWrapper implements IRestrictedAccessTypeRequestor { TypeNameMatchRequestor requestor ; private IJavaSearchScope scope ; private HandleFactory handleFactory ; private String lastPkgFragmentRootPath ; private IPackageFragmentRoot lastPkgFragmentRoot ; private HashtableOfArrayToObject packageHandles ; private Object lastProject ; private long complianceValue ; public TypeNameMatchRequestorWrapper ( TypeNameMatchRequestor requestor , IJavaSearchScope scope ) { this . requestor = requestor ; this . scope = scope ; if ( ! ( scope instanceof AbstractJavaSearchScope ) ) { this . handleFactory = new HandleFactory ( ) ; } } public void acceptType ( int modifiers , char [ ] packageName , char [ ] simpleTypeName , char [ ] [ ] enclosingTypeNames , String path , AccessRestriction access ) { try { IType type = null ; if ( this . handleFactory != null ) { Openable openable = this . handleFactory . createOpenable ( path , this . scope ) ; if ( openable == null ) return ; switch ( openable . getElementType ( ) ) { case IJavaElement . COMPILATION_UNIT : ICompilationUnit cu = ( ICompilationUnit ) openable ; if ( enclosingTypeNames != null && enclosingTypeNames . length > 0 ) { type = cu . getType ( new String ( enclosingTypeNames [ 0 ] ) ) ; for ( int j = 1 , l = enclosingTypeNames . length ; j < l ; j ++ ) { type = type . getType ( new String ( enclosingTypeNames [ j ] ) ) ; } type = type . getType ( new String ( simpleTypeName ) ) ; } else { type = cu . getType ( new String ( simpleTypeName ) ) ; } break ; case IJavaElement . CLASS_FILE : type = ( ( IClassFile ) openable ) . getType ( ) ; break ; } } else { int separatorIndex = path . indexOf ( IJavaSearchScope . JAR_FILE_ENTRY_SEPARATOR ) ; type = separatorIndex == - 1 ? createTypeFromPath ( path , new String ( simpleTypeName ) , enclosingTypeNames ) : createTypeFromJar ( path , separatorIndex ) ; } if ( type != null ) { if ( ! ( this . scope instanceof HierarchyScope ) || ( ( HierarchyScope ) this . scope ) . enclosesFineGrained ( type ) ) { final JavaSearchTypeNameMatch match = new JavaSearchTypeNameMatch ( type , modifiers ) ; if ( access != null ) { switch ( access . getProblemId ( ) ) { case IProblem . ForbiddenReference : match . setAccessibility ( IAccessRule . K_NON_ACCESSIBLE ) ; break ; case IProblem . DiscouragedReference : match . setAccessibility ( IAccessRule . K_DISCOURAGED ) ; break ; } } this . requestor . acceptTypeNameMatch ( match ) ; } } } catch ( JavaModelException e ) { } } private IType createTypeFromJar ( String resourcePath , int separatorIndex ) throws JavaModelException { if ( this . lastPkgFragmentRootPath == null || this . lastPkgFragmentRootPath . length ( ) > resourcePath . length ( ) || ! resourcePath . startsWith ( this . lastPkgFragmentRootPath ) ) { String jarPath = resourcePath . substring ( 0 , separatorIndex ) ; IPackageFragmentRoot root = ( ( AbstractJavaSearchScope ) this . scope ) . packageFragmentRoot ( resourcePath , separatorIndex , jarPath ) ; if ( root == null ) return null ; this . lastPkgFragmentRootPath = jarPath ; this . lastPkgFragmentRoot = root ; this . packageHandles = new HashtableOfArrayToObject ( 5 ) ; } String classFilePath = resourcePath . substring ( separatorIndex + 1 ) ; String [ ] simpleNames = new Path ( classFilePath ) . segments ( ) ; String [ ] pkgName ; int length = simpleNames . length - 1 ; if ( length > 0 ) { pkgName = new String [ length ] ; System . arraycopy ( simpleNames , 0 , pkgName , 0 , length ) ; } else { pkgName = CharOperation . NO_STRINGS ; } IPackageFragment pkgFragment = ( IPackageFragment ) this . packageHandles . get ( pkgName ) ; if ( pkgFragment == null ) { pkgFragment = ( ( PackageFragmentRoot ) this . lastPkgFragmentRoot ) . getPackageFragment ( pkgName ) ; if ( length == 5 && pkgName [ 4 ] . equals ( "enum" ) ) { IJavaProject proj = ( IJavaProject ) pkgFragment . getAncestor ( IJavaElement . JAVA_PROJECT ) ; if ( ! proj . equals ( this . lastProject ) ) { String complianceStr = proj . getOption ( CompilerOptions . OPTION_Source , true ) ; this . complianceValue = CompilerOptions . versionToJdkLevel ( complianceStr ) ; this . lastProject = proj ; } if ( this . complianceValue >= ClassFileConstants . JDK1_5 ) return null ; } this . packageHandles . put ( pkgName , pkgFragment ) ; } return pkgFragment . getClassFile ( simpleNames [ length ] ) . getType ( ) ; } private IType createTypeFromPath ( String resourcePath , String simpleTypeName , char [ ] [ ] enclosingTypeNames ) throws JavaModelException { int rootPathLength = - 1 ; if ( this . lastPkgFragmentRootPath == null || ! ( resourcePath . startsWith ( this . lastPkgFragmentRootPath ) && ( rootPathLength = this . lastPkgFragmentRootPath . length ( ) ) > 0 && resourcePath . charAt ( rootPathLength ) == '/' ) ) { PackageFragmentRoot root = ( PackageFragmentRoot ) ( ( AbstractJavaSearchScope ) this . scope ) . packageFragmentRoot ( resourcePath , - 1 , null ) ; if ( root == null ) return null ; this . lastPkgFragmentRoot = root ; this . lastPkgFragmentRootPath = root . internalPath ( ) . toString ( ) ; this . packageHandles = new HashtableOfArrayToObject ( 5 ) ; } resourcePath = resourcePath . substring ( this . lastPkgFragmentRootPath . length ( ) + 1 ) ; String [ ] simpleNames = new Path ( resourcePath ) . segments ( ) ; String [ ] pkgName ; int length = simpleNames . length - 1 ; if ( length > 0 ) { pkgName = new String [ length ] ; System . arraycopy ( simpleNames , 0 , pkgName , 0 , length ) ; } else { pkgName = CharOperation . NO_STRINGS ; } IPackageFragment pkgFragment = ( IPackageFragment ) this . packageHandles . get ( pkgName ) ; if ( pkgFragment == null ) { pkgFragment = ( ( PackageFragmentRoot ) this . lastPkgFragmentRoot ) . getPackageFragment ( pkgName ) ; this . packageHandles . put ( pkgName , pkgFragment ) ; } String simpleName = simpleNames [ length ] ; if ( org . eclipse . jdt . internal . core . util . Util . isJavaLikeFileName ( simpleName ) ) { ICompilationUnit unit = pkgFragment . getCompilationUnit ( simpleName ) ; int etnLength = enclosingTypeNames == null ? 0 : enclosingTypeNames . length ; IType type = ( etnLength == 0 ) ? unit . getType ( simpleTypeName ) : unit . getType ( new String ( enclosingTypeNames [ 0 ] ) ) ; if ( etnLength > 0 ) { for ( int i = 1 ; i < etnLength ; i ++ ) { type = type . getType ( new String ( enclosingTypeNames [ i ] ) ) ; } type = type . getType ( simpleTypeName ) ; } return type ; } else if ( org . eclipse . jdt . internal . compiler . util . Util . isClassFileName ( simpleName ) ) { IClassFile classFile = pkgFragment . getClassFile ( simpleName ) ; return classFile . getType ( ) ; } return null ; } } </s>