io.joynr.generator.interfaces.InterfaceSyncTemplate Maven / Gradle / Ivy
package io.joynr.generator.interfaces;
import com.google.common.base.Objects;
import com.google.inject.Inject;
import io.joynr.generator.util.JoynrJavaGeneratorExtensions;
import io.joynr.generator.util.TemplateBase;
import java.util.Iterator;
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.StringExtensions;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FMethod;
@SuppressWarnings("all")
public class InterfaceSyncTemplate {
@Inject
@Extension
private JoynrJavaGeneratorExtensions _joynrJavaGeneratorExtensions;
@Inject
@Extension
private TemplateBase _templateBase;
public CharSequence generate(final FInterface serviceInterface) {
CharSequence _xblockexpression = null;
{
final String interfaceName = this._joynrJavaGeneratorExtensions.joynrName(serviceInterface);
final String syncClassName = (interfaceName + "Sync");
final String packagePath = this._joynrJavaGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, ".");
StringConcatenation _builder = new StringConcatenation();
CharSequence _warning = this._templateBase.warning();
_builder.append(_warning, "");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.newLine();
_builder.append("package ");
_builder.append(packagePath, "");
_builder.append("; ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.newLine();
_builder.append("import java.util.List;");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("import com.fasterxml.jackson.core.type.TypeReference;");
_builder.newLine();
_builder.newLine();
_builder.append("import io.joynr.dispatcher.rpc.JoynrSyncInterface;");
_builder.newLine();
_builder.append("import io.joynr.dispatcher.rpc.annotation.JoynrRpcReturn;\t\t");
_builder.newLine();
_builder.append("import io.joynr.dispatcher.rpc.annotation.JoynrRpcParam;");
_builder.newLine();
_builder.newLine();
_builder.append("import io.joynr.exceptions.JoynrArbitrationException;");
_builder.newLine();
_builder.newLine();
{
Iterable _requiredIncludesFor = this._joynrJavaGeneratorExtensions.getRequiredIncludesFor(serviceInterface);
for(final String datatype : _requiredIncludesFor) {
_builder.append("import ");
_builder.append(datatype, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.append("//TODO: Only include the necessary imports in the xtend template. This needs to be checked depending on the fibex. ");
_builder.newLine();
_builder.append("@SuppressWarnings(\"unused\")");
_builder.newLine();
_builder.newLine();
_builder.append("public interface ");
_builder.append(syncClassName, "");
_builder.append(" extends ");
_builder.append(interfaceName, "");
_builder.append(", JoynrSyncInterface {");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
EList _attributes = this._joynrJavaGeneratorExtensions.getAttributes(serviceInterface);
for(final FAttribute attribute : _attributes) {
String attributeName = this._joynrJavaGeneratorExtensions.joynrName(attribute);
_builder.newLineIfNotEmpty();
String _mappedDatatypeOrList = this._joynrJavaGeneratorExtensions.getMappedDatatypeOrList(attribute);
String attributeType = this._joynrJavaGeneratorExtensions.getObjectDataTypeForPlainType(_mappedDatatypeOrList);
_builder.append(" ");
_builder.newLineIfNotEmpty();
String _firstUpper = StringExtensions.toFirstUpper(attributeName);
String getAttribute = ("get" + _firstUpper);
_builder.newLineIfNotEmpty();
String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
String setAttribute = ("set" + _firstUpper_1);
_builder.newLineIfNotEmpty();
_builder.newLine();
{
boolean _isReadable = this._joynrJavaGeneratorExtensions.isReadable(attribute);
if (_isReadable) {
_builder.append("\t");
_builder.append("@JoynrRpcReturn(deserialisationType = ");
String _tokenTypeForArrayType = this._joynrJavaGeneratorExtensions.getTokenTypeForArrayType(attributeType);
_builder.append(_tokenTypeForArrayType, " ");
_builder.append("Token.class)");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("public ");
_builder.append(attributeType, " ");
_builder.append(" ");
_builder.append(getAttribute, " ");
_builder.append("() throws JoynrArbitrationException;");
_builder.newLineIfNotEmpty();
}
}
{
boolean _isWritable = this._joynrJavaGeneratorExtensions.isWritable(attribute);
if (_isWritable) {
_builder.append("\t");
_builder.append("void ");
_builder.append(setAttribute, " ");
_builder.append("(@JoynrRpcParam(value=\"");
_builder.append(attributeName, " ");
_builder.append("\", deserialisationType = ");
String _tokenTypeForArrayType_1 = this._joynrJavaGeneratorExtensions.getTokenTypeForArrayType(attributeType);
_builder.append(_tokenTypeForArrayType_1, " ");
_builder.append("Token.class) ");
_builder.append(attributeType, " ");
_builder.append(" ");
_builder.append(attributeName, " ");
_builder.append(") throws JoynrArbitrationException;\t\t");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.newLine();
_builder.newLine();
{
EList _methods = this._joynrJavaGeneratorExtensions.getMethods(serviceInterface);
for(final FMethod method : _methods) {
String methodName = this._joynrJavaGeneratorExtensions.joynrName(method);
_builder.newLineIfNotEmpty();
String params = this._joynrJavaGeneratorExtensions.getTypedParameterListJavaRpc(method);
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("/*");
_builder.newLine();
_builder.append("\t");
_builder.append("* ");
_builder.append(methodName, " ");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("*/");
_builder.newLine();
{
Iterable _mappedOutputParameter = this._joynrJavaGeneratorExtensions.getMappedOutputParameter(method);
Iterator _iterator = _mappedOutputParameter.iterator();
String _next = _iterator.next();
boolean _equals = Objects.equal(_next, "void");
if (_equals) {
_builder.append("\t");
_builder.append("public void ");
_builder.append(methodName, " ");
_builder.append("(");
_builder.append(params, " ");
_builder.append(") throws JoynrArbitrationException;");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t");
_builder.append("@JoynrRpcReturn(deserialisationType = ");
Iterable _mappedOutputParameter_1 = this._joynrJavaGeneratorExtensions.getMappedOutputParameter(method);
Iterator _iterator_1 = _mappedOutputParameter_1.iterator();
String _next_1 = _iterator_1.next();
String _tokenTypeForArrayType_2 = this._joynrJavaGeneratorExtensions.getTokenTypeForArrayType(_next_1);
_builder.append(_tokenTypeForArrayType_2, " ");
_builder.append("Token.class)");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("public ");
Iterable _mappedOutputParameter_2 = this._joynrJavaGeneratorExtensions.getMappedOutputParameter(method);
Iterator _iterator_2 = _mappedOutputParameter_2.iterator();
String _next_2 = _iterator_2.next();
String _objectDataTypeForPlainType = this._joynrJavaGeneratorExtensions.getObjectDataTypeForPlainType(_next_2);
_builder.append(_objectDataTypeForPlainType, " ");
_builder.append(" ");
_builder.append(methodName, " ");
_builder.append("(");
_builder.append(params, " ");
_builder.append(") throws JoynrArbitrationException;");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.append("}");
_builder.newLine();
_builder.newLine();
_xblockexpression = (_builder);
}
return _xblockexpression;
}
}