Skip to content
Snippets Groups Projects
Commit 49dda403 authored by René Schöne's avatar René Schöne
Browse files

WIP: working on better visualization

- cherry-picked from 2084088d
- add method to add stereotype
- add stereotype to NTAs (probably not working)
- begin to add better options for DumpAst.transform()
parent f906bed0
No related branches found
No related tags found
1 merge request!9working on better visualization
package de.tudresden.inf.st.jastadd.testDumper;
import de.tudresden.inf.st.jastadd.dumpAst.ast.DumpAst;
import de.tudresden.inf.st.jastadd.dumpAst.ast.DumpBuilder;
import de.tudresden.inf.st.jastadd.dumpAst.ast.DumpListChildNode;
import de.tudresden.inf.st.jastadd.dumpAst.ast.DumpNode;
import org.jastadd.testDumper.ast.A;
......@@ -8,14 +9,46 @@ import org.jastadd.testDumper.ast.B;
import org.jastadd.testDumper.ast.C;
import org.jastadd.testDumper.ast.Root;
import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.Function;
import java.util.stream.Collectors;
@SuppressWarnings({"unused", "CommentedOutCode"})
public class TestDumperMain {
public static void main(String[] args) {
Root root = new Root();
private Root root;
private DumpAst dumpAst;
public static void main(String[] args) throws IOException {
new TestDumperMain().run();
}
void run() throws IOException {
createRoot();
ExposingDumpBuilder builder = new ExposingDumpBuilder(root);
String preamble = "{<\n>\n}";
builder.includeAttributes("simpleAttr")
.orderChildren()
.includeNonterminalAttributes("getCalculated")
.setNameMethod(n -> n == null ? "null" : n.getClass().getSimpleName())
.customPreamble(preamble);
System.out.println(">> PlantUml");
dumpAst = builder.build();
System.out.println(dumpAst.toPlantUml());
Path path = Paths.get("src/gen/resources/");
Files.createDirectories(path);
builder.dumpAsYaml(path.resolve("testDumperMain.yaml"), true);
// printAdditionalInformation();
}
private void createRoot() {
root = new Root();
root.setName("Root1");
A a = new A();
a.setName("A2");
......@@ -34,20 +67,9 @@ public class TestDumperMain {
root.addB(b1);
root.addB(b2);
root.setC(c);
}
TestUtils.ExposingDumpBuilder builder = new TestUtils.ExposingDumpBuilder(root);
builder.includeAttributes("simpleAttr")
.orderChildren()
.includeNonterminalAttributes("getCalculated")
.setNameMethod(n -> n == null ? "null" : n.getClass().getSimpleName());
System.out.println(">> PlantUml");
DumpAst dumpAst = builder.build();
System.out.println(dumpAst.toPlantUml());
String[] b = new String[]{"1"};
List<String> l = Arrays.asList(b);
private void printAdditionalInformation() {
DumpNode node = dumpAst.getDumpNode(0);
System.out.println(node.getName());
Function<? super DumpNode, String> printInfo = d ->
......@@ -72,4 +94,17 @@ public class TestDumperMain {
// System.out.println(builder.build().toYaml(true));
// System.out.println(">> YAML end");
}
static class ExposingDumpBuilder extends DumpBuilder {
protected ExposingDumpBuilder(Object target) {
super(target);
}
@Override
public DumpAst build() {
return super.build();
}
}
}
......@@ -6,6 +6,10 @@ import de.tudresden.inf.st.jastadd.dumpAst.ast.DumpNode;
import org.jastadd.testDumper.ast.*;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;
......@@ -28,11 +32,16 @@ public class TestSimple {
}
@Test
public void testCustomPreamble() {
public void testCustomPreamble() throws IOException {
Root root = createRoot(null, null);
String preamble = "{<\n>\n}";
ExposingDumpBuilder builder = new ExposingDumpBuilder(root);
builder.excludeNullNodes().customPreamble(preamble);
Path path = Paths.get("src/gen/resources/");
Files.createDirectories(path);
builder.dumpAsYaml(path.resolve("customPreamble.yaml"), true);
DumpAst dumpAst = builder.build();
String puml = dumpAst.toPlantUml();
assertThat(puml).contains(preamble);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment