package org.eclipse.jdt.internal.compiler.lookup;
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
public class BaseTypeBinding extends TypeBinding {
public static final int[] CONVERSIONS;
public static final int IDENTITY = 1;
public static final int WIDENING = 2;
public static final int NARROWING = 4;
public static final int MAX_CONVERSIONS = 16*16;
static {
CONVERSIONS = initializeConversions();
}
public static final int[] initializeConversions(){
int[] table = new int[MAX_CONVERSIONS];
table[TypeIds.Boolean2Boolean] = IDENTITY;
table[TypeIds.Byte2Byte] = IDENTITY;
table[TypeIds.Byte2Short] = WIDENING;
table[TypeIds.Byte2Char] = NARROWING;
table[TypeIds.Byte2Int] = WIDENING;
table[TypeIds.Byte2Long] = WIDENING;
table[TypeIds.Byte2Float] = WIDENING;
table[TypeIds.Byte2Double] = WIDENING;
table[TypeIds.Short2Byte] = NARROWING;
table[TypeIds.Short2Short] = IDENTITY;
table[TypeIds.Short2Char] = NARROWING;
table[TypeIds.Short2Int] = WIDENING;
table[TypeIds.Short2Long] = WIDENING;
table[TypeIds.Short2Float] = WIDENING;
table[TypeIds.Short2Double] = WIDENING;
table[TypeIds.Char2Byte] = NARROWING;
table[TypeIds.Char2Short] = NARROWING;
table[TypeIds.Char2Char] = IDENTITY;
table[TypeIds.Char2Int] = WIDENING;
table[TypeIds.Char2Long] = WIDENING;
table[TypeIds.Char2Float] = WIDENING;
table[TypeIds.Char2Double] = WIDENING;
table[TypeIds.Int2Byte] = NARROWING;
table[TypeIds.Int2Short] = NARROWING;
table[TypeIds.Int2Char] = NARROWING;
table[TypeIds.Int2Int] = IDENTITY;
table[TypeIds.Int2Long] = WIDENING;
table[TypeIds.Int2Float] = WIDENING;
table[TypeIds.Int2Double] = WIDENING;
table[TypeIds.Long2Byte] = NARROWING;
table[TypeIds.Long2Short] = NARROWING;
table[TypeIds.Long2Char] = NARROWING;
table[TypeIds.Long2Int] = NARROWING;
table[TypeIds.Long2Long] = IDENTITY;
table[TypeIds.Long2Float] = WIDENING;
table[TypeIds.Long2Double] = WIDENING;
table[TypeIds.Float2Byte] = NARROWING;
table[TypeIds.Float2Short] = NARROWING;
table[TypeIds.Float2Char] = NARROWING;
table[TypeIds.Float2Int] = NARROWING;
table[TypeIds.Float2Long] = NARROWING;
table[TypeIds.Float2Float] = IDENTITY;
table[TypeIds.Float2Double] = WIDENING;
table[TypeIds.Double2Byte] = NARROWING;
table[TypeIds.Double2Short] = NARROWING;
table[TypeIds.Double2Char] = NARROWING;
table[TypeIds.Double2Int] = NARROWING;
table[TypeIds.Double2Long] = NARROWING;
table[TypeIds.Double2Float] = NARROWING;
table[TypeIds.Double2Double]= IDENTITY;
return table;
}
public static final boolean isNarrowing(int left, int right) {
int right2left = right + (left<<4);
return right2left >= 0
&& right2left < MAX_CONVERSIONS
&& (CONVERSIONS[right2left] & (IDENTITY|NARROWING)) != 0;
}
public static final boolean isWidening(int left, int right) {
int right2left = right + (left<<4);
return right2left >= 0
&& right2left < MAX_CONVERSIONS
&& (CONVERSIONS[right2left] & (IDENTITY|WIDENING)) != 0;
}
public char[] simpleName;
private char[] constantPoolName;
BaseTypeBinding(int id, char[] name, char[] constantPoolName) {
this.tagBits |= TagBits.IsBaseType;
this.id = id;
this.simpleName = name;
this.constantPoolName = constantPoolName;
}
@Override
public char[] computeUniqueKey(boolean isLeaf) {
return constantPoolName();
}
@Override
public char[] constantPoolName() {
return this.constantPoolName;
}
@Override
public TypeBinding clone(TypeBinding enclosingType) {
return new BaseTypeBinding(this.id, this.simpleName, this.constantPoolName);
}
@Override
public PackageBinding getPackage() {
return null;
}
@Override
public final boolean isCompatibleWith(TypeBinding right, Scope captureScope) {
if (equalsEquals(this, right))
return true;
int right2left = this.id + (right.id<<4);
if (right2left >= 0
&& right2left < MAX_CONVERSIONS
&& (CONVERSIONS[right2left] & (IDENTITY|WIDENING)) != 0)
return true;
return this == TypeBinding.NULL && !right.isBaseType();
}
@Override
public void setTypeAnnotations(AnnotationBinding[] annotations, boolean evalNullAnnotations) {
super.setTypeAnnotations(annotations, false);
}
@Override
public TypeBinding unannotated() {
if (!this.hasTypeAnnotations())
return this;
switch (this.id) {
case TypeIds.T_boolean:
return TypeBinding.BOOLEAN;
case TypeIds.T_byte:
return TypeBinding.BYTE;
case TypeIds.T_char:
return TypeBinding.CHAR;
case TypeIds.T_double:
return TypeBinding.DOUBLE;
case TypeIds.T_float:
return TypeBinding.FLOAT;
case TypeIds.T_int:
return TypeBinding.INT;
case TypeIds.T_long:
return TypeBinding.LONG;
case TypeIds.T_short:
return TypeBinding.SHORT;
default:
throw new IllegalStateException();
}
}
@Override
public boolean isUncheckedException(boolean includeSupertype) {
return this == TypeBinding.NULL;
}
@Override
public int kind() {
return Binding.BASE_TYPE;
}
@Override
public char[] qualifiedSourceName() {
return this.simpleName;
}
@Override
public char[] readableName() {
return this.simpleName;
}
@Override
public char[] shortReadableName() {
return this.simpleName;
}
@Override
public char[] sourceName() {
return this.simpleName;
}
@Override
public String toString() {
return this.hasTypeAnnotations() ? annotatedDebugName() : new String(readableName());
}
}