Home » Modeling » OCL » AST AbstractVisitor get occurances of operation arguments in operation's body
| | |
Re: AST AbstractVisitor get occurances of operation arguments in operation's body [message #1015112 is a reply to message #1015102] |
Wed, 27 February 2013 13:47 |
|
Hi,
The handleOperationCallExp method traverse an OCL expression that is an
operation call. These can occur anywhere, and will definitely occur
within the body expression of an Operation. As far as the syntax of
OCL expressions is concerned, the placement of the OCL as a body
specification for an Operation is irrelevant. This is the wrong tree
to bark up.
Rather, if you're looking for references to the Parameters of the
context operation, then these will take the form of VariableExp
(variable expressions). So, you you want to implement the
handleVariableExp method of the visitor to look for VariableExps that
reference Variables representing the operation's parameters.
HTH,
Christian
On 2013-02-27 13:22:31 +0000, ModelGeek Mising name said:
> I will try to explain it better this time.
>
> I have an ecore and it contains many classes with multiple OCL
> operations. Now i haved selected a specfic OCL operation(with
> arguments) and i want to know where each argument is being used inside
> operations's body. I have tried to extend AbstractVisitor class get AST
> for operation's body. I am trying to override "handleOperationCallExp"
> method but it looks like that it will not help me finding the usage of
> specific argument inside operation body. Is there any other method in
> AbstractVisitor which can help to achieve this?
> thanks!
|
|
|
Re: AST AbstractVisitor get occurances of operation arguments in operation's body [message #1015120 is a reply to message #1015112] |
Wed, 27 February 2013 14:19 |
ModelGeek Mising name Messages: 550 Registered: June 2011 |
Senior Member |
|
|
String body = "here i am fetching the body of ocl operation"
OCL<?, EClassifier, EOperation, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject> ocl1;
ocl1 = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
OCLHelper<EClassifier, EOperation, ?, Constraint> helper = ocl1.createOCLHelper();
helper.setOperationContext(eClass, eOperation);
OCLExpression<EClassifier> query = helper.createQuery(body);
TestVisitor visitor = new TestVisitor(param);
Visitable accept = query.accept(visitor);
In my TestVisitor class i have implemented following
@Override
protected Visitable handleVariable(
Variable<EClassifier, EParameter> variable, Visitable initResult) {
System.out.println(variable);
return super.handleVariable(variable, initResult);
}
it just prints all parts of all let statements defined inside operation... it does not print arguments of operation.
Do you have any idea where i am going wrong?
[Updated on: Wed, 27 February 2013 14:20] Report message to a moderator
|
|
|
Re: AST AbstractVisitor get occurances of operation arguments in operation's body [message #1015133 is a reply to message #1015120] |
Wed, 27 February 2013 14:38 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
For the classic Ecore-based OCL, the Visitors support a user-coded
traversal of a tree of OCL model objects (but not Ecore objects).
Since many parent-child traversals are regular the handleXXX methods
factor out some common usage. Very helpful when the common usage is what
you want. A bit confusing when it isn't. In principle you should plan to
do all the vistXXX for your own full traversal, but reuse the handleXXX
if it happens to do what you want.
If something doesn't happen, it's because you didn't program it.
Regards
Ed Willink
On 27/02/2013 14:19, ModelGeek Mising name wrote:
> String body = "here i am fetching the body of ocl operation"
> OCL<?, EClassifier, EOperation, ?, ?, ?, ?, ?, ?, Constraint, EClass,
> EObject> ocl1;
> ocl1 = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
> OCLHelper<EClassifier, EOperation, ?, Constraint> helper =
> ocl1.createOCLHelper();
> helper.setOperationContext(eClass, eOperation);
> OCLExpression<EClassifier> query = helper.createQuery(body);
> TestVisitor visitor = new TestVisitor(param);
> Visitable accept = query.accept(visitor);
>
> In my TestVisitor class i have implemented following
>
>
> @Override
> protected Visitable handleVariable(
> Variable<EClassifier, EParameter> variable, Visitable
> initResult) {
> System.out.println(variable);
> return super.handleVariable(variable, initResult);
> }
>
> it just prints all parts of all let statements... it does not print
> arguments of operation.
>
> Do you have any idea where i am going wrong?
>
|
|
| |
Re: AST AbstractVisitor get occurances of operation arguments in operation's body [message #1015209 is a reply to message #1015120] |
Wed, 27 February 2013 18:34 |
|
Hi,
You are implementing the handleVariable call-back, not
handleVariableExp. They are two different things!
cW
On 2013-02-27 14:19:49 +0000, ModelGeek Mising name said:
> String body = "here i am fetching the body of ocl operation"
> OCL<?, EClassifier, EOperation, ?, ?, ?, ?, ?, ?, Constraint, EClass,
> EObject> ocl1;
> ocl1 = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
> OCLHelper<EClassifier, EOperation, ?, Constraint> helper =
> ocl1.createOCLHelper();
> helper.setOperationContext(eClass, eOperation);
> OCLExpression<EClassifier> query = helper.createQuery(body);
> TestVisitor visitor = new TestVisitor(param);
> Visitable accept = query.accept(visitor);
>
> In my TestVisitor class i have implemented following
>
>
> @Override
> protected Visitable handleVariable(
> Variable<EClassifier, EParameter> variable, Visitable initResult) {
> System.out.println(variable);
> return super.handleVariable(variable, initResult);
> }
>
> it just prints all parts of all let statements... it does not print
> arguments of operation.
>
> Do you have any idea where i am going wrong?
|
|
|
Goto Forum:
Current Time: Thu Apr 18 01:38:25 GMT 2024
Powered by FUDForum. Page generated in 0.02119 seconds
|