Search in sources :

Example 1 with Visibility

use of org.finos.legend.pure.m3.compiler.visibility.Visibility 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 2 with Visibility

use of org.finos.legend.pure.m3.compiler.visibility.Visibility in project legend-pure by finos.

the class AssociationValidator method run.

@Override
public void run(Association association, MatcherState state, Matcher matcher, ModelRepository repository, Context context) throws PureCompilationException {
    ValidatorState validatorState = (ValidatorState) state;
    ProcessorSupport processorSupport = validatorState.getProcessorSupport();
    // Validate properties
    for (Property<?, ?> property : association._properties()) {
        Validator.validate(property, validatorState, matcher, processorSupport);
        Type propertyRawType = (Type) ImportStub.withImportStubByPass(((FunctionType) processorSupport.function_getFunctionType(property))._returnType()._rawTypeCoreInstance(), processorSupport);
        if (propertyRawType == null) {
            throw new PureCompilationException(property.getSourceInformation(), "Association properties must have concrete types");
        }
        Validator.validate(propertyRawType, validatorState, matcher, processorSupport);
    }
    // Validate qualified properties
    for (QualifiedProperty<?> qualifiedProperty : association._qualifiedProperties()) {
        Validator.validate(qualifiedProperty, validatorState, matcher, processorSupport);
        Type propertyRawType = (Type) ImportStub.withImportStubByPass(((FunctionType) processorSupport.function_getFunctionType(qualifiedProperty))._returnType()._rawTypeCoreInstance(), processorSupport);
        if (propertyRawType == null) {
            throw new PureCompilationException(qualifiedProperty.getSourceInformation(), "Association properties must have concrete types");
        }
        Validator.validate(propertyRawType, validatorState, matcher, processorSupport);
    }
    // Validate visibility
    VisibilityValidation.validateAssociation(association, context, validatorState, processorSupport);
}
Also used : Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) ValidatorState(org.finos.legend.pure.m3.compiler.validation.ValidatorState) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Aggregations

ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)2 RichIterable (org.eclipse.collections.api.RichIterable)1 Context (org.finos.legend.pure.m3.compiler.Context)1 ValidatorState (org.finos.legend.pure.m3.compiler.validation.ValidatorState)1 ElementWithStereotypes (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.ElementWithStereotypes)1 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)1 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)1 M3Paths (org.finos.legend.pure.m3.navigation.M3Paths)1 M3Properties (org.finos.legend.pure.m3.navigation.M3Properties)1 PackageableElement (org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement)1 PureCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)1 CodeRepository (org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository)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