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

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

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

import com.google.inject.Inject;
import io.joynr.generator.communicationmodel.EnumTypeTemplate;
import io.joynr.generator.templates.InterfaceTemplate;
import io.joynr.generator.templates.util.InterfaceUtil;
import io.joynr.generator.templates.util.NamingUtil;
import io.joynr.generator.util.JavaTemplateFactory;
import io.joynr.generator.util.JoynrJavaGeneratorExtensions;
import io.joynr.generator.util.TemplateBase;
import java.util.HashMap;
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.FEnumerationType;
import org.franca.core.franca.FMethod;

@SuppressWarnings("all")
public class InterfacesTemplate extends InterfaceTemplate {
  @Inject
  @Extension
  private JoynrJavaGeneratorExtensions _joynrJavaGeneratorExtensions;

  @Inject
  @Extension
  private NamingUtil _namingUtil;

  @Inject
  @Extension
  private InterfaceUtil _interfaceUtil;

  @Inject
  @Extension
  private TemplateBase _templateBase;

  @Inject
  private JavaTemplateFactory templateFactory;

  @Override
  public CharSequence generate(final boolean generateVersion) {
    CharSequence _xblockexpression = null;
    {
      final String interfaceName = this._namingUtil.joynrName(this.francaIntf);
      final String className = interfaceName;
      final String packagePath = this._joynrJavaGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, ".", generateVersion);
      final boolean hasMethodWithImplicitErrorEnum = this._interfaceUtil.hasMethodWithImplicitErrorEnum(this.francaIntf);
      final HashMap methodToErrorEnumName = this._interfaceUtil.methodToErrorEnumName(this.francaIntf);
      StringConcatenation _builder = new StringConcatenation();
      _builder.newLine();
      _builder.append("\t\t");
      CharSequence _warning = this._templateBase.warning();
      _builder.append(_warning, "\t\t");
      _builder.newLineIfNotEmpty();
      _builder.append("package ");
      _builder.append(packagePath);
      _builder.append(";");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("import java.util.List;");
      _builder.newLine();
      _builder.append("import java.util.Set;");
      _builder.newLine();
      _builder.append("import java.util.HashSet;");
      _builder.newLine();
      {
        if (hasMethodWithImplicitErrorEnum) {
          _builder.append("import java.util.HashMap;");
          _builder.newLine();
          _builder.append("import java.util.Map;");
          _builder.newLine();
          _builder.append("import java.util.Map.Entry;");
          _builder.newLine();
        }
      }
      _builder.append("import io.joynr.subtypes.JoynrType;");
      _builder.newLine();
      _builder.append("import io.joynr.JoynrVersion;");
      _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();
        }
      }
      _builder.newLine();
      _builder.append("//The current generator is not able to check wether some of the imports are acutally necessary for this specific interface.");
      _builder.newLine();
      _builder.append("//Therefore some imports migth be unused in this version of the interface.");
      _builder.newLine();
      _builder.append("//To prevent warnings @SuppressWarnings(\"unused\") is being used.");
      _builder.newLine();
      _builder.append("//To prevent warnings about an unnecessary SuppressWarnings we have to import something that is not used. (e.g. TreeSet)");
      _builder.newLine();
      _builder.append("import java.util.TreeSet;");
      _builder.newLine();
      _builder.append("@SuppressWarnings(\"unused\")");
      _builder.newLine();
      _builder.append("@JoynrVersion(major = ");
      _builder.append(this.majorVersion);
      _builder.append(", minor = ");
      _builder.append(this.minorVersion);
      _builder.append(")");
      _builder.newLineIfNotEmpty();
      _builder.append("public interface ");
      _builder.append(className);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("public static String INTERFACE_NAME = \"");
      String _fullyQualifiedName = this._joynrJavaGeneratorExtensions.getFullyQualifiedName(this.francaIntf);
      _builder.append(_fullyQualifiedName, "\t");
      _builder.append("\";");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("public static Set> getDataTypes() {");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("Set> set = new HashSet<>();");
      _builder.newLine();
      {
        Iterable _requiredIncludesFor_1 = this._joynrJavaGeneratorExtensions.getRequiredIncludesFor(this.francaIntf, generateVersion);
        for(final String datatype_1 : _requiredIncludesFor_1) {
          _builder.append("\t\t");
          _builder.append("if (JoynrType.class.isAssignableFrom(");
          _builder.append(datatype_1, "\t\t");
          _builder.append(".class)) {");
          _builder.newLineIfNotEmpty();
          _builder.append("\t\t");
          _builder.append("\t");
          _builder.append("set.add(");
          _builder.append(datatype_1, "\t\t\t");
          _builder.append(".class);");
          _builder.newLineIfNotEmpty();
          _builder.append("\t\t");
          _builder.append("}");
          _builder.newLine();
        }
      }
      _builder.append("\t\t");
      _builder.append("return set;");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      {
        EList _methods = this._interfaceUtil.getMethods(this.francaIntf);
        for(final FMethod method : _methods) {
          _builder.append("\t");
          FEnumerationType enumType = method.getErrors();
          _builder.newLineIfNotEmpty();
          {
            if ((enumType != null)) {
              _builder.append("\t");
              EnumTypeTemplate enumTypeTemplate = this.templateFactory.createEnumTypeTemplate(enumType);
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              enumType.setName(methodToErrorEnumName.get(method));
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              CharSequence _generateEnumCode = enumTypeTemplate.generateEnumCode();
              _builder.append(_generateEnumCode, "\t");
              _builder.newLineIfNotEmpty();
              _builder.newLine();
            }
          }
        }
      }
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      _xblockexpression = _builder;
    }
    return _xblockexpression;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy