[SOLVED] How to avoid duplicating stereotypes?



I am developing a plug-in which relies on a set of stereotypes and I would like to check if the stereotypes already exist or if I should create them.

However, I can only access the stereotypes within the “project scope”, which means that my plug-in has no way to check if the stereotype already exists within the “workspace scope”.

Even worse, if I ignore already existing stereotypes and create new ones (duplicating them), the users only has access to the ones existing in the “workspace scope”.

Is there a way to access the workspace’s stereotypes through the Open API?

Kind regards,
Claudenir Fonseca


Sorry, there is no API to read/write workspace’s stereotypes.

But, there are 2 functions may help you:

  1. ProjectManager #getSelectableStereotypesForModelType(aModelType : String, aProject : IProject, aSort : boolean) : IModelElement[]
    It will return stereotypes, which collected from current-project ( + referenced-projects) + workspace.

  2. {Stereotype-Supported-ModelElement} #addStereotype(aName : String)
    It will create or get existing stereotype (from current-project or workspace) to add into that model element.
    for example, IClass is one of Stereotype-Supported Model Element


Thanks for the quick response.

I tried the second method before posting and it did not work. Actually it would just duplicate the stereotype within the project scope and ignore the existing one in the workspace.

But the first method worked just fine =)
I looked around the API in order to find something like that, but did not consider the possibility of finding it on the ProjectManager class.

Kind regards,