Problem found regarding Papyrus static profile generated Java; OCL expression does not detect stereotypes applied to imported package elements.
Please find attached tar file containing example Papyrus static profile project "com.validationproblem.profile" and application "ValidationProblemApp" model ValidationProblem7.tar.gz.
The profile code com.validationproblem.profile contains the resources directory, which contains a profile directory with ValidationProblem.profile and a library directory with ValidationProblem-Library models.
The ValidationProblem-Library uml model applies the ValidationProblem.profile and defines a single class called LibraryChicken with the stereotype Chicken applied to it.
The application project ValidationProblemApp defines several classes that either apply the stereotype Chicken or Duck; one of the Chicken applied classes however is the LibraryChicken that is imported from the ValidationProblem-Library.
The profile com.validationproblem.profile defines the Farm stereotype with a number of derived properies, that are summarised here and you can find in the attached tar file projects:
/animal: Animal [0..*]
let supplierElement : Set(UML::NamedElement) =
Has.allInstances()->select(base_Dependency.client->includes(self.base_NamedElement)).base_Dependency.supplier->asSet()
in Animal.allInstances()->select(supplierElement->includes(base_NamedElement))
/chicken: Chicken [0..*]
self.animal->selectByKind(Chicken)
/duck: Duck [0..*]
self.animal->selectByKind(Duck)
/allAnimals: NamedElement [0..*]
Has.allInstances()->select(base_Dependency.client->includes(self.base_NamedElement)).base_Dependency.supplier->asSet()
/allAnimalsEverywhere: Animal [0..*]
Animal.allInstances()
In the ValidationProblemApp we have defined classes:
farm <<Farm>> -> chicken1 <<Chicken>>
farm <<Farm>> -> chicken2 <<Chicken>>
farm <<Farm>> -> LibraryChicken <<Chicken>>
farm <<Farm>> -> duck1 <<Duck>>
I have represented Dependency elements with stereotype "Has" applied as "->" above.
In the ValidationProblemApp we can see that the stereotype derived properies have the following values:
/animal: Animal [0..*] = {chicken1, chicken2, duck1}
/chicken: Chicken [0..*] = {chicken1, chicken2}
/duck: Duck [0..*] = {duck1}
/allAnimals: NamedElement [0..*] = {chicken1, duck1, LibraryChicken, chicken2}
/allAnimalsEverywhere: Animal [0..*] = {chicken1, chicken2, duck1}
As you can see all this is pointing to the fact that the OCL expression Animal.allInstance() does not return "LibraryChicken"!
Note: ValidationProblem-Library Package is imported as PackageImport and class LibraryChicken is imported as ElementImport to no avail - still LibraryChicken doesn't get discovered by Animal.allInstances().
Best regards,
Deniz