Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL Pivot - Visitor implementation
OCL Pivot - Visitor implementation [message #1312588] Thu, 24 April 2014 11:31 Go to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
I want to have custom implementation of org.eclipse.ocl.examples.pivot.util.visitor. The motive of this custom implementation is to determine the place of specific property call in an OCL statement.

I am trying to override following
public Object visitPropertyCallExp(
org.eclipse.ocl.examples.pivot.PropertyCallExp callExp)

Now i want to have start and ending position of property call in OCL statement.

I have already implemented this feature in classic ocl implementation and i used
protected Integer handlePropertyCallExp(PropertyCallExp<EClassifier, EStructuralFeature> callExp, Integer sourceResult, List<Integer> qualifierResults)

and i was able to get start and end positioning by callExp.getStartPosition(), callExp.getEndPosition()

Now org.eclipse.ocl.examples.pivot.PropertyCallExp does not provide methods for start and end position.

Do you have any idea how to get start and end position of property call in OCL statement using Pivot package?

[Updated on: Thu, 24 April 2014 11:32]

Report message to a moderator

Re: OCL Pivot - Visitor implementation [message #1312614 is a reply to message #1312588] Thu, 24 April 2014 11:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

org.eclipse.ocl.examples.xtext.base.utilities.ElementUtil.getCsElement
should give you the CS ElementCS from which the AS Element was created.

Then org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode will give
you the Xtext INode

INode has all sorts of getOffset() getStartLine() etc methods.


Feel free to contribute helpers such as

ElementUtil.getStartPosition(Element)

Regards

Ed Willink


On 24/04/2014 12:31, ModelGeek Mising name wrote:
> I want to custom implementation of
> org.eclipse.ocl.examples.pivot.util.visitor. The motive of this custom
> implementation is to determine the place of specific property call in
> an OCL statement.
>
> I am trying to override following
> public Object visitPropertyCallExp(
> org.eclipse.ocl.examples.pivot.PropertyCallExp callExp)
>
> Now i want to have start and ending position of property call in OCL
> statement.
>
> I have already implemented this feature in classic ocl implementation
> and i used protected Integer
> handlePropertyCallExp(PropertyCallExp<EClassifier, EStructuralFeature>
> callExp, Integer sourceResult, List<Integer> qualifierResults)
> and i was able to get start and end positioning by
> callExp.getStartPosition(), callExp.getEndPosition()
>
> Now org.eclipse.ocl.examples.pivot.PropertyCallExp does not provide
> methods for start and end position.
>
> Do you have any idea how to get start and end position of property
> call in OCL statement using Pivot package?
>
>
Re: OCL Pivot - Visitor implementation [message #1312734 is a reply to message #1312614] Thu, 24 April 2014 13:17 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
thanks for for help!
i have overridden
public Object visitPropertyCallExp(
org.eclipse.ocl.examples.pivot.PropertyCallExp callExp)

but this method is never called, instead
public Object visiting(org.eclipse.ocl.examples.pivot.util.Visitable visitable) is called many times. Do you any idea why it is so?

org.eclipse.ocl.examples.pivot.OCL ocl1 = org.eclipse.ocl.examples.pivot.OCL.newInstance(new PivotEnvironmentFactory());
org.eclipse.ocl.examples.pivot.helper.OCLHelper helper = ocl1.createOCLHelper();
helper.setOperationContext(eClassBeingAnalyzed, eOperation);
org.eclipse.ocl.examples.pivot.ExpressionInOCL expression = helper.createBodyCondition(oclstatement);
MyVisitor visitor = new MyVisitor (helper.getContextClassifier());
Integer accept = expression.accept(visitor );


private class MyVisitor extends AbstractExtendingVisitor{
public MyVisitor (Object obj) {
super(obj)
}

@Override
public Object visitPropertyCallExp(org.eclipse.ocl.examples.pivot.PropertyCallExp callExp) {
System.out.println("propertycallexp");
return super.visitPropertyCallExp(callExp);
}

public Object visiting( org.eclipse.ocl.examples.pivot.util.Visitable visitable) {
System.out.println("visiting");
return null;
}


}

[Updated on: Thu, 24 April 2014 13:20]

Report message to a moderator

Re: OCL Pivot - Visitor implementation [message #1312810 is a reply to message #1312734] Thu, 24 April 2014 14:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

Yes you have a silly object or silly code.

Try debugging it then try reading
https://wiki.eclipse.org/OCL/ForumNetiquette

Regards

Ed Willink


On 24/04/2014 14:17, ModelGeek Mising name wrote:
> thanks for for help!
> i have overridden
> public Object visitPropertyCallExp(
> org.eclipse.ocl.examples.pivot.PropertyCallExp callExp)
>
> but this method is never called, instead public Object
> visiting(org.eclipse.ocl.examples.pivot.util.Visitable visitable) is
> called many times. Do you any idea why it is so?
>
> org.eclipse.ocl.examples.pivot.OCL ocl1 =
> org.eclipse.ocl.examples.pivot.OCL.newInstance(new
> PivotEnvironmentFactory());
> org.eclipse.ocl.examples.pivot.helper.OCLHelper
> helper = ocl1.createOCLHelper();
> helper.setOperationContext(eClassBeingAnalyzed, eOperation);
> org.eclipse.ocl.examples.pivot.ExpressionInOCL expression =
> helper.createBodyCondition(oclstatement);
> MyVisitor visitor = new MyVisitor (helper.getContextClassifier());
> Integer accept = expression.accept(visitor );
>
>
> private class AttributeRefactorer extends AbstractExtendingVisitor {
> public AttributeRefactorer(Object obj) {
> super(obj)
> }
>
> @Override
> public Object
> visitPropertyCallExp(org.eclipse.ocl.examples.pivot.PropertyCallExp
> callExp) {
> System.out.println("propertycallexp");
> return super.visitPropertyCallExp(callExp);
> }
>
> @Override
> public Object visitProperty(Property object) {
> System.out.println("property");
> return super.visitProperty(object);
> }
>
>
> }
Re: OCL Pivot - Visitor implementation [message #1320107 is a reply to message #1312810] Mon, 28 April 2014 15:42 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
thanks for the help!
I am creating pivot resource from ecore resource and from pivot i am doing the conversion to EssentialOCLCSResource. I am customizing EssentialOCLDeclarationVisitor.

I am overriding
@Override
public @Nullable
ElementCS visitPropertyCallExp(PropertyCallExp callExp) {
Property property = callExp.getReferredProperty();
Element element = callExp.getReferredElement();
ModelElementCS elemcs = ElementUtil.getCsElement(element);
int start = NodeModelUtils.getNode(elemcs).getOffset();
int end = NodeModelUtils.getNode(elemcs).getEndOffset();
System.out.println("start = " + start);
System.out.println("end = " + end);
return super.visitPropertyCallExp(callExp);
}

for me ElementUtil.getCsElement(callExp.getReferredElement()) is always null eventhough callExp.getReferredElement() is not null.....

Is ecore->pivot->xtext conversion is the way go? or is there a better strategy available?

thank you so much for your support.
Re: OCL Pivot - Visitor implementation [message #1320222 is a reply to message #1320107] Mon, 28 April 2014 17:11 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

I've no idea what you want.

You're original questuion was about obtaining start/end positions which
strongly suggests that you are transforming text->cs->as but now you
suggest you start with ecore->pivot->xtext which is the opposite.

So at least one of your approaches is almost certainly a bad way to go.

Regards

Ed Willink

On 28/04/2014 16:42, ModelGeek Mising name wrote:
> thanks for the help!
> I am creating pivot resource from ecore resource and from pivot i am
> doing the conversion to EssentialOCLCSResource. I am customizing
> EssentialOCLDeclarationVisitor.
>
> I am overriding @Override
> public @Nullable
> ElementCS visitPropertyCallExp(PropertyCallExp callExp) {
> Property property = callExp.getReferredProperty();
> Element element = callExp.getReferredElement();
> ModelElementCS elemcs = ElementUtil.getCsElement(element);
> int start = NodeModelUtils.getNode(elemcs).getOffset();
> int end = NodeModelUtils.getNode(elemcs).getEndOffset();
> System.out.println("start = " + start);
> System.out.println("end = " + end); return
> super.visitPropertyCallExp(callExp);
> }
> for me ElementUtil.getCsElement(callExp.getReferredElement()) is
> always null eventhough callExp.getReferredElement() is not null.....
>
> Is ecore->pivot->xtext conversion is the way go? or is there a better
> strategy available?
>
> thank you so much for your support.
Re: OCL Pivot - Visitor implementation [message #1321280 is a reply to message #1320222] Tue, 29 April 2014 07:30 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
Sorry for not being clear.
I have an ecore model containing multiple derived attributes. Now for one derived attribute, i want to know what other artifacts(other attribute, classes, references) are used in OCL derivation statement and where exactly in statement.
I did that in classic OCL with help of visitor.

But now i have switched to pivot.
Now i am using pivot based evaluation and i want to do the same using Pivot package.
So now i should convert ecore resource to pivot and then to AS? ecore->pivot->As?

thanks for help!
Re: OCL Pivot - Visitor implementation [message #1321282 is a reply to message #1320222] Tue, 29 April 2014 07:31 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
Sorry for not being clear.
I have an ecore model containing multiple derived attributes. Now for one derived attribute, i want to know what other artifacts(other attribute, classes, references) are used in OCL derivation statement and where exactly in statement.
I did that in classic OCL with help of visitor.

But now i have switched to pivot and want to do the same using Pivot package.


For example, without conversions, i have tried ToString visitor and i am able to get the other properties/attributes being used in OCL statement but the only problem is to get the exact start and end index of property call in OCL

I have tried to debug and ElementUtil.getCsElement calls CS2Pivot.getCSElement(Element element) and in CS2Pivot.computePivot2CSMap() operation csresource (EssentialOCLCSResource) is always empty.

so can you suggest any good strategy? Do i need the conversions?

thanks for help!

[Updated on: Tue, 29 April 2014 08:15]

Report message to a moderator

Re: OCL Pivot - Visitor implementation [message #1321346 is a reply to message #1321282] Tue, 29 April 2014 08:20 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
On 29/04/2014 08:31, ModelGeek Mising name wrote:
> Sorry for not being clear.
Using a new thread for new topics will avoid a lot of confusion.
> I have an ecore model containing multiple derived attributes. Now for
> one derived attribute, i want to know what other artifacts(other
> attribute, classes, references) are used in OCL derivation statement
> and where exactly in statement.
> I did that in classic OCL with help of visitor.
> But now i have switched to pivot and want to do the same using Pivot
> package.
> So should i convert ecore resource to pivot and then to AS?
> ecore->pivot->As?
Of course. Did you consider the
org.eclipse.ocl.examples.pivot.OCL.ecore2pivot method? (Or Ecore2Pivot
class if you want more control).

The Pivot representation is the Abstract Syntax model.

Regards

Ed Willink
>
> thanks for help!
Re: OCL Pivot - Visitor implementation [message #1321374 is a reply to message #1321346] Tue, 29 April 2014 08:41 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
I have tried org.eclipse.ocl.examples.pivot.OCL.ecore2pivot method for conversion.
But the problem is that ElementUtil.getCsElement(callExp.getReferredElement()) is always null.
I have tried to debug and ElementUtil.getCsElement calls CS2Pivot.getCSElement(Element element) and in CS2Pivot.computePivot2CSMap() operation csresource (EssentialOCLCSResource) is always empty.

Do i need ElementCS in order to get the offset using org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode(elemcs).getOffset()?

am i missing something here?

[Updated on: Tue, 29 April 2014 08:45]

Report message to a moderator

Re: OCL Pivot - Visitor implementation [message #1321497 is a reply to message #1321374] Tue, 29 April 2014 10:18 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

I was about to reply that: You can only access the CS representation if
it exists. Coming from Ecore it doesn't since the Ecore file is just
embedded OCL snippets.

But after a check, the OCL snippet is text so it has positions (in an
XMI file) and it appears that CSI2PivotMapping.update is establishing
the mappings.

So it is seems like a 'simple' bug. Perhaps an over-enthusiastic attempt
at freeing up redundant stale parses is keeping only the last CS-AS context.

See what the repeated CSI2PivotMapping.update calls are doing, and
probably raise a bug with a repro.

If you really want the XMI file positions you will probably need an
adjustment to absolute file positions rather than relative to OCL start.

Alternatively you can do what the OCLinEcore editor does and create an
overall text representation.

Regards

Ed Willink

On 29/04/2014 09:41, ModelGeek Mising name wrote:
> I have tried org.eclipse.ocl.examples.pivot.OCL.ecore2pivot method for
> conversion.
> But the problem is that
> ElementUtil.getCsElement(callExp.getReferredElement()) is always null.
> I have tried to debug and ElementUtil.getCsElement calls
> CS2Pivot.getCSElement(Element element) and in
> CS2Pivot.computePivot2CSMap() operation csresource
> (EssentialOCLCSResource) is always empty.
>
> am i missing something here?
>
>
Re: OCL Pivot - Visitor implementation [message #1321532 is a reply to message #1321497] Tue, 29 April 2014 10:41 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
thanks for your excellent support!
Now i have ecore->pivot->cs->pivot conversion and now ElementUtil.getCsElement(element) is giving me right ElementCS. Now the last thing is org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode(elemcs) returning null....
do you have any idea what is wrong?

org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode(elemcs).getOffSet() is positioning in file or in OCL statement?

i am looking at org.eclipse.ocl.examples.test.xtext.testValidate_Bug418552_oclinecore to get some understanding

[Updated on: Tue, 29 April 2014 10:43]

Report message to a moderator

Re: OCL Pivot - Visitor implementation [message #1321579 is a reply to message #1321532] Tue, 29 April 2014 11:19 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

Yes. NodeModelUtils gives you the Xtext node which will only exuist if
you have used the Xtext parser.

You have to do

ecore->pivot->cs->text->cs->pivot

to activate Xtext for text->cs

Regards

Ed

On 29/04/2014 11:41, ModelGeek Mising name wrote:
> thanks for your excellent support!
> Now i have ecore->pivot->cs->pivot conversion and now
> ElementUtil.getCsElement(element) is giving me right ElementCS. Now
> the last thing is
> org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode(elemcs)
> returning null....
> do you have any idea what is wrong?
>
>
Re: OCL Pivot - Visitor implementation [message #1321700 is a reply to message #1321579] Tue, 29 April 2014 12:49 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
thanks once again!

Can you please give me hint (or can refer to ant test case doing this) on how to do CS->Text and Text->CS?

Re: OCL Pivot - Visitor implementation [message #1321714 is a reply to message #1321700] Tue, 29 April 2014 12:56 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

Look at org.eclipse.ocl.examples.test.xtext.RoundTripTests

Regards

Ed Willink


On 29/04/2014 13:49, ModelGeek Mising name wrote:
> thanks once again!
>
> Can you please give me hint (or can refer to ant test case doing this)
> on how to do CS->Text and Text->CS?
>
>
Re: OCL Pivot - Visitor implementation [message #1321783 is a reply to message #1321714] Tue, 29 April 2014 13:54 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
sorry for too many questions but i am confused about CS->Text->CS.
I have tried to look into org.eclipse.ocl.examples.test.xtext.RoundTripTests but i am not able to understand CS->Text->CS.

Can you please guide me on how to do CS->Text->CS.

i really appreciate your help and support.

Re: OCL Pivot - Visitor implementation [message #1321863 is a reply to message #1321783] Tue, 29 April 2014 14:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

It is one hour since my last reply; that is not enough time for you to
have really studied the code.

Step through the code, with the aid of breakpoints.

I do not have time at the moment to write a tutorial.

Ask specific questions.

Regards

Ed Willink


On 29/04/2014 14:54, ModelGeek Mising name wrote:
> sorry for too many questions but i am confused about CS->Text->CS.
> I have tried to look into
> org.eclipse.ocl.examples.test.xtext.RoundTripTests but i am not able
> to understand CS->Text->CS.
>
> Can you please guide me on how to do CS->Text->CS.
>
> i really appreciate your help and support.
>
>
Re: OCL Pivot - Visitor implementation [message #1323755 is a reply to message #1321863] Wed, 30 April 2014 12:21 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
I am converting ecore->pivot->cs and then i have saving file (.oclinecore human friendly text version) and it is saved correctly and then i open the same saved file again and then i do cs->pivot conversion but org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode(elemcs) is still giving null.

Is saving file in text format (.oclinecore) is CS->Text and then loading it back to CS is what you meant by CS->Text->CS? i could not find any explicit comments in test cases code for CS->Text->CS.

thank your so much for help!
Re: OCL Pivot - Visitor implementation [message #1323877 is a reply to message #1321863] Wed, 30 April 2014 13:43 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
i have fixed the null problem.

Now the problem is that ICompositeNode only gives the information about the index of specific property in the text file. But i am looking for the property start and end index in the given OCL expression string.

Lets say i have an oclinecore model. For example "self.myattribute1 + 100"

now i want to know the index of myattribute (start index = 5, end index = 16)

the example file can be like

import ecore : 'http://www.eclipse.org/emf/2002/Ecore';

package temp : Test = 'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial'
{
class TestClass
{
attribute test : ecore::EDoubleObject { derived volatile }
{
derivation: self.myattribute1 + 100;
}
attribute myattribute1 : ecore::EDoubleObject { derived volatile }
{
derivation: 100;

}
}
}

Can you please guide me in this?
Re: OCL Pivot - Visitor implementation [message #1323949 is a reply to message #1323877] Wed, 30 April 2014 14:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
HI

If you use the OCLinEcore editor, the outline shows the AST and by
selecting elements in the outline you can see what the corresponding
text range is.

If it's what you want, see why your code differs from the OCLinEcore editor.

If it's not then may be there is a bug in the position maintenance.

Regards

Ed Willink

On 30/04/2014 14:43, ModelGeek Mising name wrote:
> i have fixed the null problem.
>
> Now the problem is that ICompositeNode only gives the information
> about the index of specific property in the text file. But i am
> looking for the property start and end index in the given OCL
> expression string.
>
> Lets say i have an oclinecore model. For example "self.myattribute1 +
> 100"
>
> now i want to know the index of myattribute (start index = 5, end
> index = 16)
>
> the example file can be like
>
> import ecore : 'http://www.eclipse.org/emf/2002/Ecore';
>
> package temp : Test =
> 'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial'
> {
> class TestClass
> {
> attribute test : ecore::EDoubleObject { derived volatile }
> {
> derivation: self.myattribute1 + 100;
> }
> attribute myattribute1 : ecore::EDoubleObject { derived
> volatile }
> {
> derivation: 100;
>
> }
> }
> }
>
> Can you please guide me in this?
>
Re: OCL Pivot - Visitor implementation [message #1323989 is a reply to message #1323949] Wed, 30 April 2014 14:53 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
I think i was not able to explain properly. ICompositeNode gives index and position of any element in file and it is correct(i can understand it is needed for outline view) but i am looking the position within one OCL statement.

For example i create visitor for "self.test1 + self.test + 100". I want to get the position of "test1" in the above mentioned ocl statement only, not the position of test1 attribute in the file containing oclinecore model.

I used to get position with in OCL expression being visited using classical OCL package(PropertyCallExp<EClassifier, EStructuralFeature> has getStartPosition and getEndPosition give the position within the ocl expression being visited).

So can i get the position of property within ocl expression being visited using visitor?

Re: OCL Pivot - Visitor implementation [message #1324004 is a reply to message #1323989] Wed, 30 April 2014 15:03 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

You still don't explain. I've no idea what you perceive to be the
difference between your two contexts.

Regards

Ed Willink

On 30/04/2014 15:53, ModelGeek Mising name wrote:
> I think i was not able to explain properly. ICompositeNode gives index
> and position of any element in file and it is correct(i can understand
> it is needed for outline view) but i am looking the position within
> one OCL statement.
>
> For example i create visitor for "self.test1 + self.test + 100". I
> want to get the position of "test1" in the above mentioned ocl
> statement only, not the position of test1 attribute in the file
> containing oclinecore model.
>
> I used to get position with in OCL expression being visited using
> classical OCL package(PropertyCallExp<EClassifier, EStructuralFeature>
> has getStartPosition and getEndPosition give the position within the
> ocl expression being visited).
>
> So can i get the position of property within ocl expression being
> visited using visitor?
>
>
Re: OCL Pivot - Visitor implementation [message #1324043 is a reply to message #1324004] Wed, 30 April 2014 15:29 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
if you can recall the functionality of PropertyCallExp<EClassifier, EStructuralFeature>.getStartPosition() operation. It does not give the position of element in text file(.ecore | .oclinecore) but in the ocl statement being visited usinf visitor initerface.

One ecore/oclinecore model can contains multiple classes, attributes and OCL statements related to attribute.

Here i am talking about only one OCL statement and i want position of one segment of ocl statement in whole OCL statement.

"self.test1 + self.test2 + 100" is an OCL statement self.test1 is part of this OCL statement and its position is (startIndex=0, endIndex = 10). This is what PropertyCallExp<EClassifier, EStructuralFeature>.getStartPosition() gives and this is what i want in pivot.

[Updated on: Wed, 30 April 2014 15:30]

Report message to a moderator

Re: OCL Pivot - Visitor implementation [message #1324091 is a reply to message #1324043] Wed, 30 April 2014 15:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
HI

If you want a locally relative rather than globally relative position,
compute the difference bettwen the globally relative offset at the start
of the overall AST and the globally relative offset of the AST node.

Regards

Ed Willink


On 30/04/2014 16:29, ModelGeek Mising name wrote:
> if you can recall the functionality of PropertyCallExp<EClassifier,
> EStructuralFeature>.getStartPosition() operation. It does not give the
> position of element in text but in the ocl statemene being visited.
> One ecore/oclinecore model can contains multiple classes, attributes
> and OCL statements related to attribute.
>
> Here i am talking about only one OCL statement and i want position of
> one segment of ocl statement in whole OCL statement.
>
> "self.test1 + self.test2 + 100" is an OCL statement self.test1 is part
> of this OCL statement and its position is (startIndex=0, endIndex =
> 10). This is what PropertyCallExp<EClassifier,
> EStructuralFeature>.getStartPosition() gives and this is what i want
> in pivot.
>
>
Re: OCL Pivot - Visitor implementation [message #1338751 is a reply to message #1324091] Wed, 07 May 2014 11:02 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
The position i am getting for an attribute is the position of element in file. For example, consider the following model. The ICompositeNode position for attribute t1 is line 11 and t2 is line 16.

Now if i want position of "t2" in derivation OCL statement of t1("2*t2" : total length of statement is 4 chars) which is 2(startIndex).
ICompositeNode gives me line index for t2 is 16

1 import ecore : 'http://www.eclipse.org/emf/2002/Ecore';
2
3 package temp : Test = 'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial'
4 {
5 class Tester
6 {
11 attribute t1: ecore::EDoubleObject { derived volatile }
12 {
13 derivation: 2*t2;
14 }
15 }
16 attribute t2: ecore::EDoubleObject { derived volatile }
17 {
18 derivation: 2*2;
19 }
20 }
21 }
22 }

In classical OCL, i used to get the position of any property call in any OCL expression with respect to the OCL statement only. So getting the elements declaration position in text file will not help me. I want the position of element call in OCL statement of other element.

Is it possible in Pivot as well?


cheers,

[Updated on: Wed, 07 May 2014 11:04]

Report message to a moderator

Re: OCL Pivot - Visitor implementation [message #1338770 is a reply to message #1338751] Wed, 07 May 2014 11:14 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

I'm sure it's possible, I do all sorts of useful things with line
numbers. But I really don't understand what you're saying.

What is a "position"?

line number/charter offset in line/character offset in file.

Regards

Ed Willink

On 07/05/2014 12:02, ModelGeek Mising name wrote:
> The position i am getting for an attribute is the position of element
> in file. For example, consider the following model. The ICompositeNode
> position for attribute t1 is line 11 and t2 is line 16.
>
> Now if i want position of "t2" in derivation OCL statement of
> t1("2*t1" : total length of statement is 4 chars) is 2(startIndex).
> ICompositeNode gives me line index for t2 is 16
>
> 1 import ecore : 'http://www.eclipse.org/emf/2002/Ecore';
> 2 3 package temp : Test =
> 'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial'
> 4 {
> 5 class Tester
> 6 {
> 11 attribute t1: ecore::EDoubleObject { derived volatile }
> 12 {
> 13 derivation: 2*t2;
> 14 }
> 15 }
> 16 attribute t2: ecore::EDoubleObject { derived volatile }
> 17 {
> 18 derivation: 2*2;
> 19 }
> 20 }
> 21 }
> 22 }
>
> In classical OCL, i used to get the position of any property call in
> any OCL expression with respect to the OCL statement only. So getting
> the elements declaration position in text file will not help me. I
> want the position of element call in OCL statement of other element.
>
> Is it possible in Pivot as well?
>
>
> cheers,
Re: OCL Pivot - Visitor implementation [message #1338787 is a reply to message #1338770] Wed, 07 May 2014 11:24 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
i am looking for start offset for property call in OCL statement.
if we consider the same model, the OCL statement for t1 is "2*t2", so the start offset of "t2" is 2.

derivation statement for t1 : "2*t2" (total length 4 chars)
start offSet of t2 in OCL statemnet is 2.

Really thankful to you for your help and support!
Re: OCL Pivot - Visitor implementation [message #1338806 is a reply to message #1338787] Wed, 07 May 2014 11:33 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

Those are character offsets, which are 1-based so 1/3 in your examples.

As I wrote earlier

"If you want a locally relative rather than globally relative position,
compute the difference bettwen the globally relative offset at the start
of the overall AST and the globally relative offset of the AST node. "

What is your problem?

Regards

Ed Willink

On 07/05/2014 12:24, ModelGeek Mising name wrote:
> i am looking for start offset for property call in OCL statement.
> if we consider the same model, the OCL statement for t1 is "2*t2", so
> the start offset of "t2" is 2.
>
> derivation statement for t1 : "2*t2" (total length 4 chars)
> start offSet of t2 in OCL statemnet is 2.
>
> Really thankful to you for your help and support!
Re: OCL Pivot - Visitor implementation [message #1338841 is a reply to message #1338806] Wed, 07 May 2014 11:51 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
Let's suppose i want to know if attribute t1 has used attribute t2 in its derivation statement and at what position(offset).
lets suppose ICompositeNode gives me offset of t1(somewhere at line 11) and we call it X.
lets suppose ICompositeNode gives me offset of t2(somewhere at line 16) and we call it Y.
Now i only want to look into part of line 13 "2*t2" and want to know if "t2" is utilized in it or not... if yes then at what offset?

1 import ecore : 'http://www.eclipse.org/emf/2002/Ecore';
2 package temp : Test =
3'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial'
4 {
5 class Tester
6 {
11 attribute t1: ecore::EDoubleObject { derived volatile }
12 {
13 derivation: 2*t2;
14 }
15 }
16 attribute t2: ecore::EDoubleObject { derived volatile }
17 {
18 derivation: 2*2;
19 }
20 }
21 }
22 }

[Updated on: Wed, 07 May 2014 11:51]

Report message to a moderator

Re: OCL Pivot - Visitor implementation [message #1338877 is a reply to message #1338841] Wed, 07 May 2014 12:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
HI

I think you want to take a break and think about your problem. You seem
to be using a really stupid approach.

If you're interested in containment, you're probably interested in model
containment not text accidents.

But if you want text, you could just toString() the t1 and t2
attributes. Or get the origainl selections.

Or your good go to the total document and work there.

Regards

Ed Willink


On 07/05/2014 12:51, ModelGeek Mising name wrote:
> Let's suppose i want to know if attribute t1 has used attribute t2 in
> its derivation statement and at what position(offset).
> lets suppose ICompositeNode gives me offset of t1(line 11) and we call
> it X.
> lets suppose ICompositeNode gives me offset of t2(line 16) and we call
> it Y.
> Now i only want to look into part of line 13 "2*t2" and want to know
> if "t2" is utilized in it or not... if yes then at what offset?
>
> 1 import ecore : 'http://www.eclipse.org/emf/2002/Ecore';
> 2 package temp : Test =
> 3'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial'
> 4 {
> 5 class Tester
> 6 {
> 11 attribute t1: ecore::EDoubleObject { derived volatile }
> 12 {
> 13 derivation: 2*t2;
> 14 }
> 15 }
> 16 attribute t2: ecore::EDoubleObject { derived volatile }
> 17 {
> 18 derivation: 2*2;
> 19 }
> 20 }
> 21 }
> 22 }
Re: OCL Pivot - Visitor implementation [message #1338929 is a reply to message #1338877] Wed, 07 May 2014 12:43 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
Actually i implemented the same solution in classic OCL and it worked very well.
I am not looking for containment at all.
I could use String operations to find a specific text in String but it will cause many problems( one example: there can be many classes in model having same attribute name e,g. class1.t2 and class2.t2 and i want to differentiate them)
if you could recall what is the functionality of org.eclipse.ocl.utilities.ASTNode.getStartPosition() then it will be easier for you to understand what i am looking for.

I respect and appreciate you for your support and help!

cheers

Re: OCL Pivot - Visitor implementation [message #1338959 is a reply to message #1338929] Wed, 07 May 2014 12:57 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

I am clearly totally unable to understand your problem, which seems to
be trivial.

Have a look at https://wiki.eclipse.org/OCL/ForumNetiquette and may be
you might get a better answer.

Regards

Ed Willink

On 07/05/2014 13:43, ModelGeek Mising name wrote:
> Actually i implemented the same solution in classic OCL and it worked
> very well.
> I am not looking for containment at all.
> I could use String operations to find a specific text in String but it
> will cause many problems( one example: there can be many classes in
> model having same attribute name e,g. class1.t2 and class2.t2 and i
> want to differentiate them)
> if you could recall what is the functionality of
> org.eclipse.ocl.utilities.ASTNode.getStartPosition() then it will be
> easier for you to understand what i am looking for.
>
> I respect and appreciate you for your support and help!
>
> cheers
>
>
Re: OCL Pivot - Visitor implementation [message #1338968 is a reply to message #1338877] Wed, 07 May 2014 13:00 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
Just to give you some inside of why i need this. let's say one attribute name is changed in model and that attribute is being used in many OCL statements of other attributes/operations etc.. and i want to update all OCL statements automatically so the new name is utilized though out the model.

thanks!

cheers

[Updated on: Wed, 07 May 2014 13:01]

Report message to a moderator

Re: OCL Pivot - Visitor implementation [message #1339009 is a reply to message #1338959] Wed, 07 May 2014 13:24 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
I have attached an example Ecore file. It contains one class and three attributes.
Attribute t1 OCL derivation statement : 2*t2
Attribute t2 OCL derivation statement : 2*2
Attribute t3 OCL derivation statement : 3*t2

Now i want to rename "t2" to "t" and want to update OCL derivation statements for t1 and t3 automatically so they should become "2*t" and "3*t" respectively.

I did this in classic OCL using visitor interface and PropertyCallExp<EClassifier, EStructuralFeature> callExp.getStartPosition(). I visited OCL derivation statements for both t1 and t3 and it helped me replacing the "t2" with "t".

I want to do the same in Pivot. I have implemented the visitor for Pivot and i am able to recognize "t2" calls in OCL statement but i am not able to get the exact offset of "t2" call in ocl statement. Once i get the exact start and end offset then i can use string operations to replace "t2" with "t" in OCL statement.

thank you so much!

Cheers,
Re: OCL Pivot - Visitor implementation [message #1339019 is a reply to message #1338929] Wed, 07 May 2014 13:25 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

I think I understand what you are telling me you think you want to do
and I see no reason why it shouldn't work.

You clearly have a test program that doesn't work and I could look at it.

Instead you want me to develop my own test program to replicate what you
refuse to tell me.

I do not have time for such pointless exercises.

If you want help, help yourself by providing the relevant information to
accompany your question.

Regards

Ed Willink

On 07/05/2014 13:43, ModelGeek Mising name wrote:
> Actually i implemented the same solution in classic OCL and it worked
> very well.
> I am not looking for containment at all.
> I could use String operations to find a specific text in String but it
> will cause many problems( one example: there can be many classes in
> model having same attribute name e,g. class1.t2 and class2.t2 and i
> want to differentiate them)
> if you could recall what is the functionality of
> org.eclipse.ocl.utilities.ASTNode.getStartPosition() then it will be
> easier for you to understand what i am looking for.
>
> I respect and appreciate you for your support and help!
>
> cheers
>
>
Re: OCL Pivot - Visitor implementation [message #1339132 is a reply to message #1339009] Wed, 07 May 2014 14:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
On 07/05/2014 14:24, ModelGeek Mising name wrote:
>
> I did this in classic OCL using visitor interface and PropertyCallExp<EClassifier, EStructuralFeature> callExp.getStartPosition(). I visited OCL derivation statements for both t1 and t3 and it helped me replacing the "t2" with "t".
>
This suggests that you wrote some Java code. Isee no Java code in your
attachment.

Regards

Ed Willink
Re: OCL Pivot - Visitor implementation [message #1341335 is a reply to message #1339132] Thu, 08 May 2014 12:38 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
I have attached the sample code. This is simple UI plugin (one view only.. so plz ignore GUI part as it was just for testing). There is one package called "pivotvisitortest" and it contain "ClassicOCL.java" and "PivotOCL.java". There is abc.oclinecore file in model folder. If you run the plugin then a small view will come up and there will following output in console.

------------Classic OCL--------------------
With Classic OCL Changed OCL Statement = (2*tNew) + 1
--------------------------------------------
------------Pivot OCL--------------------
StartIndex = 262
EndIndex = 353
2*(self.t2)+(1)




import ecore : 'http://www.eclipse.org/emf/2002/Ecore';

package temp : Test = 'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial'
{
class TestClass
{
attribute t1 : ecore::EDoubleObject { derived volatile }
{
derivation: (2*t2) + 1;
}
attribute t2 : ecore::EDoubleObject { derived volatile }
{
derivation: 2*2;
}
}
}

The model contains one class with two attribute t1 and t2. Attribute t1 is using t2 in its OCL statement (2*t2) + 1).
Now if i want to rename "t2" with "tNew" so i want to change the OCL statement for t1 to become (2*tNew) + 1.

In ClassicOCL.java, i have done that. I have created an ecore model and have visitor to visit "(2*t2) + 1" and generate "(2*tNew) + 1". Good thing in classic ocl is that i never have to save ecore model on hard drive.

In PivotOCL, i have saved the same ecore model in oclinecore format (in model folder) and i am loading it and converting in to pivot and then to ecore. I have implemented toString visitor to visit the same OCL statement (2*t2) + 1). I am able to find the call to t2 but the positioning in pointing towards the actual saved file's text not in the given OCL statement to visit.
Bad thing in this is that i have to save the model in hard drive and i had to do many conversion so it is very processing heavy.

Hope you will be able to understand the problem....

Thanks for your support.

Cheers,






Re: OCL Pivot - Visitor implementation [message #1342263 is a reply to message #1341335] Thu, 08 May 2014 21:44 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4093
Registered: July 2009
Senior Member
Hi

Your two approaches are not consistent.

Using Classic OCL you treat each OCL expression as the whole text to
refactor.

Using Pivot OCL you treat the one composite OCLinEcore document as the
text to refactor. This is potentially more efficient for many
refactorings. But of course you must deal with total document indexes,
which shouldn't be a problem.

Using Pivot OCL you could do the same as the Classic OCL parsing a
*.essentialocl document for each expression.

Refactoring in the text domain is pretty foolish. Much better to rename
the property and then use the PrettyPrinter to regenerate the source
text, thereby accommodating all renamings and avoiding possible name
collisions. If you care about your whitespace, you might need to
re-interleave it. (Only the Pivot OCL has a PrettyPrinter.)

If you are interested in refactoring you might want to look at the EMF
Refactor project.

Regards

Ed Willink



On 08/05/2014 13:38, ModelGeek Mising name wrote:
> I have attached the sample code. This is simple UI plugin (one view only.. so plz ignore GUI part as it was just for testing). There is one package called "pivotvisitortest" and it contain "ClassicOCL.java" and "PivotOCL.java". There is abc.oclinecore file in model folder. If you run the plugin then a small view will come up and there will following output in console.
>
> ------------Classic OCL--------------------
> With Classic OCL Changed OCL Statement = (2*tNew) + 1
> --------------------------------------------
> ------------Pivot OCL--------------------
> StartIndex = 262
> EndIndex = 353
> 2*(self.t2)+(1)
>
>
>
>
> import ecore : 'http://www.eclipse.org/emf/2002/Ecore';
>
> package temp : Test = 'http://www.eclipse.org/mdt/ocl/oclinecore/tutorial'
> {
> class TestClass
> {
> attribute t1 : ecore::EDoubleObject { derived volatile }
> {
> derivation: (2*t2) + 1;
> }
> attribute t2 : ecore::EDoubleObject { derived volatile }
> {
> derivation: 2*2;
> }
> }
> }
>
> The model contains one class with two attribute t1 and t2. Attribute t1 is using t2 in its OCL statement (2*t2) + 1).
> Now if i want to rename "t2" with "tNew" so i want to change the OCL statement for t1 to become (2*tNew) + 1.
>
> In ClassicOCL.java, i have done that. I have created an ecore model and have visitor to visit "(2*t2) + 1" and generate "(2*tNew) + 1". Good thing in classic ocl is that i never have to save ecore model on hard drive.
>
> In PivotOCL, i have saved the same ecore model in oclinecore format (in model folder) and i am loading it and converting in to pivot and then to ecore. I have implemented toString visitor to visit the same OCL statement (2*t2) + 1). I am able to find the call to t2 but the positioning in pointing towards the actual saved file's text not in the given OCL statement to visit.
> Bad thing in this is that i have to save the model in hard drive and i had to do many conversion so it is very processing heavy.
>
> Hope you will be able to understand the problem....
>
> Thanks for your support.
>
> Cheers,
>
>
>
>
>
>
>
Re: OCL Pivot - Visitor implementation [message #1342337 is a reply to message #1342263] Thu, 08 May 2014 22:27 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
Yes, actually i started to explore oclinecore approach as it was suggested in earlier parts of our conversation. I am looking to consider only one OCL expression instead of whole text document. I will try to *.essentialocl. I have been looking to extend prettyprintervisitor as well. I will looking EMF refactor as well. Can you guide me to any good tutorial for *.essentialocl and EMF refactor?

thank you so much for your support.

[Updated on: Thu, 08 May 2014 22:31]

Report message to a moderator

Re: OCL Pivot - Visitor implementation [message #1343749 is a reply to message #1342263] Fri, 09 May 2014 12:43 Go to previous messageGo to previous message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 515
Registered: June 2011
Senior Member
I have tried to rename the property in propertycallexp method so the expression.toString gives me the updated statement but prettyprinter give the same old statement

expression = helper.createQuery(oclToRefactor);
MyVisitor visitor = new MyVisitor(eAttribute2, new StringBuilder(), oclToRefactor, "newT");
expression.accept(visitor);
System.out.println("printer = " + PrettyPrinter.print(expression));
System.out.println("Expression.toString = " + expression.toString());

The output is
printer = (2*t2) + 1
Expression.toString = 2*(self.newT)+(1)


@Override
public String visitPropertyCallExp(@NonNull org.eclipse.ocl.examples.pivot.PropertyCallExp pc) {
Property property = pc.getReferredProperty();
EClass cClass = (EClass) property.getETarget().eContainer();
if(cClass.getName().equals(attribute.getEContainingClass().getName()) && property.getName().equals(attribute.getName())) {
property.setName(newName);
pc.setName(newName);
}
return super.visitPropertyCallExp(pc);
}

Can you please explain a bit about how to rename the property?

thanks!
Previous Topic:Invariants on EStructuralFeatures
Next Topic:EssentialOCL->Pivot->Ecore conversion
Goto Forum:
  


Current Time: Thu Oct 23 03:10:55 GMT 2014

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

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