Exemplo n.º 1
0
  private static boolean equal(JValueLiteral literal1, JValueLiteral literal2) {
    if (literal1 == null || literal2 == null) {
      return literal1 == literal2;
    }

    if (literal1 == literal2) {
      return true;
    }

    if (literal1.getClass() != literal2.getClass()) {
      // these are different literal types.
      return false;
    }

    if (literal1 instanceof JFloatLiteral) {
      int bits1 = Float.floatToRawIntBits(((JFloatLiteral) literal1).getValue());
      int bits2 = Float.floatToRawIntBits(((JFloatLiteral) literal2).getValue());
      return bits1 == bits2;
    }

    if (literal1 instanceof JDoubleLiteral) {
      long bits1 = Double.doubleToRawLongBits(((JDoubleLiteral) literal1).getValue());
      long bits2 = Double.doubleToRawLongBits(((JDoubleLiteral) literal2).getValue());
      return bits1 == bits2;
    }

    Object valueObj1 = literal1.getValueObj();
    Object valueObj2 = literal2.getValueObj();
    if (valueObj1 == null || valueObj2 == null) {
      return valueObj1 == valueObj2;
    }

    return valueObj1.equals(valueObj2);
  }
    private boolean equalLiterals(JValueLiteral l1, JValueLiteral l2) {
      Object v1 = l1.getValueObj();
      Object v2 = l2.getValueObj();

      if (v1 == v2) {
        return true;
      }

      if (v1 == null || v2 == null) {
        return false;
      }

      return v1.equals(v2);
    }
 public void evaluatesInto(String string) {
   String actual = literal == null ? "<null>" : literal.toSource();
   assertEquals(string, actual);
 }
Exemplo n.º 4
0
 @Override
 public String toString() {
   return literal.toString();
 }