| [news.eclipse.modeling.mdt.uml2] Re: Find stereotypes applicable to instances of EClass? |
I solved my problem as follows:
/*
* When is a stereotye applicable to instances of eClass?
*
* 1. when the eClass equals an extended meta-class of the stereotype
* 2. when the eClass is a subclass of the extended meta-class of the stereotype
* <=> the extended meta-class is in the set of superclasses of eClass
*/
ArrayList<Stereotype> applicableStereotypesList = new ArrayList<Stereotype>();
for (Class extendedMetaClass : stereotype.getAllExtendedMetaclasses()) {
EClassifier eExtendedMetaClass = UMLFactory.eINSTANCE.getEPackage().getEClassifier(extendedMetaClass.getName());
// 1.
if (eExtendedMetaClass == eClass){
applicableStereotypesList.add(stereotype);
break;
}
// 2.
if (eClass.getEAllSuperTypes().contains(eExtendedMetaClass)){
applicableStereotypesList.add(stereotype);
break;
}
}Timothy,
thanks for the quick answer.
Your idea is not bad. However, what happens in case that the EClass is an abstract class?
The next thing that confuses me--but that's probably a whole different problem--is that wrong elements are created when I hand the EClass to the UMLFactory. E.g. I have the EClass 'Class' and get an instance of 'Signal'. Any idea why that may be?
Thanks
Joel
Timothy Marc wrote:Hey,
what about:
Element element = (Element)UMLFactory.create(eclass); final boolean isApplicable = element.isStereotypeApplicable(stereo);
Timothy
Joel Greenyer schrieb:Hi,
given an EClass, corresponding to an UML meta-class, and a stereotype, I wonder what is the most elegant way to find out whether the stereotype is applicable to an instances of this EClass?
Any ideas?
Thanks for helping
Joel