use of org.finos.legend.pure.m3.compiler.validation.ValidatorState in project legend-pure by finos.
the class RootRouteNodeValidator method run.
@Override
public void run(RootRouteNode treePathNode, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ProcessorSupport processorSupport = state.getProcessorSupport();
GenericType genericType = treePathNode._type();
Validator.validate(genericType, (ValidatorState) state, matcher, processorSupport);
MutableSet<String> nodesValidated = Sets.mutable.empty();
validateTreePathNode(treePathNode, nodesValidated, processorSupport);
}
use of org.finos.legend.pure.m3.compiler.validation.ValidatorState in project legend-pure by finos.
the class AggregationAwareValidator method run.
@Override
public void run(AggregationAwareSetImplementation instance, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ValidatorState validatorState = (ValidatorState) state;
ProcessorSupport processorSupport = validatorState.getProcessorSupport();
for (AggregateSetImplementationContainer container : instance._aggregateSetImplementations()) {
for (AggregationFunctionSpecification aggregationFunctionSpecification : container._aggregateSpecification()._aggregateValues()) {
FunctionType mapFnType = (FunctionType) ImportStub.withImportStubByPass(aggregationFunctionSpecification._mapFn()._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), processorSupport);
Type mapFnReturnType = (Type) ImportStub.withImportStubByPass(mapFnType._returnType()._rawTypeCoreInstance(), processorSupport);
if (!Instance.instanceOf(mapFnReturnType, M3Paths.DataType, processorSupport)) {
throw new PureCompilationException(aggregationFunctionSpecification._mapFn().getSourceInformation(), "An aggregate specification's mapFunction return type should be a DataType (primitive type/enumeration)");
}
FunctionType aggregateFnType = (FunctionType) ImportStub.withImportStubByPass(aggregationFunctionSpecification._aggregateFn()._classifierGenericType()._typeArguments().toList().get(0)._rawTypeCoreInstance(), processorSupport);
Type aggregateFnReturnType = (Type) ImportStub.withImportStubByPass(aggregateFnType._returnType()._rawTypeCoreInstance(), processorSupport);
if (!Instance.instanceOf(aggregateFnReturnType, M3Paths.DataType, processorSupport)) {
throw new PureCompilationException(aggregationFunctionSpecification._aggregateFn().getSourceInformation(), "An aggregate specification's aggregateFunction return type should be a DataType (primitive type/enumeration)");
}
}
matcher.fullMatch(container._setImplementation(), state);
}
matcher.fullMatch(instance._mainSetImplementation(), state);
}
use of org.finos.legend.pure.m3.compiler.validation.ValidatorState in project legend-pure by finos.
the class MappingValidator method run.
@Override
public void run(Mapping mapping, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ValidatorState validatorState = (ValidatorState) state;
ProcessorSupport processorSupport = validatorState.getProcessorSupport();
validateIncludes(mapping, matcher, validatorState, processorSupport);
validatorState.resetSetImplementationList();
MutableListMultimap<Type, CoreInstance> setImplementationsByClass = Multimaps.mutable.list.empty();
validateMappedEntitiesInIncludes(mapping, mapping, processorSupport, setImplementationsByClass, validatorState, matcher);
validateMappedEntities(mapping, mapping._classMappings(), true, setImplementationsByClass, processorSupport, validatorState, matcher);
validateMappedEntities(mapping, mapping._associationMappings(), true, setImplementationsByClass, processorSupport, validatorState, matcher);
validateMappedEntities(mapping, mapping._enumerationMappings(), false, setImplementationsByClass, processorSupport, validatorState, matcher);
validateStar(mapping, processorSupport);
validateAssociationMappings(mapping, processorSupport);
validateEnumerationMappings(mapping, processorSupport);
validateSuperSetImplementationId(mapping, processorSupport);
validateVisibility(mapping, context, validatorState, processorSupport);
validateOperationMappings(mapping, setImplementationsByClass, processorSupport);
StoreSubstitutionValidator.validateStoreSubstitutions(mapping);
}
use of org.finos.legend.pure.m3.compiler.validation.ValidatorState in project legend-pure by finos.
the class MappingValidator method validateIncludes.
private static void validateIncludes(Mapping mapping, Matcher matcher, ValidatorState state, ProcessorSupport processorSupport) {
ListIterable<? extends MappingInclude> includes = mapping._includes().toList();
int includeCount = includes.size();
if (includeCount > 0) {
// Validate includes individually
MutableList<MapIterable<Store, Store>> storeSubstitutionMaps = FastList.newList(includeCount);
for (MappingInclude include : includes) {
Mapping owner = (Mapping) ImportStub.withImportStubByPass(include._ownerCoreInstance(), processorSupport);
if (owner != mapping) {
StringBuilder message = new StringBuilder("Corrupt mapping include: owner should be ");
PackageableElement.writeUserPathForPackageableElement(message, mapping);
message.append(", found ");
PackageableElement.writeUserPathForPackageableElement(message, owner);
throw new PureCompilationException(include.getSourceInformation(), message.toString());
}
Mapping includedMapping = (Mapping) ImportStub.withImportStubByPass(include._includedCoreInstance(), processorSupport);
Validator.validate(includedMapping, state, matcher, processorSupport);
MapIterable<Store, Store> includeStoreSubstitutions = validateIncludeStoreSubstitutions(include, processorSupport);
storeSubstitutionMaps.add(includeStoreSubstitutions);
}
if (includeCount > 1) {
MutableMap<Store, Store> mergedStoreSubstitutions = Maps.mutable.empty();
for (MapIterable<Store, Store> subMap : storeSubstitutionMaps) {
for (Pair<Store, Store> pair : subMap.keyValuesView()) {
Store original = pair.getOne();
Store substitute = pair.getTwo();
Store otherSubstitute = mergedStoreSubstitutions.put(original, substitute);
if (otherSubstitute != null && otherSubstitute != substitute) {
StringBuilder message = new StringBuilder("Store substitution error: multiple substitutions for ");
PackageableElement.writeUserPathForPackageableElement(message, original);
throw new PureCompilationException(mapping.getSourceInformation(), message.toString());
}
}
}
}
// Validate includes recursively
validateInclusionHierarchy(mapping, Lists.mutable.<Mapping>empty(), processorSupport);
}
}
use of org.finos.legend.pure.m3.compiler.validation.ValidatorState in project legend-pure by finos.
the class MappingValidator method validateVisibility.
private static void validateVisibility(Mapping mapping, Context context, ValidatorState validatorState, ProcessorSupport processorSupport) throws PureCompilationException {
Package pkg = mapping._package();
if (pkg != null) {
String sourceId = mapping.getSourceInformation().getSourceId();
for (SetImplementation classMapping : mapping._classMappings()) {
Class _class = (Class) ImportStub.withImportStubByPass(classMapping._classCoreInstance(), processorSupport);
VisibilityValidation.validatePackageAndSourceVisibility(classMapping, pkg, sourceId, context, validatorState, processorSupport, _class);
}
for (EnumerationMapping enumerationMapping : mapping._enumerationMappings()) {
Enumeration enumeration = (Enumeration) ImportStub.withImportStubByPass(enumerationMapping._enumerationCoreInstance(), processorSupport);
VisibilityValidation.validatePackageAndSourceVisibility(enumerationMapping, pkg, sourceId, context, validatorState, processorSupport, enumeration);
}
for (MappingInclude include : mapping._includes()) {
Mapping included = (Mapping) ImportStub.withImportStubByPass(include._includedCoreInstance(), processorSupport);
VisibilityValidation.validatePackageAndSourceVisibility(mapping, pkg, sourceId, context, validatorState, processorSupport, included);
}
}
}
Aggregations