diff --git a/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/generation/expressionGeneration.pure b/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/generation/expressionGeneration.pure index 7e05e0031a6..d4bda9ce28c 100644 --- a/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/generation/expressionGeneration.pure +++ b/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/generation/expressionGeneration.pure @@ -272,18 +272,21 @@ function <> 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).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).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); } ); diff --git a/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/metamodel.pure b/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/metamodel.pure index 9ce339c3451..27c61b8dadf 100644 --- a/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/metamodel.pure +++ b/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/metamodel.pure @@ -730,6 +730,7 @@ Class meta::external::language::java::metamodel::CodeDependency Class meta::external::language::java::metamodel::CodeDependencyResolutionState { + visitedFunctions: String[*]; projectsByDependency : Map[1]; } diff --git a/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/metamodel_factories.pure b/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/metamodel_factories.pure index 0bc0d659027..6ac790aca5a 100644 --- a/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/metamodel_factories.pure +++ b/legend-engine-xts-java/legend-engine-xt-javaGeneration-pure/src/main/resources/core_external_language_java/metamodel_factories.pure @@ -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;