use of org.abs_models.frontend.typechecker.UnionType in project abstools by abstools.
the class JavaBackend method getQualifiedString.
public static String getQualifiedString(Type absType) {
String res = null;
if (absType.isDataType()) {
DataTypeType dt = (DataTypeType) absType;
res = dataTypeMap.get(dt.getDecl().getName());
if (res != null)
return res;
StringBuilder sb = new StringBuilder();
if (dt.hasTypeArgs() && !containsUnboundedType(dt.getTypeArgs())) {
sb.append("<");
boolean first = true;
for (Type t : dt.getTypeArgs()) {
if (first)
first = false;
else
sb.append(',');
sb.append(getQualifiedString(t));
}
sb.append(">");
}
return getQualifiedString(dt.getDecl()) + sb.toString();
/*
* if (dt.hasTypeArgs() && !containsUnboundedType(dt.getTypeArgs()))
* {
*
* sb.append("<"); boolean first = true; for (Type t :
* dt.getTypeArgs()) { if (first) first = false; else
* sb.append(','); sb.append(getQualifiedString(t)); }
* sb.append(">"); }
*/
} else if (absType.isInterfaceType()) {
InterfaceType it = (InterfaceType) absType;
return getQualifiedString(it.getDecl());
} else if (absType.isTypeParameter()) {
TypeParameter tp = (TypeParameter) absType;
return tp.getDecl().getName();
} else if (absType.isBoundedType()) {
BoundedType bt = (BoundedType) absType;
if (bt.hasBoundType())
return getQualifiedString(bt.getBoundType());
return "?";
} else if (absType.isAnyType()) {
return "java.lang.Object";
} else if (absType.isUnionType()) {
return getQualifiedString(((UnionType) absType).getOriginatingClass());
}
throw new RuntimeException("Type " + absType.getClass().getName() + " not yet supported by Java backend");
}
use of org.abs_models.frontend.typechecker.UnionType in project abstools by abstools.
the class TypingTest method testThisTyping.
@Test
public void testThisTyping() {
Model m = assertParse("class C implements I { I m() { return this; } } interface I { }");
ClassDecl d = (ClassDecl) m.lookupModule("UnitTest").getDecl(0);
ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
assertEquals(m.lookupModule("UnitTest").getDecl(1), ((UnionType) s.getRetExp().getType()).getType(0).getDecl());
}
Aggregations