diff --git a/dumpAst/src/main/jastadd/DumpAst.relast b/dumpAst/src/main/jastadd/DumpAst.relast index 37016052d963150e99d2c96d89c32fd2dc79876a..779452c6cedcfa553835a1f74b0eef5e306faef0 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 44f62835e1c79d0a58a919a979928a9c3fdb782e..022b5226b160f434dfce25199a0c0e9fcad502e9 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 78356e35c4b0fc9aa6246fe7be3d24de2b44eb85..c7afbafc09dfbbf33ecd095627076cd005c72a10 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 0000000000000000000000000000000000000000..7609b2344767a4c3fd8857201dac2c4d1dff200c --- /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 0000000000000000000000000000000000000000..52ffc696ca865fb537d26c180f9f9f0413a2c6ed --- /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 0000000000000000000000000000000000000000..4cedce8cfa75749d2fb90adcb0ef5766e36e0ca1 --- /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 0000000000000000000000000000000000000000..7b66cc96e3e0af88dd7c124928fca2ae86fa5e53 --- /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 0000000000000000000000000000000000000000..1b51ef9f3265dfff1dc9398f886649f5a0993398 --- /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 631fcc974ebb903bd09ad6b13cd6dd5fbd875f3d..4199c73d5d37f24eae0180262f0f7910a0996148 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,3 +4,5 @@ include 'relast.preprocessor' include 'dumpAst' include 'dumpAstWithPlantuml' include 'testDumper' +include 'featureTest' +