Make CompileTimeConstant abstract class

This commit is contained in:
Natalia Ukhorskaya
2013-12-24 11:23:42 +04:00
parent 292e825fac
commit 5c88c8c58f
18 changed files with 51 additions and 132 deletions
@@ -533,7 +533,7 @@ private fun createUnconvertibleCompileTimeConstant(value: Any?): CompileTimeCons
private fun createStringConstant(value: CompileTimeConstant<*>?): StringValue? { private fun createStringConstant(value: CompileTimeConstant<*>?): StringValue? {
return when (value) { return when (value) {
null -> null null -> null
is IntegerValueTypeConstant -> createStringConstant(value.getValue().getCompileTimeConstantForNumberType(TypeUtils.NO_EXPECTED_TYPE)) is IntegerValueTypeConstant -> createStringConstant(value.getValue()!!.getCompileTimeConstantForNumberType(TypeUtils.NO_EXPECTED_TYPE))
is StringValue -> value is StringValue -> value
is IntValue, is ByteValue, is ShortValue, is LongValue, is IntValue, is ByteValue, is ShortValue, is LongValue,
is CharValue, is CharValue,
@@ -22,18 +22,10 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
public class AnnotationValue implements CompileTimeConstant<AnnotationDescriptor> { public class AnnotationValue extends CompileTimeConstant<AnnotationDescriptor> {
private final AnnotationDescriptor value;
public AnnotationValue(@NotNull AnnotationDescriptor value) { public AnnotationValue(@NotNull AnnotationDescriptor value) {
this.value = value; super(value);
}
@Override
@NotNull
public AnnotationDescriptor getValue() {
return value;
} }
@Override @Override
@@ -17,28 +17,22 @@
package org.jetbrains.jet.lang.resolve.constants; package org.jetbrains.jet.lang.resolve.constants;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import java.util.List; import java.util.List;
public class ArrayValue implements CompileTimeConstant<List<CompileTimeConstant<?>>> { public class ArrayValue extends CompileTimeConstant<List<CompileTimeConstant<?>>> {
private final List<CompileTimeConstant<?>> value;
private final JetType type; private final JetType type;
public ArrayValue(@NotNull List<CompileTimeConstant<?>> value, @NotNull JetType type) { public ArrayValue(@NotNull List<CompileTimeConstant<?>> value, @NotNull JetType type) {
this.value = value; super(value);
this.type = type; this.type = type;
} }
@Override
@NotNull
public List<CompileTimeConstant<?>> getValue() {
return value;
}
@NotNull @NotNull
@Override @Override
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) { public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
@@ -21,15 +21,13 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
public class BooleanValue implements CompileTimeConstant<Boolean> { public class BooleanValue extends CompileTimeConstant<Boolean> {
public static final BooleanValue FALSE = new BooleanValue(false); public static final BooleanValue FALSE = new BooleanValue(false);
public static final BooleanValue TRUE = new BooleanValue(true); public static final BooleanValue TRUE = new BooleanValue(true);
private final boolean value;
private BooleanValue(boolean value) { private BooleanValue(boolean value) {
this.value = value; super(value);
} }
@NotNull @NotNull
@@ -37,11 +35,6 @@ public class BooleanValue implements CompileTimeConstant<Boolean> {
return value ? TRUE : FALSE; return value ? TRUE : FALSE;
} }
@Override
public Boolean getValue() {
return value;
}
@NotNull @NotNull
@Override @Override
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) { public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
@@ -23,7 +23,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
public class ByteValue implements CompileTimeConstant<Byte> { public class ByteValue extends CompileTimeConstant<Byte> {
public static final Function<Long, ByteValue> CREATE = new Function<Long, ByteValue>() { public static final Function<Long, ByteValue> CREATE = new Function<Long, ByteValue>() {
@Override @Override
public ByteValue apply(@Nullable Long input) { public ByteValue apply(@Nullable Long input) {
@@ -32,15 +32,8 @@ public class ByteValue implements CompileTimeConstant<Byte> {
} }
}; };
private final byte value;
public ByteValue(byte value) { public ByteValue(byte value) {
this.value = value; super(value);
}
@Override
public Byte getValue() {
return value;
} }
@NotNull @NotNull
@@ -21,17 +21,10 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
public class CharValue implements CompileTimeConstant<Character> { public class CharValue extends CompileTimeConstant<Character> {
private final char value;
public CharValue(char value) { public CharValue(char value) {
this.value = value; super(value);
}
@Override
public Character getValue() {
return value;
} }
@NotNull @NotNull
@@ -17,15 +17,25 @@
package org.jetbrains.jet.lang.resolve.constants; package org.jetbrains.jet.lang.resolve.constants;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
public interface CompileTimeConstant<T> { public abstract class CompileTimeConstant<T> {
T getValue(); protected final T value;
protected CompileTimeConstant(T value) {
this.value = value;
}
@Nullable
public T getValue() {
return value;
}
@NotNull @NotNull
JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns); public abstract JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns);
<R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data); public abstract <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data);
} }
@@ -21,16 +21,10 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
public class DoubleValue implements CompileTimeConstant<Double> { public class DoubleValue extends CompileTimeConstant<Double> {
private final double value;
public DoubleValue(double value) { public DoubleValue(double value) {
this.value = value; super(value);
}
@Override
public Double getValue() {
return value;
} }
@NotNull @NotNull
@@ -22,17 +22,10 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
public class EnumValue implements CompileTimeConstant<ClassDescriptor> { public class EnumValue extends CompileTimeConstant<ClassDescriptor> {
private final ClassDescriptor value;
public EnumValue(@NotNull ClassDescriptor value) { public EnumValue(@NotNull ClassDescriptor value) {
this.value = value; super(value);
}
@Override
@NotNull
public ClassDescriptor getValue() {
return value;
} }
@NotNull @NotNull
@@ -22,7 +22,11 @@ import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
public abstract class ErrorValue implements CompileTimeConstant<Void> { public abstract class ErrorValue extends CompileTimeConstant<Void> {
public ErrorValue() {
super(null);
}
@Override @Override
@Deprecated // Should not be called, for this is not a real value, but a indication of an error @Deprecated // Should not be called, for this is not a real value, but a indication of an error
@@ -21,16 +21,10 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
public class FloatValue implements CompileTimeConstant<Float> { public class FloatValue extends CompileTimeConstant<Float> {
private final float value;
public FloatValue(float value) { public FloatValue(float value) {
this.value = value; super(value);
}
@Override
public Float getValue() {
return value;
} }
@NotNull @NotNull
@@ -23,7 +23,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
public class IntValue implements CompileTimeConstant<Integer> { public class IntValue extends CompileTimeConstant<Integer> {
public static final Function<Long, IntValue> CREATE = new Function<Long, IntValue>() { public static final Function<Long, IntValue> CREATE = new Function<Long, IntValue>() {
@Override @Override
public IntValue apply(@Nullable Long input) { public IntValue apply(@Nullable Long input) {
@@ -32,15 +32,8 @@ public class IntValue implements CompileTimeConstant<Integer> {
} }
}; };
private final int value;
public IntValue(int value) { public IntValue(int value) {
this.value = value; super(value);
}
@Override
public Integer getValue() {
return value;
} }
@NotNull @NotNull
@@ -27,12 +27,10 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import java.util.Collections; import java.util.Collections;
public class IntegerValueTypeConstant implements CompileTimeConstant<IntegerValueTypeConstructor> { public class IntegerValueTypeConstant extends CompileTimeConstant<IntegerValueTypeConstructor> {
private final IntegerValueTypeConstructor value;
public IntegerValueTypeConstant(long value) { public IntegerValueTypeConstant(long value) {
this.value = new IntegerValueTypeConstructor(value); super(new IntegerValueTypeConstructor(value));
} }
@NotNull @NotNull
@@ -49,12 +47,6 @@ public class IntegerValueTypeConstant implements CompileTimeConstant<IntegerValu
return visitor.visitNumberTypeValue(this, data); return visitor.visitNumberTypeValue(this, data);
} }
@NotNull
@Override
public IntegerValueTypeConstructor getValue() {
return value;
}
@Override @Override
public String toString() { public String toString() {
return value.toString(); return value.toString();
@@ -21,12 +21,10 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
public class JavaClassValue implements CompileTimeConstant<JetType> { public class JavaClassValue extends CompileTimeConstant<JetType> {
private final JetType value;
public JavaClassValue(JetType value) { public JavaClassValue(JetType value) {
this.value = value; super(value);
} }
@Override @Override
@@ -23,7 +23,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
public class LongValue implements CompileTimeConstant<Long> { public class LongValue extends CompileTimeConstant<Long> {
public static final Function<Long, LongValue> CREATE = new Function<Long, LongValue>() { public static final Function<Long, LongValue> CREATE = new Function<Long, LongValue>() {
@Override @Override
public LongValue apply(@Nullable Long input) { public LongValue apply(@Nullable Long input) {
@@ -31,15 +31,8 @@ public class LongValue implements CompileTimeConstant<Long> {
} }
}; };
private final long value;
public LongValue(long value) { public LongValue(long value) {
this.value = value; super(value);
}
@Override
public Long getValue() {
return value;
} }
@NotNull @NotNull
@@ -21,16 +21,12 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
public class NullValue implements CompileTimeConstant<Void> { public class NullValue extends CompileTimeConstant<Void> {
public static final NullValue NULL = new NullValue(); public static final NullValue NULL = new NullValue();
private NullValue() { private NullValue() {
} super(null);
@Override
public Void getValue() {
return null;
} }
@NotNull @NotNull
@@ -23,7 +23,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
public class ShortValue implements CompileTimeConstant<Short> { public class ShortValue extends CompileTimeConstant<Short> {
public static final Function<Long, ShortValue> CREATE = new Function<Long, ShortValue>() { public static final Function<Long, ShortValue> CREATE = new Function<Long, ShortValue>() {
@Override @Override
public ShortValue apply(@Nullable Long input) { public ShortValue apply(@Nullable Long input) {
@@ -32,15 +32,8 @@ public class ShortValue implements CompileTimeConstant<Short> {
} }
}; };
private final short value;
public ShortValue(short value) { public ShortValue(short value) {
this.value = value; super(value);
}
@Override
public Short getValue() {
return value;
} }
@NotNull @NotNull
@@ -21,17 +21,11 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
public class StringValue implements CompileTimeConstant<String> { public class StringValue extends CompileTimeConstant<String> {
private final String value;
public StringValue(String value) { public StringValue(String value) {
this.value = value; super(value);
}
@Override
public String getValue() {
return value;
} }
@NotNull @NotNull