Search in sources :

Example 1 with InterfaceTypeUse

use of abs.frontend.ast.InterfaceTypeUse in project abstools by abstools.

the class ABSUnitTestCaseBuilder method getTypesFromABSData.

Map<String, InterfaceTypeUse> getTypesFromABSData(String testName, ABSData data) {
    Map<String, InterfaceTypeUse> map = new HashMap<String, InterfaceTypeUse>();
    if (data instanceof ABSRef) {
        String type = getABSDataType(data);
        String value = getABSDataValue(data);
        if (!value.equals(NULL)) {
            map.put(heapRefBuilder.heapReferenceForTest(testName, value), new InterfaceTypeUse(type, new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
        }
    } else if (data instanceof ABSTerm) {
        ABSTerm term = (ABSTerm) data;
        for (ABSData t : getABSTermArgs(term)) {
            map.putAll(getTypesFromABSData(testName, t));
        }
    }
    return map;
}
Also used : ABSTerm(apet.testCases.ABSTerm) HashMap(java.util.HashMap) ABSRef(apet.testCases.ABSRef) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) List(java.util.List) ArrayList(java.util.ArrayList) ABSData(apet.testCases.ABSData)

Example 2 with InterfaceTypeUse

use of abs.frontend.ast.InterfaceTypeUse in project abstools by abstools.

the class ABSUnitTestCaseTranslatorHelper method createTestClass.

ClassDecl createTestClass(InterfaceDecl inf) {
    ClassDecl ct = new ClassDecl(testCaseNameBuilder.className(inf.getName()), new abs.frontend.ast.List<Annotation>(), new abs.frontend.ast.List<ParamDecl>(), new abs.frontend.ast.List<InterfaceTypeUse>(), new Opt<InitBlock>(), new abs.frontend.ast.List<CaseBranchStmt>(), new abs.frontend.ast.List<FieldDecl>(), new abs.frontend.ast.List<MethodImpl>());
    ct.addAnnotation(getTestAnnotation(suiteType));
    ct.addImplementedInterfaceUse(new InterfaceTypeUse(inf.getName(), new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
    for (MethodSig m : inf.getAllMethodSigs()) {
        ct.addMethod(createMethodImpl(m));
    }
    FieldDecl assertImpl = new FieldDecl();
    assertImpl.setName(ASSERT_HELPER);
    assertImpl.setAccess(absAssertImpl.getImplementedInterfaceUse(0).treeCopyNoTransform());
    ct.addField(assertImpl);
    InitBlock block = new InitBlock();
    block.addStmtNoTransform(getVAssign(ASSERT_HELPER, newObj(absAssertImpl, false)));
    ct.setInitBlock(block);
    return ct;
}
Also used : InitBlock(abs.frontend.ast.InitBlock) CaseBranchStmt(abs.frontend.ast.CaseBranchStmt) Annotation(abs.frontend.ast.Annotation) FieldDecl(abs.frontend.ast.FieldDecl) AbsASTBuilderUtil.createMethodSig(abs.backend.tests.AbsASTBuilderUtil.createMethodSig) MethodSig(abs.frontend.ast.MethodSig) ClassDecl(abs.frontend.ast.ClassDecl) AbsASTBuilderUtil.createMethodImpl(abs.backend.tests.AbsASTBuilderUtil.createMethodImpl) MethodImpl(abs.frontend.ast.MethodImpl) ParamDecl(abs.frontend.ast.ParamDecl) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse)

Example 3 with InterfaceTypeUse

use of abs.frontend.ast.InterfaceTypeUse in project abstools by abstools.

the class DeltaForGetSetFieldsBuilder method updateDelta.

/**
 * Add a delta that adds Getters and Setters for clazz.
 *
 * @param extensions
 * @param interf
 * @param clazz
 */
void updateDelta(Map<String, String> typeHierarchy, InterfaceTypeUse interf, ClassDecl clazz) {
    String className = clazz.getName();
    String deltaOnClassName = testCaseNameBuilder.deltaOnClass(className);
    String interfaceForModifyingClassFieldName = testCaseNameBuilder.interfaceForModifyingFieldOfClass(className);
    DeltaDecl dd = getDelta(deltaOnClassName);
    if (dd != null) {
        typeHierarchy.put(interf.getName(), interfaceForModifyingClassFieldName);
        return;
    }
    dd = new DeltaDecl();
    dd.setName(deltaOnClassName);
    dd.addDeltaAccess(new DeltaAccess(clazz.getModuleDecl().getName()));
    // add Setters and Getters
    ModifyClassModifier mcm = new ModifyClassModifier();
    mcm.setName(className);
    InterfaceDecl ai = new InterfaceDecl();
    ai.setName(interfaceForModifyingClassFieldName);
    // extends the existing interface
    InterfaceTypeUse inf = interf.treeCopyNoTransform();
    ai.addExtendedInterfaceUse(inf.treeCopyNoTransform());
    mcm.addAddedInterface(new InterfaceTypeUse(ai.getName(), new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
    typeHierarchy.put(inf.getName(), interfaceForModifyingClassFieldName);
    for (MethodImpl m : clazz.getMethodList()) {
        if (RUN_METHOD.equals(m.getMethodSig().getName())) {
            mcm.addModifier(removeRun());
            break;
        }
    }
    for (FieldDecl fd : clazz.getFieldList()) {
        AddMethodModifier smm = addSetter(fd.getName(), fd.getAccess().treeCopyNoTransform());
        AddMethodModifier gmm = addGetter(fd.getName(), fd.getAccess().treeCopyNoTransform());
        mcm.addModifier(smm);
        mcm.addModifier(gmm);
        ai.addBody(smm.getMethodImpl().getMethodSig());
        ai.addBody(gmm.getMethodImpl().getMethodSig());
    }
    dd.addModuleModifier(new AddInterfaceModifier(ai));
    dd.addModuleModifier(mcm);
    deltas.add(new DeltaWrapper(dd, false));
}
Also used : AddMethodModifier(abs.frontend.ast.AddMethodModifier) AddInterfaceModifier(abs.frontend.ast.AddInterfaceModifier) DeltaDecl(abs.frontend.ast.DeltaDecl) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) FieldDecl(abs.frontend.ast.FieldDecl) MethodImpl(abs.frontend.ast.MethodImpl) DeltaAccess(abs.frontend.ast.DeltaAccess) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Example 4 with InterfaceTypeUse

use of abs.frontend.ast.InterfaceTypeUse in project abstools by abstools.

the class ClassDeclGenerator method generateClassHeader.

private void generateClassHeader() {
    stream.print("public ");
    if (!decl.isForeign())
        stream.print("final ");
    stream.print("class " + className + " extends " + ABSObject.class.getName() + " implements " + ABSClass.class.getName());
    for (InterfaceTypeUse use : decl.getImplementedInterfaceUses()) {
        String iname = JavaBackend.getQualifiedString(((InterfaceType) use.getType()).getDecl());
        stream.print(", " + iname);
    }
}
Also used : InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse)

Example 5 with InterfaceTypeUse

use of abs.frontend.ast.InterfaceTypeUse in project abstools by abstools.

the class InferMain method shouldBeConsidered.

private boolean shouldBeConsidered(LocationTypeVariable ltv) {
    ASTNode<?> node = ltv.getNode();
    Decl contextDecl = node.getContextDecl();
    if (contextDecl != null) {
        // Don't print interface annotations in "implements/extends" clauses:
        if (node instanceof InterfaceTypeUse && (contextDecl instanceof ClassDecl || contextDecl instanceof InterfaceDecl))
            return false;
        if (contextDecl.isClass() && !config.contains(Config.CLASSES))
            return false;
        if (contextDecl.isInterface() && !config.contains(Config.INTERFACES))
            return false;
        if (contextDecl.isFunction() && !config.contains(Config.FUNCTIONS))
            return false;
    }
    if (node instanceof VarDecl && !config.contains(Config.LOCAL_VAR_DECLS))
        return false;
    if (node instanceof FieldDecl && !config.contains(Config.FIELDS))
        return false;
    if (ltv.getAnnotatedType() != null) {
        return false;
    }
    return true;
}
Also used : FieldDecl(abs.frontend.ast.FieldDecl) ClassDecl(abs.frontend.ast.ClassDecl) VarDecl(abs.frontend.ast.VarDecl) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) InterfaceDecl(abs.frontend.ast.InterfaceDecl) ClassDecl(abs.frontend.ast.ClassDecl) FieldDecl(abs.frontend.ast.FieldDecl) VarDecl(abs.frontend.ast.VarDecl) Decl(abs.frontend.ast.Decl) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Aggregations

InterfaceTypeUse (abs.frontend.ast.InterfaceTypeUse)8 FieldDecl (abs.frontend.ast.FieldDecl)4 ClassDecl (abs.frontend.ast.ClassDecl)3 ABSRef (apet.testCases.ABSRef)3 HashMap (java.util.HashMap)3 Block (abs.frontend.ast.Block)2 DeltaDecl (abs.frontend.ast.DeltaDecl)2 InterfaceDecl (abs.frontend.ast.InterfaceDecl)2 MethodImpl (abs.frontend.ast.MethodImpl)2 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)2 ABSData (apet.testCases.ABSData)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AbsASTBuilderUtil.createMethodImpl (abs.backend.tests.AbsASTBuilderUtil.createMethodImpl)1 AbsASTBuilderUtil.createMethodSig (abs.backend.tests.AbsASTBuilderUtil.createMethodSig)1 AbsASTBuilderUtil.getExpStmt (abs.backend.tests.AbsASTBuilderUtil.getExpStmt)1 AddFieldModifier (abs.frontend.ast.AddFieldModifier)1 AddInterfaceModifier (abs.frontend.ast.AddInterfaceModifier)1 AddMethodModifier (abs.frontend.ast.AddMethodModifier)1 Annotation (abs.frontend.ast.Annotation)1