Find stereotypes applicable to instances of EClass? [message #479543] |
Tue, 11 August 2009 09:57  |
Eclipse User |
|
|
|
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
|
|
|
|
|
|
|
|
Re: Find stereotypes applicable to instances of EClass? [message #479724 is a reply to message #479706] |
Wed, 12 August 2009 04:03  |
Eclipse User |
|
|
|
Joel Greenyer wrote:
> thanks for the comment. Do you have a reason not to use
> stereotype.getAllExtendedMetaclasses()?
Well, the reason is, that ElementOperations.isApplicableStereotype did
not use it. But looking into the implementation it seems to be
equivalent so using getAllExtendedMetaclasses is even better as it's
shorter.
/Christian
|
|
|
Re: Find stereotypes applicable to instances of EClass? [message #627869 is a reply to message #479543] |
Tue, 11 August 2009 10:06  |
Eclipse User |
|
|
|
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
|
|
|
Re: Find stereotypes applicable to instances of EClass? [message #627870 is a reply to message #479545] |
Tue, 11 August 2009 10:30  |
Eclipse User |
|
|
|
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
|
|
|
Re: Find stereotypes applicable to instances of EClass? [message #627871 is a reply to message #479559] |
Tue, 11 August 2009 12:24  |
Eclipse User |
|
|
|
I solved my problem as follows:
suppose I have EClass eClass and the Stereotype stereotype, then I add all stereotypes applicable to instances of the
EClass to an array list:
/*
* 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(extendedMe taClass.getName());
// 1.
if (eExtendedMetaClass == eClass){
applicableStereotypesList.add(stereotype);
break;
}
// 2.
if (eClass.getEAllSuperTypes().contains(eExtendedMetaClass)){
applicableStereotypesList.add(stereotype);
break;
}
}
Joel Greenyer wrote:
> 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
|
|
|
Re: Find stereotypes applicable to instances of EClass? [message #627872 is a reply to message #479595] |
Tue, 11 August 2009 14:44  |
Eclipse User |
|
|
|
Hi Joel,
even though it looks quite the same, I post my solution here as well,
because I think such methods should make it into the eclipse UML API:
boolean isApplicableStereotype(EClass eClass, Stereotype stereotype)
{
for(Property attribute : stereotype.getAllAttributes())
{
if(attribute.getAssociation() instanceof Extension)
{
Type type = attribute.getType();
EClassifier eClassifier = UMLPackage.eINSTANCE
.getEClassifier(type.getName());
if(eClassifier instanceof EClass &&
((EClass) eClassifier).isSuperTypeOf(eClass))
{
return true;
}
}
}
return false;
}
It assumes the Stereotype is properly defined and is inspired by
ElementOperations.isApplicableStereotype.
Greetings to Paderborn from Kassel,
Christian
|
|
|
Re: Find stereotypes applicable to instances of EClass? [message #627873 is a reply to message #479627] |
Wed, 12 August 2009 02:55  |
Eclipse User |
|
|
|
Hi Christian,
thanks for the comment. Do you have a reason not to use stereotype.getAllExtendedMetaclasses()?
Indeed I was missing such a method in the UML API.
Greetings from Paderborn to Kassel
Joel
Christian Schneider wrote:
> Hi Joel,
>
> even though it looks quite the same, I post my solution here as well,
> because I think such methods should make it into the eclipse UML API:
>
>
> boolean isApplicableStereotype(EClass eClass, Stereotype stereotype)
> {
> for(Property attribute : stereotype.getAllAttributes())
> {
> if(attribute.getAssociation() instanceof Extension)
> {
> Type type = attribute.getType();
> EClassifier eClassifier = UMLPackage.eINSTANCE
> .getEClassifier(type.getName());
> if(eClassifier instanceof EClass &&
> ((EClass) eClassifier).isSuperTypeOf(eClass))
> {
> return true;
> }
> }
> }
> return false;
> }
>
>
> It assumes the Stereotype is properly defined and is inspired by
> ElementOperations.isApplicableStereotype.
>
> Greetings to Paderborn from Kassel,
> Christian
|
|
|
Re: Find stereotypes applicable to instances of EClass? [message #627874 is a reply to message #479706] |
Wed, 12 August 2009 04:03  |
Eclipse User |
|
|
|
Joel Greenyer wrote:
> thanks for the comment. Do you have a reason not to use
> stereotype.getAllExtendedMetaclasses()?
Well, the reason is, that ElementOperations.isApplicableStereotype did
not use it. But looking into the implementation it seems to be
equivalent so using getAllExtendedMetaclasses is even better as it's
shorter.
/Christian
|
|
|
Powered by
FUDForum. Page generated in 0.03860 seconds