Skip to content

Commit 892ef54

Browse files
committed
annotations can now accept any literal + fix in JS sessions
1 parent 9c06202 commit 892ef54

File tree

47 files changed

+262
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+262
-140
lines changed

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>org.thingml.root</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.m2e.core.maven2Builder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
16+
</natures>
17+
</projectDescription>

compilers/framework/src/test/java/org/thingml/compliers/tests/LoadModelTestsCommon.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.thingml.xtext.thingML.PrimitiveType;
3636
import org.thingml.xtext.thingML.ProvidedPort;
3737
import org.thingml.xtext.thingML.State;
38+
import org.thingml.xtext.thingML.StringLiteral;
3839
import org.thingml.xtext.thingML.Thing;
3940
import org.thingml.xtext.thingML.ThingMLModel;
4041
import org.thingml.xtext.thingML.Type;
@@ -44,7 +45,7 @@ public abstract class LoadModelTestsCommon {
4445
/* --- Some helper functions --- */
4546
private void checkAnnotation(AnnotatedElement e, String type, String name, String value) {
4647
for (PlatformAnnotation a : e.getAnnotations()) {
47-
if (a.getName().equals(name) && a.getValue().equals(value))
48+
if (a.getName().equals(name) && ((StringLiteral)a.getValue()).getStringValue().equals(value))
4849
return;
4950
}
5051
fail("'"+type+"' has annotation @"+name+"='"+value+"'");

compilers/javascript/src/main/java/org/thingml/compilers/javascript/JSThingImplCompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void generateImplementation(Thing thing, Context ctx) {
7979
if (ctx.hasContextAnnotation("use_fifo", "true")) {
8080
body.append("this.fifo = fifo;");
8181
} else {
82-
body.append("this.bus = (root === null)? new EventEmitter() : this.root.bus;");
82+
body.append("this.bus = (root === null)? new EventEmitter() : root.bus;");
8383
}
8484

8585
// Common constructor body

compilers/official-network-plugins/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@
5454
<artifactId>compilers.framework</artifactId>
5555
<version>${thingml.version}</version>
5656
</dependency>
57-
<dependency>
58-
<groupId>org.thingml</groupId>
59-
<artifactId>compilers.debugGUI</artifactId>
60-
<version>${thingml.version}</version>
61-
</dependency>
6257
<dependency>
6358
<groupId>org.thingml</groupId>
6459
<artifactId>compilers.registry</artifactId>

compilers/official-network-plugins/src/main/java/org/thingml/networkplugins/c/posix/PosixMQTTPlugin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.thingml.xtext.thingML.PlatformAnnotation;
4242
import org.thingml.xtext.thingML.Port;
4343
import org.thingml.xtext.thingML.Protocol;
44+
import org.thingml.xtext.thingML.StringLiteral;
4445
import org.thingml.xtext.thingML.Thing;
4546
import org.thingml.xtext.thingML.ThingMLFactory;
4647
import org.thingml.xtext.thingML.impl.ThingMLFactoryImpl;
@@ -82,7 +83,9 @@ private void addDependencies() {
8283
factory = ThingMLFactoryImpl.init();
8384
PlatformAnnotation pan = factory.createPlatformAnnotation();
8485
pan.setName("add_c_libraries");
85-
pan.setValue("mosquitto");
86+
final StringLiteral lit = factory.createStringLiteral();
87+
lit.setStringValue("mosquitto");
88+
pan.setValue(lit);
8689
cfg.getAnnotations().add(pan);
8790
}
8891
}

compilers/official-network-plugins/src/main/java/org/thingml/networkplugins/c/posix/PosixTelluCloudSerializerPlugin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.thingml.xtext.thingML.Message;
3131
import org.thingml.xtext.thingML.Parameter;
3232
import org.thingml.xtext.thingML.PlatformAnnotation;
33+
import org.thingml.xtext.thingML.StringLiteral;
34+
import org.thingml.xtext.thingML.ThingMLFactory;
3335
import org.thingml.xtext.thingML.impl.ParameterImpl;
3436

3537
/**
@@ -165,7 +167,9 @@ public String generateSerialization(StringBuilder builder, String bufferName, Me
165167
// Set the @json_message_name annotation
166168
PlatformAnnotation jsonMsgName = EcoreUtil.copy(msg.getAnnotations().get(0));
167169
jsonMsgName.setName("json_message_name");
168-
jsonMsgName.setValue("observation");
170+
final StringLiteral lit = ThingMLFactory.eINSTANCE.createStringLiteral();
171+
lit.setStringValue("observation");
172+
jsonMsgName.setValue(lit);
169173
msg.getAnnotations().add(jsonMsgName);
170174

171175
// Generate JSON serialisation of modified message

compilers/official-network-plugins/src/main/java/org/thingml/networkplugins/c/posix/PosixWebSocketPlugin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.thingml.xtext.thingML.PlatformAnnotation;
3939
import org.thingml.xtext.thingML.Port;
4040
import org.thingml.xtext.thingML.Protocol;
41+
import org.thingml.xtext.thingML.StringLiteral;
4142
import org.thingml.xtext.thingML.Thing;
4243
import org.thingml.xtext.thingML.ThingMLFactory;
4344
import org.thingml.xtext.thingML.impl.ThingMLFactoryImpl;
@@ -78,7 +79,9 @@ private void addDependencies() {
7879
factory = ThingMLFactoryImpl.init();
7980
PlatformAnnotation pan = factory.createPlatformAnnotation();
8081
pan.setName("add_c_libraries");
81-
pan.setValue("websockets");
82+
final StringLiteral lit = factory.createStringLiteral();
83+
lit.setStringValue("websockets");
84+
pan.setValue(lit);
8285
cfg.getAnnotations().add(pan);
8386
}
8487
}

compilers/registry/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@
5858
<version>${thingml.version}</version>
5959
</dependency>
6060

61-
<dependency>
62-
<groupId>org.thingml</groupId>
63-
<artifactId>compilers.debugGUI</artifactId>
64-
<version>${thingml.version}</version>
65-
</dependency>
66-
6761
<dependency>
6862
<groupId>org.thingml</groupId>
6963
<artifactId>compilers.go</artifactId>

compilers/thingmltools/src/main/java/org/thingml/monitor/BinaryMonitorGenerator.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.thingml.thingmltools.ThingMLTool;
3131
import org.thingml.xtext.constraints.ThingMLHelpers;
3232
import org.thingml.xtext.helpers.AnnotatedElementHelper;
33+
import org.thingml.xtext.thingML.ByteLiteral;
3334
import org.thingml.xtext.thingML.Function;
3435
import org.thingml.xtext.thingML.Handler;
3536
import org.thingml.xtext.thingML.Import;
@@ -123,40 +124,52 @@ public boolean compile(ThingMLModel model, String... options) {
123124
final Message m = (Message) o;
124125
final PlatformAnnotation ma = ThingMLFactory.eINSTANCE.createPlatformAnnotation();
125126
ma.setName("id");
126-
ma.setValue(Byte.toString(ByteHelper.messageID()));
127+
final ByteLiteral id = ThingMLFactory.eINSTANCE.createByteLiteral();
128+
id.setByteValue(ByteHelper.messageID());
129+
ma.setValue(id);
127130
m.getAnnotations().add(ma);
128131
} else if (o instanceof Port) {
129132
final Port port = (Port) o;
130133
final PlatformAnnotation ma = ThingMLFactory.eINSTANCE.createPlatformAnnotation();
131134
ma.setName("id");
132-
ma.setValue(Byte.toString(ByteHelper.portID()));
135+
final ByteLiteral id = ThingMLFactory.eINSTANCE.createByteLiteral();
136+
id.setByteValue(ByteHelper.messageID());
137+
ma.setValue(id);
133138
port.getAnnotations().add(ma);
134139
}else if (o instanceof Thing) {
135140
final Thing thing = (Thing) o;
136141
if (AnnotatedElementHelper.isDefined(thing, "monitor", "not") || !AnnotatedElementHelper.hasAnnotation(thing, "monitor")) continue;
137142
final PlatformAnnotation ma = ThingMLFactory.eINSTANCE.createPlatformAnnotation();
138143
ma.setName("id");
139-
ma.setValue(Byte.toString(ByteHelper.thingID()));
144+
final ByteLiteral id = ThingMLFactory.eINSTANCE.createByteLiteral();
145+
id.setByteValue(ByteHelper.messageID());
146+
ma.setValue(id);
140147
thing.getAnnotations().add(ma);
141148
} else if (o instanceof Function) {
142149
final Function f = (Function) o;
143150
if (f.isAbstract() || AnnotatedElementHelper.isDefined(f, "monitor", "not")) continue;
144151
final PlatformAnnotation ma = ThingMLFactory.eINSTANCE.createPlatformAnnotation();
145152
ma.setName("id");
146-
ma.setValue(Byte.toString(ByteHelper.functionID()));
153+
final ByteLiteral id = ThingMLFactory.eINSTANCE.createByteLiteral();
154+
id.setByteValue(ByteHelper.messageID());
155+
ma.setValue(id);
147156
f.getAnnotations().add(ma);
148157
} else if (o instanceof Property) {
149158
final Property p = (Property) o;
150159
if (AnnotatedElementHelper.isDefined(p, "monitor", "not")) continue;
151160
final PlatformAnnotation ma = ThingMLFactory.eINSTANCE.createPlatformAnnotation();
152161
ma.setName("id");
153-
ma.setValue(Byte.toString(ByteHelper.varID()));
162+
final ByteLiteral id = ThingMLFactory.eINSTANCE.createByteLiteral();
163+
id.setByteValue(ByteHelper.messageID());
164+
ma.setValue(id);
154165
p.getAnnotations().add(ma);
155166
} else if (o instanceof Handler) {
156167
final Handler h = (Handler) o;
157168
final PlatformAnnotation ma = ThingMLFactory.eINSTANCE.createPlatformAnnotation();
158169
ma.setName("id");
159-
ma.setValue(Byte.toString(ByteHelper.handlerID()));
170+
final ByteLiteral id = ThingMLFactory.eINSTANCE.createByteLiteral();
171+
id.setByteValue(ByteHelper.messageID());
172+
ma.setValue(id);
160173
h.getAnnotations().add(ma);
161174
}
162175
}

compilers/uml/src/main/java/org/thingml/compilers/uml/PlantUMLCfgMainGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,11 @@ public void generateMainAndInit(Configuration cfg, ThingMLModel model, Context c
281281
datatypes.append("note bottom of " + t.getName() + " : ");
282282
for(PlatformAnnotation a : t.getAnnotations()) {
283283
datatypes.append("<b>@" + a.getName() + "</b>");
284-
if (a.getValue() != null) {
285-
if (a.getValue().length() > 16 || a.getValue().contains("\n"))
284+
if (AnnotatedElementHelper.toString(a.getValue()) != null) {
285+
if (AnnotatedElementHelper.toString(a.getValue()).length() > 16 || AnnotatedElementHelper.toString(a.getValue()).contains("\n"))
286286
datatypes.append(" <color:royalBlue>\"...\"</color>\\n");
287287
else
288-
datatypes.append(" <color:royalBlue>\"" + a.getValue().replace("\n", "\\n") + "\"</color>\\n");
288+
datatypes.append(" <color:royalBlue>\"" + AnnotatedElementHelper.toString(a.getValue()).replace("\n", "\\n") + "\"</color>\\n");
289289
}
290290
}
291291
if (t.getAnnotations().size() > 0)

0 commit comments

Comments
 (0)