// true iff the statement "this = other" would compile. | // true iff the statement "this = other" would compile. | ||||
public final boolean isAssignableFrom(ResolvedType other,boolean allowMissing) { | public final boolean isAssignableFrom(ResolvedType other,boolean allowMissing) { | ||||
if (other==null) return false; // not sure this should ever happen | |||||
if (other.isPrimitiveType()) { | if (other.isPrimitiveType()) { | ||||
if (!world.isInJava5Mode()) return false; | if (!world.isInJava5Mode()) return false; | ||||
if (ResolvedType.validBoxing.contains(this.getSignature()+other.getSignature())) return true; | if (ResolvedType.validBoxing.contains(this.getSignature()+other.getSignature())) return true; |
// the type parameters of interest are only those that apply to the 'last type' in the signature | // the type parameters of interest are only those that apply to the 'last type' in the signature | ||||
// if the signature is 'PMyInterface<String>$MyOtherType;' then there are none... | // if the signature is 'PMyInterface<String>$MyOtherType;' then there are none... | ||||
String lastType = null; | String lastType = null; | ||||
int nestedTypePosition = signature.indexOf("$"); | |||||
int nestedTypePosition = signature.indexOf("$", endOfParams); // don't look for $ INSIDE the parameters | |||||
if (nestedTypePosition!=-1) lastType = signature.substring(nestedTypePosition+1); | if (nestedTypePosition!=-1) lastType = signature.substring(nestedTypePosition+1); | ||||
else lastType = new String(signature); | else lastType = new String(signature); | ||||
startOfParams = lastType.indexOf("<"); | startOfParams = lastType.indexOf("<"); |
} | } | ||||
} | } | ||||
public void testTypeFactoryForParameterizedTypes() { | |||||
if (LangUtil.is15VMOrGreater()) { // no funny types pre 1.5 | |||||
UnresolvedType enumOfSimpleType = | |||||
TypeFactory.createTypeFromSignature("Pjava/lang/Enum<Ljava/lang/String;>;"); | |||||
assertEquals(1, enumOfSimpleType.getTypeParameters().length); | |||||
UnresolvedType enumOfNestedType = | |||||
TypeFactory.createTypeFromSignature("Pjava/lang/Enum<Ljavax/jws/soap/SOAPBinding$ParameterStyle;>;"); | |||||
assertEquals(1, enumOfNestedType.getTypeParameters().length); | |||||
// is this signature right? | |||||
UnresolvedType nestedTypeOfParameterized = | |||||
TypeFactory.createTypeFromSignature("PMyInterface<Ljava/lang/String;>$MyOtherType;"); | |||||
assertEquals(0, nestedTypeOfParameterized.getTypeParameters().length); | |||||
// how about this one? is this valid? | |||||
UnresolvedType doublyNestedTypeSignatures = | |||||
TypeFactory.createTypeFromSignature("PMyInterface<Ljava/lang/String;Ljava/lang/String;>$MyOtherType<Ljava/lang/Object;>;"); | |||||
assertEquals(1, doublyNestedTypeSignatures.getTypeParameters().length); | |||||
} | |||||
} | |||||
private void checkTX(UnresolvedType tx,boolean shouldBeParameterized,int numberOfTypeParameters) { | private void checkTX(UnresolvedType tx,boolean shouldBeParameterized,int numberOfTypeParameters) { | ||||
assertTrue("Expected parameterization flag to be "+shouldBeParameterized,tx.isParameterizedType()==shouldBeParameterized); | assertTrue("Expected parameterization flag to be "+shouldBeParameterized,tx.isParameterizedType()==shouldBeParameterized); | ||||
if (numberOfTypeParameters==0) { | if (numberOfTypeParameters==0) { |