예제 #1
0
 public static void removeProxy(EObject root, Resource res) {
   Iterator iter = root.eAllContents();
   while (iter.hasNext()) {
     doRemoveProxy((InternalEObject) iter.next(), res);
   }
   doRemoveProxy((InternalEObject) root, res);
 }
  public void enrich(EObject model, Element e) {
    String defaultNamespace = e.getAttribute("base");
    sigNodeMap = createMapping(theoryXPath, e, "name");
    viewNodeMap = createMapping(viewXPath, e, "name");
    sigObjMap = new HashMap<String, EObject>();
    viewObjMap = new HashMap<String, EObject>();

    TreeIterator<EObject> iter = model.eAllContents();
    while (iter.hasNext()) {
      EObject obj = iter.next();
      if (obj instanceof signatureDeclaration) {
        signatureDeclaration sig = (signatureDeclaration) obj;
        if (sigNodeMap.containsKey(sig.getSigName())) {
          sigObjMap.put(sig.getSigName(), obj);
          Element elem = sigNodeMap.get(sig.getSigName());
          String bs = defaultNamespace;
          if (elem.hasAttribute("base")) bs = elem.getAttribute("base");
          sig.setFullURI(bs + "?" + sig.getSigName());
          syncConstructs(sig.getDefs().getConstucts(), elem);
        }
      }
      if (obj instanceof viewDeclaration) {
        viewDeclaration view = (viewDeclaration) obj;
        if (viewNodeMap.containsKey(view.getViewID())) {
          Element elem = sigNodeMap.get(view.getViewID());
          viewObjMap.put(view.getViewID(), obj);
          String bs = defaultNamespace;
          if (elem.hasAttribute("base")) bs = elem.getAttribute("base");
          view.setFullURI(bs + "?" + view.getViewID());
          syncConstructs(view.getViewDefs().getConstucts(), elem);
        }
      }
    }
  }
  protected static EObject load(org.eclipse.emf.common.util.URI uri) {
    // ResourceSet resourceSet = new ResourceSetImpl();
    // UMLResourcesUtil.init(resourceSet); // MDT/UML2 4.0.0 (Juno)
    Resource resource = new XMIResourceImpl(uri);
    EPackage.Registry packageRegistry = EPackage.Registry.INSTANCE;

    try {
      System.out.println(resource);
      resource.load(null);
    } catch (IOException ioe) {
      System.err.println(ioe.getMessage());
    }
    System.out.println(resource.getContents().size());
    Iterator<EObject> it = resource.getAllContents();
    while (it.hasNext()) {
      EObject o = it.next();
      if (o instanceof Activity) {
        System.out.println(o);
        Iterator<EObject> it2 = o.eAllContents();
        while (it2.hasNext()) {
          EObject o2 = it2.next();
          System.out.println("\t" + o2);
        }
      }
    }
    return resource.getContents().get(0);
  }
 /**
  * Retrieves all children, direct and indirect, and returns them as a set. The <code>amountOfWork
  * </code> for the progress monitor is also computed in this method.
  *
  * @param root the root EObject of the hierarchy
  * @return all direct and indirect contents of <code>root</code>
  */
 protected static Set<EObject> getAllChildren(EObject root) {
   TreeIterator<EObject> allContents = root.eAllContents();
   Set<EObject> result = new LinkedHashSet<EObject>();
   while (allContents.hasNext()) {
     result.add(allContents.next());
     // count every element three times: once for deletion,
     // once for setting attributes, once for setting references
     amountOfWork += 3;
   }
   return result;
 }
 /**
  * Adds the given object and all its children to the interpretation stack such that they are
  * interpret in top down order.
  */
 public void addObjectTreeToInterpreteTopDown(org.eclipse.emf.ecore.EObject root) {
   java.util.List<org.eclipse.emf.ecore.EObject> objects =
       new java.util.ArrayList<org.eclipse.emf.ecore.EObject>();
   objects.add(root);
   java.util.Iterator<org.eclipse.emf.ecore.EObject> it = root.eAllContents();
   while (it.hasNext()) {
     org.eclipse.emf.ecore.EObject eObject = (org.eclipse.emf.ecore.EObject) it.next();
     objects.add(eObject);
   }
   addObjectsToInterpreteInReverseOrder(objects);
 }
예제 #6
0
 /**
  * Allows to construct a scope based on a single {@link EObject}. The constructed scope will
  * include the provided {@link EObject}, its direct and indirect contents ({@link
  * EObject#eAllContents()}) as well as its resource ({@link EObject#eResource}) in case one is
  * specified.
  *
  * @param eObject the {@link EObject} used to construct the scope.
  */
 public GenericMatchScope(EObject eObject) {
   eObjectsInScope.add(eObject);
   final Iterator<EObject> iterator = eObject.eAllContents();
   while (iterator.hasNext()) {
     final EObject next = iterator.next();
     eObjectsInScope.add(next);
     if (next.eResource() != null && !resourcesInScope.contains(next.eResource())) {
       resolveAll(next.eResource().getResourceSet());
       resourcesInScope.add(next.eResource());
     }
   }
 }
 /**
  * Returns the {@link EPackage} with the given name, contained by the given root.
  *
  * @param name the name of the searched EPackage
  * @param root the root in which search the EPackage
  * @return the {@link EPackage} with the given name, contained by the given root, or null if no
  *     EPackage has been found
  */
 protected EObject findPackageNamed(final String name, final EObject root) {
   final TreeIterator<EObject> iter = root.eAllContents();
   while (iter.hasNext()) {
     final EObject current = iter.next();
     if (current instanceof EPackage
         && ((EPackage) current).getName() != null
         && ((EPackage) current).getName().equals(name)) {
       return current;
     }
   }
   return null;
 }
 /**
  * Check the '.emtl' file and report in the '.mtl' file some syntax errors when we use the
  * non-standard library.
  *
  * @param iFile is the '.mtl' file
  * @param oURI is the URI of the '.emtl' file
  */
 private void checkFullOMGCompliance(File iFile, URI oURI) {
   try {
     AcceleoSourceBuffer buffer = new AcceleoSourceBuffer(iFile);
     ResourceSet oResourceSet = new ResourceSetImpl();
     EObject oRoot = ModelUtils.load(oURI, oResourceSet);
     TreeIterator<EObject> oAllContents = oRoot.eAllContents();
     while (oAllContents.hasNext()) {
       EObject oNext = oAllContents.next();
       if (oNext instanceof OperationCallExp) {
         OperationCallExp oOperationCallExp = (OperationCallExp) oNext;
         if (oOperationCallExp.getReferredOperation() != null
             && oOperationCallExp.getReferredOperation().getEAnnotation("MTL non-standard")
                 != null) { //$NON-NLS-1$
           IFile workspaceFile =
               ResourcesPlugin.getWorkspace()
                   .getRoot()
                   .getFileForLocation(new Path(iFile.getAbsolutePath()));
           if (workspaceFile != null
               && workspaceFile.isAccessible()
               && oOperationCallExp.getStartPosition() > -1) {
             int line = buffer.getLineOfOffset(oOperationCallExp.getStartPosition());
             AcceleoMarkerUtils.createMarkerOnFile(
                 AcceleoMarkerUtils.PROBLEM_MARKER_ID,
                 workspaceFile,
                 line,
                 oOperationCallExp.getStartPosition(),
                 oOperationCallExp.getEndPosition(),
                 AcceleoUIMessages.getString(
                     "AcceleoCompileOperation.NotFullyCompliant",
                     oOperationCallExp //$NON-NLS-1$
                         .getReferredOperation()
                         .getName()));
           }
         }
       }
     }
   } catch (IOException e) {
     Status status = new Status(IStatus.WARNING, AcceleoUIActivator.PLUGIN_ID, e.getMessage(), e);
     AcceleoUIActivator.getDefault().getLog().log(status);
   } catch (CoreException e) {
     AcceleoUIActivator.getDefault().getLog().log(e.getStatus());
   }
 }
 /**
  * This standard implementation searches the tree for objects of the correct type with a name
  * attribute matching the identifier.
  */
 protected void resolve(
     String identifier,
     ContainerType container,
     org.eclipse.emf.ecore.EReference reference,
     int position,
     boolean resolveFuzzy,
     ssl.resource.ssl.ISslReferenceResolveResult<ReferenceType> result) {
   try {
     org.eclipse.emf.ecore.EClass type = reference.getEReferenceType();
     org.eclipse.emf.ecore.EObject root =
         ssl.resource.ssl.util.SslEObjectUtil.findRootContainer(container);
     // first check whether the root element matches
     boolean continueSearch = checkElement(root, type, identifier, resolveFuzzy, true, result);
     if (!continueSearch) {
       return;
     }
     // then check the contents
     for (java.util.Iterator<org.eclipse.emf.ecore.EObject> iterator = root.eAllContents();
         iterator.hasNext(); ) {
       org.eclipse.emf.ecore.EObject element = iterator.next();
       continueSearch = checkElement(element, type, identifier, resolveFuzzy, true, result);
       if (!continueSearch) {
         return;
       }
     }
     org.eclipse.emf.ecore.resource.Resource resource = container.eResource();
     if (resource != null) {
       org.eclipse.emf.common.util.URI uri = getURI(identifier, resource.getURI());
       if (uri != null) {
         org.eclipse.emf.ecore.EObject element =
             loadResource(container.eResource().getResourceSet(), uri);
         if (element == null) {
           return;
         }
         checkElement(element, type, identifier, resolveFuzzy, false, result);
       }
     }
   } catch (java.lang.RuntimeException rte) {
     // catch exception here to prevent EMF proxy resolution from swallowing it
     rte.printStackTrace();
   }
 }
예제 #10
0
 /**
  * Returns all direct and indirect contents of <code>rootObject</code> as a map. All EObjects that
  * appear in these contents are mapped to their corresponding EClass.
  *
  * @param rootObject the EObject to get contents for
  * @return all contents as a map from EClass to lists of EObjects
  */
 public static Map<EClass, List<EObject>> getAllClassesAndObjects(EObject rootObject) {
   // initialize the computation process
   Map<EClass, List<EObject>> result = new LinkedHashMap<EClass, List<EObject>>();
   TreeIterator<EObject> allContents = rootObject.eAllContents();
   List<EObject> newList = new LinkedList<EObject>();
   newList.add(rootObject);
   result.put(rootObject.eClass(), newList);
   // iterate over all direct and indirect contents
   while (allContents.hasNext()) {
     EObject eObject = allContents.next();
     // did this EObject's EClass appear before?
     if (result.containsKey(eObject.eClass())) {
       result.get(eObject.eClass()).add(eObject);
     } else {
       newList = new LinkedList<EObject>();
       newList.add(eObject);
       result.put(eObject.eClass(), newList);
     }
   }
   return result;
 }
  public Collection<EObject> getParticipants(EObject root, Object[] participantsTypes) {

    List<Object> participantsTypesList = Arrays.asList(participantsTypes);
    List<EObject> results = new ArrayList<EObject>();

    // Evaluate root...
    if (participantsTypesList.contains(root.eClass())) {
      results.add(root);
    }

    // ... and all its content
    TreeIterator<EObject> it = root.eAllContents();
    while (it.hasNext()) {
      EObject modelElement = (EObject) it.next();
      // Check that metaclass of this element is a supported metaclass
      if (participantsTypesList.contains(modelElement.eClass())) {
        results.add(modelElement);
      }
    }

    return results;
  }
  /** {@inheritDoc} */
  @Override
  protected ICommand getBeforeDuplicateCommand(DuplicateElementsRequest request) {
    Object additional =
        request.getParameter(IPapyrusDuplicateCommandConstants.ADDITIONAL_DUPLICATED_ELEMENTS);
    // additional element should be a set of elements that will be duplicated. If this is null, the
    // request will be ignored.
    if (!(additional instanceof Set<?>)) {
      return super.getBeforeDuplicateCommand(request);
    }

    Set<Object> duplicatedObjects = ((Set<Object>) additional);
    EObject object = getDuplicatedEObject(request);
    if (object == null || object.eResource() == null) {
      return super.getBeforeDuplicateCommand(request);
    }

    // retrieve the Tables linked to the object
    List<Table> tablesToDuplicate = new ArrayList<Table>();

    ResourceSet resourceSet = object.eResource().getResourceSet();
    ECrossReferenceAdapter adapter = ECrossReferenceAdapter.getCrossReferenceAdapter(resourceSet);
    if (adapter == null) {
      adapter = new ECrossReferenceAdapter();
      resourceSet.eAdapters().add(adapter);
    }

    // do not proceed for graphical elements, which will have evident relationships to Diagrams
    // (owner, etc.)
    // not required for Table
    //		if(object instanceof View) {
    //			return super.getBeforeDuplicateCommand(request);
    //		}

    // check for the element itself
    Collection<Setting> settings = adapter.getInverseReferences(object, false);
    for (Setting setting : settings) {
      EObject value = setting.getEObject();
      if (value instanceof Table) {
        tablesToDuplicate.add((Table) value);
      }
    }

    // check for sub-elements
    for (Iterator<EObject> it = object.eAllContents(); it.hasNext(); ) {
      EObject child = it.next();
      settings = adapter.getInverseReferences(child, false);

      for (Setting setting : settings) {
        EObject value = setting.getEObject();
        if (value instanceof Table) {
          tablesToDuplicate.add((Table) value);
        }
      }
    }

    if (!tablesToDuplicate.isEmpty()) {
      CompositeCommand command = null;
      // create the command for all the Tables that have no command ready
      for (Table TableToDuplicate : tablesToDuplicate) {
        if (!duplicatedObjects.contains(TableToDuplicate)) {
          if (command == null) {
            command =
                new CompositeCommand(
                    "",
                    Arrays.asList(
                        new DuplicateTableCommand(
                            request.getEditingDomain(),
                            "Duplicate Table",
                            TableToDuplicate,
                            request.getAllDuplicatedElementsMap()))); // $NON-NLS-1$ //$NON-NLS-2$
          } else {
            command.add(
                new DuplicateTableCommand(
                    request.getEditingDomain(),
                    "Duplicate Table",
                    TableToDuplicate,
                    request.getAllDuplicatedElementsMap())); // $NON-NLS-1$
          }
          duplicatedObjects.add(TableToDuplicate);
        }
      }

      if (command != null) {
        if (super.getBeforeDuplicateCommand(request) != null) {
          command.add(super.getBeforeDuplicateCommand(request));
          return command.reduce();
        } else {
          return command.reduce();
        }
      }
    }

    return super.getBeforeDuplicateCommand(request);
  }
예제 #13
0
파일: Ecore2AS.java 프로젝트: eclipse/ocl
 public void update(@NonNull Resource asResource, @NonNull Collection<EObject> ecoreContents) {
   newCreateMap = new HashMap<@NonNull EObject, @NonNull Element>();
   referencers = new HashSet<@NonNull EObject>();
   genericTypes = new ArrayList<@NonNull EGenericType>();
   PivotUtilInternal.refreshList(
       asResource.getContents(), Collections.singletonList(ClassUtil.nonNull(pivotModel)));
   List<org.eclipse.ocl.pivot.Package> newPackages =
       new ArrayList<org.eclipse.ocl.pivot.Package>();
   for (EObject eObject : ecoreContents) {
     EClass eClass = eObject.eClass();
     if (eClass.getEPackage() != EcorePackage.eINSTANCE) {
       error("Non Ecore " + eClass.getName() + " for Ecore2AS.update");
     } else {
       Object pivotElement = declarationPass.doInPackageSwitch(eObject);
       if (pivotElement instanceof org.eclipse.ocl.pivot.Package) {
         newPackages.add((org.eclipse.ocl.pivot.Package) pivotElement);
       } else {
         error("Bad ecore content");
       }
     }
   }
   PivotUtilInternal.refreshList(pivotModel.getOwnedPackages(), newPackages);
   Map<@NonNull String, @NonNull Type> resolvedSpecializations =
       new HashMap<@NonNull String, @NonNull Type>();
   for (@NonNull EGenericType eGenericType : genericTypes) {
     Type pivotType = resolveType(resolvedSpecializations, eGenericType);
     if (pivotType != null) {
       newCreateMap.put(eGenericType, pivotType);
     }
   }
   for (EObject eObject : referencers) {
     referencePass.doInPackageSwitch(eObject);
   }
   for (EObject eObject : referencers) {
     if (eObject instanceof EReference) {
       Property pivotElement = getCreated(Property.class, eObject);
       if (pivotElement != null) {
         Property oppositeProperty = pivotElement.getOpposite();
         if ((oppositeProperty == null)
             && (eObject.eContainer() instanceof EClass)) { // Skip annotation references
           metamodelManager.installPropertyDeclaration(pivotElement);
         }
       }
     }
   }
   referencers = null;
   genericTypes = null;
   oldIdMap = new HashMap<@NonNull String, @NonNull Element>();
   for (EObject ecoreContent : ecoreContents) {
     Resource resource = ecoreContent.eResource();
     if (resource instanceof XMLResource) {
       XMLResource xmlResource = (XMLResource) resource;
       String id = xmlResource.getID(ecoreContent);
       if (id != null) {
         Element element = newCreateMap.get(ecoreContent);
         if (element != null) {
           oldIdMap.put(id, element);
         }
       }
       for (TreeIterator<EObject> tit = ecoreContent.eAllContents(); tit.hasNext(); ) {
         EObject eObject = tit.next();
         id = xmlResource.getID(eObject);
         if (id != null) {
           Element element = newCreateMap.get(eObject);
           if (element != null) {
             oldIdMap.put(id, element);
           }
         }
       }
     }
   }
 }