Search in sources :

Example 1 with UnionType

use of abs.frontend.typechecker.UnionType in project abstools by abstools.

the class TypingTest method testThisTyping.

@Test
public void testThisTyping() {
    Model m = assertParseOk("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());
}
Also used : UnionType(abs.frontend.typechecker.UnionType) ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 2 with UnionType

use of abs.frontend.typechecker.UnionType in project abstools by abstools.

the class TypeHierarchyContentProvider method getElements.

@Override
public Object[] getElements(Object inputElement) {
    if (inputElement instanceof Type) {
        Type type = (Type) inputElement;
        if (type.getDecl() != null) {
            return new Object[] { type.getDecl() };
        }
        if (type instanceof UnionType) {
            UnionType unionType = (UnionType) type;
            java.util.List<Object> result = new ArrayList<Object>();
            for (InterfaceType t : unionType.getTypes()) {
                for (Object e : getElements(t)) {
                    result.add(e);
                }
            }
            return result.toArray();
        }
    }
    return nothing;
}
Also used : UnionType(abs.frontend.typechecker.UnionType) Type(abs.frontend.typechecker.Type) InterfaceType(abs.frontend.typechecker.InterfaceType) UnionType(abs.frontend.typechecker.UnionType) InterfaceType(abs.frontend.typechecker.InterfaceType) ArrayList(java.util.ArrayList)

Aggregations

UnionType (abs.frontend.typechecker.UnionType)2 FrontendTest (abs.frontend.FrontendTest)1 ClassDecl (abs.frontend.ast.ClassDecl)1 Model (abs.frontend.ast.Model)1 ReturnStmt (abs.frontend.ast.ReturnStmt)1 InterfaceType (abs.frontend.typechecker.InterfaceType)1 Type (abs.frontend.typechecker.Type)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1