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

working on better visualization

- use blue color for computed relations (NTA and reference attributes)
- use diamonds for null nodes
- add featureTest module for testing
parent 8e910ed0
No related branches found
No related tags found
1 merge request!9working on better visualization
...@@ -12,7 +12,7 @@ PrintConfig ::= <Scale:double> <Version> <OrderChildren:boolean> Header* ; ...@@ -12,7 +12,7 @@ PrintConfig ::= <Scale:double> <Version> <OrderChildren:boolean> Header* ;
Header ::= <Value> ; Header ::= <Value> ;
DumpNode ::= DumpChildNode* DumpToken* DumpRelation* DumpNode ::= DumpChildNode* DumpToken* DumpRelation*
<Name> <Label> <BackgroundColor> <TextColor> <Object:Object> <Invisible:boolean> <Name> <Label> <BackgroundColor> <TextColor> <Object:Object> <Invisible:boolean> <Computed:boolean>
/InvisiblePath/ ; /InvisiblePath/ ;
InnerDumpNode ; InnerDumpNode ;
rel InnerDumpNode.DumpNode <-> DumpNode.ContainerOfInner ; rel InnerDumpNode.DumpNode <-> DumpNode.ContainerOfInner ;
......
...@@ -509,11 +509,16 @@ aspect GenerationBackend { ...@@ -509,11 +509,16 @@ aspect GenerationBackend {
} }
} }
// --- isNull ---
syn boolean DumpNode.isNull() {
return getObject() == null;
}
// --- isAstNode --- // --- isAstNode ---
syn boolean DumpNode.isAstNode() { syn boolean DumpNode.isAstNode() {
if (getObject() == null) { if (getObject() == null) {
// this is only possible for normal child nodes, and they are ast nodes // todo: check if false works
return true; return false;
} }
Class<?> clazz = getObject().getClass(); Class<?> clazz = getObject().getClass();
for (java.lang.reflect.Method method : clazz.getMethods()) { for (java.lang.reflect.Method method : clazz.getMethods()) {
......
...@@ -7,8 +7,11 @@ scale {{{Scale}}} ...@@ -7,8 +7,11 @@ scale {{{Scale}}}
{{/PrintConfig}} {{/PrintConfig}}
{{#DumpNodes}} {{#DumpNodes}}
{{#isAstNode}}
{{^Invisible}} {{^Invisible}}
{{#isNull}}
diamond {{{name}}}
{{/isNull}}
{{#isAstNode}}
object "{{{labelAndTextColor}}}" as {{{name}}} {{#backgroundColor}}#{{{backgroundColor}}}{{/backgroundColor}} { object "{{{labelAndTextColor}}}" as {{{name}}} {{#backgroundColor}}#{{{backgroundColor}}}{{/backgroundColor}} {
{{#DumpTokens}} {{#DumpTokens}}
{{#isDumpValueToken}} {{#isDumpValueToken}}
...@@ -16,15 +19,15 @@ object "{{{labelAndTextColor}}}" as {{{name}}} {{#backgroundColor}}#{{{backgroun ...@@ -16,15 +19,15 @@ object "{{{labelAndTextColor}}}" as {{{name}}} {{#backgroundColor}}#{{{backgroun
{{/isDumpValueToken}} {{/isDumpValueToken}}
{{/DumpTokens}} {{/DumpTokens}}
} }
{{/Invisible}}
{{/isAstNode}} {{/isAstNode}}
{{/Invisible}}
{{/DumpNodes}} {{/DumpNodes}}
{{#DumpNodes}} {{#DumpNodes}}
{{#DumpTokens}} {{#DumpTokens}}
{{^Invisible}} {{^Invisible}}
{{^isDumpValueToken}} {{^isDumpValueToken}}
{{{outerNodeName}}} ..> {{{innerNodeName}}} : {{{label}}} {{{outerNodeName}}} .{{#Computed}}[#blue]{{/Computed}}.> {{{innerNodeName}}} : {{{label}}}
{{/isDumpValueToken}} {{/isDumpValueToken}}
{{/Invisible}} {{/Invisible}}
{{/DumpTokens}} {{/DumpTokens}}
...@@ -32,13 +35,13 @@ object "{{{labelAndTextColor}}}" as {{{name}}} {{#backgroundColor}}#{{{backgroun ...@@ -32,13 +35,13 @@ object "{{{labelAndTextColor}}}" as {{{name}}} {{#backgroundColor}}#{{{backgroun
{{#isList}} {{#isList}}
{{#InnerDumpNodes}} {{#InnerDumpNodes}}
{{#bothVisible}} {{#bothVisible}}
{{{outerNodeName}}} *-- {{{innerNodeName}}} : {{{label}}} {{{outerNodeName}}} *-{{#Computed}}[#blue]{{/Computed}}- {{{innerNodeName}}} : {{{label}}}
{{/bothVisible}} {{/bothVisible}}
{{/InnerDumpNodes}} {{/InnerDumpNodes}}
{{/isList}} {{/isList}}
{{^isList}} {{^isList}}
{{#bothVisible}} {{#bothVisible}}
{{{outerNodeName}}} *-- {{{innerNodeName}}} : {{{label}}} {{{outerNodeName}}} *-{{#Computed}}[#blue]{{/Computed}}- {{{innerNodeName}}} : {{{label}}}
{{/bothVisible}} {{/bothVisible}}
{{/isList}} {{/isList}}
{{/DumpChildNodes}} {{/DumpChildNodes}}
......
build
src/gen-res/
src/gen/
out/
*.class
/featureTest.png
/featureTest.yml
buildscript {
repositories.mavenCentral()
dependencies {
classpath group: 'org.jastadd', name: 'jastaddgradle', version: '1.13.3'
}
}
plugins {
id 'relast2uml.java-jastadd-conventions'
id 'relast2uml.java-application-conventions'
}
apply plugin: 'jastadd'
repositories {
mavenCentral()
}
mainClassName = 'de.tudresden.inf.st.jastadd.featureTest.FeatureTestMain'
dependencies {
implementation project(":dumpAstWithPlantuml")
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}
test {
useJUnitPlatform()
}
File testingGrammar = file('./src/main/jastadd/featureTest.relast')
task relast(type: JavaExec) {
group = 'Build'
main = "-jar"
doFirst {
delete "src/gen/jastadd/*.ast"
delete "src/gen/jastadd/featureTest.jadd"
delete "src/gen/jastadd/featureTestRefResolver.jadd"
delete "src/gen/jastadd/featureTestResolverStubs.jrag"
mkdir "src/gen/jastadd/"
}
args = [
"../libs/relast.jar",
testingGrammar,
// "./src/main/jastadd/MustacheNodes.relast",
"--listClass=java.util.ArrayList",
"--jastAddList=JastAddList",
"--useJastAddNames",
"--file",
"--resolverHelper",
"--grammarName=./src/gen/jastadd/featureTest"
]
inputs.files(file("../libs/relast.jar"),
testingGrammar)
outputs.files(file("./src/gen/jastadd/featureTest.ast"),
file("./src/gen/jastadd/featureTest.jadd"),
file("./src/gen/jastadd/featureTestRefResolver.jadd"),
file('./src/gen/jastadd/featureTestResolverStubs.jrag'))
}
jastadd {
configureModuleBuild()
modules {
//noinspection GroovyAssignabilityCheck
module("featureTest") {
jastadd {
basedir ".."
include "featureTest/src/main/jastadd/**/*.ast"
include "featureTest/src/main/jastadd/**/*.jadd"
include "featureTest/src/main/jastadd/**/*.jrag"
include "featureTest/src/gen/jastadd/**/*.ast"
include "featureTest/src/gen/jastadd/**/*.jadd"
include "featureTest/src/gen/jastadd/**/*.jrag"
}
}
}
cleanGen.doFirst {
delete "src/gen/java/org"
delete "src/gen-res/BuildInfo.properties"
}
module = "featureTest"
astPackage = 'org.jastadd.featureTest.ast'
genDir = 'src/gen/java'
buildInfoDir = 'src/gen-res'
jastaddOptions = ["--lineColumnNumbers", "--List=JastAddList", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"]
}
generateAst.dependsOn relast
aspect GrammarGlobal {
syn A C.getCalculated() {
A result = new A();
result.setName("Calculated-" + getName());
return result;
}
syn JastAddList<B> C.getAlsoCalculatedList() {
JastAddList<B> result = new JastAddList<>();
B inner = new B();
inner.setName("AlsoCalculated-" + getName());
result.add(inner);
return result;
}
syn nta A C.getCalculatedNewSyntax() {
A result = new A();
result.setName("Calculated-" + getName());
return result;
}
syn nta JastAddList<B> C.getAlsoCalculatedListNewSyntax() {
JastAddList<B> result = new JastAddList<>();
B inner = new B();
inner.setName("AlsoCalculated-" + getName());
result.add(inner);
return result;
}
syn int Root.simpleAttr() = 42;
syn A Root.referenceAttr() = getA();
syn boolean ASTNode.isA() = false;
eq A.isA() = true;
}
aspect GrammarTypeLevel {
syn int AbstractT.simpleAttr() = 43;
syn nta A AbstractT.getCalculated() {
A result = new A();
result.setName("Calculated-" + getName());
return result;
}
}
// testcases with global inclusion/exclusion
Nameable ::= <Name> ;
Root : Nameable ::= A B* [C];
A : Nameable ::= B MyC:C D;
B : Nameable ::= <OtherValue> ;
C : Nameable ::= [A] <Unwanted:int> <RawReference:A> /Calculated:A/ /AlsoCalculated:B*/ ;
SubC : C ::= <RawReference:A> <Unwanted:int> [A] /Calculated:A/ /AlsoCalculated:B*/ ;
D;
rel B.oneA -> A ;
rel B.maybeC? -> C ;
rel B.manyA* -> A ;
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 ;
package de.tudresden.inf.st.jastadd.featureTest;
import de.tudresden.inf.st.jastadd.dumpAst.ast.Dumper;
import de.tudresden.inf.st.jastadd.dumpAst.ast.SkinParamBooleanSetting;
import de.tudresden.inf.st.jastadd.dumpAst.ast.SkinParamStringSetting;
import org.jastadd.featureTest.ast.*;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Main class of feature test.
*
* @author rschoene - Initial contribution
*/
public class FeatureTestMain {
public static void main(String[] args) throws IOException {
Root root = new Root();
root.setName("Root1");
A a = new A();
a.setName("A2");
B b1 = new B();
b1.setName("B3");
C c = new C();
c.setName("C4");
c.setRawReference(a);
b1.setOneA(a);
B b2 = new B();
b2.setName("B5");
C myC = new C();
myC.setName("C6");
a.setMyC(myC);
root.setA(a);
root.addB(b1);
root.addB(b2);
root.setC(c);
Path pathToYaml = Paths.get("featureTest.yml");
Path pathToPng = Paths.get("featureTest.png");
// Dumper.read(null).dumpAsPNG(pathToPng);
Dumper
// .read(null)
.read(root)
// .customPreamble("hide empty members")
.skinParam(SkinParamBooleanSetting.Shadowing, false)
.includeAttributes("referenceAttr")
.includeNonterminalAttributes("Calculated")
.includeNonterminalAttributes("AlsoCalculatedListNewSyntax")
.dumpAsYaml(pathToYaml, true)
.dumpAsPNG(pathToPng);
}
}
...@@ -4,3 +4,5 @@ include 'relast.preprocessor' ...@@ -4,3 +4,5 @@ include 'relast.preprocessor'
include 'dumpAst' include 'dumpAst'
include 'dumpAstWithPlantuml' include 'dumpAstWithPlantuml'
include 'testDumper' include 'testDumper'
include 'featureTest'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment