Search in sources :

Example 1 with DefaultABSFormatter

use of abs.backend.prettyprint.DefaultABSFormatter in project abstools by abstools.

the class PartialFunctionTest method prettyPrintImplemented.

@Test
public void prettyPrintImplemented() throws NotImplementedYetException, IOException {
    Model model = expand(parse("apply(inc)(0);", applyFunction(), incFunction()));
    PartialFunctionDecl func = getPartialFunction(model, "apply");
    assertNotNull(func);
    try (StringWriter writer = new StringWriter();
        PrintWriter pw = new PrintWriter(writer)) {
        func.prettyPrint(pw, new DefaultABSFormatter(pw));
        assertFalse(writer.toString().isEmpty());
    }
}
Also used : DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) StringWriter(java.io.StringWriter) Model(abs.frontend.ast.Model) PartialFunctionDecl(abs.frontend.ast.PartialFunctionDecl) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with DefaultABSFormatter

use of abs.backend.prettyprint.DefaultABSFormatter in project abstools by abstools.

the class PardefTest method expand.

protected final Model expand(Model model) {
    try {
        model.flattenTraitOnly();
        model.expandPartialFunctions();
        SemanticConditionList e = model.typeCheck();
        assertFalse("Type check errors! First: " + e.getFirstError(), e.containsErrors());
        return model;
    } catch (Throwable e) {
        if (e instanceof PardefModellingException) {
            // prettyprint could fail if expansion left the AST in an invalid state
            throw e;
        }
        PrintWriter pw = new PrintWriter(System.out);
        model.lookupModule("UnitTest").doPrettyPrint(pw, new DefaultABSFormatter(pw));
        pw.flush();
        throw e;
    }
}
Also used : DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) PrintWriter(java.io.PrintWriter)

Example 3 with DefaultABSFormatter

use of abs.backend.prettyprint.DefaultABSFormatter in project abstools by abstools.

the class ABSUnitTestCaseTranslator method printToFile.

@SuppressWarnings("rawtypes")
private void printToFile(List<ASTNode<ASTNode>> nodes, File file) {
    try {
        PrintStream stream = new PrintStream(file);
        PrintWriter writer = new PrintWriter(stream, true);
        ABSFormatter formatter = new DefaultABSFormatter(writer);
        for (ASTNode<ASTNode> n : nodes) {
            n.doPrettyPrint(writer, formatter);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace(new PrintStream(ConsoleHandler.getDefault().newMessageStream()));
    }
}
Also used : PrintStream(java.io.PrintStream) DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) ABSFormatter(abs.frontend.tests.ABSFormatter) ASTNode(abs.frontend.ast.ASTNode) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

Example 4 with DefaultABSFormatter

use of abs.backend.prettyprint.DefaultABSFormatter in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateTestRunner.

@Override
public void generateTestRunner(PrintStream stream) {
    ModuleDecl module = new ModuleDecl();
    module.setName(RUNNER_MAIN);
    module.setImportList(generateImportsAST());
    module.setBlock(generateMainBlockAST(module.getImportList()));
    PrintWriter writer = new PrintWriter(stream, true);
    ABSFormatter formatter = new DefaultABSFormatter(writer);
    module.doPrettyPrint(writer, formatter);
}
Also used : DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) ABSFormatter(abs.frontend.tests.ABSFormatter) ModuleDecl(abs.frontend.ast.ModuleDecl) PrintWriter(java.io.PrintWriter)

Aggregations

DefaultABSFormatter (abs.backend.prettyprint.DefaultABSFormatter)4 PrintWriter (java.io.PrintWriter)4 ABSFormatter (abs.frontend.tests.ABSFormatter)2 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)1 ASTNode (abs.frontend.ast.ASTNode)1 Model (abs.frontend.ast.Model)1 ModuleDecl (abs.frontend.ast.ModuleDecl)1 PartialFunctionDecl (abs.frontend.ast.PartialFunctionDecl)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintStream (java.io.PrintStream)1 StringWriter (java.io.StringWriter)1 Test (org.junit.Test)1