io.joynr.generator.cpp.interfaces.InterfaceCppTemplate Maven / Gradle / Ivy
package io.joynr.generator.cpp.interfaces;
import com.google.inject.Inject;
import io.joynr.generator.cpp.util.CppStdTypeUtil;
import io.joynr.generator.cpp.util.JoynrCppGeneratorExtensions;
import io.joynr.generator.cpp.util.TemplateBase;
import io.joynr.generator.templates.InterfaceTemplate;
import io.joynr.generator.templates.util.AttributeUtil;
import io.joynr.generator.templates.util.BroadcastUtil;
import io.joynr.generator.templates.util.InterfaceUtil;
import io.joynr.generator.templates.util.MethodUtil;
import io.joynr.generator.templates.util.NamingUtil;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FBroadcast;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FMethod;
@SuppressWarnings("all")
public class InterfaceCppTemplate extends InterfaceTemplate {
@Inject
@Extension
private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;
@Inject
@Extension
private CppStdTypeUtil _cppStdTypeUtil;
@Inject
@Extension
private NamingUtil _namingUtil;
@Inject
@Extension
private MethodUtil _methodUtil;
@Inject
@Extension
private AttributeUtil _attributeUtil;
@Inject
@Extension
private BroadcastUtil _broadcastUtil;
@Inject
@Extension
private TemplateBase _templateBase;
@Override
public CharSequence generate(final boolean generateVersion) {
CharSequence _xblockexpression = null;
{
InterfaceUtil.TypeSelector selector = InterfaceUtil.TypeSelector.defaultTypeSelector();
selector.transitiveTypes(true);
StringConcatenation _builder = new StringConcatenation();
final String interfaceName = this._namingUtil.joynrName(this.francaIntf);
_builder.newLineIfNotEmpty();
CharSequence _warning = this._templateBase.warning();
_builder.append(_warning);
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("#include \"");
String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, "/", generateVersion);
_builder.append(_packagePathWithJoynrPrefix);
_builder.append("/I");
_builder.append(interfaceName);
_builder.append(".h\"");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
Set _dataTypeIncludesFor = this._cppStdTypeUtil.getDataTypeIncludesFor(this.francaIntf, generateVersion);
for(final String parameterType : _dataTypeIncludesFor) {
_builder.append("#include ");
_builder.append(parameterType);
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(this.francaIntf, generateVersion);
_builder.append(_namespaceStarter);
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("const std::string& I");
_builder.append(interfaceName);
_builder.append("Base::INTERFACE_NAME()");
_builder.newLineIfNotEmpty();
_builder.append("{");
_builder.newLine();
_builder.append("\t");
_builder.append("static const std::string INTERFACE_NAME(\"");
String _fullyQualifiedName = this._joynrCppGeneratorExtensions.getFullyQualifiedName(this.francaIntf);
_builder.append(_fullyQualifiedName, "\t");
_builder.append("\");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("return INTERFACE_NAME;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("const std::int32_t I");
_builder.append(interfaceName);
_builder.append("Base::MAJOR_VERSION = ");
_builder.append(this.majorVersion);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("const std::int32_t I");
_builder.append(interfaceName);
_builder.append("Base::MINOR_VERSION = ");
_builder.append(this.minorVersion);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(this.francaIntf, generateVersion);
_builder.append(_namespaceEnder);
_builder.newLineIfNotEmpty();
_xblockexpression = _builder;
}
return _xblockexpression;
}
public HashSet getReplyMetatypes(final FInterface serviceInterface, final boolean generateVersion) {
HashSet replyMetatypes = new HashSet();
EList _methods = serviceInterface.getMethods();
for (final FMethod method : _methods) {
boolean _isEmpty = IterableExtensions.isEmpty(this._methodUtil.getOutputParameters(method));
boolean _not = (!_isEmpty);
if (_not) {
replyMetatypes.add(this._cppStdTypeUtil.getCommaSeparatedOutputParameterTypes(method, generateVersion));
}
}
EList _attributes = serviceInterface.getAttributes();
for (final FAttribute attribute : _attributes) {
boolean _isReadable = this._attributeUtil.isReadable(attribute);
if (_isReadable) {
replyMetatypes.add(this._cppStdTypeUtil.getTypeName(attribute, generateVersion));
}
}
return replyMetatypes;
}
public HashSet getBroadcastMetatypes(final FInterface serviceInterface, final boolean generateVersion) {
HashSet broadcastMetatypes = new HashSet();
EList _broadcasts = serviceInterface.getBroadcasts();
for (final FBroadcast broadcast : _broadcasts) {
boolean _isEmpty = IterableExtensions.isEmpty(this._broadcastUtil.getOutputParameters(broadcast));
boolean _not = (!_isEmpty);
if (_not) {
broadcastMetatypes.add(this._cppStdTypeUtil.getCommaSeparatedOutputParameterTypes(broadcast, generateVersion));
}
}
return broadcastMetatypes;
}
}