OCL Pivot - Visitor implementation [message #1312588] |
Thu, 24 April 2014 11:31 |
ModelGeek Mising name Messages: 550 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 #1312734 is a reply to message #1312614] |
Thu, 24 April 2014 13:17 |
ModelGeek Mising name Messages: 550 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 #1321282 is a reply to message #1320222] |
Tue, 29 April 2014 07:31 |
ModelGeek Mising name Messages: 550 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 #1321374 is a reply to message #1321346] |
Tue, 29 April 2014 08:41 |
ModelGeek Mising name Messages: 550 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 #1321532 is a reply to message #1321497] |
Tue, 29 April 2014 10:41 |
ModelGeek Mising name Messages: 550 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 #1324043 is a reply to message #1324004] |
Wed, 30 April 2014 15:29 |
ModelGeek Mising name Messages: 550 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 #1338751 is a reply to message #1324091] |
Wed, 07 May 2014 11:02 |
ModelGeek Mising name Messages: 550 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 #1338841 is a reply to message #1338806] |
Wed, 07 May 2014 11:51 |
ModelGeek Mising name Messages: 550 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 #1342337 is a reply to message #1342263] |
Thu, 08 May 2014 22:27 |
ModelGeek Mising name Messages: 550 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 #1357380 is a reply to message #1357277] |
Thu, 15 May 2014 13:47 |
ModelGeek Mising name Messages: 550 Registered: June 2011 |
Senior Member |
|
|
I have used MetaModelManagerResourceAdapter.getAdapter(csResource, ocl.getMetaModelManager()); and now conversion does not give any exception but when i try to save the resource then exception comes....
org.eclipse.ocl.examples.pivot.OCL ocl = org.eclipse.ocl.examples.pivot.OCL.newInstance(new PivotEnvironmentFactory());
ASResource asResource = null;
try {
asResource = ocl.ecore2pivot(resource);
BaseCSResource csResource = DomainUtil.nonNullState((BaseCSResource) ecoreResourceSet.createResource(URI.createFileURI("c:\\pivot\\abc.essentialocl")));
MetaModelManagerResourceAdapter.getAdapter(csResource, ocl.getMetaModelManager());
ocl.pivot2cs(asResource, csResource);
csResource.save(null);
} catch (ParserException | IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
org.eclipse.xtext.validation.IConcreteSyntaxValidator$InvalidConcreteSyntaxException: These errors need to be fixed before the model can be serialized.
RootPackageCS.ownedImport[0]->ImportCS'ecore'.pathName->PathNameCS.path[0]->PathElementWithURICS: An object of type PathElementCS is needed instead of PathElementWithURICS for serialization with rule NextPathElementCS.
RootPackageCS.ownedImport[0]->ImportCS'ecore'.pathName->PathNameCS.path[0]->PathElementWithURICS: An object of type PathElementCS is needed instead of PathElementWithURICS for serialization with rule FirstPathElementCS.
RootPackageCS.ownedNestedPackage[0]->PackageCS'temp'.ownedType[0]->ClassCS'TestClass'.ownedProperty[0]->AttributeCS't1'.ownedType->TypedTypeRefCS: An object of type CollectionTypeCS or PrimitiveTypeRefCS or TupleTypeCS is needed instead of TypedTypeRefCS for serialization with rule TypeLiteralWithMultiplicityCS.
RootPackageCS.ownedNestedPackage[0]->PackageCS'temp'.ownedType[0]->ClassCS'TestClass'.ownedProperty[0]->AttributeCS't1'.ownedType->TypedTypeRefCS: An object of type TypeNameExpCS or CollectionTypeCS or PrimitiveTypeRefCS or TupleTypeCS is needed instead of TypedTypeRefCS for serialization with rule TypeExpCS.
RootPackageCS.ownedNestedPackage[0]->PackageCS'temp'.ownedType[0]->ClassCS'TestClass'.ownedProperty[1]->AttributeCS't2'.ownedType->TypedTypeRefCS: An object of type CollectionTypeCS or PrimitiveTypeRefCS or TupleTypeCS is needed instead of TypedTypeRefCS for serialization with rule TypeLiteralWithMultiplicityCS.
RootPackageCS.ownedNestedPackage[0]->PackageCS'temp'.ownedType[0]->ClassCS'TestClass'.ownedProperty[1]->AttributeCS't2'.ownedType->TypedTypeRefCS: An object of type TypeNameExpCS or CollectionTypeCS or PrimitiveTypeRefCS or TupleTypeCS is needed instead of TypedTypeRefCS for serialization with rule TypeExpCS.
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:96)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:130)
at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:344)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:999)
thanks for your help!
[Updated on: Thu, 15 May 2014 14:11] Report message to a moderator
|
|
|
|
|
|
|