<s> package org . eclipse . jdt . core . dom ; import java . util . List ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . compiler . lookup . ArrayBinding ; import org . eclipse . jdt . internal . compiler . lookup . Binding ; import org . eclipse . jdt . internal . compiler . lookup . CompilationUnitScope ; import org . eclipse . jdt . internal . compiler . lookup . ReferenceBinding ; import org . eclipse . jdt . internal . compiler . util . SuffixConstants ; import org . eclipse . jdt . internal . compiler . util . Util ; import org . eclipse . jdt . internal . core . PackageFragment ; class RecoveredTypeBinding implements ITypeBinding { private VariableDeclaration variableDeclaration ; private Type currentType ; private BindingResolver resolver ; private int dimensions ; private RecoveredTypeBinding innerTypeBinding ; private ITypeBinding [ ] typeArguments ; private org . eclipse . jdt . internal . compiler . lookup . TypeBinding binding ; RecoveredTypeBinding ( BindingResolver resolver , VariableDeclaration variableDeclaration ) { this . variableDeclaration = variableDeclaration ; this . resolver = resolver ; this . currentType = getType ( ) ; this . dimensions = variableDeclaration . getExtraDimensions ( ) ; if ( this . currentType . isArrayType ( ) ) { this . dimensions += ( ( ArrayType ) this . currentType ) . getDimensions ( ) ; } } RecoveredTypeBinding ( BindingResolver resolver , org . eclipse . jdt . internal . compiler . lookup . TypeBinding typeBinding ) { this . resolver = resolver ; this . dimensions = typeBinding . dimensions ( ) ; this . binding = typeBinding ; } RecoveredTypeBinding ( BindingResolver resolver , Type type ) { this . currentType = type ; this . resolver = resolver ; this . dimensions = 0 ; if ( type . isArrayType ( ) ) { this . dimensions += ( ( ArrayType ) type ) . getDimensions ( ) ; } } RecoveredTypeBinding ( BindingResolver resolver , RecoveredTypeBinding typeBinding , int dimensions ) { this . innerTypeBinding = typeBinding ; this . dimensions = typeBinding . getDimensions ( ) + dimensions ; this . resolver = resolver ; } public ITypeBinding createArrayType ( int dims ) { return this . resolver . getTypeBinding ( this , dims ) ; } public String getBinaryName ( ) { return null ; } public ITypeBinding getBound ( ) { return null ; } public ITypeBinding getGenericTypeOfWildcardType ( ) { return null ; } public int getRank ( ) { return - 1 ; } public ITypeBinding getComponentType ( ) { if ( this . dimensions == 0 ) return null ; return this . resolver . getTypeBinding ( this , - 1 ) ; } public IVariableBinding [ ] getDeclaredFields ( ) { return TypeBinding . NO_VARIABLE_BINDINGS ; } public IMethodBinding [ ] getDeclaredMethods ( ) { return TypeBinding . NO_METHOD_BINDINGS ; } public int getDeclaredModifiers ( ) { return 0 ; } public ITypeBinding [ ] getDeclaredTypes ( ) { return TypeBinding . NO_TYPE_BINDINGS ; } public ITypeBinding getDeclaringClass ( ) { return null ; } public IMethodBinding getDeclaringMethod ( ) { return null ; } public int getDimensions ( ) { return this . dimensions ; } public ITypeBinding getElementType ( ) { if ( this . binding != null ) { if ( this . binding . isArrayType ( ) ) { ArrayBinding arrayBinding = ( ArrayBinding ) this . binding ; return new RecoveredTypeBinding ( this . resolver , arrayBinding . leafComponentType ) ; } else { return new RecoveredTypeBinding ( this . resolver , this . binding ) ; } } if ( this . innerTypeBinding != null ) { return this . innerTypeBinding . getElementType ( ) ; } if ( this . currentType != null && this . currentType . isArrayType ( ) ) { return this . resolver . getTypeBinding ( ( ( ArrayType ) this . currentType ) . getElementType ( ) ) ; } if ( this . variableDeclaration != null && this . variableDeclaration . getExtraDimensions ( ) != 0 ) { return this . resolver . getTypeBinding ( getType ( ) ) ; } return null ; } public ITypeBinding getErasure ( ) { return this ; } public ITypeBinding [ ] getInterfaces ( ) { return TypeBinding . NO_TYPE_BINDINGS ; } public int getModifiers ( ) { return Modifier . NONE ; } public String getName ( ) { char [ ] brackets = new char [ this . dimensions * 2 ] ; for ( int i = this . dimensions * 2 - 1 ; i >= 0 ; i -= 2 ) { brackets [ i ] = ']' ; brackets [ i - 1 ] = '[' ; } StringBuffer buffer = new StringBuffer ( getInternalName ( ) ) ; buffer . append ( brackets ) ; return String . valueOf ( buffer ) ; } private String getInternalName ( ) { if ( this . innerTypeBinding != null ) { return this . innerTypeBinding . getInternalName ( ) ; } ReferenceBinding referenceBinding = getReferenceBinding ( ) ; if ( referenceBinding != null ) { return new String ( referenceBinding . compoundName [ referenceBinding . compoundName . length - 1 ] ) ; } return getTypeNameFrom ( getType ( ) ) ; } public IPackageBinding getPackage ( ) { if ( this . binding != null ) { switch ( this . binding . kind ( ) ) { case Binding . BASE_TYPE : case Binding . ARRAY_TYPE : case Binding . TYPE_PARAMETER : case Binding . WILDCARD_TYPE : case Binding . INTERSECTION_TYPE : return null ; } IPackageBinding packageBinding = this . resolver . getPackageBinding ( this . binding . getPackage ( ) ) ; if ( packageBinding != null ) return packageBinding ; } if ( this . innerTypeBinding != null && this . dimensions > 0 ) { return null ; } CompilationUnitScope scope = this . resolver . scope ( ) ; if ( scope != null ) { return this . resolver . getPackageBinding ( scope . getCurrentPackage ( ) ) ; } return null ; } public String getQualifiedName ( ) { ReferenceBinding referenceBinding = getReferenceBinding ( ) ; if ( referenceBinding != null ) { StringBuffer buffer = new StringBuffer ( ) ; char [ ] brackets = new char [ this . dimensions * 2 ] ; for ( int i = this . dimensions * 2 - 1 ; i >= 0 ; i -= 2 ) { brackets [ i ] = ']' ; brackets [ i - 1 ] = '[' ; } buffer . append ( CharOperation . toString ( referenceBinding . compoundName ) ) ; buffer . append ( brackets ) ; return String . valueOf ( buffer ) ; } else { return getName ( ) ; } } private ReferenceBinding getReferenceBinding ( ) { if ( this . binding != null ) { if ( this . binding . isArrayType ( ) ) { ArrayBinding arrayBinding = ( ArrayBinding ) this . binding ; if ( arrayBinding . leafComponentType instanceof ReferenceBinding ) { return ( ReferenceBinding ) arrayBinding . leafComponentType ; } } else if ( this . binding instanceof ReferenceBinding ) { return ( ReferenceBinding ) this . binding ; } } else if ( this . innerTypeBinding != null ) { return this . innerTypeBinding . getReferenceBinding ( ) ; } return null ; } public ITypeBinding getSuperclass ( ) { if ( getQualifiedName ( ) . equals ( "" ) ) { return null ; } return this . resolver . resolveWellKnownType ( "" ) ; } public ITypeBinding [ ] getTypeArguments ( ) { if ( this . binding != null ) { return this . typeArguments = TypeBinding . NO_TYPE_BINDINGS ; } if ( this . typeArguments != null ) { return this . typeArguments ; } if ( this . innerTypeBinding != null ) { return this . innerTypeBinding . getTypeArguments ( ) ; } if ( this . currentType . isParameterizedType ( ) ) { ParameterizedType parameterizedType = ( ParameterizedType ) this . currentType ; List typeArgumentsList = parameterizedType . typeArguments ( ) ; int size = typeArgumentsList . size ( ) ; ITypeBinding [ ] temp = new ITypeBinding [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { ITypeBinding currentTypeBinding = ( ( Type ) typeArgumentsList . get ( i ) ) . resolveBinding ( ) ; if ( currentTypeBinding == null ) { return this . typeArguments = TypeBinding . NO_TYPE_BINDINGS ; } temp [ i ] = currentTypeBinding ; } return this . typeArguments = temp ; } return this . typeArguments = TypeBinding . NO_TYPE_BINDINGS ; } public ITypeBinding [ ] getTypeBounds ( ) { return TypeBinding . NO_TYPE_BINDINGS ; } public ITypeBinding getTypeDeclaration ( ) { return this ; } public ITypeBinding [ ] getTypeParameters ( ) { return TypeBinding . NO_TYPE_BINDINGS ; } public ITypeBinding getWildcard ( ) { return null ; } public boolean isAnnotation ( ) { return false ; } public boolean isAnonymous ( ) { return false ; } public boolean isArray ( ) { return false ; } public boolean isAssignmentCompatible ( ITypeBinding typeBinding ) { if ( "" . equals ( typeBinding . getQualifiedName ( ) ) ) { return true ; } return isEqualTo ( typeBinding ) ; } public boolean isCapture ( ) { return false ; } public boolean isCastCompatible ( ITypeBinding typeBinding ) { if ( "" . equals ( typeBinding . getQualifiedName ( ) ) ) { return true ; } return isEqualTo ( typeBinding ) ; } public boolean isClass ( ) { return true ; } public boolean isEnum ( ) { return false ; } public boolean isFromSource ( ) { return false ; } public boolean isGenericType ( ) { return false ; } public boolean isInterface ( ) { return false ; } public boolean isLocal ( ) { return false ; } public boolean isMember ( ) { return false ; } public boolean isNested ( ) { return false ; } public boolean isNullType ( ) { return false ; } public boolean isParameterizedType ( ) { if ( this . innerTypeBinding != null ) { return this . innerTypeBinding . isParameterizedType ( ) ; } if ( this . currentType != null ) { return this . currentType . isParameterizedType ( ) ; } return false ; } public boolean isPrimitive ( ) { return false ; } public boolean isRawType ( ) { return false ; } public boolean isSubTypeCompatible ( ITypeBinding typeBinding ) { if ( "" . equals ( typeBinding . getQualifiedName ( ) ) ) { return true ; } return isEqualTo ( typeBinding ) ; } public boolean isTopLevel ( ) { return true ; } public boolean isTypeVariable ( ) { return false ; } public boolean isUpperbound ( ) { return false ; } public boolean isWildcardType ( ) { return false ; } public IAnnotationBinding [ ] getAnnotations ( ) { return AnnotationBinding . NoAnnotations ; } public IJavaElement getJavaElement ( ) { IPackageBinding packageBinding = getPackage ( ) ; if ( packageBinding != null ) { final IJavaElement javaElement = packageBinding . getJavaElement ( ) ; if ( javaElement != null && javaElement . getElementType ( ) == IJavaElement . PACKAGE_FRAGMENT ) { return ( ( PackageFragment ) javaElement ) . getCompilationUnit ( getInternalName ( ) + SuffixConstants . SUFFIX_STRING_java ) . getType ( this . getName ( ) ) ; } } return null ; } public String getKey ( ) { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( "Recovered#" ) ; if ( this . innerTypeBinding != null ) { buffer . append ( "" ) . append ( this . innerTypeBinding . getKey ( ) ) ; } else if ( this . currentType != null ) { buffer . append ( "currentType" ) . append ( this . currentType . toString ( ) ) ; } else if ( this . binding != null ) { buffer . append ( "typeBinding" ) . append ( this . binding . computeUniqueKey ( ) ) ; } else if ( this . variableDeclaration != null ) { buffer . append ( "" ) . append ( this . variableDeclaration . getClass ( ) ) . append ( this . variableDeclaration . getName ( ) . getIdentifier ( ) ) . append ( this . variableDeclaration . getExtraDimensions ( ) ) ; } buffer . append ( getDimensions ( ) ) ; if ( this . typeArguments != null ) { buffer . append ( '<' ) ; for ( int i = 0 , max = this . typeArguments . length ; i < max ; i ++ ) { if ( i != 0 ) { buffer . append ( ',' ) ; } buffer . append ( this . typeArguments [ i ] . getKey ( ) ) ; } buffer . append ( '>' ) ; } return String . valueOf ( buffer ) ; } public int getKind ( ) { return IBinding . TYPE ; } public boolean isDeprecated ( ) { return false ; } public boolean isEqualTo ( IBinding other ) { if ( ! other . isRecovered ( ) || other . getKind ( ) != IBinding . TYPE ) return false ; return getKey ( ) . equals ( other . getKey ( ) ) ; } public boolean isRecovered ( ) { return true ; } public boolean isSynthetic ( ) { return false ; } private String getTypeNameFrom ( Type type ) { if ( type == null ) return Util . EMPTY_STRING ; switch ( type . getNodeType0 ( ) ) { case ASTNode . ARRAY_TYPE : ArrayType arrayType = ( ArrayType ) type ; type = arrayType . getElementType ( ) ; return getTypeNameFrom ( type ) ; case ASTNode . PARAMETERIZED_TYPE : ParameterizedType parameterizedType = ( ParameterizedType ) type ; StringBuffer buffer = new StringBuffer ( getTypeNameFrom ( parameterizedType . getType ( ) ) ) ; ITypeBinding [ ] tArguments = getTypeArguments ( ) ; final int typeArgumentsLength = tArguments . length ; if ( typeArgumentsLength != 0 ) { buffer . append ( '<' ) ; for ( int i = 0 ; i < typeArgumentsLength ; i ++ ) { if ( i > 0 ) { buffer . append ( ',' ) ; } buffer . append ( tArguments [ i ] . getName ( ) ) ; } buffer . append ( '>' ) ; } return String . valueOf ( buffer ) ; case ASTNode . PRIMITIVE_TYPE : PrimitiveType primitiveType = ( PrimitiveType ) type ; return primitiveType . getPrimitiveTypeCode ( ) . toString ( ) ; case ASTNode . QUALIFIED_TYPE : QualifiedType qualifiedType = ( QualifiedType ) type ; return qualifiedType . getName ( ) . getIdentifier ( ) ; case ASTNode . SIMPLE_TYPE : SimpleType simpleType = ( SimpleType ) type ; Name name = simpleType . getName ( ) ; if ( name . isQualifiedName ( ) ) { QualifiedName qualifiedName = ( QualifiedName ) name ; return qualifiedName . getName ( ) . getIdentifier ( ) ; } return ( ( SimpleName ) name ) . getIdentifier ( ) ; } return Util . EMPTY_STRING ; } private Type getType ( ) { if ( this . currentType != null ) { return this . currentType ; } if ( this . variableDeclaration == null ) return null ; switch ( this . variableDeclaration . getNodeType ( ) ) { case ASTNode . SINGLE_VARIABLE_DECLARATION : SingleVariableDeclaration singleVariableDeclaration = ( SingleVariableDeclaration ) this . variableDeclaration ; return singleVariableDeclaration . getType ( ) ; default : ASTNode parent = this . variableDeclaration . getParent ( ) ; switch ( parent . getNodeType ( ) ) { case ASTNode . VARIABLE_DECLARATION_EXPRESSION : VariableDeclarationExpression variableDeclarationExpression = ( VariableDeclarationExpression ) parent ; return variableDeclarationExpression . getType ( ) ; case ASTNode . VARIABLE_DECLARATION_STATEMENT : VariableDeclarationStatement statement = ( VariableDeclarationStatement ) parent ; return statement . getType ( ) ; case ASTNode . FIELD_DECLARATION : FieldDeclaration fieldDeclaration = ( FieldDeclaration ) parent ; return fieldDeclaration . getType ( ) ; } } return null ; } } </s>