예제 #1
0
 protected List<EPackageInfo> createEPackageInfosFromGenModel(
     URI genModelURI, Resource genModelResource) {
   //		ResourceSet resourceSet = createResourceSet(genModelURI);
   //		Resource resource = resourceSet.getResource(genModelURI, true);
   List<EPackageInfo> ePackageInfos = Lists.newArrayList();
   for (TreeIterator<EObject> i = genModelResource.getAllContents(); i.hasNext(); ) {
     EObject next = i.next();
     if (next instanceof GenPackage) {
       GenPackage genPackage = (GenPackage) next;
       EPackage ePackage = genPackage.getEcorePackage();
       URI importURI;
       if (ePackage.eResource() == null) {
         importURI = URI.createURI(ePackage.getNsURI());
       } else {
         importURI = ePackage.eResource().getURI();
       }
       EPackageInfo ePackageInfo =
           new EPackageInfo(
               ePackage,
               importURI,
               genModelURI,
               genPackage.getQualifiedPackageInterfaceName(),
               genPackage.getGenModel().getModelPluginID());
       ePackageInfos.add(ePackageInfo);
     } else if (!(next instanceof GenModel)) {
       i.prune();
     }
   }
   return ePackageInfos;
 }
예제 #2
0
 public PropertiesEditionContext genPackage2Context(GenPackage genPackage) {
   PropertiesEditionContext context = ComponentsFactory.eINSTANCE.createPropertiesEditionContext();
   context.setModel(genPackage);
   context.setDocumentation(
       "Edition Context for " + genPackage.getEcorePackage().getName() + " GenPackage");
   Category components = MappingFactory.eINSTANCE.createCategory();
   components.setName(genPackage.getEcorePackage().getName());
   context.getCategories().add(components);
   for (GenClass genClass : genPackage.getGenClasses()) {
     if (!genClass.getEcoreClass().isAbstract()) {
       components.getBindings().add(genClass2Component(genClass, genPackage));
     }
   }
   return context;
 }
예제 #3
0
  @Override
  public void execute() throws BuildException {

    EPackage.Registry.INSTANCE.put(GenModelPackage.eNS_URI, GenModelPackage.eINSTANCE);
    EPackage.Registry.INSTANCE.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
    EPackage.Registry.INSTANCE.put(
        "http://www.eclipse.org/uml2/2.2.0/GenModel", getUML2GenPackage());
    EPackage.Registry.INSTANCE.put(
        "http://www.eclipse.org/uml2/4.0.0/Types", getUML2TypesPackage());

    Map<String, Object> extensionToFactoryMap =
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap();
    extensionToFactoryMap.put(
        "ecore", new org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl());
    extensionToFactoryMap.put(
        "genmodel", new org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl());

    // We ignore the deprecation warning until the method is not available
    // anymore to keep this code runnable against old versions of EMF as
    // long as possible.
    @SuppressWarnings("deprecation")
    final Map<String, URI> packageNsURIToGenModelLocationMap =
        EcorePlugin.getEPackageNsURIToGenModelLocationMap();
    URI genModelURIObject = URI.createURI(genModelURI);
    ResourceSet rs = new ResourceSetImpl();
    Resource resource = null;
    try {
      resource = rs.getResource(genModelURIObject, true);

      for (GenPackage genPackage : ((GenModel) resource.getContents().get(0)).getGenPackages()) {
        EPackage ecorePackage = genPackage.getEcorePackage();
        String nsURI = ecorePackage.getNsURI();
        EPackage.Registry.INSTANCE.put(nsURI, ecorePackage);
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new BuildException("Can't load generator model from " + genModelURIObject);
    }

    packageNsURIToGenModelLocationMap.put(namespaceURI, genModelURIObject);
  }
예제 #4
0
 public void generateVisitors(@NonNull final GenPackage genPackage) {
   EPackage ePackage = genPackage.getEcorePackage();
   boolean _isDerived = this.isDerived();
   boolean _not = (!_isDerived);
   if (_not) {
     this.generateVisitableInterface(ePackage);
   }
   this.generateVisitorInterface(ePackage);
   this.generateDecorableVisitorInterface(
       ePackage, "org.eclipse.ocl.examples.xtext.base.basecs.util.BaseCSVisitor");
   this.generateAbstractVisitor(ePackage);
   this.generateAbstractNullVisitor(ePackage);
   this.generateAbstractDelegatingVisitor(ePackage);
   this.generateAbstractExtendingVisitor(ePackage);
 }
  public void generatePackages(
      GenModel genModel, List<GenPackage> genPackages, VirtualFile basedir) {
    for (GenPackage genPackage : genPackages) {
      genPackage.prepareCache();

      genModel.setImportManager(new ImportManager("org.bimserver.models"));

      String packageClassPathImpl = MODEL_PACKAGE + genPackage.getPackageName() + ".impl.";
      packageClassPathImpl =
          packageClassPathImpl.replace(".", File.separator)
              + genPackage.getPackageClassName()
              + ".java";
      VirtualFile packageVirtualFileImpl = basedir.createFile(packageClassPathImpl);
      packageVirtualFileImpl.setStringContent(
          new PackageClass().generate(new Object[] {genPackage, false, true}));

      genModel.setImportManager(new ImportManager("org.bimserver.models"));

      String packageClassPathInterface = MODEL_PACKAGE + genPackage.getPackageName() + ".";
      packageClassPathInterface =
          packageClassPathInterface.replace(".", File.separator)
              + genPackage.getPackageInterfaceName()
              + ".java";
      VirtualFile packageVirtualFileInterface = basedir.createFile(packageClassPathInterface);
      packageVirtualFileInterface.setStringContent(
          new PackageClass().generate(new Object[] {genPackage, true, false}));

      genModel.setImportManager(new ImportManager("org.bimserver.models"));

      String factoryClassPathImpl = MODEL_PACKAGE + genPackage.getPackageName() + ".impl.";
      factoryClassPathImpl =
          factoryClassPathImpl.replace(".", File.separator)
              + genPackage.getFactoryClassName()
              + ".java";
      VirtualFile factoryVirtualFileImpl = basedir.createFile(factoryClassPathImpl);
      factoryVirtualFileImpl.setStringContent(
          new FactoryClass().generate(new Object[] {genPackage, false, true}));

      genModel.setImportManager(new ImportManager("org.bimserver.models"));

      String factoryClassPathInterface = MODEL_PACKAGE + genPackage.getPackageName() + ".";
      factoryClassPathInterface =
          factoryClassPathInterface.replace(".", File.separator)
              + genPackage.getFactoryInterfaceName()
              + ".java";
      VirtualFile factoryVirtualFileInterface = basedir.createFile(factoryClassPathInterface);
      factoryVirtualFileInterface.setStringContent(
          new FactoryClass().generate(new Object[] {genPackage, true, false}));

      genModel.setImportManager(new ImportManager("org.bimserver.models"));

      String adapterFactoryClassPath = MODEL_PACKAGE + genPackage.getPackageName() + ".util.";
      adapterFactoryClassPath =
          adapterFactoryClassPath.replace(".", File.separator)
              + genPackage.getAdapterFactoryClassName()
              + ".java";
      VirtualFile adapterFactoryVirtualFile = basedir.createFile(adapterFactoryClassPath);
      adapterFactoryVirtualFile.setStringContent(new AdapterFactoryClass().generate(genPackage));

      genModel.setImportManager(new ImportManager("org.bimserver.models"));

      String switchClassPath = MODEL_PACKAGE + genPackage.getPackageName() + ".util.";
      switchClassPath =
          switchClassPath.replace(".", File.separator) + genPackage.getSwitchClassName() + ".java";
      VirtualFile switchClassVirtualFile = basedir.createFile(switchClassPath);
      switchClassVirtualFile.setStringContent(new SwitchClass().generate(genPackage));

      genModel.setImportManager(new ImportManager("org.bimserver.models"));

      String xmlClassPath = MODEL_PACKAGE + genPackage.getPackageName() + ".util.";
      xmlClassPath =
          xmlClassPath.replace(".", File.separator)
              + genPackage.getXMLProcessorClassName()
              + ".java";
      VirtualFile xmlClassVirtualFile = basedir.createFile(xmlClassPath);
      xmlClassVirtualFile.setStringContent(new XMLProcessorClass().generate(genPackage));

      genModel.setImportManager(new ImportManager("org.bimserver.models"));

      String resourceFactoryClassPath = MODEL_PACKAGE + genPackage.getPackageName() + ".util.";
      resourceFactoryClassPath =
          resourceFactoryClassPath.replace(".", File.separator)
              + genPackage.getResourceFactoryClassName()
              + ".java";
      VirtualFile resourceFactoryClassVirtualFile = basedir.createFile(resourceFactoryClassPath);
      resourceFactoryClassVirtualFile.setStringContent(
          new ResourceFactoryClass().generate(genPackage));

      genModel.setImportManager(new ImportManager("org.bimserver.models"));

      String resourceClassPath = MODEL_PACKAGE + genPackage.getPackageName() + ".util.";
      resourceClassPath =
          resourceClassPath.replace(".", File.separator)
              + genPackage.getResourceClassName()
              + ".java";
      VirtualFile resourceClassVirtualFile = basedir.createFile(resourceClassPath);
      resourceClassVirtualFile.setStringContent(new ResourceClass().generate(genPackage));

      // String validatorClassPath = "com.logiclabs.streamdb.models." +
      // genPackage.getPackageName() + ".util.";
      // validatorClassPath = validatorClassPath.replace(".",
      // File.separator) + genPackage.getValidatorClassName() + ".java";
      // VirtualFile validatorClassVirtualFile =
      // basedir.createFile(validatorClassPath);
      // validatorClassVirtualFile.setStringContent(new
      // ValidatorClass().generate(genPackage));

      for (GenClass genClass : genPackage.getGenClasses()) {
        genModel.setImportManager(new ImportManager("org.bimserver.models"));
        String implFileName = MODEL_PACKAGE + genPackage.getPackageName() + ".impl.";
        implFileName = implFileName.replace(".", File.separator) + genClass.getName() + "Impl.java";
        VirtualFile implVirtualFile = basedir.createFile(implFileName);
        implVirtualFile.setStringContent(
            new org.eclipse.emf.codegen.ecore.templates.model.Class()
                .generate(new Object[] {genClass, false, true}));

        genModel.setImportManager(new ImportManager("org.bimserver.models"));
        String interfaceFileName = MODEL_PACKAGE + genPackage.getPackageName() + ".";
        interfaceFileName =
            interfaceFileName.replace(".", File.separator) + genClass.getName() + ".java";
        VirtualFile interfaceVirtualFile = basedir.createFile(interfaceFileName);
        interfaceVirtualFile.setStringContent(
            new org.eclipse.emf.codegen.ecore.templates.model.Class()
                .generate(new Object[] {genClass, true, false}));
      }
      for (GenEnum genEnum : genPackage.getGenEnums()) {
        genModel.setImportManager(new ImportManager("org.bimserver.models"));

        String enumFileName = MODEL_PACKAGE + genPackage.getPackageName() + ".";
        enumFileName = enumFileName.replace(".", File.separator) + genEnum.getName() + ".java";
        VirtualFile enumVirtualFile = basedir.createFile(enumFileName);
        enumVirtualFile.setStringContent(new EnumClass().generate(genEnum));
      }
    }
  }
 public List<GenPackage> createGenPackages(GenModel genModel, VirtualFile basedir)
     throws DatabaseException {
   ResourceSetImpl resourceSet = new ResourceSetImpl();
   resourceSet
       .getResourceFactoryRegistry()
       .getExtensionToFactoryMap()
       .put("ecore", new EcoreResourceFactoryImpl());
   Map<VirtualFile, Resource> resources = new HashMap<VirtualFile, Resource>();
   genModel.initialize(schema.getEPackages());
   for (GenPackage genPackage : genModel.getGenPackages()) {
     genPackage.setBasePackage("org.bimserver.models");
   }
   for (EPackage ePackage : schema.getEPackages()) {
     // GenPackage genPackage = genModel.get
     // result.add(genPackage);
     // genModel.getGenPackages().add(genPackage);
     // genPackage.initialize(ePackage);
     // for (EClassifier eClassifier : ePackage.getEClassifiers()) {
     // if (eClassifier instanceof EClass) {
     // EClass eClass = (EClass) eClassifier;
     // GenClass genClass = GenModelFactory.eINSTANCE.createGenClass();
     // genClass.initialize(eClass);
     // genPackage.getGenClasses().add(genClass);
     // for (EStructuralFeature eStructuralFeature :
     // eClass.getEStructuralFeatures()) {
     // GenFeature genFeature =
     // GenModelFactory.eINSTANCE.createGenFeature();
     // genFeature.initialize(eStructuralFeature);
     // genFeature.setEcoreFeature(eStructuralFeature);
     // genClass.getGenFeatures().add(genFeature);
     // }
     // } else if (eClassifier instanceof EEnum) {
     // EEnum eEnum = (EEnum) eClassifier;
     // GenEnum genEnum = GenModelFactory.eINSTANCE.createGenEnum();
     // genEnum.setEcoreEnum(eEnum);
     // genPackage.getGenEnums().add(genEnum);
     // for (EEnumLiteral eEnumLiteral : eEnum.getELiterals()) {
     // GenEnumLiteral genEnumLiteral =
     // GenModelFactory.eINSTANCE.createGenEnumLiteral();
     // genEnumLiteral.setEcoreEnumLiteral(eEnumLiteral);
     // genEnum.getGenEnumLiterals().add(genEnumLiteral);
     // }
     // } else if (eClassifier instanceof EDataType) {
     // GenDataType genDataType =
     // GenModelFactory.eINSTANCE.createGenDataType();
     // genDataType.setEcoreDataType((EDataType) eClassifier);
     // genPackage.getGenDataTypes().add(genDataType);
     // }
     // }
     Resource resource = resourceSet.createResource(URI.createURI(ePackage.getName() + ".ecore"));
     resource.getContents().add(ePackage);
     VirtualFile ecoreFile =
         basedir.createFile(
             MODEL_PACKAGE.replace(".", "/")
                 + ePackage.getName()
                 + "/impl/"
                 + ePackage.getName()
                 + ".ecore");
     resources.put(ecoreFile, resource);
   }
   for (VirtualFile virtualFile : resources.keySet()) {
     try {
       Resource resource = resources.get(virtualFile);
       OutputStream openOutputStream = virtualFile.openOutputStream();
       resource.save(openOutputStream, null);
       openOutputStream.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   return genModel.getGenPackages();
 }
예제 #7
0
  public Object execute(ExecutionEvent event) throws ExecutionException {
    String tag = null;
    boolean copyLibraries = false;
    try {
      copyLibraries =
          (event.getParameter("emf-rest.copyLibraries") == null
              ? false
              : Boolean.valueOf(event.getParameter("emf-rest.copyLibraries")));
      tag = event.getParameter("emf-rest.tagParameter");
    } catch (Exception e) {
      e.printStackTrace();
    }
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    IStructuredSelection selection =
        (IStructuredSelection) window.getSelectionService().getSelection();
    IResource ecoreResource = (IResource) selection.getFirstElement();

    if (tag != null && tag.equals("None")) {
      GenerationListener genlistener =
          new GenerationListener(ecoreResource.getProject(), Platform.getBundle("emf-rest"), true);
      genlistener.afterFinishExecution(null, null, null);
      return null;
    }

    HashMap<String, Object> variables = new HashMap<String, Object>();
    variables.put("ecore_file", ecoreResource.getLocation().toOSString());
    variables.put(
        "genModel_file",
        ecoreResource.getLocation().toOSString().replaceFirst(".ecore", ".genmodel"));
    variables.put(
        "output", ecoreResource.getProject().findMember("src").getLocation().toOSString());
    try {
      variables.put(
          "modelDirectory",
          ecoreResource.getProject().findMember("WebContent/models").getLocation().toOSString());
    } catch (Exception ex) {
      variables.put("modelDirectory", "");
    }
    File scriptDir =
        new File(ecoreResource.getProject().getLocation().toOSString() + "/WebContent/scripts");
    if (tag == null || tag.equals("javascript")) {
      scriptDir.mkdirs();
    }
    variables.put(
        "output_js", ecoreResource.getProject().getLocation().toOSString() + "/WebContent/scripts");
    HashMap<String, GenPackage> usedGenPackages = new HashMap<String, GenPackage>();

    try {
      ResourceSet eCoreResourceSet = new ResourceSetImpl();
      Resource eCoreResource =
          eCoreResourceSet.createResource(
              URI.createFileURI(ecoreResource.getLocation().toOSString()));
      eCoreResource.load(null);
      EPackage ePackage = (EPackage) eCoreResource.getContents().get(0);
      for (EAnnotation eAnnotation : ePackage.getEAnnotations()) {
        if (eAnnotation.getSource().equalsIgnoreCase("emf.gen.usedGenPackage")) {
          ResourceSet genModelResourceSet = new ResourceSetImpl();
          Resource genModelResource =
              genModelResourceSet.createResource(
                  URI.createURI(eAnnotation.getDetails().get("genModel"), false));
          genModelResource.load(null);
          GenModel genModel = (GenModel) genModelResource.getContents().get(0);
          for (GenPackage genPackage : genModel.getGenPackages()) {
            String usedGenPackageName = eAnnotation.getDetails().get("name");
            if (genPackage.getEcorePackage().getName().equals(usedGenPackageName)) {
              usedGenPackages.put(usedGenPackageName, genPackage);
            }
          }
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    variables.put("usedGenPackages", usedGenPackages);
    variables.put("pluginName", ecoreResource.getProject().getName());
    variables.put("foreignModel", ecoreResource.getName());

    File webContentModelsPath =
        new File(
            ecoreResource.getProject().findMember("WebContent/models").getLocation().toOSString());
    String modelName = "";
    for (File file : webContentModelsPath.listFiles()) {
      if (file.getName().endsWith(".xmi")) {
        modelName = file.getName().substring(0, file.getName().lastIndexOf("."));
      }
    }
    variables.put("modelName", modelName);

    MTCChoreographer choreographer =
        MTCStandaloneUtils.startMTC(
            ecoreResource.getProject(),
            "emf-rest",
            "default.mtc",
            variables,
            (tag == null ? null : Collections.singletonList(tag)));
    ArrayList<IResource> resourceToRefresh = new ArrayList<IResource>();
    resourceToRefresh.add(ecoreResource.getProject());
    choreographer.addExecutionListener(
        new GenerationListener(
            ecoreResource.getProject(), Platform.getBundle("emf-rest"), copyLibraries));
    choreographer.start();
    choreographer.modelReady("Ecore Fully Annotated", null);
    return null;
  }
 public void buildMap(final GenModel genModel) {
   Iterable<EObject> _allContentsIterable = XcoreExtensions.allContentsIterable(genModel);
   for (final EObject genElement : _allContentsIterable) {
     boolean _matched = false;
     if (!_matched) {
       if (genElement instanceof GenPackage) {
         final GenPackage _genPackage = (GenPackage) genElement;
         _matched = true;
         EPackage _ecorePackage = _genPackage.getEcorePackage();
         ToXcoreMapping _toXcoreMapping = this.mapper.getToXcoreMapping(_ecorePackage);
         XNamedElement _xcoreElement = _toXcoreMapping.getXcoreElement();
         final XPackage xPackage = ((XPackage) _xcoreElement);
         boolean _notEquals = (!Objects.equal(xPackage, null));
         if (_notEquals) {
           XPackageMapping _mapping = this.mapper.getMapping(xPackage);
           _mapping.setGenPackage(_genPackage);
           ToXcoreMapping _toXcoreMapping_1 = this.mapper.getToXcoreMapping(_genPackage);
           _toXcoreMapping_1.setXcoreElement(xPackage);
         }
       }
     }
     if (!_matched) {
       if (genElement instanceof GenClass) {
         final GenClass _genClass = (GenClass) genElement;
         _matched = true;
         EClass _ecoreClass = _genClass.getEcoreClass();
         ToXcoreMapping _toXcoreMapping = this.mapper.getToXcoreMapping(_ecoreClass);
         XNamedElement _xcoreElement = _toXcoreMapping.getXcoreElement();
         final XClass xClass = ((XClass) _xcoreElement);
         boolean _notEquals = (!Objects.equal(xClass, null));
         if (_notEquals) {
           XClassMapping _mapping = this.mapper.getMapping(xClass);
           _mapping.setGenClass(_genClass);
           ToXcoreMapping _toXcoreMapping_1 = this.mapper.getToXcoreMapping(_genClass);
           _toXcoreMapping_1.setXcoreElement(xClass);
         }
       }
     }
     if (!_matched) {
       if (genElement instanceof GenDataType) {
         final GenDataType _genDataType = (GenDataType) genElement;
         _matched = true;
         EDataType _ecoreDataType = _genDataType.getEcoreDataType();
         ToXcoreMapping _toXcoreMapping = this.mapper.getToXcoreMapping(_ecoreDataType);
         XNamedElement _xcoreElement = _toXcoreMapping.getXcoreElement();
         final XDataType xDataType = ((XDataType) _xcoreElement);
         boolean _notEquals = (!Objects.equal(xDataType, null));
         if (_notEquals) {
           XDataTypeMapping _mapping = this.mapper.getMapping(xDataType);
           _mapping.setGenDataType(_genDataType);
           ToXcoreMapping _toXcoreMapping_1 = this.mapper.getToXcoreMapping(_genDataType);
           _toXcoreMapping_1.setXcoreElement(xDataType);
         }
       }
     }
     if (!_matched) {
       if (genElement instanceof GenFeature) {
         final GenFeature _genFeature = (GenFeature) genElement;
         _matched = true;
         EStructuralFeature _ecoreFeature = _genFeature.getEcoreFeature();
         ToXcoreMapping _toXcoreMapping = this.mapper.getToXcoreMapping(_ecoreFeature);
         XNamedElement _xcoreElement = _toXcoreMapping.getXcoreElement();
         final XStructuralFeature xFeature = ((XStructuralFeature) _xcoreElement);
         boolean _notEquals = (!Objects.equal(xFeature, null));
         if (_notEquals) {
           XFeatureMapping _mapping = this.mapper.getMapping(xFeature);
           _mapping.setGenFeature(_genFeature);
           ToXcoreMapping _toXcoreMapping_1 = this.mapper.getToXcoreMapping(_genFeature);
           _toXcoreMapping_1.setXcoreElement(xFeature);
         }
       }
     }
     if (!_matched) {
       if (genElement instanceof GenOperation) {
         final GenOperation _genOperation = (GenOperation) genElement;
         _matched = true;
         EOperation _ecoreOperation = _genOperation.getEcoreOperation();
         ToXcoreMapping _toXcoreMapping = this.mapper.getToXcoreMapping(_ecoreOperation);
         XNamedElement _xcoreElement = _toXcoreMapping.getXcoreElement();
         final XOperation xOperation = ((XOperation) _xcoreElement);
         boolean _notEquals = (!Objects.equal(xOperation, null));
         if (_notEquals) {
           XOperationMapping _mapping = this.mapper.getMapping(xOperation);
           _mapping.setGenOperation(_genOperation);
           ToXcoreMapping _toXcoreMapping_1 = this.mapper.getToXcoreMapping(_genOperation);
           _toXcoreMapping_1.setXcoreElement(xOperation);
         }
       }
     }
     if (!_matched) {
       if (genElement instanceof GenParameter) {
         final GenParameter _genParameter = (GenParameter) genElement;
         _matched = true;
         EParameter _ecoreParameter = _genParameter.getEcoreParameter();
         ToXcoreMapping _toXcoreMapping = this.mapper.getToXcoreMapping(_ecoreParameter);
         XNamedElement _xcoreElement = _toXcoreMapping.getXcoreElement();
         final XParameter xParameter = ((XParameter) _xcoreElement);
         boolean _notEquals = (!Objects.equal(xParameter, null));
         if (_notEquals) {
           XParameterMapping _mapping = this.mapper.getMapping(xParameter);
           _mapping.setGenParameter(_genParameter);
           ToXcoreMapping _toXcoreMapping_1 = this.mapper.getToXcoreMapping(_genParameter);
           _toXcoreMapping_1.setXcoreElement(xParameter);
         }
       }
     }
     if (!_matched) {
       if (genElement instanceof GenTypeParameter) {
         final GenTypeParameter _genTypeParameter = (GenTypeParameter) genElement;
         _matched = true;
         ETypeParameter _ecoreTypeParameter = _genTypeParameter.getEcoreTypeParameter();
         ToXcoreMapping _toXcoreMapping = this.mapper.getToXcoreMapping(_ecoreTypeParameter);
         XNamedElement _xcoreElement = _toXcoreMapping.getXcoreElement();
         final XTypeParameter xTypeParameter = ((XTypeParameter) _xcoreElement);
         boolean _notEquals = (!Objects.equal(xTypeParameter, null));
         if (_notEquals) {
           XTypeParameterMapping _mapping = this.mapper.getMapping(xTypeParameter);
           _mapping.setGenTypeParameter(_genTypeParameter);
           ToXcoreMapping _toXcoreMapping_1 = this.mapper.getToXcoreMapping(_genTypeParameter);
           _toXcoreMapping_1.setXcoreElement(xTypeParameter);
         }
       }
     }
     if (!_matched) {
       if (genElement instanceof GenEnumLiteral) {
         final GenEnumLiteral _genEnumLiteral = (GenEnumLiteral) genElement;
         _matched = true;
         EEnumLiteral _ecoreEnumLiteral = _genEnumLiteral.getEcoreEnumLiteral();
         ToXcoreMapping _toXcoreMapping = this.mapper.getToXcoreMapping(_ecoreEnumLiteral);
         XNamedElement _xcoreElement = _toXcoreMapping.getXcoreElement();
         final XEnumLiteral xEnumLiteral = ((XEnumLiteral) _xcoreElement);
         boolean _notEquals = (!Objects.equal(xEnumLiteral, null));
         if (_notEquals) {
           XEnumLiteralMapping _mapping = this.mapper.getMapping(xEnumLiteral);
           _mapping.setGenEnumLiteral(_genEnumLiteral);
           ToXcoreMapping _toXcoreMapping_1 = this.mapper.getToXcoreMapping(_genEnumLiteral);
           _toXcoreMapping_1.setXcoreElement(xEnumLiteral);
         }
       }
     }
   }
 }
 public void initializeUsedGenPackages(final GenModel genModel) {
   this.genModelInitializer.initialize(genModel, true);
   HashSet<EPackage> _hashSet = new HashSet<EPackage>();
   final HashSet<EPackage> referencedEPackages = _hashSet;
   UniqueEList<EPackage> _uniqueEList = new UniqueEList<EPackage>();
   final List<EPackage> ePackages = _uniqueEList;
   EList<GenPackage> _genPackages = genModel.getGenPackages();
   for (final GenPackage genPackage : _genPackages) {
     EPackage _ecorePackage = genPackage.getEcorePackage();
     ePackages.add(_ecorePackage);
   }
   int i = 0;
   int _size = ePackages.size();
   boolean _lessThan = (i < _size);
   boolean _while = _lessThan;
   while (_while) {
     {
       final EPackage ePackage = ePackages.get(i);
       int _plus = (i + 1);
       i = _plus;
       final TreeIterator<EObject> allContents = ePackage.eAllContents();
       boolean _hasNext = allContents.hasNext();
       boolean _while_1 = _hasNext;
       while (_while_1) {
         {
           final EObject eObject = allContents.next();
           if ((eObject instanceof EPackage)) {
             allContents.prune();
           } else {
             EList<EObject> _eCrossReferences = eObject.eCrossReferences();
             for (final EObject eCrossReference : _eCrossReferences) {
               boolean _matched = false;
               if (!_matched) {
                 if (eCrossReference instanceof EClassifier) {
                   final EClassifier _eClassifier = (EClassifier) eCrossReference;
                   _matched = true;
                   final EPackage referencedEPackage = _eClassifier.getEPackage();
                   ePackages.add(referencedEPackage);
                   referencedEPackages.add(referencedEPackage);
                 }
               }
               if (!_matched) {
                 if (eCrossReference instanceof EStructuralFeature) {
                   final EStructuralFeature _eStructuralFeature =
                       (EStructuralFeature) eCrossReference;
                   _matched = true;
                   EClass _eContainingClass = _eStructuralFeature.getEContainingClass();
                   final EPackage referencedEPackage = _eContainingClass.getEPackage();
                   ePackages.add(referencedEPackage);
                   referencedEPackages.add(referencedEPackage);
                 }
               }
             }
           }
         }
         boolean _hasNext_1 = allContents.hasNext();
         _while_1 = _hasNext_1;
       }
     }
     int _size_1 = ePackages.size();
     boolean _lessThan_1 = (i < _size_1);
     _while = _lessThan_1;
   }
   for (final EPackage referencedEPackage : referencedEPackages) {
     GenPackage _findGenPackage = genModel.findGenPackage(referencedEPackage);
     boolean _equals = Objects.equal(_findGenPackage, null);
     if (_equals) {
       ToXcoreMapping _toXcoreMapping = this.mapper.getToXcoreMapping(referencedEPackage);
       XNamedElement _xcoreElement = _toXcoreMapping.getXcoreElement();
       GenBase _gen = this.mapper.getGen(_xcoreElement);
       GenPackage usedGenPackage = ((GenPackage) _gen);
       boolean _equals_1 = Objects.equal(usedGenPackage, null);
       if (_equals_1) {
         GenPackage _findLocalGenPackage = this.findLocalGenPackage(referencedEPackage);
         usedGenPackage = _findLocalGenPackage;
       }
       boolean _notEquals = (!Objects.equal(usedGenPackage, null));
       if (_notEquals) {
         EList<GenPackage> _usedGenPackages = genModel.getUsedGenPackages();
         _usedGenPackages.add(usedGenPackage);
       } else {
         Resource _eResource = genModel.eResource();
         ResourceSet _resourceSet = _eResource.getResourceSet();
         final EList<Resource> resources = _resourceSet.getResources();
         i = 0;
         boolean found = false;
         boolean _and = false;
         int _size_1 = resources.size();
         boolean _lessThan_1 = (i < _size_1);
         if (!_lessThan_1) {
           _and = false;
         } else {
           boolean _not = (!found);
           _and = (_lessThan_1 && _not);
         }
         boolean _while_1 = _and;
         while (_while_1) {
           {
             final Resource resource = resources.get(i);
             boolean _and_1 = false;
             URI _uRI = resource.getURI();
             String _fileExtension = _uRI.fileExtension();
             boolean _equals_2 = "genmodel".equals(_fileExtension);
             if (!_equals_2) {
               _and_1 = false;
             } else {
               EList<EObject> _contents = resource.getContents();
               boolean _isEmpty = _contents.isEmpty();
               boolean _not_1 = (!_isEmpty);
               _and_1 = (_equals_2 && _not_1);
             }
             if (_and_1) {
               EList<EObject> _contents_1 = resource.getContents();
               EObject _get = _contents_1.get(0);
               GenPackage _findGenPackage_1 = ((GenModel) _get).findGenPackage(referencedEPackage);
               usedGenPackage = _findGenPackage_1;
               boolean _notEquals_1 = (!Objects.equal(usedGenPackage, null));
               if (_notEquals_1) {
                 EList<GenPackage> _usedGenPackages_1 = genModel.getUsedGenPackages();
                 _usedGenPackages_1.add(usedGenPackage);
                 found = true;
               }
             }
             int _plus = (i + 1);
             i = _plus;
           }
           boolean _and_1 = false;
           int _size_2 = resources.size();
           boolean _lessThan_2 = (i < _size_2);
           if (!_lessThan_2) {
             _and_1 = false;
           } else {
             boolean _not_1 = (!found);
             _and_1 = (_lessThan_2 && _not_1);
           }
           _while_1 = _and_1;
         }
         boolean _not_1 = (!found);
         if (_not_1) {
           String _plus = ("No GenPackage found for " + referencedEPackage);
           RuntimeException _runtimeException = new RuntimeException(_plus);
           throw _runtimeException;
         }
       }
     }
   }
 }
예제 #10
0
 private static String getQualifiedName(final EPackage epackage, final ResourceSet resourceSet) {
   GenPackage _genPackage = GenModelUtil2.getGenPackage(epackage, resourceSet);
   return _genPackage.getQualifiedPackageInterfaceName();
 }
 private void collectGenPackagesRequiredPluginIDs(
     Collection<GenPackage> genPackages, Set<String> pluginIDs) {
   for (GenPackage nextPackage : genPackages) {
     pluginIDs.add(nextPackage.getGenModel().getModelPluginID());
   }
 }
 public static String getJhipsterPackageName(GenPackage genPackage) {
   String basePackage = genPackage.getInterfacePackageName();
   return basePackage.length() > 0 ? basePackage + ".jhpister" : "Jhipster";
 }
예제 #13
0
  public void propagateEOperations(JavaResource resource, GenClass genClass) {
    GenPackage genPackage = genClass.getGenPackage();
    EPackage ePackage = genPackage.getEcorePackage();
    if (resource.getContents().isEmpty()
        || !(resource.getContents().get(0) instanceof CompilationUnit)) {
      return;
    }
    CompilationUnit cu = (CompilationUnit) resource.getContents().get(0);
    Class customClass = (Class) cu.getClassifiers().get(0);
    EClass eClass = genClass.getEcoreClass();

    if (eClass == null) {
      return;
    }

    Set<Method> annotatedMethods = getAnnotatedMethods(customClass);

    for (Method method : annotatedMethods) {
      for (AnnotationInstanceOrModifier modifier : method.getAnnotationsAndModifiers()) {
        if (modifier instanceof Public) {
          EOperation newEOperation = EcoreFactory.eINSTANCE.createEOperation();
          newEOperation.setName(method.getName());
          Type opType = method.getTypeReference().getTarget();
          newEOperation.setEType(
              eClassifierForCustomClass(opType, method.getTypeReference(), ePackage));
          if (isMulti(opType)) {
            newEOperation.setUpperBound(-1);
          }
          for (Parameter parameter : method.getParameters()) {
            EParameter newEParameter = EcoreFactory.eINSTANCE.createEParameter();
            newEParameter.setName(parameter.getName());
            Type paramType = parameter.getTypeReference().getTarget();
            newEParameter.setEType(
                eClassifierForCustomClass(paramType, parameter.getTypeReference(), ePackage));
            // TODO generics, ...
            newEOperation.getEParameters().add(newEParameter);
          }
          // TODO @jendrik: why is that needed?
          //					for (AnnotationInstanceOrModifier annotationInstance :
          // method.getAnnotationsAndModifiers()) {
          //						if (annotationInstance instanceof AnnotationInstance) {
          //							Classifier javaAnnotation = ((AnnotationInstance)
          // annotationInstance).getAnnotation();
          //							if (javaAnnotation.eIsProxy()) {
          //								continue;
          //							}
          //							EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
          //							eAnnotation.setSource(javaAnnotation.getContainingCompilationUnit(
          //									).getNamespacesAsString() + javaAnnotation.getName());
          //							newEOperation.getEAnnotations().add(eAnnotation);
          //						}
          //					}
          boolean operationAlreadyExists = false;
          List<EOperation> operations = eClass.getEOperations();
          List<EOperation> existingOperations = new ArrayList<EOperation>(operations);
          // must be done here already for ensuring that compared operations have the same parent
          eClass.getEOperations().add(newEOperation);
          for (EOperation existingOperation : existingOperations) {
            boolean removed = removeAnnotation(existingOperation);
            if (EcoreUtil.equals(existingOperation, newEOperation)) {
              operationAlreadyExists = true;
              removeAnnotation(existingOperation);
              annotateAsGenerated(existingOperation);
              break;
            }
            if (removed) {
              annotateAsGenerated(existingOperation);
            }
          }
          if (!operationAlreadyExists) {
            annotateAsGenerated(newEOperation);
          } else {
            eClass.getEOperations().remove(newEOperation);
          }
          break;
        }
      }
    }

    try {
      Resource ecoreResource = ePackage.eResource();
      URI originalURI = ecoreResource.getURI();
      if (originalURI.isFile()) {
        String workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
        URI platformURI =
            URI.createPlatformResourceURI(
                originalURI.toFileString().substring(workspacePath.length()), true);
        ecoreResource.setURI(platformURI);
      }
      new ResourceSaver().saveResource(ecoreResource);
      ecoreResource.setURI(originalURI);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }