示例#1
0
 @NotNull
 public JetType getArrayElementType(@NotNull JetType arrayType) {
   if (isArray(arrayType)) {
     if (arrayType.getArguments().size() != 1) {
       throw new IllegalStateException();
     }
     return arrayType.getArguments().get(0).getType();
   }
   JetType primitiveType =
       jetArrayTypeToPrimitiveJetType.get(TypeUtils.makeNotNullable(arrayType));
   if (primitiveType == null) {
     throw new IllegalStateException("not array: " + arrayType);
   }
   return primitiveType;
 }
示例#2
0
 @Nullable
 public static JetType getReceiverType(@NotNull JetType type) {
   assert isFunctionOrExtensionFunctionType(type) : type;
   if (isExtensionFunctionType(type)) {
     return type.getArguments().get(0).getType();
   }
   return null;
 }
示例#3
0
  private static boolean isTypeConstructorFqNameInSet(
      @NotNull JetType type, @NotNull Set<FqNameUnsafe> classes) {
    ClassifierDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();

    if (declarationDescriptor == null) return false;

    FqNameUnsafe fqName = DescriptorUtils.getFqName(declarationDescriptor);
    return classes.contains(fqName);
  }
示例#4
0
  public static boolean isExtensionFunctionType(@NotNull JetType type) {
    if (isExactExtensionFunctionType(type)) return true;

    for (JetType superType : type.getConstructor().getSupertypes()) {
      if (isExtensionFunctionType(superType)) return true;
    }

    return false;
  }
示例#5
0
 @NotNull
 public static List<TypeProjection> getParameterTypeProjectionsFromFunctionType(
     @NotNull JetType type) {
   assert isFunctionOrExtensionFunctionType(type);
   List<TypeProjection> arguments = type.getArguments();
   int first = isExtensionFunctionType(type) ? 1 : 0;
   int last = arguments.size() - 2;
   List<TypeProjection> parameterTypes = new ArrayList<TypeProjection>(last - first + 1);
   for (int i = first; i <= last; i++) {
     parameterTypes.add(arguments.get(i));
   }
   return parameterTypes;
 }
示例#6
0
 public static boolean isNullableAny(@NotNull JetType type) {
   return isAnyOrNullableAny(type) && type.isMarkedNullable();
 }
示例#7
0
 public static boolean isNullableNothing(@NotNull JetType type) {
   return isNothingOrNullableNothing(type) && type.isMarkedNullable();
 }
示例#8
0
 private static boolean isNotNullConstructedFromGivenClass(
     @NotNull JetType type, @NotNull FqNameUnsafe fqName) {
   return !type.isMarkedNullable() && isConstructedFromGivenClass(type, fqName);
 }
示例#9
0
 private static boolean isConstructedFromGivenClass(
     @NotNull JetType type, @NotNull FqNameUnsafe fqName) {
   ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
   return descriptor != null && fqName.equals(DescriptorUtils.getFqName(descriptor));
 }
示例#10
0
 @NotNull
 public static JetType getReturnTypeFromFunctionType(@NotNull JetType type) {
   assert isFunctionOrExtensionFunctionType(type);
   List<TypeProjection> arguments = type.getArguments();
   return arguments.get(arguments.size() - 1).getType();
 }
示例#11
0
 public static boolean isPrimitiveType(@NotNull JetType type) {
   ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
   return !type.isMarkedNullable()
       && descriptor != null
       && FQ_NAMES.primitiveTypes.contains(DescriptorUtils.getFqName(descriptor));
 }