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

3.0.0

- prepare new release
- remove deprecated inclusion/exclusion
parent 88264e06
Branches
No related tags found
1 merge request!133.0.1
...@@ -54,9 +54,6 @@ IntrinsicTokenMethod : TokenMethod ::= <Refined:boolean> ; ...@@ -54,9 +54,6 @@ IntrinsicTokenMethod : TokenMethod ::= <Refined:boolean> ;
AttributeMethod : TokenMethod ; AttributeMethod : TokenMethod ;
BuildConfig ::= StyleInformation BuildConfig ::= StyleInformation
GlobalPatternCollection:PatternCollection
ExcludeTypePattern:TypePatternCollectionMapping*
IncludeTypePattern:TypePatternCollectionMapping*
<IncludeRelationMethod:IncludeRelationMethod> <IncludeRelationMethod:IncludeRelationMethod>
<IncludeChildMethod:IncludeChildMethod> <IncludeChildMethod:IncludeChildMethod>
<IncludeAttributeMethod:IncludeAttributeMethod> <IncludeAttributeMethod:IncludeAttributeMethod>
...@@ -65,8 +62,6 @@ BuildConfig ::= StyleInformation ...@@ -65,8 +62,6 @@ BuildConfig ::= StyleInformation
<IncludeEmptyString:boolean> <IncludeEmptyString:boolean>
<ExcludeNullNodes:boolean> <ExcludeNullNodes:boolean>
<Debug:boolean>; <Debug:boolean>;
TypePatternCollectionMapping ::= <TypeRegex> PatternCollection ;
PatternCollection ::= <TokenPattern> <ChildPattern> <RelationPattern> <AttributePattern> <NonterminalAttributePattern> ;
StyleInformation ::= <ComputedColor>; StyleInformation ::= <ComputedColor>;
PrintConfig ::= Header* PrintConfig ::= Header*
......
...@@ -5,6 +5,7 @@ import net.sourceforge.plantuml.FileFormatOption; ...@@ -5,6 +5,7 @@ import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceStringReader; import net.sourceforge.plantuml.SourceStringReader;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer; import java.io.Writer;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files; import java.nio.file.Files;
...@@ -13,8 +14,6 @@ import java.util.ResourceBundle; ...@@ -13,8 +14,6 @@ import java.util.ResourceBundle;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import static de.tudresden.inf.st.jastadd.dumpAst.ast.ASTNode.matches;
/** /**
* Creating a snapshot of an AST. * Creating a snapshot of an AST.
*/ */
...@@ -31,68 +30,10 @@ public class DumpBuilder { ...@@ -31,68 +30,10 @@ public class DumpBuilder {
this.built = false; this.built = false;
this.dumpAst = new DumpAst(); this.dumpAst = new DumpAst();
dumpAst.setBuildConfig(new BuildConfig()); dumpAst.setBuildConfig(new BuildConfig());
dumpAst.getBuildConfig().setIncludeChildMethod((parentNode, childNode, contextName) -> { dumpAst.getBuildConfig().setIncludeChildMethod((parentNode, childNode, contextName) -> true);
// level 4: excluded for type? -> return no dumpAst.getBuildConfig().setIncludeRelationMethod((sourceNode, targetNode, roleName) -> true);
PatternCollection excludeOnType = dumpAst.getBuildConfig().matchExcludePatternCollection(parentNode.getClass().getSimpleName()); dumpAst.getBuildConfig().setIncludeTokenMethod((node, tokenName, value) -> true);
if (excludeOnType != null && matches(excludeOnType.childPattern(), contextName)) { dumpAst.getBuildConfig().setIncludeAttributeMethod((node, attributeName, isNTA, supplier) -> false);
return false;
}
// level 3: included for type? -> return yes
PatternCollection includeOnType = dumpAst.getBuildConfig().matchIncludePatternCollection(parentNode.getClass().getSimpleName());
if (includeOnType != null && matches(includeOnType.childPattern(), contextName)) {
return true;
}
// level 2: globally excluded? -> return no
// level 1: otherwise return yes
return !matches(dumpAst.getBuildConfig().getGlobalPatternCollection().childPattern(), contextName);
});
dumpAst.getBuildConfig().setIncludeRelationMethod((sourceNode, targetNode, roleName) -> {
// level 4: excluded for type? -> return no
PatternCollection excludeOnType = dumpAst.getBuildConfig().matchExcludePatternCollection(sourceNode.getClass().getSimpleName());
if (excludeOnType != null && matches(excludeOnType.relationPattern(), roleName)) {
return false;
}
// level 3: included for type? -> return yes
PatternCollection includeOnType = dumpAst.getBuildConfig().matchIncludePatternCollection(sourceNode.getClass().getSimpleName());
if (includeOnType != null && matches(includeOnType.relationPattern(), roleName)) {
return true;
}
// level 2: globally excluded? -> return no
// level 1: otherwise return yes
return !matches(dumpAst.getBuildConfig().getGlobalPatternCollection().relationPattern(), roleName);
});
dumpAst.getBuildConfig().setIncludeTokenMethod((node, tokenName, value) -> {
// level 4: excluded for type? -> return no
PatternCollection excludeOnType = dumpAst.getBuildConfig().matchExcludePatternCollection(node.getClass().getSimpleName());
if (excludeOnType != null && matches(excludeOnType.tokenPattern(), tokenName)) {
return false;
}
// level 3: included for type? -> return yes
PatternCollection includeOnType = dumpAst.getBuildConfig().matchIncludePatternCollection(node.getClass().getSimpleName());
if (includeOnType != null && matches(includeOnType.tokenPattern(), tokenName)) {
return true;
}
// level 2: globally excluded? -> return no
// level 1: otherwise return yes
return !matches(dumpAst.getBuildConfig().getGlobalPatternCollection().tokenPattern(), tokenName);
});
dumpAst.getBuildConfig().setIncludeAttributeMethod((node, attributeName, isNTA, supplier) -> {
// level 4: included for type? -> return yes
PatternCollection includeOnType = dumpAst.getBuildConfig().matchIncludePatternCollection(node.getClass().getSimpleName());
if (includeOnType != null && matches(isNTA ? includeOnType.ntaPattern() : includeOnType.attributePattern(), attributeName)) {
return true;
}
// level 3: excluded for type? -> return no
PatternCollection excludeOnType = dumpAst.getBuildConfig().matchExcludePatternCollection(node.getClass().getSimpleName());
if (excludeOnType != null && matches(isNTA ? excludeOnType.ntaPattern() : excludeOnType.attributePattern(), attributeName)) {
return false;
}
// level 2: globally included? -> return yes
// level 1: otherwise return no
PatternCollection global = dumpAst.getBuildConfig().getGlobalPatternCollection();
return matches(isNTA ? global.ntaPattern() : global.attributePattern(), attributeName);
});
dumpAst.getBuildConfig().setGlobalPatternCollection(new PatternCollection());
dumpAst.getBuildConfig().setStyleInformation(StyleInformation.createDefault()); dumpAst.getBuildConfig().setStyleInformation(StyleInformation.createDefault());
dumpAst.setPrintConfig(new PrintConfig()); dumpAst.setPrintConfig(new PrintConfig());
dumpAst.getPrintConfig().setScale(1); dumpAst.getPrintConfig().setScale(1);
...@@ -168,354 +109,29 @@ public class DumpBuilder { ...@@ -168,354 +109,29 @@ public class DumpBuilder {
// --- Tokens --- // --- Tokens ---
public <ASTNODE> DumpBuilder includeTokensWhen(IncludeTokenMethod<ASTNODE> spec) { public <ASTNODE> DumpBuilder includeToken(IncludeTokenMethod<ASTNODE> spec) {
dumpAst.getBuildConfig().setIncludeTokenMethod(spec); dumpAst.getBuildConfig().setIncludeTokenMethod(spec);
if (!dumpAst.getBuildConfig().getGlobalPatternCollection().getTokenPattern().isEmpty()) {
System.err.println("Overriding previous filters for tokens");
}
return thisWithResetBuilt();
}
/**
* Exclude tokens and their value if the token name matches at least one of the given regex strings.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param regex first pattern to match token names
* @param moreRegexes more patterns to match token names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder excludeTokens(String regex, String... moreRegexes) {
updateRegexes(() -> dumpAst.getBuildConfig().getGlobalPatternCollection().getTokenPattern(),
s -> dumpAst.getBuildConfig().getGlobalPatternCollection().setTokenPattern(s),
regex, moreRegexes);
return thisWithResetBuilt();
}
/**
* Exclude tokens and their value within a type if the token name matches at least one of the given regex strings.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param typeRegex pattern to match a nonterminal name
* @param regex first pattern to match token names
* @param moreRegexes more patterns to match token names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder excludeTokensFor(String typeRegex, String regex, String... moreRegexes) {
PatternCollection collection = findOrCreateExcludePatternCollection(typeRegex);
updateRegexes(collection::getTokenPattern,
collection::setTokenPattern,
regex, moreRegexes);
return thisWithResetBuilt();
}
/**
* Include tokens (again) and their value within a type if the token name matches at least one of the given regex strings.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param typeRegex pattern to match a nonterminal name
* @param regex first pattern to match token names
* @param moreRegexes more patterns to match token names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder includeTokensFor(String typeRegex, String regex, String... moreRegexes) {
PatternCollection collection = findOrCreateIncludePatternCollection(typeRegex);
updateRegexes(collection::getTokenPattern,
collection::setTokenPattern,
regex, moreRegexes);
return thisWithResetBuilt(); return thisWithResetBuilt();
} }
// --- Children --- // --- Children ---
public <ASTNODE> DumpBuilder includeChildWhen(IncludeChildMethod<ASTNODE> spec) { public <ASTNODE> DumpBuilder includeChild(IncludeChildMethod<ASTNODE> spec) {
dumpAst.getBuildConfig().setIncludeChildMethod(spec); dumpAst.getBuildConfig().setIncludeChildMethod(spec);
if (!dumpAst.getBuildConfig().getGlobalPatternCollection().getChildPattern().isEmpty()) {
System.err.println("Overriding previous filters for children");
}
return thisWithResetBuilt();
}
/**
* Exclude every child whose name (i.e., context) matches at least on of the given regex strings.
* This means, that the complete object and its (transitive) children will never be included in any output.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param regex first pattern to match child name
* @param moreRegexes more patterns to match child names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder excludeChildren(String regex, String... moreRegexes) {
updateRegexes(() -> dumpAst.getBuildConfig().getGlobalPatternCollection().getChildPattern(),
s -> dumpAst.getBuildConfig().getGlobalPatternCollection().setChildPattern(s),
regex, moreRegexes);
return thisWithResetBuilt();
}
/**
* Exclude every child within a type whose name (i.e., context) matches at least on of the given regex strings.
* This means, that the complete object and its (transitive) children will never be included in any output.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param typeRegex pattern to match a nonterminal name
* @param regex first pattern to match child name
* @param moreRegexes more patterns to match child names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder excludeChildrenFor(String typeRegex, String regex, String... moreRegexes) {
PatternCollection collection = findOrCreateExcludePatternCollection(typeRegex);
updateRegexes(collection::getChildPattern,
collection::setChildPattern,
regex, moreRegexes);
return thisWithResetBuilt();
}
/**
* Include every child (again) within a type whose name (i.e., context) matches at least on of the given regex strings.
* This means, that the complete object and its (transitive) children will never be included in any output.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param typeRegex pattern to match a nonterminal name
* @param regex first pattern to match child name
* @param moreRegexes more patterns to match child names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder includeChildrenFor(String typeRegex, String regex, String... moreRegexes) {
PatternCollection collection = findOrCreateIncludePatternCollection(typeRegex);
updateRegexes(collection::getChildPattern,
collection::setChildPattern,
regex, moreRegexes);
return thisWithResetBuilt(); return thisWithResetBuilt();
} }
// --- Attributes --- // --- Attributes ---
public <ASTNODE> DumpBuilder includeAttributeWhen(IncludeAttributeMethod<ASTNODE> spec) { public <ASTNODE> DumpBuilder includeAttribute(IncludeAttributeMethod<ASTNODE> spec) {
dumpAst.getBuildConfig().setIncludeAttributeMethod(spec); dumpAst.getBuildConfig().setIncludeAttributeMethod(spec);
if (!dumpAst.getBuildConfig().getGlobalPatternCollection().getAttributePattern().isEmpty()) {
System.err.println("Overriding previous filters for attributes");
}
return thisWithResetBuilt();
}
/**
* Include attributes (as tokens) and their value if the attribute name matches at least on of the given regex strings.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param regex first pattern to match attribute name
* @param moreRegexes more patterns to match attribute names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder includeAttributes(String regex, String... moreRegexes) {
updateRegexes(() -> dumpAst.getBuildConfig().getGlobalPatternCollection().getAttributePattern(),
s -> dumpAst.getBuildConfig().getGlobalPatternCollection().setAttributePattern(s),
regex, moreRegexes);
return thisWithResetBuilt();
}
/**
* Include attributes within a type (as tokens) and their value if the attribute name matches at least on of the given regex strings.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param typeRegex pattern to match a nonterminal name
* @param regex first pattern to match attribute name
* @param moreRegexes more patterns to match attribute names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder includeAttributesFor(String typeRegex, String regex, String... moreRegexes) {
PatternCollection collection = findOrCreateIncludePatternCollection(typeRegex);
updateRegexes(collection::getAttributePattern,
collection::setAttributePattern,
regex, moreRegexes);
return thisWithResetBuilt();
}
/**
* Exclude attributes within a type (as tokens) and their value (again) if the attribute name matches at least on of the given regex strings.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param typeRegex pattern to match a nonterminal name
* @param regex first pattern to match attribute name
* @param moreRegexes more patterns to match attribute names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder excludeAttributesFor(String typeRegex, String regex, String... moreRegexes) {
PatternCollection collection = findOrCreateExcludePatternCollection(typeRegex);
updateRegexes(collection::getAttributePattern,
collection::setAttributePattern,
regex, moreRegexes);
return thisWithResetBuilt();
}
// --- Nonterminal-Attributes ---
/**
* Includes nonterminal-attributes (as children) and their values if
* their attribute name matches at least on of the given regex strings.
* <br>
* <b>Note</b>: A leading "get" and a trailing "List" in the name will be removed prior to matching.
* Thus, it should not be contained in the regex either.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param regex first pattern to match attribute name
* @param moreRegexes more patterns to match attribute names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder includeNonterminalAttributes(String regex, String... moreRegexes) {
updateRegexes(() -> dumpAst.getBuildConfig().getGlobalPatternCollection().getNonterminalAttributePattern(),
s -> dumpAst.getBuildConfig().getGlobalPatternCollection().setNonterminalAttributePattern(s),
regex, moreRegexes);
return thisWithResetBuilt();
}
/**
* Includes nonterminal-attributes (as children) and their values within a type if
* their attribute name matches at least on of the given regex strings.
* <br>
* <b>Note</b>: A leading "get" and a trailing "List" in the name will be removed prior to matching.
* Thus, it should not be contained in the regex either.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param typeRegex pattern to match a nonterminal name
* @param regex first pattern to match attribute name
* @param moreRegexes more patterns to match attribute names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder includeNonterminalAttributesFor(String typeRegex, String regex, String... moreRegexes) {
PatternCollection collection = findOrCreateIncludePatternCollection(typeRegex);
updateRegexes(collection::getNonterminalAttributePattern,
collection::setNonterminalAttributePattern,
regex, moreRegexes);
return thisWithResetBuilt();
}
/**
* Excludes nonterminal-attributes (as children) and their values (again) within a type if
* their attribute name matches at least on of the given regex strings.
* <br>
* <b>Note</b>: A leading "get" and a trailing "List" in the name will be removed prior to matching.
* Thus, it should not be contained in the regex either.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param typeRegex pattern to match a nonterminal name
* @param regex first pattern to match attribute name
* @param moreRegexes more patterns to match attribute names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder excludeNonterminalAttributesFor(String typeRegex, String regex, String... moreRegexes) {
PatternCollection collection = findOrCreateExcludePatternCollection(typeRegex);
updateRegexes(collection::getNonterminalAttributePattern,
collection::setNonterminalAttributePattern,
regex, moreRegexes);
return thisWithResetBuilt(); return thisWithResetBuilt();
} }
// --- Relations --- // --- Relations ---
public <ASTNODE> DumpBuilder includeRelationsWhen(IncludeRelationMethod<ASTNODE> spec) { public <ASTNODE> DumpBuilder includeRelation(IncludeRelationMethod<ASTNODE> spec) {
dumpAst.getBuildConfig().setIncludeRelationMethod(spec); dumpAst.getBuildConfig().setIncludeRelationMethod(spec);
if (!dumpAst.getBuildConfig().getGlobalPatternCollection().getRelationPattern().isEmpty()) {
System.err.println("Overriding previous filters for relations");
}
return thisWithResetBuilt();
}
/**
* Exclude every relation whose role-name matches at least on of the given regex strings.
* This means two things: a) the relation to any potential target object(s) is never shown, and b) the target
* object(s) are not shown unless they are reachable by another relation or by containment.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param regex first pattern to match child name
* @param moreRegexes more patterns to match child names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder excludeRelations(String regex, String... moreRegexes) {
updateRegexes(() -> dumpAst.getBuildConfig().getGlobalPatternCollection().getRelationPattern(),
s -> dumpAst.getBuildConfig().getGlobalPatternCollection().setRelationPattern(s),
regex, moreRegexes);
return thisWithResetBuilt();
}
/**
* Exclude every relation within a type whose role-name matches at least on of the given regex strings.
* This means two things: a) the relation to any potential target object(s) is never shown, and b) the target
* object(s) are not shown unless they are reachable by another relation or by containment.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param typeRegex pattern to match a nonterminal name
* @param regex first pattern to match child name
* @param moreRegexes more patterns to match child names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder excludeRelationsFor(String typeRegex, String regex, String... moreRegexes) {
PatternCollection collection = findOrCreateExcludePatternCollection(typeRegex);
updateRegexes(collection::getRelationPattern,
collection::setRelationPattern,
regex, moreRegexes);
return thisWithResetBuilt();
}
/**
* Include every relation (again) within a type whose role-name matches at least on of the given regex strings.
* This means two things: a) the relation to any potential target object(s) is never shown, and b) the target
* object(s) are not shown unless they are reachable by another relation or by containment.
* <p>
* See {@link DumpBuilder} for details on inclusion and exclusion precedence.
*
* @param typeRegex pattern to match a nonterminal name
* @param regex first pattern to match child name
* @param moreRegexes more patterns to match child names
* @return this
* @see java.util.regex.Pattern#compile(String)
*/
@Deprecated(since = "2.0.1")
public DumpBuilder includeRelationsFor(String typeRegex, String regex, String... moreRegexes) {
PatternCollection collection = findOrCreateIncludePatternCollection(typeRegex);
updateRegexes(collection::getRelationPattern,
collection::setRelationPattern,
regex, moreRegexes);
return thisWithResetBuilt(); return thisWithResetBuilt();
} }
...@@ -653,6 +269,16 @@ public class DumpBuilder { ...@@ -653,6 +269,16 @@ public class DumpBuilder {
} }
} }
/**
* Return content as intermediate data structure used by the template engine.
*
* @return the intermediate data structure used by the template engine
* @throws TransformationException if {@link DumpAst#transform(TransformationTransferInformation, Object) transform} was not successful
*/
public String dumpAsYaml(boolean prependCreationComment) throws TransformationException {
return build().printYaml(prependCreationComment);
}
/** /**
* Write out content as intermediate data structure used by the template engine. * Write out content as intermediate data structure used by the template engine.
* *
...@@ -668,6 +294,17 @@ public class DumpBuilder { ...@@ -668,6 +294,17 @@ public class DumpBuilder {
} }
} }
/**
* Write out content as PNG image generated by plantuml.
*
* @param os a stream to write to
* @throws IOException if an I/O error happened during writing in that stream
* @throws TransformationException if {@link DumpAst#transform(TransformationTransferInformation, Object) transform} was not successful
*/
public void dumpAsPNG(OutputStream os) throws TransformationException, IOException {
dumpAs(os, FileFormat.PNG);
}
/** /**
* Write out content as PNG image generated by plantuml. * Write out content as PNG image generated by plantuml.
* *
...@@ -679,6 +316,17 @@ public class DumpBuilder { ...@@ -679,6 +316,17 @@ public class DumpBuilder {
dumpAs(destination, FileFormat.PNG); dumpAs(destination, FileFormat.PNG);
} }
/**
* Write out content as SVG image generated by plantuml.
*
* @param os a stream to write to
* @throws IOException if an I/O error happened during writing in that stream
* @throws TransformationException if {@link DumpAst#transform(TransformationTransferInformation, Object) transform} was not successful
*/
public void dumpAsSVG(OutputStream os) throws TransformationException, IOException {
dumpAs(os, FileFormat.SVG);
}
/** /**
* Write out content as SVG image generated by plantuml. * Write out content as SVG image generated by plantuml.
* *
...@@ -690,6 +338,20 @@ public class DumpBuilder { ...@@ -690,6 +338,20 @@ public class DumpBuilder {
dumpAs(destination, FileFormat.SVG); dumpAs(destination, FileFormat.SVG);
} }
/**
* Write out content as PDF image generated by plantuml.
*
* <br>
* <b>Note:</b> This requires additional dependencies, see <a href="https://plantuml.com/pdf">https://plantuml.com/pdf</a>
*
* @param os a stream to write to
* @throws IOException if an I/O error happened during writing in that stream
* @throws TransformationException if {@link DumpAst#transform(TransformationTransferInformation, Object) transform} was not successful
*/
public void dumpAsPDF(OutputStream os) throws TransformationException, IOException {
dumpAs(os, FileFormat.PDF);
}
/** /**
* Write out content as PDF generated by plantuml. * Write out content as PDF generated by plantuml.
* *
...@@ -710,6 +372,12 @@ public class DumpBuilder { ...@@ -710,6 +372,12 @@ public class DumpBuilder {
reader.outputImage(Files.newOutputStream(destination), new FileFormatOption(fileFormat)); reader.outputImage(Files.newOutputStream(destination), new FileFormatOption(fileFormat));
} }
private void dumpAs(OutputStream os, FileFormat fileFormat) throws IOException, TransformationException {
String content = build().toPlantUml();
SourceStringReader reader = new SourceStringReader(content);
reader.outputImage(os, new FileFormatOption(fileFormat));
}
// --- Helper methods --- // --- Helper methods ---
protected DumpAst build() throws TransformationException { protected DumpAst build() throws TransformationException {
...@@ -735,30 +403,6 @@ public class DumpBuilder { ...@@ -735,30 +403,6 @@ public class DumpBuilder {
return dumpAst; return dumpAst;
} }
private PatternCollection findOrCreateIncludePatternCollection(String typeRegex) {
PatternCollection result = dumpAst.getBuildConfig().findIncludePatternCollection(typeRegex);
if (result == null) {
TypePatternCollectionMapping mapping = new TypePatternCollectionMapping();
mapping.setTypeRegex(typeRegex);
result = new PatternCollection();
mapping.setPatternCollection(result);
dumpAst.getBuildConfig().addIncludeTypePattern(mapping);
}
return result;
}
private PatternCollection findOrCreateExcludePatternCollection(String typeRegex) {
PatternCollection result = dumpAst.getBuildConfig().findExcludePatternCollection(typeRegex);
if (result == null) {
TypePatternCollectionMapping mapping = new TypePatternCollectionMapping();
mapping.setTypeRegex(typeRegex);
result = new PatternCollection();
mapping.setPatternCollection(result);
dumpAst.getBuildConfig().addExcludeTypePattern(mapping);
}
return result;
}
private void updateRegexes(Supplier<String> getter, Consumer<String> setter, String regex, String... moreRegexes) { private void updateRegexes(Supplier<String> getter, Consumer<String> setter, String regex, String... moreRegexes) {
if (getter.get().isEmpty()) { if (getter.get().isEmpty()) {
setter.accept(regex); setter.accept(regex);
......
...@@ -47,7 +47,7 @@ public class FeatureTestMain { ...@@ -47,7 +47,7 @@ public class FeatureTestMain {
// .customPreamble("hide empty members") // .customPreamble("hide empty members")
.enableDebug() .enableDebug()
.customPreamble("title My fancy title") .customPreamble("title My fancy title")
.includeChildWhen((parentNode, childNode, contextName) -> { .includeChild((parentNode, childNode, contextName) -> {
if (parentNode instanceof A && ((A) parentNode).getName().equals("A2")) { if (parentNode instanceof A && ((A) parentNode).getName().equals("A2")) {
return false; return false;
} }
...@@ -56,9 +56,9 @@ public class FeatureTestMain { ...@@ -56,9 +56,9 @@ public class FeatureTestMain {
} }
return !contextName.equals("MyC"); return !contextName.equals("MyC");
}) })
.includeRelationsWhen((sourceNode, targetNode, roleName) -> .includeRelation((sourceNode, targetNode, roleName) ->
!(sourceNode instanceof B) || !((B) sourceNode).getName().equals("B6.1.1")) !(sourceNode instanceof B) || !((B) sourceNode).getName().equals("B6.1.1"))
.includeAttributeWhen((node, attributeName, isNTA, supplier) -> { .includeAttribute((node, attributeName, isNTA, supplier) -> {
switch (attributeName) { switch (attributeName) {
case "referenceAttr": case "referenceAttr":
case "collectBs": case "collectBs":
......
...@@ -198,7 +198,8 @@ public class TestExcluded { ...@@ -198,7 +198,8 @@ public class TestExcluded {
c.setBiA1(a); 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); assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, C_NAME);
DumpNode actualC = findByName(nodes, C_NAME); DumpNode actualC = findByName(nodes, C_NAME);
assertThat(valueTokens(actualC)).containsOnly( assertThat(valueTokens(actualC)).containsOnly(
...@@ -218,7 +219,8 @@ public class TestExcluded { ...@@ -218,7 +219,8 @@ public class TestExcluded {
c.setBiA1(a); 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); assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, C_NAME);
DumpNode actualC = findByName(nodes, C_NAME); DumpNode actualC = findByName(nodes, C_NAME);
assertThat(valueTokens(actualC)).containsOnly( assertThat(valueTokens(actualC)).containsOnly(
...@@ -238,7 +240,8 @@ public class TestExcluded { ...@@ -238,7 +240,8 @@ public class TestExcluded {
c.setBiA1(a); 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); assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, C_NAME);
DumpNode actualC = findByName(nodes, C_NAME); DumpNode actualC = findByName(nodes, C_NAME);
assertThat(valueTokens(actualC)).containsOnly( assertThat(valueTokens(actualC)).containsOnly(
...@@ -258,7 +261,8 @@ public class TestExcluded { ...@@ -258,7 +261,8 @@ public class TestExcluded {
c.setBiA1(a); 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); assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME, A_NAME, C_NAME);
DumpNode actualC = findByName(nodes, C_NAME); DumpNode actualC = findByName(nodes, C_NAME);
assertThat(valueTokens(actualC)).containsOnly( assertThat(valueTokens(actualC)).containsOnly(
...@@ -312,7 +316,8 @@ public class TestExcluded { ...@@ -312,7 +316,8 @@ public class TestExcluded {
}), null); }), null);
root.getA().getB().setOneA(root.getA().getMyC().getA()); 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( assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(
ROOT_NAME, A_NAME, B_NAME, A2_Name, B2_NAME); ROOT_NAME, A_NAME, B_NAME, A2_Name, B2_NAME);
DumpNode actualA = findByName(nodes, A_NAME); DumpNode actualA = findByName(nodes, A_NAME);
...@@ -333,7 +338,8 @@ public class TestExcluded { ...@@ -333,7 +338,8 @@ public class TestExcluded {
public void testRelationsExclude() throws TransformationException { public void testRelationsExclude() throws TransformationException {
Root root = setupAllRelations(); 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 // A
assertThatMapOf(normalRelationChildren(findByName(nodes, A_NAME))).containsExactlyInAnyOrder( assertThatMapOf(normalRelationChildren(findByName(nodes, A_NAME))).containsExactlyInAnyOrder(
tuple("BiC2", C_NAME), tuple("BiC3", C_NAME)); tuple("BiC2", C_NAME), tuple("BiC3", C_NAME));
...@@ -352,7 +358,8 @@ public class TestExcluded { ...@@ -352,7 +358,8 @@ public class TestExcluded {
public void testRelationsExcludeRegex1() throws TransformationException { public void testRelationsExcludeRegex1() throws TransformationException {
Root root = setupAllRelations(); 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 // A
assertThat(normalRelationChildren(findByName(nodes, A_NAME))).isEmpty(); assertThat(normalRelationChildren(findByName(nodes, A_NAME))).isEmpty();
// B // B
...@@ -369,7 +376,8 @@ public class TestExcluded { ...@@ -369,7 +376,8 @@ public class TestExcluded {
public void testRelationsExcludeRegex2() throws TransformationException { public void testRelationsExcludeRegex2() throws TransformationException {
Root root = setupAllRelations(); 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 // A
assertThatMapOf(normalRelationChildren(findByName(nodes, A_NAME))).containsExactlyInAnyOrder( assertThatMapOf(normalRelationChildren(findByName(nodes, A_NAME))).containsExactlyInAnyOrder(
tuple("BiC1", C_NAME), tuple("BiC2", C_NAME), tuple("BiC3", C_NAME)); tuple("BiC1", C_NAME), tuple("BiC2", C_NAME), tuple("BiC3", C_NAME));
......
...@@ -26,7 +26,8 @@ public class TestIncluded { ...@@ -26,7 +26,8 @@ public class TestIncluded {
public void testValueAttributeIncluded() throws TransformationException { public void testValueAttributeIncluded() throws TransformationException {
Root root = createRoot(null, null); 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); assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME); DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertThat(valueTokens(actualRoot)).containsOnly(entry("Name", ROOT_NAME), entry("simpleAttr", 42)); assertThat(valueTokens(actualRoot)).containsOnly(entry("Name", ROOT_NAME), entry("simpleAttr", 42));
...@@ -36,7 +37,8 @@ public class TestIncluded { ...@@ -36,7 +37,8 @@ public class TestIncluded {
public void testReferenceListAttributeIncluded() throws TransformationException { public void testReferenceListAttributeIncluded() throws TransformationException {
Root root = createRoot(null, null, createB(B1_NAME), createB(B2_NAME), createB(B3_NAME)); 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); assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME, B1_NAME, B2_NAME, B3_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME); DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
...@@ -58,7 +60,8 @@ public class TestIncluded { ...@@ -58,7 +60,8 @@ public class TestIncluded {
public void testReferenceAttributeIncluded() throws TransformationException { public void testReferenceAttributeIncluded() throws TransformationException {
Root root = createRoot(createA(A_NAME), null); 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); assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME, A_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME); DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertThatMapOf(referenceTokens(actualRoot)).containsOnly(tuple("referenceAttr", A_NAME)); assertThatMapOf(referenceTokens(actualRoot)).containsOnly(tuple("referenceAttr", A_NAME));
...@@ -78,7 +81,8 @@ public class TestIncluded { ...@@ -78,7 +81,8 @@ public class TestIncluded {
public void testNormalNTAIncluded() throws TransformationException { public void testNormalNTAIncluded() throws TransformationException {
Root root = createRoot(null, createC(C_NAME)); 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); assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME, C_NAME, "Calculated-" + C_NAME);
DumpNode actualC = TestUtils.findByName(nodes, C_NAME); DumpNode actualC = TestUtils.findByName(nodes, C_NAME);
assertThatMapOf(normalChildren(actualC)).containsOnly(tuple("Calculated", "Calculated-" + C_NAME)); assertThatMapOf(normalChildren(actualC)).containsOnly(tuple("Calculated", "Calculated-" + C_NAME));
...@@ -99,7 +103,8 @@ public class TestIncluded { ...@@ -99,7 +103,8 @@ public class TestIncluded {
public void testListNTAIncluded() throws TransformationException { public void testListNTAIncluded() throws TransformationException {
Root root = createRoot(null, createC(C_NAME)); 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); assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactly(ROOT_NAME, C_NAME, "AlsoCalculated-" + C_NAME);
DumpNode actualC = TestUtils.findByName(nodes, C_NAME); DumpNode actualC = TestUtils.findByName(nodes, C_NAME);
assertThatMapOf(listChildren(actualC), "AlsoCalculated").containsExactly("AlsoCalculated-" + C_NAME); assertThatMapOf(listChildren(actualC), "AlsoCalculated").containsExactly("AlsoCalculated-" + C_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.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) {
assertEmpty(findByName(nodes, name).getDumpChildNode(0));
}
}
@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);
assertEmpty(findByName(nodes, T1_NAME).getDumpChildNode(0));
assertThatMapOf(listChildren(TestUtils.findByName(nodes, T2_NAME)), "Bee").containsOnly(
T2_NAME + B_NAME);
assertEmpty(TestUtils.findByName(nodes, T3_NAME).getDumpChildNode(0));
}
@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);
assertEmpty(findByName(nodes, T3_NAME).getDumpChildNode(0));
}
@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));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment