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

Merge branch 'dev' into 'main'

3.0.1

See merge request !13
parents 5e0a3728 2b5428a6
No related branches found
No related tags found
1 merge request!133.0.1
Pipeline #15024 passed
Showing
with 180 additions and 588 deletions
......@@ -39,12 +39,3 @@ aspect GrammarGlobal {
return result;
}
}
aspect GrammarTypeLevel {
syn int AbstractT.simpleAttr() = 43;
syn nta A AbstractT.getCalculated() {
A result = new A();
result.setName("Calculated-" + getName());
return result;
}
}
......@@ -14,17 +14,6 @@ rel C.biA1 <-> A.biC1 ;
rel C.biA2* <-> A.biC2 ;
rel C.biA3? <-> A.biC3 ;
// testcases with type-level inclusion/exclusion
TRoot : Nameable ::= A T1 T2 T3 ;
abstract AbstractT : Nameable ::= B Bee:B* <SomeValue> <Unwanted:int> ;
T1 : AbstractT ;
T2 : AbstractT ;
T3 : AbstractT ;
rel AbstractT.oneA -> A ;
rel AbstractT.maybeA? -> A ;
rel AbstractT.manyA* -> A ;
Position : Nameable ::= <X:double> <Y:double> <Z:double>;
Size : Nameable ::= <Length:double> <Width:double> <Height:double>;
Orientation : Nameable ::= <X:double> <Y:double> <Z:double> <W:double>;
......
......@@ -81,10 +81,10 @@ public class TestExcluded {
tuple("BiC1", C_NAME), tuple("BiC2", C_NAME), tuple("BiC3", C_NAME));
// B
assertThatMapOf(normalRelationChildren(findByName(nodes, B_NAME))).containsExactlyInAnyOrder(
tuple("OneA", A_NAME), tuple("MaybeC", C_NAME));
tuple("OneA", A_NAME), tuple("MaybeC?", C_NAME));
// C
assertThatMapOf(normalRelationChildren(findByName(nodes, C_NAME))).containsExactlyInAnyOrder(
tuple("BiA1", A_NAME), tuple("BiA3", A_NAME));
tuple("BiA1", A_NAME), tuple("BiA3?", A_NAME));
assertThatMapOf(listRelationChildren(findByName(nodes, C_NAME)), "BiA2").containsExactlyInAnyOrder(A_NAME);
assertThatMapOf(referenceTokens(findByName(nodes, C_NAME))).containsExactlyInAnyOrder(
tuple(TOKEN_LABEL_RAW_REFERENCE, A_NAME));
......@@ -116,7 +116,7 @@ public class TestExcluded {
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, B_NAME, C_NAME);
// B
assertThatMapOf(normalRelationChildren(findByName(nodes, B_NAME))).containsExactlyInAnyOrder(
tuple("MaybeC", (C_NAME)));
tuple("MaybeC?", (C_NAME)));
// C
assertThat(normalRelationChildren(findByName(nodes, C_NAME))).isEmpty();
assertThat(listRelationChildren(findByName(nodes, C_NAME))).isEmpty();
......@@ -198,7 +198,8 @@ public class TestExcluded {
c.setBiA1(a);
}));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeTokens(TOKEN_LABEL_UNWANTED));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeToken((node, tokenName, value) ->
!tokenName.equals(TOKEN_LABEL_UNWANTED)));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, C_NAME);
DumpNode actualC = findByName(nodes, C_NAME);
assertThat(valueTokens(actualC)).containsOnly(
......@@ -218,7 +219,8 @@ public class TestExcluded {
c.setBiA1(a);
}));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeTokens(TOKEN_LABEL_UNWANTED, TOKEN_LABEL_RAW_REFERENCE));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeToken((node, tokenName, value) ->
!tokenName.equals(TOKEN_LABEL_UNWANTED) && !tokenName.equals(TOKEN_LABEL_RAW_REFERENCE)));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, C_NAME);
DumpNode actualC = findByName(nodes, C_NAME);
assertThat(valueTokens(actualC)).containsOnly(
......@@ -238,7 +240,8 @@ public class TestExcluded {
c.setBiA1(a);
}));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeTokens("bi.*"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeToken((node, tokenName, value) ->
!tokenName.startsWith("bi")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, C_NAME);
DumpNode actualC = findByName(nodes, C_NAME);
assertThat(valueTokens(actualC)).containsOnly(
......@@ -258,7 +261,8 @@ public class TestExcluded {
c.setBiA1(a);
}));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeTokens("Bi.*"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeToken((node, tokenName, value) ->
!tokenName.startsWith("Bi")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, C_NAME);
DumpNode actualC = findByName(nodes, C_NAME);
assertThat(valueTokens(actualC)).containsOnly(
......@@ -312,7 +316,8 @@ public class TestExcluded {
}), null);
root.getA().getB().setOneA(root.getA().getMyC().getA());
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeChildren("MyC"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeChild((parentNode, childNode, contextName) ->
!contextName.equals("MyC")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(
ROOT_NAME, A_NAME, B_NAME, A2_Name, B2_NAME);
DumpNode actualA = findByName(nodes, A_NAME);
......@@ -333,16 +338,17 @@ public class TestExcluded {
public void testRelationsExclude() throws TransformationException {
Root root = setupAllRelations();
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeRelations("BiC1"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeRelation((sourceNode, targetNode, roleName) ->
!roleName.equals("BiC1")));
// A
assertThatMapOf(normalRelationChildren(findByName(nodes, A_NAME))).containsExactlyInAnyOrder(
tuple("BiC2", C_NAME), tuple("BiC3", C_NAME));
// B
assertThatMapOf(normalRelationChildren(findByName(nodes, B_NAME))).containsExactlyInAnyOrder(
tuple("OneA", A_NAME), tuple("MaybeC", C_NAME));
tuple("OneA", A_NAME), tuple("MaybeC?", C_NAME));
// C
assertThatMapOf(normalRelationChildren(findByName(nodes, C_NAME))).containsExactlyInAnyOrder(
tuple("BiA1", A_NAME), tuple("BiA3", A_NAME));
tuple("BiA1", A_NAME), tuple("BiA3?", A_NAME));
assertThatMapOf(listRelationChildren(findByName(nodes, C_NAME)), "BiA2").containsExactlyInAnyOrder(A_NAME);
assertThatMapOf(referenceTokens(findByName(nodes, C_NAME))).containsExactlyInAnyOrder(
tuple(TOKEN_LABEL_RAW_REFERENCE, A_NAME));
......@@ -352,15 +358,16 @@ public class TestExcluded {
public void testRelationsExcludeRegex1() throws TransformationException {
Root root = setupAllRelations();
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeRelations("Bi.*"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeRelation((sourceNode, targetNode, roleName) ->
!roleName.startsWith("Bi")));
// A
assertThat(normalRelationChildren(findByName(nodes, A_NAME))).isEmpty();
// B
assertThatMapOf(normalRelationChildren(findByName(nodes, B_NAME))).containsExactlyInAnyOrder(
tuple("OneA", A_NAME), tuple("MaybeC", C_NAME));
tuple("OneA", A_NAME), tuple("MaybeC?", C_NAME));
// C
assertThat(normalRelationChildren(findByName(nodes, C_NAME))).isEmpty();
assertThat(listRelationChildren(findByName(nodes, C_NAME))).isEmpty();
assertEmpty(TestUtils.findByName(nodes, C_NAME).getDumpRelation(0));
assertThatMapOf(referenceTokens(findByName(nodes, C_NAME))).containsExactlyInAnyOrder(
tuple(TOKEN_LABEL_RAW_REFERENCE, A_NAME));
}
......@@ -369,16 +376,17 @@ public class TestExcluded {
public void testRelationsExcludeRegex2() throws TransformationException {
Root root = setupAllRelations();
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.excludeRelations(".*A.*"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeRelation((sourceNode, targetNode, roleName) ->
!roleName.contains("A")));
// A
assertThatMapOf(normalRelationChildren(findByName(nodes, A_NAME))).containsExactlyInAnyOrder(
tuple("BiC1", C_NAME), tuple("BiC2", C_NAME), tuple("BiC3", C_NAME));
// B
assertThatMapOf(normalRelationChildren(findByName(nodes, B_NAME))).containsExactlyInAnyOrder(
tuple("MaybeC", C_NAME));
tuple("MaybeC?", C_NAME));
// C
assertThat(normalRelationChildren(findByName(nodes, C_NAME))).isEmpty();
assertThat(listRelationChildren(findByName(nodes, C_NAME))).isEmpty();
assertEmpty(TestUtils.findByName(nodes, C_NAME).getDumpRelation(0));
assertThatMapOf(referenceTokens(findByName(nodes, C_NAME))).containsExactlyInAnyOrder(
tuple(TOKEN_LABEL_RAW_REFERENCE, A_NAME));
}
......
......@@ -26,7 +26,8 @@ public class TestIncluded {
public void testValueAttributeIncluded() throws TransformationException {
Root root = createRoot(null, null);
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeAttributes("simpleAttr"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db ->
db.includeAttribute((node, attributeName, isNTA, value) -> !isNTA && attributeName.equals("simpleAttr")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertThat(valueTokens(actualRoot)).containsOnly(entry("Name", ROOT_NAME), entry("simpleAttr", 42));
......@@ -36,7 +37,8 @@ public class TestIncluded {
public void testReferenceListAttributeIncluded() throws TransformationException {
Root root = createRoot(null, null, createB(B1_NAME), createB(B2_NAME), createB(B3_NAME));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeAttributes("setOfBs"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db ->
db.includeAttribute((node, attributeName, isNTA, value) -> !isNTA && attributeName.equals("setOfBs")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME, B1_NAME, B2_NAME, B3_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
......@@ -58,7 +60,8 @@ public class TestIncluded {
public void testReferenceAttributeIncluded() throws TransformationException {
Root root = createRoot(createA(A_NAME), null);
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeAttributes("referenceAttr"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db ->
db.includeAttribute((node, attributeName, isNTA, value) -> !isNTA && attributeName.equals("referenceAttr")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME, A_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertThatMapOf(referenceTokens(actualRoot)).containsOnly(tuple("referenceAttr", A_NAME));
......@@ -78,7 +81,8 @@ public class TestIncluded {
public void testNormalNTAIncluded() throws TransformationException {
Root root = createRoot(null, createC(C_NAME));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeNonterminalAttributes("Calculated"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db ->
db.includeAttribute((node, attributeName, isNTA, value) -> isNTA && attributeName.equals("Calculated")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME, C_NAME, "Calculated-" + C_NAME);
DumpNode actualC = TestUtils.findByName(nodes, C_NAME);
assertThatMapOf(normalChildren(actualC)).containsOnly(tuple("Calculated", "Calculated-" + C_NAME));
......@@ -99,7 +103,8 @@ public class TestIncluded {
public void testListNTAIncluded() throws TransformationException {
Root root = createRoot(null, createC(C_NAME));
List<DumpNode> nodes = TestUtils.dumpModel(root, db -> db.includeNonterminalAttributes("AlsoCalculated"));
List<DumpNode> nodes = TestUtils.dumpModel(root, db ->
db.includeAttribute((node, attributeName, isNTA, value) -> isNTA && attributeName.equals("AlsoCalculated")));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME, C_NAME, "AlsoCalculated-" + C_NAME);
DumpNode actualC = TestUtils.findByName(nodes, C_NAME);
assertThatMapOf(listChildren(actualC), "AlsoCalculated").containsExactly("AlsoCalculated-" + C_NAME);
......
......@@ -6,22 +6,28 @@ import org.jastadd.testDumper.ast.DropOffLocation;
import org.jastadd.testDumper.ast.Orientation;
import org.jastadd.testDumper.ast.Position;
import org.jastadd.testDumper.ast.Size;
import org.junit.jupiter.api.Assertions;
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 static de.tudresden.inf.st.jastadd.testDumper.TestUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* More complex test cases.
* Regression test cases.
*
* @author rschoene - Initial contribution
*/
public class TestComplex {
public class TestRegression {
@Test
public void testRegressionIssue16() throws TransformationException {
public void regressionIssue16() throws TransformationException {
DropOffLocation location = new DropOffLocation();
location.setName(ROOT_NAME);
location.setPosition(new Position(T1_NAME, 1, 2, 3));
......@@ -35,4 +41,11 @@ public class TestComplex {
entry("Y", 2.0),
entry("Z", 3.0));
}
@Test
public void regressionNoNewlineForRelationStyleMustache() throws IOException {
Path path = Paths.get("..", "dumpAst.base", "src", "main", "resources", "RelationStyle.mustache");
List<String> lines = Files.readAllLines(path);
assertEquals(1, lines.size(), "Ensure no trailing newline in RelationStyle.mustache");
}
}
......@@ -28,7 +28,7 @@ public class TestSimple {
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertEquals(1, actualRoot.getNumDumpToken());
assertEquals(0, actualRoot.getNumDumpChildNode());
assertEmpty(actualRoot.getDumpChildNode(0));
assertEquals(0, actualRoot.getNumDumpRelation());
}
......@@ -64,7 +64,8 @@ public class TestSimple {
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertEquals(1, actualRoot.getNumDumpToken());
assertEquals(1, actualRoot.getNumDumpChildNode());
assertEquals(2, actualRoot.getNumDumpChildNode());
assertEmpty(actualRoot.getDumpChildNode(1));
assertEquals(0, actualRoot.getNumDumpRelation());
assertThatMapOf(normalChildren(actualRoot)).containsExactlyInAnyOrder(tuple("A", A_NAME));
}
......@@ -86,7 +87,8 @@ public class TestSimple {
);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertEquals(1, actualRoot.getNumDumpToken());
assertEquals(2, actualRoot.getNumDumpChildNode());
assertEquals(3, actualRoot.getNumDumpChildNode());
assertEmpty(actualRoot.getDumpChildNode(1));
assertEquals(0, actualRoot.getNumDumpRelation());
DumpNode actualA = TestUtils.findByName(nodes, A_NAME);
......@@ -152,7 +154,7 @@ public class TestSimple {
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertEquals(1, actualRoot.getNumDumpToken());
assertEquals(0, actualRoot.getNumDumpChildNode());
assertEmpty(actualRoot.getDumpChildNode(0));
assertEquals(0, actualRoot.getNumDumpRelation());
assertThatMapOf(normalChildren(actualRoot)).isEmpty();
}
......@@ -165,9 +167,10 @@ public class TestSimple {
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, C_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertEquals(1, actualRoot.getNumDumpToken());
assertEquals(1, actualRoot.getNumDumpChildNode());
assertEquals(2, actualRoot.getNumDumpChildNode());
assertEmpty(actualRoot.getDumpChildNode(0));
assertEquals(0, actualRoot.getNumDumpRelation());
assertThatMapOf(normalChildren(actualRoot)).containsExactlyInAnyOrder(tuple("C", C_NAME));
assertThatMapOf(normalChildren(actualRoot)).containsExactlyInAnyOrder(tuple("C?", C_NAME));
}
@Test
......@@ -203,7 +206,7 @@ public class TestSimple {
List<DumpNode> nodes = TestUtils.dumpModel(root);
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, B_NAME, C_NAME);
DumpNode actualB = TestUtils.findByName(nodes, B_NAME);
assertThatMapOf(normalRelationChildren(actualB)).containsExactlyInAnyOrder(tuple("MaybeC", C_NAME));
assertThatMapOf(normalRelationChildren(actualB)).containsExactlyInAnyOrder(tuple("MaybeC?", C_NAME));
}
@Test
......@@ -245,7 +248,7 @@ public class TestSimple {
DumpNode actualA = TestUtils.findByName(nodes, A_NAME);
assertThatMapOf(normalRelationChildren(actualA)).containsExactlyInAnyOrder(tuple("BiC3", C_NAME));
DumpNode actualC = TestUtils.findByName(nodes, C_NAME);
assertThatMapOf(normalRelationChildren(actualC)).containsExactlyInAnyOrder(tuple("BiA3", A_NAME));
assertThatMapOf(normalRelationChildren(actualC)).containsExactlyInAnyOrder(tuple("BiA3?", A_NAME));
}
@Test
......@@ -282,7 +285,7 @@ public class TestSimple {
Root root = createRoot(createA(A_NAME), null);
List<DumpNode> nodes = TestUtils.dumpModel(root,
builder -> builder.<ASTNode<?>>setNameMethod(n -> n.isA() ? "A" : "Not A"));
builder -> builder.<ASTNode<?>>nodeStyle((node, style) -> style.setLabel(node.isA() ? "A" : "Not A")));
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertEquals("Not A", actualRoot.getLabel());
......@@ -295,7 +298,7 @@ public class TestSimple {
Root root = createRoot(createA(A_NAME), null);
List<DumpNode> nodes = TestUtils.dumpModel(root,
builder -> builder.<ASTNode<?>>setTextColorMethod(n -> n.isA() ? "red" : ""));
builder -> builder.<ASTNode<?>>nodeStyle((node, style) -> style.setTextColor(node.isA() ? "red" : "")));
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertEquals("", actualRoot.getTextColor());
......@@ -308,7 +311,7 @@ public class TestSimple {
Root root = createRoot(createA(A_NAME), null);
List<DumpNode> nodes = TestUtils.dumpModel(root,
builder -> builder.<ASTNode<?>>setBackgroundColorMethod(n -> n.isA() ? "green" : ""));
builder -> builder.<ASTNode<?>>nodeStyle((node, style) -> style.setBackgroundColor(node.isA() ? "green" : "")));
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertEquals("", actualRoot.getBackgroundColor());
......
package de.tudresden.inf.st.jastadd.testDumper;
import de.tudresden.inf.st.jastadd.dumpAst.ast.DumpNode;
import de.tudresden.inf.st.jastadd.dumpAst.ast.TransformationException;
import org.jastadd.testDumper.ast.A;
import org.jastadd.testDumper.ast.AbstractT;
import org.jastadd.testDumper.ast.TRoot;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.function.Consumer;
import static de.tudresden.inf.st.jastadd.testDumper.TestUtils.*;
import static org.assertj.core.api.Assertions.*;
/**
* Testing type-level exclusions.
* <p>
* Refer to {@link de.tudresden.inf.st.jastadd.dumpAst.ast.DumpBuilder DumpBuilder} for levels of inclusion/exclusion.
*
* @author rschoene - Initial contribution
*/
public class TestTypeLevel3 {
@Test
public void testTokenLevel2Excluded() throws TransformationException {
Consumer<AbstractT> setUnwanted = t -> t.setUnwanted(5);
TRoot root = createTRoot(createA(A_NAME), createT1(setUnwanted), createT2(setUnwanted), createT3(setUnwanted));
Assertions.assertEquals(5, root.getT2().getUnwanted());
List<DumpNode> nodes = TestUtils.dumpModel(root, dp -> dp.excludeTokens("Unwanted"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
DumpNode actualTx = TestUtils.findByName(nodes, name);
assertThat(valueTokens(actualTx)).containsOnly(entry("Name", name));
}
}
@Test
public void testTokenLevel3SomeIncluded() throws TransformationException {
Consumer<AbstractT> setUnwanted = t -> t.setUnwanted(5);
TRoot root = createTRoot(createA(A_NAME), createT1(setUnwanted), createT2(setUnwanted), createT3(setUnwanted));
Assertions.assertEquals(5, root.getT2().getUnwanted());
List<DumpNode> nodesT2 = TestUtils.dumpModel(root,
dp -> dp.excludeTokens("Unwanted")
.includeTokensFor("T2", "Unwanted"));
assertThat(nodesT2).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(valueTokens(TestUtils.findByName(nodesT2, T1_NAME))).containsOnly(
entry("Name", T1_NAME));
assertThat(valueTokens(TestUtils.findByName(nodesT2, T2_NAME))).containsOnly(
entry("Name", T2_NAME), entry("Unwanted", 5));
assertThat(valueTokens(TestUtils.findByName(nodesT2, T3_NAME))).containsOnly(
entry("Name", T3_NAME));
List<DumpNode> nodesT2T3 = TestUtils.dumpModel(root,
dp -> dp.excludeTokens("Unwanted")
.includeTokensFor("T2|T3", "Unwanted"));
assertThat(nodesT2T3).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(valueTokens(TestUtils.findByName(nodesT2T3, T1_NAME))).containsOnly(
entry("Name", T1_NAME));
assertThat(valueTokens(TestUtils.findByName(nodesT2T3, T2_NAME))).containsOnly(
entry("Name", T2_NAME), entry("Unwanted", 5));
assertThat(valueTokens(TestUtils.findByName(nodesT2T3, T3_NAME))).containsOnly(
entry("Name", T3_NAME), entry("Unwanted", 5));
}
@Test
public void testNormalChildLevel2Excluded() throws TransformationException {
Consumer<AbstractT> setB = t -> t.setB(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(setB), createT2(setB), createT3(setB));
Assertions.assertEquals(T2_NAME + B_NAME, root.getT2().getB().getName());
List<DumpNode> nodes = TestUtils.dumpModel(root, dp -> dp.excludeChildren("B"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
DumpNode actualTx = TestUtils.findByName(nodes, name);
assertThat(normalChildren(actualTx)).isEmpty();
}
}
@Test
public void testNormalChildLevel3SomeIncluded() throws TransformationException {
Consumer<AbstractT> setB = t -> t.setB(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(setB), createT2(setB), createT3(setB));
Assertions.assertEquals(T2_NAME + B_NAME, root.getT2().getB().getName());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.excludeChildren("B")
.includeChildrenFor("T2", "B"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, T2_NAME + B_NAME);
assertThat(normalChildren(TestUtils.findByName(nodes, T1_NAME))).isEmpty();
assertThatMapOf(normalChildren(TestUtils.findByName(nodes, T2_NAME))).containsOnly(
tuple("B", T2_NAME + B_NAME));
assertThat(normalChildren(TestUtils.findByName(nodes, T3_NAME))).isEmpty();
}
@Test
public void testListChildLevel2Excluded() throws TransformationException {
Consumer<AbstractT> addBee = t -> t.addBee(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(addBee), createT2(addBee), createT3(addBee));
Assertions.assertEquals(T2_NAME + B_NAME, root.getT2().getBee(0).getName());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.excludeChildren("Bee"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
assertThat(listChildren(TestUtils.findByName(nodes, name))).isEmpty();
}
}
@Test
public void testListChildLevel3SomeIncluded() throws TransformationException {
Consumer<AbstractT> addBee = t -> t.addBee(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(addBee), createT2(addBee), createT3(addBee));
Assertions.assertEquals(T2_NAME + B_NAME, root.getT2().getBee(0).getName());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.excludeChildren("Bee")
.includeChildrenFor("T2", "Bee"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, T2_NAME + B_NAME);
assertThat(listChildren(TestUtils.findByName(nodes, T1_NAME))).isEmpty();
assertThatMapOf(listChildren(TestUtils.findByName(nodes, T2_NAME)), "Bee").containsOnly(
T2_NAME + B_NAME);
assertThat(listChildren(TestUtils.findByName(nodes, T3_NAME))).isEmpty();
}
@Test
public void testRelationLevel2Excluded() throws TransformationException {
final A a = createA(A_NAME);
Consumer<AbstractT> setOneA = t -> t.setOneA(a);
TRoot root = createTRoot(a, createT1(setOneA), createT2(setOneA), createT3(setOneA));
Assertions.assertEquals(a, root.getT2().getOneA());
List<DumpNode> nodes = TestUtils.dumpModel(root, dp -> dp.excludeRelations("OneA"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
DumpNode actualTx = TestUtils.findByName(nodes, name);
assertThat(normalRelationChildren(actualTx)).isEmpty();
}
}
@Test
public void testRelationLevel3SomeIncluded() throws TransformationException {
final A a = createA(A_NAME);
Consumer<AbstractT> setOneA = t -> t.setOneA(a);
TRoot root = createTRoot(a, createT1(setOneA), createT2(setOneA), createT3(setOneA));
Assertions.assertEquals(a, root.getT2().getOneA());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.excludeRelations("OneA")
.includeRelationsFor("T2", "OneA"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(normalRelationChildren(TestUtils.findByName(nodes, T1_NAME))).isEmpty();
assertThatMapOf(normalRelationChildren(TestUtils.findByName(nodes, T2_NAME))).containsOnly(
tuple("OneA", A_NAME));
assertThat(normalRelationChildren(TestUtils.findByName(nodes, T3_NAME))).isEmpty();
}
@Test
public void testAttributeLevel2Included() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.includeAttributes("simpleAttr"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
DumpNode actualTx = findByName(nodes, name);
assertThat(valueTokens(actualTx)).containsOnly(
entry("Name", name),
entry(TOKEN_LABEL_UNWANTED, 0),
entry("simpleAttr", 43));
}
}
@Test
public void testAttributeLevel3SomeExcluded() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.includeAttributes("simpleAttr")
.excludeAttributesFor("T2", "simpleAttr"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(valueTokens(findByName(nodes, T1_NAME))).containsOnly(
entry("Name", T1_NAME), entry(TOKEN_LABEL_UNWANTED, 0), entry("simpleAttr", 43));
assertThat(valueTokens(findByName(nodes, T2_NAME))).containsOnly(
entry("Name", T2_NAME), entry(TOKEN_LABEL_UNWANTED, 0));
assertThat(valueTokens(findByName(nodes, T3_NAME))).containsOnly(
entry("Name", T3_NAME), entry(TOKEN_LABEL_UNWANTED, 0), entry("simpleAttr", 43));
}
@Test
public void testNTALevel2Included() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.includeNonterminalAttributes("Calculated"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, "Calculated-" + T1_NAME, "Calculated-" + T2_NAME, "Calculated-" + T3_NAME);
for (String name : Tx_NAMES) {
assertThatMapOf(normalChildren(findByName(nodes, name))).containsOnly(
tuple("Calculated", "Calculated-" + name));
}
}
@Test
public void testNTALevel3SomeExcluded() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.includeNonterminalAttributes("Calculated")
.excludeNonterminalAttributesFor("T2", "Calculated"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, "Calculated-" + T1_NAME, "Calculated-" + T3_NAME);
assertThatMapOf(normalChildren(findByName(nodes, T1_NAME))).containsOnly(
tuple("Calculated", "Calculated-" + T1_NAME));
assertThat(normalChildren(findByName(nodes, T2_NAME))).isEmpty();
assertThatMapOf(normalChildren(findByName(nodes, T3_NAME))).containsOnly(
tuple("Calculated", "Calculated-" + T3_NAME));
}
}
package de.tudresden.inf.st.jastadd.testDumper;
import de.tudresden.inf.st.jastadd.dumpAst.ast.DumpNode;
import de.tudresden.inf.st.jastadd.dumpAst.ast.TransformationException;
import org.jastadd.testDumper.ast.A;
import org.jastadd.testDumper.ast.AbstractT;
import org.jastadd.testDumper.ast.TRoot;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.function.Consumer;
import static de.tudresden.inf.st.jastadd.testDumper.TestUtils.*;
import static org.assertj.core.api.Assertions.*;
/**
* Testing type-level inclusions.
* <p>
* Refer to {@link de.tudresden.inf.st.jastadd.dumpAst.ast.DumpBuilder DumpBuilder} for levels of inclusion/exclusion.
*
* @author rschoene - Initial contribution
*/
public class TestTypeLevel4 {
@Test
public void testTokenLevel3Included() throws TransformationException {
Consumer<AbstractT> setUnwanted = t -> t.setUnwanted(5);
TRoot root = createTRoot(createA(A_NAME, createC(C_NAME, c -> c.setUnwanted(6))),
createT1(setUnwanted), createT2(setUnwanted), createT3(setUnwanted));
Assertions.assertEquals(5, root.getT2().getUnwanted());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeTokens(TOKEN_LABEL_UNWANTED)
.includeTokensFor("T.", TOKEN_LABEL_UNWANTED));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(
ROOT_NAME, A_NAME, C_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
DumpNode actualTx = findByName(nodes, name);
assertThat(valueTokens(actualTx)).containsOnly(entry("Name", name), entry(TOKEN_LABEL_UNWANTED, 5));
}
assertThat(valueTokens(findByName(nodes, C_NAME))).containsOnly(
entry("Name", C_NAME));
}
@Test
public void testTokenLevel4SomeExcluded() throws TransformationException {
Consumer<AbstractT> setUnwanted = t -> t.setUnwanted(5);
TRoot root = createTRoot(createA(A_NAME, createC(C_NAME, c -> c.setUnwanted(6))),
createT1(setUnwanted), createT2(setUnwanted), createT3(setUnwanted));
Assertions.assertEquals(5, root.getT2().getUnwanted());
List<DumpNode> nodesT2 = dumpModel(root,
dp -> dp.excludeTokens(TOKEN_LABEL_UNWANTED)
.includeTokensFor("T.", TOKEN_LABEL_UNWANTED)
.excludeTokensFor("T3", TOKEN_LABEL_UNWANTED));
assertThat(nodesT2).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(
ROOT_NAME, A_NAME, C_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(valueTokens(findByName(nodesT2, T1_NAME))).containsOnly(
entry("Name", T1_NAME), entry(TOKEN_LABEL_UNWANTED, 5));
assertThat(valueTokens(findByName(nodesT2, T2_NAME))).containsOnly(
entry("Name", T2_NAME), entry(TOKEN_LABEL_UNWANTED, 5));
assertThat(valueTokens(findByName(nodesT2, T3_NAME))).containsOnly(
entry("Name", T3_NAME));
assertThat(valueTokens(findByName(nodesT2, C_NAME))).containsOnly(
entry("Name", C_NAME));
List<DumpNode> nodesT2T3 = dumpModel(root,
dp -> dp.excludeTokens(TOKEN_LABEL_UNWANTED)
.includeTokensFor("T.", TOKEN_LABEL_UNWANTED)
.excludeTokensFor("T2|T3", TOKEN_LABEL_UNWANTED));
assertThat(nodesT2T3).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(
ROOT_NAME, A_NAME, C_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(valueTokens(findByName(nodesT2T3, T1_NAME))).containsOnly(
entry("Name", T1_NAME), entry(TOKEN_LABEL_UNWANTED, 5));
assertThat(valueTokens(findByName(nodesT2T3, T2_NAME))).containsOnly(
entry("Name", T2_NAME));
assertThat(valueTokens(findByName(nodesT2T3, T3_NAME))).containsOnly(
entry("Name", T3_NAME));
assertThat(valueTokens(findByName(nodesT2T3, C_NAME))).containsOnly(
entry("Name", C_NAME));
}
@Test
public void testNormalChildLevel3Included() throws TransformationException {
Consumer<AbstractT> setB = t -> t.setB(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(setB), createT2(setB), createT3(setB));
Assertions.assertEquals(T2_NAME + B_NAME, root.getT2().getB().getName());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeChildren("B")
.includeChildrenFor("T.", "B"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, T1_NAME + B_NAME, T2_NAME + B_NAME, T3_NAME + B_NAME);
for (String name : Tx_NAMES) {
assertThatMapOf(normalChildren(findByName(nodes, name))).containsOnly(
tuple("B", name + B_NAME));
}
}
@Test
public void testNormalChildLevel4SomeExcluded() throws TransformationException {
Consumer<AbstractT> setB = t -> t.setB(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(setB), createT2(setB), createT3(setB));
Assertions.assertEquals(T2_NAME + B_NAME, root.getT2().getB().getName());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeChildren("B")
.includeChildrenFor("T.", "B")
.excludeChildrenFor("T3", "B"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, T1_NAME + B_NAME, T2_NAME + B_NAME);
assertThatMapOf(normalChildren(findByName(nodes, T1_NAME))).containsOnly(
tuple("B", T1_NAME + B_NAME));
assertThatMapOf(normalChildren(findByName(nodes, T2_NAME))).containsOnly(
tuple("B", T2_NAME + B_NAME));
assertThat(normalChildren(findByName(nodes, T3_NAME))).isEmpty();
}
@Test
public void testListChildLevel3Included() throws TransformationException {
Consumer<AbstractT> addBee = t -> t.addBee(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(addBee), createT2(addBee), createT3(addBee));
Assertions.assertEquals(T3_NAME + B_NAME, root.getT3().getBee(0).getName());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeChildren("Bee")
.includeChildrenFor("T.", "Bee"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, T1_NAME + B_NAME, T2_NAME + B_NAME, T3_NAME + B_NAME);
for (String name : Tx_NAMES) {
assertThatMapOf(listChildren(findByName(nodes, name)), "Bee").containsOnly(
name + B_NAME);
}
}
@Test
public void testListChildLevel4SomeExcluded() throws TransformationException {
Consumer<AbstractT> addBee = t -> t.addBee(createB(t.getName() + B_NAME));
TRoot root = createTRoot(createA(A_NAME), createT1(addBee), createT2(addBee), createT3(addBee));
Assertions.assertEquals(T3_NAME + B_NAME, root.getT3().getBee(0).getName());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeChildren("Bee")
.includeChildrenFor("T.", "Bee")
.excludeChildrenFor("T3", "Bee"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, T1_NAME + B_NAME, T2_NAME + B_NAME);
assertThatMapOf(listChildren(findByName(nodes, T1_NAME)), "Bee").containsOnly(
T1_NAME + B_NAME);
assertThatMapOf(listChildren(findByName(nodes, T2_NAME)), "Bee").containsOnly(
T2_NAME + B_NAME);
assertThat(listChildren(findByName(nodes, T3_NAME))).isEmpty();
}
@Test
public void testRelationLevel3Included() throws TransformationException {
final A a = createA(A_NAME);
Consumer<AbstractT> setOneA = t -> t.setOneA(a);
TRoot root = createTRoot(a, createT1(setOneA), createT2(setOneA), createT3(setOneA));
Assertions.assertEquals(a, root.getT2().getOneA());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeRelations("OneA")
.includeRelationsFor("T2", "OneA"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(normalRelationChildren(findByName(nodes, T1_NAME))).isEmpty();
assertThatMapOf(normalRelationChildren(findByName(nodes, T2_NAME))).containsOnly(
tuple("OneA", A_NAME));
assertThat(normalRelationChildren(findByName(nodes, T3_NAME))).isEmpty();
}
@Test
public void testRelationLevel4SomeExcluded() throws TransformationException {
final A a = createA(A_NAME);
Consumer<AbstractT> setOneA = t -> t.setOneA(a);
TRoot root = createTRoot(a, createT1(setOneA), createT2(setOneA), createT3(setOneA));
Assertions.assertEquals(a, root.getT2().getOneA());
List<DumpNode> nodes = dumpModel(root,
dp -> dp.excludeRelations("OneA")
.includeRelationsFor("T.", "OneA")
.excludeRelationsFor("T3", "OneA"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThatMapOf(normalRelationChildren(findByName(nodes, T1_NAME))).containsOnly(
tuple("OneA", A_NAME));
assertThatMapOf(normalRelationChildren(findByName(nodes, T2_NAME))).containsOnly(
tuple("OneA", A_NAME));
assertThat(normalRelationChildren(findByName(nodes, T3_NAME))).isEmpty();
}
@Test
public void testAttributeLevel3Excluded() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.includeAttributes("simpleAttr")
.excludeAttributesFor("T.", "simpleAttr"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
for (String name : Tx_NAMES) {
DumpNode actualTx = TestUtils.findByName(nodes, name);
assertThat(valueTokens(actualTx)).containsOnly(
entry("Name", name), entry(TOKEN_LABEL_UNWANTED, 0));
}
}
@Test
public void testAttributeLevel4SomeIncluded() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.includeAttributes("simpleAttr")
.excludeAttributesFor("T.", "simpleAttr")
.includeAttributesFor("T3", "simpleAttr"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
assertThat(valueTokens(TestUtils.findByName(nodes, T1_NAME))).containsOnly(
entry("Name", T1_NAME), entry(TOKEN_LABEL_UNWANTED, 0));
assertThat(valueTokens(TestUtils.findByName(nodes, T2_NAME))).containsOnly(
entry("Name", T2_NAME), entry(TOKEN_LABEL_UNWANTED, 0));
assertThat(valueTokens(TestUtils.findByName(nodes, T3_NAME))).containsOnly(
entry("Name", T3_NAME), entry(TOKEN_LABEL_UNWANTED, 0), entry("simpleAttr", 43));
}
@Test
public void testNTALevel3Excluded() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.includeNonterminalAttributes("Calculated")
.excludeNonterminalAttributesFor("T.", "Calculated"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME);
DumpNode actualT3 = TestUtils.findByName(nodes, T3_NAME);
assertThat(normalChildren(actualT3)).isEmpty();
}
@Test
public void testNTALevel4SomeIncluded() throws TransformationException {
TRoot root = createTRoot(createA(A_NAME), createT1(), createT2(), createT3());
List<DumpNode> nodes = TestUtils.dumpModel(root,
dp -> dp.includeNonterminalAttributes("Calculated")
.excludeNonterminalAttributesFor("T.", "Calculated")
.includeNonterminalAttributesFor("T3", "Calculated"));
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, T1_NAME, T2_NAME, T3_NAME, "Calculated-" + T3_NAME);
DumpNode actualT3 = TestUtils.findByName(nodes, T3_NAME);
assertThatMapOf(normalChildren(actualT3)).containsOnly(tuple("Calculated", "Calculated-" + T3_NAME));
}
}
......@@ -11,7 +11,7 @@ import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.*;
public class TestUtils {
public static final Random rand = new Random();
......@@ -30,7 +30,6 @@ public class TestUtils {
public static final String T1_NAME = "T1" + Integer.toHexString(rand.nextInt(0xFFFFFF));
public static final String T2_NAME = "T2" + Integer.toHexString(rand.nextInt(0xFFFFFF));
public static final String T3_NAME = "T3" + Integer.toHexString(rand.nextInt(0xFFFFFF));
public static final String[] Tx_NAMES = {T1_NAME, T2_NAME, T3_NAME};
public static Root createRoot(A a, C c, B... bs) {
Root result = new Root();
......@@ -92,50 +91,9 @@ public class TestUtils {
return result;
}
public static TRoot createTRoot(A a, T1 t1, T2 t2, T3 t3) {
TRoot result = new TRoot();
result.setName(ROOT_NAME);
if (a != null) {
result.setA(a);
}
if (t1 != null) {
result.setT1(t1);
}
if (t2 != null) {
result.setT2(t2);
}
if (t3 != null) {
result.setT3(t3);
}
return result;
}
@SafeVarargs
public static T1 createT1(Consumer<AbstractT>... additionalSettings) {
return setupAbstractT(new T1(), T1_NAME, additionalSettings);
}
@SafeVarargs
public static T2 createT2(Consumer<AbstractT>... additionalSettings) {
return setupAbstractT(new T2(), T2_NAME, additionalSettings);
}
@SafeVarargs
public static T3 createT3(Consumer<AbstractT>... additionalSettings) {
return setupAbstractT(new T3(), T3_NAME, additionalSettings);
}
private static <T extends AbstractT> T setupAbstractT(T t, String name, Consumer<AbstractT>[] additionalSettings) {
t.setName(name);
for (Consumer<AbstractT> setting : additionalSettings) {
setting.accept(t);
}
return t;
}
public static final Function<DumpNode, String> NAME_EXTRACTOR = node -> {
for (DumpToken dumpToken : node.getDumpTokenList()) {
if (dumpToken.getName().equals("Name")) {
if (dumpToken.getLabel().equals("Name")) {
return dumpToken.asDumpValueToken().getValue().toString();
}
}
......@@ -150,6 +108,16 @@ public class TestUtils {
return Assertions.assertThat(map.get(key)).flatExtracting(NAME_EXTRACTOR);
}
public static void assertEmpty(DumpChildNode node) {
assertEquals(1, node.asDumpListChildNode().getNumInnerDumpNode());
assertTrue(node.asDumpListChildNode().getInnerDumpNode(0).getDumpNode().isEmpty());
}
public static void assertEmpty(DumpRelation node) {
assertEquals(1, node.asDumpListRelation().getNumInnerRelationDumpNode());
assertTrue(node.asDumpListRelation().getInnerRelationDumpNode(0).getDumpNode().isEmpty());
}
public static List<DumpNode> dumpModel(Object target) throws TransformationException {
return dumpModel(target, db -> {});
}
......@@ -188,7 +156,7 @@ public class TestUtils {
// then it is a DumpNormalChildNode
DumpNode target = ((DumpNormalChildNode) dumpChildNode).getDumpNode();
if (target != null && !target.getInvisible()) {
result.put(dumpChildNode.getName(), target);
result.put(dumpChildNode.getLabel(), target);
}
}
}
......@@ -202,7 +170,7 @@ public class TestUtils {
// then it is a DumpListChildNode
((DumpListChildNode) dumpChildNode).getInnerDumpNodeList().forEach(inner -> {
if (inner.getDumpNode() != null && !inner.getDumpNode().getInvisible()) {
result.computeIfAbsent(dumpChildNode.getName(), key -> new ArrayList<>()).add(inner.getDumpNode());
result.computeIfAbsent(dumpChildNode.getLabel(), key -> new ArrayList<>()).add(inner.getDumpNode());
}
});
}
......@@ -217,7 +185,7 @@ public class TestUtils {
// then it is a DumpNormalRelation
DumpNode target = ((DumpNormalRelation) dumpRelation).getDumpNode();
if (!target.getInvisible()) {
result.put(dumpRelation.getName(), target);
result.put(dumpRelation.getLabel(), target);
}
}
}
......@@ -231,7 +199,7 @@ public class TestUtils {
// then it is a DumpListRelation
((DumpListRelation) dumpRelation).getInnerRelationDumpNodeList().forEach(inner -> {
if (!inner.getDumpNode().getInvisible()) {
result.computeIfAbsent(dumpRelation.getName(), key -> new ArrayList<>()).add(inner.getDumpNode());
result.computeIfAbsent(dumpRelation.getLabel(), key -> new ArrayList<>()).add(inner.getDumpNode());
}
});
}
......@@ -244,9 +212,9 @@ public class TestUtils {
for (DumpToken dumpToken : node.getDumpTokenList()) {
if (!dumpToken.isDumpValueToken() && !dumpToken.isList()) {
// then it is a DumpReferenceToken
DumpNode target = ((DumpReferenceToken) dumpToken).getValue();
DumpNode target = ((DumpReferenceToken) dumpToken).getDumpNode();
if (!target.getInvisible()) {
result.put(dumpToken.getName(), target);
result.put(dumpToken.getLabel(), target);
}
}
}
......@@ -260,7 +228,7 @@ public class TestUtils {
// then it is a DumpReferenceListToken
((DumpReferenceListToken) dumpToken).getInnerRelationDumpNodeList().forEach(inner -> {
if (!inner.getDumpNode().getInvisible()) {
result.computeIfAbsent(dumpToken.getName(), key -> new ArrayList<>()).add(inner.getDumpNode());
result.computeIfAbsent(dumpToken.getLabel(), key -> new ArrayList<>()).add(inner.getDumpNode());
}
});
}
......@@ -274,7 +242,7 @@ public class TestUtils {
if (dumpToken.isDumpValueToken()) {
// then it is a DumpValueToken
DumpValueToken dumpValueToken = (DumpValueToken) dumpToken;
result.put(dumpValueToken.getName(), dumpValueToken.getValue());
result.put(dumpValueToken.getLabel(), dumpValueToken.getValue());
}
}
return result;
......
......@@ -4,7 +4,7 @@ Check the [package overview page](https://git-st.inf.tu-dresden.de/jastadd/dumpA
To use `dumpAst`, adjust your `build.gradle` as follows.
Set up the maven package source as repository:
Set up the maven package source as a repository:
```
repositories {
......@@ -19,7 +19,7 @@ Add `dumpAst` as a dependency:
```
dependencies {
implementation group: 'de.tudresden.inf.st', name: 'dumpAst', version: '1.2.0'
implementation group: 'de.tudresden.inf.st', name: 'dumpAst', version: '{{dumpAst_version()}}'
}
```
......@@ -38,7 +38,7 @@ ls dumpAst.base/build/libs/
This jar can then be copied to your project.
```bash
cp dumpAst.base/build/libs/dumpAst.base-fatJar-<version>.jar ../your-project/libs/dumpAst.jar
cp dumpAst.base/build/libs/dumpAst.base-fatJar-{{dumpAst_version()}}.jar ../your-project/libs/dumpAst.jar
cd ../your-project/
```
......
pages/docs/img/ST-black.png

18.2 KiB

# DumpAst
The tool called `DumpAst` ([see in repo](https://git-st.inf.tu-dresden.de/jastadd/dumpAst)) is used to create a snapshot of an AST and visualize it.
The tool called `DumpAst` ([see in repo](https://git-st.inf.tu-dresden.de/jastadd/dumpAst)) is used to create a snapshot of an AST and visualise it.
![](img/dumpAst.png)
......@@ -17,6 +17,6 @@ Then, read in the ASTNode in question:
Dumper.read(astNode)
```
Using the return value (a `DumpBuilder`), use methods to filter out unwanted parts, add styling or other settings.
Using the return value (a `DumpBuilder`), use methods to filter out unwanted parts and add styling or other settings.
All methods can be chained together.
Please see the [API documentation](ragdoc/index.html) for more details.
Please see [the subpage on using DumpAst](using.md) and the [API documentation](ragdoc/index.html) for more details.
# Using DumpAst
After [adding DumpAst to your project](adding.md), you can start getting snapshot of some (part of an) AST.
Here is one example with a `Model` containing nodes of type `Robot`, `Joint` and `EndEffector` amongst others.
It is explained in detail below.
```java
import de.tudresden.inf.st.jastadd.dumpAst.ast.*;
import your.model.Robot;
import your.model.Model;
import your.model.ASTNode;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) throws IOException, TransformationException {
Model model = createModel(); // (1)
DumpBuilder builder = Dumper.read(model) // (2)
.includeChild((parentNode, childNode, contextName) -> { // (3)
if (parentNode instanceof Robot && ((Robot) parentNode).getName().equals("Robot2")) {
return false;
}
return !contextName.equals("EndEffector");
})
.nodeStyle((node, style) -> {
style.useSimpleName(); // (4)
style.setBackgroundColor(node.size() > 30 ? "blue" : "white"); // (5)
})
.relationStyle((source, target, isComputed, isContainment, style) -> {
if (style.getLabel().equals("EndEffector")) {
style.setLabel(""); // (6)
}
})
.skinParam(SkinParamBooleanSetting.Shadowing, false); // (7)
builder.dumpAsPng(Paths.get("featureTest.png")); // (8)
builder.dumpAsSVG(Paths.get("featureTest.svg")); // (9)
OutputStream os = getMyOutputStream();
builder.dumpAsPNG(os); // (10)
}
}
```
DumpAst uses the [Builder design pattern](https://en.wikipedia.org/wiki/Builder_pattern) as well as a [fluent API](https://en.wikipedia.org/wiki/Fluent_interface).
That means, first, all settings are specified (2-6), and only after a "dump"-method is called (7,8) the actual snapshot is taken.
For filtering the output, there are various lambda functions (`include___`).
Those methods are available for children, attributes, relations and tokens.
By default, all children, relations and tokens are included in the output, whereas all attributes are excluded.
The steps in detail:
- (1) In the beginning, your model is somehow constructed and changed. This is indicated with the method `createModel`.
- (2) The first call is always `Dumper.read()` to which the (part of the) AST is provided as an argument. It returns an object of type [DumpBuilder](../ragdoc/#/type/DumpBuilder). With this object, the output can be changed.
- (3) [Optional] You can only include nodes of certain types by using `includeChild` and passing a lambda function, which is called for every node and should return `true` if the `childNode` shall be included in the output. It defaults to returning `true` for every node. Here, all children of a `Robot` node (except if the name of the robot is `"Robot2"`) and all children of the context named `"EndEffector"` are excluded.
- (4) and (5) [Optional] To style a node, the method `nodeStyle` is used. It accepts a lambda function, in which the style of every node can be customized by calling methods on the given `Style` object, e.g. setting the name (5) or background color (6). The default name is to use the class name along with the hashcode of the object (`node == null ? "null" : node.getClass().getSimpleName() + "@" + Integer.toHexString(node.hashCode())`).
- (6) [Optional] To style a relation, the method `relationStyle` is used. It is used similar to `nodeStyle`, but is called with source and target node of a relation (containment and non-containment). Note, that (a) the default label can be retrieved with `style.getLabel()`, (b) `target` can be `null` for lists, (c) secondary connections from a list node to the target nodes use the style of the relation and use their index as label.
- (7) [Optional] There are a few ways to style the output in general through [SkinParam](https://plantuml.com/de/skinparam). Not all of those parameters are supported; see `SkinParamBooleanSetting` and `SkinParamStringSetting`.
- (8), (9) and (10) To create an output image, use `dumpAsPng` for PNG (`dumpAsSVG` for SVG). Those methods do not return the builder object, as they produce an output. They potentially throw two kinds of exception: `IOException` (when the file could not be written) and `TransformationException` (when the AST could not be processed). As shown here, the builder object must be stored in a variable to create multiple outputs. Alternatively to a file, the result can be written to a given `OutputStream` (10).
To summarise the required steps: Specify the AST to read in, configure the output, and write ("dump") the output.
For more configuration options, please consult the [API Docs of DumpBuilder](../ragdoc/#/type/DumpBuilder) or check out [FeatureTestMain](https://git-st.inf.tu-dresden.de/jastadd/dumpAst/-/blob/main/dumpAst.prototyping/src/main/java/de/tudresden/inf/st/jastadd/featureTest/FeatureTestMain.java).
......@@ -5,11 +5,26 @@ site_dir: ../public
nav:
- "DumpAst": index.md
- "Add to your project": adding.md
- "Using DumpAst": using.md
- "API documentation": ragdoc/index.html
theme:
name: readthedocs
custom_dir: custom_theme/
name: material
font: false
palette:
# Palette toggle for light mode
- scheme: default
toggle:
icon: material/brightness-7
name: Switch to dark mode
# Palette toggle for dark mode
- scheme: slate
toggle:
icon: material/brightness-4
name: Switch to light mode
favicon: img/ST-black.png
icon:
logo: material/dump-truck
markdown_extensions:
- toc:
......
mkdocs==1.2.2
mkdocs-git-revision-date-localized-plugin==0.10.3
mkdocs-macros-plugin==0.6.3
Jinja2==2.11.2
MarkupSafe==1.1.1
mkdocs==1.4.2
mkdocs-git-revision-date-localized-plugin==1.1.0
mkdocs-macros-plugin==0.7.0
mkdocs-material==8.5.10
mkdocs-material-extensions==1.1
Jinja2==3.1.2
MarkupSafe==2.1.1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment