diff --git a/jode/jode/type/ArrayType.java b/jode/jode/type/ArrayType.java index 385b05b..42a51cc 100644 --- a/jode/jode/type/ArrayType.java +++ b/jode/jode/type/ArrayType.java @@ -169,34 +169,34 @@ public class ArrayType extends ReferenceType { return tError; } -// /** -// * Checks if we need to cast to a middle type, before we can cast from -// * fromType to this type. -// * @return the middle type, or null if it is not necessary. -// */ -// public Type getCastHelper(Type fromType) { -// Type topType = fromType.getTop(); -// switch (topType.getTypeCode()) { -// case TC_ARRAY: -// if (!elementType.isClassType() -// || !((ArrayType)topType).elementType.isClassType()) -// return tObject; -// Type middleType = elementType.getCastHelper -// (((ArrayType)topType).elementType); -// if (middleType != null) -// return tArray(middleType); -// return null; -// case TC_CLASS: -// ClassInterfacesType top = (ClassInterfacesType) topType; -// if (top.clazz == null -// && implementsAllIfaces(top.ifaces)) -// return null; -// return tObject; -// case TC_UNKNOWN: -// return null; -// } -// return tObject; -// } + /** + * Checks if we need to cast to a middle type, before we can cast from + * fromType to this type. + * @return the middle type, or null if it is not necessary. + */ + public Type getCastHelper(Type fromType) { + Type hintType = fromType.getHint(); + switch (hintType.getTypeCode()) { + case TC_ARRAY: + if (!elementType.isClassType() + || !((ArrayType)hintType).elementType.isClassType()) + return tObject; + Type middleType = elementType.getCastHelper + (((ArrayType)hintType).elementType); + if (middleType != null) + return tArray(middleType); + return null; + case TC_CLASS: + ClassInterfacesType hint = (ClassInterfacesType) hintType; + if (hint.clazz == null + && implementsAllIfaces(null, arrayIfaces, hint.ifaces)) + return null; + return tObject; + case TC_UNKNOWN: + return null; + } + return tObject; + } /** * Checks if this type represents a valid type instead of a list diff --git a/jode/jode/type/ClassInterfacesType.java b/jode/jode/type/ClassInterfacesType.java index 888c915..0261ae7 100644 --- a/jode/jode/type/ClassInterfacesType.java +++ b/jode/jode/type/ClassInterfacesType.java @@ -429,37 +429,38 @@ public class ClassInterfacesType extends ReferenceType { return sb.append("}").toString(); } -// /** -// * Checks if we need to cast to a middle type, before we can cast from -// * fromType to this type. -// * @return the middle type, or null if it is not necessary. -// */ -// public Type getCastHelper(Type fromType) { -// Type topType = fromType.getTop(); -// switch (topType.getTypeCode()) { -// case TC_ARRAY: -// if (clazz == null -// && ArrayType.implementsAllIfaces(this.ifaces)) -// return null; -// else -// return tObject; -// case TC_CLASS: -// ClassInterfacesType top = (ClassInterfacesType) topType; -// if (top.clazz == null || clazz == null -// || clazz.superClassOf(top.clazz) -// || top.clazz.superClassOf(clazz)) -// return null; -// ClassInfo superClazz = clazz.getSuperclass(); -// while (superClazz != null -// && !superClazz.superClassOf(top.clazz)) { -// superClazz = superClazz.getSuperclass(); -// } -// return tClass(superClazz.getName()); -// case TC_UNKNOWN: -// return null; -// } -// return tObject; -// } + /** + * Checks if we need to cast to a middle type, before we can cast from + * fromType to this type. + * @return the middle type, or null if it is not necessary. + */ + public Type getCastHelper(Type fromType) { + Type hintType = fromType.getHint(); + switch (hintType.getTypeCode()) { + case TC_ARRAY: + if (clazz == null + && implementsAllIfaces(null, ArrayType.arrayIfaces, + this.ifaces)) + return null; + else + return tObject; + case TC_CLASS: + ClassInterfacesType hint = (ClassInterfacesType) hintType; + if (hint.clazz == null || clazz == null + || clazz.superClassOf(hint.clazz) + || hint.clazz.superClassOf(clazz)) + return null; + ClassInfo superClazz = clazz.getSuperclass(); + while (superClazz != null + && !superClazz.superClassOf(hint.clazz)) { + superClazz = superClazz.getSuperclass(); + } + return tClass(superClazz.getName()); + case TC_UNKNOWN: + return null; + } + return tObject; + } /** * Checks if this type represents a valid type instead of a list