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);
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations