Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » UML2AS: Error when translating OpaqueExpression with multiple languages
UML2AS: Error when translating OpaqueExpression with multiple languages [message #1745911] Wed, 19 October 2016 09:30 Go to next message
German Vega is currently offline German VegaFriend
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 388 times)
Re: UML2AS: Error when translating OpaqueExpression with multiple languages [message #1745915 is a reply to message #1745911] Wed, 19 October 2016 09:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Agree there's a problem. Not sure whether I agree with the solution.

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=506191 for progress.

Regards

Ed Willink
Re: UML2AS: Error when translating OpaqueExpression with multiple languages [message #1745917 is a reply to message #1745915] Wed, 19 October 2016 10:01 Go to previous message
German Vega is currently offline German VegaFriend
Messages: 104
Registered: December 2015
Location: Grenoble, France
Senior Member
Thanks Ed,

I will follow the bug.
Previous Topic:evaluate new OCL constrains as I am drawing a UML model
Next Topic: problem string concat operation OclUndefined ?
Goto Forum:
  


Current Time: Thu Apr 18 15:17:24 GMT 2024

Powered by FUDForum. Page generated in 0.01854 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top