Search in sources :

Example 1 with ValidatorState

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);
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport)

Example 2 with ValidatorState

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);
}
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) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) AggregateSetImplementationContainer(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregateSetImplementationContainer) AggregationFunctionSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregationFunctionSpecification) ValidatorState(org.finos.legend.pure.m3.compiler.validation.ValidatorState) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 3 with ValidatorState

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);
}
Also used : FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ValidatorState(org.finos.legend.pure.m3.compiler.validation.ValidatorState)

Example 4 with ValidatorState

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);
    }
}
Also used : Store(org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store) MapIterable(org.eclipse.collections.api.map.MapIterable) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 5 with ValidatorState

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);
        }
    }
}
Also used : Enumeration(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) Package(org.finos.legend.pure.m3.coreinstance.Package) PureInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PureInstanceSetImplementation)

Aggregations

ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)18 ValidatorState (org.finos.legend.pure.m3.compiler.validation.ValidatorState)16 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)16 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)14 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)14 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)12 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)11 Package (org.finos.legend.pure.m3.coreinstance.Package)6 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)6 SourceInformation (org.finos.legend.pure.m4.coreinstance.SourceInformation)6 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)4 PureInstanceSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PureInstanceSetImplementation)3 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)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 RichIterable (org.eclipse.collections.api.RichIterable)2 Function (org.eclipse.collections.api.block.function.Function)2 KeyExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.functions.lang.KeyExpression)2 Mapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping)2 PropertyMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping)2