Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.java/src/org')
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend10
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaLanguageGenerator.java30
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend28
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/setup/GeneratorModule.java3
4 files changed, 55 insertions, 16 deletions
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend
index 51a8bd24d..f37afe00c 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend
@@ -23,8 +23,8 @@ import org.eclipse.etrice.core.room.RoomClass
import org.eclipse.etrice.core.room.Message
import org.eclipse.etrice.generator.etricegen.ExpandedActorClass
import org.eclipse.etrice.generator.etricegen.TransitionChain
-import org.eclipse.etrice.generator.generic.LanguageGenerator
import org.eclipse.etrice.generator.generic.ILanguageExtension
+import org.eclipse.etrice.generator.generic.AbstractLanguageGenerator
import java.util.List
import org.eclipse.xtext.util.Pair
@@ -32,7 +32,7 @@ import org.eclipse.xtext.util.Pair
@Singleton
class JavaExtensions implements ILanguageExtension {
- @Inject LanguageGenerator languageGen
+ @Inject AbstractLanguageGenerator languageGen
override String getTypedDataDefinition(Message m) {
@@ -86,4 +86,8 @@ class JavaExtensions implements ILanguageExtension {
def String getExecuteChainCode(ExpandedActorClass ac, TransitionChain tc) {
return languageGen.getExecuteChain(ac, tc)
}
-} \ No newline at end of file
+
+ override String arrayDeclaration(String type, int size, String name) {
+ type+" "+name+"[]";
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaLanguageGenerator.java b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaLanguageGenerator.java
new file mode 100644
index 000000000..02feb7c0b
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaLanguageGenerator.java
@@ -0,0 +1,30 @@
+package org.eclipse.etrice.generator.java.gen;
+
+import org.eclipse.etrice.core.room.PrimitiveType;
+import org.eclipse.etrice.core.room.VarDecl;
+import org.eclipse.etrice.generator.generic.AbstractLanguageGenerator;
+
+public class JavaLanguageGenerator extends AbstractLanguageGenerator {
+
+ @Override
+ public String[] getArglistAndTypedData(VarDecl data) {
+ if (data==null)
+ return new String[] {"", "", ""};
+
+ String typeName = data.getRefType().getType().getName();
+ String castTypeName = typeName;
+ if (data.getRefType().getType() instanceof PrimitiveType) {
+ typeName = ((PrimitiveType)data.getRefType().getType()).getTargetName();
+ String ct = ((PrimitiveType)data.getRefType().getType()).getCastName();
+ if (ct!=null && !ct.isEmpty())
+ castTypeName = ct;
+ }
+
+ String typedData = typeName+" "+data.getName() + " = ("+castTypeName+") generic_data;\n";
+ String dataArg = ", "+data.getName();
+ String typedArgList = ", "+typeName+" "+data.getName();
+
+ return new String[]{dataArg, typedData, typedArgList};
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend
index ded007498..e0d3f981a 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend
@@ -88,21 +88,23 @@ class ProtocolClassGen extends GenericProtocolClassGenerator {
'''
}
- def portClass(ProtocolClass pc, Boolean conj) {'''
- «var name = pc.getPortClassName(conj)»
- «var pclass = pc.getPortClass(conj)»
+ def portClass(ProtocolClass pc, Boolean conj) {
+ var pclass = pc.getPortClass(conj)
+ var portClassName = pc.getPortClassName(conj)
+ var replPortClassName = pc.getPortClassName(conj, true)
+ '''
// port class
- static public class «name» extends PortBase {
+ static public class «portClassName» extends PortBase {
«IF pclass!=null»
«helpers.userCode(pclass.userCode)»
«ENDIF»
// constructors
- public «name»(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) {
+ public «portClassName»(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) {
super(actor, name, localId, 0, addr, peerAddress);
DebuggingService.getInstance().addPortInstance(this);
}
- public «name»(IEventReceiver actor, String name, int localId, int idx, Address addr, Address peerAddress) {
+ public «portClassName»(IEventReceiver actor, String name, int localId, int idx, Address addr, Address peerAddress) {
super(actor, name, localId, idx, addr, peerAddress);
DebuggingService.getInstance().addPortInstance(this);
}
@@ -144,7 +146,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator {
«IF pclass!=null»
«helpers.attributes(pclass.attributes)»
- «helpers.operationsImplementation(pclass.operations, name)»
+ «helpers.operationsImplementation(pclass.operations, portClassName)»
«ENDIF»
// sent messages
@@ -154,16 +156,16 @@ class ProtocolClassGen extends GenericProtocolClassGenerator {
}
// replicated port class
- static public class «name»Repl {
- private ArrayList<«name»> ports;
+ static public class «replPortClassName» {
+ private ArrayList<«portClassName»> ports;
private int replication;
- public «name»Repl(IEventReceiver actor, String name, int localId, Address[] addr,
+ public «replPortClassName»(IEventReceiver actor, String name, int localId, Address[] addr,
Address[] peerAddress) {
replication = addr.length;
- ports = new ArrayList<«pc.name».«name»>(replication);
+ ports = new ArrayList<«pc.name».«portClassName»>(replication);
for (int i=0; i<replication; ++i) {
- ports.add(new «name»(
+ ports.add(new «portClassName»(
actor, name+i, localId, i, addr[i], peerAddress[i]));
}
}
@@ -176,7 +178,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator {
return ifitem.getIdx();
}
- public «name» get(int i) {
+ public «portClassName» get(int i) {
return ports.get(i);
}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/setup/GeneratorModule.java b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/setup/GeneratorModule.java
index b5518d6d8..4c604f41e 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/setup/GeneratorModule.java
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/setup/GeneratorModule.java
@@ -17,9 +17,11 @@ import org.eclipse.etrice.generator.base.DefaultTranslationProvider;
import org.eclipse.etrice.generator.base.GeneratorBaseModule;
import org.eclipse.etrice.generator.base.ITranslationProvider;
import org.eclipse.etrice.generator.java.Main;
+import org.eclipse.etrice.generator.java.gen.JavaLanguageGenerator;
import org.eclipse.etrice.generator.java.gen.MainGen;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
+import org.eclipse.etrice.generator.generic.AbstractLanguageGenerator;
import org.eclipse.etrice.generator.java.gen.JavaExtensions;
@@ -39,6 +41,7 @@ public class GeneratorModule extends GeneratorBaseModule {
// bind language specific code to generic Interfaces
binder.bind(ILanguageExtension.class).to(JavaExtensions.class);
+ binder.bind(AbstractLanguageGenerator.class).to(JavaLanguageGenerator.class);
}
}

Back to the top