예제 #1
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;
  }
  /** Test case in which we choose to delete the stereotypes. */
  @Test
  @PluginResource("/resources/wrongProfileVersion/model.uml")
  public void deleteStereotypes() {
    assertThat("Should have found zombie stereotypes", zombies, notNullValue());

    EPackage schema = getOnlyZombieSchema();

    IRepairAction action = zombies.getRepairAction(schema, IRepairAction.Kind.DELETE);
    assertThat("Wrong repair action", action.kind(), is(IRepairAction.Kind.DELETE));

    repair(schema, action);

    assertThat("Stereotypes not deleted.", modelSet.getModelResource().getContents().size(), is(1));
  }
  /**
   * Test case in which the profile application and schema location are present but reference a
   * non-existent resource. We just have to link up with the profile definition and apply it and
   * parse unknown-schema AnyTypes to reconstruct stereotypes.
   */
  @Test
  @PluginResource("/resources/missingSchema/model.uml")
  public void missingSchema() {
    assertThat("Should have found zombie stereotypes", zombies, notNullValue());

    EPackage schema = getOnlyZombieSchema();
    assertThat(
        "EPackage is not an unknown schema",
        getExtendedMetadata().demandedPackages(),
        hasItem(schema));

    IRepairAction action = zombies.getSuggestedRepairAction(schema);
    assertThat(
        "Wrong suggested repair action",
        action.kind(),
        is(IRepairAction.Kind.APPLY_LATEST_PROFILE_DEFINITION));

    repair(schema, action);
    assertStereotypeApplication();
  }
  /**
   * Test case in which the profile application is not missing, and the EPackage schema is
   * successfully resolved by EMF, but the stereotype applications are from a different version of
   * the profile than is currently applied.
   */
  @Test
  @PluginResource("/resources/wrongProfileVersion/model.uml")
  public void wrongProfileVersion() {
    assertThat("Should have found zombie stereotypes", zombies, notNullValue());

    EPackage schema = getOnlyZombieSchema();
    assertThat(
        "Did not match schema to loaded profile",
        EcoreUtil.getRootContainer(schema),
        is((EObject) profile));
    assertThat(
        "EPackage is an unknown schema",
        getExtendedMetadata().demandedPackages(),
        not(hasItem(schema)));

    IRepairAction action = zombies.getSuggestedRepairAction(schema);
    assertThat(
        "Wrong suggested repair action",
        action.kind(),
        is(IRepairAction.Kind.APPLY_LATEST_PROFILE_DEFINITION));

    repair(schema, action);
    assertStereotypeApplication();
  }
 EPackage getOnlyZombieSchema() {
   Collection<? extends EPackage> schemata = zombies.getZombiePackages();
   assertThat("Wrong number of zombie packages", schemata.size(), is(1));
   return schemata.iterator().next();
 }