Closed gdaniel closed 8 years ago
For nowcollect()
operations are basically ignored, and their body is directly translated and chained to the last step of the chain representing the collect's source expression.
For example the OCL query
ClassDeclaration.allInstances()->collect(cd | cd.bodyDeclarations)
is mapped to the following traversal
metaClassDeclarationNode.inE("kyanosInstanceOf").outV.outE("bodyDeclarations").inV
A solution to handle local iterator variable would be to use a transform
step:
metaClassDelcarationNode.inE("kyanosInstanceOf").outV.transform{def myVar = it; println(it); it._().outE("bodyDeclarations").inV}.scatter
In that case myVar corresponds to the current vertex processed (i.e. the value of the iterator in the collect)
For now iterator variables in
collect()
body are not translated, meaning that it is not possible to access a collect iterator variable in its body.Example (simplified from Train Benchmark):
OCL `package railway
endpackage`
Gremlin
def metaSensor = g.getIndex("metaclasses",Vertex.class)[[name:"Sensor"]]; def metaSensorNode = (metaSensor.hasNext() ? metaSensor.next() : null); metaSensorNode.inE("kyanosInstanceOf").outV ._().outE("monitors").inV .**segment1**.outE("connectsTo").inV .filter{def segment2 = it;segment2.outE("monitoredBy").inV .gather.transform{it.contains(**sensor**);}.next();}._()._();
Two errors there:
contains
has not been declared, and will throw a NPE