Skip to content

Commit

Permalink
update java gen round 2
Browse files Browse the repository at this point in the history
  • Loading branch information
AFine-gs committed Jan 24, 2024
1 parent 774b121 commit 024d46f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Class meta::external::language::java::transform::Conventions
newFunctionProhibitedList : meta::pure::metamodel::type::Class<Any>[*];
providedVariables : Map<String, Code>[1];
visitedFunctions : FunctionExpression[*];

existingClasses : meta::external::language::java::metamodel::Class[*];
extensions : meta::pure::extension::Extension[*];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,15 @@ function <<access.private>> meta::external::language::java::transform::processFu

$result->debugAndReturn($debug);
}
function <<access.private>> meta::external::language::java::transform::classHasFunction(cl:meta::external::language::java::metamodel::Class[1], f:FunctionSignature[1]):Boolean[1]
{
$f.class.simpleName==$cl.simpleName && $f.class.package==$cl.package && $cl.methods.name->contains($f.method.name);

}

function <<access.private>> meta::external::language::java::transform::processConcreteFunctionExpression(fe: FunctionExpression[1], conventions: Conventions[1], debug: meta::pure::tools::DebugContext[1]):Code[1]
{
print(if($debug.debug,|$debug.space+'processConcreteFunctionExpression '+$fe.func->elementToPath()+'\n',|''));

let signature = $conventions->functionSignature($fe.func->cast(@ConcreteFunctionDefinition<Any>));
let args = $fe.parametersValues->evaluateAndDeactivate()->map(p| $p->generateJava($conventions, $debug->indent()));
let argTypes = $signature.method.parameters.type;
Expand All @@ -265,11 +269,11 @@ function <<access.private>> meta::external::language::java::transform::processCo
if($argType->isJavaList(), |$arg->j_listOf($argType), |$arg)->j_cast($argType);
}
);

if(!($conventions.visitedFunctions->contains($fe)),
if(!($conventions.visitedFunctions->contains($fe)) && $conventions.existingClasses->filter(c|$c->classHasFunction($signature))->isEmpty(),
|let newCon = ^$conventions(visitedFunctions += $fe->cast(@FunctionExpression));
let name = $fe.func->elementToPath();
let dependency = newDependency(
let name = $fe.func->elementToPath();
let dependency = newDependency(
$name,
{state|
if(!$state.visitedFunctions->contains($fe.func->elementToPath()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ function meta::pure::executionPlan::platformBinding::legendJava::bindPlanToLegen
let legendJavaConfig = $platformBindingConfig->convertToLegendJavaPlatformBindingConfigIfPossible();
let generationContext = $plan->prepareGenerationContext($legendJavaConfig, $extensions, $debug);

let baseProject = $generationContext->generateTypes($debug);
let baseProject = $generationContext->generateTypes($debug); //first one
let generatedNode = $plan.rootExecutionNode->generateLegendJavaPlatformBindingCode('root', $generationContext, $extensions, $debug);
let generatedProject = $baseProject->concatenate($generatedNode.project)->toOneMany()->mergeProjects();

// $generatedProject-> meta::external::language::java::serialization::printProject()->println() ; []->toOne();
^$plan
(
rootExecutionNode = $generatedNode.node,
Expand Down Expand Up @@ -126,13 +126,13 @@ function meta::pure::executionPlan::platformBinding::legendJava::generateLegendJ

let newNode = ^$node(executionNodes = $generatedChildren.node, implementation = $generated.implementation);
let fullProject = $generated.project->concatenate($generatedChildren.project)->concatenate($context.baseProject)->mergeProjectsNullable();

let updatedContext = ^$context(generatedProjects+=$fullProject);
if ($supportingExtension.generateLegendJavaCodeForExtraChildNodes->isNotEmpty(),
| $supportingExtension.generateLegendJavaCodeForExtraChildNodes->toOne()->eval($newNode, $fullProject, $path, $context, $extensions, $debug),
| $supportingExtension.generateLegendJavaCodeForExtraChildNodes->toOne()->eval($newNode, $fullProject, $path, $updatedContext, $extensions, $debug),
| $newNode->match([
{g:GlobalGraphFetchExecutionNode[1] |
let transformedChildren = $g.children->size()->range()->map(x | $g.children->at($x)->generateLegendJavaPlatformBindingCode($path + '.globalChild' + $x->toString(), $context, $extensions, $debug));
let transformedLocal = $g.localGraphFetchExecutionNode->generateLegendJavaPlatformBindingCode($path + localGraphFetchNodePathPrefix(), $context, $extensions, $debug);
let transformedChildren = $g.children->size()->range()->map(x | $g.children->at($x)->generateLegendJavaPlatformBindingCode($path + '.globalChild' + $x->toString(), $updatedContext, $extensions, $debug));
let transformedLocal = $g.localGraphFetchExecutionNode->generateLegendJavaPlatformBindingCode($path + localGraphFetchNodePathPrefix(), ^$updatedContext(generatedProjects+=$transformedChildren.project), $extensions, $debug);
^GeneratedNode(
node = ^$g
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ function <<access.private>> meta::pure::mapping::modelToModel::executionPlan::pl
function <<access.private>> meta::pure::mapping::modelToModel::executionPlan::platformBinding::legendJava::graphFetch::setTransformerCodes(input: Code[1],path: String[1], set: InstanceSetImplementation[1], graphFetchTree: RoutedGraphFetchTree[1], graphImplClass: meta::external::language::java::metamodel::Class[1], wrapAsGraphInstance: Boolean[1], resolveToList: Boolean[1], context: GenerationContext[1], extensions: Extension[*], debug: DebugContext[1]): Code[1..*]
{
let conventions = $context.conventions;
let updatedConventions = ^$conventions(existingClasses = $context.generatedProjects->map(p|$p->allClasses()));
let requiredSubTrees = $graphFetchTree.subTrees->cast(@RoutedPropertyGraphFetchTree)->filter(st | $st.property->instanceOf(Property) && ($st.property->isPrimitiveValueProperty() || !generatePropertyNodeForComplexProperty($st, $set)));
let setHasExplosion = $set->hasExplodeProperty();
let result = j_variable($graphImplClass, 'result');
Expand All @@ -601,13 +602,13 @@ function <<access.private>> meta::pure::mapping::modelToModel::executionPlan::pl
let src = j_variable($srcJavaClass, 'src');
let isMerged = $set->isPartOfMerge();
let transform = if ($setHasExplosion,
| $set->cast(@PureInstanceSetImplementation)->propertyExplosionCodes($requiredSubTrees, $result, $graphImplClass, $src, $wrapAsGraphInstance, $resolveToList, $conventions, $extensions, $debug),
| $set->cast(@PureInstanceSetImplementation)->propertyExplosionCodes($requiredSubTrees, $result, $graphImplClass, $src, $wrapAsGraphInstance, $resolveToList, $updatedConventions, $extensions, $debug),
| let inScopeSubTrees = $requiredSubTrees->filter( t| $set->propertyMappingsByPropertyName($t.property->cast(@Property<Nil,Any|*>).name->toOne())->head()->isNotEmpty() && $isMerged || !$isMerged );

let propertyValues = $inScopeSubTrees->map({st |
let prop = $st.property->cast(@Property<Nil,Any|*>);
let propertyMapping = $set->propertyMappingsByPropertyName($prop.name->toOne())->head();
let value = $set->generatePropertyMappingTransform($prop, $propertyMapping, $src, $conventions, $extensions, $debug->indent());
let value = $set->generatePropertyMappingTransform($prop, $propertyMapping, $src, $updatedConventions, $extensions, $debug->indent());
$value->map(v| pair($prop, $v));
});
let milestoneDateGetter = {strategy: SingleDateTemporalStrategy[1] |
Expand Down Expand Up @@ -658,7 +659,6 @@ function meta::pure::mapping::modelToModel::executionPlan::platformBinding::lege
function meta::pure::mapping::modelToModel::executionPlan::platformBinding::legendJava::graphFetch::generatePropertyMappingTransform(setImpl: InstanceSetImplementation[1], property: Property<Nil,Any|*>[1], propertyMapping: PropertyMapping[0..1], src: Code[1], conventions: Conventions[1], extensions: Extension[*], explodeProperty: Boolean[1], debug: DebugContext[1]): Code[0..1]
{
print(if($debug.debug,|$debug.space+'generatePropertyMappingTransform: \''+$property.name->toOne()+'\'\n', |''));

let isNoMappingPassThru = $propertyMapping->isEmpty() && $property.owner->instanceOf(meta::pure::metamodel::type::Class) && $setImpl->passThruProperty($property, $extensions);
let isNoMappingDefaultToEmpty = $propertyMapping->isEmpty() && $property.owner->instanceOf(meta::pure::metamodel::type::Class) && $setImpl->isNoMappingDefaultToEmpty($property);
let isMergedUnMappedProperty = $propertyMapping->isEmpty() && $setImpl ->isPartOfMerge();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Class meta::pure::executionPlan::platformBinding::legendJava::GenerationContext
conventions : Conventions[1];
nodeInfos : NodeInfo[*];
baseProject : Project[0..1];
generatedProjects : Project[*];
}

Class meta::pure::executionPlan::platformBinding::legendJava::NodeInfo
Expand Down Expand Up @@ -85,6 +86,7 @@ Class meta::pure::executionPlan::platformBinding::legendJava::GeneratedNode
// ----------------------------------------------------------------------------------------------------------



function meta::pure::executionPlan::platformBinding::legendJava::projectToImplementation(project:Project[1]):JavaPlatformImplementation[1]
{
let sfer = newStringifier($project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function meta::pure::mapping::modelToModel::executionPlan::platformBinding::lege

generateLegendJavaCodeForExtraChildNodes = {node: ExecutionNode[1], project: Project[0..1], path: String[1], context: GenerationContext[1], extensions: Extension[*], debug: DebugContext[1] |
$node->match([
{i: InMemoryGraphFetchExecutionNode[1] |
{i: InMemoryGraphFetchExecutionNode[1] |
let transformedChildren = $i.children->size()->range()->map(x | $i.children->at($x)->generateLegendJavaPlatformBindingCode($path + '.localChild' + $x->toString(), $context, $extensions, $debug));
^GeneratedNode
(
Expand Down Expand Up @@ -116,7 +116,9 @@ function meta::pure::mapping::modelToModel::executionPlan::platformBinding::lege
filterCodeGenerator = {set: InstanceSetImplementation[1], src: Code[1], withoutFilter: Code[1..*], context: GenerationContext[1], debug:DebugContext[1] |
{ps : PureInstanceSetImplementation[1] |
if ($ps.filter->isNotEmpty(),
| $ps.filter.expressionSequence->at(0)->evaluateAndDeactivate()->generateJava($context.conventions, $debug->indent())->j_if($withoutFilter, j_null()->j_return()),
| let conventions = $context.conventions;
let updatedConventions = ^$conventions(existingClasses = $context.generatedProjects->map(p|$p->allClasses()));
$ps.filter.expressionSequence->at(0)->evaluateAndDeactivate()->generateJava($updatedConventions, $debug->indent())->j_if($withoutFilter, j_null()->j_return());,
| $withoutFilter
)
}
Expand Down

0 comments on commit 024d46f

Please sign in to comment.