EOL: How to create a stereotype in an existing UML profile [message #1731626] |
Sun, 08 May 2016 05:11  |
Eclipse User |
|
|
|
Hi,
I would like to add a stereotype like "foo" (which extends the <<metaclass>> Class here) to an existing UML profile named "MyProfile" in the following code:
var stereotype: Stereotype;
var elementImport: ElementImport;
var extension: Extension;
if (not Stereotype.all.exists(s|s.name = "foo"))
{
// define a new stereotype named with the classifier name
stereotype = Stereotype.createInstance();
stereotype.name = "foo";
stereotype.package = MyProfile;
}
else
{
("foo already exists!").println();
}
if (not ElementImport.all.exists(e|e.importingNamespace = MyProfile))
{
elementImport = ElementImport.createInstance();
elementImport.importingNamespace = MyProfile;
elementImport.target = UML!Class; // Error: Undefined variable, type or model: 'UML!Class'
}
if (not Extension.all.exists(e | e.package = MyProfile))
{
extension = Extension.createInstance();
extension.package = MyProfile;
extension.metaclass = elementImport.target; // Error: The feature 'metaclass' is not a valid changeable feature
extension.endType.add(stereotype); // these statements must relate the stereotype and the element import, but do not work as I expect
extension.endType.add(elementImport.target);
}
But it does not work as I expect! The usage of the "target", "metaclass" properties are erroneous. How to use and arrange these statements to associate the imported element <<metaclass>> Class and the stereotype "foo"?
Best regards,
Alireza
[Updated on: Tue, 17 May 2016 08:20] by Moderator
|
|
|
Re: EOL: How to create a stereotype in an existing UML profile [message #1731937 is a reply to message #1731626] |
Wed, 11 May 2016 04:15   |
Eclipse User |
|
|
|
"UML!Class" is just a type name, and doesn't refer to any actual objects. If you want to refer to the EClass, you'd have to load the UML metamodel as a model itself. Within your launch configuration, you could use the "Registered EMF EPackage", and then look through its EClasses to find the one named "Class".
Alternatively, a quick and dirty method could be:
var throwaway = new UML!Class;
var classType = throwaway.eClass;
As for "metaclass", if you look at the Extension EClass through the "EPackage Registry" view, you'll see that it's in italics. That means it is a derived feature, which cannot be changed directly. You have to change the features that it is derived from. If you look at the source code of ExtensionImpl and follow some method calls from getMetaclass(), you'll see that it's derived from this OCL expression:
result = metaclassEnd().type.oclAsType(Class)
metaclassEnd() is another OCL query, which according to the UML source code is defined like this:
result = (memberEnd->reject(p | ownedEnd->includes(p.oclAsType(ExtensionEnd)))->any(true))
It looks like you'll have to set memberEnd or ownedEnd in some way.
[Updated on: Wed, 11 May 2016 04:18] by Moderator
|
|
|
|
|
|
|
Re: EOL: How to create a stereotype in an existing UML profile [message #1732012 is a reply to message #1731946] |
Wed, 11 May 2016 12:53   |
Eclipse User |
|
|
|
Hi,
I used the "Registered EMF Package" model type and selected "http://www.eclipse.org/uml2/5.0.0/UML" in the Meta-model URI. Instead of setting the target property of the elementImport, I used the importedElement property to set the imported metaclass Class with the following code:
elementImport.importedElement = UML.allInstances().selectOne(e | e.eClass.name = "EClass" and e.name = "Class");
This causes the following exception error:
org.eclipse.emf.ecore.impl.EClassImpl cannot be cast to org.eclipse.uml2.uml.PackageableElement
The expected importedElement must be:
Class [name=Class, qualifiedName=UML::Class, visibility=public, isLeaf=false, isAbstract=false, isFinalSpecialization=false, isActive=false, ]
Is there any trick to resolve this exception?
Best regards,
Alireza
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04930 seconds