From b1715804ee62e146519c83962efa922cd38ae3dd Mon Sep 17 00:00:00 2001 From: rschoene <rene.schoene@tu-dresden.de> Date: Tue, 6 Sep 2022 14:11:31 +0200 Subject: [PATCH] 1.2.2 - always use refined token method, especially when method from parent also exists - also restructure debug output --- dumpAst/src/main/jastadd/ClassAnalysis.jrag | 29 +++++++++++++++ dumpAst/src/main/jastadd/DumpAst.relast | 3 +- dumpAst/src/main/jastadd/Printing.jrag | 8 ++-- .../main/resources/dumpAstVersion.properties | 4 +- featureTest/build.gradle | 2 + featureTest/src/main/jastadd/featureTest.jrag | 21 +++++++++++ .../src/main/jastadd/featureTest.relast | 2 +- .../jastadd/featureTest/FeatureTestMain.java | 37 +++++++++---------- 8 files changed, 79 insertions(+), 27 deletions(-) diff --git a/dumpAst/src/main/jastadd/ClassAnalysis.jrag b/dumpAst/src/main/jastadd/ClassAnalysis.jrag index 80176f2..fdd6052 100644 --- a/dumpAst/src/main/jastadd/ClassAnalysis.jrag +++ b/dumpAst/src/main/jastadd/ClassAnalysis.jrag @@ -75,6 +75,18 @@ aspect ClassAnalysis { IntrinsicTokenMethod tokenMethod = new IntrinsicTokenMethod(); tokenMethod.setMethod(method); tokenMethod.setName(tokenName); + TokenMethod previousTokenMethodWithSameName = result.getTokenMethodWithName(tokenName); + if (method.getName().startsWith("refined__")) { + tokenMethod.setRefined(true); + // check for previous non-refined method with same name + if (previousTokenMethodWithSameName != null) { + // replace previous method instead of adding + result.setOtherMethod(tokenMethod, previousTokenMethodWithSameName.myIndex()); + continue; + } + } else if (previousTokenMethodWithSameName != null && previousTokenMethodWithSameName.isIntrinsicTokenMethod() && previousTokenMethodWithSameName.asIntrinsicTokenMethod().getRefined()) { + continue; + } result.addOtherMethod(tokenMethod); break; case "Attribute": @@ -140,6 +152,23 @@ aspect ClassAnalysis { return result; } + TokenMethod ClassAnalysisResult.getTokenMethodWithName(String tokenName) { + // this can not be an attribute, since ClassAnalysisResult changes, and we do not use incremental eval + for (AnalysedMethod otherMethod : getOtherMethodList()) { + if (otherMethod.isTokenMethod()) { + TokenMethod tokenMethod = otherMethod.asTokenMethod(); + if (tokenMethod.getName().equals(tokenName)) { + return tokenMethod; + } + } + } + return null; + } + + inh int AnalysedMethod.myIndex(); + eq ClassAnalysisResult.getContainmentMethod(int index).myIndex() = index; + eq ClassAnalysisResult.getOtherMethod(int index).myIndex() = index; + syn java.util.List<String> DumpAst.targetOrder(Class<?> clazz) { for (java.lang.reflect.Constructor<?> method : clazz.getConstructors()) { for (java.lang.annotation.Annotation annotation : method.getAnnotations()) { diff --git a/dumpAst/src/main/jastadd/DumpAst.relast b/dumpAst/src/main/jastadd/DumpAst.relast index 55b270d..fcfd923 100644 --- a/dumpAst/src/main/jastadd/DumpAst.relast +++ b/dumpAst/src/main/jastadd/DumpAst.relast @@ -47,8 +47,9 @@ NTAListChildMethod : ListChildMethod ; SingleRelationMethod : AnalysedMethod ; ListRelationMethod : AnalysedMethod ; +// TODO can the refine bug also happen for refined attributes? abstract TokenMethod : AnalysedMethod ; -IntrinsicTokenMethod : TokenMethod ; +IntrinsicTokenMethod : TokenMethod ::= <Refined:boolean> ; AttributeMethod : TokenMethod ; BuildConfig ::= StyleInformation diff --git a/dumpAst/src/main/jastadd/Printing.jrag b/dumpAst/src/main/jastadd/Printing.jrag index 6ae0af3..f42e6fa 100644 --- a/dumpAst/src/main/jastadd/Printing.jrag +++ b/dumpAst/src/main/jastadd/Printing.jrag @@ -43,16 +43,16 @@ aspect Printing { aspect Debugging { syn String ClassAnalysisResult.prettyPrint() { StringBuilder sb = new StringBuilder(); - sb.append("ContainmentMethods:"); + sb.append("- ContainmentMethods: "); for (AnalysedMethod method : getContainmentMethodList()) { - sb.append(method.prettyPrint()).append(","); + sb.append("\n - ").append(method.prettyPrint()); } if (getNumContainmentMethod() == 0) { sb.append("none. "); } - sb.append("other methods:"); + sb.append("\n- Other methods: "); for (AnalysedMethod method : getOtherMethodList()) { - sb.append(method.prettyPrint()).append(","); + sb.append("\n - ").append(method.prettyPrint()); } if (getNumOtherMethod() == 0) { sb.append("none."); diff --git a/dumpAst/src/main/resources/dumpAstVersion.properties b/dumpAst/src/main/resources/dumpAstVersion.properties index 7968f51..dd0adf1 100644 --- a/dumpAst/src/main/resources/dumpAstVersion.properties +++ b/dumpAst/src/main/resources/dumpAstVersion.properties @@ -1,2 +1,2 @@ -#Mon Jul 25 18:03:32 CEST 2022 -version=1.2.1 +#Tue Sep 06 14:11:59 CEST 2022 +version=1.2.2 diff --git a/featureTest/build.gradle b/featureTest/build.gradle index 21ca23a..a5568a3 100644 --- a/featureTest/build.gradle +++ b/featureTest/build.gradle @@ -34,6 +34,8 @@ dependencies { implementation project(":dumpAst") jastadd2 group: 'org.jastadd', name: 'jastadd2', version: '2.3.5-dresden' relast group: 'org.jastadd', name: 'relast', version: "${relast_version}" + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.13.3' + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.13.3' implementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11' } diff --git a/featureTest/src/main/jastadd/featureTest.jrag b/featureTest/src/main/jastadd/featureTest.jrag index 9a158c1..a12910b 100644 --- a/featureTest/src/main/jastadd/featureTest.jrag +++ b/featureTest/src/main/jastadd/featureTest.jrag @@ -1,4 +1,8 @@ aspect GrammarGlobal { + + refine @com.fasterxml.jackson.annotation.JsonGetter("id") public String Nameable.getName() { + return refined(); + } syn A C.getCalculated() { A result = new A(); result.setName("Calculated-" + getName()); @@ -34,6 +38,8 @@ aspect GrammarGlobal { syn int Root.simpleAttr() = 42; syn A Root.referenceAttr() = getA(); + syn String Nameable.fancyName() = getName() + ", but fancy!"; + syn boolean ASTNode.isA() = false; eq A.isA() = true; @@ -41,6 +47,17 @@ aspect GrammarGlobal { B contributes this to Root.collectBs(); C contributes nta getAlsoCalculatedList() to Root.collectBs(); C contributes nta getAlsoCalculatedListNewSyntax() to Root.collectBs(); + + inh Root A.root(); + eq Root.getChild().root() = this; + + syn nta B A.AAA() { + B result = new B(); + result.setMaybeC(root().getC()); + return result; + } + + public static int ASTNode.counter; } aspect GrammarTypeLevel { @@ -51,3 +68,7 @@ aspect GrammarTypeLevel { return result; } } + +aspect Refining { + refine GrammarGlobal eq Nameable.fancyName() = refined() + " and more!"; +} diff --git a/featureTest/src/main/jastadd/featureTest.relast b/featureTest/src/main/jastadd/featureTest.relast index fa1c50e..7e108fe 100644 --- a/featureTest/src/main/jastadd/featureTest.relast +++ b/featureTest/src/main/jastadd/featureTest.relast @@ -1,5 +1,5 @@ // testcases with global inclusion/exclusion -Nameable ::= <Name> ; +abstract Nameable ::= <Name> ; Root : Nameable ::= A B* [C]; A : Nameable ::= B [MyC:C] [D]; B : Nameable ::= <OtherValue> ; 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 index cd6436b..bc1d372 100644 --- 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 @@ -2,10 +2,7 @@ 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 org.jastadd.featureTest.ast.A; -import org.jastadd.featureTest.ast.B; -import org.jastadd.featureTest.ast.C; -import org.jastadd.featureTest.ast.Root; +import org.jastadd.featureTest.ast.*; import java.io.IOException; import java.nio.file.Path; @@ -23,29 +20,29 @@ public class FeatureTestMain { root.setName("Root1"); A a = new A().setName("A2"); a.setB(new B().setName("B2.1")); - a.setMyC(new C().setName("C2.1")); - B b1 = new B().setName("B3"); - C c = new C().setName("C4"); - c.setA(new A().setName("A4.1").setB(new B().setName("B4.1.1"))); - c.setRawReference(a); - b1.setOneA(a); - B b2 = new B().setName("B5"); - C myC = new C().setName("C6"); - c.setA(new A().setName("A6.1").setB(new B().setName("B6.1.1"))); - a.setMyC(myC); +// a.setMyC(new C().setName("C2.1")); +// B b1 = new B().setName("B3").setOtherValue("some long text"); +// C c = new C().setName("C4"); +// c.setA(new A().setName("A4.1").setB(new B().setName("B4.1.1"))); +// c.setRawReference(a); +// b1.setOneA(a); +// B b2 = new B().setName("B5").setOtherValue("#ff00ff"); +// C myC = new C().setName("C6"); +// c.setA(new A().setName("A6.1").setB(new B().setName("B6.1.1"))); +// a.setMyC(myC); root.setA(a); - root.addB(b1); - root.addB(b2); - root.setC(c); +// root.addB(b1); +// root.addB(b2); +// root.setC(c); Path pathToYaml = Paths.get("featureTest.yml"); Path pathToPng = Paths.get("featureTest.png"); Path pathToSvg = Paths.get("featureTest.svg"); - Path pathToPdf = Paths.get("featureTest.pdf"); Dumper // .read(null) .read(root) // .customPreamble("hide empty members") + .enableDebug() .customPreamble("title My fancy title") .includeChildWhen((parentNode, childNode, contextName) -> { if (parentNode instanceof A && ((A) parentNode).getName().equals("A2")) { @@ -61,17 +58,19 @@ public class FeatureTestMain { case "collectBs": case "Calculated": case "AlsoCalculatedListNewSyntax": + case "AAA": + case "fancyName": return true; default: return false; } }) .skinParam(SkinParamBooleanSetting.Shadowing, false) + .setNameMethod(node -> node.getClass().getSimpleName() + ASTNode.counter++) // .enableRelationWithRank() .dumpAsYaml(pathToYaml, true) .dumpAsPNG(pathToPng) .dumpAsSVG(pathToSvg) - .dumpAsPDF(pathToPdf) .dumpAsSource(Paths.get("featureTest.puml")) ; } -- GitLab