Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse')
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ActorClassGen.java1394
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.java958
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/DataClassGen.java950
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java764
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java960
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/MainGen.java140
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.java2222
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/StateMachineGen.java220
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/SubSystemClassGen.java1084
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/SubSystemRunnerGen.java328
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/VariableServiceGen.java1962
11 files changed, 5491 insertions, 5491 deletions
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ActorClassGen.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ActorClassGen.java
index 247908637..47a25a0d3 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ActorClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ActorClassGen.java
@@ -1,697 +1,697 @@
-/**
- * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- */
-package org.eclipse.etrice.generator.java.gen;
-
-import com.google.common.base.Objects;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import java.util.List;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
-import org.eclipse.etrice.core.genmodel.etricegen.Root;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.ActorRef;
-import org.eclipse.etrice.core.room.Attribute;
-import org.eclipse.etrice.core.room.DetailCode;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.ProtocolClass;
-import org.eclipse.etrice.core.room.RoomModel;
-import org.eclipse.etrice.core.room.SAPRef;
-import org.eclipse.etrice.core.room.SPPRef;
-import org.eclipse.etrice.core.room.ServiceImplementation;
-import org.eclipse.etrice.core.room.StandardOperation;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.generator.base.AbstractGenerator;
-import org.eclipse.etrice.generator.base.IDataConfiguration;
-import org.eclipse.etrice.generator.base.IGeneratorFileIo;
-import org.eclipse.etrice.generator.generic.GenericActorClassGenerator;
-import org.eclipse.etrice.generator.generic.ProcedureHelpers;
-import org.eclipse.etrice.generator.generic.RoomExtensions;
-import org.eclipse.etrice.generator.java.gen.ConfigGenAddon;
-import org.eclipse.etrice.generator.java.gen.Initialization;
-import org.eclipse.etrice.generator.java.gen.JavaExtensions;
-import org.eclipse.etrice.generator.java.gen.StateMachineGen;
-import org.eclipse.xtend2.lib.StringConcatenation;
-import org.eclipse.xtext.xbase.lib.Extension;
-import org.eclipse.xtext.xbase.lib.Functions.Function1;
-import org.eclipse.xtext.xbase.lib.IterableExtensions;
-
-@Singleton
-@SuppressWarnings("all")
-public class ActorClassGen extends GenericActorClassGenerator {
- @Inject
- private IGeneratorFileIo fileIO;
-
- @Inject
- @Extension
- private JavaExtensions _javaExtensions;
-
- @Inject
- @Extension
- private RoomExtensions _roomExtensions;
-
- @Inject
- private IDataConfiguration dataConfigExt;
-
- @Inject
- private ConfigGenAddon configGenAddon;
-
- @Inject
- @Extension
- private ProcedureHelpers _procedureHelpers;
-
- @Inject
- @Extension
- private Initialization _initialization;
-
- @Inject
- @Extension
- private StateMachineGen _stateMachineGen;
-
- public void doGenerate(final Root root) {
- EList<ExpandedActorClass> _xpActorClasses = root.getXpActorClasses();
- for (final ExpandedActorClass xpac : _xpActorClasses) {
- {
- ActorClass _actorClass = xpac.getActorClass();
- final boolean manualBehavior = RoomHelpers.isBehaviorAnnotationPresent(_actorClass, "BehaviorManual");
- ActorClass _actorClass_1 = xpac.getActorClass();
- String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(_actorClass_1);
- ActorClass _actorClass_2 = xpac.getActorClass();
- String _path = this._roomExtensions.getPath(_actorClass_2);
- final String path = (_generationTargetPath + _path);
- ActorClass _actorClass_3 = xpac.getActorClass();
- String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(_actorClass_3);
- ActorClass _actorClass_4 = xpac.getActorClass();
- String _path_1 = this._roomExtensions.getPath(_actorClass_4);
- final String infopath = (_generationInfoPath + _path_1);
- ActorClass _actorClass_5 = xpac.getActorClass();
- String file = this._javaExtensions.getJavaFileName(_actorClass_5);
- if (manualBehavior) {
- String _plus = ("Abstract" + file);
- file = _plus;
- }
- CharSequence _generate = this.generate(root, xpac, manualBehavior);
- this.fileIO.generateFile("generating ActorClass implementation", path, infopath, file, _generate);
- }
- }
- }
-
- public CharSequence generate(final Root root, final ExpandedActorClass xpac, final boolean manualBehavior) {
- CharSequence _xblockexpression = null;
- {
- final ActorClass ac = xpac.getActorClass();
- String _xifexpression = null;
- if (manualBehavior) {
- String _name = ac.getName();
- String _plus = ("Abstract" + _name);
- _xifexpression = _plus;
- } else {
- String _name_1 = ac.getName();
- _xifexpression = _name_1;
- }
- final String clsname = _xifexpression;
- EList<StandardOperation> _operations = ac.getOperations();
- final Function1<StandardOperation,Boolean> _function = new Function1<StandardOperation,Boolean>() {
- public Boolean apply(final StandardOperation op) {
- boolean _isConstructor = RoomHelpers.isConstructor(op);
- return Boolean.valueOf(_isConstructor);
- }
- };
- Iterable<StandardOperation> _filter = IterableExtensions.<StandardOperation>filter(_operations, _function);
- final StandardOperation ctor = IterableExtensions.<StandardOperation>head(_filter);
- EList<StandardOperation> _operations_1 = ac.getOperations();
- final Function1<StandardOperation,Boolean> _function_1 = new Function1<StandardOperation,Boolean>() {
- public Boolean apply(final StandardOperation op) {
- boolean _isDestructor = op.isDestructor();
- return Boolean.valueOf(_isDestructor);
- }
- };
- Iterable<StandardOperation> _filter_1 = IterableExtensions.<StandardOperation>filter(_operations_1, _function_1);
- final StandardOperation dtor = IterableExtensions.<StandardOperation>head(_filter_1);
- final EList<RoomModel> models = root.getReferencedModels(ac);
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("package ");
- String _package = this._roomExtensions.getPackage(ac);
- _builder.append(_package, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- {
- List<Attribute> _dynConfigReadAttributes = this.dataConfigExt.getDynConfigReadAttributes(ac);
- boolean _isEmpty = _dynConfigReadAttributes.isEmpty();
- boolean _not = (!_isEmpty);
- if (_not) {
- _builder.append("import org.eclipse.etrice.runtime.java.config.DynConfigLock;");
- _builder.newLine();
- }
- }
- _builder.append("import org.eclipse.etrice.runtime.java.messaging.Address;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.messaging.IRTObject;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.debugging.DebuggingService;");
- _builder.newLine();
- _builder.append("import static org.eclipse.etrice.runtime.java.etunit.EtUnit.*;");
- _builder.newLine();
- _builder.newLine();
- {
- for(final RoomModel model : models) {
- _builder.append("import ");
- String _name_2 = model.getName();
- _builder.append(_name_2, "");
- _builder.append(".*;");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- {
- EList<ProtocolClass> _referencedProtocolClasses = root.getReferencedProtocolClasses(ac);
- for(final ProtocolClass pc : _referencedProtocolClasses) {
- _builder.append("import ");
- String _package_1 = this._roomExtensions.getPackage(pc);
- _builder.append(_package_1, "");
- _builder.append(".");
- String _name_3 = pc.getName();
- _builder.append(_name_3, "");
- _builder.append(".*;");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- CharSequence _userCode = this._procedureHelpers.userCode(ac, 1);
- _builder.append(_userCode, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.newLine();
- _builder.append("public ");
- {
- boolean _or = false;
- if (manualBehavior) {
- _or = true;
- } else {
- boolean _isAbstract = ac.isAbstract();
- _or = (manualBehavior || _isAbstract);
- }
- if (_or) {
- _builder.append("abstract ");
- }
- }
- _builder.append("class ");
- _builder.append(clsname, "");
- _builder.append(" extends ");
- {
- ActorClass _base = ac.getBase();
- boolean _notEquals = (!Objects.equal(_base, null));
- if (_notEquals) {
- ActorClass _base_1 = ac.getBase();
- String _name_4 = _base_1.getName();
- _builder.append(_name_4, "");
- } else {
- _builder.append("ActorClassBase");
- }
- }
- _builder.append(" {");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("\t");
- CharSequence _userCode_1 = this._procedureHelpers.userCode(ac, 2);
- _builder.append(_userCode_1, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("//--------------------- ports");
- _builder.newLine();
- {
- List<Port> _endPorts = RoomHelpers.getEndPorts(ac);
- for(final Port ep : _endPorts) {
- _builder.append("\t");
- _builder.append("protected ");
- String _portClassName = this._roomExtensions.getPortClassName(ep);
- _builder.append(_portClassName, " ");
- _builder.append(" ");
- String _name_5 = ep.getName();
- _builder.append(_name_5, " ");
- _builder.append(" = null;");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("//--------------------- saps");
- _builder.newLine();
- {
- EList<SAPRef> _strSAPs = ac.getStrSAPs();
- for(final SAPRef sap : _strSAPs) {
- _builder.append("\t");
- _builder.append("protected ");
- String _portClassName_1 = this._roomExtensions.getPortClassName(sap);
- _builder.append(_portClassName_1, " ");
- _builder.append(" ");
- String _name_6 = sap.getName();
- _builder.append(_name_6, " ");
- _builder.append(" = null;");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("//--------------------- services");
- _builder.newLine();
- {
- EList<ServiceImplementation> _serviceImplementations = ac.getServiceImplementations();
- for(final ServiceImplementation svc : _serviceImplementations) {
- _builder.append("\t");
- _builder.append("protected ");
- String _portClassName_2 = this._roomExtensions.getPortClassName(svc);
- _builder.append(_portClassName_2, " ");
- _builder.append(" ");
- SPPRef _spp = svc.getSpp();
- String _name_7 = _spp.getName();
- _builder.append(_name_7, " ");
- _builder.append(" = null;");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- _builder.append("\t");
- _builder.append("//--------------------- interface item IDs");
- _builder.newLine();
- _builder.append("\t");
- String _genInterfaceItemConstants = this.genInterfaceItemConstants(xpac);
- _builder.append(_genInterfaceItemConstants, " ");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("\t");
- String _genMinMaxConstants = this.configGenAddon.genMinMaxConstants(ac);
- _builder.append(_genMinMaxConstants, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- EList<Attribute> _attributes = ac.getAttributes();
- CharSequence _attributes_1 = this._procedureHelpers.attributes(_attributes);
- _builder.append(_attributes_1, " ");
- _builder.newLineIfNotEmpty();
- {
- List<Attribute> _dynConfigReadAttributes_1 = this.dataConfigExt.getDynConfigReadAttributes(ac);
- for(final Attribute a : _dynConfigReadAttributes_1) {
- _builder.append("\t");
- _builder.append("private DynConfigLock lock_");
- String _name_8 = a.getName();
- _builder.append(_name_8, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(ac);
- _builder.append(_operationsImplementation, " ");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("//--------------------- construction");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public ");
- _builder.append(clsname, " ");
- _builder.append("(IRTObject parent, String name) {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("super(parent, name);");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("setClassName(\"");
- String _name_9 = ac.getName();
- _builder.append(_name_9, " ");
- _builder.append("\");");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- EList<Attribute> _attributes_2 = ac.getAttributes();
- CharSequence _attributeInitialization = this._initialization.attributeInitialization(_attributes_2, ac, false);
- _builder.append(_attributeInitialization, " ");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// own ports");
- _builder.newLine();
- {
- List<Port> _endPorts_1 = RoomHelpers.getEndPorts(ac);
- for(final Port ep_1 : _endPorts_1) {
- _builder.append("\t\t");
- String _name_10 = ep_1.getName();
- _builder.append(_name_10, " ");
- _builder.append(" = new ");
- String _portClassName_3 = this._roomExtensions.getPortClassName(ep_1);
- _builder.append(_portClassName_3, " ");
- _builder.append("(this, \"");
- String _name_11 = ep_1.getName();
- _builder.append(_name_11, " ");
- _builder.append("\", IFITEM_");
- String _name_12 = ep_1.getName();
- _builder.append(_name_12, " ");
- _builder.append("); ");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// own saps");
- _builder.newLine();
- {
- EList<SAPRef> _strSAPs_1 = ac.getStrSAPs();
- for(final SAPRef sap_1 : _strSAPs_1) {
- _builder.append("\t\t");
- String _name_13 = sap_1.getName();
- _builder.append(_name_13, " ");
- _builder.append(" = new ");
- String _portClassName_4 = this._roomExtensions.getPortClassName(sap_1);
- _builder.append(_portClassName_4, " ");
- _builder.append("(this, \"");
- String _name_14 = sap_1.getName();
- _builder.append(_name_14, " ");
- _builder.append("\", IFITEM_");
- String _name_15 = sap_1.getName();
- _builder.append(_name_15, " ");
- _builder.append(", 0); ");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// own service implementations");
- _builder.newLine();
- {
- EList<ServiceImplementation> _serviceImplementations_1 = ac.getServiceImplementations();
- for(final ServiceImplementation svc_1 : _serviceImplementations_1) {
- _builder.append("\t\t");
- SPPRef _spp_1 = svc_1.getSpp();
- String _name_16 = _spp_1.getName();
- _builder.append(_name_16, " ");
- _builder.append(" = new ");
- String _portClassName_5 = this._roomExtensions.getPortClassName(svc_1);
- _builder.append(_portClassName_5, " ");
- _builder.append("(this, \"");
- SPPRef _spp_2 = svc_1.getSpp();
- String _name_17 = _spp_2.getName();
- _builder.append(_name_17, " ");
- _builder.append("\", IFITEM_");
- SPPRef _spp_3 = svc_1.getSpp();
- String _name_18 = _spp_3.getName();
- _builder.append(_name_18, " ");
- _builder.append("); ");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// sub actors");
- _builder.newLine();
- {
- EList<ActorRef> _actorRefs = ac.getActorRefs();
- for(final ActorRef sub : _actorRefs) {
- {
- int _size = sub.getSize();
- boolean _greaterThan = (_size > 1);
- if (_greaterThan) {
- _builder.append("\t\t");
- _builder.append("for (int i=0; i<");
- int _size_1 = sub.getSize();
- _builder.append(_size_1, " ");
- _builder.append("; ++i)");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("new ");
- ActorClass _type = sub.getType();
- String _name_19 = _type.getName();
- _builder.append(_name_19, " ");
- _builder.append("(this, \"");
- String _name_20 = sub.getName();
- _builder.append(_name_20, " ");
- _builder.append("_\"+i); ");
- _builder.newLineIfNotEmpty();
- } else {
- _builder.append("\t\t");
- _builder.append("new ");
- ActorClass _type_1 = sub.getType();
- String _name_21 = _type_1.getName();
- _builder.append(_name_21, " ");
- _builder.append("(this, \"");
- String _name_22 = sub.getName();
- _builder.append(_name_22, " ");
- _builder.append("\"); ");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
- {
- boolean _notEquals_1 = (!Objects.equal(ctor, null));
- if (_notEquals_1) {
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("{");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("// user defined constructor body");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t");
- AbstractGenerator _instance = AbstractGenerator.getInstance();
- DetailCode _detailCode = ctor.getDetailCode();
- String _translatedCode = _instance.getTranslatedCode(_detailCode);
- _builder.append(_translatedCode, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- _builder.newLine();
- {
- boolean _or_1 = false;
- List<Attribute> _dynConfigReadAttributes_2 = this.dataConfigExt.getDynConfigReadAttributes(ac);
- boolean _isEmpty_1 = _dynConfigReadAttributes_2.isEmpty();
- boolean _not_1 = (!_isEmpty_1);
- if (_not_1) {
- _or_1 = true;
- } else {
- List<Attribute> _dynConfigWriteAttributes = this.dataConfigExt.getDynConfigWriteAttributes(ac);
- boolean _isEmpty_2 = _dynConfigWriteAttributes.isEmpty();
- boolean _not_2 = (!_isEmpty_2);
- _or_1 = (_not_1 || _not_2);
- }
- if (_or_1) {
- {
- List<Attribute> _dynConfigReadAttributes_3 = this.dataConfigExt.getDynConfigReadAttributes(ac);
- for(final Attribute a_1 : _dynConfigReadAttributes_3) {
- _builder.append("\t\t");
- _builder.append("lock_");
- String _name_23 = a_1.getName();
- _builder.append(_name_23, " ");
- _builder.append(" = new DynConfigLock();");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- EList<Attribute> _attributes_3 = ac.getAttributes();
- List<Attribute> _dynConfigReadAttributes_4 = this.dataConfigExt.getDynConfigReadAttributes(ac);
- List<Attribute> _minus = this._roomExtensions.<Attribute>minus(_attributes_3, _dynConfigReadAttributes_4);
- String _name_24 = ac.getName();
- CharSequence _attributeSettersGettersImplementation = this._procedureHelpers.attributeSettersGettersImplementation(_minus, _name_24);
- _builder.append(_attributeSettersGettersImplementation, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- CharSequence _genDynConfigGetterSetter = this.configGenAddon.genDynConfigGetterSetter(ac);
- _builder.append(_genDynConfigGetterSetter, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("//--------------------- port getters");
- _builder.newLine();
- {
- List<Port> _endPorts_2 = RoomHelpers.getEndPorts(ac);
- for(final Port ep_2 : _endPorts_2) {
- _builder.append("\t");
- String _portClassName_6 = this._roomExtensions.getPortClassName(ep_2);
- String _name_25 = ep_2.getName();
- String _name_26 = ac.getName();
- CharSequence _terImplementation = this._procedureHelpers.getterImplementation(_portClassName_6, _name_25, _name_26);
- _builder.append(_terImplementation, " ");
- _builder.newLineIfNotEmpty();
- }
- }
- {
- EList<SAPRef> _strSAPs_2 = ac.getStrSAPs();
- for(final SAPRef sap_2 : _strSAPs_2) {
- _builder.append("\t");
- String _portClassName_7 = this._roomExtensions.getPortClassName(sap_2);
- String _name_27 = sap_2.getName();
- String _name_28 = ac.getName();
- CharSequence _terImplementation_1 = this._procedureHelpers.getterImplementation(_portClassName_7, _name_27, _name_28);
- _builder.append(_terImplementation_1, " ");
- _builder.newLineIfNotEmpty();
- }
- }
- {
- EList<ServiceImplementation> _serviceImplementations_2 = ac.getServiceImplementations();
- for(final ServiceImplementation svc_2 : _serviceImplementations_2) {
- _builder.append("\t");
- String _portClassName_8 = this._roomExtensions.getPortClassName(svc_2);
- SPPRef _spp_4 = svc_2.getSpp();
- String _name_29 = _spp_4.getName();
- String _name_30 = ac.getName();
- CharSequence _terImplementation_2 = this._procedureHelpers.getterImplementation(_portClassName_8, _name_29, _name_30);
- _builder.append(_terImplementation_2, " ");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- _builder.append("\t");
- _builder.append("//--------------------- lifecycle functions");
- _builder.newLine();
- {
- boolean _overridesStop = this._roomExtensions.overridesStop(ac);
- boolean _not_3 = (!_overridesStop);
- if (_not_3) {
- {
- if (manualBehavior) {
- _builder.append("\t");
- _builder.append("public abstract void stop();");
- _builder.newLine();
- } else {
- _builder.append("\t");
- _builder.append("public void stop(){");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("stopUser();");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("super.stop();");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
- }
- _builder.append("\t");
- _builder.newLine();
- {
- boolean _notEquals_2 = (!Objects.equal(dtor, null));
- if (_notEquals_2) {
- {
- if (manualBehavior) {
- _builder.append("\t");
- _builder.append("public abstract void destroy();");
- _builder.newLine();
- } else {
- _builder.append("\t");
- _builder.append("public void destroy(){");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("\t");
- String _name_31 = ac.getName();
- String _destructorCall = this._procedureHelpers.destructorCall(_name_31);
- _builder.append(_destructorCall, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("super.destroy();");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
- }
- _builder.newLine();
- {
- if (manualBehavior) {
- _builder.append("\t");
- _builder.append("public abstract void receiveEvent(InterfaceItemBase ifitem, int evt, Object data);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public abstract void executeInitTransition();");
- _builder.newLine();
- } else {
- {
- boolean _hasNonEmptyStateMachine = RoomHelpers.hasNonEmptyStateMachine(ac);
- if (_hasNonEmptyStateMachine) {
- _builder.append("\t");
- CharSequence _genStateMachine = this._stateMachineGen.genStateMachine(xpac);
- _builder.append(_genStateMachine, " ");
- _builder.newLineIfNotEmpty();
- } else {
- boolean _hasStateMachine = xpac.hasStateMachine();
- boolean _not_4 = (!_hasStateMachine);
- if (_not_4) {
- _builder.append("\t");
- _builder.append("//--------------------- no state machine");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data) {");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("handleSystemEvent(ifitem, evt, data);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public void executeInitTransition() {}");
- _builder.newLine();
- }
- }
- }
- }
- }
- _builder.append("};");
- _builder.newLine();
- _xblockexpression = (_builder);
- }
- return _xblockexpression;
- }
-}
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ */
+package org.eclipse.etrice.generator.java.gen;
+
+import com.google.common.base.Objects;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
+import org.eclipse.etrice.core.genmodel.etricegen.Root;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorRef;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.DetailCode;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.ProtocolClass;
+import org.eclipse.etrice.core.room.RoomModel;
+import org.eclipse.etrice.core.room.SAPRef;
+import org.eclipse.etrice.core.room.SPPRef;
+import org.eclipse.etrice.core.room.ServiceImplementation;
+import org.eclipse.etrice.core.room.StandardOperation;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.generator.base.AbstractGenerator;
+import org.eclipse.etrice.generator.base.IDataConfiguration;
+import org.eclipse.etrice.generator.base.IGeneratorFileIo;
+import org.eclipse.etrice.generator.generic.GenericActorClassGenerator;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.java.gen.ConfigGenAddon;
+import org.eclipse.etrice.generator.java.gen.Initialization;
+import org.eclipse.etrice.generator.java.gen.JavaExtensions;
+import org.eclipse.etrice.generator.java.gen.StateMachineGen;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+
+@Singleton
+@SuppressWarnings("all")
+public class ActorClassGen extends GenericActorClassGenerator {
+ @Inject
+ private IGeneratorFileIo fileIO;
+
+ @Inject
+ @Extension
+ private JavaExtensions _javaExtensions;
+
+ @Inject
+ @Extension
+ private RoomExtensions _roomExtensions;
+
+ @Inject
+ private IDataConfiguration dataConfigExt;
+
+ @Inject
+ private ConfigGenAddon configGenAddon;
+
+ @Inject
+ @Extension
+ private ProcedureHelpers _procedureHelpers;
+
+ @Inject
+ @Extension
+ private Initialization _initialization;
+
+ @Inject
+ @Extension
+ private StateMachineGen _stateMachineGen;
+
+ public void doGenerate(final Root root) {
+ EList<ExpandedActorClass> _xpActorClasses = root.getXpActorClasses();
+ for (final ExpandedActorClass xpac : _xpActorClasses) {
+ {
+ ActorClass _actorClass = xpac.getActorClass();
+ final boolean manualBehavior = RoomHelpers.isBehaviorAnnotationPresent(_actorClass, "BehaviorManual");
+ ActorClass _actorClass_1 = xpac.getActorClass();
+ String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(_actorClass_1);
+ ActorClass _actorClass_2 = xpac.getActorClass();
+ String _path = this._roomExtensions.getPath(_actorClass_2);
+ final String path = (_generationTargetPath + _path);
+ ActorClass _actorClass_3 = xpac.getActorClass();
+ String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(_actorClass_3);
+ ActorClass _actorClass_4 = xpac.getActorClass();
+ String _path_1 = this._roomExtensions.getPath(_actorClass_4);
+ final String infopath = (_generationInfoPath + _path_1);
+ ActorClass _actorClass_5 = xpac.getActorClass();
+ String file = this._javaExtensions.getJavaFileName(_actorClass_5);
+ if (manualBehavior) {
+ String _plus = ("Abstract" + file);
+ file = _plus;
+ }
+ CharSequence _generate = this.generate(root, xpac, manualBehavior);
+ this.fileIO.generateFile("generating ActorClass implementation", path, infopath, file, _generate);
+ }
+ }
+ }
+
+ public CharSequence generate(final Root root, final ExpandedActorClass xpac, final boolean manualBehavior) {
+ CharSequence _xblockexpression = null;
+ {
+ final ActorClass ac = xpac.getActorClass();
+ String _xifexpression = null;
+ if (manualBehavior) {
+ String _name = ac.getName();
+ String _plus = ("Abstract" + _name);
+ _xifexpression = _plus;
+ } else {
+ String _name_1 = ac.getName();
+ _xifexpression = _name_1;
+ }
+ final String clsname = _xifexpression;
+ EList<StandardOperation> _operations = ac.getOperations();
+ final Function1<StandardOperation,Boolean> _function = new Function1<StandardOperation,Boolean>() {
+ public Boolean apply(final StandardOperation op) {
+ boolean _isConstructor = RoomHelpers.isConstructor(op);
+ return Boolean.valueOf(_isConstructor);
+ }
+ };
+ Iterable<StandardOperation> _filter = IterableExtensions.<StandardOperation>filter(_operations, _function);
+ final StandardOperation ctor = IterableExtensions.<StandardOperation>head(_filter);
+ EList<StandardOperation> _operations_1 = ac.getOperations();
+ final Function1<StandardOperation,Boolean> _function_1 = new Function1<StandardOperation,Boolean>() {
+ public Boolean apply(final StandardOperation op) {
+ boolean _isDestructor = op.isDestructor();
+ return Boolean.valueOf(_isDestructor);
+ }
+ };
+ Iterable<StandardOperation> _filter_1 = IterableExtensions.<StandardOperation>filter(_operations_1, _function_1);
+ final StandardOperation dtor = IterableExtensions.<StandardOperation>head(_filter_1);
+ final EList<RoomModel> models = root.getReferencedModels(ac);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package ");
+ String _package = this._roomExtensions.getPackage(ac);
+ _builder.append(_package, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ {
+ List<Attribute> _dynConfigReadAttributes = this.dataConfigExt.getDynConfigReadAttributes(ac);
+ boolean _isEmpty = _dynConfigReadAttributes.isEmpty();
+ boolean _not = (!_isEmpty);
+ if (_not) {
+ _builder.append("import org.eclipse.etrice.runtime.java.config.DynConfigLock;");
+ _builder.newLine();
+ }
+ }
+ _builder.append("import org.eclipse.etrice.runtime.java.messaging.Address;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.messaging.IRTObject;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.debugging.DebuggingService;");
+ _builder.newLine();
+ _builder.append("import static org.eclipse.etrice.runtime.java.etunit.EtUnit.*;");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ for(final RoomModel model : models) {
+ _builder.append("import ");
+ String _name_2 = model.getName();
+ _builder.append(_name_2, "");
+ _builder.append(".*;");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ {
+ EList<ProtocolClass> _referencedProtocolClasses = root.getReferencedProtocolClasses(ac);
+ for(final ProtocolClass pc : _referencedProtocolClasses) {
+ _builder.append("import ");
+ String _package_1 = this._roomExtensions.getPackage(pc);
+ _builder.append(_package_1, "");
+ _builder.append(".");
+ String _name_3 = pc.getName();
+ _builder.append(_name_3, "");
+ _builder.append(".*;");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ CharSequence _userCode = this._procedureHelpers.userCode(ac, 1);
+ _builder.append(_userCode, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("public ");
+ {
+ boolean _or = false;
+ if (manualBehavior) {
+ _or = true;
+ } else {
+ boolean _isAbstract = ac.isAbstract();
+ _or = (manualBehavior || _isAbstract);
+ }
+ if (_or) {
+ _builder.append("abstract ");
+ }
+ }
+ _builder.append("class ");
+ _builder.append(clsname, "");
+ _builder.append(" extends ");
+ {
+ ActorClass _base = ac.getBase();
+ boolean _notEquals = (!Objects.equal(_base, null));
+ if (_notEquals) {
+ ActorClass _base_1 = ac.getBase();
+ String _name_4 = _base_1.getName();
+ _builder.append(_name_4, "");
+ } else {
+ _builder.append("ActorClassBase");
+ }
+ }
+ _builder.append(" {");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _userCode_1 = this._procedureHelpers.userCode(ac, 2);
+ _builder.append(_userCode_1, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("//--------------------- ports");
+ _builder.newLine();
+ {
+ List<Port> _endPorts = RoomHelpers.getEndPorts(ac);
+ for(final Port ep : _endPorts) {
+ _builder.append("\t");
+ _builder.append("protected ");
+ String _portClassName = this._roomExtensions.getPortClassName(ep);
+ _builder.append(_portClassName, " ");
+ _builder.append(" ");
+ String _name_5 = ep.getName();
+ _builder.append(_name_5, " ");
+ _builder.append(" = null;");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("//--------------------- saps");
+ _builder.newLine();
+ {
+ EList<SAPRef> _strSAPs = ac.getStrSAPs();
+ for(final SAPRef sap : _strSAPs) {
+ _builder.append("\t");
+ _builder.append("protected ");
+ String _portClassName_1 = this._roomExtensions.getPortClassName(sap);
+ _builder.append(_portClassName_1, " ");
+ _builder.append(" ");
+ String _name_6 = sap.getName();
+ _builder.append(_name_6, " ");
+ _builder.append(" = null;");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("//--------------------- services");
+ _builder.newLine();
+ {
+ EList<ServiceImplementation> _serviceImplementations = ac.getServiceImplementations();
+ for(final ServiceImplementation svc : _serviceImplementations) {
+ _builder.append("\t");
+ _builder.append("protected ");
+ String _portClassName_2 = this._roomExtensions.getPortClassName(svc);
+ _builder.append(_portClassName_2, " ");
+ _builder.append(" ");
+ SPPRef _spp = svc.getSpp();
+ String _name_7 = _spp.getName();
+ _builder.append(_name_7, " ");
+ _builder.append(" = null;");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("//--------------------- interface item IDs");
+ _builder.newLine();
+ _builder.append("\t");
+ String _genInterfaceItemConstants = this.genInterfaceItemConstants(xpac);
+ _builder.append(_genInterfaceItemConstants, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ String _genMinMaxConstants = this.configGenAddon.genMinMaxConstants(ac);
+ _builder.append(_genMinMaxConstants, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ EList<Attribute> _attributes = ac.getAttributes();
+ CharSequence _attributes_1 = this._procedureHelpers.attributes(_attributes);
+ _builder.append(_attributes_1, " ");
+ _builder.newLineIfNotEmpty();
+ {
+ List<Attribute> _dynConfigReadAttributes_1 = this.dataConfigExt.getDynConfigReadAttributes(ac);
+ for(final Attribute a : _dynConfigReadAttributes_1) {
+ _builder.append("\t");
+ _builder.append("private DynConfigLock lock_");
+ String _name_8 = a.getName();
+ _builder.append(_name_8, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(ac);
+ _builder.append(_operationsImplementation, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("//--------------------- construction");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public ");
+ _builder.append(clsname, " ");
+ _builder.append("(IRTObject parent, String name) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("super(parent, name);");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("setClassName(\"");
+ String _name_9 = ac.getName();
+ _builder.append(_name_9, " ");
+ _builder.append("\");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ EList<Attribute> _attributes_2 = ac.getAttributes();
+ CharSequence _attributeInitialization = this._initialization.attributeInitialization(_attributes_2, ac, false);
+ _builder.append(_attributeInitialization, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// own ports");
+ _builder.newLine();
+ {
+ List<Port> _endPorts_1 = RoomHelpers.getEndPorts(ac);
+ for(final Port ep_1 : _endPorts_1) {
+ _builder.append("\t\t");
+ String _name_10 = ep_1.getName();
+ _builder.append(_name_10, " ");
+ _builder.append(" = new ");
+ String _portClassName_3 = this._roomExtensions.getPortClassName(ep_1);
+ _builder.append(_portClassName_3, " ");
+ _builder.append("(this, \"");
+ String _name_11 = ep_1.getName();
+ _builder.append(_name_11, " ");
+ _builder.append("\", IFITEM_");
+ String _name_12 = ep_1.getName();
+ _builder.append(_name_12, " ");
+ _builder.append("); ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// own saps");
+ _builder.newLine();
+ {
+ EList<SAPRef> _strSAPs_1 = ac.getStrSAPs();
+ for(final SAPRef sap_1 : _strSAPs_1) {
+ _builder.append("\t\t");
+ String _name_13 = sap_1.getName();
+ _builder.append(_name_13, " ");
+ _builder.append(" = new ");
+ String _portClassName_4 = this._roomExtensions.getPortClassName(sap_1);
+ _builder.append(_portClassName_4, " ");
+ _builder.append("(this, \"");
+ String _name_14 = sap_1.getName();
+ _builder.append(_name_14, " ");
+ _builder.append("\", IFITEM_");
+ String _name_15 = sap_1.getName();
+ _builder.append(_name_15, " ");
+ _builder.append(", 0); ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// own service implementations");
+ _builder.newLine();
+ {
+ EList<ServiceImplementation> _serviceImplementations_1 = ac.getServiceImplementations();
+ for(final ServiceImplementation svc_1 : _serviceImplementations_1) {
+ _builder.append("\t\t");
+ SPPRef _spp_1 = svc_1.getSpp();
+ String _name_16 = _spp_1.getName();
+ _builder.append(_name_16, " ");
+ _builder.append(" = new ");
+ String _portClassName_5 = this._roomExtensions.getPortClassName(svc_1);
+ _builder.append(_portClassName_5, " ");
+ _builder.append("(this, \"");
+ SPPRef _spp_2 = svc_1.getSpp();
+ String _name_17 = _spp_2.getName();
+ _builder.append(_name_17, " ");
+ _builder.append("\", IFITEM_");
+ SPPRef _spp_3 = svc_1.getSpp();
+ String _name_18 = _spp_3.getName();
+ _builder.append(_name_18, " ");
+ _builder.append("); ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// sub actors");
+ _builder.newLine();
+ {
+ EList<ActorRef> _actorRefs = ac.getActorRefs();
+ for(final ActorRef sub : _actorRefs) {
+ {
+ int _size = sub.getSize();
+ boolean _greaterThan = (_size > 1);
+ if (_greaterThan) {
+ _builder.append("\t\t");
+ _builder.append("for (int i=0; i<");
+ int _size_1 = sub.getSize();
+ _builder.append(_size_1, " ");
+ _builder.append("; ++i)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("new ");
+ ActorClass _type = sub.getType();
+ String _name_19 = _type.getName();
+ _builder.append(_name_19, " ");
+ _builder.append("(this, \"");
+ String _name_20 = sub.getName();
+ _builder.append(_name_20, " ");
+ _builder.append("_\"+i); ");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("\t\t");
+ _builder.append("new ");
+ ActorClass _type_1 = sub.getType();
+ String _name_21 = _type_1.getName();
+ _builder.append(_name_21, " ");
+ _builder.append("(this, \"");
+ String _name_22 = sub.getName();
+ _builder.append(_name_22, " ");
+ _builder.append("\"); ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ {
+ boolean _notEquals_1 = (!Objects.equal(ctor, null));
+ if (_notEquals_1) {
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("// user defined constructor body");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ AbstractGenerator _instance = AbstractGenerator.getInstance();
+ DetailCode _detailCode = ctor.getDetailCode();
+ String _translatedCode = _instance.getTranslatedCode(_detailCode);
+ _builder.append(_translatedCode, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ {
+ boolean _or_1 = false;
+ List<Attribute> _dynConfigReadAttributes_2 = this.dataConfigExt.getDynConfigReadAttributes(ac);
+ boolean _isEmpty_1 = _dynConfigReadAttributes_2.isEmpty();
+ boolean _not_1 = (!_isEmpty_1);
+ if (_not_1) {
+ _or_1 = true;
+ } else {
+ List<Attribute> _dynConfigWriteAttributes = this.dataConfigExt.getDynConfigWriteAttributes(ac);
+ boolean _isEmpty_2 = _dynConfigWriteAttributes.isEmpty();
+ boolean _not_2 = (!_isEmpty_2);
+ _or_1 = (_not_1 || _not_2);
+ }
+ if (_or_1) {
+ {
+ List<Attribute> _dynConfigReadAttributes_3 = this.dataConfigExt.getDynConfigReadAttributes(ac);
+ for(final Attribute a_1 : _dynConfigReadAttributes_3) {
+ _builder.append("\t\t");
+ _builder.append("lock_");
+ String _name_23 = a_1.getName();
+ _builder.append(_name_23, " ");
+ _builder.append(" = new DynConfigLock();");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ EList<Attribute> _attributes_3 = ac.getAttributes();
+ List<Attribute> _dynConfigReadAttributes_4 = this.dataConfigExt.getDynConfigReadAttributes(ac);
+ List<Attribute> _minus = this._roomExtensions.<Attribute>minus(_attributes_3, _dynConfigReadAttributes_4);
+ String _name_24 = ac.getName();
+ CharSequence _attributeSettersGettersImplementation = this._procedureHelpers.attributeSettersGettersImplementation(_minus, _name_24);
+ _builder.append(_attributeSettersGettersImplementation, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _genDynConfigGetterSetter = this.configGenAddon.genDynConfigGetterSetter(ac);
+ _builder.append(_genDynConfigGetterSetter, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("//--------------------- port getters");
+ _builder.newLine();
+ {
+ List<Port> _endPorts_2 = RoomHelpers.getEndPorts(ac);
+ for(final Port ep_2 : _endPorts_2) {
+ _builder.append("\t");
+ String _portClassName_6 = this._roomExtensions.getPortClassName(ep_2);
+ String _name_25 = ep_2.getName();
+ String _name_26 = ac.getName();
+ CharSequence _terImplementation = this._procedureHelpers.getterImplementation(_portClassName_6, _name_25, _name_26);
+ _builder.append(_terImplementation, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ {
+ EList<SAPRef> _strSAPs_2 = ac.getStrSAPs();
+ for(final SAPRef sap_2 : _strSAPs_2) {
+ _builder.append("\t");
+ String _portClassName_7 = this._roomExtensions.getPortClassName(sap_2);
+ String _name_27 = sap_2.getName();
+ String _name_28 = ac.getName();
+ CharSequence _terImplementation_1 = this._procedureHelpers.getterImplementation(_portClassName_7, _name_27, _name_28);
+ _builder.append(_terImplementation_1, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ {
+ EList<ServiceImplementation> _serviceImplementations_2 = ac.getServiceImplementations();
+ for(final ServiceImplementation svc_2 : _serviceImplementations_2) {
+ _builder.append("\t");
+ String _portClassName_8 = this._roomExtensions.getPortClassName(svc_2);
+ SPPRef _spp_4 = svc_2.getSpp();
+ String _name_29 = _spp_4.getName();
+ String _name_30 = ac.getName();
+ CharSequence _terImplementation_2 = this._procedureHelpers.getterImplementation(_portClassName_8, _name_29, _name_30);
+ _builder.append(_terImplementation_2, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("//--------------------- lifecycle functions");
+ _builder.newLine();
+ {
+ boolean _overridesStop = this._roomExtensions.overridesStop(ac);
+ boolean _not_3 = (!_overridesStop);
+ if (_not_3) {
+ {
+ if (manualBehavior) {
+ _builder.append("\t");
+ _builder.append("public abstract void stop();");
+ _builder.newLine();
+ } else {
+ _builder.append("\t");
+ _builder.append("public void stop(){");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("stopUser();");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("super.stop();");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ {
+ boolean _notEquals_2 = (!Objects.equal(dtor, null));
+ if (_notEquals_2) {
+ {
+ if (manualBehavior) {
+ _builder.append("\t");
+ _builder.append("public abstract void destroy();");
+ _builder.newLine();
+ } else {
+ _builder.append("\t");
+ _builder.append("public void destroy(){");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t");
+ String _name_31 = ac.getName();
+ String _destructorCall = this._procedureHelpers.destructorCall(_name_31);
+ _builder.append(_destructorCall, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("super.destroy();");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ {
+ if (manualBehavior) {
+ _builder.append("\t");
+ _builder.append("public abstract void receiveEvent(InterfaceItemBase ifitem, int evt, Object data);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public abstract void executeInitTransition();");
+ _builder.newLine();
+ } else {
+ {
+ boolean _hasNonEmptyStateMachine = RoomHelpers.hasNonEmptyStateMachine(ac);
+ if (_hasNonEmptyStateMachine) {
+ _builder.append("\t");
+ CharSequence _genStateMachine = this._stateMachineGen.genStateMachine(xpac);
+ _builder.append(_genStateMachine, " ");
+ _builder.newLineIfNotEmpty();
+ } else {
+ boolean _hasStateMachine = xpac.hasStateMachine();
+ boolean _not_4 = (!_hasStateMachine);
+ if (_not_4) {
+ _builder.append("\t");
+ _builder.append("//--------------------- no state machine");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data) {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("handleSystemEvent(ifitem, evt, data);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public void executeInitTransition() {}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ }
+ _builder.append("};");
+ _builder.newLine();
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.java
index 539480c36..2d1f64bf0 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.java
@@ -1,479 +1,479 @@
-/**
- * Copyright (c) 2012 Juergen Haug
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Juergen Haug
- */
-package org.eclipse.etrice.generator.java.gen;
-
-import com.google.common.base.Objects;
-import com.google.inject.Inject;
-import java.util.ArrayList;
-import java.util.List;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance;
-import org.eclipse.etrice.core.genmodel.etricegen.InstanceBase;
-import org.eclipse.etrice.core.genmodel.etricegen.InterfaceItemInstance;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.Attribute;
-import org.eclipse.etrice.core.room.DataClass;
-import org.eclipse.etrice.core.room.DataType;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.PortClass;
-import org.eclipse.etrice.core.room.PrimitiveType;
-import org.eclipse.etrice.core.room.RefableType;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.generator.base.IDataConfiguration;
-import org.eclipse.etrice.generator.generic.ProcedureHelpers;
-import org.eclipse.etrice.generator.generic.RoomExtensions;
-import org.eclipse.etrice.generator.generic.TypeHelpers;
-import org.eclipse.etrice.generator.java.gen.Initialization;
-import org.eclipse.etrice.generator.java.gen.JavaExtensions;
-import org.eclipse.xtend2.lib.StringConcatenation;
-import org.eclipse.xtext.xbase.lib.Extension;
-import org.eclipse.xtext.xbase.lib.IterableExtensions;
-import org.eclipse.xtext.xbase.lib.StringExtensions;
-
-@SuppressWarnings("all")
-public class ConfigGenAddon {
- @Inject
- @Extension
- private JavaExtensions stdExt;
-
- @Inject
- @Extension
- private TypeHelpers typeHelpers;
-
- @Inject
- @Extension
- private ProcedureHelpers helpers;
-
- @Inject
- private IDataConfiguration dataConfigExt;
-
- @Inject
- @Extension
- private RoomExtensions _roomExtensions;
-
- @Inject
- private Initialization initGen;
-
- public CharSequence genActorInstanceConfig(final ActorInstance ai, final String aiVariableName) {
- StringConcatenation _builder = new StringConcatenation();
- {
- ActorClass _actorClass = ai.getActorClass();
- List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(_actorClass);
- for(final Attribute a : _allAttributes) {
- ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
- List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
- CharSequence _applyInstanceConfig = this.applyInstanceConfig(ai, aiVariableName, _union);
- _builder.append(_applyInstanceConfig, "");
- _builder.newLineIfNotEmpty();
- }
- }
- {
- EList<InterfaceItemInstance> _orderedIfItemInstances = ai.getOrderedIfItemInstances();
- for(final InterfaceItemInstance pi : _orderedIfItemInstances) {
- InterfaceItem _interfaceItem = pi.getInterfaceItem();
- PortClass _portClass = RoomHelpers.getPortClass(_interfaceItem);
- EList<Attribute> _attributes = null;
- if (_portClass!=null) {
- _attributes=_portClass.getAttributes();
- }
- EList<Attribute> attribs = _attributes;
- _builder.newLineIfNotEmpty();
- {
- boolean _notEquals = (!Objects.equal(attribs, null));
- if (_notEquals) {
- {
- for(final Attribute a_1 : attribs) {
- String _plus = (aiVariableName + ".");
- String _name = pi.getName();
- CharSequence _invokeGetter = this.helpers.invokeGetter(_name, null);
- String _plus_1 = (_plus + _invokeGetter);
- ArrayList<Attribute> _arrayList_1 = new ArrayList<Attribute>();
- List<Attribute> _union_1 = this._roomExtensions.<Attribute>union(_arrayList_1, a_1);
- CharSequence _applyInstanceConfig_1 = this.applyInstanceConfig(pi, _plus_1, _union_1);
- _builder.append(_applyInstanceConfig_1, "");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
- }
- }
- return _builder;
- }
-
- private CharSequence applyInstanceConfig(final InstanceBase instance, final String invokes, final List<Attribute> path) {
- CharSequence _xblockexpression = null;
- {
- Attribute a = IterableExtensions.<Attribute>last(path);
- RefableType _refType = a.getRefType();
- DataType aType = _refType.getType();
- CharSequence _switchResult = null;
- boolean _matched = false;
- if (!_matched) {
- if (aType instanceof PrimitiveType) {
- final PrimitiveType _primitiveType = (PrimitiveType)aType;
- _matched=true;
- CharSequence _xblockexpression_1 = null;
- {
- String value = this.typeHelpers.getAttrInstanceConfigValue(path, instance);
- CharSequence _xifexpression = null;
- boolean _notEquals = (!Objects.equal(value, null));
- if (_notEquals) {
- String _valueLiteral = this.stdExt.toValueLiteral(_primitiveType, value);
- CharSequence _genAttributeInitializer = this.initGen.genAttributeInitializer(a, _valueLiteral, invokes);
- _xifexpression = _genAttributeInitializer;
- }
- _xblockexpression_1 = (_xifexpression);
- }
- _switchResult = _xblockexpression_1;
- }
- }
- if (!_matched) {
- if (aType instanceof DataClass) {
- final DataClass _dataClass = (DataClass)aType;
- _matched=true;
- StringConcatenation _builder = new StringConcatenation();
- {
- List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(((DataClass) _dataClass));
- for(final Attribute e : _allAttributes) {
- String _plus = (invokes + ".");
- String _name = a.getName();
- CharSequence _invokeGetter = this.helpers.invokeGetter(_name, null);
- String _plus_1 = (_plus + _invokeGetter);
- List<Attribute> _union = this._roomExtensions.<Attribute>union(path, e);
- CharSequence _applyInstanceConfig = this.applyInstanceConfig(instance, _plus_1, _union);
- _builder.append(_applyInstanceConfig, "");
- _builder.newLineIfNotEmpty();
- }
- }
- _switchResult = _builder;
- }
- }
- _xblockexpression = (_switchResult);
- }
- return _xblockexpression;
- }
-
- public CharSequence genDynConfigGetterSetter(final ActorClass ac) {
- StringConcatenation _builder = new StringConcatenation();
- {
- List<Attribute> _dynConfigReadAttributes = this.dataConfigExt.getDynConfigReadAttributes(ac);
- for(final Attribute a : _dynConfigReadAttributes) {
- _builder.append("public ");
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- String _typeName = this.typeHelpers.typeName(_type);
- _builder.append(_typeName, "");
- {
- int _size = a.getSize();
- boolean _greaterThan = (_size > 0);
- if (_greaterThan) {
- _builder.append("[]");
- }
- }
- _builder.append(" get");
- String _name = a.getName();
- String _firstUpper = StringExtensions.toFirstUpper(_name);
- _builder.append(_firstUpper, "");
- _builder.append("(){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("if(lock_");
- String _name_1 = a.getName();
- _builder.append(_name_1, " ");
- _builder.append(" == null)");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("return ");
- String _name_2 = a.getName();
- _builder.append(_name_2, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("else");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("synchronized(lock_");
- String _name_3 = a.getName();
- _builder.append(_name_3, " ");
- _builder.append("){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("return ");
- String _name_4 = a.getName();
- _builder.append(_name_4, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.append("public void set");
- String _name_5 = a.getName();
- String _firstUpper_1 = StringExtensions.toFirstUpper(_name_5);
- _builder.append(_firstUpper_1, "");
- _builder.append("(");
- RefableType _refType_1 = a.getRefType();
- DataType _type_1 = _refType_1.getType();
- String _typeName_1 = this.typeHelpers.typeName(_type_1);
- _builder.append(_typeName_1, "");
- {
- int _size_1 = a.getSize();
- boolean _greaterThan_1 = (_size_1 > 0);
- if (_greaterThan_1) {
- _builder.append("[]");
- }
- }
- _builder.append(" ");
- String _name_6 = a.getName();
- _builder.append(_name_6, "");
- _builder.append("){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("if(lock_");
- String _name_7 = a.getName();
- _builder.append(_name_7, " ");
- _builder.append(" == null)");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("this.");
- String _name_8 = a.getName();
- _builder.append(_name_8, " ");
- _builder.append(" = ");
- String _name_9 = a.getName();
- _builder.append(_name_9, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("else");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("synchronized(lock_");
- String _name_10 = a.getName();
- _builder.append(_name_10, " ");
- _builder.append("){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("this.");
- String _name_11 = a.getName();
- _builder.append(_name_11, " ");
- _builder.append(" = ");
- String _name_12 = a.getName();
- _builder.append(_name_12, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.append("public DynConfigLock get");
- String _name_13 = a.getName();
- String _firstUpper_2 = StringExtensions.toFirstUpper(_name_13);
- _builder.append(_firstUpper_2, "");
- _builder.append("Lock(){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("return lock_");
- String _name_14 = a.getName();
- _builder.append(_name_14, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("}\t");
- _builder.newLine();
- }
- }
- {
- List<Attribute> _dynConfigWriteAttributes = this.dataConfigExt.getDynConfigWriteAttributes(ac);
- for(final Attribute a_1 : _dynConfigWriteAttributes) {
- _builder.append("public void setAndWrite");
- String _name_15 = a_1.getName();
- String _firstUpper_3 = StringExtensions.toFirstUpper(_name_15);
- _builder.append(_firstUpper_3, "");
- _builder.append("(");
- RefableType _refType_2 = a_1.getRefType();
- DataType _type_2 = _refType_2.getType();
- String _typeName_2 = this.typeHelpers.typeName(_type_2);
- _builder.append(_typeName_2, "");
- {
- int _size_2 = a_1.getSize();
- boolean _greaterThan_2 = (_size_2 > 0);
- if (_greaterThan_2) {
- _builder.append("[]");
- }
- }
- _builder.append(" ");
- String _name_16 = a_1.getName();
- _builder.append(_name_16, "");
- _builder.append("){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("set");
- String _name_17 = a_1.getName();
- String _firstUpper_4 = StringExtensions.toFirstUpper(_name_17);
- _builder.append(_firstUpper_4, " ");
- _builder.append("(");
- String _name_18 = a_1.getName();
- _builder.append(_name_18, " ");
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("getVariableService().write(this.getInstancePath()+\"/");
- String _name_19 = a_1.getName();
- _builder.append(_name_19, " ");
- _builder.append("\", ");
- String _name_20 = a_1.getName();
- _builder.append(_name_20, " ");
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- }
- }
- return _builder;
- }
-
- public String genMinMaxConstants(final ActorClass ac) {
- StringConcatenation _builder = new StringConcatenation();
- {
- List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(ac);
- for(final Attribute a : _allAttributes) {
- String _name = a.getName();
- ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
- List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
- CharSequence _genMinMaxConstantsRec = this.genMinMaxConstantsRec(ac, _name, _union);
- _builder.append(_genMinMaxConstantsRec, "");
- _builder.newLineIfNotEmpty();
- }
- }
- String result = _builder.toString();
- int _length = result.length();
- boolean _notEquals = (_length != 0);
- if (_notEquals) {
- StringConcatenation _builder_1 = new StringConcatenation();
- _builder_1.append("//--------------------- Attribute Specifications");
- String _plus = (result + _builder_1);
- result = _plus;
- }
- return result;
- }
-
- private CharSequence genMinMaxConstantsRec(final ActorClass ac, final String varNamePath, final List<Attribute> path) {
- CharSequence _xblockexpression = null;
- {
- Attribute _last = IterableExtensions.<Attribute>last(path);
- RefableType _refType = _last.getRefType();
- DataType aType = _refType.getType();
- CharSequence _switchResult = null;
- boolean _matched = false;
- if (!_matched) {
- if (aType instanceof DataClass) {
- final DataClass _dataClass = (DataClass)aType;
- _matched=true;
- StringConcatenation _builder = new StringConcatenation();
- {
- List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(((DataClass) _dataClass));
- for(final Attribute e : _allAttributes) {
- String _plus = (varNamePath + "_");
- String _name = e.getName();
- String _plus_1 = (_plus + _name);
- List<Attribute> _union = this._roomExtensions.<Attribute>union(path, e);
- CharSequence _genMinMaxConstantsRec = this.genMinMaxConstantsRec(ac, _plus_1, _union);
- _builder.append(_genMinMaxConstantsRec, "");
- _builder.newLineIfNotEmpty();
- }
- }
- _switchResult = _builder;
- }
- }
- if (!_matched) {
- if (aType instanceof PrimitiveType) {
- final PrimitiveType _primitiveType = (PrimitiveType)aType;
- _matched=true;
- CharSequence _xblockexpression_1 = null;
- {
- String temp = ((String) null);
- StringConcatenation _builder = new StringConcatenation();
- {
- String _attrClassConfigMinValue = this.dataConfigExt.getAttrClassConfigMinValue(ac, path);
- String _temp = temp = _attrClassConfigMinValue;
- boolean _notEquals = (!Objects.equal(_temp, null));
- if (_notEquals) {
- _builder.append("public static ");
- String _minMaxType = this.getMinMaxType(_primitiveType);
- _builder.append(_minMaxType, "");
- _builder.append(" MIN_");
- _builder.append(varNamePath, "");
- _builder.append(" = ");
- String _valueLiteral = this.stdExt.toValueLiteral(_primitiveType, temp);
- _builder.append(_valueLiteral, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- {
- String _attrClassConfigMaxValue = this.dataConfigExt.getAttrClassConfigMaxValue(ac, path);
- String _temp_1 = temp = _attrClassConfigMaxValue;
- boolean _notEquals_1 = (!Objects.equal(_temp_1, null));
- if (_notEquals_1) {
- _builder.append("public static ");
- String _minMaxType_1 = this.getMinMaxType(_primitiveType);
- _builder.append(_minMaxType_1, "");
- _builder.append(" MAX_");
- _builder.append(varNamePath, "");
- _builder.append(" = ");
- String _valueLiteral_1 = this.stdExt.toValueLiteral(_primitiveType, temp);
- _builder.append(_valueLiteral_1, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- _xblockexpression_1 = (_builder);
- }
- _switchResult = _xblockexpression_1;
- }
- }
- _xblockexpression = (_switchResult);
- }
- return _xblockexpression;
- }
-
- private String getMinMaxType(final PrimitiveType type) {
- String _switchResult = null;
- String _typeName = this.typeHelpers.typeName(type);
- final String _switchValue = _typeName;
- boolean _matched = false;
- if (!_matched) {
- if (Objects.equal(_switchValue,"byte")) {
- _matched=true;
- _switchResult = "int";
- }
- }
- if (!_matched) {
- if (Objects.equal(_switchValue,"short")) {
- _matched=true;
- _switchResult = "int";
- }
- }
- if (!_matched) {
- if (Objects.equal(_switchValue,"float")) {
- _matched=true;
- _switchResult = "double";
- }
- }
- if (!_matched) {
- String _typeName_1 = this.typeHelpers.typeName(type);
- _switchResult = _typeName_1;
- }
- return _switchResult;
- }
-}
+/**
+ * Copyright (c) 2012 Juergen Haug
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug
+ */
+package org.eclipse.etrice.generator.java.gen;
+
+import com.google.common.base.Objects;
+import com.google.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance;
+import org.eclipse.etrice.core.genmodel.etricegen.InstanceBase;
+import org.eclipse.etrice.core.genmodel.etricegen.InterfaceItemInstance;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.PortClass;
+import org.eclipse.etrice.core.room.PrimitiveType;
+import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.generator.base.IDataConfiguration;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.generic.TypeHelpers;
+import org.eclipse.etrice.generator.java.gen.Initialization;
+import org.eclipse.etrice.generator.java.gen.JavaExtensions;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+
+@SuppressWarnings("all")
+public class ConfigGenAddon {
+ @Inject
+ @Extension
+ private JavaExtensions stdExt;
+
+ @Inject
+ @Extension
+ private TypeHelpers typeHelpers;
+
+ @Inject
+ @Extension
+ private ProcedureHelpers helpers;
+
+ @Inject
+ private IDataConfiguration dataConfigExt;
+
+ @Inject
+ @Extension
+ private RoomExtensions _roomExtensions;
+
+ @Inject
+ private Initialization initGen;
+
+ public CharSequence genActorInstanceConfig(final ActorInstance ai, final String aiVariableName) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ ActorClass _actorClass = ai.getActorClass();
+ List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(_actorClass);
+ for(final Attribute a : _allAttributes) {
+ ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
+ CharSequence _applyInstanceConfig = this.applyInstanceConfig(ai, aiVariableName, _union);
+ _builder.append(_applyInstanceConfig, "");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ {
+ EList<InterfaceItemInstance> _orderedIfItemInstances = ai.getOrderedIfItemInstances();
+ for(final InterfaceItemInstance pi : _orderedIfItemInstances) {
+ InterfaceItem _interfaceItem = pi.getInterfaceItem();
+ PortClass _portClass = RoomHelpers.getPortClass(_interfaceItem);
+ EList<Attribute> _attributes = null;
+ if (_portClass!=null) {
+ _attributes=_portClass.getAttributes();
+ }
+ EList<Attribute> attribs = _attributes;
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _notEquals = (!Objects.equal(attribs, null));
+ if (_notEquals) {
+ {
+ for(final Attribute a_1 : attribs) {
+ String _plus = (aiVariableName + ".");
+ String _name = pi.getName();
+ CharSequence _invokeGetter = this.helpers.invokeGetter(_name, null);
+ String _plus_1 = (_plus + _invokeGetter);
+ ArrayList<Attribute> _arrayList_1 = new ArrayList<Attribute>();
+ List<Attribute> _union_1 = this._roomExtensions.<Attribute>union(_arrayList_1, a_1);
+ CharSequence _applyInstanceConfig_1 = this.applyInstanceConfig(pi, _plus_1, _union_1);
+ _builder.append(_applyInstanceConfig_1, "");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ }
+ }
+ return _builder;
+ }
+
+ private CharSequence applyInstanceConfig(final InstanceBase instance, final String invokes, final List<Attribute> path) {
+ CharSequence _xblockexpression = null;
+ {
+ Attribute a = IterableExtensions.<Attribute>last(path);
+ RefableType _refType = a.getRefType();
+ DataType aType = _refType.getType();
+ CharSequence _switchResult = null;
+ boolean _matched = false;
+ if (!_matched) {
+ if (aType instanceof PrimitiveType) {
+ final PrimitiveType _primitiveType = (PrimitiveType)aType;
+ _matched=true;
+ CharSequence _xblockexpression_1 = null;
+ {
+ String value = this.typeHelpers.getAttrInstanceConfigValue(path, instance);
+ CharSequence _xifexpression = null;
+ boolean _notEquals = (!Objects.equal(value, null));
+ if (_notEquals) {
+ String _valueLiteral = this.stdExt.toValueLiteral(_primitiveType, value);
+ CharSequence _genAttributeInitializer = this.initGen.genAttributeInitializer(a, _valueLiteral, invokes);
+ _xifexpression = _genAttributeInitializer;
+ }
+ _xblockexpression_1 = (_xifexpression);
+ }
+ _switchResult = _xblockexpression_1;
+ }
+ }
+ if (!_matched) {
+ if (aType instanceof DataClass) {
+ final DataClass _dataClass = (DataClass)aType;
+ _matched=true;
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(((DataClass) _dataClass));
+ for(final Attribute e : _allAttributes) {
+ String _plus = (invokes + ".");
+ String _name = a.getName();
+ CharSequence _invokeGetter = this.helpers.invokeGetter(_name, null);
+ String _plus_1 = (_plus + _invokeGetter);
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(path, e);
+ CharSequence _applyInstanceConfig = this.applyInstanceConfig(instance, _plus_1, _union);
+ _builder.append(_applyInstanceConfig, "");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _switchResult = _builder;
+ }
+ }
+ _xblockexpression = (_switchResult);
+ }
+ return _xblockexpression;
+ }
+
+ public CharSequence genDynConfigGetterSetter(final ActorClass ac) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ List<Attribute> _dynConfigReadAttributes = this.dataConfigExt.getDynConfigReadAttributes(ac);
+ for(final Attribute a : _dynConfigReadAttributes) {
+ _builder.append("public ");
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ String _typeName = this.typeHelpers.typeName(_type);
+ _builder.append(_typeName, "");
+ {
+ int _size = a.getSize();
+ boolean _greaterThan = (_size > 0);
+ if (_greaterThan) {
+ _builder.append("[]");
+ }
+ }
+ _builder.append(" get");
+ String _name = a.getName();
+ String _firstUpper = StringExtensions.toFirstUpper(_name);
+ _builder.append(_firstUpper, "");
+ _builder.append("(){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("if(lock_");
+ String _name_1 = a.getName();
+ _builder.append(_name_1, " ");
+ _builder.append(" == null)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("return ");
+ String _name_2 = a.getName();
+ _builder.append(_name_2, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("else");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("synchronized(lock_");
+ String _name_3 = a.getName();
+ _builder.append(_name_3, " ");
+ _builder.append("){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("return ");
+ String _name_4 = a.getName();
+ _builder.append(_name_4, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("public void set");
+ String _name_5 = a.getName();
+ String _firstUpper_1 = StringExtensions.toFirstUpper(_name_5);
+ _builder.append(_firstUpper_1, "");
+ _builder.append("(");
+ RefableType _refType_1 = a.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ String _typeName_1 = this.typeHelpers.typeName(_type_1);
+ _builder.append(_typeName_1, "");
+ {
+ int _size_1 = a.getSize();
+ boolean _greaterThan_1 = (_size_1 > 0);
+ if (_greaterThan_1) {
+ _builder.append("[]");
+ }
+ }
+ _builder.append(" ");
+ String _name_6 = a.getName();
+ _builder.append(_name_6, "");
+ _builder.append("){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("if(lock_");
+ String _name_7 = a.getName();
+ _builder.append(_name_7, " ");
+ _builder.append(" == null)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("this.");
+ String _name_8 = a.getName();
+ _builder.append(_name_8, " ");
+ _builder.append(" = ");
+ String _name_9 = a.getName();
+ _builder.append(_name_9, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("else");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("synchronized(lock_");
+ String _name_10 = a.getName();
+ _builder.append(_name_10, " ");
+ _builder.append("){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("this.");
+ String _name_11 = a.getName();
+ _builder.append(_name_11, " ");
+ _builder.append(" = ");
+ String _name_12 = a.getName();
+ _builder.append(_name_12, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("public DynConfigLock get");
+ String _name_13 = a.getName();
+ String _firstUpper_2 = StringExtensions.toFirstUpper(_name_13);
+ _builder.append(_firstUpper_2, "");
+ _builder.append("Lock(){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("return lock_");
+ String _name_14 = a.getName();
+ _builder.append(_name_14, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}\t");
+ _builder.newLine();
+ }
+ }
+ {
+ List<Attribute> _dynConfigWriteAttributes = this.dataConfigExt.getDynConfigWriteAttributes(ac);
+ for(final Attribute a_1 : _dynConfigWriteAttributes) {
+ _builder.append("public void setAndWrite");
+ String _name_15 = a_1.getName();
+ String _firstUpper_3 = StringExtensions.toFirstUpper(_name_15);
+ _builder.append(_firstUpper_3, "");
+ _builder.append("(");
+ RefableType _refType_2 = a_1.getRefType();
+ DataType _type_2 = _refType_2.getType();
+ String _typeName_2 = this.typeHelpers.typeName(_type_2);
+ _builder.append(_typeName_2, "");
+ {
+ int _size_2 = a_1.getSize();
+ boolean _greaterThan_2 = (_size_2 > 0);
+ if (_greaterThan_2) {
+ _builder.append("[]");
+ }
+ }
+ _builder.append(" ");
+ String _name_16 = a_1.getName();
+ _builder.append(_name_16, "");
+ _builder.append("){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("set");
+ String _name_17 = a_1.getName();
+ String _firstUpper_4 = StringExtensions.toFirstUpper(_name_17);
+ _builder.append(_firstUpper_4, " ");
+ _builder.append("(");
+ String _name_18 = a_1.getName();
+ _builder.append(_name_18, " ");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("getVariableService().write(this.getInstancePath()+\"/");
+ String _name_19 = a_1.getName();
+ _builder.append(_name_19, " ");
+ _builder.append("\", ");
+ String _name_20 = a_1.getName();
+ _builder.append(_name_20, " ");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ return _builder;
+ }
+
+ public String genMinMaxConstants(final ActorClass ac) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(ac);
+ for(final Attribute a : _allAttributes) {
+ String _name = a.getName();
+ ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
+ CharSequence _genMinMaxConstantsRec = this.genMinMaxConstantsRec(ac, _name, _union);
+ _builder.append(_genMinMaxConstantsRec, "");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ String result = _builder.toString();
+ int _length = result.length();
+ boolean _notEquals = (_length != 0);
+ if (_notEquals) {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("//--------------------- Attribute Specifications");
+ String _plus = (result + _builder_1);
+ result = _plus;
+ }
+ return result;
+ }
+
+ private CharSequence genMinMaxConstantsRec(final ActorClass ac, final String varNamePath, final List<Attribute> path) {
+ CharSequence _xblockexpression = null;
+ {
+ Attribute _last = IterableExtensions.<Attribute>last(path);
+ RefableType _refType = _last.getRefType();
+ DataType aType = _refType.getType();
+ CharSequence _switchResult = null;
+ boolean _matched = false;
+ if (!_matched) {
+ if (aType instanceof DataClass) {
+ final DataClass _dataClass = (DataClass)aType;
+ _matched=true;
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(((DataClass) _dataClass));
+ for(final Attribute e : _allAttributes) {
+ String _plus = (varNamePath + "_");
+ String _name = e.getName();
+ String _plus_1 = (_plus + _name);
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(path, e);
+ CharSequence _genMinMaxConstantsRec = this.genMinMaxConstantsRec(ac, _plus_1, _union);
+ _builder.append(_genMinMaxConstantsRec, "");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _switchResult = _builder;
+ }
+ }
+ if (!_matched) {
+ if (aType instanceof PrimitiveType) {
+ final PrimitiveType _primitiveType = (PrimitiveType)aType;
+ _matched=true;
+ CharSequence _xblockexpression_1 = null;
+ {
+ String temp = ((String) null);
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ String _attrClassConfigMinValue = this.dataConfigExt.getAttrClassConfigMinValue(ac, path);
+ String _temp = temp = _attrClassConfigMinValue;
+ boolean _notEquals = (!Objects.equal(_temp, null));
+ if (_notEquals) {
+ _builder.append("public static ");
+ String _minMaxType = this.getMinMaxType(_primitiveType);
+ _builder.append(_minMaxType, "");
+ _builder.append(" MIN_");
+ _builder.append(varNamePath, "");
+ _builder.append(" = ");
+ String _valueLiteral = this.stdExt.toValueLiteral(_primitiveType, temp);
+ _builder.append(_valueLiteral, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ {
+ String _attrClassConfigMaxValue = this.dataConfigExt.getAttrClassConfigMaxValue(ac, path);
+ String _temp_1 = temp = _attrClassConfigMaxValue;
+ boolean _notEquals_1 = (!Objects.equal(_temp_1, null));
+ if (_notEquals_1) {
+ _builder.append("public static ");
+ String _minMaxType_1 = this.getMinMaxType(_primitiveType);
+ _builder.append(_minMaxType_1, "");
+ _builder.append(" MAX_");
+ _builder.append(varNamePath, "");
+ _builder.append(" = ");
+ String _valueLiteral_1 = this.stdExt.toValueLiteral(_primitiveType, temp);
+ _builder.append(_valueLiteral_1, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _xblockexpression_1 = (_builder);
+ }
+ _switchResult = _xblockexpression_1;
+ }
+ }
+ _xblockexpression = (_switchResult);
+ }
+ return _xblockexpression;
+ }
+
+ private String getMinMaxType(final PrimitiveType type) {
+ String _switchResult = null;
+ String _typeName = this.typeHelpers.typeName(type);
+ final String _switchValue = _typeName;
+ boolean _matched = false;
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"byte")) {
+ _matched=true;
+ _switchResult = "int";
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"short")) {
+ _matched=true;
+ _switchResult = "int";
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"float")) {
+ _matched=true;
+ _switchResult = "double";
+ }
+ }
+ if (!_matched) {
+ String _typeName_1 = this.typeHelpers.typeName(type);
+ _switchResult = _typeName_1;
+ }
+ return _switchResult;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/DataClassGen.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/DataClassGen.java
index 1a8472723..e8401a956 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/DataClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/DataClassGen.java
@@ -1,475 +1,475 @@
-/**
- * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- */
-package org.eclipse.etrice.generator.java.gen;
-
-import com.google.common.base.Objects;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import java.util.List;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.etrice.core.genmodel.etricegen.Root;
-import org.eclipse.etrice.core.room.Attribute;
-import org.eclipse.etrice.core.room.ComplexType;
-import org.eclipse.etrice.core.room.DataClass;
-import org.eclipse.etrice.core.room.DataType;
-import org.eclipse.etrice.core.room.DetailCode;
-import org.eclipse.etrice.core.room.RefableType;
-import org.eclipse.etrice.core.room.RoomModel;
-import org.eclipse.etrice.core.room.StandardOperation;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.generator.base.IGeneratorFileIo;
-import org.eclipse.etrice.generator.generic.ProcedureHelpers;
-import org.eclipse.etrice.generator.generic.RoomExtensions;
-import org.eclipse.etrice.generator.java.gen.Initialization;
-import org.eclipse.etrice.generator.java.gen.JavaExtensions;
-import org.eclipse.xtend2.lib.StringConcatenation;
-import org.eclipse.xtext.xbase.lib.Extension;
-import org.eclipse.xtext.xbase.lib.Functions.Function1;
-import org.eclipse.xtext.xbase.lib.IterableExtensions;
-
-@Singleton
-@SuppressWarnings("all")
-public class DataClassGen {
- @Inject
- private IGeneratorFileIo fileIO;
-
- @Inject
- @Extension
- private JavaExtensions _javaExtensions;
-
- @Inject
- @Extension
- private RoomExtensions _roomExtensions;
-
- @Inject
- @Extension
- private ProcedureHelpers _procedureHelpers;
-
- @Inject
- @Extension
- private Initialization _initialization;
-
- public void doGenerate(final Root root) {
- EList<DataClass> _usedDataClasses = root.getUsedDataClasses();
- for (final DataClass dc : _usedDataClasses) {
- {
- String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(dc);
- String _path = this._roomExtensions.getPath(dc);
- String path = (_generationTargetPath + _path);
- String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(dc);
- String _path_1 = this._roomExtensions.getPath(dc);
- String infopath = (_generationInfoPath + _path_1);
- String file = this._javaExtensions.getJavaFileName(dc);
- CharSequence _generate = this.generate(root, dc);
- this.fileIO.generateFile("generating DataClass implementation", path, infopath, file, _generate);
- }
- }
- }
-
- public CharSequence generate(final Root root, final DataClass dc) {
- CharSequence _xblockexpression = null;
- {
- EList<StandardOperation> _operations = dc.getOperations();
- final Function1<StandardOperation,Boolean> _function = new Function1<StandardOperation,Boolean>() {
- public Boolean apply(final StandardOperation op) {
- boolean _isConstructor = RoomHelpers.isConstructor(op);
- return Boolean.valueOf(_isConstructor);
- }
- };
- Iterable<StandardOperation> _filter = IterableExtensions.<StandardOperation>filter(_operations, _function);
- final StandardOperation ctor = IterableExtensions.<StandardOperation>head(_filter);
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("package ");
- String _package = this._roomExtensions.getPackage(dc);
- _builder.append(_package, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("import static org.eclipse.etrice.runtime.java.etunit.EtUnit.*;");
- _builder.newLine();
- _builder.newLine();
- EList<RoomModel> models = root.getReferencedModels(dc);
- _builder.newLineIfNotEmpty();
- {
- for(final RoomModel model : models) {
- _builder.append("import ");
- String _name = model.getName();
- _builder.append(_name, "");
- _builder.append(".*;");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- CharSequence _userCode = this._procedureHelpers.userCode(dc, 1);
- _builder.append(_userCode, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.newLine();
- _builder.append("public class ");
- String _name_1 = dc.getName();
- _builder.append(_name_1, "");
- {
- DataClass _base = dc.getBase();
- boolean _notEquals = (!Objects.equal(_base, null));
- if (_notEquals) {
- _builder.append(" extends ");
- DataClass _base_1 = dc.getBase();
- String _name_2 = _base_1.getName();
- _builder.append(_name_2, "");
- }
- }
- _builder.append(" {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- CharSequence _userCode_1 = this._procedureHelpers.userCode(dc, 2);
- _builder.append(_userCode_1, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- EList<Attribute> _attributes = dc.getAttributes();
- CharSequence _attributes_1 = this._procedureHelpers.attributes(_attributes);
- _builder.append(_attributes_1, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- EList<Attribute> _attributes_2 = dc.getAttributes();
- String _name_3 = dc.getName();
- CharSequence _attributeSettersGettersImplementation = this._procedureHelpers.attributeSettersGettersImplementation(_attributes_2, _name_3);
- _builder.append(_attributeSettersGettersImplementation, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- EList<StandardOperation> _operations_1 = dc.getOperations();
- String _name_4 = dc.getName();
- CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(_operations_1, _name_4);
- _builder.append(_operationsImplementation, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("// default constructor");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public ");
- String _name_5 = dc.getName();
- _builder.append(_name_5, " ");
- _builder.append("() {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("super();");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- EList<Attribute> _attributes_3 = dc.getAttributes();
- CharSequence _attributeInitialization = this._initialization.attributeInitialization(_attributes_3, dc, true);
- _builder.append(_attributeInitialization, " ");
- _builder.newLineIfNotEmpty();
- {
- boolean _notEquals_1 = (!Objects.equal(ctor, null));
- if (_notEquals_1) {
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("{");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("// user defined constructor body");
- _builder.newLine();
- {
- DetailCode _detailCode = ctor.getDetailCode();
- EList<String> _commands = _detailCode.getCommands();
- for(final String l : _commands) {
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append(l, " ");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("// constructor using fields");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public ");
- String _name_6 = dc.getName();
- _builder.append(_name_6, " ");
- _builder.append("(");
- String _argList = this.argList(dc);
- _builder.append(_argList, " ");
- _builder.append(") {");
- _builder.newLineIfNotEmpty();
- {
- DataClass _base_2 = dc.getBase();
- boolean _notEquals_2 = (!Objects.equal(_base_2, null));
- if (_notEquals_2) {
- _builder.append("\t\t");
- _builder.append("super(");
- DataClass _base_3 = dc.getBase();
- String _paramList = this.paramList(_base_3);
- _builder.append(_paramList, " ");
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- } else {
- _builder.append("\t\t");
- _builder.append("super();");
- _builder.newLine();
- }
- }
- _builder.append("\t\t");
- _builder.newLine();
- {
- EList<Attribute> _attributes_4 = dc.getAttributes();
- for(final Attribute a : _attributes_4) {
- _builder.append("\t\t");
- _builder.append("this.");
- String _name_7 = a.getName();
- _builder.append(_name_7, " ");
- _builder.append(" = ");
- String _name_8 = a.getName();
- _builder.append(_name_8, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("// deep copy");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public ");
- String _name_9 = dc.getName();
- _builder.append(_name_9, " ");
- _builder.append(" deepCopy() {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- String _name_10 = dc.getName();
- _builder.append(_name_10, " ");
- _builder.append(" copy = new ");
- String _name_11 = dc.getName();
- _builder.append(_name_11, " ");
- _builder.append("();");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- String _deepCopy = this.deepCopy(dc);
- _builder.append(_deepCopy, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("return copy;");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("};");
- _builder.newLine();
- _xblockexpression = (_builder);
- }
- return _xblockexpression;
- }
-
- public String paramList(final DataClass _dc) {
- String result = "";
- DataClass dc = _dc;
- boolean _notEquals = (!Objects.equal(dc, null));
- boolean _while = _notEquals;
- while (_while) {
- {
- EList<Attribute> _attributes = dc.getAttributes();
- CharSequence _paramList = this.paramList(_attributes);
- String _string = _paramList.toString();
- String _plus = (_string + result);
- result = _plus;
- DataClass _base = dc.getBase();
- dc = _base;
- boolean _notEquals_1 = (!Objects.equal(dc, null));
- if (_notEquals_1) {
- String _plus_1 = (", " + result);
- result = _plus_1;
- }
- }
- boolean _notEquals_1 = (!Objects.equal(dc, null));
- _while = _notEquals_1;
- }
- return result;
- }
-
- public CharSequence paramList(final List<Attribute> attributes) {
- StringConcatenation _builder = new StringConcatenation();
- {
- boolean _hasElements = false;
- for(final Attribute a : attributes) {
- if (!_hasElements) {
- _hasElements = true;
- } else {
- _builder.appendImmediate(", ", "");
- }
- String _name = a.getName();
- _builder.append(_name, "");
- }
- }
- return _builder;
- }
-
- public String argList(final DataClass _dc) {
- String result = "";
- DataClass dc = _dc;
- boolean _notEquals = (!Objects.equal(dc, null));
- boolean _while = _notEquals;
- while (_while) {
- {
- EList<Attribute> _attributes = dc.getAttributes();
- CharSequence _argList = this._procedureHelpers.argList(_attributes);
- String _string = _argList.toString();
- String _plus = (_string + result);
- result = _plus;
- DataClass _base = dc.getBase();
- dc = _base;
- boolean _notEquals_1 = (!Objects.equal(dc, null));
- if (_notEquals_1) {
- String _plus_1 = (", " + result);
- result = _plus_1;
- }
- }
- boolean _notEquals_1 = (!Objects.equal(dc, null));
- _while = _notEquals_1;
- }
- return result;
- }
-
- public String deepCopy(final DataClass _dc) {
- String result = "";
- DataClass dc = _dc;
- boolean _notEquals = (!Objects.equal(dc, null));
- boolean _while = _notEquals;
- while (_while) {
- {
- EList<Attribute> _attributes = dc.getAttributes();
- CharSequence _deepCopy = this.deepCopy(_attributes);
- String _string = _deepCopy.toString();
- String _plus = (_string + result);
- result = _plus;
- DataClass _base = dc.getBase();
- dc = _base;
- }
- boolean _notEquals_1 = (!Objects.equal(dc, null));
- _while = _notEquals_1;
- }
- return result;
- }
-
- public CharSequence deepCopy(final List<Attribute> attributes) {
- StringConcatenation _builder = new StringConcatenation();
- {
- for(final Attribute a : attributes) {
- {
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- if ((_type instanceof ComplexType)) {
- _builder.append("if (");
- String _name = a.getName();
- _builder.append(_name, "");
- _builder.append("!=null) {");
- _builder.newLineIfNotEmpty();
- {
- int _size = a.getSize();
- boolean _equals = (_size == 0);
- if (_equals) {
- _builder.append("\t");
- _builder.append("copy.");
- String _name_1 = a.getName();
- _builder.append(_name_1, " ");
- _builder.append(" = ");
- String _name_2 = a.getName();
- _builder.append(_name_2, " ");
- _builder.append(".deepCopy();");
- _builder.newLineIfNotEmpty();
- } else {
- _builder.append("\t");
- _builder.append("for (int i=0;i<");
- String _name_3 = a.getName();
- _builder.append(_name_3, " ");
- _builder.append(".length;i++){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("copy.");
- String _name_4 = a.getName();
- _builder.append(_name_4, " ");
- _builder.append("[i] = ");
- String _name_5 = a.getName();
- _builder.append(_name_5, " ");
- _builder.append("[i].deepCopy();");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- _builder.append("}");
- _builder.newLine();
- } else {
- {
- int _size_1 = a.getSize();
- boolean _equals_1 = (_size_1 == 0);
- if (_equals_1) {
- _builder.append("copy.");
- String _name_6 = a.getName();
- _builder.append(_name_6, "");
- _builder.append(" = ");
- String _name_7 = a.getName();
- _builder.append(_name_7, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- } else {
- _builder.append("for (int i=0;i<");
- String _name_8 = a.getName();
- _builder.append(_name_8, "");
- _builder.append(".length;i++){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("copy.");
- String _name_9 = a.getName();
- _builder.append(_name_9, " ");
- _builder.append("[i] = ");
- String _name_10 = a.getName();
- _builder.append(_name_10, " ");
- _builder.append("[i];");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
- }
- }
- }
- return _builder;
- }
-}
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ */
+package org.eclipse.etrice.generator.java.gen;
+
+import com.google.common.base.Objects;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.genmodel.etricegen.Root;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.ComplexType;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.DetailCode;
+import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.core.room.RoomModel;
+import org.eclipse.etrice.core.room.StandardOperation;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.generator.base.IGeneratorFileIo;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.java.gen.Initialization;
+import org.eclipse.etrice.generator.java.gen.JavaExtensions;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+
+@Singleton
+@SuppressWarnings("all")
+public class DataClassGen {
+ @Inject
+ private IGeneratorFileIo fileIO;
+
+ @Inject
+ @Extension
+ private JavaExtensions _javaExtensions;
+
+ @Inject
+ @Extension
+ private RoomExtensions _roomExtensions;
+
+ @Inject
+ @Extension
+ private ProcedureHelpers _procedureHelpers;
+
+ @Inject
+ @Extension
+ private Initialization _initialization;
+
+ public void doGenerate(final Root root) {
+ EList<DataClass> _usedDataClasses = root.getUsedDataClasses();
+ for (final DataClass dc : _usedDataClasses) {
+ {
+ String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(dc);
+ String _path = this._roomExtensions.getPath(dc);
+ String path = (_generationTargetPath + _path);
+ String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(dc);
+ String _path_1 = this._roomExtensions.getPath(dc);
+ String infopath = (_generationInfoPath + _path_1);
+ String file = this._javaExtensions.getJavaFileName(dc);
+ CharSequence _generate = this.generate(root, dc);
+ this.fileIO.generateFile("generating DataClass implementation", path, infopath, file, _generate);
+ }
+ }
+ }
+
+ public CharSequence generate(final Root root, final DataClass dc) {
+ CharSequence _xblockexpression = null;
+ {
+ EList<StandardOperation> _operations = dc.getOperations();
+ final Function1<StandardOperation,Boolean> _function = new Function1<StandardOperation,Boolean>() {
+ public Boolean apply(final StandardOperation op) {
+ boolean _isConstructor = RoomHelpers.isConstructor(op);
+ return Boolean.valueOf(_isConstructor);
+ }
+ };
+ Iterable<StandardOperation> _filter = IterableExtensions.<StandardOperation>filter(_operations, _function);
+ final StandardOperation ctor = IterableExtensions.<StandardOperation>head(_filter);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package ");
+ String _package = this._roomExtensions.getPackage(dc);
+ _builder.append(_package, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("import static org.eclipse.etrice.runtime.java.etunit.EtUnit.*;");
+ _builder.newLine();
+ _builder.newLine();
+ EList<RoomModel> models = root.getReferencedModels(dc);
+ _builder.newLineIfNotEmpty();
+ {
+ for(final RoomModel model : models) {
+ _builder.append("import ");
+ String _name = model.getName();
+ _builder.append(_name, "");
+ _builder.append(".*;");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ CharSequence _userCode = this._procedureHelpers.userCode(dc, 1);
+ _builder.append(_userCode, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("public class ");
+ String _name_1 = dc.getName();
+ _builder.append(_name_1, "");
+ {
+ DataClass _base = dc.getBase();
+ boolean _notEquals = (!Objects.equal(_base, null));
+ if (_notEquals) {
+ _builder.append(" extends ");
+ DataClass _base_1 = dc.getBase();
+ String _name_2 = _base_1.getName();
+ _builder.append(_name_2, "");
+ }
+ }
+ _builder.append(" {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _userCode_1 = this._procedureHelpers.userCode(dc, 2);
+ _builder.append(_userCode_1, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ EList<Attribute> _attributes = dc.getAttributes();
+ CharSequence _attributes_1 = this._procedureHelpers.attributes(_attributes);
+ _builder.append(_attributes_1, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ EList<Attribute> _attributes_2 = dc.getAttributes();
+ String _name_3 = dc.getName();
+ CharSequence _attributeSettersGettersImplementation = this._procedureHelpers.attributeSettersGettersImplementation(_attributes_2, _name_3);
+ _builder.append(_attributeSettersGettersImplementation, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ EList<StandardOperation> _operations_1 = dc.getOperations();
+ String _name_4 = dc.getName();
+ CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(_operations_1, _name_4);
+ _builder.append(_operationsImplementation, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// default constructor");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public ");
+ String _name_5 = dc.getName();
+ _builder.append(_name_5, " ");
+ _builder.append("() {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("super();");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ EList<Attribute> _attributes_3 = dc.getAttributes();
+ CharSequence _attributeInitialization = this._initialization.attributeInitialization(_attributes_3, dc, true);
+ _builder.append(_attributeInitialization, " ");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _notEquals_1 = (!Objects.equal(ctor, null));
+ if (_notEquals_1) {
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("// user defined constructor body");
+ _builder.newLine();
+ {
+ DetailCode _detailCode = ctor.getDetailCode();
+ EList<String> _commands = _detailCode.getCommands();
+ for(final String l : _commands) {
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append(l, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// constructor using fields");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public ");
+ String _name_6 = dc.getName();
+ _builder.append(_name_6, " ");
+ _builder.append("(");
+ String _argList = this.argList(dc);
+ _builder.append(_argList, " ");
+ _builder.append(") {");
+ _builder.newLineIfNotEmpty();
+ {
+ DataClass _base_2 = dc.getBase();
+ boolean _notEquals_2 = (!Objects.equal(_base_2, null));
+ if (_notEquals_2) {
+ _builder.append("\t\t");
+ _builder.append("super(");
+ DataClass _base_3 = dc.getBase();
+ String _paramList = this.paramList(_base_3);
+ _builder.append(_paramList, " ");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("\t\t");
+ _builder.append("super();");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t\t");
+ _builder.newLine();
+ {
+ EList<Attribute> _attributes_4 = dc.getAttributes();
+ for(final Attribute a : _attributes_4) {
+ _builder.append("\t\t");
+ _builder.append("this.");
+ String _name_7 = a.getName();
+ _builder.append(_name_7, " ");
+ _builder.append(" = ");
+ String _name_8 = a.getName();
+ _builder.append(_name_8, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// deep copy");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public ");
+ String _name_9 = dc.getName();
+ _builder.append(_name_9, " ");
+ _builder.append(" deepCopy() {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ String _name_10 = dc.getName();
+ _builder.append(_name_10, " ");
+ _builder.append(" copy = new ");
+ String _name_11 = dc.getName();
+ _builder.append(_name_11, " ");
+ _builder.append("();");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ String _deepCopy = this.deepCopy(dc);
+ _builder.append(_deepCopy, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("return copy;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+
+ public String paramList(final DataClass _dc) {
+ String result = "";
+ DataClass dc = _dc;
+ boolean _notEquals = (!Objects.equal(dc, null));
+ boolean _while = _notEquals;
+ while (_while) {
+ {
+ EList<Attribute> _attributes = dc.getAttributes();
+ CharSequence _paramList = this.paramList(_attributes);
+ String _string = _paramList.toString();
+ String _plus = (_string + result);
+ result = _plus;
+ DataClass _base = dc.getBase();
+ dc = _base;
+ boolean _notEquals_1 = (!Objects.equal(dc, null));
+ if (_notEquals_1) {
+ String _plus_1 = (", " + result);
+ result = _plus_1;
+ }
+ }
+ boolean _notEquals_1 = (!Objects.equal(dc, null));
+ _while = _notEquals_1;
+ }
+ return result;
+ }
+
+ public CharSequence paramList(final List<Attribute> attributes) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ boolean _hasElements = false;
+ for(final Attribute a : attributes) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(", ", "");
+ }
+ String _name = a.getName();
+ _builder.append(_name, "");
+ }
+ }
+ return _builder;
+ }
+
+ public String argList(final DataClass _dc) {
+ String result = "";
+ DataClass dc = _dc;
+ boolean _notEquals = (!Objects.equal(dc, null));
+ boolean _while = _notEquals;
+ while (_while) {
+ {
+ EList<Attribute> _attributes = dc.getAttributes();
+ CharSequence _argList = this._procedureHelpers.argList(_attributes);
+ String _string = _argList.toString();
+ String _plus = (_string + result);
+ result = _plus;
+ DataClass _base = dc.getBase();
+ dc = _base;
+ boolean _notEquals_1 = (!Objects.equal(dc, null));
+ if (_notEquals_1) {
+ String _plus_1 = (", " + result);
+ result = _plus_1;
+ }
+ }
+ boolean _notEquals_1 = (!Objects.equal(dc, null));
+ _while = _notEquals_1;
+ }
+ return result;
+ }
+
+ public String deepCopy(final DataClass _dc) {
+ String result = "";
+ DataClass dc = _dc;
+ boolean _notEquals = (!Objects.equal(dc, null));
+ boolean _while = _notEquals;
+ while (_while) {
+ {
+ EList<Attribute> _attributes = dc.getAttributes();
+ CharSequence _deepCopy = this.deepCopy(_attributes);
+ String _string = _deepCopy.toString();
+ String _plus = (_string + result);
+ result = _plus;
+ DataClass _base = dc.getBase();
+ dc = _base;
+ }
+ boolean _notEquals_1 = (!Objects.equal(dc, null));
+ _while = _notEquals_1;
+ }
+ return result;
+ }
+
+ public CharSequence deepCopy(final List<Attribute> attributes) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ for(final Attribute a : attributes) {
+ {
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ if ((_type instanceof ComplexType)) {
+ _builder.append("if (");
+ String _name = a.getName();
+ _builder.append(_name, "");
+ _builder.append("!=null) {");
+ _builder.newLineIfNotEmpty();
+ {
+ int _size = a.getSize();
+ boolean _equals = (_size == 0);
+ if (_equals) {
+ _builder.append("\t");
+ _builder.append("copy.");
+ String _name_1 = a.getName();
+ _builder.append(_name_1, " ");
+ _builder.append(" = ");
+ String _name_2 = a.getName();
+ _builder.append(_name_2, " ");
+ _builder.append(".deepCopy();");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("\t");
+ _builder.append("for (int i=0;i<");
+ String _name_3 = a.getName();
+ _builder.append(_name_3, " ");
+ _builder.append(".length;i++){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("copy.");
+ String _name_4 = a.getName();
+ _builder.append(_name_4, " ");
+ _builder.append("[i] = ");
+ String _name_5 = a.getName();
+ _builder.append(_name_5, " ");
+ _builder.append("[i].deepCopy();");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ } else {
+ {
+ int _size_1 = a.getSize();
+ boolean _equals_1 = (_size_1 == 0);
+ if (_equals_1) {
+ _builder.append("copy.");
+ String _name_6 = a.getName();
+ _builder.append(_name_6, "");
+ _builder.append(" = ");
+ String _name_7 = a.getName();
+ _builder.append(_name_7, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("for (int i=0;i<");
+ String _name_8 = a.getName();
+ _builder.append(_name_8, "");
+ _builder.append(".length;i++){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("copy.");
+ String _name_9 = a.getName();
+ _builder.append(_name_9, " ");
+ _builder.append("[i] = ");
+ String _name_10 = a.getName();
+ _builder.append(_name_10, " ");
+ _builder.append("[i];");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ }
+ }
+ return _builder;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java
index 4ef1ea343..ab7dcd4d7 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java
@@ -1,382 +1,382 @@
-/**
- * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- */
-package org.eclipse.etrice.generator.java.gen;
-
-import com.google.common.base.Objects;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import java.util.ArrayList;
-import java.util.List;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.Attribute;
-import org.eclipse.etrice.core.room.DataClass;
-import org.eclipse.etrice.core.room.DataType;
-import org.eclipse.etrice.core.room.PortClass;
-import org.eclipse.etrice.core.room.PrimitiveType;
-import org.eclipse.etrice.core.room.RefableType;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.generator.generic.ProcedureHelpers;
-import org.eclipse.etrice.generator.generic.RoomExtensions;
-import org.eclipse.etrice.generator.generic.TypeHelpers;
-import org.eclipse.etrice.generator.java.gen.JavaExtensions;
-import org.eclipse.xtend2.lib.StringConcatenation;
-import org.eclipse.xtext.xbase.lib.Extension;
-import org.eclipse.xtext.xbase.lib.IterableExtensions;
-
-@Singleton
-@SuppressWarnings("all")
-public class Initialization {
- @Inject
- @Extension
- private TypeHelpers typeHelpers;
-
- @Inject
- @Extension
- private RoomExtensions _roomExtensions;
-
- @Inject
- @Extension
- private JavaExtensions languageExt;
-
- @Inject
- @Extension
- private ProcedureHelpers procedureHelpers;
-
- public CharSequence attributeInitialization(final List<Attribute> attribs, final EObject roomClass, final boolean useClassDefaultsOnly) {
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("// initialize attributes");
- _builder.newLine();
- {
- for(final Attribute a : attribs) {
- CharSequence _attributeClassInit = this.attributeClassInit(a, roomClass, useClassDefaultsOnly);
- _builder.append(_attributeClassInit, "");
- _builder.newLineIfNotEmpty();
- {
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- boolean _isDataClass = this.typeHelpers.isDataClass(_type);
- if (_isDataClass) {
- ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
- List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
- CharSequence _attributeInitPrimitiveRec = this.attributeInitPrimitiveRec(_union, roomClass);
- _builder.append(_attributeInitPrimitiveRec, "");
- }
- }
- _builder.newLineIfNotEmpty();
- }
- }
- return _builder;
- }
-
- private CharSequence attributeClassInit(final Attribute a, final EObject roomClass, final boolean useClassDefaultsOnly) {
- CharSequence _xblockexpression = null;
- {
- RefableType _refType = a.getRefType();
- DataType aType = _refType.getType();
- CharSequence _xifexpression = null;
- RefableType _refType_1 = a.getRefType();
- boolean _isRef = _refType_1.isRef();
- if (_isRef) {
- CharSequence _xifexpression_1 = null;
- String _defaultValueLiteral = a.getDefaultValueLiteral();
- boolean _notEquals = (!Objects.equal(_defaultValueLiteral, null));
- if (_notEquals) {
- String _defaultValueLiteral_1 = a.getDefaultValueLiteral();
- CharSequence _attributeInit = this.attributeInit(a, _defaultValueLiteral_1);
- _xifexpression_1 = _attributeInit;
- } else {
- CharSequence _xifexpression_2 = null;
- boolean _needsInitialization = this.languageExt.needsInitialization(a);
- if (_needsInitialization) {
- String _nullPointer = this.languageExt.nullPointer();
- CharSequence _attributeInit_1 = this.attributeInit(a, _nullPointer);
- _xifexpression_2 = _attributeInit_1;
- }
- _xifexpression_1 = _xifexpression_2;
- }
- _xifexpression = _xifexpression_1;
- } else {
- CharSequence _xifexpression_3 = null;
- boolean _isPrimitive = this.typeHelpers.isPrimitive(aType);
- if (_isPrimitive) {
- CharSequence _xblockexpression_1 = null;
- {
- ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
- List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
- String value = this.getDataConfigValue(_union, roomClass);
- boolean _equals = Objects.equal(value, null);
- if (_equals) {
- String _defaultValueLiteral_2 = a.getDefaultValueLiteral();
- value = _defaultValueLiteral_2;
- }
- CharSequence _xifexpression_4 = null;
- boolean _notEquals_1 = (!Objects.equal(value, null));
- if (_notEquals_1) {
- String _valueLiteral = this.languageExt.toValueLiteral(((PrimitiveType) aType), value);
- CharSequence _attributeInit_2 = this.attributeInit(a, _valueLiteral);
- _xifexpression_4 = _attributeInit_2;
- } else {
- CharSequence _xifexpression_5 = null;
- boolean _or = false;
- boolean _not = (!useClassDefaultsOnly);
- if (_not) {
- _or = true;
- } else {
- boolean _needsInitialization_1 = this.languageExt.needsInitialization(a);
- _or = (_not || _needsInitialization_1);
- }
- if (_or) {
- String _defaultValue = this.languageExt.defaultValue(aType);
- CharSequence _attributeInit_3 = this.attributeInit(a, _defaultValue);
- _xifexpression_5 = _attributeInit_3;
- }
- _xifexpression_4 = _xifexpression_5;
- }
- _xblockexpression_1 = (_xifexpression_4);
- }
- _xifexpression_3 = _xblockexpression_1;
- } else {
- String _defaultValue = this.languageExt.defaultValue(aType);
- CharSequence _attributeInit_2 = this.attributeInit(a, _defaultValue);
- _xifexpression_3 = _attributeInit_2;
- }
- _xifexpression = _xifexpression_3;
- }
- _xblockexpression = (_xifexpression);
- }
- return _xblockexpression;
- }
-
- private CharSequence attributeInitPrimitiveRec(final List<Attribute> path, final EObject roomClass) {
- CharSequence _xblockexpression = null;
- {
- Attribute a = IterableExtensions.<Attribute>last(path);
- RefableType _refType = a.getRefType();
- DataType aType = _refType.getType();
- CharSequence _xifexpression = null;
- boolean _isDataClass = this.typeHelpers.isDataClass(aType);
- if (_isDataClass) {
- StringConcatenation _builder = new StringConcatenation();
- {
- List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(((DataClass) aType));
- for(final Attribute e : _allAttributes) {
- List<Attribute> _union = this._roomExtensions.<Attribute>union(path, e);
- CharSequence _attributeInitPrimitiveRec = this.attributeInitPrimitiveRec(_union, roomClass);
- _builder.append(_attributeInitPrimitiveRec, "");
- _builder.newLineIfNotEmpty();
- }
- }
- return _builder;
- } else {
- CharSequence _xifexpression_1 = null;
- boolean _isPrimitive = this.typeHelpers.isPrimitive(aType);
- if (_isPrimitive) {
- String value = this.getDataConfigValue(path, roomClass);
- CharSequence _xifexpression_2 = null;
- boolean _notEquals = (!Objects.equal(value, null));
- if (_notEquals) {
- String _valueLiteral = this.languageExt.toValueLiteral(((PrimitiveType) aType), value);
- CharSequence _attributeInit = this.attributeInit(path, _valueLiteral);
- _xifexpression_2 = _attributeInit;
- }
- return _xifexpression_2;
- }
- _xifexpression = _xifexpression_1;
- }
- _xblockexpression = (_xifexpression);
- }
- return _xblockexpression;
- }
-
- private CharSequence attributeInit(final Attribute a, final String value) {
- ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
- List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
- CharSequence _attributeInit = this.attributeInit(_union, value);
- return _attributeInit;
- }
-
- private CharSequence attributeInit(final List<Attribute> path, final String value) {
- String _xifexpression = null;
- int _size = path.size();
- boolean _equals = (_size == 1);
- if (_equals) {
- _xifexpression = "this";
- } else {
- int _size_1 = path.size();
- int _minus = (_size_1 - 1);
- Iterable<Attribute> _take = IterableExtensions.<Attribute>take(path, _minus);
- CharSequence _invokeGetters = this.procedureHelpers.invokeGetters(_take, null);
- String _string = _invokeGetters.toString();
- _xifexpression = _string;
- }
- final String getter = _xifexpression;
- Attribute _last = IterableExtensions.<Attribute>last(path);
- return this.genAttributeInitializer(_last, value, getter);
- }
-
- public CharSequence genAttributeInitializer(final Attribute a, final String value, final String invokes) {
- CharSequence _xblockexpression = null;
- {
- RefableType _refType = a.getRefType();
- DataType aType = _refType.getType();
- StringConcatenation _builder = new StringConcatenation();
- {
- boolean _or = false;
- int _size = a.getSize();
- boolean _equals = (_size == 0);
- if (_equals) {
- _or = true;
- } else {
- boolean _and = false;
- boolean _and_1 = false;
- int _size_1 = a.getSize();
- boolean _greaterThan = (_size_1 > 0);
- if (!_greaterThan) {
- _and_1 = false;
- } else {
- String _typeName = this.typeHelpers.typeName(aType);
- boolean _equals_1 = "char".equals(_typeName);
- _and_1 = (_greaterThan && _equals_1);
- }
- if (!_and_1) {
- _and = false;
- } else {
- boolean _matches = value.matches("\'.\'|\\(char\\).*");
- boolean _not = (!_matches);
- _and = (_and_1 && _not);
- }
- _or = (_equals || _and);
- }
- if (_or) {
- _builder.append(invokes, "");
- _builder.append(".");
- String _name = a.getName();
- CharSequence _invokeSetter = this.procedureHelpers.invokeSetter(_name, null, value);
- _builder.append(_invokeSetter, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- } else {
- boolean _or_1 = false;
- String _trim = value.trim();
- boolean _startsWith = _trim.startsWith("{");
- boolean _not_1 = (!_startsWith);
- if (_not_1) {
- _or_1 = true;
- } else {
- String _typeName_1 = this.typeHelpers.typeName(aType);
- boolean _equals_2 = "char".equals(_typeName_1);
- _or_1 = (_not_1 || _equals_2);
- }
- if (_or_1) {
- _builder.append("{");
- _builder.newLine();
- _builder.append("\t");
- String _typeName_2 = this.typeHelpers.typeName(aType);
- _builder.append(_typeName_2, " ");
- _builder.append("[] array = new ");
- String _typeName_3 = this.typeHelpers.typeName(aType);
- _builder.append(_typeName_3, " ");
- _builder.append("[");
- int _size_2 = a.getSize();
- _builder.append(_size_2, " ");
- _builder.append("];");
- _builder.newLineIfNotEmpty();
- {
- boolean _and_2 = false;
- RefableType _refType_1 = a.getRefType();
- boolean _isRef = _refType_1.isRef();
- if (!_isRef) {
- _and_2 = false;
- } else {
- boolean _isPrimitive = this.typeHelpers.isPrimitive(aType);
- _and_2 = (_isRef && _isPrimitive);
- }
- boolean _not_2 = (!_and_2);
- if (_not_2) {
- _builder.append("\t");
- _builder.append("for (int i=0;i<");
- int _size_3 = a.getSize();
- _builder.append(_size_3, " ");
- _builder.append(";i++){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("array[i] = ");
- _builder.append(value, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- _builder.append("\t");
- _builder.append(invokes, " ");
- _builder.append(".");
- String _name_1 = a.getName();
- CharSequence _invokeSetter_1 = this.procedureHelpers.invokeSetter(_name_1, null, "array");
- _builder.append(_invokeSetter_1, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- } else {
- _builder.append(invokes, "");
- _builder.append(".");
- String _name_2 = a.getName();
- StringConcatenation _builder_1 = new StringConcatenation();
- _builder_1.append("new ");
- String _typeName_4 = this.typeHelpers.typeName(aType);
- _builder_1.append(_typeName_4, "");
- _builder_1.append("[] ");
- _builder_1.append(value, "");
- CharSequence _invokeSetter_2 = this.procedureHelpers.invokeSetter(_name_2, null, _builder_1.toString());
- _builder.append(_invokeSetter_2, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- _xblockexpression = (_builder);
- }
- return _xblockexpression;
- }
-
- private String getDataConfigValue(final List<Attribute> path, final EObject roomClass) {
- String _switchResult = null;
- boolean _matched = false;
- if (!_matched) {
- if (roomClass instanceof ActorClass) {
- final ActorClass _actorClass = (ActorClass)roomClass;
- _matched=true;
- String _attrClassConfigValue = this.typeHelpers.getAttrClassConfigValue(path, _actorClass, false);
- _switchResult = _attrClassConfigValue;
- }
- }
- if (!_matched) {
- if (roomClass instanceof PortClass) {
- final PortClass _portClass = (PortClass)roomClass;
- _matched=true;
- String _attrClassConfigValue = this.typeHelpers.getAttrClassConfigValue(path, _portClass);
- _switchResult = _attrClassConfigValue;
- }
- }
- if (!_matched) {
- if (roomClass instanceof DataClass) {
- final DataClass _dataClass = (DataClass)roomClass;
- _matched=true;
- _switchResult = null;
- }
- }
- return _switchResult;
- }
-}
+/**
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ */
+package org.eclipse.etrice.generator.java.gen;
+
+import com.google.common.base.Objects;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.PortClass;
+import org.eclipse.etrice.core.room.PrimitiveType;
+import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.generic.TypeHelpers;
+import org.eclipse.etrice.generator.java.gen.JavaExtensions;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+
+@Singleton
+@SuppressWarnings("all")
+public class Initialization {
+ @Inject
+ @Extension
+ private TypeHelpers typeHelpers;
+
+ @Inject
+ @Extension
+ private RoomExtensions _roomExtensions;
+
+ @Inject
+ @Extension
+ private JavaExtensions languageExt;
+
+ @Inject
+ @Extension
+ private ProcedureHelpers procedureHelpers;
+
+ public CharSequence attributeInitialization(final List<Attribute> attribs, final EObject roomClass, final boolean useClassDefaultsOnly) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("// initialize attributes");
+ _builder.newLine();
+ {
+ for(final Attribute a : attribs) {
+ CharSequence _attributeClassInit = this.attributeClassInit(a, roomClass, useClassDefaultsOnly);
+ _builder.append(_attributeClassInit, "");
+ _builder.newLineIfNotEmpty();
+ {
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ boolean _isDataClass = this.typeHelpers.isDataClass(_type);
+ if (_isDataClass) {
+ ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
+ CharSequence _attributeInitPrimitiveRec = this.attributeInitPrimitiveRec(_union, roomClass);
+ _builder.append(_attributeInitPrimitiveRec, "");
+ }
+ }
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ return _builder;
+ }
+
+ private CharSequence attributeClassInit(final Attribute a, final EObject roomClass, final boolean useClassDefaultsOnly) {
+ CharSequence _xblockexpression = null;
+ {
+ RefableType _refType = a.getRefType();
+ DataType aType = _refType.getType();
+ CharSequence _xifexpression = null;
+ RefableType _refType_1 = a.getRefType();
+ boolean _isRef = _refType_1.isRef();
+ if (_isRef) {
+ CharSequence _xifexpression_1 = null;
+ String _defaultValueLiteral = a.getDefaultValueLiteral();
+ boolean _notEquals = (!Objects.equal(_defaultValueLiteral, null));
+ if (_notEquals) {
+ String _defaultValueLiteral_1 = a.getDefaultValueLiteral();
+ CharSequence _attributeInit = this.attributeInit(a, _defaultValueLiteral_1);
+ _xifexpression_1 = _attributeInit;
+ } else {
+ CharSequence _xifexpression_2 = null;
+ boolean _needsInitialization = this.languageExt.needsInitialization(a);
+ if (_needsInitialization) {
+ String _nullPointer = this.languageExt.nullPointer();
+ CharSequence _attributeInit_1 = this.attributeInit(a, _nullPointer);
+ _xifexpression_2 = _attributeInit_1;
+ }
+ _xifexpression_1 = _xifexpression_2;
+ }
+ _xifexpression = _xifexpression_1;
+ } else {
+ CharSequence _xifexpression_3 = null;
+ boolean _isPrimitive = this.typeHelpers.isPrimitive(aType);
+ if (_isPrimitive) {
+ CharSequence _xblockexpression_1 = null;
+ {
+ ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
+ String value = this.getDataConfigValue(_union, roomClass);
+ boolean _equals = Objects.equal(value, null);
+ if (_equals) {
+ String _defaultValueLiteral_2 = a.getDefaultValueLiteral();
+ value = _defaultValueLiteral_2;
+ }
+ CharSequence _xifexpression_4 = null;
+ boolean _notEquals_1 = (!Objects.equal(value, null));
+ if (_notEquals_1) {
+ String _valueLiteral = this.languageExt.toValueLiteral(((PrimitiveType) aType), value);
+ CharSequence _attributeInit_2 = this.attributeInit(a, _valueLiteral);
+ _xifexpression_4 = _attributeInit_2;
+ } else {
+ CharSequence _xifexpression_5 = null;
+ boolean _or = false;
+ boolean _not = (!useClassDefaultsOnly);
+ if (_not) {
+ _or = true;
+ } else {
+ boolean _needsInitialization_1 = this.languageExt.needsInitialization(a);
+ _or = (_not || _needsInitialization_1);
+ }
+ if (_or) {
+ String _defaultValue = this.languageExt.defaultValue(aType);
+ CharSequence _attributeInit_3 = this.attributeInit(a, _defaultValue);
+ _xifexpression_5 = _attributeInit_3;
+ }
+ _xifexpression_4 = _xifexpression_5;
+ }
+ _xblockexpression_1 = (_xifexpression_4);
+ }
+ _xifexpression_3 = _xblockexpression_1;
+ } else {
+ String _defaultValue = this.languageExt.defaultValue(aType);
+ CharSequence _attributeInit_2 = this.attributeInit(a, _defaultValue);
+ _xifexpression_3 = _attributeInit_2;
+ }
+ _xifexpression = _xifexpression_3;
+ }
+ _xblockexpression = (_xifexpression);
+ }
+ return _xblockexpression;
+ }
+
+ private CharSequence attributeInitPrimitiveRec(final List<Attribute> path, final EObject roomClass) {
+ CharSequence _xblockexpression = null;
+ {
+ Attribute a = IterableExtensions.<Attribute>last(path);
+ RefableType _refType = a.getRefType();
+ DataType aType = _refType.getType();
+ CharSequence _xifexpression = null;
+ boolean _isDataClass = this.typeHelpers.isDataClass(aType);
+ if (_isDataClass) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(((DataClass) aType));
+ for(final Attribute e : _allAttributes) {
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(path, e);
+ CharSequence _attributeInitPrimitiveRec = this.attributeInitPrimitiveRec(_union, roomClass);
+ _builder.append(_attributeInitPrimitiveRec, "");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ return _builder;
+ } else {
+ CharSequence _xifexpression_1 = null;
+ boolean _isPrimitive = this.typeHelpers.isPrimitive(aType);
+ if (_isPrimitive) {
+ String value = this.getDataConfigValue(path, roomClass);
+ CharSequence _xifexpression_2 = null;
+ boolean _notEquals = (!Objects.equal(value, null));
+ if (_notEquals) {
+ String _valueLiteral = this.languageExt.toValueLiteral(((PrimitiveType) aType), value);
+ CharSequence _attributeInit = this.attributeInit(path, _valueLiteral);
+ _xifexpression_2 = _attributeInit;
+ }
+ return _xifexpression_2;
+ }
+ _xifexpression = _xifexpression_1;
+ }
+ _xblockexpression = (_xifexpression);
+ }
+ return _xblockexpression;
+ }
+
+ private CharSequence attributeInit(final Attribute a, final String value) {
+ ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
+ CharSequence _attributeInit = this.attributeInit(_union, value);
+ return _attributeInit;
+ }
+
+ private CharSequence attributeInit(final List<Attribute> path, final String value) {
+ String _xifexpression = null;
+ int _size = path.size();
+ boolean _equals = (_size == 1);
+ if (_equals) {
+ _xifexpression = "this";
+ } else {
+ int _size_1 = path.size();
+ int _minus = (_size_1 - 1);
+ Iterable<Attribute> _take = IterableExtensions.<Attribute>take(path, _minus);
+ CharSequence _invokeGetters = this.procedureHelpers.invokeGetters(_take, null);
+ String _string = _invokeGetters.toString();
+ _xifexpression = _string;
+ }
+ final String getter = _xifexpression;
+ Attribute _last = IterableExtensions.<Attribute>last(path);
+ return this.genAttributeInitializer(_last, value, getter);
+ }
+
+ public CharSequence genAttributeInitializer(final Attribute a, final String value, final String invokes) {
+ CharSequence _xblockexpression = null;
+ {
+ RefableType _refType = a.getRefType();
+ DataType aType = _refType.getType();
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ boolean _or = false;
+ int _size = a.getSize();
+ boolean _equals = (_size == 0);
+ if (_equals) {
+ _or = true;
+ } else {
+ boolean _and = false;
+ boolean _and_1 = false;
+ int _size_1 = a.getSize();
+ boolean _greaterThan = (_size_1 > 0);
+ if (!_greaterThan) {
+ _and_1 = false;
+ } else {
+ String _typeName = this.typeHelpers.typeName(aType);
+ boolean _equals_1 = "char".equals(_typeName);
+ _and_1 = (_greaterThan && _equals_1);
+ }
+ if (!_and_1) {
+ _and = false;
+ } else {
+ boolean _matches = value.matches("\'.\'|\\(char\\).*");
+ boolean _not = (!_matches);
+ _and = (_and_1 && _not);
+ }
+ _or = (_equals || _and);
+ }
+ if (_or) {
+ _builder.append(invokes, "");
+ _builder.append(".");
+ String _name = a.getName();
+ CharSequence _invokeSetter = this.procedureHelpers.invokeSetter(_name, null, value);
+ _builder.append(_invokeSetter, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ } else {
+ boolean _or_1 = false;
+ String _trim = value.trim();
+ boolean _startsWith = _trim.startsWith("{");
+ boolean _not_1 = (!_startsWith);
+ if (_not_1) {
+ _or_1 = true;
+ } else {
+ String _typeName_1 = this.typeHelpers.typeName(aType);
+ boolean _equals_2 = "char".equals(_typeName_1);
+ _or_1 = (_not_1 || _equals_2);
+ }
+ if (_or_1) {
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t");
+ String _typeName_2 = this.typeHelpers.typeName(aType);
+ _builder.append(_typeName_2, " ");
+ _builder.append("[] array = new ");
+ String _typeName_3 = this.typeHelpers.typeName(aType);
+ _builder.append(_typeName_3, " ");
+ _builder.append("[");
+ int _size_2 = a.getSize();
+ _builder.append(_size_2, " ");
+ _builder.append("];");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _and_2 = false;
+ RefableType _refType_1 = a.getRefType();
+ boolean _isRef = _refType_1.isRef();
+ if (!_isRef) {
+ _and_2 = false;
+ } else {
+ boolean _isPrimitive = this.typeHelpers.isPrimitive(aType);
+ _and_2 = (_isRef && _isPrimitive);
+ }
+ boolean _not_2 = (!_and_2);
+ if (_not_2) {
+ _builder.append("\t");
+ _builder.append("for (int i=0;i<");
+ int _size_3 = a.getSize();
+ _builder.append(_size_3, " ");
+ _builder.append(";i++){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("array[i] = ");
+ _builder.append(value, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append(invokes, " ");
+ _builder.append(".");
+ String _name_1 = a.getName();
+ CharSequence _invokeSetter_1 = this.procedureHelpers.invokeSetter(_name_1, null, "array");
+ _builder.append(_invokeSetter_1, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ } else {
+ _builder.append(invokes, "");
+ _builder.append(".");
+ String _name_2 = a.getName();
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("new ");
+ String _typeName_4 = this.typeHelpers.typeName(aType);
+ _builder_1.append(_typeName_4, "");
+ _builder_1.append("[] ");
+ _builder_1.append(value, "");
+ CharSequence _invokeSetter_2 = this.procedureHelpers.invokeSetter(_name_2, null, _builder_1.toString());
+ _builder.append(_invokeSetter_2, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+
+ private String getDataConfigValue(final List<Attribute> path, final EObject roomClass) {
+ String _switchResult = null;
+ boolean _matched = false;
+ if (!_matched) {
+ if (roomClass instanceof ActorClass) {
+ final ActorClass _actorClass = (ActorClass)roomClass;
+ _matched=true;
+ String _attrClassConfigValue = this.typeHelpers.getAttrClassConfigValue(path, _actorClass, false);
+ _switchResult = _attrClassConfigValue;
+ }
+ }
+ if (!_matched) {
+ if (roomClass instanceof PortClass) {
+ final PortClass _portClass = (PortClass)roomClass;
+ _matched=true;
+ String _attrClassConfigValue = this.typeHelpers.getAttrClassConfigValue(path, _portClass);
+ _switchResult = _attrClassConfigValue;
+ }
+ }
+ if (!_matched) {
+ if (roomClass instanceof DataClass) {
+ final DataClass _dataClass = (DataClass)roomClass;
+ _matched=true;
+ _switchResult = null;
+ }
+ }
+ return _switchResult;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java
index ac410a9b1..bc059bd4b 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java
@@ -1,480 +1,480 @@
-/**
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- */
-package org.eclipse.etrice.generator.java.gen;
-
-import com.google.common.base.Objects;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import java.util.List;
-import org.eclipse.etrice.core.room.Attribute;
-import org.eclipse.etrice.core.room.DataType;
-import org.eclipse.etrice.core.room.ExternalType;
-import org.eclipse.etrice.core.room.Message;
-import org.eclipse.etrice.core.room.PrimitiveType;
-import org.eclipse.etrice.core.room.RefableType;
-import org.eclipse.etrice.core.room.RoomClass;
-import org.eclipse.etrice.core.room.VarDecl;
-import org.eclipse.etrice.generator.generic.ILanguageExtension;
-import org.eclipse.etrice.generator.generic.TypeHelpers;
-import org.eclipse.xtend2.lib.StringConcatenation;
-import org.eclipse.xtext.util.Pair;
-import org.eclipse.xtext.xbase.lib.CollectionLiterals;
-import org.eclipse.xtext.xbase.lib.Conversions;
-import org.eclipse.xtext.xbase.lib.StringExtensions;
-
-@Singleton
-@SuppressWarnings("all")
-public class JavaExtensions implements ILanguageExtension {
- @Inject
- private TypeHelpers typeHelpers;
-
- public String getTypedDataDefinition(final Message m) {
- VarDecl _data = m.getData();
- String[] _generateArglistAndTypedData = this.generateArglistAndTypedData(_data);
- String _get = _generateArglistAndTypedData[1];
- return _get;
- }
-
- public String getJavaFileName(final RoomClass rc) {
- String _name = rc.getName();
- String _plus = (_name + ".java");
- return _plus;
- }
-
- public String toWrapper(final String type) {
- String _switchResult = null;
- boolean _matched = false;
- if (!_matched) {
- if (Objects.equal(type,"int")) {
- _matched=true;
- _switchResult = "Integer";
- }
- }
- if (!_matched) {
- if (Objects.equal(type,"char")) {
- _matched=true;
- _switchResult = "Character";
- }
- }
- if (!_matched) {
- String _firstUpper = StringExtensions.toFirstUpper(type);
- _switchResult = _firstUpper;
- }
- return _switchResult;
- }
-
- public boolean needsInitialization(final Attribute a) {
- boolean _or = false;
- boolean _or_1 = false;
- int _size = a.getSize();
- boolean _greaterThan = (_size > 0);
- if (_greaterThan) {
- _or_1 = true;
- } else {
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- boolean _isPrimitive = this.typeHelpers.isPrimitive(_type);
- boolean _not = (!_isPrimitive);
- _or_1 = (_greaterThan || _not);
- }
- if (_or_1) {
- _or = true;
- } else {
- RefableType _refType_1 = a.getRefType();
- DataType _type_1 = _refType_1.getType();
- String _typeName = this.typeHelpers.typeName(_type_1);
- boolean _equals = _typeName.equals("String");
- _or = (_or_1 || _equals);
- }
- return _or;
- }
-
- public String accessLevelPrivate() {
- return "private ";
- }
-
- public String accessLevelProtected() {
- return "protected ";
- }
-
- public String accessLevelPublic() {
- return "public ";
- }
-
- public String memberAccess() {
- return "this.";
- }
-
- public String selfPointer(final String classname, final boolean hasArgs) {
- return "";
- }
-
- public String selfPointer(final boolean hasArgs) {
- return "";
- }
-
- public String operationScope(final String classname, final boolean isDeclaration) {
- return "";
- }
-
- public String memberInDeclaration(final String namespace, final String member) {
- return member;
- }
-
- public String memberInUse(final String namespace, final String member) {
- String _plus = (namespace + ".");
- return (_plus + member);
- }
-
- public boolean usesInheritance() {
- return true;
- }
-
- public boolean usesPointers() {
- return false;
- }
-
- public String genEnumeration(final String name, final List<Pair<String,String>> entries) {
- StringConcatenation _builder = new StringConcatenation();
- {
- for(final Pair<String,String> entry : entries) {
- _builder.append("public static final int ");
- String _first = entry.getFirst();
- _builder.append(_first, "");
- _builder.append(" = ");
- String _second = entry.getSecond();
- _builder.append(_second, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- String _string = _builder.toString();
- return _string;
- }
-
- public String booleanConstant(final boolean b) {
- String _string = Boolean.valueOf(b).toString();
- return _string;
- }
-
- public String pointerLiteral() {
- return "";
- }
-
- public String nullPointer() {
- return "null";
- }
-
- public String voidPointer() {
- return "Object";
- }
-
- public String arrayDeclaration(final String type, final int size, final String name, final boolean isRef) {
- String _plus = (type + " ");
- String _plus_1 = (_plus + name);
- String _plus_2 = (_plus_1 + "[]");
- return _plus_2;
- }
-
- public String constructorName(final String cls) {
- return cls;
- }
-
- public String destructorName(final String cls) {
- String _plus = (cls + "_dtor");
- return _plus;
- }
-
- public String constructorReturnType() {
- return "";
- }
-
- public String destructorReturnType() {
- return "void";
- }
-
- public String superCall(final String baseClassName, final String method, final String args) {
- String _plus = ("super." + method);
- String _plus_1 = (_plus + "(");
- String _plus_2 = (_plus_1 + args);
- String _plus_3 = (_plus_2 + ");");
- return _plus_3;
- }
-
- public String toValueLiteral(final PrimitiveType type, final String value) {
- String _switchResult = null;
- String _targetName = type.getTargetName();
- final String _switchValue = _targetName;
- boolean _matched = false;
- if (!_matched) {
- boolean _and = false;
- boolean _isCharacterType = this.typeHelpers.isCharacterType(type);
- boolean _not = (!_isCharacterType);
- if (!_not) {
- _and = false;
- } else {
- boolean _contains = value.contains(",");
- _and = (_not && _contains);
- }
- if (_and) {
- _matched=true;
- String _xblockexpression = null;
- {
- String _replace = value.replace("{", "");
- String _replace_1 = _replace.replace("}", "");
- String _trim = _replace_1.trim();
- String[] singleValues = _trim.split(",");
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("{ ");
- {
- boolean _hasElements = false;
- for(final String v : singleValues) {
- if (!_hasElements) {
- _hasElements = true;
- } else {
- _builder.appendImmediate(", ", "");
- }
- String _trim_1 = v.trim();
- String _castValue = this.castValue(type, _trim_1);
- _builder.append(_castValue, "");
- }
- }
- _builder.append(" }");
- String _string = _builder.toString();
- _xblockexpression = (_string);
- }
- _switchResult = _xblockexpression;
- }
- }
- if (!_matched) {
- String _castValue = this.castValue(type, value);
- _switchResult = _castValue;
- }
- return _switchResult;
- }
-
- private String castValue(final PrimitiveType type, final String value) {
- String _switchResult = null;
- String _targetName = type.getTargetName();
- final String _switchValue = _targetName;
- boolean _matched = false;
- if (!_matched) {
- if (Objects.equal(_switchValue,"boolean")) {
- _matched=true;
- String _lowerCase = value.toLowerCase();
- _switchResult = _lowerCase;
- }
- }
- if (!_matched) {
- if (Objects.equal(_switchValue,"byte")) {
- _matched=true;
- String _plus = ("(byte)" + value);
- _switchResult = _plus;
- }
- }
- if (!_matched) {
- if (Objects.equal(_switchValue,"short")) {
- _matched=true;
- String _plus_1 = ("(short)" + value);
- _switchResult = _plus_1;
- }
- }
- if (!_matched) {
- if (Objects.equal(_switchValue,"int")) {
- _matched=true;
- _switchResult = value;
- }
- }
- if (!_matched) {
- if (Objects.equal(_switchValue,"long")) {
- _matched=true;
- String _plus_2 = (value + "L");
- _switchResult = _plus_2;
- }
- }
- if (!_matched) {
- if (Objects.equal(_switchValue,"float")) {
- _matched=true;
- String _plus_3 = (value + "f");
- _switchResult = _plus_3;
- }
- }
- if (!_matched) {
- if (Objects.equal(_switchValue,"double")) {
- _matched=true;
- String _plus_4 = (value + "d");
- _switchResult = _plus_4;
- }
- }
- if (!_matched) {
- if (Objects.equal(_switchValue,"char")) {
- _matched=true;
- String _xifexpression = null;
- boolean _isEmpty = value.isEmpty();
- if (_isEmpty) {
- _xifexpression = "(char) 0";
- } else {
- String _xifexpression_1 = null;
- int _length = value.length();
- boolean _equals = (_length == 1);
- if (_equals) {
- char _charAt = value.charAt(0);
- String _plus_5 = ("\'" + Character.valueOf(_charAt));
- String _plus_6 = (_plus_5 + "\'");
- _xifexpression_1 = _plus_6;
- } else {
- String _replace = value.replace("\\", "\\\\");
- String _replace_1 = _replace.replace("\"", "\\\"");
- String _plus_7 = ("\"" + _replace_1);
- String _plus_8 = (_plus_7 + "\".toCharArray()");
- _xifexpression_1 = _plus_8;
- }
- _xifexpression = _xifexpression_1;
- }
- _switchResult = _xifexpression;
- }
- }
- if (!_matched) {
- if (Objects.equal(_switchValue,"String")) {
- _matched=true;
- String _replace_2 = value.replace("\\", "\\\\");
- String _replace_3 = _replace_2.replace("\"", "\\\"");
- String _plus_9 = ("\"" + _replace_3);
- String _plus_10 = (_plus_9 + "\"");
- _switchResult = _plus_10;
- }
- }
- if (!_matched) {
- String _targetName_1 = type.getTargetName();
- UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException(_targetName_1);
- throw _unsupportedOperationException;
- }
- return _switchResult;
- }
-
- public String defaultValue(final DataType dt) {
- String _switchResult = null;
- boolean _matched = false;
- if (!_matched) {
- if (dt instanceof PrimitiveType) {
- final PrimitiveType _primitiveType = (PrimitiveType)dt;
- _matched=true;
- String _defaultValueLiteral = _primitiveType.getDefaultValueLiteral();
- String _valueLiteral = this.toValueLiteral(_primitiveType, _defaultValueLiteral);
- _switchResult = _valueLiteral;
- }
- }
- if (!_matched) {
- if (dt instanceof ExternalType) {
- final ExternalType _externalType = (ExternalType)dt;
- _matched=true;
- String _targetName = ((ExternalType) _externalType).getTargetName();
- String _plus = ("new " + _targetName);
- String _plus_1 = (_plus + "()");
- _switchResult = _plus_1;
- }
- }
- if (!_matched) {
- String _name = dt.getName();
- String _plus = ("new " + _name);
- String _plus_1 = (_plus + "()");
- _switchResult = _plus_1;
- }
- return _switchResult;
- }
-
- public String initializationWithDefaultValues(final DataType dt, final int size) {
- String _xblockexpression = null;
- {
- final String dv = this.defaultValue(dt);
- String _xifexpression = null;
- boolean _greaterThan = (size > 1);
- if (_greaterThan) {
- String _xblockexpression_1 = null;
- {
- String res = "{";
- int i = 0;
- boolean _lessThan = (i < size);
- boolean _while = _lessThan;
- while (_while) {
- {
- String _plus = (res + dv);
- res = _plus;
- int _plus_1 = (i + 1);
- i = _plus_1;
- boolean _lessThan_1 = (i < size);
- if (_lessThan_1) {
- String _plus_2 = (res + ",");
- res = _plus_2;
- }
- }
- boolean _lessThan_1 = (i < size);
- _while = _lessThan_1;
- }
- String _plus = (res + "}");
- _xblockexpression_1 = (_plus);
- }
- _xifexpression = _xblockexpression_1;
- } else {
- _xifexpression = dv;
- }
- _xblockexpression = (_xifexpression);
- }
- return _xblockexpression;
- }
-
- public String[] generateArglistAndTypedData(final VarDecl data) {
- boolean _equals = Objects.equal(data, null);
- if (_equals) {
- return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList("", "", ""), String.class));
- }
- RefableType _refType = data.getRefType();
- DataType _type = _refType.getType();
- String typeName = _type.getName();
- String castTypeName = typeName;
- RefableType _refType_1 = data.getRefType();
- DataType _type_1 = _refType_1.getType();
- if ((_type_1 instanceof PrimitiveType)) {
- RefableType _refType_2 = data.getRefType();
- DataType _type_2 = _refType_2.getType();
- String _targetName = ((PrimitiveType) _type_2).getTargetName();
- typeName = _targetName;
- RefableType _refType_3 = data.getRefType();
- DataType _type_3 = _refType_3.getType();
- final String ct = ((PrimitiveType) _type_3).getCastName();
- boolean _and = false;
- boolean _notEquals = (!Objects.equal(ct, null));
- if (!_notEquals) {
- _and = false;
- } else {
- boolean _isEmpty = ct.isEmpty();
- boolean _not = (!_isEmpty);
- _and = (_notEquals && _not);
- }
- if (_and) {
- castTypeName = ct;
- }
- }
- String _plus = (typeName + " ");
- String _name = data.getName();
- String _plus_1 = (_plus + _name);
- String _plus_2 = (_plus_1 + " = (");
- String _plus_3 = (_plus_2 + castTypeName);
- final String typedData = (_plus_3 + ") generic_data;\n");
- String _name_1 = data.getName();
- final String dataArg = (", " + _name_1);
- String _plus_4 = (", " + typeName);
- String _plus_5 = (_plus_4 + " ");
- String _name_2 = data.getName();
- final String typedArgList = (_plus_5 + _name_2);
- return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList(dataArg, typedData, typedArgList), String.class));
- }
-}
+/**
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ */
+package org.eclipse.etrice.generator.java.gen;
+
+import com.google.common.base.Objects;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.List;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.ExternalType;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.core.room.PrimitiveType;
+import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.core.room.RoomClass;
+import org.eclipse.etrice.core.room.VarDecl;
+import org.eclipse.etrice.generator.generic.ILanguageExtension;
+import org.eclipse.etrice.generator.generic.TypeHelpers;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.util.Pair;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Conversions;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+
+@Singleton
+@SuppressWarnings("all")
+public class JavaExtensions implements ILanguageExtension {
+ @Inject
+ private TypeHelpers typeHelpers;
+
+ public String getTypedDataDefinition(final Message m) {
+ VarDecl _data = m.getData();
+ String[] _generateArglistAndTypedData = this.generateArglistAndTypedData(_data);
+ String _get = _generateArglistAndTypedData[1];
+ return _get;
+ }
+
+ public String getJavaFileName(final RoomClass rc) {
+ String _name = rc.getName();
+ String _plus = (_name + ".java");
+ return _plus;
+ }
+
+ public String toWrapper(final String type) {
+ String _switchResult = null;
+ boolean _matched = false;
+ if (!_matched) {
+ if (Objects.equal(type,"int")) {
+ _matched=true;
+ _switchResult = "Integer";
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(type,"char")) {
+ _matched=true;
+ _switchResult = "Character";
+ }
+ }
+ if (!_matched) {
+ String _firstUpper = StringExtensions.toFirstUpper(type);
+ _switchResult = _firstUpper;
+ }
+ return _switchResult;
+ }
+
+ public boolean needsInitialization(final Attribute a) {
+ boolean _or = false;
+ boolean _or_1 = false;
+ int _size = a.getSize();
+ boolean _greaterThan = (_size > 0);
+ if (_greaterThan) {
+ _or_1 = true;
+ } else {
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ boolean _isPrimitive = this.typeHelpers.isPrimitive(_type);
+ boolean _not = (!_isPrimitive);
+ _or_1 = (_greaterThan || _not);
+ }
+ if (_or_1) {
+ _or = true;
+ } else {
+ RefableType _refType_1 = a.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ String _typeName = this.typeHelpers.typeName(_type_1);
+ boolean _equals = _typeName.equals("String");
+ _or = (_or_1 || _equals);
+ }
+ return _or;
+ }
+
+ public String accessLevelPrivate() {
+ return "private ";
+ }
+
+ public String accessLevelProtected() {
+ return "protected ";
+ }
+
+ public String accessLevelPublic() {
+ return "public ";
+ }
+
+ public String memberAccess() {
+ return "this.";
+ }
+
+ public String selfPointer(final String classname, final boolean hasArgs) {
+ return "";
+ }
+
+ public String selfPointer(final boolean hasArgs) {
+ return "";
+ }
+
+ public String operationScope(final String classname, final boolean isDeclaration) {
+ return "";
+ }
+
+ public String memberInDeclaration(final String namespace, final String member) {
+ return member;
+ }
+
+ public String memberInUse(final String namespace, final String member) {
+ String _plus = (namespace + ".");
+ return (_plus + member);
+ }
+
+ public boolean usesInheritance() {
+ return true;
+ }
+
+ public boolean usesPointers() {
+ return false;
+ }
+
+ public String genEnumeration(final String name, final List<Pair<String,String>> entries) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ for(final Pair<String,String> entry : entries) {
+ _builder.append("public static final int ");
+ String _first = entry.getFirst();
+ _builder.append(_first, "");
+ _builder.append(" = ");
+ String _second = entry.getSecond();
+ _builder.append(_second, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ String _string = _builder.toString();
+ return _string;
+ }
+
+ public String booleanConstant(final boolean b) {
+ String _string = Boolean.valueOf(b).toString();
+ return _string;
+ }
+
+ public String pointerLiteral() {
+ return "";
+ }
+
+ public String nullPointer() {
+ return "null";
+ }
+
+ public String voidPointer() {
+ return "Object";
+ }
+
+ public String arrayDeclaration(final String type, final int size, final String name, final boolean isRef) {
+ String _plus = (type + " ");
+ String _plus_1 = (_plus + name);
+ String _plus_2 = (_plus_1 + "[]");
+ return _plus_2;
+ }
+
+ public String constructorName(final String cls) {
+ return cls;
+ }
+
+ public String destructorName(final String cls) {
+ String _plus = (cls + "_dtor");
+ return _plus;
+ }
+
+ public String constructorReturnType() {
+ return "";
+ }
+
+ public String destructorReturnType() {
+ return "void";
+ }
+
+ public String superCall(final String baseClassName, final String method, final String args) {
+ String _plus = ("super." + method);
+ String _plus_1 = (_plus + "(");
+ String _plus_2 = (_plus_1 + args);
+ String _plus_3 = (_plus_2 + ");");
+ return _plus_3;
+ }
+
+ public String toValueLiteral(final PrimitiveType type, final String value) {
+ String _switchResult = null;
+ String _targetName = type.getTargetName();
+ final String _switchValue = _targetName;
+ boolean _matched = false;
+ if (!_matched) {
+ boolean _and = false;
+ boolean _isCharacterType = this.typeHelpers.isCharacterType(type);
+ boolean _not = (!_isCharacterType);
+ if (!_not) {
+ _and = false;
+ } else {
+ boolean _contains = value.contains(",");
+ _and = (_not && _contains);
+ }
+ if (_and) {
+ _matched=true;
+ String _xblockexpression = null;
+ {
+ String _replace = value.replace("{", "");
+ String _replace_1 = _replace.replace("}", "");
+ String _trim = _replace_1.trim();
+ String[] singleValues = _trim.split(",");
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("{ ");
+ {
+ boolean _hasElements = false;
+ for(final String v : singleValues) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(", ", "");
+ }
+ String _trim_1 = v.trim();
+ String _castValue = this.castValue(type, _trim_1);
+ _builder.append(_castValue, "");
+ }
+ }
+ _builder.append(" }");
+ String _string = _builder.toString();
+ _xblockexpression = (_string);
+ }
+ _switchResult = _xblockexpression;
+ }
+ }
+ if (!_matched) {
+ String _castValue = this.castValue(type, value);
+ _switchResult = _castValue;
+ }
+ return _switchResult;
+ }
+
+ private String castValue(final PrimitiveType type, final String value) {
+ String _switchResult = null;
+ String _targetName = type.getTargetName();
+ final String _switchValue = _targetName;
+ boolean _matched = false;
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"boolean")) {
+ _matched=true;
+ String _lowerCase = value.toLowerCase();
+ _switchResult = _lowerCase;
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"byte")) {
+ _matched=true;
+ String _plus = ("(byte)" + value);
+ _switchResult = _plus;
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"short")) {
+ _matched=true;
+ String _plus_1 = ("(short)" + value);
+ _switchResult = _plus_1;
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"int")) {
+ _matched=true;
+ _switchResult = value;
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"long")) {
+ _matched=true;
+ String _plus_2 = (value + "L");
+ _switchResult = _plus_2;
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"float")) {
+ _matched=true;
+ String _plus_3 = (value + "f");
+ _switchResult = _plus_3;
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"double")) {
+ _matched=true;
+ String _plus_4 = (value + "d");
+ _switchResult = _plus_4;
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"char")) {
+ _matched=true;
+ String _xifexpression = null;
+ boolean _isEmpty = value.isEmpty();
+ if (_isEmpty) {
+ _xifexpression = "(char) 0";
+ } else {
+ String _xifexpression_1 = null;
+ int _length = value.length();
+ boolean _equals = (_length == 1);
+ if (_equals) {
+ char _charAt = value.charAt(0);
+ String _plus_5 = ("\'" + Character.valueOf(_charAt));
+ String _plus_6 = (_plus_5 + "\'");
+ _xifexpression_1 = _plus_6;
+ } else {
+ String _replace = value.replace("\\", "\\\\");
+ String _replace_1 = _replace.replace("\"", "\\\"");
+ String _plus_7 = ("\"" + _replace_1);
+ String _plus_8 = (_plus_7 + "\".toCharArray()");
+ _xifexpression_1 = _plus_8;
+ }
+ _xifexpression = _xifexpression_1;
+ }
+ _switchResult = _xifexpression;
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"String")) {
+ _matched=true;
+ String _replace_2 = value.replace("\\", "\\\\");
+ String _replace_3 = _replace_2.replace("\"", "\\\"");
+ String _plus_9 = ("\"" + _replace_3);
+ String _plus_10 = (_plus_9 + "\"");
+ _switchResult = _plus_10;
+ }
+ }
+ if (!_matched) {
+ String _targetName_1 = type.getTargetName();
+ UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException(_targetName_1);
+ throw _unsupportedOperationException;
+ }
+ return _switchResult;
+ }
+
+ public String defaultValue(final DataType dt) {
+ String _switchResult = null;
+ boolean _matched = false;
+ if (!_matched) {
+ if (dt instanceof PrimitiveType) {
+ final PrimitiveType _primitiveType = (PrimitiveType)dt;
+ _matched=true;
+ String _defaultValueLiteral = _primitiveType.getDefaultValueLiteral();
+ String _valueLiteral = this.toValueLiteral(_primitiveType, _defaultValueLiteral);
+ _switchResult = _valueLiteral;
+ }
+ }
+ if (!_matched) {
+ if (dt instanceof ExternalType) {
+ final ExternalType _externalType = (ExternalType)dt;
+ _matched=true;
+ String _targetName = ((ExternalType) _externalType).getTargetName();
+ String _plus = ("new " + _targetName);
+ String _plus_1 = (_plus + "()");
+ _switchResult = _plus_1;
+ }
+ }
+ if (!_matched) {
+ String _name = dt.getName();
+ String _plus = ("new " + _name);
+ String _plus_1 = (_plus + "()");
+ _switchResult = _plus_1;
+ }
+ return _switchResult;
+ }
+
+ public String initializationWithDefaultValues(final DataType dt, final int size) {
+ String _xblockexpression = null;
+ {
+ final String dv = this.defaultValue(dt);
+ String _xifexpression = null;
+ boolean _greaterThan = (size > 1);
+ if (_greaterThan) {
+ String _xblockexpression_1 = null;
+ {
+ String res = "{";
+ int i = 0;
+ boolean _lessThan = (i < size);
+ boolean _while = _lessThan;
+ while (_while) {
+ {
+ String _plus = (res + dv);
+ res = _plus;
+ int _plus_1 = (i + 1);
+ i = _plus_1;
+ boolean _lessThan_1 = (i < size);
+ if (_lessThan_1) {
+ String _plus_2 = (res + ",");
+ res = _plus_2;
+ }
+ }
+ boolean _lessThan_1 = (i < size);
+ _while = _lessThan_1;
+ }
+ String _plus = (res + "}");
+ _xblockexpression_1 = (_plus);
+ }
+ _xifexpression = _xblockexpression_1;
+ } else {
+ _xifexpression = dv;
+ }
+ _xblockexpression = (_xifexpression);
+ }
+ return _xblockexpression;
+ }
+
+ public String[] generateArglistAndTypedData(final VarDecl data) {
+ boolean _equals = Objects.equal(data, null);
+ if (_equals) {
+ return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList("", "", ""), String.class));
+ }
+ RefableType _refType = data.getRefType();
+ DataType _type = _refType.getType();
+ String typeName = _type.getName();
+ String castTypeName = typeName;
+ RefableType _refType_1 = data.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ if ((_type_1 instanceof PrimitiveType)) {
+ RefableType _refType_2 = data.getRefType();
+ DataType _type_2 = _refType_2.getType();
+ String _targetName = ((PrimitiveType) _type_2).getTargetName();
+ typeName = _targetName;
+ RefableType _refType_3 = data.getRefType();
+ DataType _type_3 = _refType_3.getType();
+ final String ct = ((PrimitiveType) _type_3).getCastName();
+ boolean _and = false;
+ boolean _notEquals = (!Objects.equal(ct, null));
+ if (!_notEquals) {
+ _and = false;
+ } else {
+ boolean _isEmpty = ct.isEmpty();
+ boolean _not = (!_isEmpty);
+ _and = (_notEquals && _not);
+ }
+ if (_and) {
+ castTypeName = ct;
+ }
+ }
+ String _plus = (typeName + " ");
+ String _name = data.getName();
+ String _plus_1 = (_plus + _name);
+ String _plus_2 = (_plus_1 + " = (");
+ String _plus_3 = (_plus_2 + castTypeName);
+ final String typedData = (_plus_3 + ") generic_data;\n");
+ String _name_1 = data.getName();
+ final String dataArg = (", " + _name_1);
+ String _plus_4 = (", " + typeName);
+ String _plus_5 = (_plus_4 + " ");
+ String _name_2 = data.getName();
+ final String typedArgList = (_plus_5 + _name_2);
+ return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList(dataArg, typedData, typedArgList), String.class));
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/MainGen.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/MainGen.java
index 7f6f3f678..5f718b49e 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/MainGen.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/MainGen.java
@@ -1,70 +1,70 @@
-/**
- * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- */
-package org.eclipse.etrice.generator.java.gen;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.etrice.core.genmodel.etricegen.Root;
-import org.eclipse.etrice.generator.generic.PrepareFileSystem;
-import org.eclipse.etrice.generator.java.gen.ActorClassGen;
-import org.eclipse.etrice.generator.java.gen.DataClassGen;
-import org.eclipse.etrice.generator.java.gen.ProtocolClassGen;
-import org.eclipse.etrice.generator.java.gen.SubSystemClassGen;
-import org.eclipse.etrice.generator.java.gen.SubSystemRunnerGen;
-import org.eclipse.xtext.generator.IFileSystemAccess;
-import org.eclipse.xtext.generator.IGenerator;
-
-@Singleton
-@SuppressWarnings("all")
-public class MainGen implements IGenerator {
- @Inject
- private DataClassGen dataClassGen;
-
- @Inject
- private ProtocolClassGen protocolClassGen;
-
- @Inject
- private ActorClassGen actorClassGen;
-
- @Inject
- private SubSystemClassGen subsystemClassGen;
-
- @Inject
- private SubSystemRunnerGen subsystemRunnerGen;
-
- @Inject
- private PrepareFileSystem prepFS;
-
- public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
- this.prepFS.prepare(resource);
- EList<EObject> _contents = resource.getContents();
- for (final EObject e : _contents) {
- if ((e instanceof Root)) {
- this.doGenerate(((Root) e));
- }
- }
- }
-
- public void doGenerate(final Root e) {
- this.dataClassGen.doGenerate(e);
- this.protocolClassGen.doGenerate(e);
- this.actorClassGen.doGenerate(e);
- this.subsystemClassGen.doGenerate(e);
- boolean _isLibrary = e.isLibrary();
- boolean _not = (!_isLibrary);
- if (_not) {
- this.subsystemRunnerGen.doGenerate(e);
- }
- }
-}
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ */
+package org.eclipse.etrice.generator.java.gen;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.etrice.core.genmodel.etricegen.Root;
+import org.eclipse.etrice.generator.generic.PrepareFileSystem;
+import org.eclipse.etrice.generator.java.gen.ActorClassGen;
+import org.eclipse.etrice.generator.java.gen.DataClassGen;
+import org.eclipse.etrice.generator.java.gen.ProtocolClassGen;
+import org.eclipse.etrice.generator.java.gen.SubSystemClassGen;
+import org.eclipse.etrice.generator.java.gen.SubSystemRunnerGen;
+import org.eclipse.xtext.generator.IFileSystemAccess;
+import org.eclipse.xtext.generator.IGenerator;
+
+@Singleton
+@SuppressWarnings("all")
+public class MainGen implements IGenerator {
+ @Inject
+ private DataClassGen dataClassGen;
+
+ @Inject
+ private ProtocolClassGen protocolClassGen;
+
+ @Inject
+ private ActorClassGen actorClassGen;
+
+ @Inject
+ private SubSystemClassGen subsystemClassGen;
+
+ @Inject
+ private SubSystemRunnerGen subsystemRunnerGen;
+
+ @Inject
+ private PrepareFileSystem prepFS;
+
+ public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
+ this.prepFS.prepare(resource);
+ EList<EObject> _contents = resource.getContents();
+ for (final EObject e : _contents) {
+ if ((e instanceof Root)) {
+ this.doGenerate(((Root) e));
+ }
+ }
+ }
+
+ public void doGenerate(final Root e) {
+ this.dataClassGen.doGenerate(e);
+ this.protocolClassGen.doGenerate(e);
+ this.actorClassGen.doGenerate(e);
+ this.subsystemClassGen.doGenerate(e);
+ boolean _isLibrary = e.isLibrary();
+ boolean _not = (!_isLibrary);
+ if (_not) {
+ this.subsystemRunnerGen.doGenerate(e);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.java
index 706e555ec..83542d404 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.java
@@ -1,1111 +1,1111 @@
-/**
- * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- */
-package org.eclipse.etrice.generator.java.gen;
-
-import com.google.common.base.Objects;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import java.util.List;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.etrice.core.genmodel.base.ILogger;
-import org.eclipse.etrice.core.genmodel.etricegen.Root;
-import org.eclipse.etrice.core.room.Attribute;
-import org.eclipse.etrice.core.room.CommunicationType;
-import org.eclipse.etrice.core.room.DataClass;
-import org.eclipse.etrice.core.room.DataType;
-import org.eclipse.etrice.core.room.DetailCode;
-import org.eclipse.etrice.core.room.Message;
-import org.eclipse.etrice.core.room.MessageHandler;
-import org.eclipse.etrice.core.room.PortClass;
-import org.eclipse.etrice.core.room.PortOperation;
-import org.eclipse.etrice.core.room.PrimitiveType;
-import org.eclipse.etrice.core.room.ProtocolClass;
-import org.eclipse.etrice.core.room.RefableType;
-import org.eclipse.etrice.core.room.RoomModel;
-import org.eclipse.etrice.core.room.VarDecl;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.generator.base.IGeneratorFileIo;
-import org.eclipse.etrice.generator.generic.GenericProtocolClassGenerator;
-import org.eclipse.etrice.generator.generic.ProcedureHelpers;
-import org.eclipse.etrice.generator.generic.RoomExtensions;
-import org.eclipse.etrice.generator.generic.TypeHelpers;
-import org.eclipse.etrice.generator.java.gen.DataClassGen;
-import org.eclipse.etrice.generator.java.gen.GlobalSettings;
-import org.eclipse.etrice.generator.java.gen.Initialization;
-import org.eclipse.etrice.generator.java.gen.JavaExtensions;
-import org.eclipse.xtend2.lib.StringConcatenation;
-import org.eclipse.xtext.xbase.lib.Extension;
-import org.eclipse.xtext.xbase.lib.Functions.Function1;
-import org.eclipse.xtext.xbase.lib.IterableExtensions;
-
-@Singleton
-@SuppressWarnings("all")
-public class ProtocolClassGen extends GenericProtocolClassGenerator {
- @Inject
- private IGeneratorFileIo fileIO;
-
- @Inject
- @Extension
- private JavaExtensions _javaExtensions;
-
- @Inject
- @Extension
- private RoomExtensions _roomExtensions;
-
- @Inject
- @Extension
- private ProcedureHelpers _procedureHelpers;
-
- @Inject
- @Extension
- private Initialization _initialization;
-
- @Inject
- @Extension
- private TypeHelpers _typeHelpers;
-
- @Inject
- @Extension
- private DataClassGen _dataClassGen;
-
- @Inject
- private ILogger logger;
-
- public void doGenerate(final Root root) {
- EList<ProtocolClass> _usedProtocolClasses = root.getUsedProtocolClasses();
- for (final ProtocolClass pc : _usedProtocolClasses) {
- {
- String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(pc);
- String _path = this._roomExtensions.getPath(pc);
- final String path = (_generationTargetPath + _path);
- String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(pc);
- String _path_1 = this._roomExtensions.getPath(pc);
- final String infopath = (_generationInfoPath + _path_1);
- final String file = this._javaExtensions.getJavaFileName(pc);
- CharSequence _switchResult = null;
- CommunicationType _commType = pc.getCommType();
- final CommunicationType _switchValue = _commType;
- boolean _matched = false;
- if (!_matched) {
- if (Objects.equal(_switchValue,CommunicationType.EVENT_DRIVEN)) {
- _matched=true;
- CharSequence _generate = this.generate(root, pc);
- _switchResult = _generate;
- }
- }
- if (!_matched) {
- if (Objects.equal(_switchValue,CommunicationType.DATA_DRIVEN)) {
- _matched=true;
- CharSequence _generateDataDriven = this.generateDataDriven(root, pc);
- _switchResult = _generateDataDriven;
- }
- }
- if (!_matched) {
- if (Objects.equal(_switchValue,CommunicationType.SYNCHRONOUS)) {
- _matched=true;
- _switchResult = "";
- }
- }
- final CharSequence contents = _switchResult;
- String _string = contents.toString();
- boolean _isEmpty = _string.isEmpty();
- if (_isEmpty) {
- this.logger.logError("synchronous protocols not supported yet", pc);
- } else {
- this.fileIO.generateFile("generating ProtocolClass implementation", path, infopath, file, contents);
- }
- }
- }
- }
-
- public CharSequence generate(final Root root, final ProtocolClass pc) {
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("package ");
- String _package = this._roomExtensions.getPackage(pc);
- _builder.append(_package, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.messaging.Message;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.EventMessage;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.EventWithDataMessage;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.IEventReceiver;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.PortBase;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.ReplicatedPortBase;");
- _builder.newLine();
- {
- boolean _generateMSCInstrumentation = GlobalSettings.generateMSCInstrumentation();
- if (_generateMSCInstrumentation) {
- _builder.append("import org.eclipse.etrice.runtime.java.debugging.DebuggingService;");
- _builder.newLine();
- }
- }
- _builder.append("import static org.eclipse.etrice.runtime.java.etunit.EtUnit.*;");
- _builder.newLine();
- _builder.newLine();
- CharSequence _userCode = this._procedureHelpers.userCode(pc, 1);
- _builder.append(_userCode, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- EList<RoomModel> models = root.getReferencedModels(pc);
- _builder.newLineIfNotEmpty();
- {
- for(final RoomModel model : models) {
- _builder.append("import ");
- String _name = model.getName();
- _builder.append(_name, "");
- _builder.append(".*;");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- _builder.append("public class ");
- String _name_1 = pc.getName();
- _builder.append(_name_1, "");
- _builder.append(" {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("// message IDs");
- _builder.newLine();
- _builder.append("\t");
- String _genMessageIDs = this.genMessageIDs(pc);
- _builder.append(_genMessageIDs, " ");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("\t");
- CharSequence _userCode_1 = this._procedureHelpers.userCode(pc, 2);
- _builder.append(_userCode_1, " ");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("private static String messageStrings[] = {\"MIN\", ");
- {
- List<Message> _allOutgoingMessages = RoomHelpers.getAllOutgoingMessages(pc);
- for(final Message m : _allOutgoingMessages) {
- _builder.append("\"");
- String _name_2 = m.getName();
- _builder.append(_name_2, " ");
- _builder.append("\",");
- }
- }
- _builder.append(" ");
- {
- List<Message> _allIncomingMessages = RoomHelpers.getAllIncomingMessages(pc);
- for(final Message m_1 : _allIncomingMessages) {
- _builder.append("\"");
- String _name_3 = m_1.getName();
- _builder.append(_name_3, " ");
- _builder.append("\",");
- }
- }
- _builder.append("\"MAX\"};");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public String getMessageString(int msg_id) {");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("if (msg_id<MSG_MIN || msg_id>MSG_MAX+1){");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("// id out of range");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("return \"Message ID out of range\";");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("else{");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("return messageStrings[msg_id];");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("\t");
- CharSequence _portClass = this.portClass(pc, Boolean.valueOf(false));
- _builder.append(_portClass, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- CharSequence _portClass_1 = this.portClass(pc, Boolean.valueOf(true));
- _builder.append(_portClass_1, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- return _builder;
- }
-
- public CharSequence portClass(final ProtocolClass pc, final Boolean conj) {
- CharSequence _xblockexpression = null;
- {
- PortClass pclass = this._roomExtensions.getPortClass(pc, (conj).booleanValue());
- String portClassName = this._roomExtensions.getPortClassName(pc, (conj).booleanValue());
- String replPortClassName = this._roomExtensions.getPortClassName(pc, (conj).booleanValue(), true);
- StringConcatenation _builder = new StringConcatenation();
- _builder.newLine();
- _builder.append("// port class");
- _builder.newLine();
- _builder.append("static public class ");
- _builder.append(portClassName, "");
- _builder.append(" extends PortBase {");
- _builder.newLineIfNotEmpty();
- {
- boolean _notEquals = (!Objects.equal(pclass, null));
- if (_notEquals) {
- _builder.append("\t");
- DetailCode _userCode = pclass.getUserCode();
- CharSequence _userCode_1 = this._procedureHelpers.userCode(_userCode);
- _builder.append(_userCode_1, " ");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.append("// constructors");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public ");
- _builder.append(portClassName, " ");
- _builder.append("(IEventReceiver actor, String name, int localId) {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("this(actor, name, localId, 0);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public ");
- _builder.append(portClassName, " ");
- _builder.append("(IEventReceiver actor, String name, int localId, int idx) {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("super(actor, name, localId, idx);");
- _builder.newLine();
- {
- boolean _notEquals_1 = (!Objects.equal(pclass, null));
- if (_notEquals_1) {
- _builder.append("\t\t");
- EList<Attribute> _attributes = pclass.getAttributes();
- CharSequence _attributeInitialization = this._initialization.attributeInitialization(_attributes, pclass, true);
- _builder.append(_attributeInitialization, " ");
- _builder.newLineIfNotEmpty();
- }
- }
- {
- boolean _generateMSCInstrumentation = GlobalSettings.generateMSCInstrumentation();
- if (_generateMSCInstrumentation) {
- _builder.append("\t\t");
- _builder.append("DebuggingService.getInstance().addPortInstance(this);");
- _builder.newLine();
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("@Override");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public void receive(Message m) {");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("if (!(m instanceof EventMessage))");
- _builder.newLine();
- _builder.append("\t\t\t\t");
- _builder.append("return;");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("EventMessage msg = (EventMessage) m;");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("if (0 < msg.getEvtId() && msg.getEvtId() < MSG_MAX) {");
- _builder.newLine();
- {
- boolean _generateMSCInstrumentation_1 = GlobalSettings.generateMSCInstrumentation();
- if (_generateMSCInstrumentation_1) {
- _builder.append("\t\t\t\t");
- _builder.append("if (messageStrings[msg.getEvtId()] != \"timerTick\"){");
- _builder.newLine();
- _builder.append("\t\t\t\t");
- _builder.append("\t");
- _builder.append("DebuggingService.getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), messageStrings[msg.getEvtId()]);");
- _builder.newLine();
- _builder.append("\t\t\t\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- {
- boolean _handlesReceive = this._roomExtensions.handlesReceive(pc, (conj).booleanValue());
- if (_handlesReceive) {
- _builder.append("\t\t\t\t");
- _builder.append("switch (msg.getEvtId()) {");
- _builder.newLine();
- {
- List<MessageHandler> _receiveHandlers = this._roomExtensions.getReceiveHandlers(pc, (conj).booleanValue());
- for(final MessageHandler hdlr : _receiveHandlers) {
- _builder.append("\t\t\t\t");
- _builder.append("\t");
- _builder.append("case ");
- Message _msg = hdlr.getMsg();
- String _codeName = this._roomExtensions.getCodeName(_msg);
- _builder.append(_codeName, " ");
- _builder.append(":");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t\t");
- _builder.append("\t");
- _builder.append("{");
- _builder.newLine();
- {
- DetailCode _detailCode = hdlr.getDetailCode();
- EList<String> _commands = _detailCode.getCommands();
- for(final String command : _commands) {
- _builder.append("\t\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- _builder.append(command, " ");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t\t\t\t");
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t\t\t");
- _builder.append("\t");
- _builder.append("break;");
- _builder.newLine();
- }
- }
- _builder.append("\t\t\t\t");
- _builder.append("\t");
- _builder.append("default:");
- _builder.newLine();
- }
- }
- _builder.append("\t\t\t\t\t");
- _builder.append("if (msg instanceof EventWithDataMessage)");
- _builder.newLine();
- _builder.append("\t\t\t\t\t\t");
- _builder.append("getActor().receiveEvent(this, msg.getEvtId(), ((EventWithDataMessage)msg).getData());");
- _builder.newLine();
- _builder.append("\t\t\t\t\t");
- _builder.append("else");
- _builder.newLine();
- _builder.append("\t\t\t\t\t\t");
- _builder.append("getActor().receiveEvent(this, msg.getEvtId(), null);");
- _builder.newLine();
- {
- boolean _handlesReceive_1 = this._roomExtensions.handlesReceive(pc, (conj).booleanValue());
- if (_handlesReceive_1) {
- _builder.append("\t\t\t\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- _builder.append("\t\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- {
- boolean _notEquals_2 = (!Objects.equal(pclass, null));
- if (_notEquals_2) {
- _builder.append("\t");
- EList<Attribute> _attributes_1 = pclass.getAttributes();
- CharSequence _attributes_2 = this._procedureHelpers.attributes(_attributes_1);
- _builder.append(_attributes_2, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- EList<Attribute> _attributes_3 = pclass.getAttributes();
- CharSequence _attributeSettersGettersImplementation = this._procedureHelpers.attributeSettersGettersImplementation(_attributes_3, null);
- _builder.append(_attributeSettersGettersImplementation, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- EList<PortOperation> _operations = pclass.getOperations();
- CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(_operations, portClassName);
- _builder.append(_operationsImplementation, " ");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("// sent messages");
- _builder.newLine();
- {
- List<Message> _allMessages = RoomHelpers.getAllMessages(pc, (conj).booleanValue());
- for(final Message m : _allMessages) {
- _builder.append("\t");
- CharSequence _sendMessage = this.sendMessage(m, (conj).booleanValue());
- _builder.append(_sendMessage, " ");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("// replicated port class");
- _builder.newLine();
- _builder.append("static public class ");
- _builder.append(replPortClassName, "");
- _builder.append(" extends ReplicatedPortBase {");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public ");
- _builder.append(replPortClassName, " ");
- _builder.append("(IEventReceiver actor, String name, int localId) {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("super(actor, name, localId);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public int getReplication() {");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("return getNInterfaceItems();");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public int getIndexOf(InterfaceItemBase ifitem){");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("return ifitem.getIdx();");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public ");
- _builder.append(portClassName, " ");
- _builder.append(" get(int idx) {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("return (");
- _builder.append(portClassName, " ");
- _builder.append(") getInterfaceItem(idx);");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("protected InterfaceItemBase createInterfaceItem(IEventReceiver rcv, String name, int lid, int idx) {");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("return new ");
- _builder.append(portClassName, " ");
- _builder.append("(rcv, name, lid, idx);");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- {
- if ((conj).booleanValue()) {
- _builder.append("\t");
- _builder.append("// incoming messages");
- _builder.newLine();
- {
- List<Message> _allIncomingMessages = RoomHelpers.getAllIncomingMessages(pc);
- for(final Message m_1 : _allIncomingMessages) {
- _builder.append("\t");
- CharSequence _messageSignature = this.messageSignature(m_1);
- _builder.append(_messageSignature, " ");
- _builder.append("{");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("for (int i=0; i<getReplication(); ++i) {");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("\t\t");
- _builder.append("get(i).");
- CharSequence _messageCall = this.messageCall(m_1);
- _builder.append(_messageCall, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- } else {
- _builder.append("\t");
- _builder.append("// outgoing messages");
- _builder.newLine();
- {
- List<Message> _allOutgoingMessages = RoomHelpers.getAllOutgoingMessages(pc);
- for(final Message m_2 : _allOutgoingMessages) {
- _builder.append("\t");
- CharSequence _messageSignature_1 = this.messageSignature(m_2);
- _builder.append(_messageSignature_1, " ");
- _builder.append("{");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("for (int i=0; i<getReplication(); ++i) {");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("\t\t");
- _builder.append("get(i).");
- CharSequence _messageCall_1 = this.messageCall(m_2);
- _builder.append(_messageCall_1, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
- }
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _xblockexpression = (_builder);
- }
- return _xblockexpression;
- }
-
- public CharSequence messageSignature(final Message m) {
- StringConcatenation _builder = new StringConcatenation();
- {
- boolean _isPriv = m.isPriv();
- if (_isPriv) {
- _builder.append("private");
- } else {
- _builder.append("public");
- }
- }
- _builder.append(" void ");
- String _name = m.getName();
- _builder.append(_name, "");
- _builder.append("(");
- {
- VarDecl _data = m.getData();
- boolean _notEquals = (!Objects.equal(_data, null));
- if (_notEquals) {
- VarDecl _data_1 = m.getData();
- RefableType _refType = _data_1.getRefType();
- DataType _type = _refType.getType();
- String _typeName = this._typeHelpers.typeName(_type);
- _builder.append(_typeName, "");
- _builder.append(" ");
- VarDecl _data_2 = m.getData();
- String _name_1 = _data_2.getName();
- _builder.append(_name_1, "");
- }
- }
- _builder.append(")");
- return _builder;
- }
-
- public CharSequence messageSignatureExplicit(final Message m) {
- CharSequence _xblockexpression = null;
- {
- VarDecl _data = m.getData();
- RefableType _refType = _data.getRefType();
- DataType _type = _refType.getType();
- DataClass dc = ((DataClass) _type);
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("public void ");
- String _name = m.getName();
- _builder.append(_name, "");
- _builder.append("(");
- String _argList = this._dataClassGen.argList(dc);
- _builder.append(_argList, "");
- _builder.append(")");
- _xblockexpression = (_builder);
- }
- return _xblockexpression;
- }
-
- public CharSequence messageCall(final Message m) {
- StringConcatenation _builder = new StringConcatenation();
- String _name = m.getName();
- _builder.append(_name, "");
- _builder.append("(");
- {
- VarDecl _data = m.getData();
- boolean _notEquals = (!Objects.equal(_data, null));
- if (_notEquals) {
- _builder.append(" ");
- VarDecl _data_1 = m.getData();
- String _name_1 = _data_1.getName();
- _builder.append(_name_1, "");
- }
- }
- _builder.append(")");
- return _builder;
- }
-
- public CharSequence sendMessage(final Message m, final boolean conj) {
- CharSequence _xblockexpression = null;
- {
- String _xifexpression = null;
- if (conj) {
- _xifexpression = "IN";
- } else {
- _xifexpression = "OUT";
- }
- String dir = _xifexpression;
- MessageHandler hdlr = this._roomExtensions.getSendHandler(m, conj);
- StringConcatenation _builder = new StringConcatenation();
- CharSequence _messageSignature = this.messageSignature(m);
- _builder.append(_messageSignature, "");
- _builder.append(" {");
- _builder.newLineIfNotEmpty();
- {
- boolean _notEquals = (!Objects.equal(hdlr, null));
- if (_notEquals) {
- _builder.append("\t");
- {
- DetailCode _detailCode = hdlr.getDetailCode();
- EList<String> _commands = _detailCode.getCommands();
- for(final String command : _commands) {
- _builder.append("\t");
- _builder.append(command, " ");
- _builder.newLineIfNotEmpty();
- }
- }
- } else {
- {
- boolean _generateMSCInstrumentation = GlobalSettings.generateMSCInstrumentation();
- if (_generateMSCInstrumentation) {
- _builder.append("\t");
- _builder.append("if (messageStrings[ ");
- _builder.append(dir, " ");
- _builder.append("_");
- String _name = m.getName();
- _builder.append(_name, " ");
- _builder.append("] != \"timerTick\") {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[");
- _builder.append(dir, " ");
- _builder.append("_");
- String _name_1 = m.getName();
- _builder.append(_name_1, " ");
- _builder.append("]);");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- _builder.append("\t");
- _builder.append("if (getPeerAddress()!=null)");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("\t");
- {
- VarDecl _data = m.getData();
- boolean _equals = Objects.equal(_data, null);
- if (_equals) {
- _builder.append("getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), ");
- _builder.append(dir, " ");
- _builder.append("_");
- String _name_2 = m.getName();
- _builder.append(_name_2, " ");
- _builder.append("));");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("\t");
- } else {
- _builder.append("getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), ");
- _builder.append(dir, " ");
- _builder.append("_");
- String _name_3 = m.getName();
- _builder.append(_name_3, " ");
- _builder.append(", ");
- VarDecl _data_1 = m.getData();
- String _name_4 = _data_1.getName();
- _builder.append(_name_4, " ");
- {
- boolean _and = false;
- VarDecl _data_2 = m.getData();
- RefableType _refType = _data_2.getRefType();
- boolean _isRef = _refType.isRef();
- boolean _not = (!_isRef);
- if (!_not) {
- _and = false;
- } else {
- VarDecl _data_3 = m.getData();
- RefableType _refType_1 = _data_3.getRefType();
- DataType _type = _refType_1.getType();
- boolean _not_1 = (!(_type instanceof PrimitiveType));
- _and = (_not && _not_1);
- }
- if (_and) {
- _builder.append(".deepCopy()");
- }
- }
- _builder.append("));");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
- _builder.append("}");
- _builder.newLine();
- {
- boolean _and_1 = false;
- VarDecl _data_4 = m.getData();
- boolean _notEquals_1 = (!Objects.equal(_data_4, null));
- if (!_notEquals_1) {
- _and_1 = false;
- } else {
- VarDecl _data_5 = m.getData();
- RefableType _refType_2 = _data_5.getRefType();
- DataType _type_1 = _refType_2.getType();
- _and_1 = (_notEquals_1 && (_type_1 instanceof DataClass));
- }
- if (_and_1) {
- CharSequence _messageSignatureExplicit = this.messageSignatureExplicit(m);
- _builder.append(_messageSignatureExplicit, "");
- _builder.append(" {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- String _name_5 = m.getName();
- _builder.append(_name_5, " ");
- _builder.append("(new ");
- VarDecl _data_6 = m.getData();
- RefableType _refType_3 = _data_6.getRefType();
- DataType _type_2 = _refType_3.getType();
- String _name_6 = _type_2.getName();
- _builder.append(_name_6, " ");
- _builder.append("(");
- VarDecl _data_7 = m.getData();
- RefableType _refType_4 = _data_7.getRefType();
- DataType _type_3 = _refType_4.getType();
- String _paramList = this._dataClassGen.paramList(((DataClass) _type_3));
- _builder.append(_paramList, " ");
- _builder.append("));");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- }
- }
- _xblockexpression = (_builder);
- }
- return _xblockexpression;
- }
-
- public CharSequence generateDataDriven(final Root root, final ProtocolClass pc) {
- CharSequence _xblockexpression = null;
- {
- List<Message> _allIncomingMessages = RoomHelpers.getAllIncomingMessages(pc);
- final Function1<Message,Boolean> _function = new Function1<Message,Boolean>() {
- public Boolean apply(final Message m) {
- VarDecl _data = m.getData();
- boolean _notEquals = (!Objects.equal(_data, null));
- return Boolean.valueOf(_notEquals);
- }
- };
- final Iterable<Message> sentMsgs = IterableExtensions.<Message>filter(_allIncomingMessages, _function);
- final EList<RoomModel> models = root.getReferencedModels(pc);
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("package ");
- String _package = this._roomExtensions.getPackage(pc);
- _builder.append(_package, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.messaging.IRTObject;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.DataReceivePort;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.DataSendPort;");
- _builder.newLine();
- _builder.append("import static org.eclipse.etrice.runtime.java.etunit.EtUnit.*;");
- _builder.newLine();
- _builder.newLine();
- CharSequence _userCode = this._procedureHelpers.userCode(pc, 1);
- _builder.append(_userCode, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- {
- for(final RoomModel model : models) {
- _builder.append("import ");
- String _name = model.getName();
- _builder.append(_name, "");
- _builder.append(".*;");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- _builder.append("public class ");
- String _name_1 = pc.getName();
- _builder.append(_name_1, "");
- _builder.append(" {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- CharSequence _userCode_1 = this._procedureHelpers.userCode(pc, 2);
- _builder.append(_userCode_1, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("// send port holds data");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("static public class ");
- String _portClassName = this._roomExtensions.getPortClassName(pc, true);
- _builder.append(_portClassName, " ");
- _builder.append(" extends DataSendPort {");
- _builder.newLineIfNotEmpty();
- {
- for(final Message msg : sentMsgs) {
- _builder.append("\t\t");
- _builder.append("private ");
- VarDecl _data = msg.getData();
- RefableType _refType = _data.getRefType();
- DataType _type = _refType.getType();
- String _typeName = this._typeHelpers.typeName(_type);
- _builder.append(_typeName, " ");
- _builder.append(" ");
- String _name_2 = msg.getName();
- _builder.append(_name_2, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// constructor");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("public ");
- String _portClassName_1 = this._roomExtensions.getPortClassName(pc, true);
- _builder.append(_portClassName_1, " ");
- _builder.append("(IRTObject parent, String name, int localId) {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("super(parent, name, localId);");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// getters and setters");
- _builder.newLine();
- {
- for(final Message msg_1 : sentMsgs) {
- _builder.append("\t\t");
- _builder.append("public void ");
- String _name_3 = msg_1.getName();
- _builder.append(_name_3, " ");
- _builder.append("(");
- VarDecl _data_1 = msg_1.getData();
- RefableType _refType_1 = _data_1.getRefType();
- DataType _type_1 = _refType_1.getType();
- String _typeName_1 = this._typeHelpers.typeName(_type_1);
- _builder.append(_typeName_1, " ");
- _builder.append(" ");
- String _name_4 = msg_1.getName();
- _builder.append(_name_4, " ");
- _builder.append(") {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("this.");
- String _name_5 = msg_1.getName();
- _builder.append(_name_5, " ");
- _builder.append(" = ");
- String _name_6 = msg_1.getName();
- _builder.append(_name_6, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("public ");
- VarDecl _data_2 = msg_1.getData();
- RefableType _refType_2 = _data_2.getRefType();
- DataType _type_2 = _refType_2.getType();
- String _typeName_2 = this._typeHelpers.typeName(_type_2);
- _builder.append(_typeName_2, " ");
- _builder.append(" ");
- String _name_7 = msg_1.getName();
- _builder.append(_name_7, " ");
- _builder.append("() {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("return ");
- String _name_8 = msg_1.getName();
- _builder.append(_name_8, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("// receive port accesses send port");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("static public class ");
- String _portClassName_2 = this._roomExtensions.getPortClassName(pc, false);
- _builder.append(_portClassName_2, " ");
- _builder.append(" extends DataReceivePort {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("private ");
- String _portClassName_3 = this._roomExtensions.getPortClassName(pc, true);
- _builder.append(_portClassName_3, " ");
- _builder.append(" peer;");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// constructor");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("public ");
- String _portClassName_4 = this._roomExtensions.getPortClassName(pc, false);
- _builder.append(_portClassName_4, " ");
- _builder.append("(IRTObject parent, String name, int localId) {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("super(parent, name, localId);");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// getters");
- _builder.newLine();
- {
- for(final Message msg_2 : sentMsgs) {
- _builder.append("\t\t");
- _builder.append("public ");
- VarDecl _data_3 = msg_2.getData();
- RefableType _refType_3 = _data_3.getRefType();
- DataType _type_3 = _refType_3.getType();
- String _typeName_3 = this._typeHelpers.typeName(_type_3);
- _builder.append(_typeName_3, " ");
- _builder.append(" ");
- String _name_9 = msg_2.getName();
- _builder.append(_name_9, " ");
- _builder.append("() {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("if (peer==null)");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t\t");
- _builder.append("return ");
- VarDecl _data_4 = msg_2.getData();
- RefableType _refType_4 = _data_4.getRefType();
- DataType _type_4 = _refType_4.getType();
- String _defaultValue = this._javaExtensions.defaultValue(_type_4);
- _builder.append(_defaultValue, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("return peer.");
- String _name_10 = msg_2.getName();
- _builder.append(_name_10, " ");
- _builder.append("();");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("protected void connect(DataSendPort dataSendPort) {");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("if (dataSendPort instanceof ");
- String _portClassName_5 = this._roomExtensions.getPortClassName(pc, true);
- _builder.append(_portClassName_5, " ");
- _builder.append(")");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t\t");
- _builder.append("peer = (");
- String _portClassName_6 = this._roomExtensions.getPortClassName(pc, true);
- _builder.append(_portClassName_6, " ");
- _builder.append(")dataSendPort;");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _xblockexpression = (_builder);
- }
- return _xblockexpression;
- }
-}
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ */
+package org.eclipse.etrice.generator.java.gen;
+
+import com.google.common.base.Objects;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.genmodel.base.ILogger;
+import org.eclipse.etrice.core.genmodel.etricegen.Root;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.CommunicationType;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.DetailCode;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.core.room.MessageHandler;
+import org.eclipse.etrice.core.room.PortClass;
+import org.eclipse.etrice.core.room.PortOperation;
+import org.eclipse.etrice.core.room.PrimitiveType;
+import org.eclipse.etrice.core.room.ProtocolClass;
+import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.core.room.RoomModel;
+import org.eclipse.etrice.core.room.VarDecl;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.generator.base.IGeneratorFileIo;
+import org.eclipse.etrice.generator.generic.GenericProtocolClassGenerator;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.generic.TypeHelpers;
+import org.eclipse.etrice.generator.java.gen.DataClassGen;
+import org.eclipse.etrice.generator.java.gen.GlobalSettings;
+import org.eclipse.etrice.generator.java.gen.Initialization;
+import org.eclipse.etrice.generator.java.gen.JavaExtensions;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+
+@Singleton
+@SuppressWarnings("all")
+public class ProtocolClassGen extends GenericProtocolClassGenerator {
+ @Inject
+ private IGeneratorFileIo fileIO;
+
+ @Inject
+ @Extension
+ private JavaExtensions _javaExtensions;
+
+ @Inject
+ @Extension
+ private RoomExtensions _roomExtensions;
+
+ @Inject
+ @Extension
+ private ProcedureHelpers _procedureHelpers;
+
+ @Inject
+ @Extension
+ private Initialization _initialization;
+
+ @Inject
+ @Extension
+ private TypeHelpers _typeHelpers;
+
+ @Inject
+ @Extension
+ private DataClassGen _dataClassGen;
+
+ @Inject
+ private ILogger logger;
+
+ public void doGenerate(final Root root) {
+ EList<ProtocolClass> _usedProtocolClasses = root.getUsedProtocolClasses();
+ for (final ProtocolClass pc : _usedProtocolClasses) {
+ {
+ String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(pc);
+ String _path = this._roomExtensions.getPath(pc);
+ final String path = (_generationTargetPath + _path);
+ String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(pc);
+ String _path_1 = this._roomExtensions.getPath(pc);
+ final String infopath = (_generationInfoPath + _path_1);
+ final String file = this._javaExtensions.getJavaFileName(pc);
+ CharSequence _switchResult = null;
+ CommunicationType _commType = pc.getCommType();
+ final CommunicationType _switchValue = _commType;
+ boolean _matched = false;
+ if (!_matched) {
+ if (Objects.equal(_switchValue,CommunicationType.EVENT_DRIVEN)) {
+ _matched=true;
+ CharSequence _generate = this.generate(root, pc);
+ _switchResult = _generate;
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,CommunicationType.DATA_DRIVEN)) {
+ _matched=true;
+ CharSequence _generateDataDriven = this.generateDataDriven(root, pc);
+ _switchResult = _generateDataDriven;
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,CommunicationType.SYNCHRONOUS)) {
+ _matched=true;
+ _switchResult = "";
+ }
+ }
+ final CharSequence contents = _switchResult;
+ String _string = contents.toString();
+ boolean _isEmpty = _string.isEmpty();
+ if (_isEmpty) {
+ this.logger.logError("synchronous protocols not supported yet", pc);
+ } else {
+ this.fileIO.generateFile("generating ProtocolClass implementation", path, infopath, file, contents);
+ }
+ }
+ }
+ }
+
+ public CharSequence generate(final Root root, final ProtocolClass pc) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package ");
+ String _package = this._roomExtensions.getPackage(pc);
+ _builder.append(_package, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.messaging.Message;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.EventMessage;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.EventWithDataMessage;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.IEventReceiver;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.PortBase;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.ReplicatedPortBase;");
+ _builder.newLine();
+ {
+ boolean _generateMSCInstrumentation = GlobalSettings.generateMSCInstrumentation();
+ if (_generateMSCInstrumentation) {
+ _builder.append("import org.eclipse.etrice.runtime.java.debugging.DebuggingService;");
+ _builder.newLine();
+ }
+ }
+ _builder.append("import static org.eclipse.etrice.runtime.java.etunit.EtUnit.*;");
+ _builder.newLine();
+ _builder.newLine();
+ CharSequence _userCode = this._procedureHelpers.userCode(pc, 1);
+ _builder.append(_userCode, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ EList<RoomModel> models = root.getReferencedModels(pc);
+ _builder.newLineIfNotEmpty();
+ {
+ for(final RoomModel model : models) {
+ _builder.append("import ");
+ String _name = model.getName();
+ _builder.append(_name, "");
+ _builder.append(".*;");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("public class ");
+ String _name_1 = pc.getName();
+ _builder.append(_name_1, "");
+ _builder.append(" {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("// message IDs");
+ _builder.newLine();
+ _builder.append("\t");
+ String _genMessageIDs = this.genMessageIDs(pc);
+ _builder.append(_genMessageIDs, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _userCode_1 = this._procedureHelpers.userCode(pc, 2);
+ _builder.append(_userCode_1, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("private static String messageStrings[] = {\"MIN\", ");
+ {
+ List<Message> _allOutgoingMessages = RoomHelpers.getAllOutgoingMessages(pc);
+ for(final Message m : _allOutgoingMessages) {
+ _builder.append("\"");
+ String _name_2 = m.getName();
+ _builder.append(_name_2, " ");
+ _builder.append("\",");
+ }
+ }
+ _builder.append(" ");
+ {
+ List<Message> _allIncomingMessages = RoomHelpers.getAllIncomingMessages(pc);
+ for(final Message m_1 : _allIncomingMessages) {
+ _builder.append("\"");
+ String _name_3 = m_1.getName();
+ _builder.append(_name_3, " ");
+ _builder.append("\",");
+ }
+ }
+ _builder.append("\"MAX\"};");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public String getMessageString(int msg_id) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("if (msg_id<MSG_MIN || msg_id>MSG_MAX+1){");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("// id out of range");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("return \"Message ID out of range\";");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("else{");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("return messageStrings[msg_id];");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _portClass = this.portClass(pc, Boolean.valueOf(false));
+ _builder.append(_portClass, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ CharSequence _portClass_1 = this.portClass(pc, Boolean.valueOf(true));
+ _builder.append(_portClass_1, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ return _builder;
+ }
+
+ public CharSequence portClass(final ProtocolClass pc, final Boolean conj) {
+ CharSequence _xblockexpression = null;
+ {
+ PortClass pclass = this._roomExtensions.getPortClass(pc, (conj).booleanValue());
+ String portClassName = this._roomExtensions.getPortClassName(pc, (conj).booleanValue());
+ String replPortClassName = this._roomExtensions.getPortClassName(pc, (conj).booleanValue(), true);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.newLine();
+ _builder.append("// port class");
+ _builder.newLine();
+ _builder.append("static public class ");
+ _builder.append(portClassName, "");
+ _builder.append(" extends PortBase {");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _notEquals = (!Objects.equal(pclass, null));
+ if (_notEquals) {
+ _builder.append("\t");
+ DetailCode _userCode = pclass.getUserCode();
+ CharSequence _userCode_1 = this._procedureHelpers.userCode(_userCode);
+ _builder.append(_userCode_1, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("// constructors");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public ");
+ _builder.append(portClassName, " ");
+ _builder.append("(IEventReceiver actor, String name, int localId) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("this(actor, name, localId, 0);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public ");
+ _builder.append(portClassName, " ");
+ _builder.append("(IEventReceiver actor, String name, int localId, int idx) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("super(actor, name, localId, idx);");
+ _builder.newLine();
+ {
+ boolean _notEquals_1 = (!Objects.equal(pclass, null));
+ if (_notEquals_1) {
+ _builder.append("\t\t");
+ EList<Attribute> _attributes = pclass.getAttributes();
+ CharSequence _attributeInitialization = this._initialization.attributeInitialization(_attributes, pclass, true);
+ _builder.append(_attributeInitialization, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ {
+ boolean _generateMSCInstrumentation = GlobalSettings.generateMSCInstrumentation();
+ if (_generateMSCInstrumentation) {
+ _builder.append("\t\t");
+ _builder.append("DebuggingService.getInstance().addPortInstance(this);");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("@Override");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public void receive(Message m) {");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("if (!(m instanceof EventMessage))");
+ _builder.newLine();
+ _builder.append("\t\t\t\t");
+ _builder.append("return;");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("EventMessage msg = (EventMessage) m;");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("if (0 < msg.getEvtId() && msg.getEvtId() < MSG_MAX) {");
+ _builder.newLine();
+ {
+ boolean _generateMSCInstrumentation_1 = GlobalSettings.generateMSCInstrumentation();
+ if (_generateMSCInstrumentation_1) {
+ _builder.append("\t\t\t\t");
+ _builder.append("if (messageStrings[msg.getEvtId()] != \"timerTick\"){");
+ _builder.newLine();
+ _builder.append("\t\t\t\t");
+ _builder.append("\t");
+ _builder.append("DebuggingService.getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), messageStrings[msg.getEvtId()]);");
+ _builder.newLine();
+ _builder.append("\t\t\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ {
+ boolean _handlesReceive = this._roomExtensions.handlesReceive(pc, (conj).booleanValue());
+ if (_handlesReceive) {
+ _builder.append("\t\t\t\t");
+ _builder.append("switch (msg.getEvtId()) {");
+ _builder.newLine();
+ {
+ List<MessageHandler> _receiveHandlers = this._roomExtensions.getReceiveHandlers(pc, (conj).booleanValue());
+ for(final MessageHandler hdlr : _receiveHandlers) {
+ _builder.append("\t\t\t\t");
+ _builder.append("\t");
+ _builder.append("case ");
+ Message _msg = hdlr.getMsg();
+ String _codeName = this._roomExtensions.getCodeName(_msg);
+ _builder.append(_codeName, " ");
+ _builder.append(":");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t\t");
+ _builder.append("\t");
+ _builder.append("{");
+ _builder.newLine();
+ {
+ DetailCode _detailCode = hdlr.getDetailCode();
+ EList<String> _commands = _detailCode.getCommands();
+ for(final String command : _commands) {
+ _builder.append("\t\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append(command, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t\t\t\t");
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t\t\t");
+ _builder.append("\t");
+ _builder.append("break;");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t\t\t\t");
+ _builder.append("\t");
+ _builder.append("default:");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t\t\t\t\t");
+ _builder.append("if (msg instanceof EventWithDataMessage)");
+ _builder.newLine();
+ _builder.append("\t\t\t\t\t\t");
+ _builder.append("getActor().receiveEvent(this, msg.getEvtId(), ((EventWithDataMessage)msg).getData());");
+ _builder.newLine();
+ _builder.append("\t\t\t\t\t");
+ _builder.append("else");
+ _builder.newLine();
+ _builder.append("\t\t\t\t\t\t");
+ _builder.append("getActor().receiveEvent(this, msg.getEvtId(), null);");
+ _builder.newLine();
+ {
+ boolean _handlesReceive_1 = this._roomExtensions.handlesReceive(pc, (conj).booleanValue());
+ if (_handlesReceive_1) {
+ _builder.append("\t\t\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ boolean _notEquals_2 = (!Objects.equal(pclass, null));
+ if (_notEquals_2) {
+ _builder.append("\t");
+ EList<Attribute> _attributes_1 = pclass.getAttributes();
+ CharSequence _attributes_2 = this._procedureHelpers.attributes(_attributes_1);
+ _builder.append(_attributes_2, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ EList<Attribute> _attributes_3 = pclass.getAttributes();
+ CharSequence _attributeSettersGettersImplementation = this._procedureHelpers.attributeSettersGettersImplementation(_attributes_3, null);
+ _builder.append(_attributeSettersGettersImplementation, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ EList<PortOperation> _operations = pclass.getOperations();
+ CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(_operations, portClassName);
+ _builder.append(_operationsImplementation, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// sent messages");
+ _builder.newLine();
+ {
+ List<Message> _allMessages = RoomHelpers.getAllMessages(pc, (conj).booleanValue());
+ for(final Message m : _allMessages) {
+ _builder.append("\t");
+ CharSequence _sendMessage = this.sendMessage(m, (conj).booleanValue());
+ _builder.append(_sendMessage, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("// replicated port class");
+ _builder.newLine();
+ _builder.append("static public class ");
+ _builder.append(replPortClassName, "");
+ _builder.append(" extends ReplicatedPortBase {");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public ");
+ _builder.append(replPortClassName, " ");
+ _builder.append("(IEventReceiver actor, String name, int localId) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("super(actor, name, localId);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public int getReplication() {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("return getNInterfaceItems();");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public int getIndexOf(InterfaceItemBase ifitem){");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("return ifitem.getIdx();");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public ");
+ _builder.append(portClassName, " ");
+ _builder.append(" get(int idx) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("return (");
+ _builder.append(portClassName, " ");
+ _builder.append(") getInterfaceItem(idx);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("protected InterfaceItemBase createInterfaceItem(IEventReceiver rcv, String name, int lid, int idx) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("return new ");
+ _builder.append(portClassName, " ");
+ _builder.append("(rcv, name, lid, idx);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ {
+ if ((conj).booleanValue()) {
+ _builder.append("\t");
+ _builder.append("// incoming messages");
+ _builder.newLine();
+ {
+ List<Message> _allIncomingMessages = RoomHelpers.getAllIncomingMessages(pc);
+ for(final Message m_1 : _allIncomingMessages) {
+ _builder.append("\t");
+ CharSequence _messageSignature = this.messageSignature(m_1);
+ _builder.append(_messageSignature, " ");
+ _builder.append("{");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("for (int i=0; i<getReplication(); ++i) {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t\t");
+ _builder.append("get(i).");
+ CharSequence _messageCall = this.messageCall(m_1);
+ _builder.append(_messageCall, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ } else {
+ _builder.append("\t");
+ _builder.append("// outgoing messages");
+ _builder.newLine();
+ {
+ List<Message> _allOutgoingMessages = RoomHelpers.getAllOutgoingMessages(pc);
+ for(final Message m_2 : _allOutgoingMessages) {
+ _builder.append("\t");
+ CharSequence _messageSignature_1 = this.messageSignature(m_2);
+ _builder.append(_messageSignature_1, " ");
+ _builder.append("{");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("for (int i=0; i<getReplication(); ++i) {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t\t");
+ _builder.append("get(i).");
+ CharSequence _messageCall_1 = this.messageCall(m_2);
+ _builder.append(_messageCall_1, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+
+ public CharSequence messageSignature(final Message m) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ boolean _isPriv = m.isPriv();
+ if (_isPriv) {
+ _builder.append("private");
+ } else {
+ _builder.append("public");
+ }
+ }
+ _builder.append(" void ");
+ String _name = m.getName();
+ _builder.append(_name, "");
+ _builder.append("(");
+ {
+ VarDecl _data = m.getData();
+ boolean _notEquals = (!Objects.equal(_data, null));
+ if (_notEquals) {
+ VarDecl _data_1 = m.getData();
+ RefableType _refType = _data_1.getRefType();
+ DataType _type = _refType.getType();
+ String _typeName = this._typeHelpers.typeName(_type);
+ _builder.append(_typeName, "");
+ _builder.append(" ");
+ VarDecl _data_2 = m.getData();
+ String _name_1 = _data_2.getName();
+ _builder.append(_name_1, "");
+ }
+ }
+ _builder.append(")");
+ return _builder;
+ }
+
+ public CharSequence messageSignatureExplicit(final Message m) {
+ CharSequence _xblockexpression = null;
+ {
+ VarDecl _data = m.getData();
+ RefableType _refType = _data.getRefType();
+ DataType _type = _refType.getType();
+ DataClass dc = ((DataClass) _type);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("public void ");
+ String _name = m.getName();
+ _builder.append(_name, "");
+ _builder.append("(");
+ String _argList = this._dataClassGen.argList(dc);
+ _builder.append(_argList, "");
+ _builder.append(")");
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+
+ public CharSequence messageCall(final Message m) {
+ StringConcatenation _builder = new StringConcatenation();
+ String _name = m.getName();
+ _builder.append(_name, "");
+ _builder.append("(");
+ {
+ VarDecl _data = m.getData();
+ boolean _notEquals = (!Objects.equal(_data, null));
+ if (_notEquals) {
+ _builder.append(" ");
+ VarDecl _data_1 = m.getData();
+ String _name_1 = _data_1.getName();
+ _builder.append(_name_1, "");
+ }
+ }
+ _builder.append(")");
+ return _builder;
+ }
+
+ public CharSequence sendMessage(final Message m, final boolean conj) {
+ CharSequence _xblockexpression = null;
+ {
+ String _xifexpression = null;
+ if (conj) {
+ _xifexpression = "IN";
+ } else {
+ _xifexpression = "OUT";
+ }
+ String dir = _xifexpression;
+ MessageHandler hdlr = this._roomExtensions.getSendHandler(m, conj);
+ StringConcatenation _builder = new StringConcatenation();
+ CharSequence _messageSignature = this.messageSignature(m);
+ _builder.append(_messageSignature, "");
+ _builder.append(" {");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _notEquals = (!Objects.equal(hdlr, null));
+ if (_notEquals) {
+ _builder.append("\t");
+ {
+ DetailCode _detailCode = hdlr.getDetailCode();
+ EList<String> _commands = _detailCode.getCommands();
+ for(final String command : _commands) {
+ _builder.append("\t");
+ _builder.append(command, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ } else {
+ {
+ boolean _generateMSCInstrumentation = GlobalSettings.generateMSCInstrumentation();
+ if (_generateMSCInstrumentation) {
+ _builder.append("\t");
+ _builder.append("if (messageStrings[ ");
+ _builder.append(dir, " ");
+ _builder.append("_");
+ String _name = m.getName();
+ _builder.append(_name, " ");
+ _builder.append("] != \"timerTick\") {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[");
+ _builder.append(dir, " ");
+ _builder.append("_");
+ String _name_1 = m.getName();
+ _builder.append(_name_1, " ");
+ _builder.append("]);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("if (getPeerAddress()!=null)");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t");
+ {
+ VarDecl _data = m.getData();
+ boolean _equals = Objects.equal(_data, null);
+ if (_equals) {
+ _builder.append("getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), ");
+ _builder.append(dir, " ");
+ _builder.append("_");
+ String _name_2 = m.getName();
+ _builder.append(_name_2, " ");
+ _builder.append("));");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ } else {
+ _builder.append("getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), ");
+ _builder.append(dir, " ");
+ _builder.append("_");
+ String _name_3 = m.getName();
+ _builder.append(_name_3, " ");
+ _builder.append(", ");
+ VarDecl _data_1 = m.getData();
+ String _name_4 = _data_1.getName();
+ _builder.append(_name_4, " ");
+ {
+ boolean _and = false;
+ VarDecl _data_2 = m.getData();
+ RefableType _refType = _data_2.getRefType();
+ boolean _isRef = _refType.isRef();
+ boolean _not = (!_isRef);
+ if (!_not) {
+ _and = false;
+ } else {
+ VarDecl _data_3 = m.getData();
+ RefableType _refType_1 = _data_3.getRefType();
+ DataType _type = _refType_1.getType();
+ boolean _not_1 = (!(_type instanceof PrimitiveType));
+ _and = (_not && _not_1);
+ }
+ if (_and) {
+ _builder.append(".deepCopy()");
+ }
+ }
+ _builder.append("));");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ {
+ boolean _and_1 = false;
+ VarDecl _data_4 = m.getData();
+ boolean _notEquals_1 = (!Objects.equal(_data_4, null));
+ if (!_notEquals_1) {
+ _and_1 = false;
+ } else {
+ VarDecl _data_5 = m.getData();
+ RefableType _refType_2 = _data_5.getRefType();
+ DataType _type_1 = _refType_2.getType();
+ _and_1 = (_notEquals_1 && (_type_1 instanceof DataClass));
+ }
+ if (_and_1) {
+ CharSequence _messageSignatureExplicit = this.messageSignatureExplicit(m);
+ _builder.append(_messageSignatureExplicit, "");
+ _builder.append(" {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _name_5 = m.getName();
+ _builder.append(_name_5, " ");
+ _builder.append("(new ");
+ VarDecl _data_6 = m.getData();
+ RefableType _refType_3 = _data_6.getRefType();
+ DataType _type_2 = _refType_3.getType();
+ String _name_6 = _type_2.getName();
+ _builder.append(_name_6, " ");
+ _builder.append("(");
+ VarDecl _data_7 = m.getData();
+ RefableType _refType_4 = _data_7.getRefType();
+ DataType _type_3 = _refType_4.getType();
+ String _paramList = this._dataClassGen.paramList(((DataClass) _type_3));
+ _builder.append(_paramList, " ");
+ _builder.append("));");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+
+ public CharSequence generateDataDriven(final Root root, final ProtocolClass pc) {
+ CharSequence _xblockexpression = null;
+ {
+ List<Message> _allIncomingMessages = RoomHelpers.getAllIncomingMessages(pc);
+ final Function1<Message,Boolean> _function = new Function1<Message,Boolean>() {
+ public Boolean apply(final Message m) {
+ VarDecl _data = m.getData();
+ boolean _notEquals = (!Objects.equal(_data, null));
+ return Boolean.valueOf(_notEquals);
+ }
+ };
+ final Iterable<Message> sentMsgs = IterableExtensions.<Message>filter(_allIncomingMessages, _function);
+ final EList<RoomModel> models = root.getReferencedModels(pc);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package ");
+ String _package = this._roomExtensions.getPackage(pc);
+ _builder.append(_package, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.messaging.IRTObject;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.DataReceivePort;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.DataSendPort;");
+ _builder.newLine();
+ _builder.append("import static org.eclipse.etrice.runtime.java.etunit.EtUnit.*;");
+ _builder.newLine();
+ _builder.newLine();
+ CharSequence _userCode = this._procedureHelpers.userCode(pc, 1);
+ _builder.append(_userCode, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ {
+ for(final RoomModel model : models) {
+ _builder.append("import ");
+ String _name = model.getName();
+ _builder.append(_name, "");
+ _builder.append(".*;");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("public class ");
+ String _name_1 = pc.getName();
+ _builder.append(_name_1, "");
+ _builder.append(" {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _userCode_1 = this._procedureHelpers.userCode(pc, 2);
+ _builder.append(_userCode_1, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// send port holds data");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("static public class ");
+ String _portClassName = this._roomExtensions.getPortClassName(pc, true);
+ _builder.append(_portClassName, " ");
+ _builder.append(" extends DataSendPort {");
+ _builder.newLineIfNotEmpty();
+ {
+ for(final Message msg : sentMsgs) {
+ _builder.append("\t\t");
+ _builder.append("private ");
+ VarDecl _data = msg.getData();
+ RefableType _refType = _data.getRefType();
+ DataType _type = _refType.getType();
+ String _typeName = this._typeHelpers.typeName(_type);
+ _builder.append(_typeName, " ");
+ _builder.append(" ");
+ String _name_2 = msg.getName();
+ _builder.append(_name_2, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// constructor");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("public ");
+ String _portClassName_1 = this._roomExtensions.getPortClassName(pc, true);
+ _builder.append(_portClassName_1, " ");
+ _builder.append("(IRTObject parent, String name, int localId) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("super(parent, name, localId);");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// getters and setters");
+ _builder.newLine();
+ {
+ for(final Message msg_1 : sentMsgs) {
+ _builder.append("\t\t");
+ _builder.append("public void ");
+ String _name_3 = msg_1.getName();
+ _builder.append(_name_3, " ");
+ _builder.append("(");
+ VarDecl _data_1 = msg_1.getData();
+ RefableType _refType_1 = _data_1.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ String _typeName_1 = this._typeHelpers.typeName(_type_1);
+ _builder.append(_typeName_1, " ");
+ _builder.append(" ");
+ String _name_4 = msg_1.getName();
+ _builder.append(_name_4, " ");
+ _builder.append(") {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("this.");
+ String _name_5 = msg_1.getName();
+ _builder.append(_name_5, " ");
+ _builder.append(" = ");
+ String _name_6 = msg_1.getName();
+ _builder.append(_name_6, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("public ");
+ VarDecl _data_2 = msg_1.getData();
+ RefableType _refType_2 = _data_2.getRefType();
+ DataType _type_2 = _refType_2.getType();
+ String _typeName_2 = this._typeHelpers.typeName(_type_2);
+ _builder.append(_typeName_2, " ");
+ _builder.append(" ");
+ String _name_7 = msg_1.getName();
+ _builder.append(_name_7, " ");
+ _builder.append("() {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("return ");
+ String _name_8 = msg_1.getName();
+ _builder.append(_name_8, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// receive port accesses send port");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("static public class ");
+ String _portClassName_2 = this._roomExtensions.getPortClassName(pc, false);
+ _builder.append(_portClassName_2, " ");
+ _builder.append(" extends DataReceivePort {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("private ");
+ String _portClassName_3 = this._roomExtensions.getPortClassName(pc, true);
+ _builder.append(_portClassName_3, " ");
+ _builder.append(" peer;");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// constructor");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("public ");
+ String _portClassName_4 = this._roomExtensions.getPortClassName(pc, false);
+ _builder.append(_portClassName_4, " ");
+ _builder.append("(IRTObject parent, String name, int localId) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("super(parent, name, localId);");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// getters");
+ _builder.newLine();
+ {
+ for(final Message msg_2 : sentMsgs) {
+ _builder.append("\t\t");
+ _builder.append("public ");
+ VarDecl _data_3 = msg_2.getData();
+ RefableType _refType_3 = _data_3.getRefType();
+ DataType _type_3 = _refType_3.getType();
+ String _typeName_3 = this._typeHelpers.typeName(_type_3);
+ _builder.append(_typeName_3, " ");
+ _builder.append(" ");
+ String _name_9 = msg_2.getName();
+ _builder.append(_name_9, " ");
+ _builder.append("() {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("if (peer==null)");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t\t");
+ _builder.append("return ");
+ VarDecl _data_4 = msg_2.getData();
+ RefableType _refType_4 = _data_4.getRefType();
+ DataType _type_4 = _refType_4.getType();
+ String _defaultValue = this._javaExtensions.defaultValue(_type_4);
+ _builder.append(_defaultValue, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("return peer.");
+ String _name_10 = msg_2.getName();
+ _builder.append(_name_10, " ");
+ _builder.append("();");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("protected void connect(DataSendPort dataSendPort) {");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("if (dataSendPort instanceof ");
+ String _portClassName_5 = this._roomExtensions.getPortClassName(pc, true);
+ _builder.append(_portClassName_5, " ");
+ _builder.append(")");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t\t");
+ _builder.append("peer = (");
+ String _portClassName_6 = this._roomExtensions.getPortClassName(pc, true);
+ _builder.append(_portClassName_6, " ");
+ _builder.append(")dataSendPort;");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/StateMachineGen.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/StateMachineGen.java
index 49dbdbb61..36e6ae9f0 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/StateMachineGen.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/StateMachineGen.java
@@ -1,110 +1,110 @@
-/**
- * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- */
-package org.eclipse.etrice.generator.java.gen;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import java.util.List;
-import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.State;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.generator.base.CodegenHelpers;
-import org.eclipse.etrice.generator.generic.GenericStateMachineGenerator;
-import org.eclipse.etrice.generator.generic.RoomExtensions;
-import org.eclipse.etrice.generator.java.gen.GlobalSettings;
-import org.eclipse.xtend2.lib.StringConcatenation;
-import org.eclipse.xtext.xbase.lib.Extension;
-
-@Singleton
-@SuppressWarnings("all")
-public class StateMachineGen extends GenericStateMachineGenerator {
- @Inject
- @Extension
- private RoomExtensions _roomExtensions;
-
- public CharSequence genExtra(final ExpandedActorClass xpac) {
- CharSequence _xblockexpression = null;
- {
- final ActorClass ac = xpac.getActorClass();
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("// state names");
- _builder.newLine();
- _builder.append("protected static final String stateStrings[] = {\"<no state>\",\"<top>\",");
- {
- List<State> _allBaseStatesLeavesLast = this._roomExtensions.getAllBaseStatesLeavesLast(ac);
- boolean _hasElements = false;
- for(final State state : _allBaseStatesLeavesLast) {
- if (!_hasElements) {
- _hasElements = true;
- } else {
- _builder.appendImmediate(",", "");
- }
- _builder.append("\"");
- String _genStatePathName = CodegenHelpers.getGenStatePathName(state);
- _builder.append(_genStatePathName, "");
- _builder.append("\"");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("};");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("// history");
- _builder.newLine();
- _builder.append("protected int history[] = {NO_STATE,NO_STATE");
- {
- List<State> _allBaseStates = RoomHelpers.getAllBaseStates(ac);
- for(final State state_1 : _allBaseStates) {
- _builder.append(",NO_STATE");
- }
- }
- _builder.append("};");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("private void setState(int new_state) {");
- _builder.newLine();
- {
- boolean _generateMSCInstrumentation = GlobalSettings.generateMSCInstrumentation();
- if (_generateMSCInstrumentation) {
- _builder.append("\t");
- _builder.append("DebuggingService.getInstance().addActorState(this,stateStrings[new_state]);");
- _builder.newLine();
- }
- }
- _builder.append("\t");
- _builder.append("if (stateStrings[new_state]!=\"Idle\") {");
- _builder.newLine();
- {
- boolean _generateWithVerboseOutput = GlobalSettings.generateWithVerboseOutput();
- if (_generateWithVerboseOutput) {
- _builder.append("\t\t");
- _builder.append("System.out.println(\"state switch of \"+getInstancePath() + \": \"");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t\t");
- _builder.append("+ stateStrings[this.state] + \" -> \" + stateStrings[new_state]);");
- _builder.newLine();
- }
- }
- _builder.append("\t");
- _builder.append("}\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("this.state = new_state;");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _xblockexpression = (_builder);
- }
- return _xblockexpression;
- }
-}
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ */
+package org.eclipse.etrice.generator.java.gen;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.List;
+import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.State;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.generator.base.CodegenHelpers;
+import org.eclipse.etrice.generator.generic.GenericStateMachineGenerator;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.java.gen.GlobalSettings;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.Extension;
+
+@Singleton
+@SuppressWarnings("all")
+public class StateMachineGen extends GenericStateMachineGenerator {
+ @Inject
+ @Extension
+ private RoomExtensions _roomExtensions;
+
+ public CharSequence genExtra(final ExpandedActorClass xpac) {
+ CharSequence _xblockexpression = null;
+ {
+ final ActorClass ac = xpac.getActorClass();
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("// state names");
+ _builder.newLine();
+ _builder.append("protected static final String stateStrings[] = {\"<no state>\",\"<top>\",");
+ {
+ List<State> _allBaseStatesLeavesLast = this._roomExtensions.getAllBaseStatesLeavesLast(ac);
+ boolean _hasElements = false;
+ for(final State state : _allBaseStatesLeavesLast) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(",", "");
+ }
+ _builder.append("\"");
+ String _genStatePathName = CodegenHelpers.getGenStatePathName(state);
+ _builder.append(_genStatePathName, "");
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("};");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("// history");
+ _builder.newLine();
+ _builder.append("protected int history[] = {NO_STATE,NO_STATE");
+ {
+ List<State> _allBaseStates = RoomHelpers.getAllBaseStates(ac);
+ for(final State state_1 : _allBaseStates) {
+ _builder.append(",NO_STATE");
+ }
+ }
+ _builder.append("};");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("private void setState(int new_state) {");
+ _builder.newLine();
+ {
+ boolean _generateMSCInstrumentation = GlobalSettings.generateMSCInstrumentation();
+ if (_generateMSCInstrumentation) {
+ _builder.append("\t");
+ _builder.append("DebuggingService.getInstance().addActorState(this,stateStrings[new_state]);");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("if (stateStrings[new_state]!=\"Idle\") {");
+ _builder.newLine();
+ {
+ boolean _generateWithVerboseOutput = GlobalSettings.generateWithVerboseOutput();
+ if (_generateWithVerboseOutput) {
+ _builder.append("\t\t");
+ _builder.append("System.out.println(\"state switch of \"+getInstancePath() + \": \"");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t\t");
+ _builder.append("+ stateStrings[this.state] + \" -> \" + stateStrings[new_state]);");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("this.state = new_state;");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/SubSystemClassGen.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/SubSystemClassGen.java
index 4bc85a322..c163755a8 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/SubSystemClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/SubSystemClassGen.java
@@ -1,542 +1,542 @@
-/**
- * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- */
-package org.eclipse.etrice.generator.java.gen;
-
-import com.google.common.base.Objects;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import java.util.HashSet;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance;
-import org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician;
-import org.eclipse.etrice.core.genmodel.etricegen.InterfaceItemInstance;
-import org.eclipse.etrice.core.genmodel.etricegen.Root;
-import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.ActorRef;
-import org.eclipse.etrice.core.room.CommunicationType;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.LogicalThread;
-import org.eclipse.etrice.core.room.ProtocolClass;
-import org.eclipse.etrice.core.room.RoomModel;
-import org.eclipse.etrice.core.room.SubSystemClass;
-import org.eclipse.etrice.generator.base.IDataConfiguration;
-import org.eclipse.etrice.generator.base.IGeneratorFileIo;
-import org.eclipse.etrice.generator.base.Indexed;
-import org.eclipse.etrice.generator.generic.ProcedureHelpers;
-import org.eclipse.etrice.generator.generic.RoomExtensions;
-import org.eclipse.etrice.generator.java.gen.ConfigGenAddon;
-import org.eclipse.etrice.generator.java.gen.JavaExtensions;
-import org.eclipse.etrice.generator.java.gen.VariableServiceGen;
-import org.eclipse.xtend2.lib.StringConcatenation;
-import org.eclipse.xtext.xbase.lib.Extension;
-
-@Singleton
-@SuppressWarnings("all")
-public class SubSystemClassGen {
- @Inject
- private IGeneratorFileIo fileIO;
-
- @Inject
- @Extension
- private JavaExtensions _javaExtensions;
-
- @Inject
- @Extension
- private RoomExtensions _roomExtensions;
-
- @Inject
- private IDataConfiguration dataConfigExt;
-
- @Inject
- private ConfigGenAddon configGenAddon;
-
- @Inject
- @Extension
- private ProcedureHelpers _procedureHelpers;
-
- @Inject
- private VariableServiceGen varService;
-
- @Inject
- private IDiagnostician diagnostician;
-
- public void doGenerate(final Root root) {
- EList<SubSystemInstance> _subSystemInstances = root.getSubSystemInstances();
- for (final SubSystemInstance ssi : _subSystemInstances) {
- {
- SubSystemClass _subSystemClass = ssi.getSubSystemClass();
- String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(_subSystemClass);
- SubSystemClass _subSystemClass_1 = ssi.getSubSystemClass();
- String _path = this._roomExtensions.getPath(_subSystemClass_1);
- final String path = (_generationTargetPath + _path);
- SubSystemClass _subSystemClass_2 = ssi.getSubSystemClass();
- String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(_subSystemClass_2);
- SubSystemClass _subSystemClass_3 = ssi.getSubSystemClass();
- String _path_1 = this._roomExtensions.getPath(_subSystemClass_3);
- final String infopath = (_generationInfoPath + _path_1);
- SubSystemClass _subSystemClass_4 = ssi.getSubSystemClass();
- final String file = this._javaExtensions.getJavaFileName(_subSystemClass_4);
- this.checkDataPorts(ssi);
- CharSequence _generate = this.generate(root, ssi);
- this.fileIO.generateFile("generating SubSystemClass implementation", path, infopath, file, _generate);
- boolean _hasVariableService = this.dataConfigExt.hasVariableService(ssi);
- if (_hasVariableService) {
- this.varService.doGenerate(root, ssi);
- }
- }
- }
- }
-
- public CharSequence generate(final Root root, final SubSystemInstance comp) {
- CharSequence _xblockexpression = null;
- {
- final SubSystemClass cc = comp.getSubSystemClass();
- final EList<RoomModel> models = root.getReferencedModels(cc);
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("package ");
- String _package = this._roomExtensions.getPackage(cc);
- _builder.append(_package, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.config.IVariableService;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.messaging.IRTObject;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.messaging.MessageService;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.messaging.MessageServiceController;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.messaging.RTServices;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;");
- _builder.newLine();
- _builder.newLine();
- {
- for(final RoomModel model : models) {
- _builder.append("import ");
- String _name = model.getName();
- _builder.append(_name, "");
- _builder.append(".*;");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- CharSequence _userCode = this._procedureHelpers.userCode(cc, 1);
- _builder.append(_userCode, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("public class ");
- String _name_1 = cc.getName();
- _builder.append(_name_1, "");
- _builder.append(" extends SubSystemClassBase {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public final int THREAD__DEFAULT = 0;");
- _builder.newLine();
- {
- EList<LogicalThread> _threads = cc.getThreads();
- Iterable<Indexed<LogicalThread>> _indexed = Indexed.<LogicalThread>indexed(_threads);
- for(final Indexed<LogicalThread> thread : _indexed) {
- _builder.append("\t");
- _builder.append("public final int ");
- LogicalThread _value = thread.getValue();
- String _threadId = this.getThreadId(_value);
- _builder.append(_threadId, " ");
- _builder.append(" = ");
- int _index1 = thread.getIndex1();
- _builder.append(_index1, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- _builder.append("\t");
- CharSequence _userCode_1 = this._procedureHelpers.userCode(cc, 2);
- _builder.append(_userCode_1, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public ");
- String _name_2 = cc.getName();
- _builder.append(_name_2, " ");
- _builder.append("(IRTObject parent, String name) {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("super(parent, name);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("@Override");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data){");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("@Override\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public void instantiateMessageServices() {");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, 0, THREAD__DEFAULT, \"MessageService_Main\"));");
- _builder.newLine();
- {
- EList<LogicalThread> _threads_1 = cc.getThreads();
- for(final LogicalThread thread_1 : _threads_1) {
- _builder.append("\t\t");
- _builder.append("RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, 0, ");
- String _threadId_1 = this.getThreadId(thread_1);
- _builder.append(_threadId_1, " ");
- _builder.append(", \"MessageService_");
- String _name_3 = thread_1.getName();
- _builder.append(_name_3, " ");
- _builder.append("\" /*, thread_prio */));");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("@Override");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public void instantiateActors() {");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("MessageServiceController msgSvcCtrl = RTServices.getInstance().getMsgSvcCtrl();");
- _builder.newLine();
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// thread mappings");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("msgSvcCtrl.addPathToThread(\"");
- String _path = comp.getPath();
- _builder.append(_path, " ");
- _builder.append("\", THREAD__DEFAULT);");
- _builder.newLineIfNotEmpty();
- {
- EList<ActorInstance> _allContainedInstances = comp.getAllContainedInstances();
- for(final ActorInstance ai : _allContainedInstances) {
- {
- int _threadId_2 = ai.getThreadId();
- boolean _notEquals = (_threadId_2 != 0);
- if (_notEquals) {
- _builder.append("\t\t");
- _builder.append("msgSvcCtrl.addPathToThread(\"");
- String _path_1 = ai.getPath();
- _builder.append(_path_1, " ");
- _builder.append("\", ");
- EList<LogicalThread> _threads_2 = cc.getThreads();
- int _threadId_3 = ai.getThreadId();
- int _minus = (_threadId_3 - 1);
- LogicalThread _get = _threads_2.get(_minus);
- String _threadId_4 = this.getThreadId(_get);
- _builder.append(_threadId_4, " ");
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// port to peer port mappings");
- _builder.newLine();
- {
- EList<ActorInstance> _allContainedInstances_1 = comp.getAllContainedInstances();
- for(final ActorInstance ai_1 : _allContainedInstances_1) {
- {
- EList<InterfaceItemInstance> _orderedIfItemInstances = ai_1.getOrderedIfItemInstances();
- for(final InterfaceItemInstance pi : _orderedIfItemInstances) {
- {
- EList<InterfaceItemInstance> _peers = pi.getPeers();
- int _size = _peers.size();
- boolean _greaterThan = (_size > 0);
- if (_greaterThan) {
- _builder.append("\t\t");
- _builder.append("msgSvcCtrl.addPathToPeers(\"");
- String _path_2 = pi.getPath();
- _builder.append(_path_2, " ");
- _builder.append("\", ");
- {
- EList<InterfaceItemInstance> _peers_1 = pi.getPeers();
- boolean _hasElements = false;
- for(final InterfaceItemInstance peer : _peers_1) {
- if (!_hasElements) {
- _hasElements = true;
- } else {
- _builder.appendImmediate(",", " ");
- }
- _builder.append("\"");
- String _path_3 = peer.getPath();
- _builder.append(_path_3, " ");
- _builder.append("\"");
- }
- }
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
- }
- }
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// sub actors");
- _builder.newLine();
- {
- EList<ActorRef> _actorRefs = cc.getActorRefs();
- for(final ActorRef sub : _actorRefs) {
- {
- int _size_1 = sub.getSize();
- boolean _greaterThan_1 = (_size_1 > 1);
- if (_greaterThan_1) {
- _builder.append("\t\t");
- _builder.append("for (int i=0; i<");
- int _size_2 = sub.getSize();
- _builder.append(_size_2, " ");
- _builder.append("; ++i)");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("new ");
- ActorClass _type = sub.getType();
- String _name_4 = _type.getName();
- _builder.append(_name_4, " ");
- _builder.append("(this, \"");
- String _name_5 = sub.getName();
- _builder.append(_name_5, " ");
- _builder.append("_\"+i); ");
- _builder.newLineIfNotEmpty();
- } else {
- _builder.append("\t\t");
- _builder.append("new ");
- ActorClass _type_1 = sub.getType();
- String _name_6 = _type_1.getName();
- _builder.append(_name_6, " ");
- _builder.append("(this, \"");
- String _name_7 = sub.getName();
- _builder.append(_name_7, " ");
- _builder.append("\"); ");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// apply instance attribute configurations");
- _builder.newLine();
- {
- EList<ActorInstance> _allContainedInstances_2 = comp.getAllContainedInstances();
- for(final ActorInstance ai_2 : _allContainedInstances_2) {
- _builder.append("\t\t");
- final CharSequence cfg = this.configGenAddon.genActorInstanceConfig(ai_2, "inst");
- _builder.newLineIfNotEmpty();
- {
- int _length = cfg.length();
- boolean _greaterThan_2 = (_length > 0);
- if (_greaterThan_2) {
- _builder.append("\t\t");
- _builder.append("{");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t");
- ActorClass _actorClass = ai_2.getActorClass();
- String _name_8 = _actorClass.getName();
- _builder.append(_name_8, " ");
- _builder.append(" inst = (");
- ActorClass _actorClass_1 = ai_2.getActorClass();
- String _name_9 = _actorClass_1.getName();
- _builder.append(_name_9, " ");
- _builder.append(") getObject(\"");
- String _path_4 = ai_2.getPath();
- _builder.append(_path_4, " ");
- _builder.append("\");");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("if (inst!=null) {");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t\t");
- _builder.append(cfg, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("@Override");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public void init(){");
- _builder.newLine();
- {
- boolean _hasVariableService = this.dataConfigExt.hasVariableService(comp);
- if (_hasVariableService) {
- _builder.append("\t\t");
- _builder.append("variableService = new ");
- String _name_10 = cc.getName();
- _builder.append(_name_10, " ");
- _builder.append("VariableService(this);");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t\t");
- _builder.append("super.init();");
- _builder.newLine();
- {
- boolean _hasVariableService_1 = this.dataConfigExt.hasVariableService(comp);
- if (_hasVariableService_1) {
- _builder.append("\t\t");
- _builder.append("variableService.init();");
- _builder.newLine();
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("@Override");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public void stop(){");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("super.stop();");
- _builder.newLine();
- {
- boolean _hasVariableService_2 = this.dataConfigExt.hasVariableService(comp);
- if (_hasVariableService_2) {
- _builder.append("\t\t");
- _builder.append("variableService.stop();");
- _builder.newLine();
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("};");
- _builder.newLine();
- _xblockexpression = (_builder);
- }
- return _xblockexpression;
- }
-
- private String getThreadId(final LogicalThread thread) {
- String _name = thread.getName();
- String _upperCase = _name.toUpperCase();
- String _plus = ("THREAD_" + _upperCase);
- return _plus;
- }
-
- private void checkDataPorts(final SubSystemInstance comp) {
- HashSet<String> _hashSet = new HashSet<String>();
- final HashSet<String> found = _hashSet;
- EList<ActorInstance> _allContainedInstances = comp.getAllContainedInstances();
- for (final ActorInstance ai : _allContainedInstances) {
- {
- final int thread = ai.getThreadId();
- EList<InterfaceItemInstance> _orderedIfItemInstances = ai.getOrderedIfItemInstances();
- for (final InterfaceItemInstance pi : _orderedIfItemInstances) {
- ProtocolClass _protocol = pi.getProtocol();
- CommunicationType _commType = _protocol.getCommType();
- boolean _equals = Objects.equal(_commType, CommunicationType.DATA_DRIVEN);
- if (_equals) {
- EList<InterfaceItemInstance> _peers = pi.getPeers();
- for (final InterfaceItemInstance peer : _peers) {
- {
- EObject _eContainer = peer.eContainer();
- final ActorInstance peer_ai = ((ActorInstance) _eContainer);
- final int peer_thread = peer_ai.getThreadId();
- boolean _notEquals = (thread != peer_thread);
- if (_notEquals) {
- final String path = pi.getPath();
- final String ppath = peer.getPath();
- String _xifexpression = null;
- int _compareTo = path.compareTo(ppath);
- boolean _lessThan = (_compareTo < 0);
- if (_lessThan) {
- String _plus = (path + " and ");
- String _plus_1 = (_plus + ppath);
- _xifexpression = _plus_1;
- } else {
- String _plus_2 = (ppath + " and ");
- String _plus_3 = (_plus_2 + path);
- _xifexpression = _plus_3;
- }
- final String pair = _xifexpression;
- boolean _contains = found.contains(pair);
- boolean _not = (!_contains);
- if (_not) {
- found.add(pair);
- String _plus_4 = (pair + ": data ports placed on different threads (not supported yet)");
- InterfaceItem _interfaceItem = pi.getInterfaceItem();
- InterfaceItem _interfaceItem_1 = pi.getInterfaceItem();
- EStructuralFeature _eContainingFeature = _interfaceItem_1.eContainingFeature();
- this.diagnostician.error(_plus_4, _interfaceItem, _eContainingFeature);
- }
- }
- }
- }
- }
- }
- }
- }
- }
-}
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ */
+package org.eclipse.etrice.generator.java.gen;
+
+import com.google.common.base.Objects;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.HashSet;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance;
+import org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician;
+import org.eclipse.etrice.core.genmodel.etricegen.InterfaceItemInstance;
+import org.eclipse.etrice.core.genmodel.etricegen.Root;
+import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorRef;
+import org.eclipse.etrice.core.room.CommunicationType;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.LogicalThread;
+import org.eclipse.etrice.core.room.ProtocolClass;
+import org.eclipse.etrice.core.room.RoomModel;
+import org.eclipse.etrice.core.room.SubSystemClass;
+import org.eclipse.etrice.generator.base.IDataConfiguration;
+import org.eclipse.etrice.generator.base.IGeneratorFileIo;
+import org.eclipse.etrice.generator.base.Indexed;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.java.gen.ConfigGenAddon;
+import org.eclipse.etrice.generator.java.gen.JavaExtensions;
+import org.eclipse.etrice.generator.java.gen.VariableServiceGen;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.Extension;
+
+@Singleton
+@SuppressWarnings("all")
+public class SubSystemClassGen {
+ @Inject
+ private IGeneratorFileIo fileIO;
+
+ @Inject
+ @Extension
+ private JavaExtensions _javaExtensions;
+
+ @Inject
+ @Extension
+ private RoomExtensions _roomExtensions;
+
+ @Inject
+ private IDataConfiguration dataConfigExt;
+
+ @Inject
+ private ConfigGenAddon configGenAddon;
+
+ @Inject
+ @Extension
+ private ProcedureHelpers _procedureHelpers;
+
+ @Inject
+ private VariableServiceGen varService;
+
+ @Inject
+ private IDiagnostician diagnostician;
+
+ public void doGenerate(final Root root) {
+ EList<SubSystemInstance> _subSystemInstances = root.getSubSystemInstances();
+ for (final SubSystemInstance ssi : _subSystemInstances) {
+ {
+ SubSystemClass _subSystemClass = ssi.getSubSystemClass();
+ String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(_subSystemClass);
+ SubSystemClass _subSystemClass_1 = ssi.getSubSystemClass();
+ String _path = this._roomExtensions.getPath(_subSystemClass_1);
+ final String path = (_generationTargetPath + _path);
+ SubSystemClass _subSystemClass_2 = ssi.getSubSystemClass();
+ String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(_subSystemClass_2);
+ SubSystemClass _subSystemClass_3 = ssi.getSubSystemClass();
+ String _path_1 = this._roomExtensions.getPath(_subSystemClass_3);
+ final String infopath = (_generationInfoPath + _path_1);
+ SubSystemClass _subSystemClass_4 = ssi.getSubSystemClass();
+ final String file = this._javaExtensions.getJavaFileName(_subSystemClass_4);
+ this.checkDataPorts(ssi);
+ CharSequence _generate = this.generate(root, ssi);
+ this.fileIO.generateFile("generating SubSystemClass implementation", path, infopath, file, _generate);
+ boolean _hasVariableService = this.dataConfigExt.hasVariableService(ssi);
+ if (_hasVariableService) {
+ this.varService.doGenerate(root, ssi);
+ }
+ }
+ }
+ }
+
+ public CharSequence generate(final Root root, final SubSystemInstance comp) {
+ CharSequence _xblockexpression = null;
+ {
+ final SubSystemClass cc = comp.getSubSystemClass();
+ final EList<RoomModel> models = root.getReferencedModels(cc);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package ");
+ String _package = this._roomExtensions.getPackage(cc);
+ _builder.append(_package, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.config.IVariableService;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.messaging.IRTObject;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.messaging.MessageService;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.messaging.MessageServiceController;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.messaging.RTServices;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ for(final RoomModel model : models) {
+ _builder.append("import ");
+ String _name = model.getName();
+ _builder.append(_name, "");
+ _builder.append(".*;");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ CharSequence _userCode = this._procedureHelpers.userCode(cc, 1);
+ _builder.append(_userCode, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("public class ");
+ String _name_1 = cc.getName();
+ _builder.append(_name_1, "");
+ _builder.append(" extends SubSystemClassBase {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public final int THREAD__DEFAULT = 0;");
+ _builder.newLine();
+ {
+ EList<LogicalThread> _threads = cc.getThreads();
+ Iterable<Indexed<LogicalThread>> _indexed = Indexed.<LogicalThread>indexed(_threads);
+ for(final Indexed<LogicalThread> thread : _indexed) {
+ _builder.append("\t");
+ _builder.append("public final int ");
+ LogicalThread _value = thread.getValue();
+ String _threadId = this.getThreadId(_value);
+ _builder.append(_threadId, " ");
+ _builder.append(" = ");
+ int _index1 = thread.getIndex1();
+ _builder.append(_index1, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _userCode_1 = this._procedureHelpers.userCode(cc, 2);
+ _builder.append(_userCode_1, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public ");
+ String _name_2 = cc.getName();
+ _builder.append(_name_2, " ");
+ _builder.append("(IRTObject parent, String name) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("super(parent, name);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("@Override");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data){");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("@Override\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public void instantiateMessageServices() {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, 0, THREAD__DEFAULT, \"MessageService_Main\"));");
+ _builder.newLine();
+ {
+ EList<LogicalThread> _threads_1 = cc.getThreads();
+ for(final LogicalThread thread_1 : _threads_1) {
+ _builder.append("\t\t");
+ _builder.append("RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, 0, ");
+ String _threadId_1 = this.getThreadId(thread_1);
+ _builder.append(_threadId_1, " ");
+ _builder.append(", \"MessageService_");
+ String _name_3 = thread_1.getName();
+ _builder.append(_name_3, " ");
+ _builder.append("\" /*, thread_prio */));");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("@Override");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public void instantiateActors() {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("MessageServiceController msgSvcCtrl = RTServices.getInstance().getMsgSvcCtrl();");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// thread mappings");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("msgSvcCtrl.addPathToThread(\"");
+ String _path = comp.getPath();
+ _builder.append(_path, " ");
+ _builder.append("\", THREAD__DEFAULT);");
+ _builder.newLineIfNotEmpty();
+ {
+ EList<ActorInstance> _allContainedInstances = comp.getAllContainedInstances();
+ for(final ActorInstance ai : _allContainedInstances) {
+ {
+ int _threadId_2 = ai.getThreadId();
+ boolean _notEquals = (_threadId_2 != 0);
+ if (_notEquals) {
+ _builder.append("\t\t");
+ _builder.append("msgSvcCtrl.addPathToThread(\"");
+ String _path_1 = ai.getPath();
+ _builder.append(_path_1, " ");
+ _builder.append("\", ");
+ EList<LogicalThread> _threads_2 = cc.getThreads();
+ int _threadId_3 = ai.getThreadId();
+ int _minus = (_threadId_3 - 1);
+ LogicalThread _get = _threads_2.get(_minus);
+ String _threadId_4 = this.getThreadId(_get);
+ _builder.append(_threadId_4, " ");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// port to peer port mappings");
+ _builder.newLine();
+ {
+ EList<ActorInstance> _allContainedInstances_1 = comp.getAllContainedInstances();
+ for(final ActorInstance ai_1 : _allContainedInstances_1) {
+ {
+ EList<InterfaceItemInstance> _orderedIfItemInstances = ai_1.getOrderedIfItemInstances();
+ for(final InterfaceItemInstance pi : _orderedIfItemInstances) {
+ {
+ EList<InterfaceItemInstance> _peers = pi.getPeers();
+ int _size = _peers.size();
+ boolean _greaterThan = (_size > 0);
+ if (_greaterThan) {
+ _builder.append("\t\t");
+ _builder.append("msgSvcCtrl.addPathToPeers(\"");
+ String _path_2 = pi.getPath();
+ _builder.append(_path_2, " ");
+ _builder.append("\", ");
+ {
+ EList<InterfaceItemInstance> _peers_1 = pi.getPeers();
+ boolean _hasElements = false;
+ for(final InterfaceItemInstance peer : _peers_1) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(",", " ");
+ }
+ _builder.append("\"");
+ String _path_3 = peer.getPath();
+ _builder.append(_path_3, " ");
+ _builder.append("\"");
+ }
+ }
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// sub actors");
+ _builder.newLine();
+ {
+ EList<ActorRef> _actorRefs = cc.getActorRefs();
+ for(final ActorRef sub : _actorRefs) {
+ {
+ int _size_1 = sub.getSize();
+ boolean _greaterThan_1 = (_size_1 > 1);
+ if (_greaterThan_1) {
+ _builder.append("\t\t");
+ _builder.append("for (int i=0; i<");
+ int _size_2 = sub.getSize();
+ _builder.append(_size_2, " ");
+ _builder.append("; ++i)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("new ");
+ ActorClass _type = sub.getType();
+ String _name_4 = _type.getName();
+ _builder.append(_name_4, " ");
+ _builder.append("(this, \"");
+ String _name_5 = sub.getName();
+ _builder.append(_name_5, " ");
+ _builder.append("_\"+i); ");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("\t\t");
+ _builder.append("new ");
+ ActorClass _type_1 = sub.getType();
+ String _name_6 = _type_1.getName();
+ _builder.append(_name_6, " ");
+ _builder.append("(this, \"");
+ String _name_7 = sub.getName();
+ _builder.append(_name_7, " ");
+ _builder.append("\"); ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// apply instance attribute configurations");
+ _builder.newLine();
+ {
+ EList<ActorInstance> _allContainedInstances_2 = comp.getAllContainedInstances();
+ for(final ActorInstance ai_2 : _allContainedInstances_2) {
+ _builder.append("\t\t");
+ final CharSequence cfg = this.configGenAddon.genActorInstanceConfig(ai_2, "inst");
+ _builder.newLineIfNotEmpty();
+ {
+ int _length = cfg.length();
+ boolean _greaterThan_2 = (_length > 0);
+ if (_greaterThan_2) {
+ _builder.append("\t\t");
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ ActorClass _actorClass = ai_2.getActorClass();
+ String _name_8 = _actorClass.getName();
+ _builder.append(_name_8, " ");
+ _builder.append(" inst = (");
+ ActorClass _actorClass_1 = ai_2.getActorClass();
+ String _name_9 = _actorClass_1.getName();
+ _builder.append(_name_9, " ");
+ _builder.append(") getObject(\"");
+ String _path_4 = ai_2.getPath();
+ _builder.append(_path_4, " ");
+ _builder.append("\");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("if (inst!=null) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t\t");
+ _builder.append(cfg, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("@Override");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public void init(){");
+ _builder.newLine();
+ {
+ boolean _hasVariableService = this.dataConfigExt.hasVariableService(comp);
+ if (_hasVariableService) {
+ _builder.append("\t\t");
+ _builder.append("variableService = new ");
+ String _name_10 = cc.getName();
+ _builder.append(_name_10, " ");
+ _builder.append("VariableService(this);");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t\t");
+ _builder.append("super.init();");
+ _builder.newLine();
+ {
+ boolean _hasVariableService_1 = this.dataConfigExt.hasVariableService(comp);
+ if (_hasVariableService_1) {
+ _builder.append("\t\t");
+ _builder.append("variableService.init();");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("@Override");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public void stop(){");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("super.stop();");
+ _builder.newLine();
+ {
+ boolean _hasVariableService_2 = this.dataConfigExt.hasVariableService(comp);
+ if (_hasVariableService_2) {
+ _builder.append("\t\t");
+ _builder.append("variableService.stop();");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+
+ private String getThreadId(final LogicalThread thread) {
+ String _name = thread.getName();
+ String _upperCase = _name.toUpperCase();
+ String _plus = ("THREAD_" + _upperCase);
+ return _plus;
+ }
+
+ private void checkDataPorts(final SubSystemInstance comp) {
+ HashSet<String> _hashSet = new HashSet<String>();
+ final HashSet<String> found = _hashSet;
+ EList<ActorInstance> _allContainedInstances = comp.getAllContainedInstances();
+ for (final ActorInstance ai : _allContainedInstances) {
+ {
+ final int thread = ai.getThreadId();
+ EList<InterfaceItemInstance> _orderedIfItemInstances = ai.getOrderedIfItemInstances();
+ for (final InterfaceItemInstance pi : _orderedIfItemInstances) {
+ ProtocolClass _protocol = pi.getProtocol();
+ CommunicationType _commType = _protocol.getCommType();
+ boolean _equals = Objects.equal(_commType, CommunicationType.DATA_DRIVEN);
+ if (_equals) {
+ EList<InterfaceItemInstance> _peers = pi.getPeers();
+ for (final InterfaceItemInstance peer : _peers) {
+ {
+ EObject _eContainer = peer.eContainer();
+ final ActorInstance peer_ai = ((ActorInstance) _eContainer);
+ final int peer_thread = peer_ai.getThreadId();
+ boolean _notEquals = (thread != peer_thread);
+ if (_notEquals) {
+ final String path = pi.getPath();
+ final String ppath = peer.getPath();
+ String _xifexpression = null;
+ int _compareTo = path.compareTo(ppath);
+ boolean _lessThan = (_compareTo < 0);
+ if (_lessThan) {
+ String _plus = (path + " and ");
+ String _plus_1 = (_plus + ppath);
+ _xifexpression = _plus_1;
+ } else {
+ String _plus_2 = (ppath + " and ");
+ String _plus_3 = (_plus_2 + path);
+ _xifexpression = _plus_3;
+ }
+ final String pair = _xifexpression;
+ boolean _contains = found.contains(pair);
+ boolean _not = (!_contains);
+ if (_not) {
+ found.add(pair);
+ String _plus_4 = (pair + ": data ports placed on different threads (not supported yet)");
+ InterfaceItem _interfaceItem = pi.getInterfaceItem();
+ InterfaceItem _interfaceItem_1 = pi.getInterfaceItem();
+ EStructuralFeature _eContainingFeature = _interfaceItem_1.eContainingFeature();
+ this.diagnostician.error(_plus_4, _interfaceItem, _eContainingFeature);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/SubSystemRunnerGen.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/SubSystemRunnerGen.java
index 8bb578aa2..592662ee4 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/SubSystemRunnerGen.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/SubSystemRunnerGen.java
@@ -1,164 +1,164 @@
-/**
- * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- */
-package org.eclipse.etrice.generator.java.gen;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.etrice.core.genmodel.etricegen.Root;
-import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance;
-import org.eclipse.etrice.core.genmodel.etricegen.SystemInstance;
-import org.eclipse.etrice.core.room.SubSystemClass;
-import org.eclipse.etrice.generator.base.IGeneratorFileIo;
-import org.eclipse.etrice.generator.generic.RoomExtensions;
-import org.eclipse.xtend2.lib.StringConcatenation;
-import org.eclipse.xtext.xbase.lib.Extension;
-
-@Singleton
-@SuppressWarnings("all")
-public class SubSystemRunnerGen {
- @Inject
- private IGeneratorFileIo fileIO;
-
- @Inject
- @Extension
- private RoomExtensions roomExt;
-
- public void doGenerate(final Root root) {
- EList<SubSystemInstance> _subSystemInstances = root.getSubSystemInstances();
- for (final SubSystemInstance sc : _subSystemInstances) {
- {
- SubSystemClass _subSystemClass = sc.getSubSystemClass();
- String _generationTargetPath = this.roomExt.getGenerationTargetPath(_subSystemClass);
- SubSystemClass _subSystemClass_1 = sc.getSubSystemClass();
- String _path = this.roomExt.getPath(_subSystemClass_1);
- final String path = (_generationTargetPath + _path);
- SubSystemClass _subSystemClass_2 = sc.getSubSystemClass();
- String _generationInfoPath = this.roomExt.getGenerationInfoPath(_subSystemClass_2);
- SubSystemClass _subSystemClass_3 = sc.getSubSystemClass();
- String _path_1 = this.roomExt.getPath(_subSystemClass_3);
- final String infopath = (_generationInfoPath + _path_1);
- SubSystemClass _subSystemClass_4 = sc.getSubSystemClass();
- String _name = _subSystemClass_4.getName();
- final String file = (_name + "Runner.java");
- CharSequence _generate = this.generate(root, sc);
- this.fileIO.generateFile("generating SubSystemRunner implementation", path, infopath, file, _generate);
- }
- }
- }
-
- public CharSequence generate(final Root root, final SubSystemInstance ssc) {
- CharSequence _xblockexpression = null;
- {
- final SubSystemClass cc = ssc.getSubSystemClass();
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("/**");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* @author generated by eTrice");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* this class contains the main function running component ");
- String _name = ssc.getName();
- _builder.append(_name, " ");
- _builder.newLineIfNotEmpty();
- _builder.append(" ");
- _builder.append("* it instantiates ");
- String _name_1 = ssc.getName();
- _builder.append(_name_1, " ");
- _builder.append(" and starts and ends the lifecycle");
- _builder.newLineIfNotEmpty();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.newLine();
- _builder.append("package ");
- String _package = this.roomExt.getPackage(cc);
- _builder.append(_package, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.RTSystem;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.modelbase.SubSystemRunnerBase;");
- _builder.newLine();
- _builder.newLine();
- _builder.append("class ");
- String _name_2 = cc.getName();
- String _plus = (_name_2 + "Runner");
- _builder.append(_plus, "");
- _builder.append(" extends SubSystemRunnerBase {");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("/**");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* main function");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* creates the main component and starts and stops the lifecycle");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public static void main(String[] args) {");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// instantiate the main component");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("RTSystem sys = ");
- {
- EObject _eContainer = ssc.eContainer();
- if ((_eContainer instanceof SystemInstance)) {
- _builder.append("new RTSystem(\"");
- EObject _eContainer_1 = ssc.eContainer();
- String _name_3 = ((SystemInstance) _eContainer_1).getName();
- _builder.append(_name_3, " ");
- _builder.append("\")");
- } else {
- _builder.append("null");
- }
- }
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- String _name_4 = cc.getName();
- _builder.append(_name_4, " ");
- _builder.append(" main_component = new ");
- String _name_5 = cc.getName();
- _builder.append(_name_5, " ");
- _builder.append("(sys, \"");
- String _name_6 = ssc.getName();
- _builder.append(_name_6, " ");
- _builder.append("\");");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("run(main_component, args);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("};");
- _builder.newLine();
- _xblockexpression = (_builder);
- }
- return _xblockexpression;
- }
-}
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ */
+package org.eclipse.etrice.generator.java.gen;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.genmodel.etricegen.Root;
+import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance;
+import org.eclipse.etrice.core.genmodel.etricegen.SystemInstance;
+import org.eclipse.etrice.core.room.SubSystemClass;
+import org.eclipse.etrice.generator.base.IGeneratorFileIo;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.Extension;
+
+@Singleton
+@SuppressWarnings("all")
+public class SubSystemRunnerGen {
+ @Inject
+ private IGeneratorFileIo fileIO;
+
+ @Inject
+ @Extension
+ private RoomExtensions roomExt;
+
+ public void doGenerate(final Root root) {
+ EList<SubSystemInstance> _subSystemInstances = root.getSubSystemInstances();
+ for (final SubSystemInstance sc : _subSystemInstances) {
+ {
+ SubSystemClass _subSystemClass = sc.getSubSystemClass();
+ String _generationTargetPath = this.roomExt.getGenerationTargetPath(_subSystemClass);
+ SubSystemClass _subSystemClass_1 = sc.getSubSystemClass();
+ String _path = this.roomExt.getPath(_subSystemClass_1);
+ final String path = (_generationTargetPath + _path);
+ SubSystemClass _subSystemClass_2 = sc.getSubSystemClass();
+ String _generationInfoPath = this.roomExt.getGenerationInfoPath(_subSystemClass_2);
+ SubSystemClass _subSystemClass_3 = sc.getSubSystemClass();
+ String _path_1 = this.roomExt.getPath(_subSystemClass_3);
+ final String infopath = (_generationInfoPath + _path_1);
+ SubSystemClass _subSystemClass_4 = sc.getSubSystemClass();
+ String _name = _subSystemClass_4.getName();
+ final String file = (_name + "Runner.java");
+ CharSequence _generate = this.generate(root, sc);
+ this.fileIO.generateFile("generating SubSystemRunner implementation", path, infopath, file, _generate);
+ }
+ }
+ }
+
+ public CharSequence generate(final Root root, final SubSystemInstance ssc) {
+ CharSequence _xblockexpression = null;
+ {
+ final SubSystemClass cc = ssc.getSubSystemClass();
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @author generated by eTrice");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* this class contains the main function running component ");
+ String _name = ssc.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("* it instantiates ");
+ String _name_1 = ssc.getName();
+ _builder.append(_name_1, " ");
+ _builder.append(" and starts and ends the lifecycle");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("package ");
+ String _package = this.roomExt.getPackage(cc);
+ _builder.append(_package, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.RTSystem;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.modelbase.SubSystemRunnerBase;");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("class ");
+ String _name_2 = cc.getName();
+ String _plus = (_name_2 + "Runner");
+ _builder.append(_plus, "");
+ _builder.append(" extends SubSystemRunnerBase {");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* main function");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* creates the main component and starts and stops the lifecycle");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public static void main(String[] args) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// instantiate the main component");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("RTSystem sys = ");
+ {
+ EObject _eContainer = ssc.eContainer();
+ if ((_eContainer instanceof SystemInstance)) {
+ _builder.append("new RTSystem(\"");
+ EObject _eContainer_1 = ssc.eContainer();
+ String _name_3 = ((SystemInstance) _eContainer_1).getName();
+ _builder.append(_name_3, " ");
+ _builder.append("\")");
+ } else {
+ _builder.append("null");
+ }
+ }
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ String _name_4 = cc.getName();
+ _builder.append(_name_4, " ");
+ _builder.append(" main_component = new ");
+ String _name_5 = cc.getName();
+ _builder.append(_name_5, " ");
+ _builder.append("(sys, \"");
+ String _name_6 = ssc.getName();
+ _builder.append(_name_6, " ");
+ _builder.append("\");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("run(main_component, args);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/VariableServiceGen.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/VariableServiceGen.java
index 2980752a7..f71a74296 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/VariableServiceGen.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/VariableServiceGen.java
@@ -1,981 +1,981 @@
-/**
- * Copyright (c) 2012 Juergen Haug
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Juergen Haug
- */
-package org.eclipse.etrice.generator.java.gen;
-
-import com.google.common.base.Objects;
-import com.google.common.collect.Iterables;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance;
-import org.eclipse.etrice.core.genmodel.etricegen.Root;
-import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.Attribute;
-import org.eclipse.etrice.core.room.DataClass;
-import org.eclipse.etrice.core.room.DataType;
-import org.eclipse.etrice.core.room.RefableType;
-import org.eclipse.etrice.core.room.RoomModel;
-import org.eclipse.etrice.core.room.SubSystemClass;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.etrice.generator.base.IDataConfiguration;
-import org.eclipse.etrice.generator.base.IGeneratorFileIo;
-import org.eclipse.etrice.generator.generic.ProcedureHelpers;
-import org.eclipse.etrice.generator.generic.RoomExtensions;
-import org.eclipse.etrice.generator.generic.TypeHelpers;
-import org.eclipse.etrice.generator.java.gen.JavaExtensions;
-import org.eclipse.xtend2.lib.StringConcatenation;
-import org.eclipse.xtext.xbase.lib.Conversions;
-import org.eclipse.xtext.xbase.lib.Extension;
-import org.eclipse.xtext.xbase.lib.IterableExtensions;
-import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
-import org.eclipse.xtext.xbase.lib.StringExtensions;
-
-@Singleton
-@SuppressWarnings("all")
-public class VariableServiceGen {
- @Inject
- private IGeneratorFileIo fileIO;
-
- @Inject
- @Extension
- private JavaExtensions stdExt;
-
- @Inject
- @Extension
- private RoomExtensions roomExt;
-
- @Inject
- private IDataConfiguration configExt;
-
- @Inject
- @Extension
- private ProcedureHelpers helpers;
-
- @Inject
- @Extension
- private TypeHelpers _typeHelpers;
-
- public void doGenerate(final Root root, final SubSystemInstance ssi) {
- SubSystemClass _subSystemClass = ssi.getSubSystemClass();
- String _generationTargetPath = this.roomExt.getGenerationTargetPath(_subSystemClass);
- SubSystemClass _subSystemClass_1 = ssi.getSubSystemClass();
- String _path = this.roomExt.getPath(_subSystemClass_1);
- final String path = (_generationTargetPath + _path);
- SubSystemClass _subSystemClass_2 = ssi.getSubSystemClass();
- String _generationInfoPath = this.roomExt.getGenerationInfoPath(_subSystemClass_2);
- SubSystemClass _subSystemClass_3 = ssi.getSubSystemClass();
- String _path_1 = this.roomExt.getPath(_subSystemClass_3);
- final String infopath = (_generationInfoPath + _path_1);
- SubSystemClass _subSystemClass_4 = ssi.getSubSystemClass();
- String _name = _subSystemClass_4.getName();
- final String file = (_name + "VariableService.java");
- CharSequence _generate = this.generate(root, ssi);
- this.fileIO.generateFile("generating VariableService implementation", path, infopath, file, _generate);
- }
-
- private CharSequence generate(final Root root, final SubSystemInstance comp) {
- CharSequence _xblockexpression = null;
- {
- SubSystemClass cc = comp.getSubSystemClass();
- HashMap<ActorInstance,List<Attribute>> _hashMap = new HashMap<ActorInstance,List<Attribute>>();
- final HashMap<ActorInstance,List<Attribute>> aisAttrMap = _hashMap;
- EList<ActorInstance> _allContainedInstances = comp.getAllContainedInstances();
- final Procedure1<ActorInstance> _function = new Procedure1<ActorInstance>() {
- public void apply(final ActorInstance ai) {
- List<Attribute> _dynConfigReadAttributes = VariableServiceGen.this.configExt.getDynConfigReadAttributes(ai);
- boolean _isEmpty = _dynConfigReadAttributes.isEmpty();
- boolean _not = (!_isEmpty);
- if (_not) {
- List<Attribute> _dynConfigReadAttributes_1 = VariableServiceGen.this.configExt.getDynConfigReadAttributes(ai);
- aisAttrMap.put(ai, _dynConfigReadAttributes_1);
- }
- }
- };
- IterableExtensions.<ActorInstance>forEach(_allContainedInstances, _function);
- StringConcatenation _builder = new StringConcatenation();
- _builder.newLine();
- _builder.append("package ");
- SubSystemClass _subSystemClass = comp.getSubSystemClass();
- String _package = this.roomExt.getPackage(_subSystemClass);
- _builder.append(_package, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("import java.util.Arrays;");
- _builder.newLine();
- _builder.append("import java.util.HashMap;");
- _builder.newLine();
- _builder.append("import java.util.Map;");
- _builder.newLine();
- _builder.append("import org.eclipse.etrice.runtime.java.config.AbstractVariableService;");
- _builder.newLine();
- String _userCode1 = this.configExt.getUserCode1(comp);
- _builder.append(_userCode1, "");
- _builder.newLineIfNotEmpty();
- {
- Set<ActorInstance> _keySet = aisAttrMap.keySet();
- HashSet<RoomModel> _roomModels = this.getRoomModels(_keySet);
- for(final RoomModel model : _roomModels) {
- _builder.append("import ");
- String _name = model.getName();
- _builder.append(_name, "");
- _builder.append(".*;");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- _builder.newLine();
- _builder.append("public class ");
- String _name_1 = cc.getName();
- String _plus = (_name_1 + "VariableService");
- _builder.append(_plus, "");
- _builder.append(" extends AbstractVariableService{");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("private ");
- SubSystemClass _subSystemClass_1 = comp.getSubSystemClass();
- String _name_2 = _subSystemClass_1.getName();
- _builder.append(_name_2, " ");
- _builder.append(" subSystem;");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("// Actor instances");
- _builder.newLine();
- {
- Set<ActorInstance> _keySet_1 = aisAttrMap.keySet();
- for(final ActorInstance ai : _keySet_1) {
- _builder.append("\t");
- _builder.append("private ");
- ActorClass _actorClass = ai.getActorClass();
- String _name_3 = _actorClass.getName();
- _builder.append(_name_3, " ");
- _builder.append(" ");
- CharSequence _varName = this.getVarName(ai);
- _builder.append(_varName, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public ");
- String _name_4 = cc.getName();
- String _plus_1 = (_name_4 + "VariableService");
- _builder.append(_plus_1, " ");
- _builder.append("(");
- String _name_5 = cc.getName();
- _builder.append(_name_5, " ");
- _builder.append(" subSystem) {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("super(");
- String _userCode2 = this.configExt.getUserCode2(comp);
- _builder.append(_userCode2, " ");
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("this.subSystem = subSystem;");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("@Override");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("protected void initInstances(){");
- _builder.newLine();
- {
- Set<ActorInstance> _keySet_2 = aisAttrMap.keySet();
- for(final ActorInstance ai_1 : _keySet_2) {
- _builder.append("\t\t");
- CharSequence _varName_1 = this.getVarName(ai_1);
- _builder.append(_varName_1, " ");
- _builder.append(" = (");
- ActorClass _actorClass_1 = ai_1.getActorClass();
- String _name_6 = _actorClass_1.getName();
- _builder.append(_name_6, " ");
- _builder.append(")subSystem.getInstance(\"");
- String _path = ai_1.getPath();
- _builder.append(_path, " ");
- _builder.append("\");");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("@Override");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("protected void setAttributeValues(Map<String, Object> values) {");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("Object object;");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("String id = null;");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.newLine();
- {
- Set<ActorInstance> _keySet_3 = aisAttrMap.keySet();
- for(final ActorInstance ai_2 : _keySet_3) {
- {
- List<Attribute> _get = aisAttrMap.get(ai_2);
- for(final Attribute a : _get) {
- _builder.append("\t\t");
- _builder.append("try{");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("boolean changed = false;");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t");
- ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
- List<Attribute> _union = this.roomExt.<Attribute>union(_arrayList, a);
- CharSequence _genSetAttributeValues1 = this.genSetAttributeValues1(_union, ai_2);
- _builder.append(_genSetAttributeValues1, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("if(changed)");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t\t");
- _builder.append("synchronized(");
- CharSequence _varName_2 = this.getVarName(ai_2);
- _builder.append(_varName_2, " ");
- _builder.append(".");
- String _name_7 = a.getName();
- String _plus_2 = (_name_7 + "Lock");
- CharSequence _invokeGetter = this.helpers.invokeGetter(_plus_2, null);
- _builder.append(_invokeGetter, " ");
- _builder.append("){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t\t\t");
- _builder.append("if(");
- CharSequence _varName_3 = this.getVarName(ai_2);
- _builder.append(_varName_3, " ");
- _builder.append(".");
- String _name_8 = a.getName();
- String _plus_3 = (_name_8 + "Lock");
- CharSequence _invokeGetter_1 = this.helpers.invokeGetter(_plus_3, null);
- _builder.append(_invokeGetter_1, " ");
- _builder.append(".isUpdate()){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t\t\t\t");
- ArrayList<Attribute> _arrayList_1 = new ArrayList<Attribute>();
- List<Attribute> _union_1 = this.roomExt.<Attribute>union(_arrayList_1, a);
- CharSequence _genSetAttributeValues2 = this.genSetAttributeValues2(_union_1, ai_2);
- _builder.append(_genSetAttributeValues2, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("}catch(IllegalArgumentException e){");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("error(id, e);");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("@Override");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("protected Map<String, Object> getAttributeValues(){");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("Map<String, Object> values = new HashMap<String, Object>();");
- _builder.newLine();
- {
- Set<ActorInstance> _keySet_4 = aisAttrMap.keySet();
- for(final ActorInstance ai_3 : _keySet_4) {
- {
- List<Attribute> _get_1 = aisAttrMap.get(ai_3);
- for(final Attribute a_1 : _get_1) {
- _builder.append("\t\t");
- ArrayList<Attribute> _arrayList_2 = new ArrayList<Attribute>();
- List<Attribute> _union_2 = this.roomExt.<Attribute>union(_arrayList_2, a_1);
- CharSequence _genGetAttributeValues = this.genGetAttributeValues(_union_2, ai_3);
- _builder.append(_genGetAttributeValues, " ");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("return values;");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("@Override");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("public void writeDataClass(String id, Object dcObject, Map<String, Object> writeMap) {");
- _builder.newLine();
- _builder.append("\t\t");
- Set<ActorInstance> _keySet_5 = aisAttrMap.keySet();
- HashSet<DataClass> dataClasses = this.getDynConfigDataClasses(_keySet_5);
- _builder.newLineIfNotEmpty();
- {
- for(final DataClass dc : dataClasses) {
- _builder.append("\t\t");
- _builder.append("if(dcObject.getClass().equals(");
- String _typeName = this._typeHelpers.typeName(dc);
- _builder.append(_typeName, " ");
- _builder.append(".class))");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("\t");
- _builder.append("writeDataClass(id, (");
- String _typeName_1 = this._typeHelpers.typeName(dc);
- _builder.append(_typeName_1, " ");
- _builder.append(") dcObject, writeTasks);");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("// DataClasses write operations");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- {
- HashSet<DataClass> _allDataClasses = this.getAllDataClasses(dataClasses);
- for(final DataClass dc_1 : _allDataClasses) {
- _builder.append("\t");
- _builder.append("private void writeDataClass(String id, ");
- String _typeName_2 = this._typeHelpers.typeName(dc_1);
- _builder.append(_typeName_2, " ");
- _builder.append(" object, Map<String, Object> map){");
- _builder.newLineIfNotEmpty();
- {
- List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(dc_1);
- for(final Attribute a_2 : _allAttributes) {
- {
- RefableType _refType = a_2.getRefType();
- DataType _type = _refType.getType();
- boolean _isPrimitive = this._typeHelpers.isPrimitive(_type);
- if (_isPrimitive) {
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("map.put(id+\"/");
- String _name_9 = a_2.getName();
- _builder.append(_name_9, " ");
- _builder.append("\", ");
- {
- int _size = a_2.getSize();
- boolean _greaterThan = (_size > 0);
- if (_greaterThan) {
- _builder.append("toObjectArray(");
- }
- }
- _builder.append("object.");
- String _name_10 = a_2.getName();
- CharSequence _invokeGetter_2 = this.helpers.invokeGetter(_name_10, null);
- _builder.append(_invokeGetter_2, " ");
- {
- int _size_1 = a_2.getSize();
- boolean _greaterThan_1 = (_size_1 > 0);
- if (_greaterThan_1) {
- _builder.append(")");
- }
- }
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- } else {
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("writeDataClass(id+\"/");
- String _name_11 = a_2.getName();
- _builder.append(_name_11, " ");
- _builder.append("\", object.");
- String _name_12 = a_2.getName();
- CharSequence _invokeGetter_3 = this.helpers.invokeGetter(_name_12, null);
- _builder.append(_invokeGetter_3, " ");
- _builder.append(", map);");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("@Override");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("protected int getPollingTimerUser(){");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("return ");
- int _pollingTimerUser = this.configExt.getPollingTimerUser(comp);
- _builder.append(_pollingTimerUser, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _xblockexpression = (_builder);
- }
- return _xblockexpression;
- }
-
- private CharSequence genMinMaxCheck(final List<Attribute> path, final ActorClass ac) {
- CharSequence _xblockexpression = null;
- {
- Attribute a = IterableExtensions.<Attribute>last(path);
- String aVarName = this.toAbsolutePath(path, "_");
- String _attrClassConfigMinValue = this.configExt.getAttrClassConfigMinValue(ac, path);
- boolean min = (!Objects.equal(_attrClassConfigMinValue, null));
- String _attrClassConfigMaxValue = this.configExt.getAttrClassConfigMaxValue(ac, path);
- boolean max = (!Objects.equal(_attrClassConfigMaxValue, null));
- CharSequence _xifexpression = null;
- boolean _or = false;
- if (min) {
- _or = true;
- } else {
- _or = (min || max);
- }
- if (_or) {
- StringConcatenation _builder = new StringConcatenation();
- {
- int _size = a.getSize();
- boolean _greaterThan = (_size > 0);
- if (_greaterThan) {
- _builder.append("for(");
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- String _typeName = this._typeHelpers.typeName(_type);
- _builder.append(_typeName, "");
- _builder.append(" e : ");
- _builder.append(aVarName, "");
- _builder.append(")");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- }
- }
- _builder.append("checkMinMax(");
- {
- int _size_1 = a.getSize();
- boolean _greaterThan_1 = (_size_1 > 0);
- if (_greaterThan_1) {
- _builder.append("e");
- } else {
- _builder.append(aVarName, "");
- }
- }
- _builder.append(", ");
- {
- if (min) {
- String _name = ac.getName();
- _builder.append(_name, "");
- _builder.append(".MIN");
- _builder.append(aVarName, "");
- } else {
- _builder.append("null");
- }
- }
- _builder.append(", ");
- {
- if (max) {
- String _name_1 = ac.getName();
- _builder.append(_name_1, "");
- _builder.append(".MAX");
- _builder.append(aVarName, "");
- } else {
- _builder.append("null");
- }
- }
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- _xifexpression = _builder;
- }
- _xblockexpression = (_xifexpression);
- }
- return _xblockexpression;
- }
-
- private HashSet<DataClass> getDynConfigDataClasses(final Iterable<ActorInstance> ais) {
- HashSet<DataClass> _hashSet = new HashSet<DataClass>();
- final HashSet<DataClass> result = _hashSet;
- final Procedure1<ActorInstance> _function = new Procedure1<ActorInstance>() {
- public void apply(final ActorInstance ai) {
- List<Attribute> _dynConfigReadAttributes = VariableServiceGen.this.configExt.getDynConfigReadAttributes(ai);
- final Procedure1<Attribute> _function = new Procedure1<Attribute>() {
- public void apply(final Attribute a) {
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- boolean _isDataClass = VariableServiceGen.this._typeHelpers.isDataClass(_type);
- if (_isDataClass) {
- RefableType _refType_1 = a.getRefType();
- DataType _type_1 = _refType_1.getType();
- result.add(((DataClass) _type_1));
- }
- }
- };
- IterableExtensions.<Attribute>forEach(_dynConfigReadAttributes, _function);
- }
- };
- IterableExtensions.<ActorInstance>forEach(ais, _function);
- return result;
- }
-
- private HashSet<DataClass> getAllDataClasses(final Iterable<DataClass> dcs) {
- HashSet<DataClass> _hashSet = new HashSet<DataClass>();
- final HashSet<DataClass> result = _hashSet;
- Iterables.<DataClass>addAll(result, dcs);
- LinkedList<DataClass> _linkedList = new LinkedList<DataClass>();
- final LinkedList<DataClass> visit = _linkedList;
- Iterables.<DataClass>addAll(visit, dcs);
- boolean _isEmpty = visit.isEmpty();
- boolean _not = (!_isEmpty);
- boolean _while = _not;
- while (_while) {
- {
- DataClass dc = visit.pop();
- List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(dc);
- final Procedure1<Attribute> _function = new Procedure1<Attribute>() {
- public void apply(final Attribute a) {
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- boolean _isDataClass = VariableServiceGen.this._typeHelpers.isDataClass(_type);
- if (_isDataClass) {
- RefableType _refType_1 = a.getRefType();
- DataType _type_1 = _refType_1.getType();
- visit.add(((DataClass) _type_1));
- }
- }
- };
- IterableExtensions.<Attribute>forEach(_allAttributes, _function);
- }
- boolean _isEmpty_1 = visit.isEmpty();
- boolean _not_1 = (!_isEmpty_1);
- _while = _not_1;
- }
- return result;
- }
-
- private HashSet<RoomModel> getRoomModels(final Collection<ActorInstance> ais) {
- HashSet<RoomModel> _hashSet = new HashSet<RoomModel>();
- final HashSet<RoomModel> models = _hashSet;
- final Procedure1<ActorInstance> _function = new Procedure1<ActorInstance>() {
- public void apply(final ActorInstance ai) {
- ActorClass _actorClass = ai.getActorClass();
- EObject _eContainer = _actorClass.eContainer();
- models.add(((RoomModel) _eContainer));
- }
- };
- IterableExtensions.<ActorInstance>forEach(ais, _function);
- return models;
- }
-
- private String toAbsolutePath(final List<Attribute> path, final String pathDelim) {
- StringConcatenation _builder = new StringConcatenation();
- {
- for(final Attribute p : path) {
- _builder.append(pathDelim, "");
- String _name = p.getName();
- _builder.append(_name, "");
- }
- }
- String _string = _builder.toString();
- return _string;
- }
-
- private CharSequence getVarName(final ActorInstance ai) {
- StringConcatenation _builder = new StringConcatenation();
- {
- String _path = ai.getPath();
- String[] _split = _path.split("/");
- Iterable<String> _drop = IterableExtensions.<String>drop(((Iterable<String>)Conversions.doWrapArray(_split)), 2);
- boolean _hasElements = false;
- for(final String p : _drop) {
- if (!_hasElements) {
- _hasElements = true;
- } else {
- _builder.appendImmediate("_", "");
- }
- _builder.append(p, "");
- }
- }
- return _builder;
- }
-
- private CharSequence genGetAttributeValues(final List<Attribute> path, final ActorInstance ai) {
- CharSequence _xblockexpression = null;
- {
- final Attribute a = IterableExtensions.<Attribute>last(path);
- CharSequence _xifexpression = null;
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- boolean _isPrimitive = this._typeHelpers.isPrimitive(_type);
- if (_isPrimitive) {
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("values.put(\"");
- String _path = ai.getPath();
- _builder.append(_path, "");
- String _absolutePath = this.toAbsolutePath(path, "/");
- _builder.append(_absolutePath, "");
- _builder.append("\", ");
- {
- int _size = a.getSize();
- boolean _greaterThan = (_size > 0);
- if (_greaterThan) {
- _builder.append("toObjectArray(");
- }
- }
- CharSequence _varName = this.getVarName(ai);
- _builder.append(_varName, "");
- _builder.append(".");
- CharSequence _invokeGetters = this.helpers.invokeGetters(path, null);
- _builder.append(_invokeGetters, "");
- {
- int _size_1 = a.getSize();
- boolean _greaterThan_1 = (_size_1 > 0);
- if (_greaterThan_1) {
- _builder.append(")");
- }
- }
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- _xifexpression = _builder;
- } else {
- CharSequence _xifexpression_1 = null;
- RefableType _refType_1 = a.getRefType();
- DataType _type_1 = _refType_1.getType();
- boolean _isDataClass = this._typeHelpers.isDataClass(_type_1);
- if (_isDataClass) {
- CharSequence _xblockexpression_1 = null;
- {
- RefableType _refType_2 = a.getRefType();
- DataType _type_2 = _refType_2.getType();
- DataClass dataClass = ((DataClass) _type_2);
- StringConcatenation _builder_1 = new StringConcatenation();
- {
- List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(dataClass);
- for(final Attribute at : _allAttributes) {
- List<Attribute> _union = this.roomExt.<Attribute>union(path, at);
- CharSequence _genGetAttributeValues = this.genGetAttributeValues(_union, ai);
- _builder_1.append(_genGetAttributeValues, "");
- _builder_1.newLineIfNotEmpty();
- }
- }
- _xblockexpression_1 = (_builder_1);
- }
- _xifexpression_1 = _xblockexpression_1;
- }
- _xifexpression = _xifexpression_1;
- }
- _xblockexpression = (_xifexpression);
- }
- return _xblockexpression;
- }
-
- private CharSequence genSetAttributeValues1(final List<Attribute> path, final ActorInstance ai) {
- CharSequence _xblockexpression = null;
- {
- Attribute a = IterableExtensions.<Attribute>last(path);
- String aVarName = this.toAbsolutePath(path, "_");
- CharSequence _xifexpression = null;
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- boolean _isPrimitive = this._typeHelpers.isPrimitive(_type);
- if (_isPrimitive) {
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("id = \"");
- String _path = ai.getPath();
- _builder.append(_path, "");
- String _absolutePath = this.toAbsolutePath(path, "/");
- _builder.append(_absolutePath, "");
- _builder.append("\";");
- _builder.newLineIfNotEmpty();
- {
- int _size = a.getSize();
- boolean _equals = (_size == 0);
- if (_equals) {
- RefableType _refType_1 = a.getRefType();
- DataType _type_1 = _refType_1.getType();
- String _typeName = this._typeHelpers.typeName(_type_1);
- String _wrapper = this.stdExt.toWrapper(_typeName);
- _builder.append(_wrapper, "");
- } else {
- RefableType _refType_2 = a.getRefType();
- DataType _type_2 = _refType_2.getType();
- String _typeName_1 = this._typeHelpers.typeName(_type_2);
- _builder.append(_typeName_1, "");
- _builder.append("[]");
- }
- }
- _builder.append(" ");
- _builder.append(aVarName, "");
- _builder.append(" = null;");
- _builder.newLineIfNotEmpty();
- _builder.append("object = values.get(id);");
- _builder.newLine();
- _builder.append("if(object != null){");
- _builder.newLine();
- _builder.append("\t");
- _builder.append(aVarName, " ");
- _builder.append(" = ensure");
- RefableType _refType_3 = a.getRefType();
- DataType _type_3 = _refType_3.getType();
- String _typeName_2 = this._typeHelpers.typeName(_type_3);
- String _firstUpper = StringExtensions.toFirstUpper(_typeName_2);
- _builder.append(_firstUpper, " ");
- {
- int _size_1 = a.getSize();
- boolean _greaterThan = (_size_1 > 0);
- if (_greaterThan) {
- _builder.append("Array");
- }
- }
- _builder.append("(object");
- {
- int _size_2 = a.getSize();
- boolean _greaterThan_1 = (_size_2 > 0);
- if (_greaterThan_1) {
- _builder.append(", ");
- int _size_3 = a.getSize();
- _builder.append(_size_3, " ");
- }
- }
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- ActorClass _actorClass = ai.getActorClass();
- CharSequence _genMinMaxCheck = this.genMinMaxCheck(path, _actorClass);
- _builder.append(_genMinMaxCheck, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("if(!");
- {
- int _size_4 = a.getSize();
- boolean _equals_1 = (_size_4 == 0);
- if (_equals_1) {
- _builder.append(aVarName, " ");
- _builder.append(".equals(");
- } else {
- _builder.append("Arrays.equals(");
- _builder.append(aVarName, " ");
- _builder.append(", ");
- }
- }
- _builder.append("(");
- {
- int _size_5 = a.getSize();
- boolean _equals_2 = (_size_5 == 0);
- if (_equals_2) {
- RefableType _refType_4 = a.getRefType();
- DataType _type_4 = _refType_4.getType();
- String _typeName_3 = this._typeHelpers.typeName(_type_4);
- String _wrapper_1 = this.stdExt.toWrapper(_typeName_3);
- _builder.append(_wrapper_1, " ");
- } else {
- RefableType _refType_5 = a.getRefType();
- DataType _type_5 = _refType_5.getType();
- String _typeName_4 = this._typeHelpers.typeName(_type_5);
- _builder.append(_typeName_4, " ");
- _builder.append("[]");
- }
- }
- _builder.append(")getDiffMap().get(id)))");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("changed = true;");
- _builder.newLine();
- _builder.append("} else");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("warning(id, \"is missing\");");
- _builder.newLine();
- _xifexpression = _builder;
- } else {
- CharSequence _xifexpression_1 = null;
- RefableType _refType_6 = a.getRefType();
- DataType _type_6 = _refType_6.getType();
- boolean _isDataClass = this._typeHelpers.isDataClass(_type_6);
- if (_isDataClass) {
- CharSequence _xblockexpression_1 = null;
- {
- RefableType _refType_7 = a.getRefType();
- DataType _type_7 = _refType_7.getType();
- DataClass dataClass = ((DataClass) _type_7);
- StringConcatenation _builder_1 = new StringConcatenation();
- {
- List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(dataClass);
- for(final Attribute at : _allAttributes) {
- List<Attribute> _union = this.roomExt.<Attribute>union(path, at);
- CharSequence _genSetAttributeValues1 = this.genSetAttributeValues1(_union, ai);
- _builder_1.append(_genSetAttributeValues1, "");
- _builder_1.newLineIfNotEmpty();
- }
- }
- _xblockexpression_1 = (_builder_1);
- }
- _xifexpression_1 = _xblockexpression_1;
- }
- _xifexpression = _xifexpression_1;
- }
- _xblockexpression = (_xifexpression);
- }
- return _xblockexpression;
- }
-
- private CharSequence genSetAttributeValues2(final List<Attribute> path, final ActorInstance ai) {
- CharSequence _xblockexpression = null;
- {
- Attribute a = IterableExtensions.<Attribute>last(path);
- String aVarName = this.toAbsolutePath(path, "_");
- CharSequence _xifexpression = null;
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- boolean _isPrimitive = this._typeHelpers.isPrimitive(_type);
- if (_isPrimitive) {
- CharSequence _xblockexpression_1 = null;
- {
- String _xifexpression_1 = null;
- int _size = path.size();
- boolean _greaterThan = (_size > 1);
- if (_greaterThan) {
- int _size_1 = path.size();
- int _minus = (_size_1 - 1);
- Iterable<Attribute> _take = IterableExtensions.<Attribute>take(path, _minus);
- CharSequence _invokeGetters = this.helpers.invokeGetters(_take, null);
- String _plus = (_invokeGetters + ".");
- _xifexpression_1 = _plus;
- } else {
- _xifexpression_1 = "";
- }
- final String getters = _xifexpression_1;
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("if(");
- _builder.append(aVarName, "");
- _builder.append(" != null){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- CharSequence _varName = this.getVarName(ai);
- _builder.append(_varName, " ");
- _builder.append(".");
- _builder.append(getters, " ");
- String _name = a.getName();
- CharSequence _invokeSetter = this.helpers.invokeSetter(_name, null, aVarName);
- _builder.append(_invokeSetter, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("getDiffMap().put(\"");
- String _path = ai.getPath();
- _builder.append(_path, " ");
- String _absolutePath = this.toAbsolutePath(path, "/");
- _builder.append(_absolutePath, " ");
- _builder.append("\", ");
- _builder.append(aVarName, " ");
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- _xblockexpression_1 = (_builder);
- }
- _xifexpression = _xblockexpression_1;
- } else {
- CharSequence _xifexpression_1 = null;
- RefableType _refType_1 = a.getRefType();
- DataType _type_1 = _refType_1.getType();
- boolean _isDataClass = this._typeHelpers.isDataClass(_type_1);
- if (_isDataClass) {
- CharSequence _xblockexpression_2 = null;
- {
- RefableType _refType_2 = a.getRefType();
- DataType _type_2 = _refType_2.getType();
- final DataClass dataClass = ((DataClass) _type_2);
- StringConcatenation _builder = new StringConcatenation();
- {
- List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(dataClass);
- for(final Attribute at : _allAttributes) {
- List<Attribute> _union = this.roomExt.<Attribute>union(path, at);
- CharSequence _genSetAttributeValues2 = this.genSetAttributeValues2(_union, ai);
- _builder.append(_genSetAttributeValues2, "");
- _builder.newLineIfNotEmpty();
- }
- }
- _xblockexpression_2 = (_builder);
- }
- _xifexpression_1 = _xblockexpression_2;
- }
- _xifexpression = _xifexpression_1;
- }
- _xblockexpression = (_xifexpression);
- }
- return _xblockexpression;
- }
-}
+/**
+ * Copyright (c) 2012 Juergen Haug
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug
+ */
+package org.eclipse.etrice.generator.java.gen;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance;
+import org.eclipse.etrice.core.genmodel.etricegen.Root;
+import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.core.room.RoomModel;
+import org.eclipse.etrice.core.room.SubSystemClass;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.generator.base.IDataConfiguration;
+import org.eclipse.etrice.generator.base.IGeneratorFileIo;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.generic.TypeHelpers;
+import org.eclipse.etrice.generator.java.gen.JavaExtensions;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.Conversions;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+
+@Singleton
+@SuppressWarnings("all")
+public class VariableServiceGen {
+ @Inject
+ private IGeneratorFileIo fileIO;
+
+ @Inject
+ @Extension
+ private JavaExtensions stdExt;
+
+ @Inject
+ @Extension
+ private RoomExtensions roomExt;
+
+ @Inject
+ private IDataConfiguration configExt;
+
+ @Inject
+ @Extension
+ private ProcedureHelpers helpers;
+
+ @Inject
+ @Extension
+ private TypeHelpers _typeHelpers;
+
+ public void doGenerate(final Root root, final SubSystemInstance ssi) {
+ SubSystemClass _subSystemClass = ssi.getSubSystemClass();
+ String _generationTargetPath = this.roomExt.getGenerationTargetPath(_subSystemClass);
+ SubSystemClass _subSystemClass_1 = ssi.getSubSystemClass();
+ String _path = this.roomExt.getPath(_subSystemClass_1);
+ final String path = (_generationTargetPath + _path);
+ SubSystemClass _subSystemClass_2 = ssi.getSubSystemClass();
+ String _generationInfoPath = this.roomExt.getGenerationInfoPath(_subSystemClass_2);
+ SubSystemClass _subSystemClass_3 = ssi.getSubSystemClass();
+ String _path_1 = this.roomExt.getPath(_subSystemClass_3);
+ final String infopath = (_generationInfoPath + _path_1);
+ SubSystemClass _subSystemClass_4 = ssi.getSubSystemClass();
+ String _name = _subSystemClass_4.getName();
+ final String file = (_name + "VariableService.java");
+ CharSequence _generate = this.generate(root, ssi);
+ this.fileIO.generateFile("generating VariableService implementation", path, infopath, file, _generate);
+ }
+
+ private CharSequence generate(final Root root, final SubSystemInstance comp) {
+ CharSequence _xblockexpression = null;
+ {
+ SubSystemClass cc = comp.getSubSystemClass();
+ HashMap<ActorInstance,List<Attribute>> _hashMap = new HashMap<ActorInstance,List<Attribute>>();
+ final HashMap<ActorInstance,List<Attribute>> aisAttrMap = _hashMap;
+ EList<ActorInstance> _allContainedInstances = comp.getAllContainedInstances();
+ final Procedure1<ActorInstance> _function = new Procedure1<ActorInstance>() {
+ public void apply(final ActorInstance ai) {
+ List<Attribute> _dynConfigReadAttributes = VariableServiceGen.this.configExt.getDynConfigReadAttributes(ai);
+ boolean _isEmpty = _dynConfigReadAttributes.isEmpty();
+ boolean _not = (!_isEmpty);
+ if (_not) {
+ List<Attribute> _dynConfigReadAttributes_1 = VariableServiceGen.this.configExt.getDynConfigReadAttributes(ai);
+ aisAttrMap.put(ai, _dynConfigReadAttributes_1);
+ }
+ }
+ };
+ IterableExtensions.<ActorInstance>forEach(_allContainedInstances, _function);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.newLine();
+ _builder.append("package ");
+ SubSystemClass _subSystemClass = comp.getSubSystemClass();
+ String _package = this.roomExt.getPackage(_subSystemClass);
+ _builder.append(_package, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("import java.util.Arrays;");
+ _builder.newLine();
+ _builder.append("import java.util.HashMap;");
+ _builder.newLine();
+ _builder.append("import java.util.Map;");
+ _builder.newLine();
+ _builder.append("import org.eclipse.etrice.runtime.java.config.AbstractVariableService;");
+ _builder.newLine();
+ String _userCode1 = this.configExt.getUserCode1(comp);
+ _builder.append(_userCode1, "");
+ _builder.newLineIfNotEmpty();
+ {
+ Set<ActorInstance> _keySet = aisAttrMap.keySet();
+ HashSet<RoomModel> _roomModels = this.getRoomModels(_keySet);
+ for(final RoomModel model : _roomModels) {
+ _builder.append("import ");
+ String _name = model.getName();
+ _builder.append(_name, "");
+ _builder.append(".*;");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("public class ");
+ String _name_1 = cc.getName();
+ String _plus = (_name_1 + "VariableService");
+ _builder.append(_plus, "");
+ _builder.append(" extends AbstractVariableService{");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("private ");
+ SubSystemClass _subSystemClass_1 = comp.getSubSystemClass();
+ String _name_2 = _subSystemClass_1.getName();
+ _builder.append(_name_2, " ");
+ _builder.append(" subSystem;");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// Actor instances");
+ _builder.newLine();
+ {
+ Set<ActorInstance> _keySet_1 = aisAttrMap.keySet();
+ for(final ActorInstance ai : _keySet_1) {
+ _builder.append("\t");
+ _builder.append("private ");
+ ActorClass _actorClass = ai.getActorClass();
+ String _name_3 = _actorClass.getName();
+ _builder.append(_name_3, " ");
+ _builder.append(" ");
+ CharSequence _varName = this.getVarName(ai);
+ _builder.append(_varName, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public ");
+ String _name_4 = cc.getName();
+ String _plus_1 = (_name_4 + "VariableService");
+ _builder.append(_plus_1, " ");
+ _builder.append("(");
+ String _name_5 = cc.getName();
+ _builder.append(_name_5, " ");
+ _builder.append(" subSystem) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("super(");
+ String _userCode2 = this.configExt.getUserCode2(comp);
+ _builder.append(_userCode2, " ");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("this.subSystem = subSystem;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("@Override");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("protected void initInstances(){");
+ _builder.newLine();
+ {
+ Set<ActorInstance> _keySet_2 = aisAttrMap.keySet();
+ for(final ActorInstance ai_1 : _keySet_2) {
+ _builder.append("\t\t");
+ CharSequence _varName_1 = this.getVarName(ai_1);
+ _builder.append(_varName_1, " ");
+ _builder.append(" = (");
+ ActorClass _actorClass_1 = ai_1.getActorClass();
+ String _name_6 = _actorClass_1.getName();
+ _builder.append(_name_6, " ");
+ _builder.append(")subSystem.getInstance(\"");
+ String _path = ai_1.getPath();
+ _builder.append(_path, " ");
+ _builder.append("\");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("@Override");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("protected void setAttributeValues(Map<String, Object> values) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("Object object;");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("String id = null;");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.newLine();
+ {
+ Set<ActorInstance> _keySet_3 = aisAttrMap.keySet();
+ for(final ActorInstance ai_2 : _keySet_3) {
+ {
+ List<Attribute> _get = aisAttrMap.get(ai_2);
+ for(final Attribute a : _get) {
+ _builder.append("\t\t");
+ _builder.append("try{");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("boolean changed = false;");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
+ List<Attribute> _union = this.roomExt.<Attribute>union(_arrayList, a);
+ CharSequence _genSetAttributeValues1 = this.genSetAttributeValues1(_union, ai_2);
+ _builder.append(_genSetAttributeValues1, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("if(changed)");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t\t");
+ _builder.append("synchronized(");
+ CharSequence _varName_2 = this.getVarName(ai_2);
+ _builder.append(_varName_2, " ");
+ _builder.append(".");
+ String _name_7 = a.getName();
+ String _plus_2 = (_name_7 + "Lock");
+ CharSequence _invokeGetter = this.helpers.invokeGetter(_plus_2, null);
+ _builder.append(_invokeGetter, " ");
+ _builder.append("){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t\t\t");
+ _builder.append("if(");
+ CharSequence _varName_3 = this.getVarName(ai_2);
+ _builder.append(_varName_3, " ");
+ _builder.append(".");
+ String _name_8 = a.getName();
+ String _plus_3 = (_name_8 + "Lock");
+ CharSequence _invokeGetter_1 = this.helpers.invokeGetter(_plus_3, null);
+ _builder.append(_invokeGetter_1, " ");
+ _builder.append(".isUpdate()){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t\t\t\t");
+ ArrayList<Attribute> _arrayList_1 = new ArrayList<Attribute>();
+ List<Attribute> _union_1 = this.roomExt.<Attribute>union(_arrayList_1, a);
+ CharSequence _genSetAttributeValues2 = this.genSetAttributeValues2(_union_1, ai_2);
+ _builder.append(_genSetAttributeValues2, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("}catch(IllegalArgumentException e){");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("error(id, e);");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("@Override");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("protected Map<String, Object> getAttributeValues(){");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("Map<String, Object> values = new HashMap<String, Object>();");
+ _builder.newLine();
+ {
+ Set<ActorInstance> _keySet_4 = aisAttrMap.keySet();
+ for(final ActorInstance ai_3 : _keySet_4) {
+ {
+ List<Attribute> _get_1 = aisAttrMap.get(ai_3);
+ for(final Attribute a_1 : _get_1) {
+ _builder.append("\t\t");
+ ArrayList<Attribute> _arrayList_2 = new ArrayList<Attribute>();
+ List<Attribute> _union_2 = this.roomExt.<Attribute>union(_arrayList_2, a_1);
+ CharSequence _genGetAttributeValues = this.genGetAttributeValues(_union_2, ai_3);
+ _builder.append(_genGetAttributeValues, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("return values;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("@Override");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public void writeDataClass(String id, Object dcObject, Map<String, Object> writeMap) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ Set<ActorInstance> _keySet_5 = aisAttrMap.keySet();
+ HashSet<DataClass> dataClasses = this.getDynConfigDataClasses(_keySet_5);
+ _builder.newLineIfNotEmpty();
+ {
+ for(final DataClass dc : dataClasses) {
+ _builder.append("\t\t");
+ _builder.append("if(dcObject.getClass().equals(");
+ String _typeName = this._typeHelpers.typeName(dc);
+ _builder.append(_typeName, " ");
+ _builder.append(".class))");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ _builder.append("writeDataClass(id, (");
+ String _typeName_1 = this._typeHelpers.typeName(dc);
+ _builder.append(_typeName_1, " ");
+ _builder.append(") dcObject, writeTasks);");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// DataClasses write operations");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ {
+ HashSet<DataClass> _allDataClasses = this.getAllDataClasses(dataClasses);
+ for(final DataClass dc_1 : _allDataClasses) {
+ _builder.append("\t");
+ _builder.append("private void writeDataClass(String id, ");
+ String _typeName_2 = this._typeHelpers.typeName(dc_1);
+ _builder.append(_typeName_2, " ");
+ _builder.append(" object, Map<String, Object> map){");
+ _builder.newLineIfNotEmpty();
+ {
+ List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(dc_1);
+ for(final Attribute a_2 : _allAttributes) {
+ {
+ RefableType _refType = a_2.getRefType();
+ DataType _type = _refType.getType();
+ boolean _isPrimitive = this._typeHelpers.isPrimitive(_type);
+ if (_isPrimitive) {
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("map.put(id+\"/");
+ String _name_9 = a_2.getName();
+ _builder.append(_name_9, " ");
+ _builder.append("\", ");
+ {
+ int _size = a_2.getSize();
+ boolean _greaterThan = (_size > 0);
+ if (_greaterThan) {
+ _builder.append("toObjectArray(");
+ }
+ }
+ _builder.append("object.");
+ String _name_10 = a_2.getName();
+ CharSequence _invokeGetter_2 = this.helpers.invokeGetter(_name_10, null);
+ _builder.append(_invokeGetter_2, " ");
+ {
+ int _size_1 = a_2.getSize();
+ boolean _greaterThan_1 = (_size_1 > 0);
+ if (_greaterThan_1) {
+ _builder.append(")");
+ }
+ }
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("writeDataClass(id+\"/");
+ String _name_11 = a_2.getName();
+ _builder.append(_name_11, " ");
+ _builder.append("\", object.");
+ String _name_12 = a_2.getName();
+ CharSequence _invokeGetter_3 = this.helpers.invokeGetter(_name_12, null);
+ _builder.append(_invokeGetter_3, " ");
+ _builder.append(", map);");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("@Override");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("protected int getPollingTimerUser(){");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("return ");
+ int _pollingTimerUser = this.configExt.getPollingTimerUser(comp);
+ _builder.append(_pollingTimerUser, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+
+ private CharSequence genMinMaxCheck(final List<Attribute> path, final ActorClass ac) {
+ CharSequence _xblockexpression = null;
+ {
+ Attribute a = IterableExtensions.<Attribute>last(path);
+ String aVarName = this.toAbsolutePath(path, "_");
+ String _attrClassConfigMinValue = this.configExt.getAttrClassConfigMinValue(ac, path);
+ boolean min = (!Objects.equal(_attrClassConfigMinValue, null));
+ String _attrClassConfigMaxValue = this.configExt.getAttrClassConfigMaxValue(ac, path);
+ boolean max = (!Objects.equal(_attrClassConfigMaxValue, null));
+ CharSequence _xifexpression = null;
+ boolean _or = false;
+ if (min) {
+ _or = true;
+ } else {
+ _or = (min || max);
+ }
+ if (_or) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ int _size = a.getSize();
+ boolean _greaterThan = (_size > 0);
+ if (_greaterThan) {
+ _builder.append("for(");
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ String _typeName = this._typeHelpers.typeName(_type);
+ _builder.append(_typeName, "");
+ _builder.append(" e : ");
+ _builder.append(aVarName, "");
+ _builder.append(")");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ }
+ }
+ _builder.append("checkMinMax(");
+ {
+ int _size_1 = a.getSize();
+ boolean _greaterThan_1 = (_size_1 > 0);
+ if (_greaterThan_1) {
+ _builder.append("e");
+ } else {
+ _builder.append(aVarName, "");
+ }
+ }
+ _builder.append(", ");
+ {
+ if (min) {
+ String _name = ac.getName();
+ _builder.append(_name, "");
+ _builder.append(".MIN");
+ _builder.append(aVarName, "");
+ } else {
+ _builder.append("null");
+ }
+ }
+ _builder.append(", ");
+ {
+ if (max) {
+ String _name_1 = ac.getName();
+ _builder.append(_name_1, "");
+ _builder.append(".MAX");
+ _builder.append(aVarName, "");
+ } else {
+ _builder.append("null");
+ }
+ }
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _xifexpression = _builder;
+ }
+ _xblockexpression = (_xifexpression);
+ }
+ return _xblockexpression;
+ }
+
+ private HashSet<DataClass> getDynConfigDataClasses(final Iterable<ActorInstance> ais) {
+ HashSet<DataClass> _hashSet = new HashSet<DataClass>();
+ final HashSet<DataClass> result = _hashSet;
+ final Procedure1<ActorInstance> _function = new Procedure1<ActorInstance>() {
+ public void apply(final ActorInstance ai) {
+ List<Attribute> _dynConfigReadAttributes = VariableServiceGen.this.configExt.getDynConfigReadAttributes(ai);
+ final Procedure1<Attribute> _function = new Procedure1<Attribute>() {
+ public void apply(final Attribute a) {
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ boolean _isDataClass = VariableServiceGen.this._typeHelpers.isDataClass(_type);
+ if (_isDataClass) {
+ RefableType _refType_1 = a.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ result.add(((DataClass) _type_1));
+ }
+ }
+ };
+ IterableExtensions.<Attribute>forEach(_dynConfigReadAttributes, _function);
+ }
+ };
+ IterableExtensions.<ActorInstance>forEach(ais, _function);
+ return result;
+ }
+
+ private HashSet<DataClass> getAllDataClasses(final Iterable<DataClass> dcs) {
+ HashSet<DataClass> _hashSet = new HashSet<DataClass>();
+ final HashSet<DataClass> result = _hashSet;
+ Iterables.<DataClass>addAll(result, dcs);
+ LinkedList<DataClass> _linkedList = new LinkedList<DataClass>();
+ final LinkedList<DataClass> visit = _linkedList;
+ Iterables.<DataClass>addAll(visit, dcs);
+ boolean _isEmpty = visit.isEmpty();
+ boolean _not = (!_isEmpty);
+ boolean _while = _not;
+ while (_while) {
+ {
+ DataClass dc = visit.pop();
+ List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(dc);
+ final Procedure1<Attribute> _function = new Procedure1<Attribute>() {
+ public void apply(final Attribute a) {
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ boolean _isDataClass = VariableServiceGen.this._typeHelpers.isDataClass(_type);
+ if (_isDataClass) {
+ RefableType _refType_1 = a.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ visit.add(((DataClass) _type_1));
+ }
+ }
+ };
+ IterableExtensions.<Attribute>forEach(_allAttributes, _function);
+ }
+ boolean _isEmpty_1 = visit.isEmpty();
+ boolean _not_1 = (!_isEmpty_1);
+ _while = _not_1;
+ }
+ return result;
+ }
+
+ private HashSet<RoomModel> getRoomModels(final Collection<ActorInstance> ais) {
+ HashSet<RoomModel> _hashSet = new HashSet<RoomModel>();
+ final HashSet<RoomModel> models = _hashSet;
+ final Procedure1<ActorInstance> _function = new Procedure1<ActorInstance>() {
+ public void apply(final ActorInstance ai) {
+ ActorClass _actorClass = ai.getActorClass();
+ EObject _eContainer = _actorClass.eContainer();
+ models.add(((RoomModel) _eContainer));
+ }
+ };
+ IterableExtensions.<ActorInstance>forEach(ais, _function);
+ return models;
+ }
+
+ private String toAbsolutePath(final List<Attribute> path, final String pathDelim) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ for(final Attribute p : path) {
+ _builder.append(pathDelim, "");
+ String _name = p.getName();
+ _builder.append(_name, "");
+ }
+ }
+ String _string = _builder.toString();
+ return _string;
+ }
+
+ private CharSequence getVarName(final ActorInstance ai) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ String _path = ai.getPath();
+ String[] _split = _path.split("/");
+ Iterable<String> _drop = IterableExtensions.<String>drop(((Iterable<String>)Conversions.doWrapArray(_split)), 2);
+ boolean _hasElements = false;
+ for(final String p : _drop) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate("_", "");
+ }
+ _builder.append(p, "");
+ }
+ }
+ return _builder;
+ }
+
+ private CharSequence genGetAttributeValues(final List<Attribute> path, final ActorInstance ai) {
+ CharSequence _xblockexpression = null;
+ {
+ final Attribute a = IterableExtensions.<Attribute>last(path);
+ CharSequence _xifexpression = null;
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ boolean _isPrimitive = this._typeHelpers.isPrimitive(_type);
+ if (_isPrimitive) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("values.put(\"");
+ String _path = ai.getPath();
+ _builder.append(_path, "");
+ String _absolutePath = this.toAbsolutePath(path, "/");
+ _builder.append(_absolutePath, "");
+ _builder.append("\", ");
+ {
+ int _size = a.getSize();
+ boolean _greaterThan = (_size > 0);
+ if (_greaterThan) {
+ _builder.append("toObjectArray(");
+ }
+ }
+ CharSequence _varName = this.getVarName(ai);
+ _builder.append(_varName, "");
+ _builder.append(".");
+ CharSequence _invokeGetters = this.helpers.invokeGetters(path, null);
+ _builder.append(_invokeGetters, "");
+ {
+ int _size_1 = a.getSize();
+ boolean _greaterThan_1 = (_size_1 > 0);
+ if (_greaterThan_1) {
+ _builder.append(")");
+ }
+ }
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _xifexpression = _builder;
+ } else {
+ CharSequence _xifexpression_1 = null;
+ RefableType _refType_1 = a.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ boolean _isDataClass = this._typeHelpers.isDataClass(_type_1);
+ if (_isDataClass) {
+ CharSequence _xblockexpression_1 = null;
+ {
+ RefableType _refType_2 = a.getRefType();
+ DataType _type_2 = _refType_2.getType();
+ DataClass dataClass = ((DataClass) _type_2);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ {
+ List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(dataClass);
+ for(final Attribute at : _allAttributes) {
+ List<Attribute> _union = this.roomExt.<Attribute>union(path, at);
+ CharSequence _genGetAttributeValues = this.genGetAttributeValues(_union, ai);
+ _builder_1.append(_genGetAttributeValues, "");
+ _builder_1.newLineIfNotEmpty();
+ }
+ }
+ _xblockexpression_1 = (_builder_1);
+ }
+ _xifexpression_1 = _xblockexpression_1;
+ }
+ _xifexpression = _xifexpression_1;
+ }
+ _xblockexpression = (_xifexpression);
+ }
+ return _xblockexpression;
+ }
+
+ private CharSequence genSetAttributeValues1(final List<Attribute> path, final ActorInstance ai) {
+ CharSequence _xblockexpression = null;
+ {
+ Attribute a = IterableExtensions.<Attribute>last(path);
+ String aVarName = this.toAbsolutePath(path, "_");
+ CharSequence _xifexpression = null;
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ boolean _isPrimitive = this._typeHelpers.isPrimitive(_type);
+ if (_isPrimitive) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("id = \"");
+ String _path = ai.getPath();
+ _builder.append(_path, "");
+ String _absolutePath = this.toAbsolutePath(path, "/");
+ _builder.append(_absolutePath, "");
+ _builder.append("\";");
+ _builder.newLineIfNotEmpty();
+ {
+ int _size = a.getSize();
+ boolean _equals = (_size == 0);
+ if (_equals) {
+ RefableType _refType_1 = a.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ String _typeName = this._typeHelpers.typeName(_type_1);
+ String _wrapper = this.stdExt.toWrapper(_typeName);
+ _builder.append(_wrapper, "");
+ } else {
+ RefableType _refType_2 = a.getRefType();
+ DataType _type_2 = _refType_2.getType();
+ String _typeName_1 = this._typeHelpers.typeName(_type_2);
+ _builder.append(_typeName_1, "");
+ _builder.append("[]");
+ }
+ }
+ _builder.append(" ");
+ _builder.append(aVarName, "");
+ _builder.append(" = null;");
+ _builder.newLineIfNotEmpty();
+ _builder.append("object = values.get(id);");
+ _builder.newLine();
+ _builder.append("if(object != null){");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append(aVarName, " ");
+ _builder.append(" = ensure");
+ RefableType _refType_3 = a.getRefType();
+ DataType _type_3 = _refType_3.getType();
+ String _typeName_2 = this._typeHelpers.typeName(_type_3);
+ String _firstUpper = StringExtensions.toFirstUpper(_typeName_2);
+ _builder.append(_firstUpper, " ");
+ {
+ int _size_1 = a.getSize();
+ boolean _greaterThan = (_size_1 > 0);
+ if (_greaterThan) {
+ _builder.append("Array");
+ }
+ }
+ _builder.append("(object");
+ {
+ int _size_2 = a.getSize();
+ boolean _greaterThan_1 = (_size_2 > 0);
+ if (_greaterThan_1) {
+ _builder.append(", ");
+ int _size_3 = a.getSize();
+ _builder.append(_size_3, " ");
+ }
+ }
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ ActorClass _actorClass = ai.getActorClass();
+ CharSequence _genMinMaxCheck = this.genMinMaxCheck(path, _actorClass);
+ _builder.append(_genMinMaxCheck, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("if(!");
+ {
+ int _size_4 = a.getSize();
+ boolean _equals_1 = (_size_4 == 0);
+ if (_equals_1) {
+ _builder.append(aVarName, " ");
+ _builder.append(".equals(");
+ } else {
+ _builder.append("Arrays.equals(");
+ _builder.append(aVarName, " ");
+ _builder.append(", ");
+ }
+ }
+ _builder.append("(");
+ {
+ int _size_5 = a.getSize();
+ boolean _equals_2 = (_size_5 == 0);
+ if (_equals_2) {
+ RefableType _refType_4 = a.getRefType();
+ DataType _type_4 = _refType_4.getType();
+ String _typeName_3 = this._typeHelpers.typeName(_type_4);
+ String _wrapper_1 = this.stdExt.toWrapper(_typeName_3);
+ _builder.append(_wrapper_1, " ");
+ } else {
+ RefableType _refType_5 = a.getRefType();
+ DataType _type_5 = _refType_5.getType();
+ String _typeName_4 = this._typeHelpers.typeName(_type_5);
+ _builder.append(_typeName_4, " ");
+ _builder.append("[]");
+ }
+ }
+ _builder.append(")getDiffMap().get(id)))");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("changed = true;");
+ _builder.newLine();
+ _builder.append("} else");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("warning(id, \"is missing\");");
+ _builder.newLine();
+ _xifexpression = _builder;
+ } else {
+ CharSequence _xifexpression_1 = null;
+ RefableType _refType_6 = a.getRefType();
+ DataType _type_6 = _refType_6.getType();
+ boolean _isDataClass = this._typeHelpers.isDataClass(_type_6);
+ if (_isDataClass) {
+ CharSequence _xblockexpression_1 = null;
+ {
+ RefableType _refType_7 = a.getRefType();
+ DataType _type_7 = _refType_7.getType();
+ DataClass dataClass = ((DataClass) _type_7);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ {
+ List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(dataClass);
+ for(final Attribute at : _allAttributes) {
+ List<Attribute> _union = this.roomExt.<Attribute>union(path, at);
+ CharSequence _genSetAttributeValues1 = this.genSetAttributeValues1(_union, ai);
+ _builder_1.append(_genSetAttributeValues1, "");
+ _builder_1.newLineIfNotEmpty();
+ }
+ }
+ _xblockexpression_1 = (_builder_1);
+ }
+ _xifexpression_1 = _xblockexpression_1;
+ }
+ _xifexpression = _xifexpression_1;
+ }
+ _xblockexpression = (_xifexpression);
+ }
+ return _xblockexpression;
+ }
+
+ private CharSequence genSetAttributeValues2(final List<Attribute> path, final ActorInstance ai) {
+ CharSequence _xblockexpression = null;
+ {
+ Attribute a = IterableExtensions.<Attribute>last(path);
+ String aVarName = this.toAbsolutePath(path, "_");
+ CharSequence _xifexpression = null;
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ boolean _isPrimitive = this._typeHelpers.isPrimitive(_type);
+ if (_isPrimitive) {
+ CharSequence _xblockexpression_1 = null;
+ {
+ String _xifexpression_1 = null;
+ int _size = path.size();
+ boolean _greaterThan = (_size > 1);
+ if (_greaterThan) {
+ int _size_1 = path.size();
+ int _minus = (_size_1 - 1);
+ Iterable<Attribute> _take = IterableExtensions.<Attribute>take(path, _minus);
+ CharSequence _invokeGetters = this.helpers.invokeGetters(_take, null);
+ String _plus = (_invokeGetters + ".");
+ _xifexpression_1 = _plus;
+ } else {
+ _xifexpression_1 = "";
+ }
+ final String getters = _xifexpression_1;
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("if(");
+ _builder.append(aVarName, "");
+ _builder.append(" != null){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ CharSequence _varName = this.getVarName(ai);
+ _builder.append(_varName, " ");
+ _builder.append(".");
+ _builder.append(getters, " ");
+ String _name = a.getName();
+ CharSequence _invokeSetter = this.helpers.invokeSetter(_name, null, aVarName);
+ _builder.append(_invokeSetter, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("getDiffMap().put(\"");
+ String _path = ai.getPath();
+ _builder.append(_path, " ");
+ String _absolutePath = this.toAbsolutePath(path, "/");
+ _builder.append(_absolutePath, " ");
+ _builder.append("\", ");
+ _builder.append(aVarName, " ");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ _xblockexpression_1 = (_builder);
+ }
+ _xifexpression = _xblockexpression_1;
+ } else {
+ CharSequence _xifexpression_1 = null;
+ RefableType _refType_1 = a.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ boolean _isDataClass = this._typeHelpers.isDataClass(_type_1);
+ if (_isDataClass) {
+ CharSequence _xblockexpression_2 = null;
+ {
+ RefableType _refType_2 = a.getRefType();
+ DataType _type_2 = _refType_2.getType();
+ final DataClass dataClass = ((DataClass) _type_2);
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(dataClass);
+ for(final Attribute at : _allAttributes) {
+ List<Attribute> _union = this.roomExt.<Attribute>union(path, at);
+ CharSequence _genSetAttributeValues2 = this.genSetAttributeValues2(_union, ai);
+ _builder.append(_genSetAttributeValues2, "");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _xblockexpression_2 = (_builder);
+ }
+ _xifexpression_1 = _xblockexpression_2;
+ }
+ _xifexpression = _xifexpression_1;
+ }
+ _xblockexpression = (_xifexpression);
+ }
+ return _xblockexpression;
+ }
+}

Back to the top