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