Example #1
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;
 }
 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;
 }
 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);
 }
  @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);
  }
  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;
         }
       }
     }
   }
 }
  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();
    }
  }