Skip to content

Commit

Permalink
Optimize Concrete Function Generation for java plans
Browse files Browse the repository at this point in the history
  • Loading branch information
AFine-gs committed Jan 23, 2024
1 parent caa18af commit 010b5bf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,21 @@ function <<access.private>> meta::external::language::java::transform::processCo
let dependency = newDependency(
$name,
{state|
print(if($debug.debug,|$debug.space+'Implementation of: \''+$fe.func->elementToPath()+'\'\n',|''));
if(!$state.visitedFunctions->contains($fe.func->elementToPath()),
|print(if($debug.debug,|$debug.space+'Implementation of: \''+$fe.func->elementToPath()+'\'\n',|''));
let updatedState = $state->addDependencyVisitedFunctions($fe.func->elementToPath());

let implBody = $fe.func->cast(@ConcreteFunctionDefinition<Any>).expressionSequence->evaluateAndDeactivate()->generateJavaMethodBody($newCon, $debug->indent());
let classesUsed = $signature.method->typesUsed()->concatenate($implBody->typesUsed())->typesToClasses();
let withImports = javaClass('public', $signature.class)
->usingKnownPackages($conventions->knownPackages())
->imports($conventions->standardImports());
let impl = $withImports->addMethod(javaMethod(['public', 'static'], $signature.method.returnType, $signature.method.name, $signature.method.parameters, $implBody));
let dependencies = $implBody->dependencies()->removeDuplicates();
let withDependencies = $dependencies->resolveProjects($state);
let project = mergeProjects(newProject()->addClass($impl)->concatenate($withDependencies->getProjects($dependencies))->toOneMany());
$withDependencies->addDependencyProject($name, $project);
let implBody = $fe.func->cast(@ConcreteFunctionDefinition<Any>).expressionSequence->evaluateAndDeactivate()->generateJavaMethodBody($newCon, $debug->indent());
let classesUsed = $signature.method->typesUsed()->concatenate($implBody->typesUsed())->typesToClasses();
let withImports = javaClass('public', $signature.class)
->usingKnownPackages($conventions->knownPackages())
->imports($conventions->standardImports());
let impl = $withImports->addMethod(javaMethod(['public', 'static'], $signature.method.returnType, $signature.method.name, $signature.method.parameters, $implBody));
let dependencies = $implBody->dependencies()->removeDuplicates();
let withDependencies = $dependencies->resolveProjects($updatedState);
let project = mergeProjects(newProject()->addClass($impl)->concatenate($withDependencies->getProjects($dependencies))->toOneMany());
$withDependencies->addDependencyProject($name, $project);
,|$state);
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ Class meta::external::language::java::metamodel::CodeDependency

Class meta::external::language::java::metamodel::CodeDependencyResolutionState
{
visitedFunctions: String[*];
projectsByDependency : Map<String, Project>[1];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,12 @@ function meta::external::language::java::factory::resolveProjects(dependencies:C
$dependencies->fold({d, s| $d.stateUpdater->eval($s)}, $state);
}

function meta::external::language::java::factory::addDependencyVisitedFunctions(state:CodeDependencyResolutionState[1], visitedFunctions:String[1]):CodeDependencyResolutionState[1]
{
^$state(visitedFunctions=$state.visitedFunctions->concatenate($visitedFunctions));
}


function meta::external::language::java::factory::getProjects(state:CodeDependencyResolutionState[1], dependencies:CodeDependency[*]):Project[*]
{
$state.projectsByDependency->keyValues()->filter({kv|$kv.first->in($dependencies.name)}).second;
Expand Down

0 comments on commit 010b5bf

Please sign in to comment.