Пример #1
0
  public void testConstants() throws Exception {
    assertType("1", builtIns.getIntType());
    assertType("0x1", builtIns.getIntType());
    assertType("0X1", builtIns.getIntType());
    assertType("0b1", builtIns.getIntType());
    assertType("0B1", builtIns.getIntType());

    assertType("1.toLong()", builtIns.getLongType());

    assertType("1.0", builtIns.getDoubleType());
    assertType("1.0.toDouble()", builtIns.getDoubleType());
    assertType("0x1.fffffffffffffp1023", builtIns.getDoubleType());

    assertType("1.0.toFloat()", builtIns.getFloatType());
    assertType("0x1.fffffffffffffp1023.toFloat()", builtIns.getFloatType());

    assertType("true", builtIns.getBooleanType());
    assertType("false", builtIns.getBooleanType());

    assertType("'d'", builtIns.getCharType());

    assertType("\"d\"", builtIns.getStringType());
    assertType("\"\"\"d\"\"\"", builtIns.getStringType());

    assertType("Unit", KotlinBuiltIns.getInstance().getUnitType());

    assertType("null", KotlinBuiltIns.getInstance().getNullableNothingType());
  }
Пример #2
0
  @Nullable
  public static KotlinType getDefaultPrimitiveNumberType(
      @NotNull Collection<KotlinType> supertypes) {
    if (supertypes.isEmpty()) {
      return null;
    }

    KotlinBuiltIns builtIns = supertypes.iterator().next().getConstructor().getBuiltIns();
    KotlinType doubleType = builtIns.getDoubleType();
    if (supertypes.contains(doubleType)) {
      return doubleType;
    }
    KotlinType intType = builtIns.getIntType();
    if (supertypes.contains(intType)) {
      return intType;
    }
    KotlinType longType = builtIns.getLongType();
    if (supertypes.contains(longType)) {
      return longType;
    }
    return null;
  }
Пример #3
0
  public static Map<String, DeclarationDescriptor> prepareDefaultNameToDescriptors(
      Project project, KotlinCoreEnvironment environment) {
    KotlinBuiltIns builtIns = JvmPlatform.INSTANCE.getBuiltIns();

    Map<String, DeclarationDescriptor> nameToDescriptor =
        new HashMap<String, DeclarationDescriptor>();
    nameToDescriptor.put(
        "kotlin::Int.plus(Int)",
        standardFunction(builtIns.getInt(), "plus", project, builtIns.getIntType()));
    FunctionDescriptor descriptorForGet =
        standardFunction(builtIns.getArray(), "get", project, builtIns.getIntType());
    nameToDescriptor.put("kotlin::Array.get(Int)", descriptorForGet.getOriginal());
    nameToDescriptor.put(
        "kotlin::Int.compareTo(Double)",
        standardFunction(builtIns.getInt(), "compareTo", project, builtIns.getDoubleType()));
    @NotNull
    FunctionDescriptor descriptorForSet =
        standardFunction(
            builtIns.getArray(), "set", project, builtIns.getIntType(), builtIns.getIntType());
    nameToDescriptor.put("kotlin::Array.set(Int, Int)", descriptorForSet.getOriginal());

    return nameToDescriptor;
  }