UML2AS: Error when translating OpaqueExpression with multiple languages [message #1745911] |
Wed, 19 October 2016 09:30 |
German Vega Messages: 104 Registered: December 2015 Location: Grenoble, France |
Senior Member |
|
|
I am working in a tool that transforms UML models with OCL constraints mixed with constraints expressed in other languages. So the UML models my tool handles usually contain constraints with OpaqueExpressions with several bodies and languages.
Everything is working good most of the time, I can programmatically load the model and parse the associated OCL constraints using the pivot model. But sometimes, I got errors in which the corresponding ExpressionInOCL has an owned body that is not the specified OCL body, but is mistakenly taking one of the expressions in another language.
I've been debugging my code and pinpointed the problem to this method in class UML2AS
public ExpressionInOCL refreshOpaqueExpression(org.eclipse.uml2.uml.@NonNull OpaqueExpression umlExpression) {
ExpressionInOCL pivotElement = refreshNamedElement(ExpressionInOCL.class, PivotPackage.Literals.EXPRESSION_IN_OCL, umlExpression);
pivotElement.setBody(null);
List<String> umlBodies = umlExpression.getBodies();
List<String> umlLanguages = umlExpression.getLanguages();
for (int i = 0; i < umlBodies.size(); i++) {
String asLanguage = PivotConstants.OCL_LANGUAGE;
if (i < umlLanguages.size()) { // languages are optional, with defaults implementation defined ==> OCL
String umlLanguage = umlLanguages.get(i);
if ((umlLanguage != null) && (umlLanguage.length() > 0)) {
asLanguage = umlLanguage;
}
}
String umlBody = umlBodies.get(i);
if ((umlBody != null) && asLanguage.equals(PivotConstants.OCL_LANGUAGE)) {
EObject eContainer = umlExpression.eContainer();
if (eContainer instanceof org.eclipse.uml2.uml.Constraint) {
EObject eContainerContainer = eContainer.eContainer();
if (eContainerContainer instanceof org.eclipse.uml2.uml.Operation) {
org.eclipse.uml2.uml.Operation umlOperation = (org.eclipse.uml2.uml.Operation)eContainerContainer;
if (umlOperation.getBodyCondition() == eContainer) {
umlBody = PivotUtilInternal.getBodyExpression(umlBody);
}
}
}
}
pivotElement.setBody(umlBody);
}
copyNamedElement(pivotElement, umlExpression);
return pivotElement;
}
Notice that the body of the pivotElement is set to the umlBody irrespective of the specified asLanguage. I think this is a bug. The correction may be as simple as putting the statement that sets the body of the pivot element inside the "if" that tests the language.
To reproduce the problem just open the attached model in the UML2 editor and perform OCL validation. I am using the Neon version of OCL. You will find that single language OpaqueExpressions parses ok, but parsing of the the multi-language expressions depends on the order of the body languages: it only parses ok if the OCL body is the last in the list.
I can workaround the problem in my tool by reordering the body lists before parsing the OCL, so the correction is not urgent, but please considering opening a bug, if you agree with my analysis.
Thanks
German Vega
-
Attachment: model2.uml
(Size: 1.90KB, Downloaded 398 times)
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08442 seconds