Пример #1
0
  public void dispose() {
    comparison = null;
    for (ResourceSet rs : resourceSets) {
      EList<Resource> resources = rs.getResources();
      for (Resource resource : resources) {
        TreeIterator<EObject> allContents = EcoreUtil.getAllProperContents(resource, false);
        while (allContents.hasNext()) {
          final EObject next = allContents.next();
          next.eAdapters().clear();
        }
        resource.eAdapters().clear();
      }

      rs.getResources().clear();
      rs.eAdapters().clear();
    }

    resourceSets = null;

    Job cleanJob =
        new Job("ClearWorkspace") {
          @Override
          protected IStatus run(IProgressMonitor monitor) {
            try {
              // Close & delete projects from workspace
              IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
              for (IProject project : projects) {
                project.close(new NullProgressMonitor());
                project.delete(false, new NullProgressMonitor());
              }
            } catch (CoreException e) {
              Throwables.propagate(e);
            }
            return Status.OK_STATUS;
          }
        };
    cleanJob.schedule();
    try {
      cleanJob.join();
    } catch (InterruptedException e) {
      Throwables.propagate(e);
    }

    if (repository != null) {
      repository.close();
      repository = null;
    }
    for (Runnable disposer : disposers) {
      disposer.run();
    }
    disposers.clear();

    // Delete repository from temp directory
    GitUtil.deleteRepo(repoFile);
  }
Пример #2
0
 public void testExternalFormOfEReference() throws Exception {
   Registry registry = EPackage.Registry.INSTANCE;
   Set<String> uris = Sets.newHashSet(registry.keySet());
   for (String string : uris) {
     EPackage ePackage = registry.getEPackage(string);
     TreeIterator<Object> iterator = EcoreUtil.getAllProperContents(ePackage, true);
     while (iterator.hasNext()) {
       Object next = iterator.next();
       if (next instanceof EReference) {
         EReference ref = (EReference) next;
         String externalForm = EcoreUtil2.toExternalForm(ref);
         assertEquals(
             ref.toString() + " - " + externalForm,
             ref,
             EcoreUtil2.getEReferenceFromExternalForm(registry, externalForm));
       }
     }
   }
 }
Пример #3
0
  protected ZombieStereotypesDescriptor getZombieStereotypes(Resource resource, Package root) {
    ZombieStereotypesDescriptor result = null;

    Collection<ProfileApplication> profileApplications = Lists.newArrayList();
    for (TreeIterator<EObject> iter =
            EcoreUtil.getAllProperContents(Collections.singleton(root), false);
        iter.hasNext(); ) {
      EObject next = iter.next();
      if (next instanceof ProfileApplication) {
        profileApplications.add((ProfileApplication) next);
        iter.prune();
      } else if (!(next instanceof Package) && !(next instanceof Component)) {
        // No sense looking for packages except in the things that can contain packages
        iter.prune();
      }
    }

    Set<EPackage> appliedDefinitions = getAppliedDefinitions(profileApplications);

    Function<? super EPackage, Profile> profileSupplier = dynamicProfileSupplier;
    if (profileSupplier == null) {
      profileSupplier = presenter.getDynamicProfileSupplier();
    }

    ZombieStereotypesDescriptor zombies =
        new ZombieStereotypesDescriptor(
            resource, root, appliedDefinitions, profileSupplier, getLabelProvider());

    for (EObject next : resource.getContents()) {
      if (!(next instanceof Element)) {
        zombies.analyze(next);
      }
    }

    if (zombies.hasZombies()) {
      result = zombies;
    }

    return result;
  }
Пример #4
0
  /**
   * Creates an iterable containing all the Papyrus Tables that are descending from the context.
   *
   * @author olivier melois (Atos)
   */
  public static Iterable<EObject> createDescendantTablesIterable(EObject context) {

    Set<EObject> result = Sets.newHashSet();

    TreeIterator<EObject> eAllContents =
        EcoreUtil.getAllProperContents(context, true); // was context.eAllContents().
    Iterator<EObject> contextAndDescendants =
        Iterators.concat(eAllContents, Iterators.singletonIterator(context));

    final Predicate<Setting> keepPapyrusTableInstances =
        new Predicate<Setting>() {

          public boolean apply(Setting setting) {
            boolean result = true;
            if (setting != null) {
              EObject settingEObject = setting.getEObject();
              result &= settingEObject instanceof PapyrusTableInstance;
              result &=
                  PapyrustableinstancePackage.Literals.PAPYRUS_TABLE_INSTANCE__TABLE
                      == setting.getEStructuralFeature();
            } else {
              result = false;
            }
            return result;
          }
        };

    /*
     * Predicate used to keep the usages which are PapyrusTableInstances
     */
    Predicate<Setting> keepTableInstances =
        new Predicate<Setting>() {

          public boolean apply(Setting setting) {
            boolean result = true;
            if (setting != null) {
              EObject settingEObject = setting.getEObject();
              result &= settingEObject instanceof TableInstance;
              result &=
                  setting.getEStructuralFeature()
                      == TableinstancePackage.Literals.TABLE_INSTANCE__CONTEXT;

              Collection<Setting> references = PapyrusEcoreUtils.getUsages(settingEObject);
              Iterable<Setting> papyrusTableInstances =
                  Iterables.filter(references, keepPapyrusTableInstances);
              // Veryfing that there is at least one papyrusTableInstance
              result = result && !Iterables.isEmpty(papyrusTableInstances);

            } else {
              result = false;
            }
            return result;
          }
        };

    /*
     * Function to get the eObject from a setting
     */
    Function<Setting, EObject> getEObject =
        new Function<Setting, EObject>() {

          public EObject apply(Setting input) {
            EObject settingEObject = input.getEObject();
            Collection<Setting> references = PapyrusEcoreUtils.getUsages(settingEObject);
            Iterable<Setting> papyrusTableInstances =
                Iterables.filter(references, keepPapyrusTableInstances);
            // Getting the eobject of thie first element of this iterable.
            return Iterables.get(papyrusTableInstances, 0).getEObject();
          }
        };

    /*
     * For the context and his descendants :
     */
    while (contextAndDescendants.hasNext()) {
      EObject current = contextAndDescendants.next();
      // Usages
      Iterable<Setting> usages = PapyrusEcoreUtils.getUsages(current);
      // Filtering to keep only papyrus table instances.
      Iterable<Setting> tableInstanceSettings = Iterables.filter(usages, keepTableInstances);
      // Getting the eObjects
      Iterable<EObject> papyrusTableInstances =
          Iterables.transform(tableInstanceSettings, getEObject);
      // Adding all the kept usages.
      Iterables.addAll(result, papyrusTableInstances);
    }

    return result;
  }