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

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


  UnconditionalFlowInfo flowInfo = this.upstreamNullFlowInfo.
    addPotentialNullInfoFrom(callerFlowInfo.unconditionalInitsWithoutSideEffect());
  if ((this.tagBits & FlowContext.DEFER_NULL_DIAGNOSTIC) != 0) {
    // check only immutable null checks on innermost looping context
    for (int i = 0; i < this.nullCount; i++) {
      LocalVariableBinding local = this.nullLocals[i];
      Expression expression = this.nullReferences[i];
      // final local variable
      switch (this.nullCheckTypes[i]) {
        case CAN_ONLY_NON_NULL | IN_COMPARISON_NULL:
        case CAN_ONLY_NON_NULL | IN_COMPARISON_NON_NULL:
          if (flowInfo.isDefinitelyNonNull(local)) {
            this.nullReferences[i] = null;
            if (this.nullCheckTypes[i] == (CAN_ONLY_NON_NULL | IN_COMPARISON_NON_NULL)) {
              if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
                scope.problemReporter().localVariableRedundantCheckOnNonNull(local, expression);
              }
            } else {
              if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
                scope.problemReporter().localVariableNonNullComparedToNull(local, expression);
              }
            }
            continue;
          }
          break;
        case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL:
        case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL:
          if (flowInfo.isDefinitelyNonNull(local)) {
            this.nullReferences[i] = null;
            if (this.nullCheckTypes[i] == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) {
              if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
                scope.problemReporter().localVariableRedundantCheckOnNonNull(local, expression);
              }
            } else {
              if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
                scope.problemReporter().localVariableNonNullComparedToNull(local, expression);
              }
            }
            continue;
          }
          if (flowInfo.isDefinitelyNull(local)) {
            this.nullReferences[i] = null;
            if (this.nullCheckTypes[i] == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) {
              if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
                scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
              }
            } else {
              if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
                scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
              }
            }
            continue;
          }
          break;
        case CAN_ONLY_NULL | IN_COMPARISON_NULL:
        case CAN_ONLY_NULL | IN_COMPARISON_NON_NULL:
        case CAN_ONLY_NULL | IN_ASSIGNMENT:
        case CAN_ONLY_NULL | IN_INSTANCEOF:
          if (flowInfo.isDefinitelyNull(local)) {
            this.nullReferences[i] = null;
            switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
              case FlowContext.IN_COMPARISON_NULL:
                if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                  scope.problemReporter().localVariableNullReference(local, expression);
                  continue;
                }
                if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
                  scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
                }
                continue;
              case FlowContext.IN_COMPARISON_NON_NULL:
                if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                  scope.problemReporter().localVariableNullReference(local, expression);
                  continue;
                }
                if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
                  scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
                }
                continue;
              case FlowContext.IN_ASSIGNMENT:
                scope.problemReporter().localVariableRedundantNullAssignment(local, expression);
                continue;
              case FlowContext.IN_INSTANCEOF:
                scope.problemReporter().localVariableNullInstanceof(local, expression);
                continue;
            }
          } else if (flowInfo.isPotentiallyNull(local)) {
            switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
              case FlowContext.IN_COMPARISON_NULL:
                this.nullReferences[i] = null;
                if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                  scope.problemReporter().localVariablePotentialNullReference(local, expression);
                  continue;
                }
                break;
              case FlowContext.IN_COMPARISON_NON_NULL:
                this.nullReferences[i] = null;
                if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                  scope.problemReporter().localVariablePotentialNullReference(local, expression);
                  continue;
                }
                break;
            }
          } 
          break;
        case MAY_NULL:
          if (flowInfo.isDefinitelyNull(local)) {
            this.nullReferences[i] = null;
            scope.problemReporter().localVariableNullReference(local, expression);
            continue;
          }
          break;
        default:
          // never happens
      }
      this.parent.recordUsingNullReference(scope, local, expression,
          this.nullCheckTypes[i], flowInfo);
    }
  }
  else {
    // check inconsistent null checks on outermost looping context
    for (int i = 0; i < this.nullCount; i++) {
      Expression expression = this.nullReferences[i];
      // final local variable
      LocalVariableBinding local = this.nullLocals[i];
      switch (this.nullCheckTypes[i]) {
        case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL:
        case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL:
          if (flowInfo.isDefinitelyNonNull(local)) {
            this.nullReferences[i] = null;
View Full Code Here


    if (!isField()) {
      ASTNode node = this.resolver.findDeclaringNode(this);
      while (true) {
        if (node == null) {
          if (this.binding instanceof LocalVariableBinding) {
            LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
            BlockScope blockScope = localVariableBinding.declaringScope;
            if (blockScope != null) {
              ReferenceContext referenceContext = blockScope.referenceContext();
              if (referenceContext instanceof Initializer) {
                return null;
View Full Code Here

    }
    int sourceEnd = sourceStart+sourceLength-1;
    char[] typeSig = this.binding.type.genericTypeSignature();
    JavaElement parent = null;
    IMethodBinding declaringMethod = getDeclaringMethod();
    final LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
    if (declaringMethod == null) {
      ReferenceContext referenceContext = localVariableBinding.declaringScope.referenceContext();
      if (referenceContext instanceof TypeDeclaration){
        // Local variable is declared inside an initializer
        TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
View Full Code Here

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

      if (!fieldBinding.isStatic()) {
        currentScope.resetEnclosingMethodStaticFlag();
      }
      break;
    case Binding.LOCAL : // reading 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;
View Full Code Here

public void checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo, boolean checkString) {
  // cannot override localVariableBinding because this would project o.m onto o when
  // analyzing assignments
  if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.LOCAL) {
    LocalVariableBinding local = (LocalVariableBinding) this.binding;
    if (local != null &&
      (local.type.tagBits & TagBits.IsBaseType) == 0 &&
      (checkString || local.type.id != TypeIds.T_JavaLangString)) {
      if ((this.bits & ASTNode.IsNonNull) == 0) {
        flowContext.recordUsingNullReference(scope, local, this,
View Full Code Here

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

  //If inlinable field, forget the access emulation, the code gen will directly target it
  if (((this.bits & ASTNode.DepthMASK) == 0) || (this.constant != Constant.NotAConstant)) {
    return;
  }
  if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.LOCAL) {
    LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
    if (localVariableBinding != null) {
      if ((localVariableBinding.tagBits & TagBits.NotInitialized) != 0) {
        // local was tagged as uninitialized
        return;
      }
View Full Code Here

      case Binding.VARIABLE : //============only variable===========
      case Binding.TYPE | Binding.VARIABLE :
        if (this.binding instanceof LocalVariableBinding) {
          this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
          this.bits |= Binding.LOCAL;
          LocalVariableBinding local = (LocalVariableBinding) this.binding;
          if (!local.isFinal() && ((this.bits & ASTNode.DepthMASK) != 0)) {
            scope.problemReporter().cannotReferToNonFinalOuterLocal((LocalVariableBinding) this.binding, this);
          }
          if (local.type != null && (local.type.tagBits & TagBits.HasMissingType) != 0) {
            // only complain if field reference (for local, its type got flagged already)
            return null;
View Full Code Here

        }
        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
      LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
      if (!flowInfo.isDefinitelyAssigned(localBinding)){// for local variable debug attributes
        this.bits |= ASTNode.FirstAssignmentToLocal;
      } else {
        this.bits &= ~ASTNode.FirstAssignmentToLocal;
      }
      if (localBinding.isFinal()) {
        if ((this.bits & ASTNode.DepthMASK) == 0) {
          // tolerate assignment to final local in unreachable code (45674)
          if ((isReachable && isCompound) || !localBinding.isBlankFinal()){
            currentScope.problemReporter().cannotAssignToFinalLocal(localBinding, this);
          } else if (flowInfo.isPotentiallyAssigned(localBinding)) {
            currentScope.problemReporter().duplicateInitializationOfFinalLocal(localBinding, this);
          } else {
            flowContext.recordSettingFinal(localBinding, this, flowInfo);
View Full Code Here

TOP

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

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.