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

1.2.1

- testing with latest JastAdd version, and with incremental=param and tracing=flush
- handle optionals if not set
- remove erroneous print statement for child inclusion
- fix JavaDoc warnings
parent 69402d31
No related branches found
No related tags found
1 merge request!121.2.2
Pipeline #14256 passed
...@@ -36,6 +36,10 @@ abstract SingleChildMethod : AnalysedMethod ; ...@@ -36,6 +36,10 @@ abstract SingleChildMethod : AnalysedMethod ;
NormalSingleChildMethod : SingleChildMethod ; NormalSingleChildMethod : SingleChildMethod ;
NTASingleChildMethod : SingleChildMethod ; NTASingleChildMethod : SingleChildMethod ;
abstract OptChildMethod : AnalysedMethod ::= <CheckMethod:java.lang.reflect.Method> ;
NormalOptChildMethod : OptChildMethod ;
NTAOptChildMethod : OptChildMethod ;
abstract ListChildMethod : AnalysedMethod ; abstract ListChildMethod : AnalysedMethod ;
NormalListChildMethod : ListChildMethod ; NormalListChildMethod : ListChildMethod ;
NTAListChildMethod : ListChildMethod ; NTAListChildMethod : ListChildMethod ;
......
...@@ -18,6 +18,12 @@ aspect Navigation { ...@@ -18,6 +18,12 @@ aspect Navigation {
syn boolean AnalysedMethod.isSingleChildMethod() = false; syn boolean AnalysedMethod.isSingleChildMethod() = false;
eq SingleChildMethod.isSingleChildMethod() = true; eq SingleChildMethod.isSingleChildMethod() = true;
/** Tests if AnalysedMethod is a OptChildMethod.
* @return 'true' if this is a OptChildMethod, otherwise 'false'
*/
syn boolean AnalysedMethod.isOptChildMethod() = false;
eq OptChildMethod.isOptChildMethod() = true;
/** Tests if AnalysedMethod is a ListChildMethod. /** Tests if AnalysedMethod is a ListChildMethod.
* @return 'true' if this is a ListChildMethod, otherwise 'false' * @return 'true' if this is a ListChildMethod, otherwise 'false'
*/ */
...@@ -123,6 +129,13 @@ aspect Navigation { ...@@ -123,6 +129,13 @@ aspect Navigation {
eq AnalysedMethod.asSingleChildMethod() = null; eq AnalysedMethod.asSingleChildMethod() = null;
eq SingleChildMethod.asSingleChildMethod() = this; eq SingleChildMethod.asSingleChildMethod() = this;
/** casts a AnalysedMethod into a OptChildMethod if possible.
* @return 'this' cast to a OptChildMethod or 'null'
*/
syn OptChildMethod AnalysedMethod.asOptChildMethod();
eq AnalysedMethod.asOptChildMethod() = null;
eq OptChildMethod.asOptChildMethod() = this;
/** casts a AnalysedMethod into a ListChildMethod if possible. /** casts a AnalysedMethod into a ListChildMethod if possible.
* @return 'this' cast to a ListChildMethod or 'null' * @return 'this' cast to a ListChildMethod or 'null'
*/ */
......
...@@ -11,7 +11,7 @@ aspect GenerationBackend { ...@@ -11,7 +11,7 @@ aspect GenerationBackend {
public boolean computed; public boolean computed;
public TransformationOptions asRelation() { public TransformationOptions asRelation() {
return fromSource(Source.RELATION, false).allowNullObjectsOnce(); return fromSource(Source.RELATION, false).computed(false).allowNullObjectsOnce();
} }
public TransformationOptions asRoot() { public TransformationOptions asRoot() {
...@@ -123,9 +123,19 @@ aspect GenerationBackend { ...@@ -123,9 +123,19 @@ aspect GenerationBackend {
System.out.println("for node " + obj + ", analysis was:\n" + car.prettyPrint()); System.out.println("for node " + obj + ", analysis was:\n" + car.prettyPrint());
} }
for (AnalysedMethod containmentMethod : car.getContainmentMethodList()) { for (AnalysedMethod containmentMethod : car.getContainmentMethodList()) {
if (containmentMethod.isSingleChildMethod()) { if (containmentMethod.isSingleChildMethod() || containmentMethod.isOptChildMethod()) {
// -- singleChild -- // -- singleChild or optChild --
Object target = containmentMethod.getMethod().invoke(obj); Object target;
if (containmentMethod.isOptChildMethod() && !((boolean) containmentMethod.asOptChildMethod().getCheckMethod().invoke(obj))) {
if (getBuildConfig().getExcludeNullNodes()) {
continue;
//target = containmentMethod.getMethod().invoke(obj);
} else {
target = null;
}
} else {
target = containmentMethod.getMethod().invoke(obj);
}
String childName = containmentMethod.getName(); String childName = containmentMethod.getName();
if (!getBuildConfig().getIncludeChildMethod().shouldInclude(obj, target, childName)) { if (!getBuildConfig().getIncludeChildMethod().shouldInclude(obj, target, childName)) {
continue; continue;
...@@ -328,12 +338,14 @@ aspect GenerationBackend { ...@@ -328,12 +338,14 @@ aspect GenerationBackend {
case "OptChild": case "OptChild":
contextNameToAdd = invokeName(annotation); contextNameToAdd = invokeName(annotation);
try { try {
// the annotated method is "get???Opt", but we want "get???" // the annotated method is "get???Opt", but we want "get???" and "has???"
java.lang.reflect.Method realGetter = clazz.getMethod("get" + contextNameToAdd); java.lang.reflect.Method realGetter = clazz.getMethod("get" + contextNameToAdd);
NormalSingleChildMethod normalSingleChildMethod = new NormalSingleChildMethod(); java.lang.reflect.Method checkMethod = clazz.getMethod("has" + contextNameToAdd);
normalSingleChildMethod.setMethod(realGetter); NormalOptChildMethod normalOptChildMethod = new NormalOptChildMethod();
normalSingleChildMethod.setName(contextNameToAdd); normalOptChildMethod.setMethod(realGetter);
containmentMethodToAdd = normalSingleChildMethod; normalOptChildMethod.setCheckMethod(checkMethod);
normalOptChildMethod.setName(contextNameToAdd);
containmentMethodToAdd = normalOptChildMethod;
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
System.err.println("Could not find getter for Opt-child " + contextNameToAdd + " in " + clazzName); System.err.println("Could not find getter for Opt-child " + contextNameToAdd + " in " + clazzName);
throw new RuntimeException(e); throw new RuntimeException(e);
......
...@@ -56,7 +56,6 @@ public class DumpBuilder { ...@@ -56,7 +56,6 @@ public class DumpBuilder {
this.target = target; this.target = target;
buildConfig = new BuildConfig(); buildConfig = new BuildConfig();
buildConfig.setIncludeChildMethod((parentNode, childNode, contextName) -> { buildConfig.setIncludeChildMethod((parentNode, childNode, contextName) -> {
System.out.printf("child: %s, %s, %s%n", parentNode, childNode, contextName);
// level 4: excluded for type? -> return no // level 4: excluded for type? -> return no
PatternCollection excludeOnType = buildConfig.matchExcludePatternCollection(parentNode.getClass().getSimpleName()); PatternCollection excludeOnType = buildConfig.matchExcludePatternCollection(parentNode.getClass().getSimpleName());
if (excludeOnType != null && matches(excludeOnType.childPattern(), contextName)) { if (excludeOnType != null && matches(excludeOnType.childPattern(), contextName)) {
...@@ -580,7 +579,7 @@ public class DumpBuilder { ...@@ -580,7 +579,7 @@ public class DumpBuilder {
} }
/** /**
* Set the method defining, what name a node has (default: n -> n == null ? "null" : n.getClass().getSimpleName() + "@" + Integer.toHexString(n.hashCode())). * Set the method defining, what name a node has (default: {@code n -> n == null ? "null" : n.getClass().getSimpleName() + "@" + Integer.toHexString(n.hashCode())}).
* *
* <p>Example:<br> * <p>Example:<br>
* {@code builder.<ASTNode<?>>setNameMethod(n -> n.isA() ? "A" : "Not A")} * {@code builder.<ASTNode<?>>setNameMethod(n -> n.isA() ? "A" : "Not A")}
...@@ -594,7 +593,7 @@ public class DumpBuilder { ...@@ -594,7 +593,7 @@ public class DumpBuilder {
} }
/** /**
* Set the method defining, what background color a node has (default: n -> ""). * Set the method defining, what background color a node has (default: {@code n -> ""}).
* *
* <p>Example:<br> * <p>Example:<br>
* {@code builder.<ASTNode<?>>setBackgroundColorMethod(n -> n.isA() ? "red" : "blue")} * {@code builder.<ASTNode<?>>setBackgroundColorMethod(n -> n.isA() ? "red" : "blue")}
...@@ -608,7 +607,7 @@ public class DumpBuilder { ...@@ -608,7 +607,7 @@ public class DumpBuilder {
} }
/** /**
* Set the method defining, what text color a node has (default: n -> ""). * Set the method defining, what text color a node has (default: {@code n -> ""}).
* *
* <p>Example:<br> * <p>Example:<br>
* {@code builder.<ASTNode<?>>setTextColorMethod(n -> n.isA() ? "black" : "white")} * {@code builder.<ASTNode<?>>setTextColorMethod(n -> n.isA() ? "black" : "white")}
...@@ -622,7 +621,7 @@ public class DumpBuilder { ...@@ -622,7 +621,7 @@ public class DumpBuilder {
} }
/** /**
* Set the method defining, what stereotype a node has (default: n -> ""). * Set the method defining, what stereotype a node has (default: {@code n -> ""}).
* *
* <p>Example:<br> * <p>Example:<br>
* {@code builder.<ASTNode<?>>setStereotypeMethod(n -> n.isA() ? "MyStereoType" : "")} * {@code builder.<ASTNode<?>>setStereotypeMethod(n -> n.isA() ? "MyStereoType" : "")}
......
#Tue Jul 05 15:14:22 CEST 2022 #Mon Jul 25 18:03:32 CEST 2022
version=1.2.0 version=1.2.1
...@@ -32,6 +32,7 @@ configurations { ...@@ -32,6 +32,7 @@ configurations {
dependencies { dependencies {
implementation project(':dumpAst') implementation project(':dumpAst')
relast group: 'org.jastadd', name: 'relast', version: "${relast_version}" relast group: 'org.jastadd', name: 'relast', version: "${relast_version}"
jastadd2 "org.jastadd:jastadd2:2.3.5-dresden-6"
implementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11' implementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
...@@ -109,7 +110,7 @@ jastadd { ...@@ -109,7 +110,7 @@ jastadd {
astPackage = 'org.jastadd.testDumper.ast' astPackage = 'org.jastadd.testDumper.ast'
genDir = 'src/gen/java' genDir = 'src/gen/java'
buildInfoDir = 'src/gen-res' buildInfoDir = 'src/gen-res'
jastaddOptions = ["--lineColumnNumbers", "--List=JastAddList", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"] jastaddOptions = ["--lineColumnNumbers", "--List=JastAddList", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all", "--incremental=param", "--tracing=cache,flush"]
} }
// --- Tests --- // --- Tests ---
......
...@@ -143,6 +143,19 @@ public class TestSimple { ...@@ -143,6 +143,19 @@ public class TestSimple {
assertFalse(actualC.hasSuccessor()); assertFalse(actualC.hasSuccessor());
} }
@Test
public void testNoOptChild() {
Root root = new Root().setName(ROOT_NAME);
List<DumpNode> nodes = TestUtils.dumpModel(root);
assertThat(nodes).flatExtracting(NAME_EXTRACTOR).containsExactlyInAnyOrder(ROOT_NAME);
DumpNode actualRoot = TestUtils.findByName(nodes, ROOT_NAME);
assertEquals(1, actualRoot.getNumDumpToken());
assertEquals(0, actualRoot.getNumDumpChildNode());
assertEquals(0, actualRoot.getNumDumpRelation());
assertThatMapOf(normalChildren(actualRoot)).isEmpty();
}
@Test @Test
public void testOneOptChild() { public void testOneOptChild() {
Root root = createRoot(null, createC(C_NAME)); Root root = createRoot(null, createC(C_NAME));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment