Commit a769a0f5 authored by René Schöne's avatar René Schöne
Browse files

WIP: Compiles again with mustache.

parent ffd6ff31
...@@ -74,12 +74,12 @@ task relast(type: JavaExec) { ...@@ -74,12 +74,12 @@ task relast(type: JavaExec) {
inputs.files file("../libs/relast.jar"), inputs.files file("../libs/relast.jar"),
file("../relast.preprocessor/src/main/jastadd/RelAST.relast"), file("../relast.preprocessor/src/main/jastadd/RelAST.relast"),
file("src/main/jastadd/Ros2Rag.relast") file("./src/main/jastadd/Ros2Rag.relast")
file("src/main/jastadd/MustacheNodes.relast") file("./src/main/jastadd/MustacheNodes.relast")
outputs.files file("./src/gen/jastadd/Ros2Rag.ast"), outputs.files file("./src/gen/jastadd/Ros2Rag.ast"),
file("src/gen/jastadd/Ros2Rag.jadd"), file("./src/gen/jastadd/Ros2Rag.jadd"),
file("src/gen/jastadd/Ros2RagRefResolver.jadd"), file("./src/gen/jastadd/Ros2RagRefResolver.jadd"),
file('src/gen/jastadd/Ros2RagResolverStubs.jrag') file('./src/gen/jastadd/Ros2RagResolverStubs.jrag')
} }
jastadd { jastadd {
......
//TypeComponentMustache ; //TypeComponentMustache ;
//rel TypeComponentMustache.TypeComponent -> TypeComponent ; //rel TypeComponentMustache.TypeComponent -> TypeComponent ;
MRos2Rag ::= ReadDefinition:MReadDefinition* WriteDefinition:MWriteDefinition* MappingDefinition:MMappingDefinition* DependencyDefinition:MDependencyDefinition* TypeComponent:MTypeComponent*; MRos2Rag ::= ReadDefinition:MReadDefinition* WriteDefinition:MWriteDefinition* MappingDefinition:MMappingDefinition* DependencyDefinition:MDependencyDefinition* RootTypeChildren:MTypeComponent* TokenComponent:MTokenComponent*;
MUpdateDefinition ::= <FirstInputVarName>; abstract MUpdateDefinition ::= InnerMappingDefinition:MInnerMappingDefinition*;
MReadDefinition : MUpdateDefinition; MReadDefinition : MUpdateDefinition;
MWriteDefinition : MUpdateDefinition; MWriteDefinition : MUpdateDefinition;
MMappingDefinition; MMappingDefinition;
MInnerMappingDefinition;
MDependencyDefinition; MDependencyDefinition;
MTypeComponent; MTypeComponent;
MTokenComponent;
MUpdateDefinition.InnerMappingDefinition* -> MInnerMappingDefinition; rel MRos2Rag.Ros2Rag -> Ros2Rag;
MInnerMappingDefinition.MappingDefinition -> MappingDefinition; rel MInnerMappingDefinition.MappingDefinition -> MappingDefinition;
MReadDefinition.ReadFromMqttDefinition -> ReadFromMqttDefinition; rel MReadDefinition.ReadFromMqttDefinition -> ReadFromMqttDefinition;
MWriteDefinition.WriteToMqttDefinition -> WriteToMqttDefinition; rel MWriteDefinition.WriteToMqttDefinition -> WriteToMqttDefinition;
MMappingDefinition.MappingDefinition -> MappingDefinition; rel MMappingDefinition.MappingDefinition -> MappingDefinition;
MDependencyDefinition.DependencyDefinition -> DependencyDefinition; rel MDependencyDefinition.DependencyDefinition -> DependencyDefinition;
MTypeComponent.TypeComponent -> TypeComponent; rel MTypeComponent.TypeComponent -> TypeComponent;
MTypeComponent.DependencyDefinition* -> MDependencyDefinition; rel MTokenComponent.TokenComponent -> TokenComponent;
rel MTokenComponent.DependencyDefinition* -> MDependencyDefinition;
...@@ -2,10 +2,12 @@ aspect Navigation { ...@@ -2,10 +2,12 @@ aspect Navigation {
// --- program --- // --- program ---
eq Ros2Rag.getChild().program() = getProgram(); eq Ros2Rag.getChild().program() = getProgram();
eq MRos2Rag.getChild().program() = getRos2Rag().program();
// --- ros2rag --- // --- ros2rag ---
inh Ros2Rag ASTNode.ros2rag(); inh Ros2Rag ASTNode.ros2rag();
eq Ros2Rag.getChild().ros2rag() = this; eq Ros2Rag.getChild().ros2rag() = this;
eq MRos2Rag.getChild().ros2rag() = getRos2Rag();
// --- containedFile (first equation should be in preprocessor) --- // --- containedFile (first equation should be in preprocessor) ---
eq Program.getChild().containedFile() = null; eq Program.getChild().containedFile() = null;
...@@ -32,6 +34,7 @@ aspect Navigation { ...@@ -32,6 +34,7 @@ aspect Navigation {
eq GrammarFile.getChild().containedFileName() = getFileName(); eq GrammarFile.getChild().containedFileName() = getFileName();
eq Ros2Rag.getChild().containedFileName() = getFileName(); eq Ros2Rag.getChild().containedFileName() = getFileName();
eq Program.getChild().containedFileName() = null; eq Program.getChild().containedFileName() = null;
eq MRos2Rag.getChild().containedFileName() = null;
// --- isTokenUpdateDefinition --- // --- isTokenUpdateDefinition ---
syn boolean UpdateDefinition.isTokenUpdateDefinition() = false; syn boolean UpdateDefinition.isTokenUpdateDefinition() = false;
......
...@@ -31,34 +31,36 @@ aspect AttributesForMustache { ...@@ -31,34 +31,36 @@ aspect AttributesForMustache {
// --- MUpdateDefinition --- // --- MUpdateDefinition ---
syn String MUpdateDefinition.preemptiveExpectedValue(); syn String MUpdateDefinition.preemptiveExpectedValue();
syn String MUpdateDefinition.preemptiveReturn(); syn String MUpdateDefinition.preemptiveReturn();
syn String MUpdateDefinition.mqttUpdaterAttribute(); syn TokenUpdateDefinition MUpdateDefinition.updateDef();
syn UpdateDefinition MUpdateDefinition.updateDef(); syn String MUpdateDefinition.firstInputVarName();
eq MUpdateDefinition.getMInnerMappingDefinition(int i).isLast() = i == numInnerMappingDefinition(); eq MUpdateDefinition.getInnerMappingDefinition(int i).isLast() = i == getNumInnerMappingDefinition();
eq MUpdateDefinition.getInnerMappingDefinition().resultVarPrefix() = resultVarPrefix(); eq MUpdateDefinition.getInnerMappingDefinition().resultVarPrefix() = resultVarPrefix();
eq MUpdateDefinition.getInnerMappingDefinition(int i).inputVarName() = i == 0 ? getFirstInputVarName() : resultVarPrefix() + getMInnerMappingDefinition(i - 1).getMappingDefinition().methodName(); eq MUpdateDefinition.getInnerMappingDefinition(int i).inputVarName() = i == 0 ? firstInputVarName() : resultVarPrefix() + getInnerMappingDefinition(i - 1).getMappingDefinition().methodName();
eq MRos2Rag.getChild().mqttUpdaterField() = getRos2Rag().mqttUpdaterField();
syn String MUpdateDefinition.mqttUpdaterAttribute() = updateDef().mqttUpdaterAttribute();
syn String MUpdateDefinition.connectMethod() = updateDef().connectMethod(); syn String MUpdateDefinition.connectMethod() = updateDef().connectMethod();
syn TokenComponent MUpdateDefinition.token() = updateDef().getToken(); syn TokenComponent MUpdateDefinition.token() = updateDef().getToken();
syn boolean MUpdateDefinition.alwaysApply() = updateDef().getAlwaysApply(); syn boolean MUpdateDefinition.alwaysApply() = updateDef().getAlwaysApply();
syn String MUpdateDefinition.resultVarPrefix() = "result"; // we do not need "_" here, because methodName begins with one syn String MUpdateDefinition.resultVarPrefix() = "result"; // we do not need "_" here, because methodName begins with one
syn String MUpdateDefinition.parentTypeName() = token().containingTypeDecl().getName(); syn String MUpdateDefinition.parentTypeName() = token().containingTypeDecl().getName();
syn String MUpdateDefinition.TokenName() = token().getName(); syn String MUpdateDefinition.tokenName() = token().getName();
syn MInnerMappingDefinition MUpdateDefinition.lastDefinition() = getInnerMappingDefinition(numInnerMappingDefinition() - 1); syn MInnerMappingDefinition MUpdateDefinition.lastDefinition() = getInnerMappingDefinition(getNumInnerMappingDefinition() - 1);
syn String MUpdateDefinition.lastDefinitionType() = lastDefinition().ToType(); syn String MUpdateDefinition.lastDefinitionType() = lastDefinition().ToType();
syn String MUpdateDefinition.lastDefinitionName() = lastDefinition().methodName(); syn String MUpdateDefinition.lastDefinitionName() = lastDefinition().methodName();
syn String MUpdateDefinition.lastResult() = resultVarPrefix() + lastDefinitionName();
syn String MUpdateDefinition.condition() { syn String MUpdateDefinition.condition() {
String lastVarName = resultVarPrefix() + lastDefinitionDefinitionName();
if (lastDefinition().getMappingDefinition().getToType().isArray()) { if (lastDefinition().getMappingDefinition().getToType().isArray()) {
return "java.util.Arrays.equals(" + preemptiveExpectedValue() + ", " + lastVarName + ")"; return "java.util.Arrays.equals(" + preemptiveExpectedValue() + ", " + lastResult() + ")";
} }
if (token().isPrimitiveType() && lastDefinition().getMappingDefinition().getToType().isPrimitiveType()) { if (token().isPrimitiveType() && lastDefinition().getMappingDefinition().getToType().isPrimitiveType()) {
return preemptiveExpectedValue() + " == " + lastVarName; return preemptiveExpectedValue() + " == " + lastResult();
} }
if (lastDefinition().getMappingDefinition().isDefaultMappingDefinition()) { if (lastDefinition().getMappingDefinition().isDefaultMappingDefinition()) {
return preemptiveExpectedValue() + " != null && " + preemptiveExpectedValue() + ".equals(" + lastVarName ")"; return preemptiveExpectedValue() + " != null && " + preemptiveExpectedValue() + ".equals(" + lastResult() + ")";
} }
return preemptiveExpectedValue() + " != null ? " + preemptiveExpectedValue() + ".equals(" + lastVarName ") : " + inputVariableName + " == null"; return preemptiveExpectedValue() + " != null ? " + preemptiveExpectedValue() + ".equals(" + lastResult() + ") : " + lastResult() + " == null";
} }
// --- MInnerMappingDefinition --- // --- MInnerMappingDefinition ---
...@@ -69,18 +71,16 @@ aspect AttributesForMustache { ...@@ -69,18 +71,16 @@ aspect AttributesForMustache {
inh String MInnerMappingDefinition.inputVarName(); inh String MInnerMappingDefinition.inputVarName();
// --- MReadDefinition --- // --- MReadDefinition ---
eq MReadDefinition.connectMethod() = getReadFromMqttDefinition().connectMethod(); eq MReadDefinition.preemptiveExpectedValue() = "get" + tokenName() + "()";
eq MReadDefinition.preemptiveExpectedValue() = "get" + TokenName() + "()";
eq MReadDefinition.preemptiveReturn() = "return;"; eq MReadDefinition.preemptiveReturn() = "return;";
eq MReadDefinition.updateDef() = getReadFromMqttDefinition(); eq MReadDefinition.updateDef() = getReadFromMqttDefinition();
eq MReadDefinition.firstInputVarName() = "message";
syn String MReadDefinition.mqttUpdaterAttribute() = getReadFromMqttDefinition().mqttUpdaterAttribute;
syn String MReadDefinition.lastResult() = getReadFromMqttDefinition();
// --- MWriteDefinition --- // --- MWriteDefinition ---
eq MWriteDefinition.preemptiveExpectedValue() = lastValue(); eq MWriteDefinition.preemptiveExpectedValue() = lastValue();
eq MWriteDefinition.preemptiveReturn() = "return false;"; eq MWriteDefinition.preemptiveReturn() = "return false;";
eq MWriteDefinition.updateDef() = getWriteToMqttDefinition(); eq MWriteDefinition.updateDef() = getWriteToMqttDefinition();
eq MWriteDefinition.firstInputVarName() = "get" + tokenName() + "()";
syn String MWriteDefinition.writeTopic() = getWriteToMqttDefinition().writeTopic(); syn String MWriteDefinition.writeTopic() = getWriteToMqttDefinition().writeTopic();
syn String MWriteDefinition.lastValue() = getWriteToMqttDefinition().lastValue(); syn String MWriteDefinition.lastValue() = getWriteToMqttDefinition().lastValue();
...@@ -101,69 +101,88 @@ aspect AttributesForMustache { ...@@ -101,69 +101,88 @@ aspect AttributesForMustache {
syn String MDependencyDefinition.sourceParentTypeName() = getDependencyDefinition().getSource().containingTypeDecl().getName(); syn String MDependencyDefinition.sourceParentTypeName() = getDependencyDefinition().getSource().containingTypeDecl().getName();
syn String MDependencyDefinition.internalRelationPrefix() = getDependencyDefinition().internalRelationPrefix(); syn String MDependencyDefinition.internalRelationPrefix() = getDependencyDefinition().internalRelationPrefix();
syn nta MUpdateDefinition MDependencyDefinition.targetUpdateDefinition() { syn nta MUpdateDefinition MDependencyDefinition.targetUpdateDefinition() {
return wrap(getDependencyDefinition().targetUpdateDefinition()); return getDependencyDefinition().targetUpdateDefinition().toMustache();
} }
// --- MTypeComponent --- // --- MTypeComponent ---
syn String MTypeComponent.parentTypeName() = getTypeComponent().containingTypeDecl().getName();
syn String MTypeComponent.name() = getTypeComponent().getName(); syn String MTypeComponent.name() = getTypeComponent().getName();
syn String MTypeComponent.javaType() = getTypeComponent().getJavaTypeUse().prettyPrint(); inh String MTypeComponent.mqttUpdaterAttribute();
syn String MTypeComponent.internalName() = getTypeComponent().internalName(); inh String MTypeComponent.mqttUpdaterField();
// --- MTokenComponent ---
syn String MTokenComponent.parentTypeName() = getTokenComponent().containingTypeDecl().getName();
syn String MTokenComponent.name() = getTokenComponent().getName();
syn String MTokenComponent.javaType() = getTokenComponent().getJavaTypeUse().prettyPrint();
syn String MTokenComponent.internalName() = getTokenComponent().internalName();
// --- wrap --- // --- toMustache ---
syn lazy MRos2Rag Ros2Rag.wrap() { syn lazy MRos2Rag Ros2Rag.toMustache() {
MRos2Rag result = new MRos2Rag(); MRos2Rag result = new MRos2Rag();
result.setRos2Rag(this);
for (UpdateDefinition def : getUpdateDefinitionList()) { for (UpdateDefinition def : getUpdateDefinitionList()) {
if (def.isWriteToMqttDefinition()) { if (def.isWriteToMqttDefinition()) {
result.addWriteDefinition(def.asWriteToMqttDefinition.wrap()); result.addWriteDefinition(def.asWriteToMqttDefinition().toMustache());
} else { } else {
result.addReadDefinition(def.asReadFromMqttDefinition().wrap()); result.addReadDefinition(def.asReadFromMqttDefinition().toMustache());
} }
} }
for (MappingDefinition def : allMappingDefinitions()) { for (MappingDefinition def : allMappingDefinitions()) {
result.addMappingDefinition(def.wrap()); result.addMappingDefinition(def.toMustache());
} }
for (DependencyDefinition def : getDependencyDefinitionList()) { for (DependencyDefinition def : getDependencyDefinitionList()) {
result.addDependencyDefinition(def.wrap()); result.addDependencyDefinition(def.toMustache());
} }
for (TokenComponent token : getProgram().allTokenComponents()) { for (TokenComponent token : getProgram().allTokenComponents()) {
result.addTokenComponent(token.wrap()); result.addTokenComponent(token.toMustache());
}
for (Component child : rootNode.getComponentList()) {
if (child.isTypeComponent()) {
result.addRootTypeChildren(child.asTypeComponent().toMustache());
}
} }
return result; return result;
} }
//MInnerMappingDefinition.MappingDefinition -> MappingDefinition; //MInnerMappingDefinition.MappingDefinition -> MappingDefinition;
private void MUpdateDefinition.addInnerMappings() { protected void MUpdateDefinition.addInnerMappings() {
for (MappingDefinition def : updateDefinition().effectiveMappings()) { for (MappingDefinition def : updateDef().effectiveMappings()) {
addInnerMappingDefinition(def.wrap()); MInnerMappingDefinition inner = new MInnerMappingDefinition();
inner.setMappingDefinition(def);
addInnerMappingDefinition(inner);
} }
} }
syn lazy MReadDefinition ReadFromMqttDefinition.wrap() { syn lazy MReadDefinition ReadFromMqttDefinition.toMustache() {
MReadDefinition result = new MReadDefinition(); MReadDefinition result = new MReadDefinition();
result.setReadFromMqttDefinition(this); result.setReadFromMqttDefinition(this);
result.addInnerMappings(); result.addInnerMappings();
return result; return result;
} }
syn lazy MWriteDefinition WriteToMqttDefinition.wrap() { syn lazy MWriteDefinition WriteToMqttDefinition.toMustache() {
MWriteDefinition result = new MWriteDefinition(); MWriteDefinition result = new MWriteDefinition();
result.setWriteToMqttDefinition(this); result.setWriteToMqttDefinition(this);
result.addInnerMappings(); result.addInnerMappings();
return result; return result;
} }
syn lazy MMappingDefinition MappingDefinition.wrap() { syn lazy MMappingDefinition MappingDefinition.toMustache() {
MMappingDefinition result = new MMappingDefinition(); MMappingDefinition result = new MMappingDefinition();
result.setMappingDefinition(this); result.setMappingDefinition(this);
return result; return result;
} }
syn lazy MDependencyDefinition DependencyDefinition.wrap() { syn lazy MDependencyDefinition DependencyDefinition.toMustache() {
MDependencyDefinition result = new MDependencyDefinition(); MDependencyDefinition result = new MDependencyDefinition();
result.setDependencyDefinition(this); result.setDependencyDefinition(this);
return result; return result;
} }
syn lazy MTypeComponent TypeComponent.wrap() { syn lazy MTypeComponent TypeComponent.toMustache() {
MTypeComponent result = new MTypeComponent(); MTypeComponent result = new MTypeComponent();
result.setTypeComponent(this); result.setTypeComponent(this);
return result;
}
syn lazy MTokenComponent TokenComponent.toMustache() {
MTokenComponent result = new MTokenComponent();
result.setTokenComponent(this);
for (DependencyDefinition def : getDependencySourceDefinitionList()) { for (DependencyDefinition def : getDependencySourceDefinitionList()) {
result.addDependencyDefinition(def.wrap()); result.addDependencyDefinition(def.toMustache());
} }
return result; return result;
} }
...@@ -202,239 +221,241 @@ aspect AspectGeneration { ...@@ -202,239 +221,241 @@ aspect AspectGeneration {
eq Ros2Rag.getChild().mqttUpdaterAttribute() = mqttUpdaterAttribute(); eq Ros2Rag.getChild().mqttUpdaterAttribute() = mqttUpdaterAttribute();
// --- mqttUpdaterField --- // --- mqttUpdaterField ---
eq Ros2Rag.getChild().mqttUpdaterField() = mqttUpdaterField();
// --- rootNodeName --- // --- rootNodeName ---
syn String ASTNode.rootNodeName() = rootNode.getName(); syn String ASTNode.rootNodeName() = rootNode.getName();
// mustache specific nodes // mustache specific nodes
syn nta TypeComponentMustache TypeComponent.mustache() { // syn nta TypeComponentMustache TypeComponent.mustache() {
TypeComponentMustache result = new TypeComponentMustache(); // TypeComponentMustache result = new TypeComponentMustache();
result.setTypeComponent(this); // result.setTypeComponent(this);
return result; // return result;
} // }
syn String TypeComponentMustache.name() = getTypeComponent().getName(); // syn String TypeComponentMustache.name() = getTypeComponent().getName();
inh String TypeComponentMustache.mqttUpdaterAttribute(); // inh String TypeComponentMustache.mqttUpdaterAttribute();
inh String TypeComponentMustache.mqttUpdaterField(); // inh String TypeComponentMustache.mqttUpdaterField();
//
// mustache specific attributes // // mustache specific attributes
syn java.util.List<TypeComponentMustache> Ros2Rag.rootTypeChildren() { // syn java.util.List<TypeComponentMustache> Ros2Rag.rootTypeChildren() {
java.util.List<TypeComponentMustache> result = new java.util.ArrayList<>(); // java.util.List<TypeComponentMustache> result = new java.util.ArrayList<>();
for (Component child : rootNode.getComponentList()) { // for (Component child : rootNode.getComponentList()) {
if (child.isTypeComponent()){ // if (child.isTypeComponent()){
result.add(child.asTypeComponent().mustache()); // result.add(child.asTypeComponent().mustache());
} // }
} // }
return result; // return result;
} // }
public String Ros2Rag.generateAspect(String rootNodeName) { public String Ros2Rag.generateAspect(String rootNodeName) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
rootNode = getProgram().resolveTypeDecl(rootNodeName); rootNode = getProgram().resolveTypeDecl(rootNodeName);
generateMqttAspect(sb);
generateGrammarExtension(sb);
return sb.toString();
}
public void Ros2Rag.generateMqttAspect(StringBuilder sb) {
String rootNodeName = rootNode.getName();
com.github.mustachejava.MustacheFactory mf = new com.github.mustachejava.DefaultMustacheFactory(); com.github.mustachejava.MustacheFactory mf = new com.github.mustachejava.DefaultMustacheFactory();
com.github.mustachejava.Mustache m = mf.compile("mqtt.mustache"); com.github.mustachejava.Mustache m = mf.compile("ros2rag.mustache");
m.execute(new java.io.PrintWriter(new org.jastadd.ros2rag.compiler.AppendableWriter(sb)), this); m.execute(new java.io.PrintWriter(new org.jastadd.ros2rag.compiler.AppendableWriter(sb)), this);
// generateMqttAspect(sb);
// generateGrammarExtension(sb);
return sb.toString();
} }
//
public void Ros2Rag.generateGrammarExtension(StringBuilder sb) { // public void Ros2Rag.generateMqttAspect(StringBuilder sb) {
sb.append("aspect ROS2RAG {\n"); // String rootNodeName = rootNode.getName();
// com.github.mustachejava.MustacheFactory mf = new com.github.mustachejava.DefaultMustacheFactory();
for (UpdateDefinition def : getUpdateDefinitionList()) { // com.github.mustachejava.Mustache m = mf.compile("mqtt.mustache");
def.generateAspect(sb); // m.execute(new java.io.PrintWriter(new org.jastadd.ros2rag.compiler.AppendableWriter(sb)), this);
} // }
for (MappingDefinition def : allMappingDefinitions()) { //
def.generateAspect(sb); // public void Ros2Rag.generateGrammarExtension(StringBuilder sb) {
} // sb.append("aspect ROS2RAG {\n");
for (DependencyDefinition def : getDependencyDefinitionList()) { //
def.generateAspect(sb); // for (UpdateDefinition def : getUpdateDefinitionList()) {
} // def.generateAspect(sb);
for (TokenComponent token : getProgram().allTokenComponents()) { // }
token.generateAspect(sb); // for (MappingDefinition def : allMappingDefinitions()) {
} // def.generateAspect(sb);
// }
sb.append("}\n"); // for (DependencyDefinition def : getDependencyDefinitionList()) {
} // def.generateAspect(sb);
// }
abstract void UpdateDefinition.generateAspect(StringBuilder sb); // for (TokenComponent token : getProgram().allTokenComponents()) {
// token.generateAspect(sb);
String TokenUpdateDefinition.generateMappingApplication(StringBuilder sb, int indent, // }
String initialInputVariableName) { //
final String resultVariablePrefix = "result"; // we do not need "_" here, because methodName begins with one // sb.append("}\n");
String inputVariableName = initialInputVariableName; // }
// last variable need to be declared before begin of try //
MappingDefinition lastDefinition = effectiveMappings().get(effectiveMappings().size() - 1); // abstract void UpdateDefinition.generateAspect(StringBuilder sb);
sb.append(ind(indent)).append(lastDefinition.getToType().prettyPrint()).append(" ") //
.append(resultVariablePrefix).append(lastDefinition.methodName()).append(";\n"); // String TokenUpdateDefinition.generateMappingApplication(StringBuilder sb, int indent,
sb.append(ind(indent)).append("try {\n"); // String initialInputVariableName) {
for (MappingDefinition mappingDefinition : effectiveMappings()) { // final String resultVariablePrefix = "result"; // we do not need "_" here, because methodName begins with one
String resultVariableName = resultVariablePrefix + mappingDefinition.methodName(); // String inputVariableName = initialInputVariableName;
sb.append(ind(indent + 1)); // // last variable need to be declared before begin of try
if (mappingDefinition != lastDefinition) { // MappingDefinition lastDefinition = effectiveMappings().get(effectiveMappings().size() - 1);
sb.append(mappingDefinition.getToType().prettyPrint()).append(" "); // sb.append(ind(indent)).append(lastDefinition.getToType().prettyPrint()).append(" ")
} // .append(resultVariablePrefix).append(lastDefinition.methodName()).append(";\n");
sb.append(resultVariablePrefix).append(mappingDefinition.methodName()) // sb.append(ind(indent)).append("try {\n");
.append(" = ").append(mappingDefinition.methodName()).append("(") // for (MappingDefinition mappingDefinition : effectiveMappings()) {
.append(inputVariableName).append(");\n"); // String resultVariableName = resultVariablePrefix + mappingDefinition.methodName();
inputVariableName = resultVariableName; // sb.append(ind(indent + 1));
} // if (mappingDefinition != lastDefinition) {
sb.append(ind(indent)).append("} catch (Exception e) {\n"); // sb.append(mappingDefinition.getToType().prettyPrint()).append(" ");
sb.append(ind(indent + 1)).append("e.printStackTrace();\n"); // }
sb.append(ind(indent + 1)).append(preemptiveReturnStatement()).append("\n"); // sb.append(resultVariablePrefix).append(mappingDefinition.methodName())
sb.append(ind(indent)).append("}\n"); // .append(" = ").append(mappingDefinition.methodName()).append("(")
if (!getAlwaysApply()) { // .append(inputVariableName).append(");\n");
MappingDefinition lastMapping = effectiveMappings().get(effectiveMappings().size() - 1); // inputVariableName = resultVariableName;
sb.append(ind(indent)).append("if ("); // }
if (lastMapping.getToType().isArray()) { // sb.append(ind(indent)).append("} catch (Exception e) {\n");
sb.append("java.util.Arrays.equals(").append(preemptiveExpectedValue()) // sb.append(ind(indent + 1)).append("e.printStackTrace();\n");
.append(", ").append(inputVariableName).append(")"); // sb.append(ind(indent + 1)).append(preemptiveReturnStatement()).append("\n");
} else { // sb.append(ind(indent)).append("}\n");
sb.append(preemptiveExpectedValue()); // if (!getAlwaysApply()) {
if (getToken().isPrimitiveType() && lastMapping.getToType().isPrimitiveType()) { // MappingDefinition lastMapping = effectiveMappings().get(effectiveMappings().size() - 1);
sb.append(" == ").append(inputVariableName); // sb.append(ind(indent)).append("if (");
} else if (lastMapping.isDefaultMappingDefinition()) { // if (lastMapping.getToType().isArray()) {
sb.append(" != null && ").append(preemptiveExpectedValue()).append(".equals(") // sb.append("java.util.Arrays.equals(").append(preemptiveExpectedValue())
.append(inputVariableName).append(")"); // .append(", ").append(inputVariableName).append(")");
} else { // } else {
sb.append(" != null ? ").append(preemptiveExpectedValue()).append(".equals(") // sb.append(preemptiveExpectedValue());
.append(inputVariableName).append(")").append(" : ") // if (getToken().isPrimitiveType() && lastMapping.getToType().isPrimitiveType()) {
.append(inputVariableName).append(" == null"); // sb.append(" == ").append(inputVariableName);
} // } else if (lastMapping.isDefaultMappingDefinition()) {
} // sb.append(" != null && ").append(preemptiveExpectedValue()).append(".equals(")
sb.append(") { ").append(preemptiveReturnStatement()).append(" }\n"); // .append(inputVariableName).append(")");
} // } else {
return inputVariableName; // sb.append(" != null ? ").append(preemptiveExpectedValue()).append(".equals(")
} // .append(inputVariableName).append(")").append(" : ")
// .append(inputVariableName).append(" == null");
syn String TokenUpdateDefinition.preemptiveExpectedValue(); // }
eq ReadFromMqttDefinition.preemptiveExpectedValue() = "get" + getToken().getName() + "()"; // }
eq WriteToMqttDefinition.preemptiveExpectedValue() = lastValue(); // sb.append(") { ").append(preemptiveReturnStatement()).append(" }\n");
// }
syn String TokenUpdateDefinition.preemptiveReturnStatement(); // return inputVariableName;
eq ReadFromMqttDefinition.preemptiveReturnStatement() = "return;"; // }
eq WriteToMqttDefinition.preemptiveReturnStatement() = "return false;"; //
// syn String TokenUpdateDefinition.preemptiveExpectedValue();
@Override // eq ReadFromMqttDefinition.preemptiveExpectedValue() = "get" + getToken().getName() + "()";
void ReadFromMqttDefinition.generateAspect(StringBuilder sb) { // eq WriteToMqttDefinition.preemptiveExpectedValue() = lastValue();
sb.append(ind(1)).append("public void ").append(getToken().containingTypeDecl().getName()).append(".") //
.append(connectMethod()).append("(String topic) {\n"); // syn String TokenUpdateDefinition.preemptiveReturnStatement();
sb.append(ind(2)).append(mqttUpdaterAttribute()).append("().newConnection(topic, message -> {\n"); // eq ReadFromMqttDefinition.preemptiveReturnStatement() = "return;";
String lastResult = generateMappingApplication(sb, 3, "message"); // eq WriteToMqttDefinition.preemptiveReturnStatement() = "return false;";
if (loggingEnabledForReads) { //
sb.append(ind(3)).append("System.out.println(\"[Read] \" + topic + \" -> ") // @Override
.append(getToken().getName()).append(" = \" + ").append(lastResult) // void ReadFromMqttDefinition.generateAspect(StringBuilder sb) {
.append(");\n"); // sb.append(ind(1)).append("public void ").append(getToken().containingTypeDecl().getName()).append(".")
} // .append(connectMethod()).append("(String topic) {\n");
sb.append(ind(3)).append("set").append(getToken().getName()).append("(").append(lastResult).append(");\n"); // sb.append(ind(2)).append(mqttUpdaterAttribute()).append("().newConnection(topic, message -> {\n");
sb.append(ind(2)).append("});\n"); // String lastResult = generateMappingApplication(sb, 3, "message");
sb.append(ind(1)).append("}\n\n"); // if (loggingEnabledForReads) {
} // sb.append(ind(3)).append("System.out.println(\"[Read] \" + topic + \" -> ")
// .append(getToken().getName()).append(" = \" + ").append(lastResult)
@Override // .append(");\n");
void WriteToMqttDefinition.generateAspect(StringBuilder sb) { // }
String parentTypeName = getToken().containingTypeDecl().getName(); // sb.append(ind(3)).append("set").append(getToken().getName()).append("(").append(lastResult).append(");\n");
// fields // sb.append(ind(2)).append("});\n");
sb.append(ind(1)).append("private String ").append(parentTypeName).append(".") // sb.append(ind(1)).append("}\n\n");
.append(writeTopic()).append(" = null;\n"); // }
sb.append(ind(1)).append("private byte[] ").append(parentTypeName).append(".") //
.append(lastValue()).append(" = null;\n"); // @Override
// void WriteToMqttDefinition.generateAspect(StringBuilder sb) {
// connect method // String parentTypeName = getToken().containingTypeDecl().getName();
sb.append(ind(1)).append("public void ").append(parentTypeName).append(".") // // fields
.append(connectMethod()).append("(String topic, boolean writeCurrentValue) {\n"); // sb.append(ind(1)).append("private String ").append(parentTypeName).append(".")
sb.append(ind(2)).append(writeTopic()).append(" = topic;\n"); // .append(writeTopic()).append(" = null;\n");
sb.append(ind(2)).append(updateMethod()).append("();\n"); // sb.append(ind(1)).append("private byte[] ").append(parentTypeName).append(".")
sb.append(ind(2)).append("if (writeCurrentValue) {\n"); // .append(lastValue()).append(" = null;\n");
sb.append(ind(3)).append(writeMethod()).append("();\n"); //
sb.append(ind(2)).append("}\n"); // // connect method
sb.append(ind(1)).append("}\n\n"); // sb.append(ind(1)).append("public void ").append(parentTypeName).append(".")
// .append(connectMethod()).append("(String topic, boolean writeCurrentValue) {\n");
// update method // sb.append(ind(2)).append(writeTopic()).append(" = topic;\n");
sb.append(ind(1)).append("protected boolean ").append(parentTypeName).append(".") // sb.append(ind(2)).append(updateMethod()).append("();\n");
.append(updateMethod()).append("() {\n");