All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.joynr.generator.interfaces.InterfaceSubscriptionTemplate Maven / Gradle / Ivy

There is a newer version: 0.9.3
Show newest version
package io.joynr.generator.interfaces;

import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.inject.Inject;
import io.joynr.generator.util.InterfaceTemplate;
import io.joynr.generator.util.JoynrJavaGeneratorExtensions;
import io.joynr.generator.util.TemplateBase;
import java.util.Collection;
import java.util.HashSet;
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;

@SuppressWarnings("all")
public class InterfaceSubscriptionTemplate implements InterfaceTemplate {
  @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 subscriptionClassName = (interfaceName + "SubscriptionInterface");
      final String packagePath = this._joynrJavaGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, ".");
      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();
      {
        boolean _needsListImport = this._joynrJavaGeneratorExtensions.needsListImport(serviceInterface, false, true);
        if (_needsListImport) {
          _builder.append("import java.util.List;");
          _builder.newLine();
          _builder.newLine();
        }
      }
      _builder.append("import io.joynr.dispatcher.rpc.JoynrSubscriptionInterface;");
      _builder.newLine();
      _builder.newLine();
      {
        EList _attributes = this._joynrJavaGeneratorExtensions.getAttributes(serviceInterface);
        int _size = _attributes.size();
        boolean _greaterThan = (_size > 0);
        if (_greaterThan) {
          _builder.append("import com.fasterxml.jackson.core.type.TypeReference;");
          _builder.newLine();
          {
            boolean _hasReadAttribute = this._joynrJavaGeneratorExtensions.hasReadAttribute(serviceInterface);
            if (_hasReadAttribute) {
              _builder.append("import io.joynr.dispatcher.rpc.annotation.JoynrRpcSubscription;");
              _builder.newLine();
              _builder.append("import io.joynr.pubsub.subscription.AttributeSubscriptionListener;");
              _builder.newLine();
              _builder.append("import io.joynr.pubsub.SubscriptionQos;");
              _builder.newLine();
            }
          }
        }
      }
      _builder.newLine();
      {
        Iterable _requiredIncludesFor = this._joynrJavaGeneratorExtensions.getRequiredIncludesFor(serviceInterface, false, true, false, false);
        for(final String datatype : _requiredIncludesFor) {
          _builder.append("import ");
          _builder.append(datatype, "");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.newLine();
      _builder.append("public interface ");
      _builder.append(subscriptionClassName, "");
      _builder.append(" extends JoynrSubscriptionInterface, ");
      _builder.append(interfaceName, "");
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      EList _attributes_1 = this._joynrJavaGeneratorExtensions.getAttributes(serviceInterface);
      final Function _function = new Function() {
        public String apply(final FAttribute attribute) {
          return InterfaceSubscriptionTemplate.this._joynrJavaGeneratorExtensions.getMappedDatatypeOrList(attribute);
        }
      };
      Collection _transform = Collections2.transform(_attributes_1, _function);
      final HashSet attrTypeset = new HashSet(_transform);
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      {
        for(final String attributeType : attrTypeset) {
          _builder.append("\t");
          _builder.append("public static class ");
          String _tokenTypeForArrayType = this._joynrJavaGeneratorExtensions.getTokenTypeForArrayType(attributeType);
          _builder.append(_tokenTypeForArrayType, "\t");
          _builder.append("Reference extends TypeReference<");
          _builder.append(attributeType, "\t");
          _builder.append("> {}");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.newLine();
      {
        EList _attributes_2 = this._joynrJavaGeneratorExtensions.getAttributes(serviceInterface);
        for(final FAttribute attribute : _attributes_2) {
          String attributeName = this._joynrJavaGeneratorExtensions.joynrName(attribute);
          _builder.newLineIfNotEmpty();
          String _mappedDatatypeOrList = this._joynrJavaGeneratorExtensions.getMappedDatatypeOrList(attribute);
          String attributeType_1 = this._joynrJavaGeneratorExtensions.getObjectDataTypeForPlainType(_mappedDatatypeOrList);
          _builder.append(" ");
          _builder.newLineIfNotEmpty();
          {
            boolean _isReadable = this._joynrJavaGeneratorExtensions.isReadable(attribute);
            if (_isReadable) {
              _builder.newLine();
              _builder.append("\t");
              _builder.append("@JoynrRpcSubscription(attributeName = \"");
              _builder.append(attributeName, "\t");
              _builder.append("\", attributeType = ");
              String _tokenTypeForArrayType_1 = this._joynrJavaGeneratorExtensions.getTokenTypeForArrayType(attributeType_1);
              _builder.append(_tokenTypeForArrayType_1, "\t");
              _builder.append("Reference.class)");
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              _builder.append("public String subscribeTo");
              String _firstUpper = StringExtensions.toFirstUpper(attributeName);
              _builder.append(_firstUpper, "\t");
              _builder.append("(AttributeSubscriptionListener<");
              _builder.append(attributeType_1, "\t");
              _builder.append("> listener, SubscriptionQos subscriptionQos);");
              _builder.newLineIfNotEmpty();
              _builder.newLine();
              _builder.append("\t");
              _builder.append("@JoynrRpcSubscription(attributeName = \"");
              _builder.append(attributeName, "\t");
              _builder.append("\", attributeType = ");
              String _tokenTypeForArrayType_2 = this._joynrJavaGeneratorExtensions.getTokenTypeForArrayType(attributeType_1);
              _builder.append(_tokenTypeForArrayType_2, "\t");
              _builder.append("Reference.class)");
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              _builder.append("public String subscribeTo");
              String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
              _builder.append(_firstUpper_1, "\t");
              _builder.append("(AttributeSubscriptionListener<");
              _builder.append(attributeType_1, "\t");
              _builder.append("> listener, SubscriptionQos subscriptionQos, String subscriptionId);");
              _builder.newLineIfNotEmpty();
              _builder.newLine();
              _builder.append("\t");
              _builder.append("public void unsubscribeFrom");
              String _firstUpper_2 = StringExtensions.toFirstUpper(attributeName);
              _builder.append(_firstUpper_2, "\t");
              _builder.append("(String subscriptionId);");
              _builder.newLineIfNotEmpty();
            }
          }
        }
      }
      _builder.append("}");
      _builder.newLine();
      _xblockexpression = _builder;
    }
    return _xblockexpression;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy