
io.joynr.generator.cpp.util.JoynrCppGeneratorExtensions Maven / Gradle / Ivy
package io.joynr.generator.cpp.util;
import com.google.common.base.Objects;
import com.google.common.collect.Iterators;
import com.google.common.collect.UnmodifiableIterator;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.joynr.generator.util.JoynrGeneratorExtensions;
import java.io.File;
import java.util.HashSet;
import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.franca.core.franca.FAnnotation;
import org.franca.core.franca.FAnnotationBlock;
import org.franca.core.franca.FAnnotationType;
import org.franca.core.franca.FBasicTypeId;
import org.franca.core.franca.FBroadcast;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FModelElement;
import org.franca.core.franca.FType;
import org.franca.core.franca.FTypeRef;
import org.franca.core.franca.FTypedElement;
@SuppressWarnings("all")
public class JoynrCppGeneratorExtensions extends JoynrGeneratorExtensions {
@Inject
@Named("generationId")
private String dllExportName;
public String getNamespaceStarter(final FInterface interfaceType) {
UnmodifiableIterator _packageNames = this.getPackageNames(interfaceType);
return this.getNamespaceStarter(_packageNames);
}
public String getNamespaceStarter(final FType datatype) {
return this.getNamespaceStarter(datatype, false);
}
public String[] getNamespaces(final FType datatype, final boolean includeTypeCollection) {
String packagePath = this.getPackagePathWithoutJoynrPrefix(datatype, ".");
boolean _and = false;
if (!includeTypeCollection) {
_and = false;
} else {
boolean _isPartOfTypeCollection = this.isPartOfTypeCollection(datatype);
_and = _isPartOfTypeCollection;
}
if (_and) {
String _packagePath = packagePath;
String _typeCollectionName = this.getTypeCollectionName(datatype);
String _plus = ("." + _typeCollectionName);
packagePath = (_packagePath + _plus);
}
return packagePath.split("\\.");
}
public String getNamespaceStarter(final FType datatype, final boolean includeTypeCollection) {
String[] _namespaces = this.getNamespaces(datatype, includeTypeCollection);
UnmodifiableIterator _forArray = Iterators.forArray(_namespaces);
return this.getNamespaceStarter(_forArray);
}
public String getNamespaceEnder(final FInterface interfaceType) {
UnmodifiableIterator _packageNames = this.getPackageNames(interfaceType);
return this.getNamespaceEnder(_packageNames);
}
public String getNamespaceEnder(final FType datatype, final boolean includeTypeCollection) {
String[] _namespaces = this.getNamespaces(datatype, includeTypeCollection);
UnmodifiableIterator _forArray = Iterators.forArray(_namespaces);
return this.getNamespaceEnder(_forArray);
}
public String getNamespaceEnder(final FType datatype) {
UnmodifiableIterator _packageNames = this.getPackageNames(datatype);
return this.getNamespaceEnder(_packageNames);
}
private String getNamespaceStarter(final Iterator packageList) {
return this.getNamespaceStarterFromPackageList(packageList);
}
public String getNamespaceStarterFromPackageList(final Iterator packageList) {
StringBuilder sb = new StringBuilder();
String _joynrGenerationPrefix = this.getJoynrGenerationPrefix();
String _plus = ("namespace " + _joynrGenerationPrefix);
String _plus_1 = (_plus + " { ");
sb.append(_plus_1);
while (packageList.hasNext()) {
String _next = packageList.next();
String _plus_2 = ("namespace " + _next);
String _plus_3 = (_plus_2 + " { ");
sb.append(_plus_3);
}
return sb.toString();
}
private String getNamespaceEnder(final Iterator packageList) {
return this.getNameSpaceEnderFromPackageList(packageList);
}
public String getNameSpaceEnderFromPackageList(final Iterator packageList) {
StringBuilder sb = new StringBuilder();
String _joynrGenerationPrefix = this.getJoynrGenerationPrefix();
String _plus = ("} /* namespace " + _joynrGenerationPrefix);
String _plus_1 = (_plus + " */ ");
sb.append(_plus_1);
while (packageList.hasNext()) {
String _next = packageList.next();
String _plus_2 = ("} /* namespace " + _next);
String _plus_3 = (_plus_2 + " */ ");
sb.insert(0, _plus_3);
}
return sb.toString();
}
public String buildPackagePath(final FType datatype, final String separator) {
return this.buildPackagePath(datatype, separator, false);
}
public String buildPackagePath(final FType datatype, final String separator, final boolean includeTypeCollection) {
boolean _equals = Objects.equal(datatype, null);
if (_equals) {
return "";
}
String packagepath = "";
try {
String _packagePathWithJoynrPrefix = this.getPackagePathWithJoynrPrefix(datatype, separator);
packagepath = _packagePathWithJoynrPrefix;
} catch (final Throwable _t) {
if (_t instanceof IllegalStateException) {
final IllegalStateException e = (IllegalStateException)_t;
} else {
throw Exceptions.sneakyThrow(_t);
}
}
boolean _notEquals = (!Objects.equal(packagepath, ""));
if (_notEquals) {
packagepath = (packagepath + separator);
}
boolean _and = false;
if (!includeTypeCollection) {
_and = false;
} else {
boolean _isPartOfTypeCollection = this.isPartOfTypeCollection(datatype);
_and = _isPartOfTypeCollection;
}
if (_and) {
String _packagepath = packagepath;
String _typeCollectionName = this.getTypeCollectionName(datatype);
String _plus = (_typeCollectionName + separator);
packagepath = (_packagepath + _plus);
}
return packagepath;
}
public CharSequence appendDoxygenSummaryAndWriteSeeAndDescription(final FModelElement element, final String prefix) {
StringConcatenation _builder = new StringConcatenation();
{
FAnnotationBlock _comment = element.getComment();
boolean _notEquals = (!Objects.equal(_comment, null));
if (_notEquals) {
{
FAnnotationBlock _comment_1 = element.getComment();
EList _elements = _comment_1.getElements();
for(final FAnnotation comment : _elements) {
{
FAnnotationType _type = comment.getType();
boolean _equals = Objects.equal(_type, FAnnotationType.DESCRIPTION);
if (_equals) {
_builder.append(prefix, "");
_builder.append(" @brief ");
String _comment_2 = comment.getComment();
String _replaceAll = _comment_2.replaceAll("\\s+", " ");
String _replaceAll_1 = _replaceAll.replaceAll("\n", ("\n" + prefix));
_builder.append(_replaceAll_1, "");
_builder.newLineIfNotEmpty();
}
}
}
}
{
FAnnotationBlock _comment_3 = element.getComment();
EList _elements_1 = _comment_3.getElements();
for(final FAnnotation comment_1 : _elements_1) {
{
FAnnotationType _type_1 = comment_1.getType();
boolean _equals_1 = Objects.equal(_type_1, FAnnotationType.SEE);
if (_equals_1) {
_builder.append(prefix, "");
_builder.append(" @see ");
String _comment_4 = comment_1.getComment();
String _replaceAll_2 = _comment_4.replaceAll("\\s+", " ");
String _replaceAll_3 = _replaceAll_2.replaceAll("\n", ("\n" + prefix));
_builder.append(_replaceAll_3, "");
_builder.newLineIfNotEmpty();
}
}
{
FAnnotationType _type_2 = comment_1.getType();
boolean _equals_2 = Objects.equal(_type_2, FAnnotationType.DETAILS);
if (_equals_2) {
_builder.append(prefix, "");
_builder.newLineIfNotEmpty();
_builder.append(prefix, "");
_builder.append(" ");
String _comment_5 = comment_1.getComment();
String _replaceAll_4 = _comment_5.replaceAll("\\s+", " ");
String _replaceAll_5 = _replaceAll_4.replaceAll("\n", ("\n" + prefix));
_builder.append(_replaceAll_5, "");
_builder.newLineIfNotEmpty();
}
}
}
}
}
}
return _builder;
}
public CharSequence appendDoxygenComment(final FModelElement element, final String prefix) {
StringConcatenation _builder = new StringConcatenation();
{
FAnnotationBlock _comment = element.getComment();
boolean _notEquals = (!Objects.equal(_comment, null));
if (_notEquals) {
{
FAnnotationBlock _comment_1 = element.getComment();
EList _elements = _comment_1.getElements();
for(final FAnnotation comment : _elements) {
{
FAnnotationType _type = comment.getType();
boolean _equals = Objects.equal(_type, FAnnotationType.DESCRIPTION);
if (_equals) {
String _comment_2 = comment.getComment();
String _replaceAll = _comment_2.replaceAll("\\s+", " ");
String _replaceAll_1 = _replaceAll.replaceAll("\n", ("\n" + prefix));
_builder.append(_replaceAll_1, "");
_builder.newLineIfNotEmpty();
}
}
}
}
}
}
return _builder;
}
public CharSequence appendDoxygenParameter(final FModelElement element, final String prefix) {
StringConcatenation _builder = new StringConcatenation();
{
FAnnotationBlock _comment = element.getComment();
boolean _notEquals = (!Objects.equal(_comment, null));
if (_notEquals) {
{
FAnnotationBlock _comment_1 = element.getComment();
EList _elements = _comment_1.getElements();
for(final FAnnotation comment : _elements) {
{
FAnnotationType _type = comment.getType();
boolean _equals = Objects.equal(_type, FAnnotationType.DESCRIPTION);
if (_equals) {
_builder.append(prefix, "");
_builder.append(" @param ");
String _joynrName = this.joynrName(element);
_builder.append(_joynrName, "");
_builder.append(" ");
String _comment_2 = comment.getComment();
String _replaceAll = _comment_2.replaceAll("\\s+", " ");
String _replaceAll_1 = _replaceAll.replaceAll("\n", ("\n" + prefix));
_builder.append(_replaceAll_1, "");
_builder.newLineIfNotEmpty();
}
}
}
}
}
}
return _builder;
}
public String getOneLineWarning() {
return "/* Generated Code */ ";
}
public String getEnumContainer(final FType enumeration) {
String packagepath = this.buildPackagePath(enumeration, "::");
String _joynrNameQt = this.joynrNameQt(enumeration);
return (packagepath + _joynrNameQt);
}
public String getEnumContainer(final FTypeRef enumeration) {
FType _derived = enumeration.getDerived();
return this.getEnumContainer(_derived);
}
public String getNestedEnumName() {
return "Enum";
}
public String getJoynrTypeName(final FTypedElement element) {
String _xblockexpression = null;
{
final FTypeRef datatypeRef = element.getType();
final FType datatype = datatypeRef.getDerived();
final FBasicTypeId predefined = datatypeRef.getPredefined();
String _switchResult = null;
boolean _matched = false;
if (!_matched) {
boolean _isArray = this.isArray(element);
if (_isArray) {
_matched=true;
_switchResult = "List";
}
}
if (!_matched) {
boolean _isEnum = this.isEnum(datatypeRef);
if (_isEnum) {
_matched=true;
String _packagePathWithJoynrPrefix = this.getPackagePathWithJoynrPrefix(datatype, ".");
String _plus = (_packagePathWithJoynrPrefix +
".");
String _joynrName = this.joynrName(datatype);
_switchResult = (_plus + _joynrName);
}
}
if (!_matched) {
boolean _isString = this.isString(predefined);
if (_isString) {
_matched=true;
_switchResult = "String";
}
}
if (!_matched) {
boolean _isInt = this.isInt(predefined);
if (_isInt) {
_matched=true;
_switchResult = "Integer";
}
}
if (!_matched) {
boolean _isLong = this.isLong(predefined);
if (_isLong) {
_matched=true;
_switchResult = "Long";
}
}
if (!_matched) {
boolean _isDouble = this.isDouble(predefined);
if (_isDouble) {
_matched=true;
_switchResult = "Double";
}
}
if (!_matched) {
boolean _isFloat = this.isFloat(predefined);
if (_isFloat) {
_matched=true;
_switchResult = "Double";
}
}
if (!_matched) {
boolean _isBool = this.isBool(predefined);
if (_isBool) {
_matched=true;
_switchResult = "Boolean";
}
}
if (!_matched) {
boolean _isByte = this.isByte(predefined);
if (_isByte) {
_matched=true;
_switchResult = "Byte";
}
}
if (!_matched) {
boolean _notEquals = (!Objects.equal(datatype, null));
if (_notEquals) {
_matched=true;
String _packagePathWithJoynrPrefix_1 = this.getPackagePathWithJoynrPrefix(datatype, ".");
String _plus_1 = (_packagePathWithJoynrPrefix_1 +
".");
String _joynrName_1 = this.joynrName(datatype);
_switchResult = (_plus_1 + _joynrName_1);
}
}
if (!_matched) {
String _name = predefined.getName();
String _plus_2 = ("Unhandled primitive type: " + _name);
throw new RuntimeException(_plus_2);
}
_xblockexpression = _switchResult;
}
return _xblockexpression;
}
public String getDllExportMacro() {
boolean _isEmpty = this.dllExportName.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
String _upperCase = this.dllExportName.toUpperCase();
return (_upperCase + "_EXPORT ");
}
return "";
}
public String getDllExportIncludeStatement() {
boolean _isEmpty = this.dllExportName.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
String _joynrGenerationPrefix = this.getJoynrGenerationPrefix();
String _plus = ("#include \"" + _joynrGenerationPrefix);
String _plus_1 = (_plus + "/");
String _plus_2 = (_plus_1 + this.dllExportName);
return (_plus_2 + "Export.h\"");
}
return "";
}
public String joynrNameQt(final FType type) {
String _joynrName = this.joynrName(type);
return ("Qt" + _joynrName);
}
public String joynrNameStd(final FType type) {
return this.joynrName(type);
}
public Iterable getAllPrimitiveTypes(final FInterface serviceInterface) {
HashSet
© 2015 - 2025 Weber Informatics LLC | Privacy Policy