Beispiel #1
0
  @Nullable("for boxed values which can't be compared by ==")
  private Integer getOrCreateEqClassIndex(@NotNull DfaValue dfaValue) {
    int i = getEqClassIndex(dfaValue);
    if (i != -1) return i;
    if (!canBeInRelation(dfaValue)
        || !canBeReused(dfaValue)
            && !(((DfaBoxedValue) dfaValue).getWrappedValue() instanceof DfaConstValue)) {
      return null;
    }
    int freeIndex = myEqClasses.indexOf(null);
    int resultIndex = freeIndex >= 0 ? freeIndex : myEqClasses.size();
    EqClass aClass = new EqClass(myFactory);
    aClass.add(dfaValue.getID());

    if (freeIndex >= 0) {
      myEqClasses.set(freeIndex, aClass);
    } else {
      myEqClasses.add(aClass);
    }
    addToMap(dfaValue.getID(), resultIndex);

    return resultIndex;
  }
Beispiel #2
0
  private int getEqClassIndex(@NotNull final DfaValue dfaValue) {
    final int id = unwrap(dfaValue).getID();
    int[] classes = myIdToEqClassesIndices.get(id);

    int result = -1;
    if (classes != null) {
      for (int index : classes) {
        EqClass aClass = myEqClasses.get(index);
        if (!aClass.contains(dfaValue.getID())) continue;
        if (!canBeReused(dfaValue) && aClass.size() > 1) break;
        result = index;
        break;
      }
    }
    return result;
  }
Beispiel #3
0
 private boolean checkCompareWithBooleanLiteral(
     DfaValue dfaLeft, DfaValue dfaRight, boolean negated) {
   if (dfaRight instanceof DfaConstValue) {
     Object constVal = ((DfaConstValue) dfaRight).getValue();
     if (constVal instanceof Boolean) {
       DfaConstValue negVal =
           myFactory
               .getConstFactory()
               .createFromValue(!((Boolean) constVal).booleanValue(), PsiType.BOOLEAN, null);
       if (!applyRelation(dfaLeft, negVal, !negated)) {
         return false;
       }
       if (!applyRelation(dfaLeft.createNegated(), negVal, negated)) {
         return false;
       }
     }
   }
   return true;
 }