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

io.joynr.generator.JoynrJavaGenerator Maven / Gradle / Ivy

The newest version!
package io.joynr.generator;

import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.name.Named;
import io.joynr.generator.communicationmodel.CommunicationModelGenerator;
import io.joynr.generator.filter.FilterGenerator;
import io.joynr.generator.interfaces.InterfaceGenerator;
import io.joynr.generator.provider.ProviderGenerator;
import io.joynr.generator.proxy.ProxyGenerator;
import io.joynr.generator.templates.util.NamingUtil;
import io.joynr.generator.templates.util.SupportedFrancaFeatureChecker;
import io.joynr.generator.util.JavaTemplateFactory;
import io.joynr.generator.util.JoynrJavaGeneratorExtensions;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.xbase.lib.Extension;
import org.franca.core.dsl.FrancaPersistenceManager;
import org.franca.core.franca.FCompoundType;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FModel;

@SuppressWarnings("all")
public class JoynrJavaGenerator implements IJoynrGenerator {
  @Inject
  private InterfaceGenerator interfacesGenerator;

  @Inject
  private CommunicationModelGenerator communicationModelGenerator;

  @Inject
  private ProxyGenerator proxyGenerator;

  @Inject
  private ProviderGenerator providerGenerator;

  @Inject
  private FilterGenerator filterGenerator;

  @Inject
  @Extension
  private JoynrJavaGeneratorExtensions _joynrJavaGeneratorExtensions;

  @Inject
  @Named(NamingUtil.JOYNR_GENERATOR_NOVERSIONGENERATION_COMMENT)
  public boolean versioningComment;

  @Inject
  @Named(NamingUtil.JOYNR_GENERATOR_PACKAGEWITHVERSION)
  public boolean packageWithVersion;

  @Inject
  @Named("generateProxyCode")
  public boolean generateProxyCode;

  @Inject
  @Named("generateProviderCode")
  public boolean generateProviderCode;

  private boolean generateVersionedCommunicationModel = false;

  private boolean generateUnversionedCommunicationModel = false;

  @Override
  public String getLanguageId() {
    return "java";
  }

  @Override
  public com.google.inject.Module getGeneratorModule() {
    return new AbstractModule() {
      @Override
      protected void configure() {
        this.install(new FactoryModuleBuilder().build(JavaTemplateFactory.class));
        this.bind(JoynrJavaGeneratorExtensions.class).in(Singleton.class);
      }
    };
  }

  @Override
  public void updateCommunicationModelGeneration(final Resource input) {
    EObject _get = input.getContents().get(0);
    final FModel fModel = ((FModel) _get);
    int _size = fModel.getInterfaces().size();
    boolean _equals = (_size == 0);
    if (_equals) {
      this.generateVersionedCommunicationModel = true;
    }
    EList _interfaces = fModel.getInterfaces();
    for (final FInterface fInterface : _interfaces) {
      {
        this._joynrJavaGeneratorExtensions.checkVersioningOption(fInterface, this.packageWithVersion);
        boolean _xifexpression = false;
        if (this.versioningComment) {
          boolean _commentContainsNoVersionGeneration = this._joynrJavaGeneratorExtensions.commentContainsNoVersionGeneration(fInterface);
          _xifexpression = (!_commentContainsNoVersionGeneration);
        } else {
          _xifexpression = this.packageWithVersion;
        }
        final boolean generateVersioning = _xifexpression;
        if (generateVersioning) {
          this.generateVersionedCommunicationModel = true;
        } else {
          this.generateUnversionedCommunicationModel = true;
        }
      }
    }
  }

  /**
   * Triggers the generation. In case the parameter "generate" is set to false, the generator is cleaning the generation folder
   */
  @Override
  public void doGenerate(final Resource input, final IFileSystemAccess fsa) {
    final boolean isFrancaIDLResource = input.getURI().fileExtension().equals(FrancaPersistenceManager.FRANCA_FILE_EXTENSION);
    Preconditions.checkArgument(isFrancaIDLResource, ("Unknown input: " + input));
    EObject _get = input.getContents().get(0);
    final FModel fModel = ((FModel) _get);
    this._joynrJavaGeneratorExtensions.checkForNamedArrays(fModel, input.getURI().path());
    SupportedFrancaFeatureChecker.checkModel(fModel);
    EList _interfaces = fModel.getInterfaces();
    for (final FInterface fInterface : _interfaces) {
      {
        boolean _xifexpression = false;
        if (this.versioningComment) {
          boolean _commentContainsNoVersionGeneration = this._joynrJavaGeneratorExtensions.commentContainsNoVersionGeneration(fInterface);
          _xifexpression = (!_commentContainsNoVersionGeneration);
        } else {
          _xifexpression = this.packageWithVersion;
        }
        final boolean generateVersioning = _xifexpression;
        this._joynrJavaGeneratorExtensions.checkVersioningOption(fInterface, this.packageWithVersion);
        this.interfacesGenerator.doGenerate(fInterface, fsa, generateVersioning);
        if (this.generateProxyCode) {
          this.proxyGenerator.doGenerate(fInterface, fsa, generateVersioning);
        }
        if (this.generateProviderCode) {
          this.providerGenerator.doGenerate(fInterface, fsa, generateVersioning);
          this.filterGenerator.doGenerate(fInterface, fsa, generateVersioning);
        }
      }
    }
  }

  @Override
  public void generateCommunicationModel(final Resource input, final IFileSystemAccess fsa) {
    EObject _get = input.getContents().get(0);
    final FModel fModel = ((FModel) _get);
    if (this.generateVersionedCommunicationModel) {
      this.communicationModelGenerator.doGenerate(fModel, fsa, true);
    }
    if (this.generateUnversionedCommunicationModel) {
      this.communicationModelGenerator.doGenerate(fModel, fsa, false);
    }
  }

  @Override
  public void clearCommunicationModelGenerationSettings() {
    this.generateVersionedCommunicationModel = false;
    this.generateUnversionedCommunicationModel = false;
  }

  public Iterable findAllFInterfaces(final Resource resource) {
    final HashSet result = new HashSet();
    final ResourceSet rs = resource.getResourceSet();
    EList _resources = rs.getResources();
    for (final Resource r : _resources) {
      EList _contents = r.getContents();
      for (final EObject c : _contents) {
        if ((c instanceof FModel)) {
          result.addAll(((FModel)c).getInterfaces());
        }
      }
    }
    return result;
  }

  public Iterable findAllComplexTypes(final Resource resource) {
    final HashSet result = new HashSet();
    final ResourceSet rs = resource.getResourceSet();
    EList _resources = rs.getResources();
    for (final Resource r : _resources) {
      EList _contents = r.getContents();
      for (final EObject c : _contents) {
        if ((c instanceof FModel)) {
          Iterables.addAll(result, this._joynrJavaGeneratorExtensions.getCompoundDataTypes(((FModel)c)));
        }
      }
    }
    return result;
  }

  @Override
  public void setParameters(final Map parameter) {
    if (((parameter.get("ignoreInvalidNullClassMembers") != null) && 
      parameter.get("ignoreInvalidNullClassMembers").equals("true"))) {
      this._joynrJavaGeneratorExtensions.activateIgnoreInvalidNullClassMembersExtension();
    }
  }

  @Override
  public Set supportedParameters() {
    List _asList = Arrays.asList("jee", "ignoreInvalidNullClassMembers");
    return new HashSet(_asList);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy