<s> package org . eclipse . jdt . internal . compiler . lookup ; import org . eclipse . jdt . internal . compiler . ast . * ; import org . eclipse . jdt . internal . compiler . classfmt . ClassFileConstants ; import org . eclipse . jdt . internal . compiler . codegen . CodeStream ; import org . eclipse . jdt . internal . compiler . flow . FlowInfo ; import org . eclipse . jdt . internal . compiler . flow . UnconditionalFlowInfo ; import org . eclipse . jdt . internal . compiler . impl . ReferenceContext ; import org . eclipse . jdt . internal . compiler . problem . ProblemReporter ; public class MethodScope extends BlockScope { public ReferenceContext referenceContext ; public boolean isStatic ; public boolean isConstructorCall = false ; public FieldBinding initializedField ; public int lastVisibleFieldID = - 1 ; public int analysisIndex ; public boolean isPropagatingInnerClassEmulation ; public int lastIndex = 0 ; public long [ ] definiteInits = new long [ 4 ] ; public long [ ] [ ] extraDefiniteInits = new long [ 4 ] [ ] ; public boolean insideTypeAnnotation = false ; public SyntheticArgumentBinding [ ] extraSyntheticArguments ; public MethodScope ( ClassScope parent , ReferenceContext context , boolean isStatic ) { super ( METHOD_SCOPE , parent ) ; this . locals = new LocalVariableBinding [ 5 ] ; this . referenceContext = context ; this . isStatic = isStatic ; this . startIndex = 0 ; } String basicToString ( int tab ) { String newLine = "n" ; for ( int i = tab ; -- i >= 0 ; ) newLine += "t" ; String s = newLine + "" ; newLine += "t" ; s += newLine + "locals:" ; for ( int i = 0 ; i < this . localIndex ; i ++ ) s += newLine + "t" + this . locals [ i ] . toString ( ) ; s += newLine + "" + this . startIndex ; s += newLine + "" + this . isConstructorCall ; s += newLine + "" + this . initializedField ; s += newLine + "" + this . lastVisibleFieldID ; s += newLine + "" + this . referenceContext ; return s ; } private void checkAndSetModifiersForConstructor ( MethodBinding methodBinding ) { int modifiers = methodBinding . modifiers ; final ReferenceBinding declaringClass = methodBinding . declaringClass ; if ( ( modifiers & ExtraCompilerModifiers . AccAlternateModifierProblem ) != 0 ) problemReporter ( ) . duplicateModifierForMethod ( declaringClass , ( AbstractMethodDeclaration ) this . referenceContext ) ; if ( ( ( ( ConstructorDeclaration ) this . referenceContext ) . bits & ASTNode . IsDefaultConstructor ) != 0 ) { final int DECLARING_FLAGS = ClassFileConstants . AccEnum | ClassFileConstants . AccPublic | ClassFileConstants . AccProtected ; final int VISIBILITY_FLAGS = ClassFileConstants . AccPrivate | ClassFileConstants . AccPublic | ClassFileConstants . AccProtected ; int flags ; if ( ( flags = declaringClass . modifiers & DECLARING_FLAGS ) != 0 ) { if ( ( flags & ClassFileConstants . AccEnum ) != 0 ) { modifiers &= ~ VISIBILITY_FLAGS ; modifiers |= ClassFileConstants . AccPrivate ; } else { modifiers &= ~ VISIBILITY_FLAGS ; modifiers |= flags ; } } } int realModifiers = modifiers & ExtraCompilerModifiers . AccJustFlag ; final int UNEXPECTED_MODIFIERS = ~ ( ClassFileConstants . AccPublic | ClassFileConstants . AccPrivate | ClassFileConstants . AccProtected | ClassFileConstants . AccStrictfp ) ; if ( declaringClass . isEnum ( ) && ( ( ( ConstructorDeclaration ) this . referenceContext ) . bits & ASTNode . IsDefaultConstructor ) == 0 ) { final int UNEXPECTED_ENUM_CONSTR_MODIFIERS = ~ ( ClassFileConstants . AccPrivate | ClassFileConstants . AccStrictfp ) ; if ( ( realModifiers & UNEXPECTED_ENUM_CONSTR_MODIFIERS ) != 0 ) { problemReporter ( ) . illegalModifierForEnumConstructor ( ( AbstractMethodDeclaration ) this . referenceContext ) ; modifiers &= ~ ExtraCompilerModifiers . AccJustFlag | ~ UNEXPECTED_ENUM_CONSTR_MODIFIERS ; } else if ( ( ( ( AbstractMethodDeclaration ) this . referenceContext ) . modifiers & ClassFileConstants . AccStrictfp ) != 0 ) { problemReporter ( ) . illegalModifierForMethod ( ( AbstractMethodDeclaration ) this . referenceContext ) ; } modifiers |= ClassFileConstants . AccPrivate ; } else if ( ( realModifiers & UNEXPECTED_MODIFIERS ) != 0 ) { problemReporter ( ) . illegalModifierForMethod ( ( AbstractMethodDeclaration ) this . referenceContext ) ; modifiers &= ~ ExtraCompilerModifiers . AccJustFlag | ~ UNEXPECTED_MODIFIERS ; } else if ( ( ( ( AbstractMethodDeclaration ) this . referenceContext ) . modifiers & ClassFileConstants . AccStrictfp ) != 0 ) { problemReporter ( ) . illegalModifierForMethod ( ( AbstractMethodDeclaration ) this . referenceContext ) ; } int accessorBits = realModifiers & ( ClassFileConstants . AccPublic | ClassFileConstants . AccProtected | ClassFileConstants . AccPrivate ) ; if ( ( accessorBits & ( accessorBits - 1 ) ) != 0 ) { problemReporter ( ) . illegalVisibilityModifierCombinationForMethod ( declaringClass , ( AbstractMethodDeclaration ) this . referenceContext ) ; if ( ( accessorBits & ClassFileConstants . AccPublic ) != 0 ) { if ( ( accessorBits & ClassFileConstants . AccProtected ) != 0 ) modifiers &= ~ ClassFileConstants . AccProtected ; if ( ( accessorBits & ClassFileConstants . AccPrivate ) != 0 ) modifiers &= ~ ClassFileConstants . AccPrivate ; } else if ( ( accessorBits & ClassFileConstants . AccProtected ) != 0 && ( accessorBits & ClassFileConstants . AccPrivate ) != 0 ) { modifiers &= ~ ClassFileConstants . AccPrivate ; } } methodBinding . modifiers = modifiers ; } private void checkAndSetModifiersForMethod ( MethodBinding methodBinding ) { int modifiers = methodBinding . modifiers ; final ReferenceBinding declaringClass = methodBinding . declaringClass ; if ( ( modifiers & ExtraCompilerModifiers . AccAlternateModifierProblem ) != 0 ) problemReporter ( ) . duplicateModifierForMethod ( declaringClass , ( AbstractMethodDeclaration ) this . referenceContext ) ; int realModifiers = modifiers & ExtraCompilerModifiers . AccJustFlag ; if ( declaringClass . isInterface ( ) ) { if ( ( realModifiers & ~ ( ClassFileConstants . AccPublic | ClassFileConstants . AccAbstract ) ) != 0 ) { if ( ( declaringClass . modifiers & ClassFileConstants . AccAnnotation ) != 0 ) problemReporter ( ) . illegalModifierForAnnotationMember ( ( AbstractMethodDeclaration ) this . referenceContext ) ; else problemReporter ( ) . illegalModifierForInterfaceMethod ( ( AbstractMethodDeclaration ) this . referenceContext ) ; } return ; } final int UNEXPECTED_MODIFIERS = ~ ( ClassFileConstants . AccPublic | ClassFileConstants . AccPrivate | ClassFileConstants . AccProtected | ClassFileConstants . AccAbstract | ClassFileConstants . AccStatic | ClassFileConstants . AccFinal | ClassFileConstants . AccSynchronized | ClassFileConstants . AccNative | ClassFileConstants . AccStrictfp ) ; if ( ( realModifiers & UNEXPECTED_MODIFIERS ) != 0 ) { problemReporter ( ) . illegalModifierForMethod ( ( AbstractMethodDeclaration ) this . referenceContext ) ; modifiers &= ~ ExtraCompilerModifiers . AccJustFlag | ~ UNEXPECTED_MODIFIERS ; } int accessorBits = realModifiers & ( ClassFileConstants . AccPublic | ClassFileConstants . AccProtected | ClassFileConstants . AccPrivate ) ; if ( ( accessorBits & ( accessorBits - 1 ) ) != 0 ) { problemReporter ( ) . illegalVisibilityModifierCombinationForMethod ( declaringClass , ( AbstractMethodDeclaration ) this . referenceContext ) ; if ( ( accessorBits & ClassFileConstants . AccPublic ) != 0 ) { if ( ( accessorBits & ClassFileConstants . AccProtected ) != 0 ) modifiers &= ~ ClassFileConstants . AccProtected ; if ( ( accessorBits & ClassFileConstants . AccPrivate ) != 0 ) modifiers &= ~ ClassFileConstants . AccPrivate ; } else if ( ( accessorBits & ClassFileConstants . AccProtected ) != 0 && ( accessorBits & ClassFileConstants . AccPrivate ) != 0 ) { modifiers &= ~ ClassFileConstants . AccPrivate ; } } if ( ( modifiers & ClassFileConstants . AccAbstract ) != 0 ) { int incompatibleWithAbstract = ClassFileConstants . AccPrivate | ClassFileConstants . AccStatic | ClassFileConstants . AccFinal | ClassFileConstants . AccSynchronized | ClassFileConstants . AccNative | ClassFileConstants . AccStrictfp ; if ( ( modifiers & incompatibleWithAbstract ) != 0 ) problemReporter ( ) . illegalAbstractModifierCombinationForMethod ( declaringClass , ( AbstractMethodDeclaration ) this . referenceContext ) ; if ( ! methodBinding . declaringClass . isAbstract ( ) ) problemReporter ( ) . abstractMethodInAbstractClass ( ( SourceTypeBinding ) declaringClass , ( AbstractMethodDeclaration ) this . referenceContext ) ; } if ( ( modifiers & ClassFileConstants . AccNative ) != 0 && ( modifiers & ClassFileConstants . AccStrictfp ) != 0 ) problemReporter ( ) . nativeMethodsCannotBeStrictfp ( declaringClass , ( AbstractMethodDeclaration ) this . referenceContext ) ; if ( ( ( realModifiers & ClassFileConstants . AccStatic ) != 0 ) && declaringClass . isNestedType ( ) && ! declaringClass . isStatic ( ) ) problemReporter ( ) . unexpectedStaticModifierForMethod ( declaringClass , ( AbstractMethodDeclaration ) this . referenceContext ) ; methodBinding . modifiers = modifiers ; } public void checkUnusedParameters ( MethodBinding method ) { if ( method . isAbstract ( ) || ( method . isImplementing ( ) && ! compilerOptions ( ) . reportUnusedParameterWhenImplementingAbstract ) || ( method . isOverriding ( ) && ! method . isImplementing ( ) && ! compilerOptions ( ) . reportUnusedParameterWhenOverridingConcrete ) || method . isMain ( ) ) { return ; } for ( int i = 0 , maxLocals = this . localIndex ; i < maxLocals ; i ++ ) { LocalVariableBinding local = this . locals [ i ] ; if ( local == null || ( ( local . tagBits & TagBits . IsArgument ) == 0 ) ) { break ; } if ( local . useFlag == LocalVariableBinding . UNUSED && ( ( local . declaration . bits & ASTNode . IsLocalDeclarationReachable ) != 0 ) ) { problemReporter ( ) . unusedArgument ( local . declaration ) ; } } } public void computeLocalVariablePositions ( int initOffset , CodeStream codeStream ) { this . offset = initOffset ; this . maxOffset = initOffset ; int ilocal = 0 , maxLocals = this . localIndex ; while ( ilocal < maxLocals ) { LocalVariableBinding local = this . locals [ ilocal ] ; if ( local == null || ( ( local . tagBits & TagBits . IsArgument ) == 0 ) ) break ; codeStream . record ( local ) ; local . resolvedPosition = this . offset ; if ( ( local . type == TypeBinding . LONG ) || ( local . type == TypeBinding . DOUBLE ) ) { this . offset += 2 ; } else { this . offset ++ ; } if ( this . offset > 0xFF ) { problemReporter ( ) . noMoreAvailableSpaceForArgument ( local , local . declaration ) ; } ilocal ++ ; } if ( this . extraSyntheticArguments != null ) { for ( int iarg = 0 , maxArguments = this . extraSyntheticArguments . length ; iarg < maxArguments ; iarg ++ ) { SyntheticArgumentBinding argument = this . extraSyntheticArguments [ iarg ] ; argument . resolvedPosition = this . offset ; if ( ( argument . type == TypeBinding . LONG ) || ( argument . type == TypeBinding . DOUBLE ) ) { this . offset += 2 ; } else { this . offset ++ ; } if ( this . offset > 0xFF ) { problemReporter ( ) . noMoreAvailableSpaceForArgument ( argument , ( ASTNode ) this . referenceContext ) ; } } } this . computeLocalVariablePositions ( ilocal , this . offset , codeStream ) ; } MethodBinding createMethod ( AbstractMethodDeclaration method ) { this . referenceContext = method ; method . scope = this ; SourceTypeBinding declaringClass = referenceType ( ) . binding ; int modifiers = method . modifiers | ExtraCompilerModifiers . AccUnresolved ; if ( method . isConstructor ( ) ) { if ( method . isDefaultConstructor ( ) ) modifiers |= ExtraCompilerModifiers . AccIsDefaultConstructor ; method . binding = new MethodBinding ( modifiers , null , null , declaringClass ) ; checkAndSetModifiersForConstructor ( method . binding ) ; } else { if ( declaringClass . isInterface ( ) ) modifiers |= ClassFileConstants . AccPublic | ClassFileConstants . AccAbstract ; method . binding = new MethodBinding ( modifiers , method . selector , null , null , null , declaringClass ) ; checkAndSetModifiersForMethod ( method . binding ) ; } this . isStatic = method . binding . isStatic ( ) ; Argument [ ] argTypes = method . arguments ; int argLength = argTypes == null ? 0 : argTypes . length ; if ( argLength > 0 && compilerOptions ( ) . sourceLevel >= ClassFileConstants . JDK1_5 ) { if ( argTypes [ -- argLength ] . isVarArgs ( ) ) method . binding . modifiers |= ClassFileConstants . AccVarargs ; while ( -- argLength >= 0 ) { if ( argTypes [ argLength ] . isVarArgs ( ) ) problemReporter ( ) . illegalVararg ( argTypes [ argLength ] , method ) ; } } TypeParameter [ ] typeParameters = method . typeParameters ( ) ; if ( typeParameters == null || typeParameters . length == 0 ) { method . binding . typeVariables = Binding . NO_TYPE_VARIABLES ; } else { method . binding . typeVariables = createTypeVariables ( typeParameters , method . binding ) ; method . binding . modifiers |= ExtraCompilerModifiers . AccGenericSignature ; } return method . binding ; } public FieldBinding findField ( TypeBinding receiverType , char [ ] fieldName , InvocationSite invocationSite , boolean needResolve ) { FieldBinding field = super . findField ( receiverType , fieldName , invocationSite , needResolve ) ; if ( field == null ) return null ; if ( ! field . isValidBinding ( ) ) return field ; if ( field . isStatic ( ) ) return field ; if ( ! this . isConstructorCall || receiverType != enclosingSourceType ( ) ) return field ; if ( invocationSite instanceof SingleNameReference ) return new ProblemFieldBinding ( field , field . declaringClass , fieldName , ProblemReasons . NonStaticReferenceInConstructorInvocation ) ; if ( invocationSite instanceof QualifiedNameReference ) { QualifiedNameReference name = ( QualifiedNameReference ) invocationSite ; if ( name . binding == null ) return new ProblemFieldBinding ( field , field . declaringClass , fieldName , ProblemReasons . NonStaticReferenceInConstructorInvocation ) ; } return field ; } public boolean isInsideConstructor ( ) { return ( this . referenceContext instanceof ConstructorDeclaration ) ; } public boolean isInsideInitializer ( ) { return ( this . referenceContext instanceof TypeDeclaration ) ; } public boolean isInsideInitializerOrConstructor ( ) { return ( this . referenceContext instanceof TypeDeclaration ) || ( this . referenceContext instanceof ConstructorDeclaration ) ; } public ProblemReporter problemReporter ( ) { ProblemReporter problemReporter = referenceCompilationUnit ( ) . problemReporter ; problemReporter . referenceContext = this . referenceContext ; return problemReporter ; } public final int recordInitializationStates ( FlowInfo flowInfo ) { if ( ( flowInfo . tagBits & FlowInfo . UNREACHABLE_OR_DEAD ) != 0 ) return - 1 ; UnconditionalFlowInfo unconditionalFlowInfo = flowInfo . unconditionalInitsWithoutSideEffect ( ) ; long [ ] extraInits = unconditionalFlowInfo . extra == null ? null : unconditionalFlowInfo . extra [ 0 ] ; long inits = unconditionalFlowInfo . definiteInits ; checkNextEntry : for ( int i = this . lastIndex ; -- i >= 0 ; ) { if ( this . definiteInits [ i ] == inits ) { long [ ] otherInits = this . extraDefiniteInits [ i ] ; if ( ( extraInits != null ) && ( otherInits != null ) ) { if ( extraInits . length == otherInits . length ) { int j , max ; for ( j = 0 , max = extraInits . length ; j < max ; j ++ ) { if ( extraInits [ j ] != otherInits [ j ] ) { continue checkNextEntry ; } } return i ; } } else { if ( ( extraInits == null ) && ( otherInits == null ) ) { return i ; } } } } if ( this . definiteInits . length == this . lastIndex ) { System . arraycopy ( this . definiteInits , 0 , ( this . definiteInits = new long [ this . lastIndex + 20 ] ) , 0 , this . lastIndex ) ; System . arraycopy ( this . extraDefiniteInits , 0 , ( this . extraDefiniteInits = new long [ this . lastIndex + 20 ] [ ] ) , 0 , this . lastIndex ) ; } this . definiteInits [ this . lastIndex ] = inits ; if ( extraInits != null ) { this . extraDefiniteInits [ this . lastIndex ] = new long [ extraInits . length ] ; System . arraycopy ( extraInits , 0 , this . extraDefiniteInits [ this . lastIndex ] , 0 , extraInits . length ) ; } return this . lastIndex ++ ; } public AbstractMethodDeclaration referenceMethod ( ) { if ( this . referenceContext instanceof AbstractMethodDeclaration ) return ( AbstractMethodDeclaration ) this . referenceContext ; return null ; } public TypeDeclaration referenceType ( ) { return ( ( ClassScope ) this . parent ) . referenceContext ; } } </s>