io.joynr.generator.interfaces.InterfaceStatelessAsyncTemplate Maven / Gradle / Ivy
The newest version!
package io.joynr.generator.interfaces;
import com.google.inject.Inject;
import io.joynr.generator.templates.InterfaceTemplate;
import io.joynr.generator.templates.util.AttributeUtil;
import io.joynr.generator.templates.util.InterfaceUtil;
import io.joynr.generator.templates.util.MethodUtil;
import io.joynr.generator.templates.util.NamingUtil;
import io.joynr.generator.util.JavaTypeUtil;
import io.joynr.generator.util.JoynrJavaGeneratorExtensions;
import io.joynr.generator.util.TemplateBase;
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.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FMethod;
@SuppressWarnings("all")
public class InterfaceStatelessAsyncTemplate extends InterfaceTemplate {
@Inject
@Extension
private JoynrJavaGeneratorExtensions _joynrJavaGeneratorExtensions;
@Inject
@Extension
private JavaTypeUtil _javaTypeUtil;
@Inject
@Extension
private MethodUtil _methodUtil;
@Inject
@Extension
private InterfaceUtil _interfaceUtil;
@Inject
@Extension
private NamingUtil _namingUtil;
@Inject
@Extension
private TemplateBase _templateBase;
@Inject
@Extension
private AttributeUtil _attributeUtil;
@Override
public CharSequence generate(final boolean generateVersion) {
CharSequence _xblockexpression = null;
{
final String interfaceName = this._namingUtil.joynrName(this.francaIntf);
final String statelessAsyncClassName = (interfaceName + "StatelessAsync");
final String packagePath = this._joynrJavaGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, ".", generateVersion);
StringConcatenation _builder = new StringConcatenation();
CharSequence _warning = this._templateBase.warning();
_builder.append(_warning);
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("package ");
_builder.append(packagePath);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import io.joynr.StatelessAsync;");
_builder.newLine();
_builder.append("import io.joynr.dispatcher.rpc.annotation.StatelessCallbackCorrelation;");
_builder.newLine();
_builder.append("import io.joynr.proxy.MessageIdCallback;");
_builder.newLine();
_builder.append("import io.joynr.UsedBy;");
_builder.newLine();
_builder.newLine();
{
Iterable _requiredStatelessAsyncIncludesFor = this._joynrJavaGeneratorExtensions.getRequiredStatelessAsyncIncludesFor(this.francaIntf, generateVersion);
for(final String datatype : _requiredStatelessAsyncIncludesFor) {
_builder.append("import ");
_builder.append(datatype);
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
_builder.append("@StatelessAsync");
_builder.newLine();
_builder.append("@UsedBy(");
String _proxyClassName = this._joynrJavaGeneratorExtensions.getProxyClassName(this.francaIntf);
_builder.append(_proxyClassName);
_builder.append(".class)");
_builder.newLineIfNotEmpty();
_builder.append("public interface ");
_builder.append(statelessAsyncClassName);
_builder.append(" extends ");
_builder.append(interfaceName);
{
boolean _hasFireAndForgetMethods = this._interfaceUtil.hasFireAndForgetMethods(this.francaIntf);
if (_hasFireAndForgetMethods) {
_builder.append(", ");
_builder.append(interfaceName);
_builder.append("FireAndForget");
}
}
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
EList _attributes = this._interfaceUtil.getAttributes(this.francaIntf);
boolean _hasElements = false;
for(final FAttribute attribute : _attributes) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate("\n", "");
}
String attributeName = this._namingUtil.joynrName(attribute);
_builder.newLineIfNotEmpty();
String attributeType = this._javaTypeUtil.getObjectDataTypeForPlainType(this._javaTypeUtil.getTypeName(attribute));
_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();
{
boolean _isReadable = this._attributeUtil.isReadable(attribute);
if (_isReadable) {
_builder.append("\t");
_builder.append("/*");
_builder.newLine();
_builder.append("\t");
_builder.append("* ");
_builder.append(attributeName, "\t");
_builder.append(" getter");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("@StatelessCallbackCorrelation(\"");
int _hashCode = getAttribute.hashCode();
_builder.append(_hashCode, "\t");
_builder.append("\")");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("void ");
_builder.append(getAttribute, "\t");
_builder.append("(MessageIdCallback messageIdCallback);");
_builder.newLineIfNotEmpty();
}
}
{
boolean _isWritable = this._attributeUtil.isWritable(attribute);
if (_isWritable) {
_builder.append("\t");
_builder.append("/*");
_builder.newLine();
_builder.append("\t");
_builder.append("* ");
_builder.append(attributeName, "\t");
_builder.append(" setter");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("@StatelessCallbackCorrelation(\"");
int _hashCode_1 = setAttribute.hashCode();
_builder.append(_hashCode_1, "\t");
_builder.append("\")");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("void ");
_builder.append(setAttribute, "\t");
_builder.append("(");
_builder.append(attributeType, "\t");
_builder.append(" ");
_builder.append(attributeName, "\t");
_builder.append(", MessageIdCallback messageIdCallback);");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.newLine();
{
final Function1 _function = new Function1() {
@Override
public Boolean apply(final FMethod it) {
boolean _isFireAndForget = it.isFireAndForget();
return Boolean.valueOf((!_isFireAndForget));
}
};
Iterable _filter = IterableExtensions.filter(this._interfaceUtil.getMethods(this.francaIntf), _function);
boolean _hasElements_1 = false;
for(final FMethod method : _filter) {
if (!_hasElements_1) {
_hasElements_1 = true;
} else {
_builder.appendImmediate("\n", "");
}
String methodName = this._namingUtil.joynrName(method);
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("/*");
_builder.newLine();
_builder.append("\t");
_builder.append("* ");
_builder.append(methodName, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("@StatelessCallbackCorrelation(\"");
int _hashCode_2 = this._methodUtil.createMethodSignatureFromOutParameters(method).hashCode();
_builder.append(_hashCode_2, "\t");
_builder.append("\")");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("void ");
_builder.append(methodName, "\t");
_builder.append("(");
_builder.newLineIfNotEmpty();
{
int _size = IterableExtensions.size(this._methodUtil.getInputParameters(method));
boolean _greaterThan = (_size > 0);
if (_greaterThan) {
_builder.append("\t\t\t");
String _typedParameterList = this._javaTypeUtil.getTypedParameterList(this._methodUtil.getInputParameters(method));
_builder.append(_typedParameterList, "\t\t\t");
_builder.append(",");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t\t\t");
_builder.append("MessageIdCallback messageIdCallback");
_builder.newLine();
_builder.append("\t");
_builder.append(");");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
_xblockexpression = _builder;
}
return _xblockexpression;
}
}