All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.joynr.generator.provider.InterfaceProviderTemplate Maven / Gradle / Ivy
package io.joynr.generator.provider;
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 java.util.ArrayList;
import java.util.HashMap;
import org.eclipse.emf.common.util.EList;
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.StringExtensions;
import org.franca.core.franca.FArgument;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FEnumerationType;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FMethod;
import org.franca.core.franca.FTypedElement;
@SuppressWarnings("all")
public class InterfaceProviderTemplate extends InterfaceTemplate {
@Inject
@Extension
private JoynrJavaGeneratorExtensions _joynrJavaGeneratorExtensions;
@Inject
@Extension
private JavaTypeUtil _javaTypeUtil;
@Inject
@Extension
private InterfaceUtil _interfaceUtil;
@Inject
@Extension
private MethodUtil _methodUtil;
@Inject
@Extension
private AttributeUtil _attributeUtil;
@Inject
@Extension
private NamingUtil _namingUtil;
@Inject
@Extension
private TemplateBase _templateBase;
public void init(final FInterface serviceInterface, final HashMap methodToDeferredName) {
ArrayList _arrayList = new ArrayList();
this.init(serviceInterface, methodToDeferredName, _arrayList);
}
public void init(final FInterface serviceInterface, final HashMap methodToDeferredName, final ArrayList uniqueMethodsToCreateDeferreds) {
HashMap uniqueMethodSignatureToPromiseName = new HashMap();
HashMap methodNameToCount = this._methodUtil.overloadedMethodCounts(this._interfaceUtil.getMethods(serviceInterface));
HashMap methodNameToIndex = new HashMap();
EList _methods = this._interfaceUtil.getMethods(serviceInterface);
for (final FMethod method : _methods) {
if ((IterableExtensions.isEmpty(this._methodUtil.getOutputParameters(method)) && (!this._methodUtil.hasErrorEnum(method)))) {
methodToDeferredName.put(method, "DeferredVoid");
} else {
Integer _get = methodNameToCount.get(method.getName());
boolean _equals = ((_get).intValue() == 1);
if (_equals) {
String _firstUpper = StringExtensions.toFirstUpper(method.getName());
String _plus = (_firstUpper + "Deferred");
methodToDeferredName.put(method, _plus);
uniqueMethodsToCreateDeferreds.add(method);
} else {
boolean _containsKey = methodNameToIndex.containsKey(method.getName());
boolean _not = (!_containsKey);
if (_not) {
methodNameToIndex.put(method.getName(), Integer.valueOf(0));
}
final String methodSignature = this._methodUtil.createMethodSignatureFromOutAndErrorParameters(method);
boolean _containsKey_1 = uniqueMethodSignatureToPromiseName.containsKey(methodSignature);
boolean _not_1 = (!_containsKey_1);
if (_not_1) {
Integer index = methodNameToIndex.get(method.getName());
index++;
methodNameToIndex.put(method.getName(), index);
String _firstUpper_1 = StringExtensions.toFirstUpper(method.getName());
String _plus_1 = (_firstUpper_1 + index);
uniqueMethodSignatureToPromiseName.put(methodSignature, _plus_1);
uniqueMethodsToCreateDeferreds.add(method);
}
String _get_1 = uniqueMethodSignatureToPromiseName.get(methodSignature);
String _plus_2 = (_get_1 + "Deferred");
methodToDeferredName.put(method, _plus_2);
}
}
}
}
@Override
public CharSequence generate(final boolean generateVersion) {
CharSequence _xblockexpression = null;
{
HashMap methodToDeferredName = new HashMap();
HashMap methodToErrorEnumName = this._interfaceUtil.methodToErrorEnumName(this.francaIntf);
ArrayList uniqueMethodsToCreateDeferreds = new ArrayList();
this.init(this.francaIntf, methodToDeferredName, uniqueMethodsToCreateDeferreds);
final String interfaceName = this._namingUtil.joynrName(this.francaIntf);
final String className = this._joynrJavaGeneratorExtensions.getProviderClassName(this.francaIntf);
final String packagePath = this._joynrJavaGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, ".", generateVersion);
StringConcatenation _builder = new StringConcatenation();
CharSequence _warning = this._templateBase.warning();
_builder.append(_warning);
_builder.newLineIfNotEmpty();
_builder.append("package ");
_builder.append(packagePath);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
if (((this._interfaceUtil.hasNonFireAndForgetMethods(this.francaIntf) || this._interfaceUtil.hasReadAttribute(this.francaIntf)) || this._interfaceUtil.hasWriteAttribute(this.francaIntf))) {
{
if (((this._interfaceUtil.getMethods(this.francaIntf).size() > 0) || this._interfaceUtil.hasReadAttribute(this.francaIntf))) {
_builder.append("import io.joynr.provider.Promise;");
_builder.newLine();
}
}
{
boolean _hasReadAttribute = this._interfaceUtil.hasReadAttribute(this.francaIntf);
if (_hasReadAttribute) {
_builder.append("import io.joynr.provider.Deferred;");
_builder.newLine();
}
}
{
boolean _isEmpty = uniqueMethodsToCreateDeferreds.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
_builder.append("import io.joynr.provider.AbstractDeferred;");
_builder.newLine();
}
}
{
if ((this._interfaceUtil.hasWriteAttribute(this.francaIntf) || this._interfaceUtil.hasMethodWithoutReturnValue(this.francaIntf))) {
_builder.append("import io.joynr.provider.DeferredVoid;");
_builder.newLine();
}
}
}
}
{
boolean _hasMethodWithErrorEnum = this._interfaceUtil.hasMethodWithErrorEnum(this.francaIntf);
if (_hasMethodWithErrorEnum) {
_builder.append("import joynr.exceptions.ApplicationException;");
_builder.newLine();
}
}
_builder.newLine();
_builder.append("import io.joynr.provider.JoynrInterface;");
_builder.newLine();
_builder.append("import io.joynr.JoynrVersion;");
_builder.newLine();
_builder.newLine();
{
Iterable _requiredIncludesFor = this._joynrJavaGeneratorExtensions.getRequiredIncludesFor(this.francaIntf, generateVersion);
for(final String datatype : _requiredIncludesFor) {
_builder.append("import ");
_builder.append(datatype);
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
{
if ((this._interfaceUtil.hasNotifiableAttribute(this.francaIntf) || (!this.francaIntf.getBroadcasts().isEmpty()))) {
_builder.newLine();
_builder.append("import io.joynr.provider.SubscriptionPublisherInjection;");
_builder.newLine();
_builder.newLine();
_builder.append("interface ");
_builder.append(interfaceName);
_builder.append("SubscriptionPublisherInjection extends SubscriptionPublisherInjection<");
_builder.append(interfaceName);
_builder.append("SubscriptionPublisher> { }");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
_builder.append("@JoynrInterface(provides = ");
_builder.append(interfaceName);
_builder.append(".class, provider = ");
_builder.append(className);
_builder.append(".class, name = \"");
String _fullyQualifiedName = this._joynrJavaGeneratorExtensions.getFullyQualifiedName(this.francaIntf);
_builder.append(_fullyQualifiedName);
_builder.append("\")");
_builder.newLineIfNotEmpty();
_builder.append("@JoynrVersion(major = ");
_builder.append(this.majorVersion);
_builder.append(", minor = ");
_builder.append(this.minorVersion);
_builder.append(")");
_builder.newLineIfNotEmpty();
{
if ((this._interfaceUtil.hasNotifiableAttribute(this.francaIntf) || (!this.francaIntf.getBroadcasts().isEmpty()))) {
_builder.append("public interface ");
_builder.append(className);
_builder.append(" extends ");
_builder.append(interfaceName);
_builder.append("SubscriptionPublisherInjection {");
_builder.newLineIfNotEmpty();
} else {
_builder.append("public interface ");
_builder.append(className);
_builder.append(" {");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
{
EList _attributes = this._interfaceUtil.getAttributes(this.francaIntf);
for(final FAttribute attribute : _attributes) {
_builder.append("\t");
String attributeName = this._namingUtil.joynrName(attribute);
_builder.newLineIfNotEmpty();
_builder.append("\t");
String attributeType = this._javaTypeUtil.getObjectDataTypeForPlainType(this._javaTypeUtil.getTypeName(attribute));
_builder.newLineIfNotEmpty();
_builder.newLine();
{
boolean _isReadable = this._attributeUtil.isReadable(attribute);
if (_isReadable) {
_builder.append("\t");
_builder.append("Promise> get");
String _firstUpper = StringExtensions.toFirstUpper(attributeName);
_builder.append(_firstUpper, "\t");
_builder.append("();");
_builder.newLineIfNotEmpty();
}
}
{
boolean _isWritable = this._attributeUtil.isWritable(attribute);
if (_isWritable) {
_builder.append("\t");
_builder.append("Promise set");
String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
_builder.append(_firstUpper_1, "\t");
_builder.append("(");
_builder.append(attributeType, "\t");
_builder.append(" ");
_builder.append(attributeName, "\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
}
}
}
}
{
EList _methods = this._interfaceUtil.getMethods(this.francaIntf);
for(final FMethod method : _methods) {
_builder.append("\t");
String methodName = this._namingUtil.joynrName(method);
_builder.newLineIfNotEmpty();
_builder.append("\t");
String params = this._javaTypeUtil.getTypedParameterList(this._methodUtil.getInputParameters(method));
_builder.newLineIfNotEmpty();
_builder.append("\t");
String comments = this._javaTypeUtil.getJavadocCommentsParameterListJavaRpc(method);
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* ");
_builder.append(methodName, "\t ");
_builder.newLineIfNotEmpty();
_builder.append("\t");
{
boolean _equals = comments.equals("");
boolean _not_1 = (!_equals);
if (_not_1) {
_builder.append(comments, "\t");
}
}
_builder.newLineIfNotEmpty();
{
boolean _isFireAndForget = method.isFireAndForget();
if (_isFireAndForget) {
_builder.append("\t");
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("public void ");
_builder.append(methodName, "\t");
_builder.append("(");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t");
_builder.append(" ");
_builder.append("* @return promise for asynchronous handling");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("public Promise<");
String _get = methodToDeferredName.get(method);
_builder.append(_get, "\t");
_builder.append("> ");
_builder.append(methodName, "\t");
_builder.append("(");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("\t\t");
{
boolean _equals_1 = params.equals("");
boolean _not_2 = (!_equals_1);
if (_not_2) {
_builder.append(params, "\t\t\t");
}
}
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(");");
_builder.newLine();
}
}
{
for(final FMethod method_1 : uniqueMethodsToCreateDeferreds) {
_builder.newLine();
_builder.append("\t");
_builder.append("public class ");
String _get_1 = methodToDeferredName.get(method_1);
_builder.append(_get_1, "\t");
_builder.append(" extends AbstractDeferred {");
_builder.newLineIfNotEmpty();
{
boolean _isEmpty_1 = IterableExtensions.isEmpty(this._methodUtil.getOutputParameters(method_1));
if (_isEmpty_1) {
_builder.append("\t");
_builder.append("\t");
_builder.append("public synchronized boolean resolve() {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("\t");
_builder.append("Object[] values = new Object[] { };");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("\t");
_builder.append("return super.resolve(values);");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
} else {
if (((((Object[])Conversions.unwrapArray(this._methodUtil.getOutputParameters(method_1), Object.class)).length == 1) && (this._javaTypeUtil.isArray(((FTypedElement[])Conversions.unwrapArray(this._methodUtil.getOutputParameters(method_1), FTypedElement.class))[0]) || this._javaTypeUtil.isByteBuffer((((FArgument[])Conversions.unwrapArray(this._methodUtil.getOutputParameters(method_1), FArgument.class))[0]).getType())))) {
_builder.append("\t");
_builder.append("\t");
_builder.append("public synchronized boolean resolve(");
String _commaSeperatedTypedOutputParameterList = this._javaTypeUtil.getCommaSeperatedTypedOutputParameterList(method_1);
_builder.append(_commaSeperatedTypedOutputParameterList, "\t\t");
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("\t");
_builder.append("return super.resolve((Object) ");
String _commaSeperatedUntypedOutputParameterList = this._javaTypeUtil.getCommaSeperatedUntypedOutputParameterList(method_1);
_builder.append(_commaSeperatedUntypedOutputParameterList, "\t\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
} else {
_builder.append("\t");
_builder.append("\t");
_builder.append("public synchronized boolean resolve(");
String _commaSeperatedTypedOutputParameterList_1 = this._javaTypeUtil.getCommaSeperatedTypedOutputParameterList(method_1);
_builder.append(_commaSeperatedTypedOutputParameterList_1, "\t\t");
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("\t");
_builder.append("return super.resolve(");
String _commaSeperatedUntypedOutputParameterList_1 = this._javaTypeUtil.getCommaSeperatedUntypedOutputParameterList(method_1);
_builder.append(_commaSeperatedUntypedOutputParameterList_1, "\t\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
}
{
boolean _hasErrorEnum = this._methodUtil.hasErrorEnum(method_1);
if (_hasErrorEnum) {
{
FEnumerationType _errors = method_1.getErrors();
boolean _tripleNotEquals = (_errors != null);
if (_tripleNotEquals) {
_builder.append("\t");
_builder.append("\t");
_builder.append("public synchronized boolean reject(");
_builder.append(packagePath, "\t\t");
_builder.append(".");
_builder.append(interfaceName, "\t\t");
_builder.append(".");
String _get_2 = methodToErrorEnumName.get(method_1);
_builder.append(_get_2, "\t\t");
_builder.append(" error) {");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t");
_builder.append("\t");
_builder.append("public synchronized boolean reject(");
String _buildPackagePath = this._joynrJavaGeneratorExtensions.buildPackagePath(method_1.getErrorEnum(), ".", true, generateVersion);
_builder.append(_buildPackagePath, "\t\t");
_builder.append(".");
String _joynrName = this._namingUtil.joynrName(method_1.getErrorEnum());
_builder.append(_joynrName, "\t\t");
_builder.append(" error) {");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("\t");
_builder.append("\t");
_builder.append("return super.reject(new ApplicationException(error));");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
_xblockexpression = _builder;
}
return _xblockexpression;
}
}