use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportAccessor in project legend-pure by finos.
the class FunctionExpressionProcessor method throwNoMatchException.
private static void throwNoMatchException(FunctionExpression functionExpression, ProcessorState processorState, ProcessorSupport processorSupport) throws PureCompilationException {
StringBuilder message = new StringBuilder("The system can't find a match for the function: ");
StringBuilder functionSignatureBuilder = new StringBuilder();
org.finos.legend.pure.m3.navigation.functionexpression.FunctionExpression.printFunctionSignatureFromExpression(functionSignatureBuilder, functionExpression, processorSupport);
message.append(functionSignatureBuilder);
SourceInformation functionExpressionSourceInformation = functionExpression.getSourceInformation();
String functionName = getFunctionName(functionExpression);
SetIterable<CoreInstance> possibleFunctions = processorSupport.function_getFunctionsForName(functionName);
if ((0 < possibleFunctions.size()) && (possibleFunctions.size() < 20)) {
ImportGroup functionExpressionImportGroup = functionExpression._importGroup();
SetIterable<String> alreadyImportedPackages = functionExpressionImportGroup._imports().collect(ImportAccessor::_path, Sets.mutable.empty());
PartitionSet<CoreInstance> partition = possibleFunctions.partition(f -> {
Package functionPackage = ((Function<?>) f)._package();
return null == functionPackage._package() || alreadyImportedPackages.contains(PackageableElement.getUserPathForPackageableElement(functionPackage));
});
SetIterable<CoreInstance> possibleFunctionsWithPackageNotImported = partition.getRejected();
SetIterable<CoreInstance> possibleFunctionsWithPackageImported = partition.getSelected();
MutableList<CoreInstance> candidatesNotInCoreImportsWithPackageNotImported = Lists.mutable.empty();
MutableList<CoreInstance> candidatesInCoreImportsWithPackageNotImported = Lists.mutable.empty();
MutableList<CoreInstance> candidatesNotInCoreImportsWithPackageImported = Lists.mutable.empty();
MutableList<CoreInstance> candidatesInCoreImportsWithPackageImported = Lists.mutable.empty();
// Get core imports, do not add functions found in coreImports to candidates
ImportGroup coreImport = (ImportGroup) processorSupport.package_getByUserPath(M3Paths.coreImport);
MutableSet<String> coreImports = coreImport._imports().collect(ImportAccessor::_path).toSet();
populateFunctionCandidates(processorState, processorSupport, functionExpressionSourceInformation, possibleFunctionsWithPackageNotImported, candidatesNotInCoreImportsWithPackageNotImported, candidatesInCoreImportsWithPackageNotImported, coreImports);
populateFunctionCandidates(processorState, processorSupport, functionExpressionSourceInformation, possibleFunctionsWithPackageImported, candidatesNotInCoreImportsWithPackageImported, candidatesInCoreImportsWithPackageImported, coreImports);
throw new PureUnmatchedFunctionException(functionExpression.getSourceInformation(), functionSignatureBuilder.toString(), functionName, candidatesInCoreImportsWithPackageNotImported, candidatesNotInCoreImportsWithPackageNotImported, candidatesInCoreImportsWithPackageImported, candidatesNotInCoreImportsWithPackageImported, functionExpressionImportGroup, processorSupport);
}
throw new PureCompilationException(functionExpression.getSourceInformation(), message.toString());
}
Aggregations