store nullability information in TypeInfo

This commit is contained in:
Dmitry Jemerov
2011-06-30 17:46:52 +02:00
parent 01a08ecd04
commit 840f9ffef1
6 changed files with 44 additions and 17 deletions
+17 -10
View File
@@ -10,15 +10,18 @@ import java.util.Arrays;
public class TypeInfo<T> implements JetObject {
private TypeInfo<?> typeInfo;
private final Class<T> theClass;
private final boolean nullable;
private final TypeInfo[] typeParameters;
public TypeInfo(Class<T> theClass) {
public TypeInfo(Class<T> theClass, boolean nullable) {
this.theClass = theClass;
this.nullable = nullable;
this.typeParameters = null;
}
public TypeInfo(Class<T> theClass, TypeInfo[] typeParameters) {
public TypeInfo(Class<T> theClass, boolean nullable, TypeInfo[] typeParameters) {
this.theClass = theClass;
this.nullable = nullable;
this.typeParameters = typeParameters;
}
@@ -33,6 +36,9 @@ public class TypeInfo<T> implements JetObject {
if (!theClass.isAssignableFrom(other.theClass)) {
return false;
}
if (nullable != other.nullable) {
return false;
}
if (typeParameters != null) {
if (other.typeParameters == null || other.typeParameters.length != typeParameters.length) {
throw new IllegalArgumentException("inconsistent type infos for the same class");
@@ -68,6 +74,7 @@ public class TypeInfo<T> implements JetObject {
TypeInfo typeInfo = (TypeInfo) o;
if (!theClass.equals(typeInfo.theClass)) return false;
if (nullable != typeInfo.nullable) return false;
if (!Arrays.equals(typeParameters, typeInfo.typeParameters)) return false;
return true;
@@ -80,12 +87,12 @@ public class TypeInfo<T> implements JetObject {
return result;
}
public static final TypeInfo<Byte> BYTE_TYPE_INFO = new TypeInfo<Byte>(Byte.class);
public static final TypeInfo<Short> SHORT_TYPE_INFO = new TypeInfo<Short>(Short.class);
public static final TypeInfo<Integer> INT_TYPE_INFO = new TypeInfo<Integer>(Integer.class);
public static final TypeInfo<Long> LONG_TYPE_INFO = new TypeInfo<Long>(Long.class);
public static final TypeInfo<Character> CHAR_TYPE_INFO = new TypeInfo<Character>(Character.class);
public static final TypeInfo<Boolean> BOOL_TYPE_INFO = new TypeInfo<Boolean>(Boolean.class);
public static final TypeInfo<Float> FLOAT_TYPE_INFO = new TypeInfo<Float>(Float.class);
public static final TypeInfo<Double> DOUBLE_TYPE_INFO = new TypeInfo<Double>(Double.class);
public static final TypeInfo<Byte> BYTE_TYPE_INFO = new TypeInfo<Byte>(Byte.class, false);
public static final TypeInfo<Short> SHORT_TYPE_INFO = new TypeInfo<Short>(Short.class, false);
public static final TypeInfo<Integer> INT_TYPE_INFO = new TypeInfo<Integer>(Integer.class, false);
public static final TypeInfo<Long> LONG_TYPE_INFO = new TypeInfo<Long>(Long.class, false);
public static final TypeInfo<Character> CHAR_TYPE_INFO = new TypeInfo<Character>(Character.class, false);
public static final TypeInfo<Boolean> BOOL_TYPE_INFO = new TypeInfo<Boolean>(Boolean.class, false);
public static final TypeInfo<Float> FLOAT_TYPE_INFO = new TypeInfo<Float>(Float.class, false);
public static final TypeInfo<Double> DOUBLE_TYPE_INFO = new TypeInfo<Double>(Double.class, false);
}