Package org.eclipse.jdt.internal.compiler.lookup

Examples of org.eclipse.jdt.internal.compiler.lookup.FieldBinding


  fieldStore(currentScope, codeStream, lastFieldBinding, this.syntheticWriteAccessor, getFinalReceiverType(), false /*implicit this*/, valueRequired);
  // equivalent to valuesRequired[maxOtherBindings]
}

public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
  FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream);
  // check if this post increment is the only usage of a private field
  reportOnlyUselesslyReadPrivateField(currentScope, lastFieldBinding, valueRequired);
  boolean isFirst = lastFieldBinding == this.binding
    && (this.indexOfFirstFieldBinding == 1 || lastFieldBinding.declaringClass == currentScope.enclosingReceiverType())
    && this.otherBindings == null; // could be dup: next.next.next
  TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, lastFieldBinding, getFinalReceiverType(), isFirst);     
  SyntheticMethodBinding accessor = this.syntheticReadAccessors == null
      ? null
      : this.syntheticReadAccessors[this.syntheticReadAccessors.length - 1];
  if (lastFieldBinding.isStatic()) {
    if (accessor == null) {
      codeStream.fieldAccess(Opcodes.OPC_getstatic, lastFieldBinding, constantPoolDeclaringClass);
    } else {
      codeStream.invoke(Opcodes.OPC_invokestatic, accessor, constantPoolDeclaringClass);
    }
  } else {
    codeStream.dup();
    if (accessor == null) {
      codeStream.fieldAccess(Opcodes.OPC_getfield, lastFieldBinding, null /* default declaringClass */);
    } else {
      codeStream.invoke(Opcodes.OPC_invokestatic, accessor, null /* default declaringClass */);
    }
  }
  TypeBinding requiredGenericCast = getGenericCast(this.otherBindings == null ? 0 : this.otherBindings.length);
  TypeBinding operandType;
  if (requiredGenericCast != null) {
    codeStream.checkcast(requiredGenericCast);
    operandType = requiredGenericCast;
  } else {
    operandType = lastFieldBinding.type;
  }   
  // duplicate the old field value
  if (valueRequired) {
    if (lastFieldBinding.isStatic()) {
      switch (operandType.id) {
        case TypeIds.T_long :
        case TypeIds.T_double :
          codeStream.dup2();
          break;
View Full Code Here


*/
public FieldBinding generateReadSequence(BlockScope currentScope, CodeStream codeStream) {
  // determine the rank until which we now we do not need any actual value for the field access
  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 & ASTNode.RestrictiveFlagMASK) {
    case Binding.FIELD :
      lastFieldBinding = ((FieldBinding) this.binding).original();
      lastGenericCast = this.genericCast;
      lastReceiverType = this.actualReceiverType;
      // if first field is actually constant, we can inline it
      if (lastFieldBinding.constant() != Constant.NotAConstant) {
        break;
      }
      if ((needValue && !lastFieldBinding.isStatic()) || lastGenericCast != null) {
        int pc = codeStream.position;
        if ((this.bits & ASTNode.DepthMASK) != 0) {
          ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT);
          Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
          codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope);
        } else {
          generateReceiver(codeStream);
        }
        codeStream.recordPositionsFrom(pc, this.sourceStart);
      }
      break;
    case Binding.LOCAL : // reading the first local variable
      lastFieldBinding = null;
      lastGenericCast = null;
      LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
      lastReceiverType = localBinding.type;
      if (!needValue) break; // no value needed
      // regular local variable read
      Constant localConstant = localBinding.constant();
      if (localConstant != Constant.NotAConstant) {
        codeStream.generateConstant(localConstant, 0);
        // no implicit conversion
      } else {
        // outer local?
        if ((this.bits & ASTNode.DepthMASK) != 0) {
          // outer local can be reached either through a synthetic arg or a synthetic field
          VariableBinding[] path = currentScope.getEmulationPath(localBinding);
          codeStream.generateOuterAccess(path, this, localBinding, currentScope);
        } else {
          codeStream.load(localBinding);
        }
      }
      break;
    default : // should not occur
      return null;
  }

  // all intermediate field accesses are read accesses
  // only the last field binding is a write access
  int positionsLength = this.sourcePositions.length;
  FieldBinding initialFieldBinding = lastFieldBinding; // can be null if initial was a local binding
  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(); // perform null check
            codeStream.pop();
View Full Code Here

  }
}
public TypeBinding getOtherFieldBindings(BlockScope scope) {
  // At this point restrictiveFlag may ONLY have two potential value : FIELD LOCAL (i.e cast <<(VariableBinding) binding>> is valid)
  int length = this.tokens.length;
  FieldBinding field = ((this.bits & Binding.FIELD) != 0) ? (FieldBinding) this.binding : null;
  TypeBinding type = ((VariableBinding) this.binding).type;
  int index = this.indexOfFirstFieldBinding;
  if (index == length) { //  restrictiveFlag == FIELD
    this.constant = ((FieldBinding) this.binding).constant();
    // perform capture conversion if read access
    return (type != null && (this.bits & ASTNode.IsStrictlyAssigned) == 0)
        ? type.capture(scope, this.sourceEnd)
        : type;
  }
  // allocation of the fieldBindings array  and its respective constants
  int otherBindingsLength = length - index;
  this.otherBindings = new FieldBinding[otherBindingsLength];
  this.otherDepths = new int[otherBindingsLength];

  // fill the first constant (the one of the binding)
  this.constant = ((VariableBinding) this.binding).constant();
  // save first depth, since will be updated by visibility checks of other bindings
  int firstDepth = (this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT;
  // iteration on each field
  while (index < length) {
    char[] token = this.tokens[index];
    if (type == null)
      return null; // could not resolve type prior to this point

    this.bits &= ~ASTNode.DepthMASK; // flush previous depth if any
    FieldBinding previousField = field;
    field = scope.getField(type.capture(scope, (int)this.sourcePositions[index]), token, this);
    int place = index - this.indexOfFirstFieldBinding;
    this.otherBindings[place] = field;
    this.otherDepths[place] = (this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT;
    if (field.isValidBinding()) {
      // set generic cast of for previous field (if any)
      if (previousField != null) {
        TypeBinding fieldReceiverType = type;
        TypeBinding oldReceiverType = fieldReceiverType;
        fieldReceiverType = fieldReceiverType.getErasureCompatibleType(field.declaringClass);// handle indirect inheritance thru variable secondary bound
        FieldBinding originalBinding = previousField.original();
        if (fieldReceiverType != oldReceiverType || originalBinding.type.leafComponentType().isTypeVariable()) { // record need for explicit cast at codegen
            setGenericCast(index-1,originalBinding.type.genericCast(fieldReceiverType)); // type cannot be base-type even in boxing case
        }       
        }
      // only last field is actually a write access if any
View Full Code Here

  // index == 0 denotes the first fieldBinding, index > 0 denotes one of the 'otherBindings', index < 0 denotes a write access (to last binding)
  if (fieldBinding.constant() != Constant.NotAConstant)
    return;

  if (fieldBinding.isPrivate()) { // private access
      FieldBinding codegenField = getCodegenBinding(index < 0 ? (this.otherBindings == null ? 0 : this.otherBindings.length) : index);
      ReferenceBinding declaringClass = codegenField.declaringClass;
    if (declaringClass != currentScope.enclosingSourceType()) {
        setSyntheticAccessor(fieldBinding, index, ((SourceTypeBinding) declaringClass).addSyntheticMethod(codegenField, index >= 0 /*read-access?*/, false /*not super access*/));
      currentScope.problemReporter().needToEmulateFieldAccess(codegenField, this, index >= 0 /*read-access?*/);
      return;
    }
  } else if (fieldBinding.isProtected()){
      int depth = (index == 0 || (index < 0 && this.otherDepths == null))
          ? (this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT
           : this.otherDepths[index < 0 ? this.otherDepths.length-1 : index-1];

    // implicit protected access
    if (depth > 0 && (fieldBinding.declaringClass.getPackage() != currentScope.enclosingSourceType().getPackage())) {
        FieldBinding codegenField = getCodegenBinding(index < 0 ? (this.otherBindings == null ? 0 : this.otherBindings.length) : index);
        setSyntheticAccessor(fieldBinding, index,
                ((SourceTypeBinding) currentScope.enclosingSourceType().enclosingTypeAt(depth)).addSyntheticMethod(codegenField, index >= 0 /*read-access?*/, false /*not super access*/));
      currentScope.problemReporter().needToEmulateFieldAccess(codegenField, this, index >= 0 /*read-access?*/);
      return;
    }
 
View Full Code Here

            // only complain if field reference (for local, its type got flagged already)
            return null;
          }
          this.resolvedType = getOtherFieldBindings(scope);
          if (this.resolvedType != null && (this.resolvedType.tagBits & TagBits.HasMissingType) != 0) {
            FieldBinding lastField = this.otherBindings[this.otherBindings.length - 1];
            scope.problemReporter().invalidField(this, new ProblemFieldBinding(lastField.declaringClass, lastField.name, ProblemReasons.NotFound), this.tokens.length, this.resolvedType.leafComponentType());
            return null;
          }
          return this.resolvedType;
        }
        if (this.binding instanceof FieldBinding) {
          this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
          this.bits |= Binding.FIELD;
          FieldBinding fieldBinding = (FieldBinding) this.binding;
          MethodScope methodScope = scope.methodScope();
          ReferenceBinding declaringClass = fieldBinding.original().declaringClass;
          SourceTypeBinding sourceType = methodScope.enclosingSourceType();
          // check for forward references
          if ((this.indexOfFirstFieldBinding == 1 || (fieldBinding.modifiers & ClassFileConstants.AccEnum) != 0 || (!fieldBinding.isFinal() && declaringClass.isEnum())) // enum constants are checked even when qualified
              && sourceType == declaringClass
              && methodScope.lastVisibleFieldID >= 0
              && fieldBinding.id >= methodScope.lastVisibleFieldID
              && (!fieldBinding.isStatic() || methodScope.isStatic)) {
            scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding);
          }
          if (isFieldUseDeprecated(fieldBinding, scope, this.indexOfFirstFieldBinding == this.tokens.length ? this.bits : 0)) {
            scope.problemReporter().deprecatedField(fieldBinding, this)
          }
          if (fieldBinding.isStatic()) {
            // only last field is actually a write access if any
            // check if accessing enum static field in initializer
            if (declaringClass.isEnum()) {
              if ((sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body
                  && fieldBinding.constant() == Constant.NotAConstant
                  && !methodScope.isStatic
                  && methodScope.isInsideInitializerOrConstructor()) {
                scope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this);
              }
            }
            if (this.indexOfFirstFieldBinding > 1
                && fieldBinding.declaringClass != this.actualReceiverType
                && fieldBinding.declaringClass.canBeSeenBy(scope)) {
              scope.problemReporter().indirectAccessToStaticField(this, fieldBinding);
            }           
          } else {
            if (this.indexOfFirstFieldBinding == 1 && scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) {
              scope.problemReporter().unqualifiedFieldAccess(this, fieldBinding);
            }
            //must check for the static status....
            if (this.indexOfFirstFieldBinding > //accessing to a field using a type as "receiver" is allowed only with static field
                 || scope.methodScope().isStatic) {   // the field is the first token of the qualified reference....
              scope.problemReporter().staticFieldAccessToNonStaticVariable(this, fieldBinding);
              return null;
             }
          }
         
          this.resolvedType = getOtherFieldBindings(scope);
          if (this.resolvedType != null
              && (this.resolvedType.tagBits & TagBits.HasMissingType) != 0) {
            FieldBinding lastField = this.indexOfFirstFieldBinding == this.tokens.length ? (FieldBinding)this.binding : this.otherBindings[this.otherBindings.length - 1];
            scope.problemReporter().invalidField(this, new ProblemFieldBinding(lastField.declaringClass, lastField.name, ProblemReasons.NotFound), this.tokens.length, this.resolvedType.leafComponentType());
            return null;
          }
          return this.resolvedType;
        }
View Full Code Here

                scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, currentExpression, true);
              } else if (currentExpression instanceof NameReference) {
                NameReference nameReference = (NameReference) currentExpression;
                final Binding nameReferenceBinding = nameReference.binding;
                if (nameReferenceBinding.kind() == Binding.FIELD) {
                  FieldBinding fieldBinding = (FieldBinding) nameReferenceBinding;
                  if (!fieldBinding.declaringClass.isEnum()) {
                    scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, currentExpression, true);
                  }
                }
              }
            }
          }
        } else if (this.value instanceof NameReference) {
          NameReference nameReference = (NameReference) this.value;
          final Binding nameReferenceBinding = nameReference.binding;
          if (nameReferenceBinding.kind() == Binding.FIELD) {
            FieldBinding fieldBinding = (FieldBinding) nameReferenceBinding;
            if (!fieldBinding.declaringClass.isEnum()) {
              if (!fieldBinding.type.isArrayType()) {
                scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value, true);
              } else {
                scope.problemReporter().annotationValueMustBeArrayInitializer(this.binding.declaringClass, this.name, this.value);
View Full Code Here

  boolean isReachable = (flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0;
  // compound assignment extra work
  if (isCompound) { // check the variable part is initialized if blank final
    switch (this.bits & ASTNode.RestrictiveFlagMASK) {
      case Binding.FIELD : // reading a field
        FieldBinding fieldBinding = (FieldBinding) this.binding;
        if (fieldBinding.isBlankFinal()
            && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) {
          FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo);
          if (!fieldInits.isDefinitelyAssigned(fieldBinding)) {
            currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
          }
        }
        if (!fieldBinding.isStatic()) {
          // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682
          currentScope.resetEnclosingMethodStaticFlag();
        }
        manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/);
        break;
      case Binding.LOCAL : // reading a local variable
        // check if assigning a final blank field
        LocalVariableBinding localBinding;
        if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) this.binding)) {
          currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
          // we could improve error msg here telling "cannot use compound assignment on final local variable"
        }
        if (localBinding.useFlag != LocalVariableBinding.USED) {
          // https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
          // access from compound assignment does not prevent "unused" warning, unless unboxing is involved:
          if (isReachable && (this.implicitConversion & TypeIds.UNBOXING) != 0) {
            localBinding.useFlag = LocalVariableBinding.USED;
          } else {
            // use values < 0 to count the number of compound uses:
            if (localBinding.useFlag <= LocalVariableBinding.UNUSED)
              localBinding.useFlag--;
          }
        }
    }
  }
  if (assignment.expression != null) {
    flowInfo = assignment.expression.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
  }
  switch (this.bits & ASTNode.RestrictiveFlagMASK) {
    case Binding.FIELD : // assigning to a field
      manageSyntheticAccessIfNecessary(currentScope, flowInfo, false /*write-access*/);

      // check if assigning a final field
      FieldBinding fieldBinding = (FieldBinding) this.binding;
      if (fieldBinding.isFinal()) {
        // inside a context where allowed
        if (!isCompound && fieldBinding.isBlankFinal() && currentScope.allowBlankFinalFieldAssignment(fieldBinding)) {
          if (flowInfo.isPotentiallyAssigned(fieldBinding)) {
            currentScope.problemReporter().duplicateInitializationOfBlankFinalField(fieldBinding, this);
          } else {
            flowContext.recordSettingFinal(fieldBinding, this, flowInfo);
          }
          flowInfo.markAsDefinitelyAssigned(fieldBinding);
        } else {
          currentScope.problemReporter().cannotAssignToFinalField(fieldBinding, this);
        }
      }
      if (!fieldBinding.isStatic()) {
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682
        currentScope.resetEnclosingMethodStaticFlag();
      }
      break;
    case Binding.LOCAL : // assigning to a local variable
View Full Code Here

    case Binding.FIELD : // reading a field
      if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) {
        manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/);
      }
      // check if reading a final blank field
      FieldBinding fieldBinding = (FieldBinding) this.binding;
      if (fieldBinding.isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) {
        FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo);
        if (!fieldInits.isDefinitelyAssigned(fieldBinding)) {
          currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
        }
      }
      if (!fieldBinding.isStatic()) {
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682
        currentScope.resetEnclosingMethodStaticFlag();
      }
      break;
    case Binding.LOCAL : // reading a local variable
View Full Code Here

  }
  return flowInfo;
}

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;
View Full Code Here

public void computeConversion(Scope scope, TypeBinding runtimeTimeType, TypeBinding compileTimeType) {
  if (runtimeTimeType == null || compileTimeType == null)
    return;
  if ((this.bits & Binding.FIELD) != 0 && this.binding != null && this.binding.isValidBinding()) {
    // set the generic cast after the fact, once the type expectation is fully known (no need for strict cast)
    FieldBinding field = (FieldBinding) this.binding;
    FieldBinding originalBinding = field.original();
    TypeBinding originalType = originalBinding.type;
    // extra cast needed if field type is type variable
    if (originalType.leafComponentType().isTypeVariable()) {
        TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType())
          ? compileTimeType  // unboxing: checkcast before conversion
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.lookup.FieldBinding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.