Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 350402

Summary: [Static Profiles] API proposal to get StereotypeApplication from a UML Element
Product: [Modeling] MDT.UML2 Reporter: Yann Tanguy <yann.tanguy>
Component: CoreAssignee: Kenn Hussey <Kenn.Hussey>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: Kenn.Hussey
Version: unspecifiedKeywords: plan
Target Milestone: M4Flags: Kenn.Hussey: iplog+
Kenn.Hussey: juno+
Hardware: PC   
OS: Windows 7   
Whiteboard: Community Support

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.