From f906bed00695d624c8406a3b9f7bda40fa547011 Mon Sep 17 00:00:00 2001
From: rschoene <rene.schoene@tu-dresden.de>
Date: Wed, 2 Mar 2022 10:47:17 +0100
Subject: [PATCH] working on better visualization

- use blue color for computed relations (NTA and reference attributes)
- use diamonds for null nodes
- add featureTest module for testing
---
 dumpAst/src/main/jastadd/DumpAst.relast       |  2 +-
 .../src/main/jastadd/GenerationBackend.jadd   |  9 +-
 dumpAst/src/main/resources/dumpAst.mustache   | 17 ++--
 featureTest/.gitignore                        |  7 ++
 featureTest/build.gradle                      | 96 +++++++++++++++++++
 featureTest/src/main/jastadd/featureTest.jrag | 44 +++++++++
 .../src/main/jastadd/featureTest.relast       | 26 +++++
 .../jastadd/featureTest/FeatureTestMain.java  | 54 +++++++++++
 settings.gradle                               |  2 +
 9 files changed, 247 insertions(+), 10 deletions(-)
 create mode 100644 featureTest/.gitignore
 create mode 100644 featureTest/build.gradle
 create mode 100644 featureTest/src/main/jastadd/featureTest.jrag
 create mode 100644 featureTest/src/main/jastadd/featureTest.relast
 create mode 100644 featureTest/src/main/java/de/tudresden/inf/st/jastadd/featureTest/FeatureTestMain.java

diff --git a/dumpAst/src/main/jastadd/DumpAst.relast b/dumpAst/src/main/jastadd/DumpAst.relast
index 3701605..779452c 100644
--- a/dumpAst/src/main/jastadd/DumpAst.relast
+++ b/dumpAst/src/main/jastadd/DumpAst.relast
@@ -12,7 +12,7 @@ PrintConfig ::= <Scale:double> <Version> <OrderChildren:boolean> Header* ;
 Header ::= <Value> ;
 
 DumpNode ::=  DumpChildNode* DumpToken* DumpRelation*
- <Name> <Label> <BackgroundColor> <TextColor> <Object:Object> <Invisible:boolean>
+ <Name> <Label> <BackgroundColor> <TextColor> <Object:Object> <Invisible:boolean> <Computed:boolean>
  /InvisiblePath/ ;
 InnerDumpNode ;
 rel InnerDumpNode.DumpNode <-> DumpNode.ContainerOfInner ;
diff --git a/dumpAst/src/main/jastadd/GenerationBackend.jadd b/dumpAst/src/main/jastadd/GenerationBackend.jadd
index 44f6283..022b522 100644
--- a/dumpAst/src/main/jastadd/GenerationBackend.jadd
+++ b/dumpAst/src/main/jastadd/GenerationBackend.jadd
@@ -509,11 +509,16 @@ aspect GenerationBackend {
     }
   }
 
+  // --- isNull ---
+  syn boolean DumpNode.isNull() {
+    return getObject() == null;
+  }
+
   // --- isAstNode ---
   syn boolean DumpNode.isAstNode() {
     if (getObject() == null) {
-      // this is only possible for normal child nodes, and they are ast nodes
-      return true;
+      // todo: check if false works
+      return false;
     }
     Class<?> clazz = getObject().getClass();
     for (java.lang.reflect.Method method : clazz.getMethods()) {
diff --git a/dumpAst/src/main/resources/dumpAst.mustache b/dumpAst/src/main/resources/dumpAst.mustache
index 78356e3..c7afbaf 100644
--- a/dumpAst/src/main/resources/dumpAst.mustache
+++ b/dumpAst/src/main/resources/dumpAst.mustache
@@ -7,8 +7,11 @@ scale {{{Scale}}}
 {{/PrintConfig}}
 
 {{#DumpNodes}}
-  {{#isAstNode}}
-    {{^Invisible}}
+  {{^Invisible}}
+    {{#isNull}}
+diamond {{{name}}}
+    {{/isNull}}
+    {{#isAstNode}}
 object "{{{labelAndTextColor}}}" as {{{name}}} {{#backgroundColor}}#{{{backgroundColor}}}{{/backgroundColor}} {
       {{#DumpTokens}}
         {{#isDumpValueToken}}
@@ -16,15 +19,15 @@ object "{{{labelAndTextColor}}}" as {{{name}}} {{#backgroundColor}}#{{{backgroun
         {{/isDumpValueToken}}
       {{/DumpTokens}}
 }
-    {{/Invisible}}
-  {{/isAstNode}}
+    {{/isAstNode}}
+  {{/Invisible}}
 {{/DumpNodes}}
 
 {{#DumpNodes}}
   {{#DumpTokens}}
     {{^Invisible}}
       {{^isDumpValueToken}}
-{{{outerNodeName}}} ..> {{{innerNodeName}}} : {{{label}}}
+{{{outerNodeName}}} .{{#Computed}}[#blue]{{/Computed}}.> {{{innerNodeName}}} : {{{label}}}
       {{/isDumpValueToken}}
     {{/Invisible}}
   {{/DumpTokens}}
@@ -32,13 +35,13 @@ object "{{{labelAndTextColor}}}" as {{{name}}} {{#backgroundColor}}#{{{backgroun
     {{#isList}}
       {{#InnerDumpNodes}}
         {{#bothVisible}}
-{{{outerNodeName}}} *-- {{{innerNodeName}}} : {{{label}}}
+{{{outerNodeName}}} *-{{#Computed}}[#blue]{{/Computed}}- {{{innerNodeName}}} : {{{label}}}
         {{/bothVisible}}
       {{/InnerDumpNodes}}
     {{/isList}}
     {{^isList}}
       {{#bothVisible}}
-{{{outerNodeName}}} *-- {{{innerNodeName}}} : {{{label}}}
+{{{outerNodeName}}} *-{{#Computed}}[#blue]{{/Computed}}- {{{innerNodeName}}} : {{{label}}}
       {{/bothVisible}}
     {{/isList}}
   {{/DumpChildNodes}}
diff --git a/featureTest/.gitignore b/featureTest/.gitignore
new file mode 100644
index 0000000..7609b23
--- /dev/null
+++ b/featureTest/.gitignore
@@ -0,0 +1,7 @@
+build
+src/gen-res/
+src/gen/
+out/
+*.class
+/featureTest.png
+/featureTest.yml
diff --git a/featureTest/build.gradle b/featureTest/build.gradle
new file mode 100644
index 0000000..52ffc69
--- /dev/null
+++ b/featureTest/build.gradle
@@ -0,0 +1,96 @@
+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
diff --git a/featureTest/src/main/jastadd/featureTest.jrag b/featureTest/src/main/jastadd/featureTest.jrag
new file mode 100644
index 0000000..4cedce8
--- /dev/null
+++ b/featureTest/src/main/jastadd/featureTest.jrag
@@ -0,0 +1,44 @@
+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;
+  }
+}
diff --git a/featureTest/src/main/jastadd/featureTest.relast b/featureTest/src/main/jastadd/featureTest.relast
new file mode 100644
index 0000000..7b66cc9
--- /dev/null
+++ b/featureTest/src/main/jastadd/featureTest.relast
@@ -0,0 +1,26 @@
+// 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 ;
diff --git a/featureTest/src/main/java/de/tudresden/inf/st/jastadd/featureTest/FeatureTestMain.java b/featureTest/src/main/java/de/tudresden/inf/st/jastadd/featureTest/FeatureTestMain.java
new file mode 100644
index 0000000..1b51ef9
--- /dev/null
+++ b/featureTest/src/main/java/de/tudresden/inf/st/jastadd/featureTest/FeatureTestMain.java
@@ -0,0 +1,54 @@
+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);
+  }
+}
diff --git a/settings.gradle b/settings.gradle
index 631fcc9..4199c73 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -4,3 +4,5 @@ include 'relast.preprocessor'
 include 'dumpAst'
 include 'dumpAstWithPlantuml'
 include 'testDumper'
+include 'featureTest'
+
-- 
GitLab