Пример #1
0
  /**
   * Perform binary promotion of a pair of types; this routine implements JLS 5.6.2. If the input
   * types are not supported by unary promotion, if such types are identical to a type C, then C is
   * returned, otherwise Object is returned.
   */
  Type binaryPromotion(Type t1, Type t2) {
    Type unboxedT1 = types.unboxedTypeOrType(t1);
    Type unboxedT2 = types.unboxedTypeOrType(t2);

    if (unboxedT1.isNumeric() && unboxedT2.isNumeric()) {
      if (unboxedT1.hasTag(TypeTag.DOUBLE) || unboxedT2.hasTag(TypeTag.DOUBLE)) {
        return syms.doubleType;
      } else if (unboxedT1.hasTag(TypeTag.FLOAT) || unboxedT2.hasTag(TypeTag.FLOAT)) {
        return syms.floatType;
      } else if (unboxedT1.hasTag(TypeTag.LONG) || unboxedT2.hasTag(TypeTag.LONG)) {
        return syms.longType;
      } else {
        return syms.intType;
      }
    } else if (types.isSameType(unboxedT1, unboxedT2)) {
      return unboxedT1;
    } else {
      return syms.objectType;
    }
  }