GitLab update scheduled for Friday, October 22th between 08:15 and 08:45 CEST. If unpleasant, please contact René or Martin.

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

Extracting mqtt aspect for tiny template.

parent f8eb816f
Pipeline #6964 passed with stages
in 6 minutes and 20 seconds
......@@ -20,7 +20,7 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.8'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
// api 'org.jastadd:jastadd:2.3.4'
runtime 'org.jastadd:jastadd:2.3.4'
implementation 'org.jastadd:jastadd:2.3.4'
api group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
}
......
aspect Configuration {
public static boolean ASTNode.loggingEnabledForReads = false;
public static boolean ASTNode.loggingEnabledForWrites = false;
protected static TypeDecl ASTNode.rootNode;
}
......@@ -52,52 +52,38 @@ aspect AspectGeneration {
public String Ros2Rag.generateAspect(String rootNodeName) {
StringBuilder sb = new StringBuilder();
TypeDecl rootNode = getProgram().resolveTypeDecl(rootNodeName);
generateMqttAspect(sb, rootNode);
rootNode = getProgram().resolveTypeDecl(rootNodeName);
generateMqttAspect(sb);
generateGrammarExtension(sb);
return sb.toString();
}
public void Ros2Rag.generateMqttAspect(StringBuilder sb, TypeDecl rootNode) {
String rootNodeName = rootNode.getName();
sb.append("aspect MQTT {\n");
sb.append(ind(1)).append("private MqttUpdater ").append(rootNodeName)
.append(".").append(mqttUpdaterField()).append(" = new MqttUpdater();\n");
// mqttSetHost(String host)
sb.append(ind(1)).append("public void ").append(rootNodeName).append(".")
.append(mqttSetHostMethod()).append("(String host) throws java.io.IOException {\n");
sb.append(ind(2)).append(mqttUpdaterField()).append(".setHost(host);\n");
sb.append(ind(1)).append("}\n");
// mqttSetHost(String host, int port)
sb.append(ind(1)).append("public void ").append(rootNodeName).append(".")
.append(mqttSetHostMethod()).append("(String host, int port) throws java.io.IOException {\n");
sb.append(ind(2)).append(mqttUpdaterField()).append(".setHost(host, port);\n");
sb.append(ind(1)).append("}\n\n");
// mqttWaitUntilReady
sb.append(ind(1)).append("public boolean ").append(rootNodeName).append(".")
.append(mqttWaitUntilReadyMethod()).append("(long time, java.util.concurrent.TimeUnit unit) {\n");
sb.append(ind(2)).append("return ").append(mqttUpdaterField()).append(".waitUntilReady(time, unit);\n");
sb.append(ind(1)).append("}\n\n");
// mqttClose
sb.append(ind(1)).append("public void ").append(rootNodeName).append(".")
.append(mqttCloseMethod()).append("() {\n");
sb.append(ind(2)).append(mqttUpdaterField()).append(".close();\n");
sb.append(ind(1)).append("}\n\n");
public void Ros2Rag.generateMqttAspect(StringBuilder sb) {
org.jastadd.tinytemplate.TinyTemplate tt;
try {
tt = new org.jastadd.tinytemplate.TinyTemplate();
tt.loadTemplates(Ros2Rag.class.getClassLoader().getResourceAsStream("mqtt.tt"));
} catch (org.jastadd.tinytemplate.TemplateParser.SyntaxError e) {
e.printStackTrace();
return;
}
org.jastadd.tinytemplate.SimpleContext context = new org.jastadd.tinytemplate.SimpleContext(tt, this);
context.bind("rootNodeName", rootNode.getName());
context.bind("RootTypeChildrenMqtt", emitRootTypeChildrenMqtt(tt));
context.expand(context, "Ros2Rag.mqtt", sb);
}
// mqttUpdater
sb.append(ind(1)).append("inh MqttUpdater ASTNode.").append(mqttUpdaterAttribute()).append("();\n");
public String Ros2Rag.emitRootTypeChildrenMqtt(org.jastadd.tinytemplate.TinyTemplate tt) {
StringBuilder sb = new StringBuilder();
org.jastadd.tinytemplate.SimpleContext context = new org.jastadd.tinytemplate.SimpleContext(tt, this);
context.bind("rootNodeName", rootNode.getName());
for (Component child : rootNode.getComponentList()) {
if (child.isTypeComponent()) {
sb.append(ind(1)).append("eq ").append(rootNodeName)
.append(".get").append(child.getName()).append("().")
.append(mqttUpdaterAttribute()).append("() = ").append(mqttUpdaterField()).append(";\n");
context.bind("Name", child.getName());
context.expand(context, "TypeComponent.mqtt", sb);
}
}
sb.append("}\n\n");
return sb.toString();
}
public void Ros2Rag.generateGrammarExtension(StringBuilder sb) {
......
Ros2Rag.mqtt [[
aspect MQTT {
private MqttUpdater $rootNodeName.#(mqttUpdaterField) = new MqttUpdater();
public void $rootNodeName.#(mqttSetHostMethod)(String host) throws java.io.IOException {
#(mqttUpdaterField).setHost(host);
}
public void $rootNodeName.#(mqttSetHostMethod)(String host, int port) throws java.io.IOException {
#(mqttUpdaterField).setHost(host, port);
}
public boolean $rootNodeName.#(mqttWaitUntilReadyMethod)(long time, java.util.concurrent.TimeUnit unit) {
return #(mqttUpdaterField).waitUntilReady(time, unit);
}
public void $rootNodeName.#(mqttCloseMethod)() {
#(mqttUpdaterField).close();
}
inh MqttUpdater ASTNode.#(mqttUpdaterAttribute)();
$RootTypeChildrenMqtt
}
]]
TypeComponent.mqtt [[
eq $rootNodeName.get$(Name)().#(mqttUpdaterAttribute)() = #(mqttUpdaterField);
]]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment