Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix source tree calculation for qualified property #3149

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2487,4 +2487,74 @@ Mapping meta::pure::graphFetch::tests::sourceTreeCalc::functionCaching::testMapp
}
)

###Pure
import meta::pure::graphFetch::routing::*;
import meta::pure::mapping::*;
import meta::pure::graphFetch::*;
import meta::pure::graphFetch::execution::*;
function <<test.Test>> meta::pure::graphFetch::tests::sourceTreeCalc::testNestedQualifiedPropertyWithMultiExpression():Boolean[1]
{
let grammar = '###Pure\n'+
'import meta::pure::graphFetch::*;\n'+
'import meta::test::*;\n'+
'import meta::pure::graphFetch::routing::*;\n'+
'import meta::test::withSourceQualifiedProperty::*;\n'+
'\n'+
'function <<test.Test>> meta::test::testWithSourceQualifiedProperty():GraphFetchTree[1]\n'+
'{\n'+
' #{\n'+
' A {\n'+
' a1\n'+
' }\n'+
' }#;\n'+
'}\n'+
'\n'+
'Class meta::test::withSourceQualifiedProperty::A\n'+
'{\n'+
' a1: String[1];\n'+
'}\n'+
'\n'+
'Class meta::test::withSourceQualifiedProperty::_A\n'+
'{\n'+
' a1: _B[1];\n'+
' qa(i:Integer[1]) {\n'+
' if($i == 1,\n'+
' | $this.a1,\n'+
' | ^_B(b1=\'sdfds\')\n'+
' );\n'+
' }: _B[1];\n'+
'}\n'+
'\n'+
'Class meta::test::withSourceQualifiedProperty::_B\n'+
'{\n'+
' b1: String[1];\n'+
'}\n'+
'\n'+
'###Mapping\n'+
'import meta::test::withSourceQualifiedProperty::*;\n'+
'\n'+
'Mapping meta::test::withSourceQualifiedProperty::testMapping\n'+
'(\n'+
' A: Pure\n'+
' {\n'+
' ~src _A\n'+
' a1: $src.qa(1).b1\n'+
' }\n'+
')';

let elements = meta::legend::compileLegendGrammar($grammar);
let mapping = $elements->filter(e|$e->instanceOf(Mapping))->at(0)->cast(@Mapping);
let function = $elements->filter(e|$e->instanceOf(FunctionDefinition))->at(0)->cast(@FunctionDefinition<{->GraphFetchTree[1]}>);
let tree = $function.expressionSequence->at(0)->cast(@InstanceValue)->evaluateAndDeactivate().values->at(0)->cast(@RootGraphFetchTree<Any>);

let sourceTree = calculateSourceTree($tree, $mapping, meta::pure::extension::defaultExtensions())->sortTree();

let expected = '#{meta::test::withSourceQualifiedProperty::_A {\n'+
' a1 {\n'+
' b1\n'+
' }\n'+
'}}#';

assertEquals($expected, $sourceTree->asString(true));
}

Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,18 @@ function <<access.private>> meta::pure::lineage::scanProperties::dummyNodeForCla
^PropertyPathNode( class = $c, property= getDummyProperty());
}

function <<access.private>> meta::pure::lineage::scanProperties::findAndAddChildrenAtTheEnd(tree: PropertyPathTree[1], path: PropertyPathNode[*], toAdd: PropertyPathTree[*]):PropertyPathTree[1]
function meta::pure::lineage::scanProperties::findAndAddChildrenAtTheEnd(tree: PropertyPathTree[1], path: PropertyPathNode[*], toAdd: PropertyPathTree[*]):PropertyPathTree[1]
{
if($path->isEmpty(),
| ^$tree(children += $toAdd),
| let first = $path->at(0);
let correctTree = $tree.children->filter(x | $x.value->instanceOf(PropertyPathNode) && ($x.value->cast(@PropertyPathNode).property == $first.property))->toOne();
let otherTrees = $tree.children->remove($correctTree);
^$tree(
children = $otherTrees->concatenate($correctTree->findAndAddChildrenAtTheEnd($path->tail(), $toAdd))
let correctTree = $tree.children->filter(x | $x.value->instanceOf(PropertyPathNode) && ($x.value->cast(@PropertyPathNode).property == $first.property));
if($correctTree->isEmpty(),
|^$tree(children += $toAdd),
| let otherTrees = $tree.children->remove($correctTree->toOne());
^$tree(
children = $otherTrees->concatenate($correctTree->toOne()->findAndAddChildrenAtTheEnd($path->tail(), $toAdd))
);
);
)
}
Expand Down Expand Up @@ -788,8 +791,8 @@ function <<access.private>> meta::pure::lineage::scanProperties::recurse_inlineQ
{|
let qual = $p.value->cast(@PropertyPathNode).property->cast(@QualifiedProperty<Any>);
let qualifierTreeCurrent = $qual.expressionSequence->evaluateAndDeactivate()->toOne()->internal_scanProperties([], noVars(), $config,^Map<String,ScanPropertiesState>(), noDebug()).current;
let qualifierTree = $p.qualifierSubTree.children->toOne();
findAndAddChildrenAtTheEnd($qualifierTree, $qualifierTreeCurrent.values, $p.children).children;
let qualifierTree = $p.qualifierSubTree.children;
$qualifierTree->map(t | $t->findAndAddChildrenAtTheEnd($qualifierTreeCurrent.values, $p.children)).children;
}
)->map(nt| $nt->recurse_inlineQualifiedPropertyNodes($config));
},
Expand Down
Loading