Split CompileTimeConstant into two entities

1. ConstantValue
	* just holds some value and its type
	* implementations for concrete constants
2. CompileTimeConstant
	* is only produced by ConstantExpressionEvaluator
	* has additional flags (canBeUsedInAnnotation etc)
	* has two implementations TypedCompileTimeConstant containing a constant value
		and IntegerValueConstant which does not have exact type
	* can be converted to ConstantValue

Adjustt usages to use ConstantValue if flags are not needed
Add tests for some uncovered cases
This commit is contained in:
Pavel V. Talanov
2015-07-07 14:56:19 +03:00
parent 155f00578d
commit c313887641
134 changed files with 791 additions and 907 deletions
@@ -187,9 +187,9 @@ public abstract class AnnotationCodegen {
return !type.isMarkedNullable() && classifier instanceof TypeParameterDescriptor && TypeUtils.hasNullableSuperType(type);
}
public void generateAnnotationDefaultValue(@NotNull CompileTimeConstant value, @NotNull JetType expectedType) {
public void generateAnnotationDefaultValue(@NotNull ConstantValue<?> value, @NotNull JetType expectedType) {
AnnotationVisitor visitor = visitAnnotation(null, false); // Parameters are unimportant
genCompileTimeValue(null, value, expectedType, visitor);
genCompileTimeValue(null, value, visitor);
visitor.visitEnd();
}
@@ -212,17 +212,16 @@ public abstract class AnnotationCodegen {
}
private void genAnnotationArguments(AnnotationDescriptor annotationDescriptor, AnnotationVisitor annotationVisitor) {
for (Map.Entry<ValueParameterDescriptor, CompileTimeConstant<?>> entry : annotationDescriptor.getAllValueArguments().entrySet()) {
for (Map.Entry<ValueParameterDescriptor, ConstantValue<?>> entry : annotationDescriptor.getAllValueArguments().entrySet()) {
ValueParameterDescriptor descriptor = entry.getKey();
String name = descriptor.getName().asString();
genCompileTimeValue(name, entry.getValue(), descriptor.getType(), annotationVisitor);
genCompileTimeValue(name, entry.getValue(), annotationVisitor);
}
}
private void genCompileTimeValue(
@Nullable final String name,
@NotNull CompileTimeConstant<?> value,
@NotNull final JetType expectedType,
@NotNull ConstantValue<?> value,
@NotNull final AnnotationVisitor annotationVisitor
) {
AnnotationArgumentVisitor argumentVisitor = new AnnotationArgumentVisitor<Void, Void>() {
@@ -281,8 +280,8 @@ public abstract class AnnotationCodegen {
@Override
public Void visitArrayValue(ArrayValue value, Void data) {
AnnotationVisitor visitor = annotationVisitor.visitArray(name);
for (CompileTimeConstant<?> argument : value.getValue()) {
genCompileTimeValue(null, argument, value.getType(), visitor);
for (ConstantValue<?> argument : value.getValue()) {
genCompileTimeValue(null, argument, visitor);
}
visitor.visitEnd();
return null;
@@ -303,14 +302,7 @@ public abstract class AnnotationCodegen {
return null;
}
@Override
public Void visitNumberTypeValue(IntegerValueTypeConstant value, Void data) {
Object numberType = value.getValue(expectedType);
annotationVisitor.visit(name, numberType);
return null;
}
private Void visitSimpleValue(CompileTimeConstant value) {
private Void visitSimpleValue(ConstantValue<?> value) {
annotationVisitor.visit(name, value.getValue());
return null;
}
@@ -325,7 +317,7 @@ public abstract class AnnotationCodegen {
return visitUnsupportedValue(value);
}
private Void visitUnsupportedValue(CompileTimeConstant value) {
private Void visitUnsupportedValue(ConstantValue<?> value) {
throw new IllegalStateException("Don't know how to compile annotation value " + value);
}
};
@@ -349,7 +341,7 @@ public abstract class AnnotationCodegen {
private RetentionPolicy getRetentionPolicy(@NotNull Annotated descriptor) {
AnnotationDescriptor kotlinAnnotation = descriptor.getAnnotations().findAnnotation(KotlinBuiltIns.FQ_NAMES.annotation);
if (kotlinAnnotation != null) {
for (Map.Entry<ValueParameterDescriptor, CompileTimeConstant<?>> argument: kotlinAnnotation.getAllValueArguments().entrySet()) {
for (Map.Entry<ValueParameterDescriptor, ConstantValue<?>> argument: kotlinAnnotation.getAllValueArguments().entrySet()) {
if ("retention".equals(argument.getKey().getName().asString()) && argument.getValue() instanceof EnumValue) {
ClassDescriptor enumEntry = ((EnumValue) argument.getValue()).getValue();
JetType classObjectType = getClassObjectType(enumEntry);
@@ -366,9 +358,9 @@ public abstract class AnnotationCodegen {
}
AnnotationDescriptor retentionAnnotation = descriptor.getAnnotations().findAnnotation(new FqName(Retention.class.getName()));
if (retentionAnnotation != null) {
Collection<CompileTimeConstant<?>> valueArguments = retentionAnnotation.getAllValueArguments().values();
Collection<ConstantValue<?>> valueArguments = retentionAnnotation.getAllValueArguments().values();
if (!valueArguments.isEmpty()) {
CompileTimeConstant<?> compileTimeConstant = valueArguments.iterator().next();
ConstantValue<?> compileTimeConstant = valueArguments.iterator().next();
if (compileTimeConstant instanceof EnumValue) {
ClassDescriptor enumEntry = ((EnumValue) compileTimeConstant).getValue();
JetType classObjectType = getClassObjectType(enumEntry);
@@ -49,12 +49,12 @@ import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.impl.ScriptCodeDescriptor;
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils;
import org.jetbrains.kotlin.diagnostics.Errors;
import org.jetbrains.kotlin.jvm.RuntimeAssertionInfo;
import org.jetbrains.kotlin.jvm.bindingContextSlices.BindingContextSlicesPackage;
import org.jetbrains.kotlin.lexer.JetTokens;
import org.jetbrains.kotlin.load.java.JvmAbi;
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor;
import org.jetbrains.kotlin.jvm.RuntimeAssertionInfo;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
@@ -68,9 +68,8 @@ import org.jetbrains.kotlin.resolve.calls.model.*;
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
import org.jetbrains.kotlin.resolve.constants.evaluate.EvaluatePackage;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage;
import org.jetbrains.kotlin.resolve.inline.InlineUtil;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
@@ -1292,20 +1291,19 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
@Override
public StackValue visitConstantExpression(@NotNull JetConstantExpression expression, StackValue receiver) {
CompileTimeConstant<?> compileTimeValue = getCompileTimeConstant(expression, bindingContext);
ConstantValue<?> compileTimeValue = getCompileTimeConstant(expression, bindingContext);
assert compileTimeValue != null;
return StackValue.constant(compileTimeValue.getValue(), expressionType(expression));
}
@Nullable
public static CompileTimeConstant getCompileTimeConstant(@NotNull JetExpression expression, @NotNull BindingContext bindingContext) {
public static ConstantValue<?> getCompileTimeConstant(@NotNull JetExpression expression, @NotNull BindingContext bindingContext) {
CompileTimeConstant<?> compileTimeValue = ConstantExpressionEvaluator.getConstant(expression, bindingContext);
if (compileTimeValue instanceof IntegerValueTypeConstant) {
JetType expectedType = bindingContext.getType(expression);
assert expectedType != null : "Expression is not type checked: " + expression.getText();
return EvaluatePackage.createCompileTimeConstantWithType((IntegerValueTypeConstant) compileTimeValue, expectedType);
if (compileTimeValue == null) {
return null;
}
return compileTimeValue;
JetType expectedType = bindingContext.getType(expression);
return compileTimeValue.toConstantValue(expectedType);
}
@Override
@@ -3012,7 +3010,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
private boolean isIntZero(JetExpression expr, Type exprType) {
CompileTimeConstant<?> exprValue = getCompileTimeConstant(expr, bindingContext);
ConstantValue<?> exprValue = getCompileTimeConstant(expr, bindingContext);
return isIntPrimitive(exprType) && exprValue != null && Integer.valueOf(0).equals(exprValue.getValue());
}
@@ -45,7 +45,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.annotations.AnnotationsPackage;
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.CallResolverUtilPackage;
import org.jetbrains.kotlin.resolve.constants.ArrayValue;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.constants.KClassValue;
import org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage;
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
@@ -538,7 +538,7 @@ public class FunctionCodegen {
AnnotationDescriptor annotation = function.getAnnotations().findAnnotation(new FqName("kotlin.throws"));
if (annotation == null) return ArrayUtil.EMPTY_STRING_ARRAY;
Collection<CompileTimeConstant<?>> values = annotation.getAllValueArguments().values();
Collection<ConstantValue<?>> values = annotation.getAllValueArguments().values();
if (values.isEmpty()) return ArrayUtil.EMPTY_STRING_ARRAY;
Object value = values.iterator().next();
@@ -547,9 +547,9 @@ public class FunctionCodegen {
List<String> strings = ContainerUtil.mapNotNull(
arrayValue.getValue(),
new Function<CompileTimeConstant<?>, String>() {
new Function<ConstantValue<?>, String>() {
@Override
public String fun(CompileTimeConstant<?> constant) {
public String fun(ConstantValue<?> constant) {
if (constant instanceof KClassValue) {
KClassValue classValue = (KClassValue) constant;
ClassDescriptor classDescriptor = DescriptorUtils.getClassDescriptorForType(classValue.getValue());
@@ -39,8 +39,7 @@ import org.jetbrains.kotlin.resolve.BindingContextUtils;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage;
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
@@ -379,26 +378,28 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
JetExpression initializer = property.getInitializer();
CompileTimeConstant<?> initializerValue;
if (property.isVar() && initializer != null) {
BindingTrace tempTrace = TemporaryBindingTrace.create(state.getBindingTrace(), "property initializer");
initializerValue = ConstantExpressionEvaluator.evaluate(initializer, tempTrace, propertyDescriptor.getType());
}
else {
initializerValue = propertyDescriptor.getCompileTimeInitializer();
}
ConstantValue<?> initializerValue = computeInitializerValue(property, propertyDescriptor, initializer);
// we must write constant values for fields in light classes,
// because Java's completion for annotation arguments uses this information
if (initializerValue == null) return state.getClassBuilderMode() != ClassBuilderMode.LIGHT_CLASSES;
//TODO: OPTIMIZATION: don't initialize static final fields
Object value = initializerValue instanceof IntegerValueTypeConstant
? ((IntegerValueTypeConstant) initializerValue).getValue(propertyDescriptor.getType())
: initializerValue.getValue();
JetType jetType = getPropertyOrDelegateType(property, propertyDescriptor);
Type type = typeMapper.mapType(jetType);
return !skipDefaultValue(propertyDescriptor, value, type);
return !skipDefaultValue(propertyDescriptor, initializerValue.getValue(), type);
}
@Nullable
private ConstantValue<?> computeInitializerValue(
@NotNull JetProperty property,
@NotNull PropertyDescriptor propertyDescriptor,
@Nullable JetExpression initializer
) {
if (property.isVar() && initializer != null) {
BindingTrace tempTrace = TemporaryBindingTrace.create(state.getBindingTrace(), "property initializer");
return ConstantExpressionEvaluator.evaluateToConstantValue(initializer, tempTrace, propertyDescriptor.getType());
}
return propertyDescriptor.getCompileTimeInitializer();
}
@NotNull
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.resolve.DescriptorFactory;
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
import org.jetbrains.kotlin.resolve.annotations.AnnotationsPackage;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor;
import org.jetbrains.kotlin.types.ErrorUtils;
@@ -180,7 +180,7 @@ public class PropertyCodegen {
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
JetExpression defaultValue = p.getDefaultValue();
if (defaultValue != null) {
CompileTimeConstant<?> constant = ExpressionCodegen.getCompileTimeConstant(defaultValue, bindingContext);
ConstantValue<?> constant = ExpressionCodegen.getCompileTimeConstant(defaultValue, bindingContext);
assert constant != null : "Default value for annotation parameter should be compile time value: " + defaultValue.getText();
AnnotationCodegen annotationCodegen = AnnotationCodegen.forAnnotationDefaultValue(mv, typeMapper);
annotationCodegen.generateAnnotationDefaultValue(constant, descriptor.getType());
@@ -311,7 +311,7 @@ public class PropertyCodegen {
Object value = null;
if (shouldWriteFieldInitializer(propertyDescriptor)) {
CompileTimeConstant<?> initializer = propertyDescriptor.getCompileTimeInitializer();
ConstantValue<?> initializer = propertyDescriptor.getCompileTimeInitializer();
if (initializer != null) {
value = initializer.getValue();
}
@@ -45,7 +45,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.constants.EnumValue;
import org.jetbrains.kotlin.resolve.constants.NullValue;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
@@ -537,7 +537,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
WhenByEnumsMapping mapping = new WhenByEnumsMapping(classDescriptor, currentClassName, fieldNumber);
for (CompileTimeConstant constant : SwitchCodegenUtil.getAllConstants(expression, bindingContext)) {
for (ConstantValue<?> constant : SwitchCodegenUtil.getAllConstants(expression, bindingContext)) {
if (constant instanceof NullValue) continue;
assert constant instanceof EnumValue : "expression in when should be EnumValue";
@@ -554,9 +554,9 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
SwitchCodegenUtil.checkAllItemsAreConstantsSatisfying(
expression,
bindingContext,
new Function1<CompileTimeConstant, Boolean>() {
new Function1<ConstantValue<?>, Boolean>() {
@Override
public Boolean invoke(@NotNull CompileTimeConstant constant) {
public Boolean invoke(@NotNull ConstantValue<?> constant) {
return constant instanceof EnumValue || constant instanceof NullValue;
}
}
@@ -54,7 +54,7 @@ import org.jetbrains.kotlin.resolve.annotations.AnnotationsPackage;
import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.constants.StringValue;
import org.jetbrains.kotlin.resolve.jvm.AsmTypes;
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
@@ -721,10 +721,10 @@ public class JetTypeMapper {
AnnotationDescriptor platformNameAnnotation = descriptor.getAnnotations().findAnnotation(new FqName("kotlin.platform.platformName"));
if (platformNameAnnotation == null) return null;
Map<ValueParameterDescriptor, CompileTimeConstant<?>> arguments = platformNameAnnotation.getAllValueArguments();
Map<ValueParameterDescriptor, ConstantValue<?>> arguments = platformNameAnnotation.getAllValueArguments();
if (arguments.isEmpty()) return null;
CompileTimeConstant<?> name = arguments.values().iterator().next();
ConstantValue<?> name = arguments.values().iterator().next();
if (!(name instanceof StringValue)) return null;
return ((StringValue) name).getValue();
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.codegen.when;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.codegen.ExpressionCodegen;
import org.jetbrains.kotlin.psi.JetWhenExpression;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.constants.EnumValue;
import org.jetbrains.org.objectweb.asm.Label;
import org.jetbrains.org.objectweb.asm.Type;
@@ -58,7 +58,7 @@ public class EnumSwitchCodegen extends SwitchCodegen {
}
@Override
protected void processConstant(@NotNull CompileTimeConstant constant, @NotNull Label entryLabel) {
protected void processConstant(@NotNull ConstantValue<?> constant, @NotNull Label entryLabel) {
assert constant instanceof EnumValue : "guaranteed by usage contract";
putTransitionOnce(mapping.getIndexByEntry((EnumValue) constant), entryLabel);
}
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.codegen.when;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.codegen.ExpressionCodegen;
import org.jetbrains.kotlin.psi.JetWhenExpression;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.org.objectweb.asm.Label;
public class IntegralConstantsSwitchCodegen extends SwitchCodegen {
@@ -32,7 +32,7 @@ public class IntegralConstantsSwitchCodegen extends SwitchCodegen {
}
@Override
protected void processConstant(@NotNull CompileTimeConstant constant, @NotNull Label entryLabel) {
protected void processConstant(@NotNull ConstantValue<?> constant, @NotNull Label entryLabel) {
assert constant.getValue() != null : "constant value should not be null";
int value = (constant.getValue() instanceof Number)
? ((Number) constant.getValue()).intValue()
@@ -21,7 +21,7 @@ import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.codegen.ExpressionCodegen;
import org.jetbrains.kotlin.psi.JetWhenExpression;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.constants.StringValue;
import org.jetbrains.org.objectweb.asm.Label;
import org.jetbrains.org.objectweb.asm.Type;
@@ -47,7 +47,7 @@ public class StringSwitchCodegen extends SwitchCodegen {
@Override
protected void processConstant(
@NotNull CompileTimeConstant constant, @NotNull Label entryLabel
@NotNull ConstantValue<?> constant, @NotNull Label entryLabel
) {
assert constant instanceof StringValue : "guaranteed by usage contract";
int hashCode = constant.hashCode();
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.codegen.FrameMap;
import org.jetbrains.kotlin.psi.JetWhenEntry;
import org.jetbrains.kotlin.psi.JetWhenExpression;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.constants.NullValue;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.TypeUtils;
@@ -96,7 +96,7 @@ abstract public class SwitchCodegen {
for (JetWhenEntry entry : expression.getEntries()) {
Label entryLabel = new Label();
for (CompileTimeConstant constant : SwitchCodegenUtil.getConstantsFromEntry(entry, bindingContext)) {
for (ConstantValue<?> constant : SwitchCodegenUtil.getConstantsFromEntry(entry, bindingContext)) {
if (constant instanceof NullValue) continue;
processConstant(constant, entryLabel);
}
@@ -110,7 +110,7 @@ abstract public class SwitchCodegen {
}
abstract protected void processConstant(
@NotNull CompileTimeConstant constant,
@NotNull ConstantValue<?> constant,
@NotNull Label entryLabel
);
@@ -154,7 +154,7 @@ abstract public class SwitchCodegen {
private int findNullEntryIndex(@NotNull JetWhenExpression expression) {
int entryIndex = 0;
for (JetWhenEntry entry : expression.getEntries()) {
for (CompileTimeConstant constant : SwitchCodegenUtil.getConstantsFromEntry(entry, bindingContext)) {
for (ConstantValue<?> constant : SwitchCodegenUtil.getConstantsFromEntry(entry, bindingContext)) {
if (constant instanceof NullValue) {
return entryIndex;
}
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.codegen.ExpressionCodegen;
import org.jetbrains.kotlin.codegen.binding.CodegenBinding;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.constants.IntegerValueConstant;
import org.jetbrains.kotlin.resolve.constants.NullValue;
import org.jetbrains.kotlin.resolve.constants.StringValue;
@@ -36,7 +36,7 @@ public class SwitchCodegenUtil {
public static boolean checkAllItemsAreConstantsSatisfying(
@NotNull JetWhenExpression expression,
@NotNull BindingContext bindingContext,
Function1<CompileTimeConstant, Boolean> predicate
Function1<ConstantValue<?>, Boolean> predicate
) {
for (JetWhenEntry entry : expression.getEntries()) {
for (JetWhenCondition condition : entry.getConditions()) {
@@ -49,7 +49,7 @@ public class SwitchCodegenUtil {
if (patternExpression == null) return false;
CompileTimeConstant constant = ExpressionCodegen.getCompileTimeConstant(patternExpression, bindingContext);
ConstantValue<?> constant = ExpressionCodegen.getCompileTimeConstant(patternExpression, bindingContext);
if (constant == null || !predicate.invoke(constant)) {
return false;
}
@@ -60,11 +60,11 @@ public class SwitchCodegenUtil {
}
@NotNull
public static Iterable<CompileTimeConstant> getAllConstants(
public static Iterable<ConstantValue<?>> getAllConstants(
@NotNull JetWhenExpression expression,
@NotNull BindingContext bindingContext
) {
List<CompileTimeConstant> result = new ArrayList<CompileTimeConstant>();
List<ConstantValue<?>> result = new ArrayList<ConstantValue<?>>();
for (JetWhenEntry entry : expression.getEntries()) {
addConstantsFromEntry(result, entry, bindingContext);
@@ -74,7 +74,7 @@ public class SwitchCodegenUtil {
}
private static void addConstantsFromEntry(
@NotNull List<CompileTimeConstant> result,
@NotNull List<ConstantValue<?>> result,
@NotNull JetWhenEntry entry,
@NotNull BindingContext bindingContext
) {
@@ -89,11 +89,11 @@ public class SwitchCodegenUtil {
}
@NotNull
public static Iterable<CompileTimeConstant> getConstantsFromEntry(
public static Iterable<ConstantValue<?>> getConstantsFromEntry(
@NotNull JetWhenEntry entry,
@NotNull BindingContext bindingContext
) {
List<CompileTimeConstant> result = new ArrayList<CompileTimeConstant>();
List<ConstantValue<?>> result = new ArrayList<ConstantValue<?>>();
addConstantsFromEntry(result, entry, bindingContext);
return result;
}
@@ -132,7 +132,7 @@ public class SwitchCodegenUtil {
@NotNull JetWhenExpression expression,
@NotNull BindingContext bindingContext
) {
for (CompileTimeConstant constant : getAllConstants(expression, bindingContext)) {
for (ConstantValue<?> constant : getAllConstants(expression, bindingContext)) {
if (constant != null && !(constant instanceof NullValue)) return true;
}
@@ -150,10 +150,10 @@ public class SwitchCodegenUtil {
return false;
}
return checkAllItemsAreConstantsSatisfying(expression, bindingContext, new Function1<CompileTimeConstant, Boolean>() {
return checkAllItemsAreConstantsSatisfying(expression, bindingContext, new Function1<ConstantValue<?>, Boolean>() {
@Override
public Boolean invoke(
@NotNull CompileTimeConstant constant
@NotNull ConstantValue<?> constant
) {
return constant instanceof IntegerValueConstant;
}
@@ -170,10 +170,10 @@ public class SwitchCodegenUtil {
return false;
}
return checkAllItemsAreConstantsSatisfying(expression, bindingContext, new Function1<CompileTimeConstant, Boolean>() {
return checkAllItemsAreConstantsSatisfying(expression, bindingContext, new Function1<ConstantValue<?>, Boolean>() {
@Override
public Boolean invoke(
@NotNull CompileTimeConstant constant
@NotNull ConstantValue<?> constant
) {
return constant instanceof StringValue || constant instanceof NullValue;
}