Package org.eclipse.jdt.internal.compiler.ast

Examples of org.eclipse.jdt.internal.compiler.ast.Expression


   * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ThrowStatement, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
   */
  public boolean visit(ThrowStatement throwStatement, BlockScope scope) {

    this.scribe.printNextToken(TerminalTokens.TokenNamethrow);
    Expression expression = throwStatement.exception;
    final int numberOfParens = (expression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
    if ((numberOfParens > 0 && this.preferences.insert_space_before_parenthesized_expression_in_throw)
        || numberOfParens == 0) {
      this.scribe.space();
    }
    expression.traverse(this, scope);
    /*
     * Print the semi-colon
     */
    this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
    this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
View Full Code Here


    this.scribe.printNextToken(operator, this.preferences.insert_space_before_unary_operator);
    if (this.preferences.insert_space_after_unary_operator) {
      this.scribe.space();
    }
    Expression expression = unaryExpression.expression;

    if (expression instanceof PrefixExpression) {
      PrefixExpression prefixExpression = (PrefixExpression) expression;
      final int numberOfParensForExpression = (prefixExpression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
      if (numberOfParensForExpression == 0) {
        switch(operatorValue) {
          case OperatorIds.PLUS:
            if (prefixExpression.operator == OperatorIds.PLUS) {
              this.scribe.space();
            }
            break;
          case OperatorIds.MINUS:
            if (prefixExpression.operator == OperatorIds.MINUS) {
              this.scribe.space();
            }
            break;
        }
      }
    } else if (expression instanceof UnaryExpression) {
      UnaryExpression unaryExpression2 = (UnaryExpression) expression;
      final int numberOfParensForExpression = (unaryExpression2.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
      if (numberOfParensForExpression == 0) {
        int operatorValue2 = (unaryExpression2.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT;
        switch(operatorValue) {
          case OperatorIds.PLUS:
            if (operatorValue2 == OperatorIds.PLUS) {
              this.scribe.space();
            }
            break;
          case OperatorIds.MINUS:
            if (operatorValue2 == OperatorIds.MINUS) {
              this.scribe.space();
            }
            break;
        }
      }
    }
    expression.traverse(this, scope);

    if (numberOfParens > 0) {
      manageClosingParenthesizedExpression(unaryExpression, numberOfParens);
    }
    return false;
View Full Code Here

  this.visitIfNeeded(methodDeclaration);

  if (isInRange) {
    if (methodDeclaration instanceof AnnotationMethodDeclaration) {
      AnnotationMethodDeclaration annotationMethodDeclaration = (AnnotationMethodDeclaration) methodDeclaration;
      Expression expression = annotationMethodDeclaration.defaultValue;
      if (expression != null) {
        this.requestor.exitMethod(methodDeclaration.declarationSourceEnd, expression);
        return;
      }
    }
View Full Code Here

          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:
          Expression expression = (Expression)location;
          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 & ~HIDE_NULL_COMPARISON_WARNING_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.nullCheckTypes[i] & HIDE_NULL_COMPARISON_WARNING) == 0) {
                  scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
                }
                continue;
              case FlowContext.IN_COMPARISON_NON_NULL:
                if (((this.nullCheckTypes[i] & CHECK_MASK & ~HIDE_NULL_COMPARISON_WARNING_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                  scope.problemReporter().localVariableNullReference(local, expression);
                  continue;
                }
                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 & ~HIDE_NULL_COMPARISON_WARNING_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 & ~HIDE_NULL_COMPARISON_WARNING_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, location);
            continue;
          }
          break;
        case ASSIGN_TO_NONNULL:
          int nullStatus = flowInfo.nullStatus(local);
          if (nullStatus != FlowInfo.NON_NULL) {
            this.parent.recordNullityMismatch(scope, (Expression)location, this.providedExpectedTypes[i][0], this.providedExpectedTypes[i][1], nullStatus);
          }
          break;
        case EXIT_RESOURCE:
            FakedTrackingVariable trackingVar = local.closeTracker;
            if (trackingVar != null) {
              if (trackingVar.hasDefinitelyNoResource(flowInfo)) {
                continue; // no resource - no warning.
              }
              if (trackingVar.isClosedInFinallyOfEnclosing(scope)) {
                continue;
              }
              if (this.parent.recordExitAgainstResource(scope, flowInfo, trackingVar, location)) {
                this.nullReferences[i] = null;
                continue;
              }
            }
          break;
        case IN_UNBOXING:
          checkUnboxing(scope, (Expression) location, flowInfo);
          continue; // delegation to parent already handled in the above.
        default:
          // never happens
      }
      // https://bugs.eclipse.org/376263: avoid further deferring if the upstream info
      // already has definite information (which might get lost for deferred checking).
      if (!(this.nullCheckTypes[i] == MAY_NULL && upstreamCopy.isDefinitelyNonNull(local))) {
        this.parent.recordUsingNullReference(scope, local, location,
            this.nullCheckTypes[i], flowInfo);
      }
    }
  }
  else {
    // check inconsistent null checks on outermost looping context
    for (int i = 0; i < this.nullCount; i++) {
      ASTNode location = this.nullReferences[i];
      // final local variable
      LocalVariableBinding local = this.nullLocals[i];
      switch (this.nullCheckTypes[i] & ~HIDE_NULL_COMPARISON_WARNING_MASK) {
        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] & ~HIDE_NULL_COMPARISON_WARNING_MASK) == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) {
              if ((this.nullCheckTypes[i] & HIDE_NULL_COMPARISON_WARNING) == 0) {
                scope.problemReporter().localVariableRedundantCheckOnNonNull(local, location);
              }
            } else {
              scope.problemReporter().localVariableNonNullComparedToNull(local, location);
            }
            continue;
          }
          //$FALL-THROUGH$
        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:
          Expression expression = (Expression) location;
          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 & ~HIDE_NULL_COMPARISON_WARNING_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
View Full Code Here

  checkType |= (this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING);
  int checkTypeWithoutHideNullWarning = checkType & ~FlowContext.HIDE_NULL_COMPARISON_WARNING_MASK;
  switch (checkTypeWithoutHideNullWarning) {
    case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL:
    case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL:
      Expression reference = (Expression)location;
      if (flowInfo.isDefinitelyNonNull(local)) {
        if (checkTypeWithoutHideNullWarning == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) {
          if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
            scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
          }
View Full Code Here

  // all related catch blocks are marked as reachable... instead of those only
  // until the point where it is safely handled (Smarter - see comment at the end)
  FlowContext traversedContext = this;
  ArrayList abruptlyExitedLoops = null;
  if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_7 && location instanceof ThrowStatement) {
    Expression throwExpression = ((ThrowStatement)location).exception;
    LocalVariableBinding throwArgBinding = throwExpression.localVariableBinding();
    if (throwExpression instanceof SingleNameReference // https://bugs.eclipse.org/bugs/show_bug.cgi?id=350361
        && throwArgBinding instanceof CatchParameterBinding && throwArgBinding.isEffectivelyFinal()) {
      CatchParameterBinding parameter = (CatchParameterBinding) throwArgBinding;
      checkExceptionHandlers(parameter.getPreciseTypes(), location, flowInfo, scope);
      return;
View Full Code Here

      //$FALL-THROUGH$
    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:
      Expression reference = (Expression)location;
      if (flowInfo.isDefinitelyNull(local)) {
        switch(checkTypeWithoutHideNullWarning & CONTEXT_MASK) {
          case FlowContext.IN_COMPARISON_NULL:
            if (((checkTypeWithoutHideNullWarning & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
              scope.problemReporter().localVariableNullReference(local, reference);
View Full Code Here

          //$FALL-THROUGH$
        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:
          Expression expression = (Expression) location;
          if (flowInfo.isDefinitelyNull(local)) {
            switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
              case FlowContext.IN_COMPARISON_NULL:
                if (((this.nullCheckTypes[i] & CHECK_MASK & ~HIDE_NULL_COMPARISON_WARNING_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                  scope.problemReporter().localVariableNullReference(local, expression);
View Full Code Here

          case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL:
          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:
            Expression reference = (Expression) location;
            if (flowInfo.cannotBeNull(local)) {
              if (checkTypeWithoutHideNullWarning == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) {
                if ((checkType & HIDE_NULL_COMPARISON_WARNING) == 0) {
                  scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
                }
                flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
              } else if (checkTypeWithoutHideNullWarning == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) {
                scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
                flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
              }
              return;
            }
            if (flowInfo.canOnlyBeNull(local)) {
              switch(checkTypeWithoutHideNullWarning & CONTEXT_MASK) {
                case FlowContext.IN_COMPARISON_NULL:
                  if (((checkTypeWithoutHideNullWarning & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                    scope.problemReporter().localVariableNullReference(local, reference);
                    return;
                  }
                  if ((checkType & HIDE_NULL_COMPARISON_WARNING) == 0) {
                    scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
                  }
                  flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
                  return;
                case FlowContext.IN_COMPARISON_NON_NULL:
                  if (((checkTypeWithoutHideNullWarning & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                    scope.problemReporter().localVariableNullReference(local, reference);
                    return;
                  }
                  scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
                  flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
                  return;
                case FlowContext.IN_ASSIGNMENT:
                  scope.problemReporter().localVariableRedundantNullAssignment(local, reference);
                  return;
                case FlowContext.IN_INSTANCEOF:
                  scope.problemReporter().localVariableNullInstanceof(local, reference);
                  return;
              }
            } else if (flowInfo.isPotentiallyNull(local)) {
              switch(checkTypeWithoutHideNullWarning & CONTEXT_MASK) {
                case FlowContext.IN_COMPARISON_NULL:
                  if (((checkTypeWithoutHideNullWarning & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                    scope.problemReporter().localVariablePotentialNullReference(local, reference);
                    return;
                  }
                  break;
                case FlowContext.IN_COMPARISON_NON_NULL:
                  if (((checkTypeWithoutHideNullWarning & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                    scope.problemReporter().localVariablePotentialNullReference(local, reference);
                    return;
                  }
                  break;
              }
            }
            break;
          case MAY_NULL :
            if (flowInfo.cannotBeNull(local)) {
              return;
            }
            if (flowInfo.canOnlyBeNull(local)) {
              scope.problemReporter().localVariableNullReference(local, location);
              return;
            }
            break;
          default:
            // never happens
        }
      }
      else { // no enclosing loop, be as precise as possible right now
        switch (checkTypeWithoutHideNullWarning) {
          case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL:
          case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL:
            if (flowInfo.isDefinitelyNonNull(local)) {
              if (checkTypeWithoutHideNullWarning == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) {
                if ((checkType & HIDE_NULL_COMPARISON_WARNING) == 0) {
                  scope.problemReporter().localVariableRedundantCheckOnNonNull(local, location);
                }
                flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
              } else {
                scope.problemReporter().localVariableNonNullComparedToNull(local, location);
                flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
              }
              return;
            }
            //$FALL-THROUGH$
          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:
            Expression reference = (Expression) location;
            if (flowInfo.isDefinitelyNull(local)) {
              switch(checkTypeWithoutHideNullWarning & CONTEXT_MASK) {
                case FlowContext.IN_COMPARISON_NULL:
                  if (((checkTypeWithoutHideNullWarning & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                    scope.problemReporter().localVariableNullReference(local, reference);
View Full Code Here

  // all related catch blocks are marked as reachable... instead of those only
  // until the point where it is safely handled (Smarter - see comment at the end)
  FlowContext traversedContext = this;
  ArrayList abruptlyExitedLoops = null;
  if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_7 && location instanceof ThrowStatement) {
    Expression throwExpression = ((ThrowStatement)location).exception;
    LocalVariableBinding throwArgBinding = throwExpression.localVariableBinding();
    if (throwExpression instanceof SingleNameReference // https://bugs.eclipse.org/bugs/show_bug.cgi?id=350361
        && throwArgBinding instanceof CatchParameterBinding && throwArgBinding.isEffectivelyFinal()) {
      CatchParameterBinding parameter = (CatchParameterBinding) throwArgBinding;
      checkExceptionHandlers(parameter.getPreciseTypes(), location, flowInfo, scope);
      return;
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.ast.Expression

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.