Skip to content

Commit

Permalink
Generating map instead of initializing manually.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Gerashchenko authored and Evgeny Gerashchenko committed Feb 13, 2013
1 parent 522530e commit 14f3144
Showing 1 changed file with 14 additions and 11 deletions.
Expand Up @@ -22,23 +22,26 @@
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.lang.PrimitiveType;

import java.util.List;

import static org.jetbrains.jet.codegen.AsmUtil.isPrimitiveNumberClassDescriptor;

public class RangeCodegenUtil {
private static final ImmutableMap<String, JetType> RANGE_TO_ELEMENT_TYPE = ImmutableMap.<String, JetType>builder()
.put("ByteRange", KotlinBuiltIns.getInstance().getByteType())
.put("ShortRange", KotlinBuiltIns.getInstance().getShortType())
.put("IntRange", KotlinBuiltIns.getInstance().getIntType())
.put("LongRange", KotlinBuiltIns.getInstance().getLongType())
.put("FloatRange", KotlinBuiltIns.getInstance().getFloatType())
.put("DoubleRange", KotlinBuiltIns.getInstance().getDoubleType())
.put("CharRange", KotlinBuiltIns.getInstance().getCharType())
.build();
private static final ImmutableMap<FqName, PrimitiveType> RANGE_TO_ELEMENT_TYPE;

static {
ImmutableMap.Builder<FqName, PrimitiveType> rangeBuilder = ImmutableMap.builder();
for (PrimitiveType primitiveType : PrimitiveType.values()) {
rangeBuilder.put(primitiveType.getRangeClassName(), primitiveType);
}
RANGE_TO_ELEMENT_TYPE = rangeBuilder.build();
}

private RangeCodegenUtil() {}

Expand Down Expand Up @@ -77,14 +80,14 @@ else if (loopRange instanceof JetBinaryExpression) {
}

@Nullable
public static JetType getPrimitiveRangeElementType(JetType rangeType) {
private static PrimitiveType getPrimitiveRangeElementType(JetType rangeType) {
ClassifierDescriptor declarationDescriptor = rangeType.getConstructor().getDeclarationDescriptor();
assert declarationDescriptor != null;
if (declarationDescriptor != KotlinBuiltIns.getInstance().getBuiltInsScope().getClassifier(declarationDescriptor.getName())) {
// Must be a standard library class
return null;
}
return RANGE_TO_ELEMENT_TYPE.get(declarationDescriptor.getName().getName());
return RANGE_TO_ELEMENT_TYPE.get(DescriptorUtils.getFQName(declarationDescriptor).toSafe());
}

public static boolean isOptimizableRangeTo(CallableDescriptor rangeTo) {
Expand Down

0 comments on commit 14f3144

Please sign in to comment.