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

1.2.0

- add support for PDF (requires additional dependencies)
- avoid parametrized attributes
- avoid computing NTAs before checking whether to include them
- cleanup of DumpBuilder
parent 0e57e5ef
No related branches found
No related tags found
No related merge requests found
Pipeline #14082 passed
...@@ -164,16 +164,15 @@ aspect GenerationBackend { ...@@ -164,16 +164,15 @@ aspect GenerationBackend {
for (AnalysedMethod otherMethod : car.getOtherMethodList()) { for (AnalysedMethod otherMethod : car.getOtherMethodList()) {
if (otherMethod.isSingleChildMethod()) { if (otherMethod.isSingleChildMethod()) {
// -- singleChild -- // -- singleChild --
Object target = otherMethod.getMethod().invoke(obj);
String childName = otherMethod.getName(); String childName = otherMethod.getName();
boolean computed = otherMethod.asSingleChildMethod().isNTASingleChildMethod(); boolean computed = otherMethod.asSingleChildMethod().isNTASingleChildMethod();
boolean shouldInclude = computed ? boolean shouldInclude = computed ?
getBuildConfig().getIncludeAttributeMethod().shouldInclude(obj, childName, true, () -> catchedInvoke(otherMethod.getMethod(), obj)) : getBuildConfig().getIncludeAttributeMethod().shouldInclude(obj, childName, true, () -> catchedInvoke(otherMethod.getMethod(), obj)) :
getBuildConfig().getIncludeChildMethod().shouldInclude(obj, target, childName); getBuildConfig().getIncludeChildMethod().shouldInclude(obj, otherMethod.getMethod().invoke(obj), childName);
if (!shouldInclude) { if (!shouldInclude) {
continue; continue;
} }
DumpNode targetNode = transform(tti, target, options.asNormal(false).computed(computed).allowNullObjectsOnce()); DumpNode targetNode = transform(tti, otherMethod.getMethod().invoke(obj), options.asNormal(false).computed(computed).allowNullObjectsOnce());
if (targetNode != null) { if (targetNode != null) {
DumpNormalChildNode normalChild = new DumpNormalChildNode(); DumpNormalChildNode normalChild = new DumpNormalChildNode();
normalChild.setName(childName); normalChild.setName(childName);
...@@ -183,19 +182,17 @@ aspect GenerationBackend { ...@@ -183,19 +182,17 @@ aspect GenerationBackend {
} }
} else if (otherMethod.isListChildMethod()) { } else if (otherMethod.isListChildMethod()) {
// -- listChild -- // -- listChild --
// it is always a NTAListChildMethod
String childName = otherMethod.getName();
if (!getBuildConfig().getIncludeAttributeMethod().shouldInclude(obj, childName, true, () -> catchedInvoke(otherMethod.getMethod(), obj))) {
continue;
}
Iterable<?> targetList = (Iterable<?>) otherMethod.getMethod().invoke(obj); Iterable<?> targetList = (Iterable<?>) otherMethod.getMethod().invoke(obj);
DumpListChildNode listChild = new DumpListChildNode(); DumpListChildNode listChild = new DumpListChildNode();
boolean computed = otherMethod.asListChildMethod().isNTAListChildMethod(); boolean computed = otherMethod.asListChildMethod().isNTAListChildMethod();
listChild.setComputed(computed); listChild.setComputed(computed);
String childName = otherMethod.getName();
listChild.setName(childName); listChild.setName(childName);
for (Object target : targetList) { for (Object target : targetList) {
boolean shouldInclude = computed ?
getBuildConfig().getIncludeAttributeMethod().shouldInclude(obj, childName, true, () -> catchedInvoke(otherMethod.getMethod(), obj)) :
getBuildConfig().getIncludeChildMethod().shouldInclude(obj, target, childName);
if (!shouldInclude) {
continue;
}
DumpNode targetNode = transform(tti, target, options.asNormal(false).computed(computed)); DumpNode targetNode = transform(tti, target, options.asNormal(false).computed(computed));
if (target != null && targetNode != null) { if (target != null && targetNode != null) {
listChild.addInnerDumpNode(new InnerDumpNode().setDumpNode(targetNode)); listChild.addInnerDumpNode(new InnerDumpNode().setDumpNode(targetNode));
...@@ -385,6 +382,10 @@ aspect GenerationBackend { ...@@ -385,6 +382,10 @@ aspect GenerationBackend {
result.addOtherMethod(tokenMethod); result.addOtherMethod(tokenMethod);
break; break;
case "Attribute": case "Attribute":
if (method.getParameterCount() > 0) {
// ignore parametrized attributes
continue;
}
String attributeName = method.getName(); String attributeName = method.getName();
boolean isNTA = (boolean) invokeMethod("isNTA", annotation); boolean isNTA = (boolean) invokeMethod("isNTA", annotation);
if (isNTA) { if (isNTA) {
......
package de.tudresden.inf.st.jastadd.dumpAst.ast; package de.tudresden.inf.st.jastadd.dumpAst.ast;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceStringReader;
import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ResourceBundle;
import java.util.function.Consumer;
import java.util.function.Supplier;
import static de.tudresden.inf.st.jastadd.dumpAst.ast.ASTNode.matches; import static de.tudresden.inf.st.jastadd.dumpAst.ast.ASTNode.matches;
...@@ -661,11 +672,11 @@ public class DumpBuilder { ...@@ -661,11 +672,11 @@ public class DumpBuilder {
* *
* @param destination path of destination file * @param destination path of destination file
* @return this * @return this
* @throws java.io.IOException if an I/O error happend during opening or writing in that file * @throws java.io.IOException if an I/O error happened during opening or writing in that file
*/ */
public DumpBuilder dumpAsSource(java.nio.file.Path destination) throws java.io.IOException { public DumpBuilder dumpAsSource(Path destination) throws java.io.IOException {
String content = build().toPlantUml(); String content = build().toPlantUml();
try (java.io.Writer writer = java.nio.file.Files.newBufferedWriter(destination)) { try (Writer writer = Files.newBufferedWriter(destination)) {
writer.write(content); writer.write(content);
} }
return this; return this;
...@@ -677,11 +688,11 @@ public class DumpBuilder { ...@@ -677,11 +688,11 @@ public class DumpBuilder {
* @param destination path of destination file * @param destination path of destination file
* @param prependCreationComment whether to add the creation date as first line * @param prependCreationComment whether to add the creation date as first line
* @return this * @return this
* @throws java.io.IOException if an I/O error happend during opening or writing in that file * @throws java.io.IOException if an I/O error happened during opening or writing in that file
*/ */
public DumpBuilder dumpAsYaml(java.nio.file.Path destination, boolean prependCreationComment) throws java.io.IOException { public DumpBuilder dumpAsYaml(Path destination, boolean prependCreationComment) throws java.io.IOException {
String content = build().printYaml(prependCreationComment); String content = build().printYaml(prependCreationComment);
try (java.io.Writer writer = java.nio.file.Files.newBufferedWriter(destination)) { try (Writer writer = Files.newBufferedWriter(destination)) {
writer.write(content); writer.write(content);
} }
return this; return this;
...@@ -692,12 +703,10 @@ public class DumpBuilder { ...@@ -692,12 +703,10 @@ public class DumpBuilder {
* *
* @param destination path of destination file * @param destination path of destination file
* @return this * @return this
* @throws java.io.IOException if an I/O error happend during opening or writing in that file * @throws java.io.IOException if an I/O error happened during opening or writing in that file
*/ */
public DumpBuilder dumpAsPNG(java.nio.file.Path destination) throws java.io.IOException { public DumpBuilder dumpAsPNG(Path destination) throws java.io.IOException {
String content = build().toPlantUml(); dumpAs(destination, FileFormat.PNG);
net.sourceforge.plantuml.SourceStringReader reader = new net.sourceforge.plantuml.SourceStringReader(content);
reader.outputImage(java.nio.file.Files.newOutputStream(destination));
return this; return this;
} }
...@@ -706,16 +715,34 @@ public class DumpBuilder { ...@@ -706,16 +715,34 @@ public class DumpBuilder {
* *
* @param destination path of destination file * @param destination path of destination file
* @return this * @return this
* @throws java.io.IOException if an I/O error happend during opening or writing in that file * @throws java.io.IOException if an I/O error happened during opening or writing in that file
*/ */
public DumpBuilder dumpAsSVG(java.nio.file.Path destination) throws java.io.IOException { public DumpBuilder dumpAsSVG(Path destination) throws java.io.IOException {
String content = build().toPlantUml(); dumpAs(destination, FileFormat.SVG);
net.sourceforge.plantuml.SourceStringReader reader = new net.sourceforge.plantuml.SourceStringReader(content); return this;
reader.outputImage(java.nio.file.Files.newOutputStream(destination), }
new net.sourceforge.plantuml.FileFormatOption(net.sourceforge.plantuml.FileFormat.SVG));
/**
* Write out content as PDF generated by plantuml.
*
* <br>
* <b>Note:</b> This requires additional dependencies, see <a href="https://plantuml.com/pdf">https://plantuml.com/pdf</a>
*
* @param destination path of destination file
* @return this
* @throws java.io.IOException if an I/O error happened during opening or writing in that file
*/
public DumpBuilder dumpAsPDF(Path destination) throws java.io.IOException {
dumpAs(destination, FileFormat.PDF);
return this; return this;
} }
private void dumpAs(Path destination, FileFormat fileFormat) throws IOException {
String content = build().toPlantUml();
SourceStringReader reader = new SourceStringReader(content);
reader.outputImage(Files.newOutputStream(destination), new FileFormatOption(fileFormat));
}
// --- Helper methods --- // --- Helper methods ---
protected DumpAst build() { protected DumpAst build() {
...@@ -767,7 +794,7 @@ public class DumpBuilder { ...@@ -767,7 +794,7 @@ public class DumpBuilder {
return result; return result;
} }
private void updateRegexes(java.util.function.Supplier<String> getter, java.util.function.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);
} else { } else {
...@@ -780,7 +807,7 @@ public class DumpBuilder { ...@@ -780,7 +807,7 @@ public class DumpBuilder {
private String readVersion() { private String readVersion() {
try { try {
java.util.ResourceBundle resources = java.util.ResourceBundle.getBundle("dumpAstVersion"); ResourceBundle resources = ResourceBundle.getBundle("dumpAstVersion");
return resources.getString("version"); return resources.getString("version");
} catch (java.util.MissingResourceException e) { } catch (java.util.MissingResourceException e) {
return "version ?"; return "version ?";
......
#Thu Jun 23 16:13:20 CEST 2022 #Tue Jul 05 15:14:22 CEST 2022
version=1.1.0 version=1.2.0
...@@ -40,6 +40,8 @@ public class FeatureTestMain { ...@@ -40,6 +40,8 @@ public class FeatureTestMain {
Path pathToYaml = Paths.get("featureTest.yml"); Path pathToYaml = Paths.get("featureTest.yml");
Path pathToPng = Paths.get("featureTest.png"); Path pathToPng = Paths.get("featureTest.png");
Path pathToSvg = Paths.get("featureTest.svg");
Path pathToPdf = Paths.get("featureTest.pdf");
Dumper Dumper
// .read(null) // .read(null)
.read(root) .read(root)
...@@ -68,6 +70,8 @@ public class FeatureTestMain { ...@@ -68,6 +70,8 @@ public class FeatureTestMain {
// .enableRelationWithRank() // .enableRelationWithRank()
.dumpAsYaml(pathToYaml, true) .dumpAsYaml(pathToYaml, true)
.dumpAsPNG(pathToPng) .dumpAsPNG(pathToPng)
.dumpAsSVG(pathToSvg)
.dumpAsPDF(pathToPdf)
.dumpAsSource(Paths.get("featureTest.puml")) .dumpAsSource(Paths.get("featureTest.puml"))
; ;
} }
......
...@@ -19,7 +19,7 @@ Add `dumpAst` as a dependency: ...@@ -19,7 +19,7 @@ Add `dumpAst` as a dependency:
``` ```
dependencies { dependencies {
implementation group: 'de.tudresden.inf.st', name: 'dumpAst', version: '1.0.1' implementation group: 'de.tudresden.inf.st', name: 'dumpAst', version: '1.2.0'
} }
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment