@NotNull private String renderDefaultType(@NotNull JetType type) { StringBuilder sb = new StringBuilder(); sb.append(renderTypeName(type.getConstructor())); if (!type.getArguments().isEmpty()) { sb.append("<"); appendTypeProjections(type.getArguments(), sb); sb.append(">"); } if (type.isNullable()) { sb.append("?"); } return sb.toString(); }
public static boolean containsErrorType(@Nullable JetType type) { if (type == null) return false; if (type.isError()) return true; for (TypeProjection projection : type.getArguments()) { if (containsErrorType(projection.getType())) return true; } return false; }
public static FunctionDescriptor getInvokeFunction(@NotNull JetType functionType) { assert KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(functionType); ClassifierDescriptor classDescriptorForFunction = functionType.getConstructor().getDeclarationDescriptor(); assert classDescriptorForFunction instanceof ClassDescriptor; Collection<FunctionDescriptor> invokeFunctions = ((ClassDescriptor) classDescriptorForFunction) .getMemberScope(functionType.getArguments()) .getFunctions(Name.identifier("invoke")); assert invokeFunctions.size() == 1; return invokeFunctions.iterator().next(); }
@NotNull private List<TypeProjection> getTypeArgsOfType( @NotNull JetType autoType, @NotNull ClassifierDescriptor classifier, @NotNull List<TypeAndVariance> typesFromSuper) { List<TypeProjection> autoArguments = autoType.getArguments(); if (!(classifier instanceof ClassDescriptor)) { assert autoArguments.isEmpty() : "Unexpected type arguments when type constructor is not ClassDescriptor, type = " + autoType; return autoArguments; } List<List<TypeProjectionAndVariance>> typeArgumentsFromSuper = calculateTypeArgumentsFromSuper((ClassDescriptor) classifier, typesFromSuper); // Modify type arguments using info from typesFromSuper List<TypeProjection> resultArguments = Lists.newArrayList(); for (TypeParameterDescriptor parameter : classifier.getTypeConstructor().getParameters()) { TypeProjection argument = autoArguments.get(parameter.getIndex()); JetType argumentType = argument.getType(); List<TypeProjectionAndVariance> projectionsFromSuper = typeArgumentsFromSuper.get(parameter.getIndex()); List<TypeAndVariance> argTypesFromSuper = getTypes(projectionsFromSuper); JetType type = modifyTypeAccordingToSuperMethods(argumentType, argTypesFromSuper, TYPE_ARGUMENT); Variance projectionKind = calculateArgumentProjectionKindFromSuper(argument, projectionsFromSuper); resultArguments.add(new TypeProjection(projectionKind, type)); } return resultArguments; }