| Summary: | [Static Profiles] API proposal to get StereotypeApplication from a UML Element | ||
|---|---|---|---|
| Product: | [Modeling] MDT.UML2 | Reporter: | Yann Tanguy <yann.tanguy> |
| Component: | Core | Assignee: | Kenn Hussey <Kenn.Hussey> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | Kenn.Hussey |
| Version: | unspecified | Keywords: | plan |
| Target Milestone: | M4 | Flags: | Kenn.Hussey:
iplog+
Kenn.Hussey: juno+ |
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | Community Support | ||
The utility method has been added and committed to git. |
Here is an utility API proposal (specific to static profiles) that could be shared in order get StereotypeApplication instances easily. Usage example (assuming "Requirement" is a Stereotype from a Static Profile) : Requirement req = Utils.getStereotypeApplication(umlElement, Requirement.class); /** * Convenient method to retrieve the StereotypeApplication by passing an element of the static profile. * * @param <T> * the type of stereotype to look for * @param element * an UML model element * @param clazz * the class of an element of a static profile. Compatible sub-types will be returned as well * @return the stereotype application or null if such stereotype is not applied */ @SuppressWarnings("unchecked") public static <T extends EObject> T getStereotypeApplication(Element element, java.lang.Class<T> clazz) { for(EObject stereoApplication : element.getStereotypeApplications()) { // check whether the stereotype is an instance of the passed parameter class if(clazz.isInstance(stereoApplication)) { return (T)stereoApplication; } } return null; }