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

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

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

import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
import io.joynr.generator.IJoynrGenerator;
import io.joynr.generator.communicationmodel.CommunicationModelGenerator;
import io.joynr.generator.interfaces.InterfaceGenerator;
import io.joynr.generator.provider.ProviderGenerator;
import io.joynr.generator.proxy.ProxyGenerator;
import io.joynr.generator.util.IgnoreSVNFileFilter;
import io.joynr.generator.util.JoynrJavaGeneratorExtensions;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.util.Files;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.franca.core.dsl.FrancaPersistenceManager;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FModel;
import org.franca.core.franca.FType;

@SuppressWarnings("all")
public class JoynrJavaGenerator implements IJoynrGenerator {
  @Inject
  private InterfaceGenerator interfacesGenerator;
  
  @Inject
  private CommunicationModelGenerator communicationModelGenerator;
  
  @Inject
  private ProxyGenerator proxyGenerator;
  
  @Inject
  private ProviderGenerator providerGenerator;
  
  @Inject
  @Extension
  private JoynrJavaGeneratorExtensions _joynrJavaGeneratorExtensions;
  
  @Inject
  private FrancaPersistenceManager francaPersistenceManager;
  
  public String getLanguageId() {
    return "java";
  }
  
  public void doGenerate(final Resource input, final IFileSystemAccess fsa) {
    URI _uRI = input.getURI();
    String _fileExtension = _uRI.fileExtension();
    String _fileExtension_1 = this.francaPersistenceManager.getFileExtension();
    final boolean isFrancaIDLResource = _fileExtension.equals(_fileExtension_1);
    String _plus = ("Unknown input: " + input);
    Preconditions.checkArgument(isFrancaIDLResource, _plus);
    EList _contents = input.getContents();
    EObject _get = _contents.get(0);
    final FModel fModel = ((FModel) _get);
    EList _interfaces = fModel.getInterfaces();
    for (final FInterface fInterface : _interfaces) {
      {
        this.interfacesGenerator.doGenerate(fInterface, fsa);
        this.proxyGenerator.doGenerate(fInterface, fsa);
        this.providerGenerator.doGenerate(fInterface, fsa);
      }
    }
    this.communicationModelGenerator.doGenerate(fModel, fsa);
  }
  
  public void cleanDirectory(final String path) {
    File _file = new File(path);
    final File directory = _file;
    boolean _exists = directory.exists();
    boolean _not = (!_exists);
    if (_not) {
      directory.mkdirs();
    } else {
      try {
        IgnoreSVNFileFilter _ignoreSVNFileFilter = new IgnoreSVNFileFilter();
        Files.cleanFolder(directory, _ignoreSVNFileFilter, true, false);
      } catch (final Throwable _t) {
        if (_t instanceof FileNotFoundException) {
          final FileNotFoundException e = (FileNotFoundException)_t;
          e.printStackTrace();
        } else {
          throw Exceptions.sneakyThrow(_t);
        }
      }
    }
  }
  
  public Iterable findAllFInterfaces(final Resource resource) {
    HashSet _hashSet = new HashSet();
    final HashSet result = _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)) {
          EList _interfaces = ((FModel) c).getInterfaces();
          result.addAll(_interfaces);
        }
      }
    }
    return result;
  }
  
  public Iterable findAllComplexTypes(final Resource resource) {
    HashSet _hashSet = new HashSet();
    final HashSet result = _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)) {
          Iterable _complexDataTypes = this._joynrJavaGeneratorExtensions.getComplexDataTypes(((FModel) c));
          Iterables.addAll(result, _complexDataTypes);
        }
      }
    }
    return result;
  }
  
  public String getFilePath(final Resource resource) {
    final IWorkspaceRoot root = EcorePlugin.getWorkspaceRoot();
    URI _uRI = resource.getURI();
    boolean _isFile = _uRI.isFile();
    if (_isFile) {
      URI _uRI_1 = resource.getURI();
      return _uRI_1.toFileString();
    }
    URI _uRI_2 = resource.getURI();
    String _platformString = _uRI_2.toPlatformString(true);
    Path _path = new Path(_platformString);
    final Path platformPath = _path;
    final IFile file = root.getFile(platformPath);
    IPath _location = file.getLocation();
    return _location.toString();
  }
  
  public void setParameters(final Map parameter) {
  }
  
  public Set supportedParameters() {
    HashSet _newHashSet = Sets.newHashSet();
    return _newHashSet;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy