@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; }
@Nullable public static JetType getReceiverType(@NotNull JetType type) { assert isFunctionOrExtensionFunctionType(type) : type; if (isExtensionFunctionType(type)) { return type.getArguments().get(0).getType(); } return null; }
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); }
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; }
@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; }
public static boolean isNullableAny(@NotNull JetType type) { return isAnyOrNullableAny(type) && type.isMarkedNullable(); }
public static boolean isNullableNothing(@NotNull JetType type) { return isNothingOrNullableNothing(type) && type.isMarkedNullable(); }
private static boolean isNotNullConstructedFromGivenClass( @NotNull JetType type, @NotNull FqNameUnsafe fqName) { return !type.isMarkedNullable() && isConstructedFromGivenClass(type, fqName); }
private static boolean isConstructedFromGivenClass( @NotNull JetType type, @NotNull FqNameUnsafe fqName) { ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); return descriptor != null && fqName.equals(DescriptorUtils.getFqName(descriptor)); }
@NotNull public static JetType getReturnTypeFromFunctionType(@NotNull JetType type) { assert isFunctionOrExtensionFunctionType(type); List<TypeProjection> arguments = type.getArguments(); return arguments.get(arguments.size() - 1).getType(); }
public static boolean isPrimitiveType(@NotNull JetType type) { ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); return !type.isMarkedNullable() && descriptor != null && FQ_NAMES.primitiveTypes.contains(DescriptorUtils.getFqName(descriptor)); }