<s> package org . eclipse . jdt . internal . compiler . lookup ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . compiler . ast . ASTNode ; import org . eclipse . jdt . internal . compiler . ast . FieldDeclaration ; import org . eclipse . jdt . internal . compiler . ast . TypeDeclaration ; import org . eclipse . jdt . internal . compiler . classfmt . ClassFileConstants ; import org . eclipse . jdt . internal . compiler . impl . Constant ; public class FieldBinding extends VariableBinding { public ReferenceBinding declaringClass ; protected FieldBinding ( ) { super ( null , null , 0 , null ) ; } public FieldBinding ( char [ ] name , TypeBinding type , int modifiers , ReferenceBinding declaringClass , Constant constant ) { super ( name , type , modifiers , constant ) ; this . declaringClass = declaringClass ; } public FieldBinding ( FieldBinding initialFieldBinding , ReferenceBinding declaringClass ) { super ( initialFieldBinding . name , initialFieldBinding . type , initialFieldBinding . modifiers , initialFieldBinding . constant ( ) ) ; this . declaringClass = declaringClass ; this . id = initialFieldBinding . id ; setAnnotations ( initialFieldBinding . getAnnotations ( ) ) ; } public FieldBinding ( FieldDeclaration field , TypeBinding type , int modifiers , ReferenceBinding declaringClass ) { this ( field . name , type , modifiers , declaringClass , null ) ; field . binding = this ; } public final boolean canBeSeenBy ( PackageBinding invocationPackage ) { if ( isPublic ( ) ) return true ; if ( isPrivate ( ) ) return false ; return invocationPackage == this . declaringClass . getPackage ( ) ; } public final boolean canBeSeenBy ( TypeBinding receiverType , InvocationSite invocationSite , Scope scope ) { if ( isPublic ( ) ) return true ; SourceTypeBinding invocationType = scope . enclosingSourceType ( ) ; if ( invocationType == this . declaringClass && invocationType == receiverType ) return true ; if ( invocationType == null ) return ! isPrivate ( ) && scope . getCurrentPackage ( ) == this . declaringClass . fPackage ; if ( isProtected ( ) ) { if ( invocationType == this . declaringClass ) return true ; if ( invocationType . fPackage == this . declaringClass . fPackage ) return true ; ReferenceBinding currentType = invocationType ; int depth = 0 ; ReferenceBinding receiverErasure = ( ReferenceBinding ) receiverType . erasure ( ) ; ReferenceBinding declaringErasure = ( ReferenceBinding ) this . declaringClass . erasure ( ) ; do { if ( currentType . findSuperTypeOriginatingFrom ( declaringErasure ) != null ) { if ( invocationSite . isSuperAccess ( ) ) return true ; if ( receiverType instanceof ArrayBinding ) return false ; if ( isStatic ( ) ) { if ( depth > 0 ) invocationSite . setDepth ( depth ) ; return true ; } if ( currentType == receiverErasure || receiverErasure . findSuperTypeOriginatingFrom ( currentType ) != null ) { if ( depth > 0 ) invocationSite . setDepth ( depth ) ; return true ; } } depth ++ ; currentType = currentType . enclosingType ( ) ; } while ( currentType != null ) ; return false ; } if ( isPrivate ( ) ) { receiverCheck : { if ( receiverType != this . declaringClass ) { if ( receiverType . isTypeVariable ( ) && ( ( TypeVariableBinding ) receiverType ) . isErasureBoundTo ( this . declaringClass . erasure ( ) ) ) break receiverCheck ; return false ; } } if ( invocationType != this . declaringClass ) { ReferenceBinding outerInvocationType = invocationType ; ReferenceBinding temp = outerInvocationType . enclosingType ( ) ; while ( temp != null ) { outerInvocationType = temp ; temp = temp . enclosingType ( ) ; } ReferenceBinding outerDeclaringClass = ( ReferenceBinding ) this . declaringClass . erasure ( ) ; temp = outerDeclaringClass . enclosingType ( ) ; while ( temp != null ) { outerDeclaringClass = temp ; temp = temp . enclosingType ( ) ; } if ( outerInvocationType != outerDeclaringClass ) return false ; } return true ; } PackageBinding declaringPackage = this . declaringClass . fPackage ; if ( invocationType . fPackage != declaringPackage ) return false ; if ( receiverType instanceof ArrayBinding ) return false ; TypeBinding originalDeclaringClass = this . declaringClass . original ( ) ; ReferenceBinding currentType = ( ReferenceBinding ) receiverType ; do { if ( currentType . isCapture ( ) ) { if ( originalDeclaringClass == currentType . erasure ( ) . original ( ) ) return true ; } else { if ( originalDeclaringClass == currentType . original ( ) ) return true ; } PackageBinding currentPackage = currentType . fPackage ; if ( currentPackage != null && currentPackage != declaringPackage ) return false ; } while ( ( currentType = currentType . superclass ( ) ) != null ) ; return false ; } public char [ ] computeUniqueKey ( boolean isLeaf ) { char [ ] declaringKey = this . declaringClass == null ? CharOperation . NO_CHAR : this . declaringClass . computeUniqueKey ( false ) ; int declaringLength = declaringKey . length ; int nameLength = this . name . length ; char [ ] returnTypeKey = this . type == null ? new char [ ] { 'V' } : this . type . computeUniqueKey ( false ) ; int returnTypeLength = returnTypeKey . length ; char [ ] uniqueKey = new char [ declaringLength + 1 + nameLength + 1 + returnTypeLength ] ; int index = 0 ; System . arraycopy ( declaringKey , 0 , uniqueKey , index , declaringLength ) ; index += declaringLength ; uniqueKey [ index ++ ] = '.' ; System . arraycopy ( this . name , 0 , uniqueKey , index , nameLength ) ; index += nameLength ; uniqueKey [ index ++ ] = ')' ; System . arraycopy ( returnTypeKey , 0 , uniqueKey , index , returnTypeLength ) ; return uniqueKey ; } public Constant constant ( ) { Constant fieldConstant = this . constant ; if ( fieldConstant == null ) { if ( isFinal ( ) ) { FieldBinding originalField = original ( ) ; if ( originalField . declaringClass instanceof SourceTypeBinding ) { SourceTypeBinding sourceType = ( SourceTypeBinding ) originalField . declaringClass ; if ( sourceType . scope != null ) { TypeDeclaration typeDecl = sourceType . scope . referenceContext ; FieldDeclaration fieldDecl = typeDecl . declarationOf ( originalField ) ; MethodScope initScope = originalField . isStatic ( ) ? typeDecl . staticInitializerScope : typeDecl . initializerScope ; boolean old = initScope . insideTypeAnnotation ; try { initScope . insideTypeAnnotation = false ; fieldDecl . resolve ( initScope ) ; } finally { initScope . insideTypeAnnotation = old ; } fieldConstant = originalField . constant == null ? Constant . NotAConstant : originalField . constant ; } else { fieldConstant = Constant . NotAConstant ; } } else { fieldConstant = Constant . NotAConstant ; } } else { fieldConstant = Constant . NotAConstant ; } this . constant = fieldConstant ; } return fieldConstant ; } public char [ ] genericSignature ( ) { if ( ( this . modifiers & ExtraCompilerModifiers . AccGenericSignature ) == 0 ) return null ; return this . type . genericTypeSignature ( ) ; } public final int getAccessFlags ( ) { return this . modifiers & ExtraCompilerModifiers . AccJustFlag ; } public AnnotationBinding [ ] getAnnotations ( ) { FieldBinding originalField = original ( ) ; ReferenceBinding declaringClassBinding = originalField . declaringClass ; if ( declaringClassBinding == null ) { return Binding . NO_ANNOTATIONS ; } return declaringClassBinding . retrieveAnnotations ( originalField ) ; } public long getAnnotationTagBits ( ) { FieldBinding originalField = original ( ) ; if ( ( originalField . tagBits & TagBits . AnnotationResolved ) == 0 && originalField . declaringClass instanceof SourceTypeBinding ) { ClassScope scope = ( ( SourceTypeBinding ) originalField . declaringClass ) . scope ; if ( scope == null ) { this . tagBits |= ( TagBits . AnnotationResolved | TagBits . DeprecatedAnnotationResolved ) ; return 0 ; } TypeDeclaration typeDecl = scope . referenceContext ; FieldDeclaration fieldDecl = typeDecl . declarationOf ( originalField ) ; if ( fieldDecl != null ) { MethodScope initializationScope = isStatic ( ) ? typeDecl . staticInitializerScope : typeDecl . initializerScope ; FieldBinding previousField = initializationScope . initializedField ; int previousFieldID = initializationScope . lastVisibleFieldID ; try { initializationScope . initializedField = originalField ; initializationScope . lastVisibleFieldID = originalField . id ; ASTNode . resolveAnnotations ( initializationScope , fieldDecl . annotations , originalField ) ; } finally { initializationScope . initializedField = previousField ; initializationScope . lastVisibleFieldID = previousFieldID ; } } } return originalField . tagBits ; } public final boolean isDefault ( ) { return ! isPublic ( ) && ! isProtected ( ) && ! isPrivate ( ) ; } public final boolean isDeprecated ( ) { return ( this . modifiers & ClassFileConstants . AccDeprecated ) != 0 ; } public final boolean isPrivate ( ) { return ( this . modifiers & ClassFileConstants . AccPrivate ) != 0 ; } public final boolean isOrEnclosedByPrivateType ( ) { if ( ( this . modifiers & ClassFileConstants . AccPrivate ) != 0 ) return true ; return this . declaringClass != null && this . declaringClass . isOrEnclosedByPrivateType ( ) ; } public final boolean isProtected ( ) { return ( this . modifiers & ClassFileConstants . AccProtected ) != 0 ; } public final boolean isPublic ( ) { return ( this . modifiers & ClassFileConstants . AccPublic ) != 0 ; } public final boolean isStatic ( ) { return ( this . modifiers & ClassFileConstants . AccStatic ) != 0 ; } public final boolean isSynthetic ( ) { return ( this . modifiers & ClassFileConstants . AccSynthetic ) != 0 ; } public final boolean isTransient ( ) { return ( this . modifiers & ClassFileConstants . AccTransient ) != 0 ; } public final boolean isUsed ( ) { return ( this . modifiers & ExtraCompilerModifiers . AccLocallyUsed ) != 0 ; } public final boolean isViewedAsDeprecated ( ) { return ( this . modifiers & ( ClassFileConstants . AccDeprecated | ExtraCompilerModifiers . AccDeprecatedImplicitly ) ) != 0 ; } public final boolean isVolatile ( ) { return ( this . modifiers & ClassFileConstants . AccVolatile ) != 0 ; } public final int kind ( ) { return FIELD ; } public FieldBinding original ( ) { return this ; } public void setAnnotations ( AnnotationBinding [ ] annotations ) { this . declaringClass . storeAnnotations ( this , annotations ) ; } public FieldDeclaration sourceField ( ) { SourceTypeBinding sourceType ; try { sourceType = ( SourceTypeBinding ) this . declaringClass ; } catch ( ClassCastException e ) { return null ; } FieldDeclaration [ ] fields = sourceType . scope . referenceContext . fields ; if ( fields != null ) { for ( int i = fields . length ; -- i >= 0 ; ) if ( this == fields [ i ] . binding ) return fields [ i ] ; } return null ; } } </s>