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

io.joynr.generator.util.JoynrJavaGeneratorExtensions Maven / Gradle / Ivy

The newest version!
package io.joynr.generator.util;

import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import io.joynr.generator.templates.util.BroadcastUtil;
import io.joynr.generator.templates.util.InterfaceUtil;
import io.joynr.generator.templates.util.JoynrGeneratorExtensions;
import java.util.Iterator;
import java.util.TreeSet;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Extension;
import org.franca.core.franca.FAnnotation;
import org.franca.core.franca.FAnnotationBlock;
import org.franca.core.franca.FAnnotationType;
import org.franca.core.franca.FBroadcast;
import org.franca.core.franca.FCompoundType;
import org.franca.core.franca.FField;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FModelElement;
import org.franca.core.franca.FType;
import org.franca.core.franca.FTypedElement;

@Singleton
@SuppressWarnings("all")
public class JoynrJavaGeneratorExtensions extends JoynrGeneratorExtensions {
  @Inject
  @Extension
  private JavaTypeUtil _javaTypeUtil;

  @Inject
  @Extension
  private InterfaceUtil _interfaceUtil;

  @Inject
  @Extension
  private BroadcastUtil _broadcastUtil;

  private boolean ignoreInvalidNullClassMembersExtension = false;

  public String getNamespaceStarter(final FInterface interfaceType, final boolean generateVersion) {
    return this.getNamespaceStarter(this.getPackageNames(interfaceType, generateVersion));
  }

  public String getNamespaceStarter(final FType datatype, final boolean generateVersion) {
    return this.getNamespaceStarter(this.getPackageNames(datatype, generateVersion));
  }

  public String getNamespaceEnder(final FInterface interfaceType, final boolean generateVersion) {
    return this.getNamespaceEnder(this.getPackageNames(interfaceType, generateVersion));
  }

  public String getNamespaceEnder(final FType datatype, final boolean generateVersion) {
    return this.getNamespaceEnder(this.getPackageNames(datatype, generateVersion));
  }

  private String getNamespaceStarter(final Iterator packageList) {
    return this.getNamespaceStarterFromPackageList(packageList);
  }

  public String getNamespaceStarterFromPackageList(final Iterator packageList) {
    StringBuilder sb = new StringBuilder();
    while (packageList.hasNext()) {
      String _next = packageList.next();
      String _plus = ("namespace " + _next);
      String _plus_1 = (_plus + "{ ");
      sb.append(_plus_1);
    }
    return sb.toString();
  }

  private String getNamespaceEnder(final Iterator packageList) {
    return this.getNameSpaceEnderFromPackageList(packageList);
  }

  public String getNameSpaceEnderFromPackageList(final Iterator packageList) {
    StringBuilder sb = new StringBuilder();
    while (packageList.hasNext()) {
      String _next = packageList.next();
      String _plus = ("} /* namespace " + _next);
      String _plus_1 = (_plus + " */ ");
      sb.insert(0, _plus_1);
    }
    return sb.toString();
  }

  public Iterable getRequiredIncludesFor(final FCompoundType datatype, final boolean generateVersion) {
    return this.getRequiredIncludesFor(datatype, true, generateVersion);
  }

  public Iterable getRequiredIncludesFor(final FCompoundType datatype, final boolean includingExendedType, final boolean generateVersion) {
    final Iterable members = this._javaTypeUtil.getComplexMembers(datatype);
    final TreeSet typeList = new TreeSet();
    boolean _hasExtendsDeclaration = this._javaTypeUtil.hasExtendsDeclaration(datatype);
    if (_hasExtendsDeclaration) {
      if (includingExendedType) {
        typeList.add(this.getIncludeOf(this._javaTypeUtil.getExtendedType(datatype), generateVersion));
      }
      Iterables.addAll(typeList, this.getRequiredIncludesFor(this._javaTypeUtil.getExtendedType(datatype), false, generateVersion));
    }
    for (final FField member : members) {
      {
        final Object type = this._javaTypeUtil.getDatatype(member.getType());
        if ((type instanceof FType)) {
          typeList.add(this.getIncludeOf(((FType)type), generateVersion));
        }
      }
    }
    return typeList;
  }

  public Iterable getRequiredIncludesFor(final FInterface serviceInterface, final boolean generateVersion) {
    return this.getRequiredIncludesFor(serviceInterface, true, true, true, true, true, true, generateVersion);
  }

  public Iterable getRequiredIncludesFor(final FInterface serviceInterface, final boolean methods, final boolean readAttributes, final boolean writeAttributes, final boolean notifyAttributes, final boolean broadcasts, final boolean fireAndForget, final boolean generateVersion) {
    final TreeSet includeSet = new TreeSet();
    final InterfaceUtil.TypeSelector selector = InterfaceUtil.TypeSelector.defaultTypeSelector();
    selector.methods(methods);
    selector.fireAndForget(fireAndForget);
    selector.readAttributes(readAttributes);
    selector.writeAttributes(writeAttributes);
    selector.notifyAttributes(notifyAttributes);
    selector.broadcasts(broadcasts);
    Iterable _allComplexTypes = this._interfaceUtil.getAllComplexTypes(serviceInterface, selector);
    for (final FType datatype : _allComplexTypes) {
      {
        final String include = this.getIncludeOf(datatype, generateVersion);
        if ((include != null)) {
          includeSet.add(include);
        }
      }
    }
    return includeSet;
  }

  public Iterable getRequiredIncludesFor(final FBroadcast broadcast, final boolean generateVersion) {
    final TreeSet includeSet = new TreeSet();
    Iterable _allComplexTypes = this._broadcastUtil.getAllComplexTypes(broadcast);
    for (final FType datatype : _allComplexTypes) {
      includeSet.add(this.getIncludeOf(datatype, generateVersion));
    }
    return includeSet;
  }

  public Iterable getRequiredStatelessAsyncIncludesFor(final FInterface serviceInterface, final boolean generateVersion) {
    TreeSet _xblockexpression = null;
    {
      final TreeSet includeSet = new TreeSet();
      Iterable _allComplexStatelessAsyncTypes = this._interfaceUtil.getAllComplexStatelessAsyncTypes(serviceInterface, true, false);
      for (final FType datatype : _allComplexStatelessAsyncTypes) {
        {
          final String include = this.getIncludeOf(datatype, generateVersion);
          if ((include != null)) {
            includeSet.add(include);
          }
        }
      }
      _xblockexpression = includeSet;
    }
    return _xblockexpression;
  }

  public Iterable getRequiredStatelessAsyncCallbackIncludesFor(final FInterface serviceInterface, final boolean generateVersion) {
    TreeSet _xblockexpression = null;
    {
      final TreeSet includeSet = new TreeSet();
      Iterable _allComplexStatelessAsyncTypes = this._interfaceUtil.getAllComplexStatelessAsyncTypes(serviceInterface, false, true);
      for (final FType datatype : _allComplexStatelessAsyncTypes) {
        {
          final String include = this.getIncludeOf(datatype, generateVersion);
          if ((include != null)) {
            includeSet.add(include);
          }
        }
      }
      _xblockexpression = includeSet;
    }
    return _xblockexpression;
  }

  public String ReformatComment(final FAnnotation comment, final String prefixForNewLines) {
    return comment.getComment().replaceAll("\\s+", " ").replaceAll("\n", ("\n" + prefixForNewLines));
  }

  public CharSequence appendJavadocSummaryAndWriteSeeAndDescription(final FModelElement element, final String prefixForNewLines) {
    StringConcatenation _builder = new StringConcatenation();
    {
      FAnnotationBlock _comment = element.getComment();
      boolean _tripleNotEquals = (_comment != null);
      if (_tripleNotEquals) {
        {
          EList _elements = element.getComment().getElements();
          for(final FAnnotation comment : _elements) {
            {
              FAnnotationType _type = comment.getType();
              boolean _equals = Objects.equal(_type, FAnnotationType.DESCRIPTION);
              if (_equals) {
                _builder.append(prefixForNewLines);
                _builder.append(" ");
                String _ReformatComment = this.ReformatComment(comment, prefixForNewLines);
                _builder.append(_ReformatComment);
                _builder.newLineIfNotEmpty();
              }
            }
          }
        }
        {
          EList _elements_1 = element.getComment().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(prefixForNewLines);
                _builder.append(" @see ");
                String _ReformatComment_1 = this.ReformatComment(comment_1, prefixForNewLines);
                _builder.append(_ReformatComment_1);
                _builder.newLineIfNotEmpty();
              }
            }
            {
              FAnnotationType _type_2 = comment_1.getType();
              boolean _equals_2 = Objects.equal(_type_2, FAnnotationType.DETAILS);
              if (_equals_2) {
                _builder.append(prefixForNewLines);
                _builder.newLineIfNotEmpty();
                _builder.append(prefixForNewLines);
                _builder.append(" ");
                String _ReformatComment_2 = this.ReformatComment(comment_1, prefixForNewLines);
                _builder.append(_ReformatComment_2);
                _builder.newLineIfNotEmpty();
              }
            }
          }
        }
      }
    }
    return _builder;
  }

  public CharSequence appendJavadocComment(final FModelElement element, final String prefixForNewLines) {
    StringConcatenation _builder = new StringConcatenation();
    String _elementDescription = this.getElementDescription(element, prefixForNewLines);
    _builder.append(_elementDescription);
    _builder.newLineIfNotEmpty();
    return _builder;
  }

  public String getElementDescription(final FModelElement element, final String prefixForNewLines) {
    String description = "";
    boolean found = false;
    FAnnotationBlock _comment = element.getComment();
    boolean _tripleNotEquals = (_comment != null);
    if (_tripleNotEquals) {
      EList _elements = element.getComment().getElements();
      for (final FAnnotation comment : _elements) {
        FAnnotationType _type = comment.getType();
        boolean _equals = Objects.equal(_type, FAnnotationType.DESCRIPTION);
        if (_equals) {
          String _description = description;
          String _ReformatComment = this.ReformatComment(comment, prefixForNewLines);
          description = (_description + _ReformatComment);
          found = true;
        }
      }
    }
    if ((!found)) {
      String _description_1 = description;
      description = (_description_1 + "description missing in Franca model.");
    }
    return description;
  }

  public String appendJavadocParameter(final FTypedElement element, final String prefixForNewLines) {
    String _joynrName = this._namingUtil.joynrName(element);
    String _plus = ((prefixForNewLines + " @param ") + _joynrName);
    String description = (_plus + " ");
    String _description = description;
    String _elementDescription = this.getElementDescription(element, prefixForNewLines);
    description = (_description + _elementDescription);
    boolean _isTypeDef = this._javaTypeUtil.isTypeDef(element.getType());
    if (_isTypeDef) {
      String _description_1 = description;
      String _joynrName_1 = this._namingUtil.joynrName(element.getType());
      String _plus_1 = ((("\n" + prefixForNewLines) + 
        " (type resolved from modeled Franca typedef ") + _joynrName_1);
      String _plus_2 = (_plus_1 + 
        " as ");
      String _typeName = this._javaTypeUtil.getTypeName(this._javaTypeUtil.getTypeDefType(element.getType()).getActualType());
      String _plus_3 = (_plus_2 + _typeName);
      String _plus_4 = (_plus_3 + 
        ")");
      description = (_description_1 + _plus_4);
    }
    return description;
  }

  public String getIncludeOf(final FType dataType, final boolean generateVersion) {
    String _buildPackagePath = this.buildPackagePath(dataType, ".", true, generateVersion);
    String _plus = (_buildPackagePath + ".");
    String _joynrName = this._namingUtil.joynrName(dataType);
    return (_plus + _joynrName);
  }

  public boolean hasArrayMembers(final FCompoundType datatype) {
    EList _members = this._javaTypeUtil.getMembers(datatype);
    for (final FField member : _members) {
      boolean _isArray = this._javaTypeUtil.isArray(member);
      if (_isArray) {
        return true;
      }
    }
    return false;
  }

  public String getJoynTypePackagePrefix() {
    return this.getJoynrGenerationPrefix();
  }

  public boolean activateIgnoreInvalidNullClassMembersExtension() {
    return this.ignoreInvalidNullClassMembersExtension = true;
  }

  public boolean ignoreInvalidNullClassMembersExtension() {
    return this.ignoreInvalidNullClassMembersExtension;
  }

  public String getProviderClassName(final FInterface francaIntf) {
    String _joynrName = this._namingUtil.joynrName(francaIntf);
    return (_joynrName + "Provider");
  }

  public String getProxyClassName(final FInterface francaIntf) {
    String _joynrName = this._namingUtil.joynrName(francaIntf);
    return (_joynrName + "Proxy");
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy