Search in sources :

Example 1 with Processor

use of org.finos.legend.pure.m3.compiler.postprocessing.processor.Processor in project legend-pure by finos.

the class InstanceValueProcessor method process.

@Override
public void process(InstanceValue instance, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
    TypeInferenceContext typeInferenceContext = state.getTypeInferenceContext();
    ListIterable<? extends CoreInstance> values = ImportStub.withImportStubByPasses(ListHelper.wrapListIterable(instance._valuesCoreInstance()), processorSupport);
    boolean isCollection = values.size() > 1;
    values.forEachWithIndex((child, i) -> {
        if (isCollection) {
            typeInferenceContext.addStateForCollectionElement();
        }
        if (child instanceof ValueSpecification) {
            InstanceValueSpecificationContext usageContext = (InstanceValueSpecificationContext) processorSupport.newAnonymousCoreInstance(null, M3Paths.InstanceValueSpecificationContext);
            usageContext._offset(i);
            usageContext._instanceValue(instance);
            ((ValueSpecification) child)._usageContext(usageContext);
        } else if (child instanceof RootRouteNode) {
            ((RootRouteNode) child)._owner(instance);
        }
        if (child instanceof org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub) {
            ImportStub.processImportStub((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub) child, repository, processorSupport);
        } else // TODO Is this check necessary? The post-processor keeps track of what has been processed.
        if (!(child instanceof Class)) {
            PostProcessor.processElement(matcher, child, state, processorSupport);
        }
    });
    if (isCollection) {
        TypeInference.potentiallyUpdateParentTypeParamForInstanceValueWithManyElements(instance, typeInferenceContext, state, processorSupport);
    }
    updateInstanceValue(instance, processorSupport);
}
Also used : ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) InstanceValueSpecificationContext(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValueSpecificationContext) ImportStub(org.finos.legend.pure.m3.navigation.importstub.ImportStub) RootRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.RootRouteNode) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) TypeInferenceContext(org.finos.legend.pure.m3.compiler.postprocessing.inference.TypeInferenceContext)

Example 2 with Processor

use of org.finos.legend.pure.m3.compiler.postprocessing.processor.Processor in project legend-pure by finos.

the class GraphLoader method populateBackReferences.

private void populateBackReferences(ListIterable<CoreInstance> instances, Message message) {
    if (message != null) {
        message.setMessage("    Populating reverse references (" + instances.size() + " instances)...");
    }
    MapIterable<CoreInstance, ? extends ListIterable<Processor>> processorsByType = getProcessorsByType();
    CoreInstance annotatedElementClass = getByUserPath(M3Paths.AnnotatedElement);
    CoreInstance associationClass = getByUserPath(M3Paths.Association);
    CoreInstance functionDefinitionClass = getByUserPath(M3Paths.FunctionDefinition);
    CoreInstance functionExpressionClass = getByUserPath(M3Paths.FunctionExpression);
    CoreInstance newPropertyRouteNodeFunctionDefinition = getByUserPath(M3Paths.NewPropertyRouteNodeFunctionDefinition);
    CoreInstance typeClass = getByUserPath(M3Paths.Type);
    BackReferencePopulator backReferencePopulator = new BackReferencePopulator(this.repository, this.context, this.processorSupport, processorsByType, annotatedElementClass, associationClass, functionDefinitionClass, functionExpressionClass, newPropertyRouteNodeFunctionDefinition, typeClass);
    if (shouldParallelize(instances.size(), POPULATE_BACK_REFERENCES_THRESHOLD)) {
        ForkJoinTools.forEach(this.forkJoinPool, instances, backReferencePopulator, POPULATE_BACK_REFERENCES_THRESHOLD);
    } else {
        instances.forEach(backReferencePopulator);
    }
}
Also used : Processor(org.finos.legend.pure.m3.compiler.postprocessing.processor.Processor) AnnotatedElementProcessor(org.finos.legend.pure.m3.compiler.postprocessing.processor.AnnotatedElementProcessor) SpecializationProcessor(org.finos.legend.pure.m3.compiler.postprocessing.SpecializationProcessor) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance)

Example 3 with Processor

use of org.finos.legend.pure.m3.compiler.postprocessing.processor.Processor in project legend-pure by finos.

the class GraphLoader method getProcessorsByType.

private MapIterable<CoreInstance, ? extends ListIterable<Processor>> getProcessorsByType() {
    MutableMap<CoreInstance, MutableList<Processor>> processorsByType = Maps.mutable.empty();
    RichIterable<Processor> processors = LazyIterate.concatenate(this.parserLibrary.getParsers().asLazy().flatCollect(Parser::getProcessors), this.inlineDSLLibrary.getInlineDSLs().asLazy().flatCollect(InlineDSL::getProcessors)).selectInstancesOf(Processor.class);
    for (Processor processor : processors) {
        CoreInstance type = getByUserPath(processor.getClassName());
        // Type may not be loaded yet, and that is ok.
        if (type != null) {
            processorsByType.getIfAbsentPut(type, Lists.mutable::empty).add(processor);
        }
    }
    return processorsByType;
}
Also used : Processor(org.finos.legend.pure.m3.compiler.postprocessing.processor.Processor) AnnotatedElementProcessor(org.finos.legend.pure.m3.compiler.postprocessing.processor.AnnotatedElementProcessor) SpecializationProcessor(org.finos.legend.pure.m3.compiler.postprocessing.SpecializationProcessor) MutableList(org.eclipse.collections.api.list.MutableList) Lists(org.eclipse.collections.api.factory.Lists) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) InlineDSL(org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSL) Parser(org.finos.legend.pure.m3.serialization.grammar.Parser)

Example 4 with Processor

use of org.finos.legend.pure.m3.compiler.postprocessing.processor.Processor in project legend-pure by finos.

the class Visibility method isVisibleInRepository.

/**
 * Return whether the given instance is visible in the
 * given repository.  This is true if the repository
 * the instance is defined in is visible to the given
 * repository.  It is also true if the given repository
 * is null.
 *
 * @param instance         Pure instance
 * @param repository       repository
 * @param processorSupport processor support
 * @return whether instance is visible in repository
 */
private static boolean isVisibleInRepository(CoreInstance instance, CodeRepository repository, RichIterable<CodeRepository> codeRepositories, ProcessorSupport processorSupport) {
    if (codeRepositories == null || repository == null) {
        return true;
    }
    // Packages must be handled specially since they are not defined in a source
    if (processorSupport.instance_instanceOf(instance, M3Paths.Package)) {
        String packagePath = PackageableElement.getUserPathForPackageableElement(instance, "::");
        if (M3Paths.Root.equals(packagePath)) {
            return true;
        }
        for (CodeRepository repo : PureCodeStorage.getVisibleRepositories(codeRepositories, repository)) {
            if (repo.isPackageAllowed(packagePath)) {
                return true;
            }
        }
        return false;
    }
    SourceInformation sourceInfo = instance.getSourceInformation();
    if (sourceInfo == null) {
        throw new RuntimeException("Cannot test visibility for an instance with no source information: " + instance);
    }
    String instanceRepositoryName = PureCodeStorage.getSourceRepoName(sourceInfo.getSourceId());
    if (instanceRepositoryName == null) {
        return false;
    }
    CodeRepository instanceRepository = codeRepositories.select(r -> r.getName().equals(instanceRepositoryName)).getFirst();
    return (instanceRepository != null) && repository.isVisible(instanceRepository);
}
Also used : Context(org.finos.legend.pure.m3.compiler.Context) PackageableElement(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement) RichIterable(org.eclipse.collections.api.RichIterable) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) CodeRepository(org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository) PureCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage) M3Properties(org.finos.legend.pure.m3.navigation.M3Properties) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ElementWithStereotypes(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.ElementWithStereotypes) M3Paths(org.finos.legend.pure.m3.navigation.M3Paths) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) CodeRepository(org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation)

Example 5 with Processor

use of org.finos.legend.pure.m3.compiler.postprocessing.processor.Processor in project legend-pure by finos.

the class Visibility method isVisibleInSource.

/**
 * Return whether the given instance is visible in the
 * identified source.  This is true if the instance is
 * visible to the repository the source is in.  It is
 * also true if sourceId is null or if no repository can
 * be found for the identified source.
 *
 * @param instance         Pure instance
 * @param sourceId         source identifier
 * @param processorSupport processor support
 * @return whether instance is visible in the given source
 */
public static boolean isVisibleInSource(CoreInstance instance, String sourceId, RichIterable<CodeRepository> codeRepositories, ProcessorSupport processorSupport) {
    if (sourceId == null) {
        return true;
    }
    String repositoryName = PureCodeStorage.getSourceRepoName(sourceId);
    CodeRepository repository = codeRepositories == null || repositoryName == null ? null : codeRepositories.select(r -> r.getName().equals(repositoryName)).getFirst();
    return isVisibleInRepository(instance, repository, codeRepositories, processorSupport);
}
Also used : CodeRepository(org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository)

Aggregations

List (java.util.List)3 Objects (java.util.Objects)3 MutableList (org.eclipse.collections.api.list.MutableList)3 Lists (org.eclipse.collections.impl.factory.Lists)3 ListIterate (org.eclipse.collections.impl.utility.ListIterate)3 ValueSpecification (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification)3 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)3 LambdaFunction (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction)3 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)3 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)3 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)3 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)3 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 RichIterable (org.eclipse.collections.api.RichIterable)2 FastList (org.eclipse.collections.impl.list.mutable.FastList)2 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)2 Multiplicity (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity)2 PropertyMapping (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.PropertyMapping)2 AggregateSetImplementationContainer (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.AggregateSetImplementationContainer)2