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

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


   * @see IVariableBinding#getDeclaringClass()
   */
  public ITypeBinding getDeclaringClass() {
    if (isField()) {
      if (this.declaringClass == null) {
        FieldBinding fieldBinding = (FieldBinding) this.binding;
        this.declaringClass = this.resolver.getTypeBinding(fieldBinding.declaringClass);
      }
      return this.declaringClass;
    } else {
      return null;
View Full Code Here


   * @see IVariableBinding#getVariableDeclaration()
   * @since 3.1
   */
  public IVariableBinding getVariableDeclaration() {
    if (isField()) {
      FieldBinding fieldBinding = (FieldBinding) this.binding;
      return this.resolver.getVariableBinding(fieldBinding.original());
    }
    return this;
  }
View Full Code Here

  // for static import, binding can be a field binding or a member type binding
  // verify that in this case binding is static and use declaring class for fields
  Binding refBinding = binding;
  if (importRef.isStatic()) {
    if (binding instanceof FieldBinding) {
      FieldBinding fieldBinding = (FieldBinding) binding;
      if (!fieldBinding.isStatic()) return;
      refBinding = fieldBinding.declaringClass;
    } else if (binding instanceof MethodBinding) {
      MethodBinding methodBinding = (MethodBinding) binding;
      if (!methodBinding.isStatic()) return;
      refBinding = methodBinding.declaringClass;
View Full Code Here

      // check missing blank final field initializations
      flowInfo = flowInfo.mergedWith(staticInitializerFlowContext.initsOnReturn);
      FieldBinding[] fields = this.scope.enclosingSourceType().fields();
      for (int i = 0, count = fields.length; i < count; i++) {
        FieldBinding field;
        if ((field = fields[i]).isStatic()
          && field.isFinal()
          && (!flowInfo.isDefinitelyAssigned(fields[i]))) {
          this.scope.problemReporter().uninitializedBlankFinalField(
            field,
            this.scope.referenceType().declarationOf(field.original()));
          // can complain against the field decl, since only one <clinit>
        }
      }
      // check static initializers thrown exceptions
      staticInitializerFlowContext.checkInitializerExceptions(
View Full Code Here

public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment, boolean isCompound) {
  // 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();
  boolean complyTo14 = currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4;
  FieldBinding lastFieldBinding = null;
  switch (this.bits & ASTNode.RestrictiveFlagMASK) {
    case Binding.FIELD : // reading a field
      lastFieldBinding = (FieldBinding) this.binding;
      if (needValue || complyTo14) {
        manageSyntheticAccessIfNecessary(currentScope, lastFieldBinding, 0, flowInfo);
      }
      // check if final blank field
      if (lastFieldBinding.isBlankFinal()
            && this.otherBindings != null // the last field binding is only assigned
           && currentScope.needBlankFinalFieldInitializationCheck(lastFieldBinding)) {
        FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(lastFieldBinding.declaringClass.original(), flowInfo);
        if (!fieldInits.isDefinitelyAssigned(lastFieldBinding)) {
          currentScope.problemReporter().uninitializedBlankFinalField(lastFieldBinding, this);
        }
      }
      if (!lastFieldBinding.isStatic()) {
        currentScope.resetEnclosingMethodStaticFlag();
      }
      break;
    case Binding.LOCAL :
      // first binding is a local variable
      LocalVariableBinding localBinding;
      if (!flowInfo
        .isDefinitelyAssigned(localBinding = (LocalVariableBinding) this.binding)) {
        currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
      }
      if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)  {
        localBinding.useFlag = LocalVariableBinding.USED;
      } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) {
        localBinding.useFlag = LocalVariableBinding.FAKE_USED;
      }
      if (needValue) {
        checkNPE(currentScope, flowContext, flowInfo, true);
      }
  }

  if (needValue) {
    manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo);
    // only for first binding
  }
  // all intermediate field accesses are read accesses
  if (this.otherBindings != null) {
    for (int i = 0; i < otherBindingsCount-1; i++) {
      lastFieldBinding = this.otherBindings[i];
      needValue = !this.otherBindings[i+1].isStatic();
      if (needValue || complyTo14) {
        manageSyntheticAccessIfNecessary(currentScope, lastFieldBinding, i + 1, flowInfo);
      }
    }
    lastFieldBinding = this.otherBindings[otherBindingsCount-1];
  }

  if (isCompound) {
    if (otherBindingsCount == 0
        && lastFieldBinding.isBlankFinal()
        && currentScope.needBlankFinalFieldInitializationCheck(lastFieldBinding)) {
      FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(lastFieldBinding.declaringClass, flowInfo);
      if (!fieldInits.isDefinitelyAssigned(lastFieldBinding)) {
        currentScope.problemReporter().uninitializedBlankFinalField(lastFieldBinding, this);
      }
    }
    manageSyntheticAccessIfNecessary(currentScope, lastFieldBinding, otherBindingsCount, flowInfo);
  }

  if (assignment.expression != null) {
    flowInfo =
      assignment
        .expression
        .analyseCode(currentScope, flowContext, flowInfo)
        .unconditionalInits();
  }

  // the last field access is a write access
  if (lastFieldBinding.isFinal()) {
    // in a context where it can be assigned?
    if (otherBindingsCount == 0
        && this.indexOfFirstFieldBinding == 1
        && lastFieldBinding.isBlankFinal()
        && !isCompound
        && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)) {
      if (flowInfo.isPotentiallyAssigned(lastFieldBinding)) {
        currentScope.problemReporter().duplicateInitializationOfBlankFinalField(lastFieldBinding, this);
      } else {
View Full Code Here

  switch (this.bits & ASTNode.RestrictiveFlagMASK) {
    case Binding.FIELD : // reading a field
      if (needValue || complyTo14) {
        manageSyntheticAccessIfNecessary(currentScope, (FieldBinding) this.binding, 0, flowInfo);
      }
      FieldBinding fieldBinding = (FieldBinding) this.binding;
      if (this.indexOfFirstFieldBinding == 1) { // was an implicit reference to the first field binding
        // check if reading a final blank field
        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()) {
        currentScope.resetEnclosingMethodStaticFlag();
      }
      break;
    case Binding.LOCAL : // reading a local variable
      LocalVariableBinding localBinding;
View Full Code Here

*/
public void computeConversion(Scope scope, TypeBinding runtimeTimeType, TypeBinding compileTimeType) {
  if (runtimeTimeType == null || compileTimeType == null)
    return;
  // set the generic cast after the fact, once the type expectation is fully known (no need for strict cast)
  FieldBinding field = null;
  int length = this.otherBindings == null ? 0 : this.otherBindings.length;
  if (length == 0) {
    if ((this.bits & Binding.FIELD) != 0 && this.binding != null && this.binding.isValidBinding()) {
      field = (FieldBinding) this.binding;
    }
  } else {
    field  = this.otherBindings[length-1];
  }
  if (field != null) {
    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

  super.computeConversion(scope, runtimeTimeType, compileTimeType);
}

public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) {
  int pc = codeStream.position;
  FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream);
  codeStream.recordPositionsFrom(pc , this.sourceStart);
  assignment.expression.generateCode(currentScope, codeStream, true);
  fieldStore(currentScope, codeStream, lastFieldBinding, this.syntheticWriteAccessor, getFinalReceiverType(), false /*implicit this*/, valueRequired);
  // equivalent to valuesRequired[maxOtherBindings]
  if (valueRequired) {
View Full Code Here

  if (this.constant != Constant.NotAConstant) {
    if (valueRequired) {
      codeStream.generateConstant(this.constant, this.implicitConversion);
    }
  } else {
    FieldBinding 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();
        }
View Full Code Here

  }
  codeStream.recordPositionsFrom(pc, this.sourceStart);
}

public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
  FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream);
  // check if compound assignment 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, null /* default declaringClass */);
    }
 
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.