Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » AST AbstractVisitor get occurances of operation arguments in operation's body
AST AbstractVisitor get occurances of operation arguments in operation's body [message #1015085] Wed, 27 February 2013 06:52 Go to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 501
Registered: June 2011
Senior Member
Hi,

I would like to know where precisely argument/arguments are being used in operation's body.
I have tried to extend AbstractVisitor and i have tried to override "handleOperationCallExp" but it does not serve the purpose.

Do you have any clue which method would be the one in AbstractVisitor to get the argument usage in operation's body?

thanks!

Cheers,
Re: AST AbstractVisitor get occurances of operation arguments in operation's body [message #1015094 is a reply to message #1015085] Wed, 27 February 2013 07:54 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

You clearly think you know what you're doing and so assume that I do
too; I don't. You need to be much clearer.

On 27/02/2013 11:52, ModelGeek Mising name wrote:
> I would like to know where precisely argument/arguments are being used
> in operation's body.
Read the code. Edit the code and look at the compiler errors. Instrument
the code.

Regards

Ed Willink
Re: AST AbstractVisitor get occurances of operation arguments in operation's body [message #1015102 is a reply to message #1015094] Wed, 27 February 2013 08:22 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 501
Registered: June 2011
Senior Member
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 #1015112 is a reply to message #1015102] Wed, 27 February 2013 08:47 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 779
Registered: July 2009
Senior Member
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 09:19 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 501
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 09: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 09:38 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
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 #1015139 is a reply to message #1015133] Wed, 27 February 2013 09:50 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 501
Registered: June 2011
Senior Member
thanks alot! It is solved.
Re: AST AbstractVisitor get occurances of operation arguments in operation's body [message #1015209 is a reply to message #1015120] Wed, 27 February 2013 13:34 Go to previous message
Christian W. Damus is currently offline Christian W. Damus
Messages: 779
Registered: July 2009
Senior Member
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?
Previous Topic:[OCLinEcore] Evalutaion difference beween OCL console and invariant in the model
Next Topic:OCLinEcore editor hungry? (eats characters)
Goto Forum:
  


Current Time: Sat Aug 30 12:39:54 EDT 2014

Powered by FUDForum. Page generated in 0.01734 seconds