<s> package org . eclipse . jdt . internal . eval ; import org . eclipse . jdt . internal . compiler . ast . ASTNode ; import org . eclipse . jdt . internal . compiler . ast . Assignment ; import org . eclipse . jdt . internal . compiler . ast . CompoundAssignment ; import org . eclipse . jdt . internal . compiler . ast . Expression ; import org . eclipse . jdt . internal . compiler . ast . IntLiteral ; import org . eclipse . jdt . internal . compiler . ast . QualifiedNameReference ; import org . eclipse . jdt . internal . compiler . classfmt . ClassFileConstants ; import org . eclipse . jdt . internal . compiler . codegen . CodeStream ; import org . eclipse . jdt . internal . compiler . codegen . Opcodes ; import org . eclipse . jdt . internal . compiler . flow . FlowInfo ; import org . eclipse . jdt . internal . compiler . impl . Constant ; import org . eclipse . jdt . internal . compiler . lookup . Binding ; import org . eclipse . jdt . internal . compiler . lookup . BlockScope ; import org . eclipse . jdt . internal . compiler . lookup . FieldBinding ; import org . eclipse . jdt . internal . compiler . lookup . LocalVariableBinding ; import org . eclipse . jdt . internal . compiler . lookup . MethodBinding ; import org . eclipse . jdt . internal . compiler . lookup . MethodScope ; import org . eclipse . jdt . internal . compiler . lookup . ProblemBinding ; import org . eclipse . jdt . internal . compiler . lookup . ProblemFieldBinding ; import org . eclipse . jdt . internal . compiler . lookup . ProblemReasons ; import org . eclipse . jdt . internal . compiler . lookup . ReferenceBinding ; import org . eclipse . jdt . internal . compiler . lookup . TypeBinding ; import org . eclipse . jdt . internal . compiler . lookup . TypeIds ; import org . eclipse . jdt . internal . compiler . lookup . VariableBinding ; public class CodeSnippetQualifiedNameReference extends QualifiedNameReference implements EvaluationConstants , ProblemReasons { EvaluationContext evaluationContext ; FieldBinding delegateThis ; public CodeSnippetQualifiedNameReference ( char [ ] [ ] sources , long [ ] positions , int sourceStart , int sourceEnd , EvaluationContext evaluationContext ) { super ( sources , positions , sourceStart , sourceEnd ) ; this . evaluationContext = evaluationContext ; } public TypeBinding checkFieldAccess ( BlockScope scope ) { FieldBinding fieldBinding = ( FieldBinding ) this . binding ; MethodScope methodScope = scope . methodScope ( ) ; TypeBinding declaringClass = fieldBinding . original ( ) . declaringClass ; if ( ( this . indexOfFirstFieldBinding == 1 || declaringClass . isEnum ( ) ) && methodScope . enclosingSourceType ( ) == declaringClass && methodScope . lastVisibleFieldID >= 0 && fieldBinding . id >= methodScope . lastVisibleFieldID && ( ! fieldBinding . isStatic ( ) || methodScope . isStatic ) ) { scope . problemReporter ( ) . forwardReference ( this , this . indexOfFirstFieldBinding - 1 , fieldBinding ) ; } this . bits &= ~ ASTNode . RestrictiveFlagMASK ; this . bits |= Binding . FIELD ; return getOtherFieldBindings ( scope ) ; } public void generateCode ( BlockScope currentScope , CodeStream codeStream , boolean valueRequired ) { int pc = codeStream . position ; if ( ( this . bits & Binding . VARIABLE ) == 0 ) { codeStream . recordPositionsFrom ( pc , this . sourceStart ) ; return ; } FieldBinding lastFieldBinding = this . otherBindings == null ? ( FieldBinding ) this . binding : this . otherBindings [ this . otherBindings . length - 1 ] ; if ( lastFieldBinding . canBeSeenBy ( getFinalReceiverType ( ) , this , currentScope ) ) { super . generateCode ( currentScope , codeStream , valueRequired ) ; return ; } lastFieldBinding = generateReadSequence ( currentScope , codeStream ) ; if ( lastFieldBinding != null ) { boolean isStatic = lastFieldBinding . isStatic ( ) ; Constant fieldConstant = lastFieldBinding . constant ( ) ; if ( fieldConstant != Constant . NotAConstant ) { if ( ! isStatic ) { codeStream . invokeObjectGetClass ( ) ; codeStream . pop ( ) ; } if ( valueRequired ) { codeStream . generateConstant ( fieldConstant , this . implicitConversion ) ; } } else { boolean isFirst = lastFieldBinding == this . binding && ( this . indexOfFirstFieldBinding == 1 || lastFieldBinding . declaringClass == currentScope . enclosingReceiverType ( ) ) && this . otherBindings == null ; TypeBinding requiredGenericCast = getGenericCast ( this . otherBindings == null ? 0 : this . otherBindings . length ) ; if ( valueRequired || ( ! isFirst && currentScope . compilerOptions ( ) . complianceLevel >= ClassFileConstants . JDK1_4 ) || ( ( this . implicitConversion & TypeIds . UNBOXING ) != 0 ) || requiredGenericCast != null ) { int lastFieldPc = codeStream . position ; if ( lastFieldBinding . declaringClass == null ) { codeStream . arraylength ( ) ; if ( valueRequired ) { codeStream . generateImplicitConversion ( this . implicitConversion ) ; } else { codeStream . pop ( ) ; } } else { codeStream . generateEmulatedReadAccessForField ( lastFieldBinding ) ; if ( requiredGenericCast != null ) codeStream . checkcast ( requiredGenericCast ) ; if ( valueRequired ) { codeStream . generateImplicitConversion ( this . implicitConversion ) ; } else { boolean isUnboxing = ( this . implicitConversion & TypeIds . UNBOXING ) != 0 ; if ( isUnboxing ) codeStream . generateImplicitConversion ( this . implicitConversion ) ; switch ( isUnboxing ? postConversionType ( currentScope ) . id : lastFieldBinding . type . id ) { case T_long : case T_double : codeStream . pop2 ( ) ; break ; default : codeStream . pop ( ) ; } } } int fieldPosition = ( int ) ( this . sourcePositions [ this . sourcePositions . length - 1 ] >>> 32 ) ; codeStream . recordPositionsFrom ( lastFieldPc , fieldPosition ) ; } else { if ( ! isStatic ) { codeStream . invokeObjectGetClass ( ) ; codeStream . pop ( ) ; } } } } codeStream . recordPositionsFrom ( pc , this . sourceStart ) ; } public void generateAssignment ( BlockScope currentScope , CodeStream codeStream , Assignment assignment , boolean valueRequired ) { FieldBinding lastFieldBinding = this . otherBindings == null ? ( FieldBinding ) this . binding : this . otherBindings [ this . otherBindings . length - 1 ] ; if ( lastFieldBinding . canBeSeenBy ( getFinalReceiverType ( ) , this , currentScope ) ) { super . generateAssignment ( currentScope , codeStream , assignment , valueRequired ) ; return ; } lastFieldBinding = generateReadSequence ( currentScope , codeStream ) ; codeStream . generateEmulationForField ( lastFieldBinding ) ; codeStream . swap ( ) ; assignment . expression . generateCode ( currentScope , codeStream , true ) ; if ( valueRequired ) { switch ( lastFieldBinding . type . id ) { case TypeIds . T_long : case TypeIds . T_double : codeStream . dup2_x2 ( ) ; break ; default : codeStream . dup_x2 ( ) ; break ; } } codeStream . generateEmulatedWriteAccessForField ( lastFieldBinding ) ; if ( valueRequired ) { codeStream . generateImplicitConversion ( assignment . implicitConversion ) ; } } public void generateCompoundAssignment ( BlockScope currentScope , CodeStream codeStream , Expression expression , int operator , int assignmentImplicitConversion , boolean valueRequired ) { FieldBinding lastFieldBinding = this . otherBindings == null ? ( FieldBinding ) this . binding : this . otherBindings [ this . otherBindings . length - 1 ] ; if ( lastFieldBinding . canBeSeenBy ( getFinalReceiverType ( ) , this , currentScope ) ) { super . generateCompoundAssignment ( currentScope , codeStream , expression , operator , assignmentImplicitConversion , valueRequired ) ; return ; } lastFieldBinding = generateReadSequence ( currentScope , codeStream ) ; if ( lastFieldBinding . isStatic ( ) ) { codeStream . generateEmulationForField ( lastFieldBinding ) ; codeStream . swap ( ) ; codeStream . aconst_null ( ) ; codeStream . swap ( ) ; codeStream . generateEmulatedReadAccessForField ( lastFieldBinding ) ; } else { codeStream . generateEmulationForField ( lastFieldBinding ) ; codeStream . swap ( ) ; codeStream . dup ( ) ; codeStream . generateEmulatedReadAccessForField ( lastFieldBinding ) ; } int operationTypeID ; if ( ( operationTypeID = ( this . implicitConversion & IMPLICIT_CONVERSION_MASK ) >> 4 ) == T_JavaLangString ) { codeStream . generateStringConcatenationAppend ( currentScope , null , expression ) ; } else { codeStream . generateImplicitConversion ( this . implicitConversion ) ; if ( expression == IntLiteral . One ) { codeStream . generateConstant ( expression . constant , this . implicitConversion ) ; } else { expression . generateCode ( currentScope , codeStream , true ) ; } codeStream . sendOperator ( operator , operationTypeID ) ; codeStream . generateImplicitConversion ( assignmentImplicitConversion ) ; } if ( valueRequired ) { switch ( lastFieldBinding . type . id ) { case TypeIds . T_long : case TypeIds . T_double : codeStream . dup2_x2 ( ) ; break ; default : codeStream . dup_x2 ( ) ; break ; } } codeStream . generateEmulatedWriteAccessForField ( lastFieldBinding ) ; } public void generatePostIncrement ( BlockScope currentScope , CodeStream codeStream , CompoundAssignment postIncrement , boolean valueRequired ) { FieldBinding lastFieldBinding = this . otherBindings == null ? ( FieldBinding ) this . binding : this . otherBindings [ this . otherBindings . length - 1 ] ; if ( lastFieldBinding . canBeSeenBy ( getFinalReceiverType ( ) , this , currentScope ) ) { super . generatePostIncrement ( currentScope , codeStream , postIncrement , valueRequired ) ; return ; } lastFieldBinding = generateReadSequence ( currentScope , codeStream ) ; codeStream . generateEmulatedReadAccessForField ( lastFieldBinding ) ; if ( valueRequired ) { switch ( lastFieldBinding . type . id ) { case TypeIds . T_long : case TypeIds . T_double : codeStream . dup2 ( ) ; break ; default : codeStream . dup ( ) ; break ; } } codeStream . generateEmulationForField ( lastFieldBinding ) ; if ( ( lastFieldBinding . type == TypeBinding . LONG ) || ( lastFieldBinding . type == TypeBinding . DOUBLE ) ) { codeStream . dup_x2 ( ) ; codeStream . pop ( ) ; if ( lastFieldBinding . isStatic ( ) ) { codeStream . aconst_null ( ) ; } else { generateReadSequence ( currentScope , codeStream ) ; } codeStream . dup_x2 ( ) ; codeStream . pop ( ) ; } else { codeStream . dup_x1 ( ) ; codeStream . pop ( ) ; if ( lastFieldBinding . isStatic ( ) ) { codeStream . aconst_null ( ) ; } else { generateReadSequence ( currentScope , codeStream ) ; } codeStream . dup_x1 ( ) ; codeStream . pop ( ) ; } codeStream . generateConstant ( postIncrement . expression . constant , this . implicitConversion ) ; codeStream . sendOperator ( postIncrement . operator , lastFieldBinding . type . id ) ; codeStream . generateImplicitConversion ( postIncrement . preAssignImplicitConversion ) ; codeStream . generateEmulatedWriteAccessForField ( lastFieldBinding ) ; } public FieldBinding generateReadSequence ( BlockScope currentScope , CodeStream codeStream ) { int otherBindingsCount = this . otherBindings == null ? 0 : this . otherBindings . length ; boolean needValue = otherBindingsCount == 0 || ! this . otherBindings [ 0 ] . isStatic ( ) ; FieldBinding lastFieldBinding ; TypeBinding lastGenericCast ; TypeBinding lastReceiverType ; boolean complyTo14 = currentScope . compilerOptions ( ) . complianceLevel >= ClassFileConstants . JDK1_4 ; switch ( this . bits & RestrictiveFlagMASK ) { case Binding . FIELD : lastFieldBinding = ( ( FieldBinding ) this . binding ) . original ( ) ; lastGenericCast = this . genericCast ; lastReceiverType = this . actualReceiverType ; if ( lastFieldBinding . constant ( ) != Constant . NotAConstant ) { break ; } if ( needValue ) { if ( lastFieldBinding . canBeSeenBy ( this . actualReceiverType , this , currentScope ) ) { if ( ! lastFieldBinding . isStatic ( ) ) { if ( ( this . bits & DepthMASK ) != 0 ) { ReferenceBinding targetType = currentScope . enclosingSourceType ( ) . enclosingTypeAt ( ( this . bits & DepthMASK ) >> DepthSHIFT ) ; Object [ ] emulationPath = currentScope . getEmulationPath ( targetType , true , false ) ; codeStream . generateOuterAccess ( emulationPath , this , targetType , currentScope ) ; } else { generateReceiver ( codeStream ) ; } } } else { if ( ! lastFieldBinding . isStatic ( ) ) { if ( ( this . bits & DepthMASK ) != 0 ) { currentScope . problemReporter ( ) . needImplementation ( this ) ; } else { generateReceiver ( codeStream ) ; } } else { codeStream . aconst_null ( ) ; } } } break ; case Binding . LOCAL : lastFieldBinding = null ; lastGenericCast = null ; LocalVariableBinding localBinding = ( LocalVariableBinding ) this . binding ; lastReceiverType = localBinding . type ; if ( ! needValue ) break ; Constant localConstant = localBinding . constant ( ) ; if ( localConstant != Constant . NotAConstant ) { codeStream . generateConstant ( localConstant , 0 ) ; } else { if ( ( this . bits & DepthMASK ) != 0 ) { VariableBinding [ ] path = currentScope . getEmulationPath ( localBinding ) ; codeStream . generateOuterAccess ( path , this , localBinding , currentScope ) ; } else { codeStream . load ( localBinding ) ; } } break ; default : return null ; } int positionsLength = this . sourcePositions . length ; FieldBinding initialFieldBinding = lastFieldBinding ; if ( this . otherBindings != null ) { for ( int i = 0 ; i < otherBindingsCount ; i ++ ) { int pc = codeStream . position ; FieldBinding nextField = this . otherBindings [ i ] . original ( ) ; TypeBinding nextGenericCast = this . otherGenericCasts == null ? null : this . otherGenericCasts [ i ] ; if ( lastFieldBinding != null ) { needValue = ! nextField . isStatic ( ) ; Constant fieldConstant = lastFieldBinding . constant ( ) ; if ( fieldConstant != Constant . NotAConstant ) { if ( i > 0 && ! lastFieldBinding . isStatic ( ) ) { codeStream . invokeObjectGetClass ( ) ; codeStream . pop ( ) ; } if ( needValue ) { codeStream . generateConstant ( fieldConstant , 0 ) ; } } else { if ( needValue || ( i > 0 && complyTo14 ) || lastGenericCast != null ) { if ( lastFieldBinding . canBeSeenBy ( lastReceiverType , this , currentScope ) ) { MethodBinding accessor = this . syntheticReadAccessors == null ? null : this . syntheticReadAccessors [ i ] ; if ( accessor == null ) { TypeBinding constantPoolDeclaringClass = CodeStream . getConstantPoolDeclaringClass ( currentScope , lastFieldBinding , lastReceiverType , i == 0 && this . indexOfFirstFieldBinding == 1 ) ; if ( lastFieldBinding . isStatic ( ) ) { codeStream . fieldAccess ( Opcodes . OPC_getstatic , lastFieldBinding , constantPoolDeclaringClass ) ; } else { codeStream . fieldAccess ( Opcodes . OPC_getfield , lastFieldBinding , constantPoolDeclaringClass ) ; } } else { codeStream . invoke ( Opcodes . OPC_invokestatic , accessor , null ) ; } } else { codeStream . generateEmulatedReadAccessForField ( lastFieldBinding ) ; } if ( lastGenericCast != null ) { codeStream . checkcast ( lastGenericCast ) ; lastReceiverType = lastGenericCast ; } else { lastReceiverType = lastFieldBinding . type ; } if ( ! needValue ) codeStream . pop ( ) ; } else { if ( lastFieldBinding == initialFieldBinding ) { if ( lastFieldBinding . isStatic ( ) ) { if ( initialFieldBinding . declaringClass != this . actualReceiverType . erasure ( ) ) { if ( lastFieldBinding . canBeSeenBy ( lastReceiverType , this , currentScope ) ) { MethodBinding accessor = this . syntheticReadAccessors == null ? null : this . syntheticReadAccessors [ i ] ; if ( accessor == null ) { TypeBinding constantPoolDeclaringClass = CodeStream . getConstantPoolDeclaringClass ( currentScope , lastFieldBinding , lastReceiverType , i == 0 && this . indexOfFirstFieldBinding == 1 ) ; codeStream . fieldAccess ( Opcodes . OPC_getstatic , lastFieldBinding , constantPoolDeclaringClass ) ; } else { codeStream . invoke ( Opcodes . OPC_invokestatic , accessor , null ) ; } } else { codeStream . generateEmulatedReadAccessForField ( lastFieldBinding ) ; } codeStream . pop ( ) ; } } } else if ( ! lastFieldBinding . isStatic ( ) ) { codeStream . invokeObjectGetClass ( ) ; codeStream . pop ( ) ; } lastReceiverType = lastFieldBinding . type ; } if ( ( positionsLength - otherBindingsCount + i - 1 ) >= 0 ) { int fieldPosition = ( int ) ( this . sourcePositions [ positionsLength - otherBindingsCount + i - 1 ] >>> 32 ) ; codeStream . recordPositionsFrom ( pc , fieldPosition ) ; } } } lastFieldBinding = nextField ; lastGenericCast = nextGenericCast ; if ( lastFieldBinding != null && ! lastFieldBinding . canBeSeenBy ( lastReceiverType , this , currentScope ) ) { if ( lastFieldBinding . isStatic ( ) ) { codeStream . aconst_null ( ) ; } } } } return lastFieldBinding ; } public void generateReceiver ( CodeStream codeStream ) { codeStream . aload_0 ( ) ; if ( this . delegateThis != null ) { codeStream . fieldAccess ( Opcodes . OPC_getfield , this . delegateThis , null ) ; } } public TypeBinding getOtherFieldBindings ( BlockScope scope ) { int length = this . tokens . length ; if ( ( this . bits & Binding . FIELD ) != 0 ) { if ( ! ( ( FieldBinding ) this . binding ) . isStatic ( ) ) { if ( this . indexOfFirstFieldBinding == 1 ) { if ( scope . methodScope ( ) . isStatic ) { scope . problemReporter ( ) . staticFieldAccessToNonStaticVariable ( this , ( FieldBinding ) this . binding ) ; return null ; } } else { scope . problemReporter ( ) . staticFieldAccessToNonStaticVariable ( this , ( FieldBinding ) this . binding ) ; return null ; } } if ( isFieldUseDeprecated ( ( FieldBinding ) this . binding , scope , this . indexOfFirstFieldBinding == length ? this . bits : 0 ) ) { scope . problemReporter ( ) . deprecatedField ( ( FieldBinding ) this . binding , this ) ; } } TypeBinding type = ( ( VariableBinding ) this . binding ) . type ; int index = this . indexOfFirstFieldBinding ; if ( index == length ) { this . constant = ( ( FieldBinding ) this . binding ) . constant ( ) ; return type ; } int otherBindingsLength = length - index ; this . otherBindings = new FieldBinding [ otherBindingsLength ] ; this . constant = ( ( VariableBinding ) this . binding ) . constant ( ) ; while ( index < length ) { char [ ] token = this . tokens [ index ] ; if ( type == null ) return null ; FieldBinding field = scope . getField ( type , token , this ) ; int place = index - this . indexOfFirstFieldBinding ; this . otherBindings [ place ] = field ; if ( ! field . isValidBinding ( ) ) { CodeSnippetScope localScope = new CodeSnippetScope ( scope ) ; if ( this . delegateThis == null ) { if ( this . evaluationContext . declaringTypeName != null ) { this . delegateThis = scope . getField ( scope . enclosingSourceType ( ) , DELEGATE_THIS , this ) ; if ( this . delegateThis == null ) { return super . reportError ( scope ) ; } this . actualReceiverType = this . delegateThis . type ; } else { this . constant = Constant . NotAConstant ; scope . problemReporter ( ) . invalidField ( this , field , index , type ) ; return null ; } } field = localScope . getFieldForCodeSnippet ( this . delegateThis . type , token , this ) ; this . otherBindings [ place ] = field ; } if ( field . isValidBinding ( ) ) { if ( isFieldUseDeprecated ( field , scope , index + 1 == length ? this . bits : 0 ) ) { scope . problemReporter ( ) . deprecatedField ( field , this ) ; } if ( this . constant != Constant . NotAConstant ) { this . constant = field . constant ( ) ; } type = field . type ; index ++ ; } else { this . constant = Constant . NotAConstant ; scope . problemReporter ( ) . invalidField ( this , field , index , type ) ; return null ; } } return ( this . otherBindings [ otherBindingsLength - 1 ] ) . type ; } public void manageSyntheticAccessIfNecessary ( BlockScope currentScope , FieldBinding fieldBinding , int index , FlowInfo flowInfo ) { } public TypeBinding reportError ( BlockScope scope ) { if ( this . evaluationContext . declaringTypeName != null ) { this . delegateThis = scope . getField ( scope . enclosingSourceType ( ) , DELEGATE_THIS , this ) ; if ( this . delegateThis == null ) { return super . reportError ( scope ) ; } this . actualReceiverType = this . delegateThis . type ; } else { return super . reportError ( scope ) ; } if ( ( this . binding instanceof ProblemFieldBinding && ( ( ProblemFieldBinding ) this . binding ) . problemId ( ) == NotFound ) || ( this . binding instanceof ProblemBinding && ( ( ProblemBinding ) this . binding ) . problemId ( ) == NotFound ) ) { FieldBinding fieldBinding = scope . getField ( this . delegateThis . type , this . tokens [ 0 ] , this ) ; if ( ! fieldBinding . isValidBinding ( ) ) { if ( ( ( ProblemFieldBinding ) fieldBinding ) . problemId ( ) == NotVisible ) { CodeSnippetScope localScope = new CodeSnippetScope ( scope ) ; this . binding = localScope . getFieldForCodeSnippet ( this . delegateThis . type , this . tokens [ 0 ] , this ) ; if ( this . binding . isValidBinding ( ) ) { return checkFieldAccess ( scope ) ; } else { return super . reportError ( scope ) ; } } else { return super . reportError ( scope ) ; } } this . binding = fieldBinding ; return checkFieldAccess ( scope ) ; } TypeBinding result ; if ( this . binding instanceof ProblemFieldBinding && ( ( ProblemFieldBinding ) this . binding ) . problemId ( ) == NotVisible ) { CodeSnippetScope localScope = new CodeSnippetScope ( scope ) ; if ( ( this . binding = localScope . getBinding ( this . tokens , this . bits & RestrictiveFlagMASK , this , ( ReferenceBinding ) this . delegateThis . type ) ) . isValidBinding ( ) ) { this . bits &= ~ RestrictiveFlagMASK ; this . bits |= Binding . FIELD ; result = getOtherFieldBindings ( scope ) ; } else { return super . reportError ( scope ) ; } if ( result != null && result . isValidBinding ( ) ) { return result ; } } return super . reportError ( scope ) ; } } </s>