Search in sources :

Example 1 with ImportAccessor

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());
}
Also used : ImportAccessor(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportAccessor) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) Function(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.Function) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Package(org.finos.legend.pure.m3.coreinstance.Package) ImportGroup(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportGroup) PureUnmatchedFunctionException(org.finos.legend.pure.m3.exception.PureUnmatchedFunctionException) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Aggregations

Package (org.finos.legend.pure.m3.coreinstance.Package)1 ImportAccessor (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportAccessor)1 ImportGroup (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportGroup)1 Function (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.Function)1 LambdaFunction (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction)1 PureUnmatchedFunctionException (org.finos.legend.pure.m3.exception.PureUnmatchedFunctionException)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1 SourceInformation (org.finos.legend.pure.m4.coreinstance.SourceInformation)1 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)1