From d0e9a7419ec24593b597df6fe5fe2d6e1b0abc4f Mon Sep 17 00:00:00 2001
From: rschoene <rene.schoene@tu-dresden.de>
Date: Mon, 16 May 2022 18:33:50 +0200
Subject: [PATCH] 1.0.2

- avoid duplicate token values (#14)
- add debugging information if enabled
---
 .../src/main/jastadd/GenerationBackend.jadd   | 19 ++++++----
 dumpAst/src/main/jastadd/Printing.jrag        | 28 ++++++++++++++
 .../st/jastadd/dumpAst/ast/DumpBuilder.java   |  1 +
 .../main/resources/dumpAstVersion.properties  |  4 +-
 testDumper/src/main/jastadd/testDumper.relast |  6 +++
 .../st/jastadd/testDumper/TestComplex.java    | 37 +++++++++++++++++++
 .../inf/st/jastadd/testDumper/TestSimple.java |  4 --
 7 files changed, 85 insertions(+), 14 deletions(-)
 create mode 100644 testDumper/src/test/java/de/tudresden/inf/st/jastadd/testDumper/TestComplex.java

diff --git a/dumpAst/src/main/jastadd/GenerationBackend.jadd b/dumpAst/src/main/jastadd/GenerationBackend.jadd
index be9aaff..fa8b0df 100644
--- a/dumpAst/src/main/jastadd/GenerationBackend.jadd
+++ b/dumpAst/src/main/jastadd/GenerationBackend.jadd
@@ -119,6 +119,9 @@ aspect GenerationBackend {
       return node;
     }
     final ClassAnalysisResult car = analyzeClass(obj.getClass());
+    if (getBuildConfig().getDebug()) {
+      System.out.println("for node " + obj + ", analysis was:\n" + car.prettyPrint());
+    }
     for (AnalysedMethod containmentMethod : car.getContainmentMethodList()) {
       if (containmentMethod.isSingleChildMethod()) {
         // -- singleChild --
@@ -138,10 +141,10 @@ aspect GenerationBackend {
         DumpListChildNode listChild = new DumpListChildNode();
         listChild.setComputed(false);
         String childName = containmentMethod.getName();
-        boolean shouldBeInvisisble = !isChildEnabled(objClassName, childName);
+        boolean shouldBeInvisible = !isChildEnabled(objClassName, childName);
         listChild.setName(childName);
         for (Object target : targetList) {
-          DumpNode targetNode = transform(tti, target, options.asNormal(shouldBeInvisisble));
+          DumpNode targetNode = transform(tti, target, options.asNormal(shouldBeInvisible));
           if (target != null && targetNode != null) {
             listChild.addInnerDumpNode(new InnerDumpNode().setDumpNode(targetNode));
           }
@@ -174,10 +177,10 @@ aspect GenerationBackend {
         boolean computed = otherMethod.asListChildMethod().isNTAListChildMethod();
         listChild.setComputed(computed);
         String childName = otherMethod.getName();
-        boolean shouldBeInvisisble = !isChildEnabled(objClassName, childName);
+        boolean shouldBeInvisible = !isChildEnabled(objClassName, childName);
         listChild.setName(childName);
         for (Object target : targetList) {
-          DumpNode targetNode = transform(tti, target, options.asNormal(shouldBeInvisisble).computed(computed));
+          DumpNode targetNode = transform(tti, target, options.asNormal(shouldBeInvisible).computed(computed));
           if (target != null && targetNode != null) {
             listChild.addInnerDumpNode(new InnerDumpNode().setDumpNode(targetNode));
           }
@@ -251,7 +254,7 @@ aspect GenerationBackend {
     ClassAnalysisResult result = new ClassAnalysisResult();
     String clazzName = clazz.getSimpleName();
     java.util.List<String> targetOrder = targetOrder(clazz);
-    for (java.lang.reflect.Method method : clazz.getMethods()) {
+    methodLoop: for (java.lang.reflect.Method method : clazz.getMethods()) {
       for (java.lang.annotation.Annotation annotation : method.getAnnotations()) {
         String canonicalName = annotation.annotationType().getCanonicalName();
         if (canonicalName.startsWith(astNodeAnnotationPrefix())) {
@@ -366,11 +369,11 @@ aspect GenerationBackend {
             int indexOfContextInTarget = targetOrder.indexOf(contextNameToAdd);
             if (indexOfContextInTarget == 0) {
               result.getContainmentMethodList().insertChild(containmentMethodToAdd, 0);
-              continue;
+              continue methodLoop;
             }
             if (indexOfContextInTarget == targetOrder.size() - 1) {
               result.addContainmentMethod(containmentMethodToAdd);
-              continue;
+              continue methodLoop;
             }
 
             for (int i = 0, size = result.getNumContainmentMethod(); i < size; i++) {
@@ -378,7 +381,7 @@ aspect GenerationBackend {
               int indexOfCurrentInTarget = targetOrder.indexOf(currentContextName);
               if (indexOfCurrentInTarget > indexOfContextInTarget) {
                 result.getContainmentMethodList().insertChild(containmentMethodToAdd, i);
-                break;
+                continue methodLoop;
               }
             }
             result.addContainmentMethod(containmentMethodToAdd);
diff --git a/dumpAst/src/main/jastadd/Printing.jrag b/dumpAst/src/main/jastadd/Printing.jrag
index e4565af..8fdcc8e 100644
--- a/dumpAst/src/main/jastadd/Printing.jrag
+++ b/dumpAst/src/main/jastadd/Printing.jrag
@@ -33,3 +33,31 @@ aspect Printing {
   syn boolean DumpNormalChildNode.bothVisible() = bothVisible(containingDumpNode(), getDumpNode());
   syn boolean DumpNormalRelation.bothVisible() = bothVisible(containingDumpNode(), getDumpNode());
 }
+
+aspect Debugging {
+  syn String ClassAnalysisResult.prettyPrint() {
+    StringBuilder sb = new StringBuilder();
+    sb.append("ContainmentMethods:");
+    for (AnalysedMethod method : getContainmentMethodList()) {
+      sb.append(method.prettyPrint()).append(",");
+    }
+    if (getNumContainmentMethod() == 0) {
+      sb.append("none. ");
+    }
+    sb.append("other methods:");
+    for (AnalysedMethod method : getOtherMethodList()) {
+      sb.append(method.prettyPrint()).append(",");
+    }
+    if (getNumOtherMethod() == 0) {
+      sb.append("none.");
+    }
+    return sb.toString();
+  }
+  syn String AnalysedMethod.prettyPrint() {
+    String methodString = "?";
+    try {
+      methodString = getMethod().toString();
+    } catch (Exception ignore) {}
+    return this.getClass().getSimpleName() + "[Method: " + methodString + ", Name: " + getName() + "]";
+  }
+}
diff --git a/dumpAst/src/main/java/de/tudresden/inf/st/jastadd/dumpAst/ast/DumpBuilder.java b/dumpAst/src/main/java/de/tudresden/inf/st/jastadd/dumpAst/ast/DumpBuilder.java
index 176896a..87466ee 100644
--- a/dumpAst/src/main/java/de/tudresden/inf/st/jastadd/dumpAst/ast/DumpBuilder.java
+++ b/dumpAst/src/main/java/de/tudresden/inf/st/jastadd/dumpAst/ast/DumpBuilder.java
@@ -51,6 +51,7 @@ public class DumpBuilder {
 
   /**
    * Add debug information in dumped content, mainly version numbers.
+   * Also dump debugging information while reading in object.
    *
    * @return this
    */
diff --git a/dumpAst/src/main/resources/dumpAstVersion.properties b/dumpAst/src/main/resources/dumpAstVersion.properties
index e6d184e..6e2bce7 100644
--- a/dumpAst/src/main/resources/dumpAstVersion.properties
+++ b/dumpAst/src/main/resources/dumpAstVersion.properties
@@ -1,2 +1,2 @@
-#Tue Mar 22 14:11:27 CET 2022
-version=1.0.1
+#Mon May 16 18:32:38 CEST 2022
+version=1.0.2
diff --git a/testDumper/src/main/jastadd/testDumper.relast b/testDumper/src/main/jastadd/testDumper.relast
index 7b66cc9..cf9d37f 100644
--- a/testDumper/src/main/jastadd/testDumper.relast
+++ b/testDumper/src/main/jastadd/testDumper.relast
@@ -24,3 +24,9 @@ T3 : AbstractT ;
 rel AbstractT.oneA -> A ;
 rel AbstractT.maybeA? -> A ;
 rel AbstractT.manyA* -> A ;
+
+Position : Nameable ::= <X:double> <Y:double> <Z:double>;
+Size : Nameable ::= <Length:double> <Width:double> <Height:double>;
+Orientation : Nameable ::= <X:double> <Y:double> <Z:double> <W:double>;
+ObjectOfInterest : Nameable ::= Position Size Orientation;
+DropOffLocation : ObjectOfInterest;
diff --git a/testDumper/src/test/java/de/tudresden/inf/st/jastadd/testDumper/TestComplex.java b/testDumper/src/test/java/de/tudresden/inf/st/jastadd/testDumper/TestComplex.java
new file mode 100644
index 0000000..856bab3
--- /dev/null
+++ b/testDumper/src/test/java/de/tudresden/inf/st/jastadd/testDumper/TestComplex.java
@@ -0,0 +1,37 @@
+package de.tudresden.inf.st.jastadd.testDumper;
+
+import de.tudresden.inf.st.jastadd.dumpAst.ast.DumpNode;
+import org.jastadd.testDumper.ast.DropOffLocation;
+import org.jastadd.testDumper.ast.Orientation;
+import org.jastadd.testDumper.ast.Position;
+import org.jastadd.testDumper.ast.Size;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static de.tudresden.inf.st.jastadd.testDumper.TestUtils.*;
+import static org.assertj.core.api.Assertions.*;
+
+/**
+ * More complex test cases.
+ *
+ * @author rschoene - Initial contribution
+ */
+public class TestComplex {
+
+  @Test
+  public void testRegressionIssue16() {
+    DropOffLocation location = new DropOffLocation();
+    location.setName(ROOT_NAME);
+    location.setPosition(new Position(T1_NAME, 1, 2, 3));
+    location.setOrientation(new Orientation(T2_NAME, 4, 5, 6, 7));
+    location.setSize(new Size(T3_NAME, 8, 9, 10));
+
+    List<DumpNode> nodes = TestUtils.dumpModel(location);
+    assertThat(valueTokens(findByName(nodes, T1_NAME))).containsOnly(
+        entry("Name", T1_NAME),
+        entry("X", 1.0),
+        entry("Y", 2.0),
+        entry("Z", 3.0));
+  }
+}
diff --git a/testDumper/src/test/java/de/tudresden/inf/st/jastadd/testDumper/TestSimple.java b/testDumper/src/test/java/de/tudresden/inf/st/jastadd/testDumper/TestSimple.java
index 1b9be71..ec0037e 100644
--- a/testDumper/src/test/java/de/tudresden/inf/st/jastadd/testDumper/TestSimple.java
+++ b/testDumper/src/test/java/de/tudresden/inf/st/jastadd/testDumper/TestSimple.java
@@ -120,10 +120,6 @@ public class TestSimple {
     DumpNode actualB3 = TestUtils.findByName(nodes, B3_NAME);
     DumpNode actualC = TestUtils.findByName(nodes, C_NAME);
 
-    for (DumpNode d : children) {
-      System.out.println(d.getName() + "/" + d.getLabel() + " = " + d);
-    }
-
     assertEquals(actualB1, actualA.successor(), actualA.successor().getName());
     assertEquals(actualB2, actualB1.successor(), actualB1.successor().getName());
     assertEquals(actualB3, actualB2.successor(), actualB2.successor().getName());
-- 
GitLab