Пример #1
0
 public void generateCode(BlockScope currentScope, boolean valueRequired) {
   if (this.constant != Constant.NotAConstant) {
     return;
   } else {
     switch (this.bits & ASTNode.RestrictiveFlagMASK) {
       case Binding.FIELD: // reading a field
         FieldBinding codegenField = ((FieldBinding) this.binding).original();
         Constant fieldConstant = codegenField.constant();
         if (fieldConstant != Constant.NotAConstant) {
           return;
         }
         if (codegenField.isStatic()) {
           if (!valueRequired
               // if no valueRequired, still need possible side-effects of <clinit> invocation,
               // if field belongs to different class
               && ((FieldBinding) this.binding).original().declaringClass
                   == this.actualReceiverType.erasure()
               && ((this.implicitConversion & TypeIds.UNBOXING) == 0)
               && this.genericCast == null) {
             // if no valueRequired, optimize out entire gen
             return;
           }
         } else {
           if (!valueRequired
               && (this.implicitConversion & TypeIds.UNBOXING) == 0
               && this.genericCast == null) {
             // if no valueRequired, optimize out entire gen
             return;
           }
         }
         break;
       case Binding.LOCAL: // reading a local
         LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
         if (localBinding.resolvedPosition == -1) {
           if (valueRequired) {
             // restart code gen
             localBinding.useFlag = LocalVariableBinding.USED;
             throw new AbortMethod(null, null);
           }
           return;
         }
         if (!valueRequired && (this.implicitConversion & TypeIds.UNBOXING) == 0) {
           // if no valueRequired, optimize out entire gen
           return;
         }
         break;
       default: // type
         return;
     }
   }
 }
Пример #2
0
  public TypeBinding checkFieldAccess(BlockScope scope) {
    FieldBinding fieldBinding = (FieldBinding) this.binding;
    this.constant = fieldBinding.constant();

    this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
    this.bits |= Binding.FIELD;
    MethodScope methodScope = scope.methodScope();
    if (fieldBinding.isStatic()) {
      // check if accessing enum static field in initializer
      ReferenceBinding declaringClass = fieldBinding.declaringClass;
      if (declaringClass.isEnum()) {
        SourceTypeBinding sourceType = scope.enclosingSourceType();
        if (this.constant == Constant.NotAConstant
            && !methodScope.isStatic
            && (sourceType == declaringClass
                || sourceType.superclass == declaringClass) // enum constant body
            && methodScope.isInsideInitializerOrConstructor()) {
          scope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this);
        }
      }
    } else {
      if (scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess)
          != ProblemSeverities.Ignore) {
        scope.problemReporter().unqualifiedFieldAccess(this, fieldBinding);
      }
      // must check for the static status....
      if (methodScope.isStatic) {
        scope.problemReporter().staticFieldAccessToNonStaticVariable(this, fieldBinding);
        return fieldBinding.type;
      }
    }

    if (isFieldUseDeprecated(fieldBinding, scope, this.bits))
      scope.problemReporter().deprecatedField(fieldBinding, this);

    if ((this.bits & ASTNode.IsStrictlyAssigned) == 0
        && methodScope.enclosingSourceType() == fieldBinding.original().declaringClass
        && methodScope.lastVisibleFieldID >= 0
        && fieldBinding.id >= methodScope.lastVisibleFieldID
        && (!fieldBinding.isStatic() || methodScope.isStatic)) {
      scope.problemReporter().forwardReference(this, 0, fieldBinding);
      this.bits |= ASTNode.IgnoreNoEffectAssignCheck;
    }
    return fieldBinding.type;
  }