Graham L
Graham L

Reputation: 11

Applying Eclipse Papyrus Designer stereotypes programmatically

I have created a java program that uses Eclipse UML2 to load a .uml file and perform a model translation that (amongst other things) applies Papyrus Designer stereotypes (Codegen and C_Cpp profiles). Papyrus Designer can then be used to load the resulting model and generate cpp. I have successfully used the plugin jars as libraries in a standard java project, but I'm having problems transitioning to an Eclipse plugin project. The pertinent code is:

Profile codegenProfile = loadProfile(codegenProfileUri); // loads the profile resource from its plugin jar and returns the org.eclipse.uml2.uml.Profile
codegenProfile.define();
...
model.applyProfile(codegenProfile);
...
final Stereotype listHint = codegenProfile.getOwnedStereotype("ListHint");
model.applyStereotype(listHint);
// etc

I have to define() the profile to avoid an exception when applying the profile:

java.lang.IllegalArgumentException: profile "C_Cpp" has no Ecore definition

In my plugin version of the project I load the profile ok but get an exception when applying the stereotype:

java.lang.IllegalArgumentException: org.eclipse.uml2.uml.internal.impl.StereotypeImpl@540dcfba (name: ListHint, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
    at org.eclipse.uml2.uml.internal.operations.ElementOperations.setValue(ElementOperations.java:667)
    at org.eclipse.uml2.uml.internal.impl.ElementImpl.setValue(ElementImpl.java:307)

Looking at ElementOperations, the problem is in:

EObject eObject = element.getStereotypeApplication(stereotype);

if (eObject == null) {
   throw new IllegalArgumentException(String.valueOf(stereotype));
}

which suggests the profile has not been properly initialised

Upvotes: 1

Views: 135

Answers (0)

Related Questions