Exemple #1
0
 public Diagnostic generateGenModel(final GenModel genModel, final IFileSystemAccess fsa) {
   Diagnostic _xifexpression = null;
   String _modelDirectory = genModel.getModelDirectory();
   boolean _notEquals = (!Objects.equal(_modelDirectory, null));
   if (_notEquals) {
     Diagnostic _xblockexpression = null;
     {
       genModel.setCanGenerate(true);
       final XcoreGeneratorImpl generator = this.xcoreGeneratorImplProvider.get();
       generator.setInput(genModel);
       generator.setFileSystemAccess(fsa);
       String _modelDirectory_1 = genModel.getModelDirectory();
       generator.setModelDirectory(_modelDirectory_1);
       BasicMonitor _basicMonitor = new BasicMonitor();
       generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, _basicMonitor);
       BasicMonitor _basicMonitor_1 = new BasicMonitor();
       generator.generate(genModel, GenBaseGeneratorAdapter.EDIT_PROJECT_TYPE, _basicMonitor_1);
       BasicMonitor _basicMonitor_2 = new BasicMonitor();
       generator.generate(genModel, GenBaseGeneratorAdapter.EDITOR_PROJECT_TYPE, _basicMonitor_2);
       BasicMonitor _basicMonitor_3 = new BasicMonitor();
       Diagnostic _generate =
           generator.generate(
               genModel, GenBaseGeneratorAdapter.TESTS_PROJECT_TYPE, _basicMonitor_3);
       _xblockexpression = (_generate);
     }
     _xifexpression = _xblockexpression;
   }
   return _xifexpression;
 }
 public GenModel getGenModel(final XPackage pack) {
   XPackageMapping _mapping = this.mapper.getMapping(pack);
   final EPackage ePackage = _mapping.getEPackage();
   final GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
   Set<EPackage> _singleton = Collections.<EPackage>singleton(ePackage);
   genModel.initialize(_singleton);
   Resource _eResource = pack.eResource();
   EList<EObject> _contents = _eResource.getContents();
   _contents.add(1, genModel);
   this.buildMap(genModel);
   return genModel;
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 public EList<String> getAllRequiredPlugins() {
   Collection<String> rv = new LinkedHashSet<String>(getRequiredPlugins());
   if (getEditorGen() != null) {
     final GenModel genModel = getEditorGen().getDomainGenModel();
     if (genModel != null) {
       rv.add(genModel.getModelPluginID());
       rv.add(genModel.getEditPluginID());
       for (Iterator<GenPackage> it = genModel.getAllUsedGenPackagesWithClassifiers().iterator();
           it.hasNext(); ) {
         GenModel nextGenModel = it.next().getGenModel();
         if (nextGenModel.hasEditSupport()) {
           rv.add(nextGenModel.getModelPluginID());
           rv.add(nextGenModel.getEditPluginID());
         }
       }
     }
     rv.addAll(getExpressionsRequiredPluginIDs());
     rv.addAll(getValidationRequiredPluginIDs());
     rv.addAll(getMetricsRequiredPluginIDs());
     rv.addAll(getViewmapRequiredPluginIDs());
   }
   for (Iterator<String> it = rv.iterator(); it.hasNext(); ) {
     if (GenCommonBaseImpl.isEmpty(it.next())) {
       it.remove();
     }
   }
   return new BasicEList<String>(rv);
 }
 /** @generated NOT */
 public String getName() {
   String result = getNameGen();
   if (GenCommonBaseImpl.isEmpty(result)) {
     GenEditorGenerator generator = getEditorGen();
     if (generator != null) {
       String prefix = "Diagram Editor";
       GenModel genModel = generator.getDomainGenModel();
       if (genModel != null) {
         prefix = genModel.getModelName();
       }
       result = prefix + " Plugin";
     }
   }
   return result;
 }
Exemple #5
0
  public void invoke(IWorkflowContext ctx) {
    ResourceSet resSet = getResourceSet();
    Resource resource = resSet.getResource(URI.createURI(genModel), true);
    final GenModel genModel = (GenModel) resource.getContents().get(0);
    genModel.setCanGenerate(true);
    genModel.reconcile();
    createGenModelSetup().registerGenModel(genModel);

    Generator generator =
        new Generator() {
          @Override
          public JControlModel getJControlModel() {
            return new JControlModel() {
              @Override
              public boolean canMerge() {
                return false;
              }
            };
          }
        };
    log.info("generating EMF code for " + this.genModel);
    generator
        .getAdapterFactoryDescriptorRegistry()
        .addDescriptor(
            GenModelPackage.eNS_URI,
            new GeneratorAdapterDescriptor(getTypeMapper(), getLineDelimiter()));
    generator.setInput(genModel);

    Diagnostic diagnostic =
        generator.generate(
            genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, new BasicMonitor());

    if (diagnostic.getSeverity() != Diagnostic.OK) log.info(diagnostic);

    if (generateEdit) {
      Diagnostic editDiag =
          generator.generate(
              genModel, GenBaseGeneratorAdapter.EDIT_PROJECT_TYPE, new BasicMonitor());
      if (editDiag.getSeverity() != Diagnostic.OK) log.info(editDiag);
    }

    if (generateEditor) {
      Diagnostic editorDiag =
          generator.generate(
              genModel, GenBaseGeneratorAdapter.EDITOR_PROJECT_TYPE, new BasicMonitor());
      if (editorDiag.getSeverity() != Diagnostic.OK) log.info(editorDiag);
    }
  }
Exemple #6
0
 public void executeTransformation(IExecutionInformation executionInformation) throws Exception {
   ResourceSet resourceSet = new ResourceSetImpl();
   Resource resource =
       resourceSet.createResource(locator.getEMFURI(inputModels.get(0).getModel()));
   resource.load(null);
   EcoreUtil.resolveAll(resourceSet);
   GenModel genModel = (GenModel) resource.getContents().get(0);
   genModel.setCanGenerate(true);
   // generate the code
   Generator generator = new Generator();
   generator.setInput(genModel);
   generator.generate(
       genModel,
       GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE,
       new BasicMonitor.Printing(System.err));
   for (File file : outputFiles) {
     executionEnvironment.fileReady(file, transformation);
   }
 }
Exemple #7
0
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();

    /**
     * Copyright (c) 2005 IBM Corporation and others. All rights reserved. This program and the
     * accompanying materials are made available under the terms of the Eclipse Public License v1.0
     * which accompanies this distribution, and is available at
     * http://www.eclipse.org/legal/epl-v10.html
     *
     * <p>Contributors: IBM - Initial API and implementation
     */
    GenModel genModel = (GenModel) argument; /* Trick to import java.util.* without warnings */
    Iterator.class.getName();
    stringBuffer.append(TEXT_1);
    stringBuffer.append(TEXT_2);
    stringBuffer.append(TEXT_3);
    {
      GenBase copyrightHolder =
          argument instanceof GenBase
              ? (GenBase) argument
              : argument instanceof Object[] && ((Object[]) argument)[0] instanceof GenBase
                  ? (GenBase) ((Object[]) argument)[0]
                  : null;
      if (copyrightHolder != null && copyrightHolder.hasCopyright()) {
        stringBuffer.append(TEXT_4);
        stringBuffer.append(
            copyrightHolder.getCopyright(
                copyrightHolder.getGenModel().getIndentation(stringBuffer)));
      }
    }
    stringBuffer.append(TEXT_5);
    if (genModel.isBundleManifest()) {
      stringBuffer.append(TEXT_6);
    } else {
      stringBuffer.append(TEXT_7);
      stringBuffer.append(genModel.getTestsPluginID());
      stringBuffer.append(TEXT_8);
      for (String pluginID : genModel.getTestsRequiredPlugins()) {
        stringBuffer.append(TEXT_9);
        stringBuffer.append(pluginID);
        stringBuffer.append(TEXT_10);
        if (!pluginID.startsWith("org.eclipse.core.runtime")) {
          stringBuffer.append(TEXT_11);
        }
        stringBuffer.append(TEXT_12);
      }
      stringBuffer.append(TEXT_13);
      if (genModel.isRuntimeJar()) {
        stringBuffer.append(TEXT_14);
        stringBuffer.append(genModel.getTestsPluginID());
        stringBuffer.append(TEXT_15);
      } else {
        stringBuffer.append(TEXT_16);
      }
      stringBuffer.append(TEXT_17);
    }
    stringBuffer.append(TEXT_18);
    stringBuffer.append(TEXT_19);
    return stringBuffer.toString();
  }
  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 VirtualFile generate(VirtualFile basedir) throws DatabaseException {
    GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
    genModel.setRuntimeVersion(GenRuntimeVersion.EMF25);
    genModel.setComplianceLevel(GenJDKLevel.JDK60_LITERAL);
    genModel.setFeatureDelegation(GenDelegationKind.REFLECTIVE_LITERAL);
    genModel.setRootExtendsClass("org.bimserver.emf.IdEObjectImpl");
    genModel.setRootExtendsInterface("org.bimserver.emf.IdEObject");
    genModel.setSuppressContainment(true);
    genModel.setCodeFormatting(true);
    genModel.setCopyrightText(StringUtils.readFromFile(new File("copyright.txt")));
    genModel.setCanGenerate(true);
    genModel.setModelDirectory("test");
    genModel.setModelName("model name");
    genModel.setForceOverwrite(true);
    genModel.setSuppressNotification(false);
    genModel.setContainmentProxies(false);
    genModel.setBinaryCompatibleReflectiveMethods(false);
    genModel.setPublicConstructors(false);
    genModel.setMinimalReflectiveMethods(true); // More code, but faster
    genModel.setUpdateClasspath(false);

    genModel.initialize(schema.getEPackages());

    GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor(
        GenModelPackage.eNS_URI, GenModelGeneratorAdapterFactory.DESCRIPTOR);
    Generator generator = new Generator();
    generator.setInput(genModel);
    generator.generate(
        genModel,
        GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE,
        new BasicMonitor.Printing(System.out));

    //		List<GenPackage> genPackages = createGenPackages(genModel, basedir);
    //		generatePackages(genModel, genPackages, basedir);

    return basedir;
  }
 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();
 }
  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;
  }
Exemple #12
0
  public void testBug370824() throws Exception {
    if (EMFPlugin.IS_ECLIPSE_RUNNING) {
      IWorkspace workspace = ResourcesPlugin.getWorkspace();
      IProject project = workspace.getRoot().getProject("org.eclipse.ocl.examples.xtext.tests");
      if (!project.exists()) {
        project.create(null);
      }
    }
    metaModelManager = new MetaModelManager();
    String oclinecoreFile =
        "package bug370824 : bug370824 = 'http://bug370824'\n"
            + "{\n"
            + "    class Clase1\n"
            + "    {\n"
            + "        invariant : self.name.size() > 0;\n"
            + "        attribute name : String[?] { ordered };\n"
            + "    }\n"
            + "}\n";
    createEcoreFile(metaModelManager, "Bug370824", oclinecoreFile);
    String genmodelFile =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<genmodel:GenModel xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\"\n"
            + "    xmlns:genmodel=\"http://www.eclipse.org/emf/2002/GenModel\" modelDirectory=\"/org.eclipse.ocl.examples.xtext.tests/src-gen\" modelPluginID=\"org.eclipse.ocl.examples.xtext.tests.bug370824\"\n"
            + "    modelName=\"Bug370824\" importerID=\"org.eclipse.emf.importer.ecore\" complianceLevel=\"5.0\"\n"
            + "    copyrightFields=\"false\">\n"
            + "  <foreignModel>Bug370824.ecore</foreignModel>\n"
            + "  <genPackages prefix=\"Bug370824\" disposableProviderFactory=\"true\" ecorePackage=\"Bug370824.ecore#/\">\n"
            + "  </genPackages>\n"
            + "</genmodel:GenModel>\n"
            + "\n";
    createGenModelFile("Bug370824.genmodel", genmodelFile);
    GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor(
        GenModelPackage.eNS_URI, OCLGeneratorAdapterFactory.DESCRIPTOR);
    URI fileURI = getProjectFileURI("Bug370824.genmodel");
    //		System.out.println("Generating Ecore Model using '" + fileURI + "'");
    metaModelManager.dispose();
    metaModelManager = new MetaModelManager();
    ResourceSet resourceSet = metaModelManager.getExternalResourceSet();
    resourceSet.getPackageRegistry().put(GenModelPackage.eNS_URI, GenModelPackage.eINSTANCE);
    resourceSet
        .getResourceFactoryRegistry()
        .getExtensionToFactoryMap()
        .put("genmodel", new EcoreResourceFactoryImpl());
    GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor(
        GenModelPackage.eNS_URI, GenModelGeneratorAdapterFactory.DESCRIPTOR);
    GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor(
        GenModelPackage.eNS_URI, OCLGeneratorAdapterFactory.DESCRIPTOR);
    if (resourceSet instanceof ResourceSetImpl) {
      ResourceSetImpl resourceSetImpl = (ResourceSetImpl) resourceSet;
      Map<URI, Resource> uriResourceMap = resourceSetImpl.getURIResourceMap();
      if (uriResourceMap != null) {
        uriResourceMap.clear();
      }
    }
    resourceSet.getResources().clear();
    Resource resource = resourceSet.getResource(fileURI, true);
    // EcoreUtil.resolveAll(resourceSet); -- genModel can fail if
    // proxies resolved here
    // problem arises if genmodel has an obsolete feature for a feature
    // moved up the inheritance hierarchy
    // since the proxy seems to be successfully resolved giving a double
    // feature
    checkResourceSet(resourceSet);
    EObject eObject = resource.getContents().get(0);
    if (!(eObject instanceof GenModel)) {
      throw new ConfigurationException("No GenModel found in '" + resource.getURI() + "'");
    }
    GenModel genModel = (GenModel) eObject;
    genModel.reconcile();
    checkResourceSet(resourceSet);
    // genModel.setCanGenerate(true);
    // validate();

    genModel.setValidateModel(true); // The more checks the better
    //		genModel.setCodeFormatting(true); // Normalize layout
    genModel.setForceOverwrite(false); // Don't overwrite read-only
    // files
    genModel.setCanGenerate(true);
    // genModel.setFacadeHelperClass(null); // Non-null gives JDT
    // default NPEs
    //		genModel.setFacadeHelperClass(StandaloneASTFacadeHelper.class.getName()); // Bug 308069
    // genModel.setValidateModel(true);
    genModel.setBundleManifest(false); // New manifests should be
    // generated manually
    genModel.setUpdateClasspath(false); // New class-paths should be
    // generated manually
    genModel.setComplianceLevel(GenJDKLevel.JDK50_LITERAL);
    // genModel.setRootExtendsClass("org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container");
    Diagnostic diagnostic = genModel.diagnose();
    if (diagnostic.getSeverity() != Diagnostic.OK) {
      fail(diagnostic.toString());
    }

    /*
     * JavaModelManager.getJavaModelManager().initializePreferences();
     * new
     * JavaCorePreferenceInitializer().initializeDefaultPreferences();
     *
     * GenJDKLevel genSDKcomplianceLevel =
     * genModel.getComplianceLevel(); String complianceLevel =
     * JavaCore.VERSION_1_5; switch (genSDKcomplianceLevel) { case
     * JDK60_LITERAL: complianceLevel = JavaCore.VERSION_1_6; case
     * JDK14_LITERAL: complianceLevel = JavaCore.VERSION_1_4; default:
     * complianceLevel = JavaCore.VERSION_1_5; } // Hashtable<?,?>
     * defaultOptions = JavaCore.getDefaultOptions(); //
     * JavaCore.setComplianceOptions(complianceLevel, defaultOptions);
     * // JavaCore.setOptions(defaultOptions);
     */

    Generator generator = GenModelUtil.createGenerator(genModel);
    Monitor monitor = new BasicMonitor();
    diagnostic = generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, monitor);
    if (diagnostic.getSeverity() != Diagnostic.OK) {
      fail(diagnostic.toString());
    }
  }
 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;
         }
       }
     }
   }
 }
Exemple #14
0
 /** Adds an import. */
 public void addImport(EObject caller, String qualifiedName) {
   GenModel genModel = getGenModel(caller);
   genModel.addImport(qualifiedName);
 }
Exemple #15
0
 /**
  * Initializing EMF importManager on a genmodel. To fix call of import manager in a genmodel which
  * is not the genmodel used by the default import manager
  */
 public void initializeImportManagerForGenmodel(
     EObject caller, GenModel model, String packageName, String className) {
   ImportManager importManager = new ImportManager(packageName, className);
   model.setImportManager(importManager);
 }