Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350402 - [Static Profiles] API proposal to get StereotypeApplication from a UML Element
Summary: [Static Profiles] API proposal to get StereotypeApplication from a UML Element
Status: RESOLVED FIXED
Alias: None
Product: MDT.UML2
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: M4   Edit
Assignee: Kenn Hussey CLA
QA Contact:
URL:
Whiteboard: Community Support
Keywords: plan
Depends on:
Blocks:
 
Reported: 2011-06-27 03:35 EDT by Yann Tanguy CLA
Modified: 2012-05-22 12:37 EDT (History)
1 user (show)

See Also:
Kenn.Hussey: iplog+
Kenn.Hussey: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yann Tanguy CLA 2011-06-27 03:35:14 EDT
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;
   }
Comment 1 Kenn Hussey CLA 2011-08-22 23:34:59 EDT
The utility method has been added and committed to git.