Methods in KotlinBuiltIns made static where already possible

This commit is contained in:
Andrey Breslav
2014-12-02 15:50:16 +03:00
parent 75c887048e
commit ea4f0ab214
25 changed files with 68 additions and 72 deletions
@@ -367,9 +367,8 @@ public class ConstraintSystemImpl implements ConstraintSystem {
assert superType != TypeUtils.PLACEHOLDER_FUNCTION_TYPE : "The type for " + constraintPosition + " shouldn't be a placeholder for function type";
KotlinBuiltIns kotlinBuiltIns = KotlinBuiltIns.getInstance();
if (subType == TypeUtils.PLACEHOLDER_FUNCTION_TYPE) {
if (!kotlinBuiltIns.isFunctionOrExtensionFunctionType(superType)) {
if (!KotlinBuiltIns.isFunctionOrExtensionFunctionType(superType)) {
if (isMyTypeVariable(superType)) {
// a constraint binds type parameter and any function type, so there is no new info and no error
return;
@@ -383,7 +382,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
// function literal without declaring receiver type { x -> ... }
// can be considered as extension function if one is expected
// (special type constructor for function/ extension function should be introduced like PLACEHOLDER_FUNCTION_TYPE)
if (constraintKind == SUB_TYPE && kotlinBuiltIns.isFunctionType(subType) && kotlinBuiltIns.isExtensionFunctionType(superType)) {
if (constraintKind == SUB_TYPE && KotlinBuiltIns.isFunctionType(subType) && KotlinBuiltIns.isExtensionFunctionType(superType)) {
subType = createCorrespondingExtensionFunctionType(subType, DONT_CARE);
}
@@ -522,7 +521,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
@NotNull
public static JetType createCorrespondingExtensionFunctionType(@NotNull JetType functionType, @NotNull JetType receiverType) {
assert KotlinBuiltIns.getInstance().isFunctionType(functionType);
assert KotlinBuiltIns.isFunctionType(functionType);
List<TypeProjection> typeArguments = functionType.getArguments();
assert !typeArguments.isEmpty();
@@ -103,7 +103,7 @@ public class KotlinBuiltIns {
private final Map<JetType, JetType> primitiveJetTypeToJetArrayType;
private final Map<JetType, JetType> jetArrayTypeToPrimitiveJetType;
private final FqNames fqNames = new FqNames();
private static final FqNames FQ_NAMES = new FqNames();
private KotlinBuiltIns() {
builtInsModule = new ModuleDescriptorImpl(
@@ -734,11 +734,11 @@ public class KotlinBuiltIns {
// Functions
public boolean isFunctionOrExtensionFunctionType(@NotNull JetType type) {
public static boolean isFunctionOrExtensionFunctionType(@NotNull JetType type) {
return isFunctionType(type) || isExtensionFunctionType(type);
}
public boolean isFunctionType(@NotNull JetType type) {
public static boolean isFunctionType(@NotNull JetType type) {
if (isExactFunctionType(type)) return true;
for (JetType superType : type.getConstructor().getSupertypes()) {
@@ -748,7 +748,7 @@ public class KotlinBuiltIns {
return false;
}
public boolean isExtensionFunctionType(@NotNull JetType type) {
public static boolean isExtensionFunctionType(@NotNull JetType type) {
if (isExactExtensionFunctionType(type)) return true;
for (JetType superType : type.getConstructor().getSupertypes()) {
@@ -758,16 +758,16 @@ public class KotlinBuiltIns {
return false;
}
public boolean isExactFunctionOrExtensionFunctionType(@NotNull JetType type) {
public static boolean isExactFunctionOrExtensionFunctionType(@NotNull JetType type) {
return isExactFunctionType(type) || isExactExtensionFunctionType(type);
}
public boolean isExactFunctionType(@NotNull JetType type) {
return isTypeConstructorFqNameInSet(type, fqNames.functionClasses);
public static boolean isExactFunctionType(@NotNull JetType type) {
return isTypeConstructorFqNameInSet(type, FQ_NAMES.functionClasses);
}
public boolean isExactExtensionFunctionType(@NotNull JetType type) {
return isTypeConstructorFqNameInSet(type, fqNames.extensionFunctionClasses);
public static boolean isExactExtensionFunctionType(@NotNull JetType type) {
return isTypeConstructorFqNameInSet(type, FQ_NAMES.extensionFunctionClasses);
}
private static boolean isTypeConstructorFqNameInSet(@NotNull JetType type, @NotNull Set<FqNameUnsafe> classes) {
@@ -780,7 +780,7 @@ public class KotlinBuiltIns {
}
@Nullable
public JetType getReceiverType(@NotNull JetType type) {
public static JetType getReceiverType(@NotNull JetType type) {
assert isFunctionOrExtensionFunctionType(type) : type;
if (isExtensionFunctionType(type)) {
return type.getArguments().get(0).getType();
@@ -789,7 +789,7 @@ public class KotlinBuiltIns {
}
@NotNull
public List<ValueParameterDescriptor> getValueParameters(@NotNull FunctionDescriptor functionDescriptor, @NotNull JetType type) {
public static List<ValueParameterDescriptor> getValueParameters(@NotNull FunctionDescriptor functionDescriptor, @NotNull JetType type) {
assert isFunctionOrExtensionFunctionType(type);
List<TypeProjection> parameterTypes = getParameterTypeProjectionsFromFunctionType(type);
List<ValueParameterDescriptor> valueParameters = new ArrayList<ValueParameterDescriptor>(parameterTypes.size());
@@ -805,14 +805,14 @@ public class KotlinBuiltIns {
}
@NotNull
public JetType getReturnTypeFromFunctionType(@NotNull JetType type) {
public static JetType getReturnTypeFromFunctionType(@NotNull JetType type) {
assert isFunctionOrExtensionFunctionType(type);
List<TypeProjection> arguments = type.getArguments();
return arguments.get(arguments.size() - 1).getType();
}
@NotNull
public List<TypeProjection> getParameterTypeProjectionsFromFunctionType(@NotNull JetType type) {
public static List<TypeProjection> getParameterTypeProjectionsFromFunctionType(@NotNull JetType type) {
assert isFunctionOrExtensionFunctionType(type);
List<TypeProjection> arguments = type.getArguments();
int first = isExtensionFunctionType(type) ? 1 : 0;
@@ -826,13 +826,13 @@ public class KotlinBuiltIns {
// Recognized & special
public boolean isSpecialClassWithNoSupertypes(@NotNull ClassDescriptor descriptor) {
public static boolean isSpecialClassWithNoSupertypes(@NotNull ClassDescriptor descriptor) {
FqNameUnsafe fqName = DescriptorUtils.getFqName(descriptor);
return fqNames.any.equals(fqName) || fqNames.nothing.equals(fqName);
return FQ_NAMES.any.equals(fqName) || FQ_NAMES.nothing.equals(fqName);
}
public boolean isAny(@NotNull ClassDescriptor descriptor) {
return fqNames.any.equals(DescriptorUtils.getFqName(descriptor));
public static boolean isAny(@NotNull ClassDescriptor descriptor) {
return FQ_NAMES.any.equals(DescriptorUtils.getFqName(descriptor));
}
public boolean isNothing(@NotNull JetType type) {
@@ -861,8 +861,8 @@ public class KotlinBuiltIns {
return getStringType().equals(type);
}
public boolean isCloneable(@NotNull ClassDescriptor descriptor) {
return fqNames.cloneable.equals(DescriptorUtils.getFqName(descriptor));
public static boolean isCloneable(@NotNull ClassDescriptor descriptor) {
return FQ_NAMES.cloneable.equals(DescriptorUtils.getFqName(descriptor));
}
public boolean isData(@NotNull ClassDescriptor classDescriptor) {
@@ -877,9 +877,9 @@ public class KotlinBuiltIns {
return containsAnnotation(declarationDescriptor, getTailRecursiveAnnotationClass());
}
public boolean isSuppressAnnotation(@NotNull AnnotationDescriptor annotationDescriptor) {
public static boolean isSuppressAnnotation(@NotNull AnnotationDescriptor annotationDescriptor) {
ClassifierDescriptor classifier = annotationDescriptor.getType().getConstructor().getDeclarationDescriptor();
return classifier != null && fqNames.suppress.equals(DescriptorUtils.getFqName(classifier));
return classifier != null && FQ_NAMES.suppress.equals(DescriptorUtils.getFqName(classifier));
}
static boolean containsAnnotation(DeclarationDescriptor descriptor, ClassDescriptor annotationClass) {
@@ -43,7 +43,6 @@ import org.jetbrains.jet.utils.UtilsPackage;
import java.util.*;
import static org.jetbrains.jet.lang.types.TypeUtils.CANT_INFER_LAMBDA_PARAM_TYPE;
import static org.jetbrains.jet.lang.types.TypeUtils.DONT_CARE;
public class DescriptorRendererImpl implements DescriptorRenderer {
@@ -360,7 +359,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
}
private boolean shouldRenderAsPrettyFunctionType(@NotNull JetType type) {
return KotlinBuiltIns.getInstance().isExactFunctionOrExtensionFunctionType(type) && prettyFunctionTypes;
return KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type) && prettyFunctionTypes;
}
@NotNull
@@ -484,16 +483,16 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
private String renderFunctionType(@NotNull JetType type) {
StringBuilder sb = new StringBuilder();
JetType receiverType = KotlinBuiltIns.getInstance().getReceiverType(type);
JetType receiverType = KotlinBuiltIns.getReceiverType(type);
if (receiverType != null) {
sb.append(renderNormalizedType(receiverType));
sb.append(".");
}
sb.append("(");
appendTypeProjections(KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(type), sb);
appendTypeProjections(KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(type), sb);
sb.append(") ").append(arrow()).append(" ");
sb.append(renderNormalizedType(KotlinBuiltIns.getInstance().getReturnTypeFromFunctionType(type)));
sb.append(renderNormalizedType(KotlinBuiltIns.getReturnTypeFromFunctionType(type)));
if (type.isNullable()) {
return "(" + sb + ")?";
@@ -91,7 +91,7 @@ public class DescriptorSerializer {
builder.addTypeParameter(typeParameter(typeParameterDescriptor));
}
if (!KotlinBuiltIns.getInstance().isSpecialClassWithNoSupertypes(classDescriptor)) {
if (!KotlinBuiltIns.isSpecialClassWithNoSupertypes(classDescriptor)) {
// Special classes (Any, Nothing) have no supertypes
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
builder.addSupertype(type(supertype));