コード例 #1
0
 @Override
 public DfaInstructionState[] visitPush(
     PushInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
   if (instruction.isReferenceRead()) {
     DfaValue dfaValue = instruction.getValue();
     if (dfaValue instanceof DfaVariableValue) {
       DfaConstValue constValue = memState.getConstantValue((DfaVariableValue) dfaValue);
       myPossibleVariableValues.putValue(
           instruction,
           constValue != null
                   && (constValue.getValue() == null || constValue.getValue() instanceof Boolean)
               ? constValue
               : ANY_VALUE);
     }
   }
   return super.visitPush(instruction, runner, memState);
 }
コード例 #2
0
  @Nullable
  private static DfaInstructionState[] checkComparingWithConstant(
      BinopInstruction instruction,
      DataFlowRunner runner,
      DfaMemoryState memState,
      DfaVariableValue var,
      IElementType opSign,
      double comparedWith) {
    DfaConstValue knownConstantValue = memState.getConstantValue(var);
    Object knownValue = knownConstantValue == null ? null : knownConstantValue.getValue();
    if (knownValue instanceof Number) {
      double knownDouble = ((Number) knownValue).doubleValue();
      return checkComparisonWithKnownRange(
          instruction, runner, memState, opSign, comparedWith, knownDouble, knownDouble);
    }

    PsiType varType = var.getVariableType();
    if (!(varType instanceof PsiPrimitiveType)) return null;

    if (varType == PsiType.FLOAT || varType == PsiType.DOUBLE) return null;

    double minValue =
        varType == PsiType.BYTE
            ? Byte.MIN_VALUE
            : varType == PsiType.SHORT
                ? Short.MIN_VALUE
                : varType == PsiType.INT
                    ? Integer.MIN_VALUE
                    : varType == PsiType.CHAR ? Character.MIN_VALUE : Long.MIN_VALUE;
    double maxValue =
        varType == PsiType.BYTE
            ? Byte.MAX_VALUE
            : varType == PsiType.SHORT
                ? Short.MAX_VALUE
                : varType == PsiType.INT
                    ? Integer.MAX_VALUE
                    : varType == PsiType.CHAR ? Character.MAX_VALUE : Long.MAX_VALUE;

    return checkComparisonWithKnownRange(
        instruction, runner, memState, opSign, comparedWith, minValue, maxValue);
  }