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

Merge branch 'rest' into 'master'

Rest

Closes #24

See merge request jastadd/ros2rag!5
parents 2b5156d5 29847fd7
Pipeline #7593 passed with stages
in 6 minutes and 29 seconds
......@@ -5,3 +5,4 @@
.classpath
.idea/
.gradle/
build/
......@@ -69,19 +69,12 @@ task relast(type: JavaExec) {
group = 'Build'
main = "-jar"
doFirst {
delete "src/gen/jastadd/*.ast"
delete "src/gen/jastadd/RagConnect.jadd"
delete "src/gen/jastadd/RagConnectRefResolver.jadd"
delete "src/gen/jastadd/RagConnectResolverStubs.jrag"
mkdir "src/gen/jastadd/"
}
args = [
"../libs/relast.jar",
"../relast.preprocessor/src/main/jastadd/RelAst.relast",
"./src/main/jastadd/RagConnect.relast",
"./src/main/jastadd/MustacheNodes.relast",
"./src/main/jastadd/YAML.relast",
"--listClass=java.util.ArrayList",
"--jastAddList=JastAddList",
"--useJastAddNames",
......@@ -90,14 +83,15 @@ task relast(type: JavaExec) {
"--grammarName=./src/gen/jastadd/RagConnect"
]
inputs.files file("../libs/relast.jar"),
file("../relast.preprocessor/src/main/jastadd/RelAST.relast"),
file("./src/main/jastadd/RagConnect.relast")
file("./src/main/jastadd/MustacheNodes.relast")
outputs.files file("./src/gen/jastadd/RagConnect.ast"),
file("./src/gen/jastadd/RagConnect.jadd"),
file("./src/gen/jastadd/RagConnectRefResolver.jadd"),
file('./src/gen/jastadd/RagConnectResolverStubs.jrag')
inputs.files("../libs/relast.jar",
"../relast.preprocessor/src/main/jastadd/RelAst.relast",
"./src/main/jastadd/RagConnect.relast",
"./src/main/jastadd/MustacheNodes.relast",
"./src/main/jastadd/YAML.relast")
outputs.files("./src/gen/jastadd/RagConnect.ast",
"./src/gen/jastadd/RagConnect.jadd",
"./src/gen/jastadd/RagConnectRefResolver.jadd",
'./src/gen/jastadd/RagConnectResolverStubs.jrag')
}
jastadd {
......
aspect Analysis {
// --- lookupTokenEndpointDefinition ---
inh TokenEndpointDefinition TokenEndpointDefinition.lookupTokenEndpointDefinition(TokenComponent token);
eq RagConnect.getEndpointDefinition().lookupTokenEndpointDefinition(TokenComponent token) {
inh java.util.List<TokenEndpointDefinition> TokenEndpointDefinition.lookupTokenEndpointDefinitions(TokenComponent token);
eq RagConnect.getEndpointDefinition().lookupTokenEndpointDefinitions(TokenComponent token) = lookupTokenEndpointDefinitions(token);
syn java.util.List<TokenEndpointDefinition> RagConnect.lookupTokenEndpointDefinitions(TokenComponent token) {
java.util.List<TokenEndpointDefinition> result = new java.util.ArrayList<>();
for (EndpointDefinition def : getEndpointDefinitionList()) {
if (def.isTokenEndpointDefinition() && def.asTokenEndpointDefinition().getToken().equals(token)) {
return def.asTokenEndpointDefinition();
result.add(def.asTokenEndpointDefinition());
}
}
return null;
return result;
}
// --- lookupDependencyDefinition ---
......@@ -22,6 +24,34 @@ aspect Analysis {
}
// --- isAlreadyDefined ---
syn boolean TokenEndpointDefinition.isAlreadyDefined() = lookupTokenEndpointDefinition(getToken()) != this;
syn boolean TokenEndpointDefinition.isAlreadyDefined() = lookupTokenEndpointDefinitions(getToken()).size() > 1;
syn boolean DependencyDefinition.isAlreadyDefined() = lookupDependencyDefinition(getSource().containingTypeDecl(), getID()) != this;
syn boolean MappingDefinitionType.assignableTo(JavaTypeUse target);
eq JavaMappingDefinitionType.assignableTo(JavaTypeUse target) = getType().assignableTo(target);
eq JavaArrayMappingDefinitionType.assignableTo(JavaTypeUse target) {
if (!target.getName().endsWith("[]")) { return false; }
return getType().assignableTo(new SimpleJavaTypeUse(target.getName().replace("[]", "")));
}
syn boolean JavaTypeUse.assignableTo(JavaTypeUse target) {
// target var = this;
return target.primitivePrettyPrint().equals(this.primitivePrettyPrint());
}
syn String JavaTypeUse.primitivePrettyPrint() {
switch(getName()) {
case "int":
case "Integer": return "int";
case "short":
case "Short": return "short";
case "long":
case "Long": return "long";
case "float":
case "Float": return "float";
case "double":
case "Double": return "double";
case "char":
case "Character": return "char";
default: return getName();
}
}
}
......@@ -7,32 +7,32 @@ aspect Errors {
[new TreeSet<ErrorMessage>()]
root RagConnect;
ReceiveFromMqttDefinition contributes error("Receive definition already defined for " + getToken().getName())
ReceiveTokenEndpointDefinition contributes error("Receive definition already defined for " + getToken().getName())
when isAlreadyDefined()
to RagConnect.errors();
ReceiveFromMqttDefinition contributes error("Receiving target token must not be an NTA token!")
ReceiveTokenEndpointDefinition contributes error("Receiving target token must not be an NTA token!")
when getToken().getNTA()
to RagConnect.errors();
// if first mapping is null, then suitableDefaultMapping() == null
ReceiveFromMqttDefinition contributes error("No suitable default mapping found for type " +
ReceiveTokenEndpointDefinition contributes error("No suitable default mapping found for type " +
((getMappingList().isEmpty())
? getToken().getJavaTypeUse().prettyPrint()
? getToken().effectiveJavaTypeUse().prettyPrint()
: getMappingList().get(0).getFromType().prettyPrint()))
when effectiveMappings().get(0) == null
to RagConnect.errors();
ReceiveFromMqttDefinition contributes error("to-type of last mapping must be type of the Token!")
when getToken().getJavaTypeUse().prettyPrint().equals(
effectiveMappings().get(effectiveMappings().size() - 1))
ReceiveTokenEndpointDefinition contributes error("to-type of last mapping (" + effectiveMappings().get(effectiveMappings().size() - 1).getToType().prettyPrint() + ") not assignable to type of the Token (" + getToken().effectiveJavaTypeUse().prettyPrint() + ")!")
when !effectiveMappings().get(effectiveMappings().size() - 1).getToType().assignableTo(
getToken().effectiveJavaTypeUse())
to RagConnect.errors();
SendToMqttDefinition contributes error("Sending target token must be an NTA token!")
SendTokenEndpointDefinition contributes error("Sending target token must be an NTA token!")
when !getToken().getNTA()
to RagConnect.errors();
SendToMqttDefinition contributes error("Send definition already defined for " + getToken().getName())
SendTokenEndpointDefinition contributes error("Send definition already defined for " + getToken().getName())
when isAlreadyDefined()
to RagConnect.errors();
......@@ -44,7 +44,7 @@ aspect Errors {
when isAlreadyDefinedAsList()
to RagConnect.errors();
DependencyDefinition contributes error("There must be a send update definition targeting " + getSource().parentTypeypeAndName() + " for dependency definition " + getID())
DependencyDefinition contributes error("There must be a send endpoint definition targeting " + getSource().parentTypeypeAndName() + " for dependency definition " + getID())
when targetEndpointDefinition() == null
to RagConnect.errors();
}
......
//TypeComponentMustache ;
//rel TypeComponentMustache.TypeComponent -> TypeComponent ;
MRagConnect ::= ReceiveDefinition:MReceiveDefinition* SendDefinition:MSendDefinition* MappingDefinition:MMappingDefinition* DependencyDefinition:MDependencyDefinition* RootTypeComponent:MTypeComponent* TokenComponent:MTokenComponent*;
abstract MEndpointDefinition ::= InnerMappingDefinition:MInnerMappingDefinition*;
MReceiveDefinition : MEndpointDefinition;
......@@ -12,9 +9,9 @@ MTypeComponent;
MTokenComponent;
rel MRagConnect.RagConnect -> RagConnect;
rel MInnerMappingDefinition.MappingDefinition -> MappingDefinition;
rel MReceiveDefinition.ReceiveFromMqttDefinition -> ReceiveFromMqttDefinition;
rel MSendDefinition.SendToMqttDefinition -> SendToMqttDefinition;
rel MInnerMappingDefinition.MMappingDefinition -> MMappingDefinition;
rel MReceiveDefinition.ReceiveTokenEndpointDefinition -> ReceiveTokenEndpointDefinition;
rel MSendDefinition.SendTokenEndpointDefinition -> SendTokenEndpointDefinition;
rel MMappingDefinition.MappingDefinition -> MappingDefinition;
rel MDependencyDefinition.DependencyDefinition -> DependencyDefinition;
rel MTypeComponent.TypeComponent -> TypeComponent;
......
......@@ -10,9 +10,12 @@ aspect Navigation {
eq MRagConnect.getChild().ragconnect() = getRagConnect();
// --- containedFile
eq Grammar.getChild().containedFile() = null;
eq RagConnect.getChild().containedFile() = null;
eq MRagConnect.getChild().containedFile() = null;
// --- containedFileName ---
eq Grammar.getChild().containedFileName() = null; // should be in PP
eq RagConnect.getChild().containedFileName() = getFileName();
eq MRagConnect.getChild().containedFileName() = null;
......@@ -24,30 +27,33 @@ aspect Navigation {
syn TokenEndpointDefinition EndpointDefinition.asTokenEndpointDefinition() = null;
eq TokenEndpointDefinition.asTokenEndpointDefinition() = this;
// --- isSendToMqttDefinition ---
syn boolean EndpointDefinition.isSendToMqttDefinition() = false;
eq SendToMqttDefinition.isSendToMqttDefinition() = true;
// --- isSendTokenEndpointDefinition ---
syn boolean EndpointDefinition.isSendTokenEndpointDefinition() = false;
eq SendTokenEndpointDefinition.isSendTokenEndpointDefinition() = true;
// --- asSendToMqttDefinition ---
syn SendToMqttDefinition EndpointDefinition.asSendToMqttDefinition() = null;
eq SendToMqttDefinition.asSendToMqttDefinition() = this;
// --- asSendTokenEndpointDefinition ---
syn SendTokenEndpointDefinition EndpointDefinition.asSendTokenEndpointDefinition() = null;
eq SendTokenEndpointDefinition.asSendTokenEndpointDefinition() = this;
// --- asReceiveFromMqttDefinition ---
syn ReceiveFromMqttDefinition EndpointDefinition.asReceiveFromMqttDefinition() = null;
eq ReceiveFromMqttDefinition.asReceiveFromMqttDefinition() = this;
// --- asReceiveTokenEndpointDefinition ---
syn ReceiveTokenEndpointDefinition EndpointDefinition.asReceiveTokenEndpointDefinition() = null;
eq ReceiveTokenEndpointDefinition.asReceiveTokenEndpointDefinition() = this;
// --- targetEndpointDefinition ---
syn SendToMqttDefinition DependencyDefinition.targetEndpointDefinition() {
syn SendTokenEndpointDefinition DependencyDefinition.targetEndpointDefinition() {
// resolve definition in here, as we do not need resolveMethod in any other place (yet)
for (EndpointDefinition endpointDefinition : ragconnect().getEndpointDefinitionList()) {
if (endpointDefinition.isSendToMqttDefinition() &&
endpointDefinition.asSendToMqttDefinition().getToken().equals(this.getTarget())) {
return endpointDefinition.asSendToMqttDefinition();
if (endpointDefinition.isSendTokenEndpointDefinition() &&
endpointDefinition.asSendTokenEndpointDefinition().getToken().equals(this.getTarget())) {
return endpointDefinition.asSendTokenEndpointDefinition();
}
}
return null;
}
// --- effectiveJavaTypeUse (should be in preprocessor) ---
syn lazy JavaTypeUse TokenComponent.effectiveJavaTypeUse() = hasJavaTypeUse() ? getJavaTypeUse() : new SimpleJavaTypeUse("String");
// --- isDefaultMappingDefinition ---
syn boolean MappingDefinition.isDefaultMappingDefinition() = false;
eq DefaultMappingDefinition.isDefaultMappingDefinition() = true;
......
aspect Printing {
String ASTNode.PRINT_INDENT = " ";
syn String MappingDefinitionType.prettyPrint();
eq JavaMappingDefinitionType.prettyPrint() = getType().getName();
eq JavaArrayMappingDefinitionType.prettyPrint() = getType().getName() + "[]";
syn String JavaTypeUse.prettyPrint() {
StringBuilder sb = new StringBuilder();
generateAbstractGrammar(sb);
return sb.toString();
}
syn String Document.prettyPrint() {
StringBuilder sb = new StringBuilder();
sb.append("# RagConnect created at ").append(java.time.Instant.now()).append("\n");
for (ComplexElement element : getComplexElementList()) {
element.prettyPrint(sb, false, "");
}
if (sb.charAt(sb.length() - 1) != '\n') {
sb.append("\n");
}
return sb.toString();
}
syn StringBuilder Element.prettyPrint(StringBuilder sb, boolean printIndent, String indent);
eq ValueElement.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
sb.append(getValue());
return sb;
}
eq StringElement.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
sb.append("\"").append(getValue()).append("\"");
return sb;
}
eq ListElement.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
if (isEmpty()) {
sb.append("[]");
} else {
for (Element element : getElementList()) {
sb.append(indent).append("- ");
element.prettyPrint(sb, false, indent + PRINT_INDENT);
sb.append("\n");
}
// delete last newline
sb.deleteCharAt(sb.length() - 1);
}
return sb;
}
eq KeyValuePair.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
if (printIndent) sb.append(indent);
sb.append(getKey()).append(": ");
if (getValue().isComplex() && !getValue().isEmpty()) {
sb.append("\n");
getValue().prettyPrint(sb, true, indent + PRINT_INDENT); //);
} else {
getValue().prettyPrint(sb, false, indent);
}
return sb;
}
eq MappingElement.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
if (isEmpty()) {
sb.append("{}");
} else {
boolean first = true;
for (KeyValuePair pair : getKeyValuePairList()) {
if (!first || printIndent) sb.append(indent);
first = false;
pair.prettyPrint(sb, false, indent); // + PRINT_INDENT
sb.append("\n");
}
// delete last newline
sb.deleteCharAt(sb.length() - 1);
}
return sb;
}
}
......@@ -2,13 +2,13 @@ RagConnect ::= EndpointDefinition* DependencyDefinition* MappingDefinition* Prog
abstract EndpointDefinition ::= <AlwaysApply:boolean> ;
rel EndpointDefinition.Mapping* -> MappingDefinition;
rel EndpointDefinition.Mapping* <-> MappingDefinition.UsedAt*;
abstract TokenEndpointDefinition : EndpointDefinition;
rel TokenEndpointDefinition.Token -> TokenComponent;
ReceiveFromMqttDefinition : TokenEndpointDefinition;
SendToMqttDefinition : TokenEndpointDefinition;
ReceiveTokenEndpointDefinition : TokenEndpointDefinition;
SendTokenEndpointDefinition : TokenEndpointDefinition;
DependencyDefinition ::= <ID>;
rel DependencyDefinition.Source <-> TokenComponent.DependencySourceDefinition*;
......
aspect Util {
static String ASTNode.capitalize(String s) {
return Character.toUpperCase(s.charAt(0)) + s.substring(1);
}
}
aspect Navigation {
eq Document.getChild().program() = null;
eq Document.getChild().ragconnect() = null;
eq Document.getChild().containedFile() = null;
eq Document.getChild().containedFileName() = getFileName();
syn boolean Element.isComplex() = false;
eq ComplexElement.isComplex() = true;
syn boolean Element.isEmpty() = false;
eq MappingElement.isEmpty() = getNumKeyValuePair() == 0;
eq ListElement.isEmpty() = getNumElement() == 0;
}
aspect Helper {
public static ValueElement ValueElement.of(int value) {
return new ValueElement(String.valueOf(value));
}
public static ValueElement ValueElement.of(boolean value) {
return new ValueElement(String.valueOf(value));
}
public static ValueElement ValueElement.of(String value) {
return new ValueElement(value);
}
public static StringElement StringElement.of(String value) {
return new StringElement(value);
}
public void MappingElement.addKeyValuePair(String key, Element value) {
addKeyValuePair(new KeyValuePair(key, value));
}
}
Document ::= <FileName> ComplexElement* ;
abstract Element ;
abstract ComplexElement : Element ;
MappingElement : ComplexElement ::= KeyValuePair* ;
KeyValuePair : ComplexElement ::= <Key> Value:Element ;
ListElement : ComplexElement ::= Element* ;
abstract SimpleElement : Element ;
ValueElement : SimpleElement ::= <Value> ;
StringElement : SimpleElement ::= <Value> ;
......@@ -2,4 +2,6 @@ aspect Configuration {
public static boolean ASTNode.loggingEnabledForReads = false;
public static boolean ASTNode.loggingEnabledForWrites = false;
public static TypeDecl ASTNode.rootNode;
public static boolean ASTNode.usesMqtt;
public static boolean ASTNode.usesRest;
}
aspect GenerationUtils {
public static final String ASTNode.aspectIndent = " ";
public String ASTNode.ind(int n) {
StringBuilder s = new StringBuilder();
for (int i = 0; i < n; i++) {
s.append(aspectIndent);
}
return s.toString();
}
// --- prettyPrint ---
syn String MappingDefinitionType.prettyPrint();
eq JavaMappingDefinitionType.prettyPrint() = getType().getName();
eq JavaArrayMappingDefinitionType.prettyPrint() = getType().getName() + "[]";
syn String JavaTypeUse.prettyPrint() {
StringBuilder sb = new StringBuilder();
generateAbstractGrammar(sb);
return sb.toString();
}
}
/* Open questions
- Should all string constants be defined on the normal AST, or on the special mustache AST?
/*
Design considerations
- InnerMappingDefinition needed for iteration attribute (first, last) - not easily possible with list-relation
*/
aspect AttributesForMustache {
// --- MRagConnect ---
eq MRagConnect.getChild().mqttHandlerAttribute() = mqttHandlerAttribute();
eq MRagConnect.getChild().mqttHandlerField() = mqttHandlerField();
eq MRagConnect.getRootTypeComponent(int i).isFirst() = i == 0;
syn String MRagConnect.mqttHandlerAttribute() = getRagConnect().mqttHandlerAttribute();
syn String MRagConnect.mqttHandlerField() = getRagConnect().mqttHandlerField();
syn String MRagConnect.mqttSetHostMethod() = getRagConnect().mqttSetHostMethod();
syn String MRagConnect.mqttWaitUntilReadyMethod() = getRagConnect().mqttWaitUntilReadyMethod();
syn String MRagConnect.mqttCloseMethod() = getRagConnect().mqttCloseMethod();
syn String MRagConnect.closeMethod() = "ragconnectCloseConnections";
syn String MRagConnect.mqttHandlerAttribute() = "_mqttHandler";
syn String MRagConnect.mqttHandlerField() = "_mqttHandler";
syn String MRagConnect.mqttSetupWaitUntilReadyMethod() = "ragconnectSetupMqttWaitUntilReady";
syn String MRagConnect.restHandlerAttribute() = "_restHandler";
syn String MRagConnect.restHandlerField() = "_restHandler";
// --- MEndpointDefinition ---
syn String MEndpointDefinition.preemptiveExpectedValue();
......@@ -44,29 +22,25 @@ aspect AttributesForMustache {
syn String MEndpointDefinition.firstInputVarName();
eq MEndpointDefinition.getInnerMappingDefinition(int i).isLast() = i == getNumInnerMappingDefinition() - 1;
eq MEndpointDefinition.getInnerMappingDefinition().resultVarPrefix() = resultVarPrefix();
eq MEndpointDefinition.getInnerMappingDefinition(int i).inputVarName() = i == 0 ? firstInputVarName() : resultVarPrefix() + getInnerMappingDefinition(i - 1).getMappingDefinition().methodName();
inh String MEndpointDefinition.mqttHandlerAttribute();
eq MEndpointDefinition.getInnerMappingDefinition(int i).inputVarName() = i == 0 ? firstInputVarName() : getInnerMappingDefinition(i - 1).outputVarName();
syn String MEndpointDefinition.connectMethod() = endpointDef().connectMethod();
syn String MEndpointDefinition.connectParameterName() = "uriString";
syn String MEndpointDefinition.connectMethod() = "connect" + tokenName();
syn TokenComponent MEndpointDefinition.token() = endpointDef().getToken();
syn boolean MEndpointDefinition.alwaysApply() = endpointDef().getAlwaysApply();
syn String MEndpointDefinition.resultVarPrefix() = "result"; // we do not need "_" here, because methodName begins with one
syn String MEndpointDefinition.parentTypeName() = token().containingTypeDecl().getName();
syn String MEndpointDefinition.tokenName() = token().getName();
syn MInnerMappingDefinition MEndpointDefinition.lastDefinition() = getInnerMappingDefinition(getNumInnerMappingDefinition() - 1);
syn String MEndpointDefinition.lastDefinitionToType() = lastDefinition().ToType();
syn String MEndpointDefinition.lastDefinitionName() = lastDefinition().methodName();
syn String MEndpointDefinition.lastResult() = resultVarPrefix() + lastDefinitionName();
syn String MEndpointDefinition.lastDefinitionToType() = lastDefinition().toType();
syn String MEndpointDefinition.lastResult() = lastDefinition().outputVarName();
syn String MEndpointDefinition.condition() {
if (lastDefinition().getMappingDefinition().getToType().isArray()) {
if (lastDefinition().mappingDef().getToType().isArray()) {
return "java.util.Arrays.equals(" + preemptiveExpectedValue() + ", " + lastResult() + ")";
}
if (token().isPrimitiveType() && lastDefinition().getMappingDefinition().getToType().isPrimitiveType()) {
if (token().isPrimitiveType() && lastDefinition().mappingDef().getToType().isPrimitiveType()) {
return preemptiveExpectedValue() + " == " + lastResult();
}
if (lastDefinition().getMappingDefinition().isDefaultMappingDefinition()) {
if (lastDefinition().mappingDef().isDefaultMappingDefinition()) {
return preemptiveExpectedValue() + " != null && " + preemptiveExpectedValue() + ".equals(" + lastResult() + ")";
}
return preemptiveExpectedValue() + " != null ? " + preemptiveExpectedValue() + ".equals(" + lastResult() + ") : " + lastResult() + " == null";
......@@ -74,66 +48,67 @@ aspect AttributesForMustache {
// --- MInnerMappingDefinition ---
inh boolean MInnerMappingDefinition.isLast();
inh String MInnerMappingDefinition.resultVarPrefix();
syn String MInnerMappingDefinition.ToType() = getMappingDefinition().getToType().prettyPrint();
syn String MInnerMappingDefinition.methodName() = getMappingDefinition().methodName();
inh String MInnerMappingDefinition.inputVarName();
syn String MInnerMappingDefinition.toType() = mappingDef().getToType().prettyPrint();
syn String MInnerMappingDefinition.methodName() = getMMappingDefinition().methodName();
syn MappingDefinition MInnerMappingDefinition.mappingDef() = getMMappingDefinition().getMappingDefinition();
syn String MInnerMappingDefinition.outputVarName() = "result" + methodName(); // we do not need "_" in between here, because methodName begins with one
// --- MReceiveDefinition ---
eq MReceiveDefinition.preemptiveExpectedValue() = "get" + tokenName() + "()";
eq MReceiveDefinition.preemptiveReturn() = "return;";
eq MReceiveDefinition.endpointDef() = getReceiveFromMqttDefinition();
eq MReceiveDefinition.endpointDef() = getReceiveTokenEndpointDefinition();
eq MReceiveDefinition.firstInputVarName() = "message";
// --- MSendDefinition ---
eq MSendDefinition.preemptiveExpectedValue() = lastValue();
eq MSendDefinition.preemptiveReturn() = "return false;";
eq MSendDefinition.endpointDef() = getSendToMqttDefinition();
eq MSendDefinition.endpointDef() = getSendTokenEndpointDefinition();
eq MSendDefinition.firstInputVarName() = "get" + tokenName() + "()";
syn String MSendDefinition.sendTopic() = getSendToMqttDefinition().sendTopic();
syn String MSendDefinition.lastValue() = getSendToMqttDefinition().lastValue();
syn String MSendDefinition.updateMethod() = getSendToMqttDefinition().updateMethod();
syn String MSendDefinition.writeMethod() = getSendToMqttDefinition().writeMethod();
syn String MSendDefinition.tokenResetMethod() = getSendToMqttDefinition().tokenResetMethod();
syn String MSendDefinition.sender() = "_sender_" + tokenName();
syn String MSendDefinition.lastValue() = "_lastValue" + tokenName();
syn String MSendDefinition.updateMethod() = "_update_" + tokenName();
syn String MSendDefinition.writeMethod() = "_writeLastValue_" + tokenName();
syn String MSendDefinition.tokenResetMethod() = "get" + tokenName() + "_reset";
// --- MMappingDefinition ---
syn String MMappingDefinition.toType() = getMappingDefinition().getToType().prettyPrint();
syn String MMappingDefinition.methodName() = getMappingDefinition().methodName();
syn String MMappingDefinition.methodName() = "_apply_" + getMappingDefinition().getID();
syn String MMappingDefinition.fromType() = getMappingDefinition().getFromType().prettyPrint();
syn String MMappingDefinition.fromVariableName() = getMappingDefinition().getFromVariableName();
syn String MMappingDefinition.content() = getMappingDefinition().getContent();
// --- MDependencyDefinition ---
syn String MDependencyDefinition.targetParentTypeName() = getDependencyDefinition().getTarget().containingTypeDecl().getName();
syn String MDependencyDefinition.dependencyMethod() = getDependencyDefinition().dependencyMethod();
syn String MDependencyDefinition.dependencyMethod() = "add" + capitalize(getDependencyDefinition().getID());
syn String MDependencyDefinition.sourceParentTypeName() = getDependencyDefinition().getSource().containingTypeDecl().getName();
syn String MDependencyDefinition.internalRelationPrefix() = getDependencyDefinition().internalRelationPrefix();
syn nta MEndpointDefinition MDependencyDefinition.targetEndpointDefinition() {
syn String MDependencyDefinition.internalRelationPrefix() = "_internal_" + getDependencyDefinition().getID();
syn nta MSendDefinition MDependencyDefinition.targetEndpointDefinition() {
return getDependencyDefinition().targetEndpointDefinition().toMustache();
}
// --- MTypeComponent ---
syn String MTypeComponent.name() = getTypeComponent().getName();
inh String MTypeComponent.mqttHandlerAttribute();
inh String MTypeComponent.mqttHandlerField();
inh boolean MTypeComponent.isFirst();
// --- 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();
syn String MTokenComponent.javaType() = getTokenComponent().effectiveJavaTypeUse().prettyPrint();
syn String MTokenComponent.internalName() = getTokenComponent().getDependencySourceDefinitionList().isEmpty() ? externalName() : "_internal_" + name();
syn String MTokenComponent.externalName() = name();
// --- toMustache ---
syn lazy MRagConnect RagConnect.toMustache() {
MRagConnect result = new MRagConnect();
result.setRagConnect(this);
for (EndpointDefinition def : getEndpointDefinitionList()) {
if (def.isSendToMqttDefinition()) {
result.addSendDefinition(def.asSendToMqttDefinition().toMustache());
if (def.isSendTokenEndpointDefinition()) {
SendTokenEndpointDefinition sendDef = def.asSendTokenEndpointDefinition();
result.addSendDefinition(sendDef.toMustache());
} else {
result.addReceiveDefinition(def.asReceiveFromMqttDefinition().toMustache());
result.addReceiveDefinition(def.asReceiveTokenEndpointDefinition().toMustache());
}
}
for (MappingDefinition def : allMappingDefinitions()) {
......@@ -155,41 +130,46 @@ aspect AttributesForMustache {
return result;
}
//MInnerMappingDefinition.MappingDefinition -> MappingDefinition;
protected void MEndpointDefinition.addInnerMappings() {
for (MappingDefinition def : endpointDef().effectiveMappings()) {
MInnerMappingDefinition inner = new MInnerMappingDefinition();
inner.setMappingDefinition(def);
inner.setMMappingDefinition(def.toMustache());
addInnerMappingDefinition(inner);
}
}
syn lazy MReceiveDefinition ReceiveFromMqttDefinition.toMustache() {
syn lazy MReceiveDefinition ReceiveTokenEndpointDefinition.toMustache() {
MReceiveDefinition result = new MReceiveDefinition();
result.setReceiveFromMqttDefinition(this);
result.setReceiveTokenEndpointDefinition(this);
result.addInnerMappings();
return result;
}
syn lazy MSendDefinition SendToMqttDefinition.toMustache() {
syn lazy MSendDefinition SendTokenEndpointDefinition.toMustache() {
MSendDefinition result = new MSendDefinition();
result.setSendToMqttDefinition(this);
result.setSendTokenEndpointDefinition(this);
result.addInnerMappings();
return result;
}
syn lazy MMappingDefinition MappingDefinition.toMustache() {
MMappingDefinition result = new MMappingDefinition();
result.setMappingDefinition(this);
return result;
}
syn lazy MDependencyDefinition DependencyDefinition.toMustache() {
MDependencyDefinition result = new MDependencyDefinition();
result.setDependencyDefinition(this);
return result;
}
syn lazy MTypeComponent TypeComponent.toMustache() {
MTypeComponent result = new MTypeComponent();
result.setTypeComponent(this);
return result;
}