Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Mauricio Moya (Arquesoft) on June 28, 2018, 06:43:39 am

Title: Ultimate code for changing estereotype?
Post by: Mauricio Moya (Arquesoft) on June 28, 2018, 06:43:39 am
Hi. After several tests and reading several posts in the forum about different versions of EA, I'm a bit confused about the ultimate right way to change a stereotype programatically. In a simple scenary as follows:
-There are two stereotypes, from the same profile, extending the same metaclass
-Both stereotypes add the same tag values to the elements.

Sometimes you create the element with the wrong stereotype (A), and later you want to change it to the stereotype B (with a script). What is the right procedure?

I'm particulary confused with: element.Stereotype, element.StereotypeEx, element.FQStereotype, element.MetaType, element.SynchTaggedValues.

Thanks in advance.
Title: Re: Ultimate code for changing estereotype?
Post by: Geert Bellekens on June 28, 2018, 02:03:10 pm
I've found that setting element.StereotypeEx always seems to do the job.

I hardly ever use any of the other methods/properties, if at all.

Geert
Title: Re: Ultimate code for changing estereotype?
Post by: Eve on June 28, 2018, 02:47:24 pm
I'm particulary confused with: element.Stereotype, element.StereotypeEx, element.FQStereotype, element.MetaType, element.SynchTaggedValues.
Title: Re: Ultimate code for changing estereotype?
Post by: Mauricio Moya (Arquesoft) on June 29, 2018, 04:41:07 am
So, the right way to do it is as follows?
Code: [Select]
element.StereotypeEx = "MyStereotype";
element.Update();

or like this?
Code: [Select]
element.StereotypeEx = "MyProfile::MyStereotype";
element.Update();

So, I think: how does EA know which one of two stereotypes (with the same name but in different profiles) you want to set?
Title: Re: Ultimate code for changing estereotype?
Post by: qwerty on June 29, 2018, 07:04:40 am
The first one will (silently) add EAUML (the default profile). So I would guess. Any stereotype is only part of a profile. This has been introduced in some recent UML version (don't get me nailed on that). But EA still uses its glue-profile so you can stumble from one pitfall to the next.

It's strange (ehrm, no; not at all) that Stereotype (without Ex) has never been deprecated (like some other attributes/operations). EA is conziztent as its "Generalisation".

q.
Title: Re: Ultimate code for changing estereotype?
Post by: Nizam on June 29, 2018, 09:36:57 am
Better to go with the FQ Name, and also take a note of the 'synchronize Stereotypes.' call
Title: Re: Ultimate code for changing estereotype?
Post by: Eve on July 02, 2018, 09:49:48 am
The first one will (silently) add EAUML (the default profile). So I would guess. Any stereotype is only part of a profile.
Not quite true.

If you don't specify a fully qualified name, EA will apply a matching stereotype from any profile. Only if no matching stereotype exists will it create a new stereotype entry.

As a result, you get an insidious bug in your code. It works fine until some other profile including a stereotype with that name loads before yours.

Please... Always fully qualify your stereotypes.
Title: Re: Ultimate code for changing estereotype?
Post by: qwerty on July 02, 2018, 03:55:53 pm
As a result, you get an insidious bug in your code. It works fine until some other profile including a stereotype with that name loads before yours.

Please... Always fully qualify your stereotypes.
Phew. Even worse :-( How about EA insisting on a FQN when checking the parameters?

q.
Title: Re: Ultimate code for changing estereotype?
Post by: Geert Bellekens on July 02, 2018, 04:20:40 pm
As a result, you get an insidious bug in your code. It works fine until some other profile including a stereotype with that name loads before yours.

Please... Always fully qualify your stereotypes.
Phew. Even worse :-( How about EA insisting on a FQN when checking the parameters?

q.
And breaking a bunch of existing working code?
I hope not.

Geert
Title: Re: Ultimate code for changing estereotype?
Post by: qwerty on July 02, 2018, 07:46:13 pm
Well, that's the attitude still having "Generalisation" and other rotten stuff. Software is not dead. You have to work on it to keep it alive.

Of course it would have been better to require FQN in the first place when this operation had been introduced.

q.