From 71605638e6c4d220bd12c2b463846e217606f856 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 19 Oct 2012 00:46:03 +0400 Subject: [PATCH] Extract method --- .../jet/lang/types/lang/KotlinBuiltIns.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java index 601c17d3b16..c1b3b23b983 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java @@ -804,14 +804,13 @@ public class KotlinBuiltIns { } public boolean isFunctionType(@NotNull JetType type) { - DeclarationDescriptor constructor = type.getConstructor().getDeclarationDescriptor(); - return functionClassesSet.contains(constructor) || extensionFunctionClassesSet.contains(constructor); + return setContainsClassOf(functionClassesSet, type) || setContainsClassOf(extensionFunctionClassesSet, type); } @Nullable public JetType getReceiverType(@NotNull JetType type) { assert isFunctionType(type) : type; - if (extensionFunctionClassesSet.contains(type.getConstructor().getDeclarationDescriptor())) { + if (setContainsClassOf(extensionFunctionClassesSet, type)) { return type.getArguments().get(0).getType(); } return null; @@ -843,7 +842,7 @@ public class KotlinBuiltIns { public List getParameterTypeProjectionsFromFunctionType(@NotNull JetType type) { assert isFunctionType(type); List arguments = type.getArguments(); - int first = extensionFunctionClassesSet.contains(type.getConstructor().getDeclarationDescriptor()) ? 1 : 0; + int first = setContainsClassOf(extensionFunctionClassesSet, type) ? 1 : 0; int last = arguments.size() - 2; List parameterTypes = Lists.newArrayList(); for (int i = first; i <= last; i++) { @@ -936,7 +935,7 @@ public class KotlinBuiltIns { @Deprecated public boolean isTupleType(@NotNull JetType type) { - return tupleClassesSet.contains(type.getConstructor().getDeclarationDescriptor()); + return setContainsClassOf(tupleClassesSet, type); } @NotNull @@ -961,11 +960,16 @@ public class KotlinBuiltIns { return new JetTypeImpl(annotations, tuple.getTypeConstructor(), false, typeArguments, tuple.getMemberScope(typeArguments)); } - private List toProjections(List arguments) { + private static List toProjections(List arguments) { List result = new ArrayList(); for (JetType argument : arguments) { result.add(new TypeProjection(Variance.OUT_VARIANCE, argument)); } return result; } + + private static boolean setContainsClassOf(ImmutableSet set, JetType type) { + //noinspection SuspiciousMethodCalls + return set.contains(type.getConstructor().getDeclarationDescriptor()); + } }