diff options
| author | Christian W. Damus | 2017-01-08 13:06:48 +0000 |
|---|---|---|
| committer | Christian W. Damus | 2017-01-08 17:37:12 +0000 |
| commit | 2cd598712ef7b41ccf640abf2efc7f4221d187d7 (patch) | |
| tree | e989b3cab73caa8727e9044ab6b1682a5892516a | |
| parent | 061b62a07bb9d566655fbb6172a20e2b037d145d (diff) | |
| download | org.eclipse.papyrus-rt-2cd598712ef7b41ccf640abf2efc7f4221d187d7.tar.gz org.eclipse.papyrus-rt-2cd598712ef7b41ccf640abf2efc7f4221d187d7.tar.xz org.eclipse.papyrus-rt-2cd598712ef7b41ccf640abf2efc7f4221d187d7.zip | |
Bug 467545: [UML-RT] PapyrusRT shall provide a UML specific implementation to support redefinition
Refactor the InheritanceKind enumeration into the façade API and rationalize
some of the API terminology related to it in the UMLRTNamedElement.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=467545
Change-Id: I18c9e14943203436bfe1905af02b242e749adf2e
| -rw-r--r-- | plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/UMLRTInheritanceKind.java (renamed from plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/util/InheritanceKind.java) | 20 | ||||
| -rw-r--r-- | plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/UMLRTNamedElement.java | 79 | ||||
| -rw-r--r-- | tests/junit/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml.tests/src/org/eclipse/papyrusrt/umlrt/uml/tests/InheritanceKindTest.java (renamed from tests/junit/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml.tests/src/org/eclipse/papyrusrt/umlrt/uml/util/tests/InheritanceKindTest.java) | 20 |
3 files changed, 71 insertions, 48 deletions
diff --git a/plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/util/InheritanceKind.java b/plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/UMLRTInheritanceKind.java index d5301e702..061559b18 100644 --- a/plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/util/InheritanceKind.java +++ b/plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/UMLRTInheritanceKind.java @@ -11,17 +11,17 @@ * *****************************************************************************/ -package org.eclipse.papyrusrt.umlrt.uml.util; +package org.eclipse.papyrusrt.umlrt.uml; import java.util.Comparator; -import org.eclipse.papyrusrt.umlrt.uml.UMLRTNamedElement; +import org.eclipse.papyrusrt.umlrt.uml.util.UMLRTExtensionUtil; import org.eclipse.uml2.uml.Element; /** * Enumeration of the possible inheritance states of an element in an UML-RT model. */ -public enum InheritanceKind { +public enum UMLRTInheritanceKind { /** The element is inherited from another namespace and not redefined. */ INHERITED, /** The element is inherited from another namespace and is locally redefined. */ @@ -39,8 +39,8 @@ public enum InheritanceKind { * * @return its inheritance kind: never {@code null}, but maybe {@link #NONE} */ - public static InheritanceKind of(Element element) { - InheritanceKind result = NONE; + public static UMLRTInheritanceKind of(Element element) { + UMLRTInheritanceKind result = NONE; if (UMLRTExtensionUtil.isInherited(element)) { if (UMLRTExtensionUtil.isVirtualElement(element)) { @@ -63,8 +63,12 @@ public enum InheritanceKind { * * @return its inheritance kind: never {@code null}, but maybe {@link #NONE} */ - public static InheritanceKind of(UMLRTNamedElement element) { - return of(element.toUML()); + public static UMLRTInheritanceKind of(UMLRTNamedElement element) { + return nullSafe(element.getInheritanceKind()); + } + + static UMLRTInheritanceKind nullSafe(UMLRTInheritanceKind kind) { + return (kind == null) ? NONE : kind; } /** @@ -74,7 +78,7 @@ public enum InheritanceKind { * @return an inheritance kind comparator */ public static Comparator<Element> comparator() { - return Comparator.comparing(InheritanceKind::of); + return Comparator.comparing(UMLRTInheritanceKind::of); } /** diff --git a/plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/UMLRTNamedElement.java b/plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/UMLRTNamedElement.java index 42ccacc2d..335e6d6bd 100644 --- a/plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/UMLRTNamedElement.java +++ b/plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/UMLRTNamedElement.java @@ -139,71 +139,90 @@ public abstract class UMLRTNamedElement extends FacadeObject { } /** + * Queries my inheritance kind. + * + * @return my inheritance kind + */ + public UMLRTInheritanceKind getInheritanceKind() { + return UMLRTInheritanceKind.of(toUML()); + } + + /** * Queries whether I am a redefinition of some inherited element - * in my context namespace, even if I am {@linkplain #isVirtualRedefinition() virtual} - * or {@linkplain #isExcluded() excluded}. + * in my context namespace, but not redefined for {@linkplain #isExcluded() exclusion}. * - * @return whether I am a redefinition of an inherited element + * @return whether I am a (normal) redefinition of an inherited element * + * @see #getInheritanceKind() * @see #isVirtualRedefinition() * @see #isExcluded() */ public boolean isRedefinition() { - return internal().map(InternalUMLRTElement::rtIsRedefinition).orElse(false); + return getInheritanceKind() == UMLRTInheritanceKind.REDEFINED; } /** - * Queries whether I am a <em>virtual redefintion</em>, representing + * Queries whether I am a <em>virtual redefinition</em>, representing * a local proxy in my context namespace for an element inherited by that * namespace. A virtual element does not actually exist in the UML(-RT) * model and therefore cannot be an {@linkplain #isExcluded() exclusion} - * but is necessarily a {@linkplain #isRedefinition() redefinition}. + * but is necessarily {@linkplain #isInherited() inherited}. * Any change made to a virtual definition causes it to be * {@linkplain #reify() reified}, which changes it into a real redefinition * that exists in the model. * * @return whether I am a virtual redefinition of an inherited element * - * @see #isRedefinition() + * @see #getInheritanceKind() + * @see #isInherited() * @see #isExcluded() * @see #reify() */ public boolean isVirtualRedefinition() { - return internal().map(InternalUMLRTElement::rtIsVirtual).orElse(false); + return getInheritanceKind() == UMLRTInheritanceKind.INHERITED; } /** - * Queries whether I am a {@linkplain #isRedefinition() redefinition} that + * Queries whether I am an {@linkplain #isInherited() inherited} element that * exists solely to exclude the inherited element from my context namespace. * * @return whether I am an exclusion of an inherited element * - * @see #isRedefinition() + * @see #getInheritanceKind() + * @see #isInherited() * @see #exclude() * @see #reinherit() */ @Override public boolean isExcluded() { - boolean result = false; - - NamedElement uml = toUML(); - if (uml instanceof InternalUMLRTElement) { - result = ((InternalUMLRTElement) uml).rtIsExcluded(); - } + return getInheritanceKind() == UMLRTInheritanceKind.EXCLUDED; + } - return result; + /** + * Queries whether I am an inherited element of any + * {@linkplain #getInheritanceKind() inheritance kind}, even redefined or excluded. + * + * @return {@code false} if I am not a redefinable element or am the root of a + * real or potential redefinition hierarchy; {@code true}, otherwise + * + * @see #getInheritanceKind() + * @see #isVirtualRedefinition() + * @see #isInherited() + * @see #isExcluded() + */ + public boolean isInherited() { + return getInheritanceKind() != UMLRTInheritanceKind.NONE; } /** - * Excludes me from my namespace, if I am a - * {@linkplain #isRedefinition() redefinition} - * of an inherited element. + * Excludes me from my namespace, if I am an + * {@linkplain #isInherited() inherited} element. * * @return {@code true} if I was not excluded before but am after; * {@code false}, otherwise * * @see #isExcluded() - * @see #isRedefinition() + * @see #isInherited() * @see #reinherit() */ public boolean exclude() { @@ -225,7 +244,7 @@ public abstract class UMLRTNamedElement extends FacadeObject { * {@code false}, otherwise * * @see #isExcluded() - * @see #isRedefinition() + * @see #isInherited() * @see #exclude() */ public boolean reinherit() { @@ -257,10 +276,10 @@ public abstract class UMLRTNamedElement extends FacadeObject { * Queries the element that I redefine, whether that be * {@linkplain #isVirtualRedefinition() virtual redefinition} or a real element. * - * @return my immediate redefined element, or {@code null} if I am not a - * {@link #isRedefinition() redefinition} of some element + * @return my immediate redefined element, or {@code null} if I am not an + * {@link #isInherited() inherited} element * - * @see #isRedefinition() + * @see #isInherited() * @see #isVirtualRedefinition() * @see #getInheritedElement() */ @@ -299,9 +318,9 @@ public abstract class UMLRTNamedElement extends FacadeObject { * inherited element. * * @return the real inherited element that I redefined, or {@code null} - * if I am not a {@link #isRedefinition() redefinition} of some element + * if I am not an {@link #isInherited() inherited} element * - * @see #isRedefinition() + * @see #isInherited() * @see #getRedefinedElement() */ public UMLRTNamedElement getInheritedElement() { @@ -319,10 +338,10 @@ public abstract class UMLRTNamedElement extends FacadeObject { * myself if I am a root definition, otherwise the root definition of my * {@link #getRedefinedElement() redefined element, recursively. * - * @return the real inherited element that I redefined, or {@code null} - * if I am not a {@link #isRedefinition() redefinition} of some element + * @return the real inherited element that I redefine, or {@code null} + * if I am not an {@link #isInherited() inherited} element * - * @see #isRedefinition() + * @see #isInherited() * @see #getRedefinedElement() * @see #getInheritedElement() */ diff --git a/tests/junit/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml.tests/src/org/eclipse/papyrusrt/umlrt/uml/util/tests/InheritanceKindTest.java b/tests/junit/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml.tests/src/org/eclipse/papyrusrt/umlrt/uml/tests/InheritanceKindTest.java index 5ea81ce7e..6425f11fd 100644 --- a/tests/junit/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml.tests/src/org/eclipse/papyrusrt/umlrt/uml/util/tests/InheritanceKindTest.java +++ b/tests/junit/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml.tests/src/org/eclipse/papyrusrt/umlrt/uml/tests/InheritanceKindTest.java @@ -11,7 +11,7 @@ * *****************************************************************************/ -package org.eclipse.papyrusrt.umlrt.uml.util.tests; +package org.eclipse.papyrusrt.umlrt.uml.tests; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -22,18 +22,18 @@ import java.util.Collections; import java.util.List; import org.eclipse.papyrusrt.umlrt.uml.UMLRTCapsule; +import org.eclipse.papyrusrt.umlrt.uml.UMLRTInheritanceKind; import org.eclipse.papyrusrt.umlrt.uml.UMLRTNamedElement; import org.eclipse.papyrusrt.umlrt.uml.UMLRTProtocol; import org.eclipse.papyrusrt.umlrt.uml.tests.util.ModelFixture; import org.eclipse.papyrusrt.umlrt.uml.tests.util.TestModel; -import org.eclipse.papyrusrt.umlrt.uml.util.InheritanceKind; import org.eclipse.uml2.uml.NamedElement; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; /** - * Test suite for the {@link InheritanceKind} enumeration. + * Test suite for the {@link UMLRTInheritanceKind} enumeration. */ @TestModel("inheritance/connectors.uml") public class InheritanceKindTest { @@ -47,28 +47,28 @@ public class InheritanceKindTest { @Test public void noneKind() { - assertThat(InheritanceKind.of(local()), is(InheritanceKind.NONE)); + assertThat(UMLRTInheritanceKind.of(local()), is(UMLRTInheritanceKind.NONE)); // Not an inheritable thing - assertThat(InheritanceKind.of(getCapsule()), is(InheritanceKind.NONE)); + assertThat(UMLRTInheritanceKind.of(getCapsule()), is(UMLRTInheritanceKind.NONE)); // No element - assertThat(InheritanceKind.of((NamedElement) null), is(InheritanceKind.NONE)); + assertThat(UMLRTInheritanceKind.of((NamedElement) null), is(UMLRTInheritanceKind.NONE)); } @Test public void inheritedKind() { - assertThat(InheritanceKind.of(inherited()), is(InheritanceKind.INHERITED)); + assertThat(UMLRTInheritanceKind.of(inherited()), is(UMLRTInheritanceKind.INHERITED)); } @Test public void redefinedKind() { - assertThat(InheritanceKind.of(redefined()), is(InheritanceKind.REDEFINED)); + assertThat(UMLRTInheritanceKind.of(redefined()), is(UMLRTInheritanceKind.REDEFINED)); } @Test public void excludedKind() { - assertThat(InheritanceKind.of(excluded()), is(InheritanceKind.EXCLUDED)); + assertThat(UMLRTInheritanceKind.of(excluded()), is(UMLRTInheritanceKind.EXCLUDED)); } @Test @@ -76,7 +76,7 @@ public class InheritanceKindTest { List<UMLRTNamedElement> elements = new ArrayList<>(Arrays.asList( local(), excluded(), redefined(), inherited())); - Collections.sort(elements, InheritanceKind.facadeComparator()); + Collections.sort(elements, UMLRTInheritanceKind.facadeComparator()); assertThat(elements, is(Arrays.asList(inherited(), redefined(), excluded(), local()))); } |
