Skip to content

Commit 892ef54

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

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

+17
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

+2-1
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

+1-1
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

-5
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

+4-1
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

+5-1
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

+4-1
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

-6
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

+19-6
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

+3-3
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)

language/thingml.ui.tests/META-INF/MANIFEST.MF

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Require-Bundle: thingml.ui,
1212
org.eclipse.core.runtime,
1313
org.eclipse.ui.workbench;resolution:=optional,
1414
org.eclipse.xtext.testing,
15-
org.eclipse.xtext.xbase.testing
15+
org.eclipse.xtext.xbase.testing,
16+
org.eclipse.xtext.ui.testing
1617
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1718
Export-Package: org.thingml.xtext.ui.tests;x-internal=true
1819
Import-Package: org.hamcrest.core,

language/thingml.ui/src/org/thingml/xtext/ui/labeling/ThingMLLabelProvider.xtend

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import org.thingml.xtext.thingML.InternalTransition
3535
import org.thingml.xtext.thingML.ReceiveMessage
3636
import org.thingml.xtext.thingML.Handler
3737
import org.thingml.xtext.thingML.IntegerLiteral
38+
import org.thingml.xtext.helpers.AnnotatedElementHelper
3839

3940
/**
4041
* Provides labels for EObjects.
@@ -75,10 +76,10 @@ class ThingMLLabelProvider extends DefaultEObjectLabelProvider {
7576
'outline/open iconic/paperclip-2x.png'
7677
}
7778
def text(PlatformAnnotation annotation) {
78-
if (annotation.value.length < 16)
79-
annotation.name + ': ' + annotation.value
79+
if (AnnotatedElementHelper.toString(annotation.value).length < 16)
80+
annotation.name + ': ' + AnnotatedElementHelper.toString(annotation.value)
8081
else
81-
annotation.name + ': ' + annotation.value.substring(0, 16) + "..."
82+
annotation.name + ': ' + AnnotatedElementHelper.toString(annotation.value).substring(0, 16) + "..."
8283
}
8384

8485
def image(Type datatype) {

language/thingml/.classpath

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="src" path="src-gen"/>
54
<classpathentry kind="src" path="xtend-gen"/>
5+
<classpathentry kind="src" path="src-gen"/>
66
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
77
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
8+
<classpathentry kind="lib" path="antlr-generator-3.2.0-patch.jar"/>
89
<classpathentry kind="output" path="target/classes"/>
910
</classpath>

language/thingml/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.jar

language/thingml/README.MD

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- You need to manually download https://download.itemis.com/antlr-generator-3.2.0-patch.jar
2+
- In Eclipse, add it to your classpath
3+
4+
This file is no more distributed with XText (for Licensing issues) but is needed should you want to modify the language.

language/thingml/src/org/thingml/annotations/Annotation.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.eclipse.emf.ecore.EClass;
2020
import org.eclipse.emf.ecore.EObject;
21+
import org.thingml.xtext.thingML.Literal;
2122
import org.thingml.xtext.thingML.ThingMLPackage;
2223

2324
public class Annotation {
@@ -37,7 +38,7 @@ public String getName() {
3738
return name;
3839
}
3940

40-
public boolean check(EObject source, String value) {
41+
public boolean check(EObject source, Literal value) {
4142
for(EClass clazz : scope) {
4243
if (clazz.isInstance(source)) {
4344
return true;

language/thingml/src/org/thingml/annotations/AnnotationRegistry.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public class AnnotationRegistry {
237237
final String tc_name = "type_checker";
238238
final String tc_desc = "Specifies the abstract type of a ThingML-defined primitive type. Used by the type checker.";
239239
final EClass tc_scope[] = {ThingMLPackage.eINSTANCE.getType()};
240-
final String tc_values[] = {"Byte", "Integer", "Boolean", "Character", "String", "Real", "Void", "Object"};
240+
final String tc_values[] = {"Byte", "Integer", "Boolean", "Character", "String", "Real", "Void", "Object", "Any"};
241241
final Annotation tc_annotation = new EnumAnnotation(tc_name, tc_desc, tc_scope, tc_values);
242242
annotations.put(tc_name, tc_annotation);
243243

@@ -377,6 +377,27 @@ public class AnnotationRegistry {
377377
"Optional registry to publish NPM packages on other registries.",
378378
new EClass[] {ThingMLPackage.eINSTANCE.getConfiguration()}
379379
));
380+
381+
/** Testing **/
382+
annotations.put("test_onlything", new Annotation(
383+
"test_onlything",
384+
"Only for testing annotations. Please ignore.",
385+
new EClass[] {ThingMLPackage.eINSTANCE.getThing()}
386+
));
387+
388+
annotations.put("test_integer", new IntegerAnnotation(
389+
"test_integer",
390+
"Only for testing annotations. Please ignore.",
391+
new EClass[] {ThingMLPackage.eINSTANCE.getThing()},
392+
false
393+
));
394+
395+
annotations.put("test_enum", new EnumAnnotation(
396+
"test_enum",
397+
"Only for testing annotations. Please ignore.",
398+
new EClass[] {ThingMLPackage.eINSTANCE.getThing()},
399+
new String[] {"A", "B", "C"}
400+
));
380401
}
381402

382403
public static String toMD() {

language/thingml/src/org/thingml/annotations/EnumAnnotation.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import org.eclipse.emf.ecore.EClass;
2222
import org.eclipse.emf.ecore.EObject;
23+
import org.thingml.xtext.helpers.AnnotatedElementHelper;
24+
import org.thingml.xtext.thingML.Literal;
2325

2426
public class EnumAnnotation extends Annotation {
2527

@@ -29,12 +31,13 @@ public EnumAnnotation(String name, String description, EClass[] scope, String va
2931
super(name, description, scope);
3032
this.values = values;
3133
}
32-
34+
3335
@Override
34-
public boolean check(EObject source, String value) {
36+
public boolean check(EObject source, Literal value) {
3537
if (!super.check(source, value)) return false;
3638
for(String v : values) {
37-
if (value.equals(v)) {
39+
final String stringValue = AnnotatedElementHelper.toString(value);
40+
if (v.equals(stringValue)) {
3841
return true;
3942
}
4043
}

language/thingml/src/org/thingml/annotations/IntegerAnnotation.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import org.eclipse.emf.ecore.EClass;
2020
import org.eclipse.emf.ecore.EObject;
21+
import org.thingml.xtext.helpers.AnnotatedElementHelper;
22+
import org.thingml.xtext.thingML.IntegerLiteral;
23+
import org.thingml.xtext.thingML.Literal;
2124

2225
public class IntegerAnnotation extends Annotation {
2326

@@ -29,10 +32,10 @@ public IntegerAnnotation(String name, String description, EClass[] scope, boolea
2932
}
3033

3134
@Override
32-
public boolean check(EObject source, String value) {
35+
public boolean check(EObject source, Literal value) {
3336
if (!super.check(source, value)) return false;
3437
try {
35-
int v = Integer.parseInt(value);
38+
long v = (value instanceof IntegerLiteral)? ((IntegerLiteral)value).getIntValue() : Integer.parseInt(AnnotatedElementHelper.toString(value));
3639
if (onlyPositive) return v >= 0;
3740
return true;
3841
} catch (NumberFormatException nfe) {
@@ -45,7 +48,7 @@ public String toString() {
4548
if (onlyPositive)
4649
return super.toString() + " Valid values are positive integers.";
4750
else
48-
return super.toString() + " Valid values integers.";
51+
return super.toString() + " Valid values are integers.";
4952
}
5053

5154
}

0 commit comments

Comments
 (0)