Search in sources :

Example 1 with Generalization

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization in project legend-pure by finos.

the class TypeUnbind method run.

@Override
public void run(Type type, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    ProcessorSupport processorSupport = state.getProcessorSupport();
    for (Generalization generalization : type._generalizations()) {
        GenericType general = generalization._general();
        Type generalRawType = null;
        try {
            generalRawType = (Type) ImportStub.withImportStubByPass(general._rawTypeCoreInstance(), processorSupport);
        } catch (PureCompilationException ex) {
        // Ignore - if we can't resolve this type was probably already unbound
        }
        if (generalRawType != null) {
            ListIterable<? extends CoreInstance> specializationsToRemove = generalRawType.getValueInValueForMetaPropertyToManyByIndex(M3Properties.specializations, IndexSpecifications.getPropertyValueIndexSpec(M3Properties.specific), type);
            for (CoreInstance specialization : specializationsToRemove.toList()) {
                generalRawType._specializationsRemove((Generalization) specialization);
            }
            if (generalRawType.getValueForMetaPropertyToMany(M3Properties.specializations).isEmpty()) {
                generalRawType._specializationsRemove();
            }
        }
        Shared.cleanUpGenericType(general, (UnbindState) state, processorSupport);
    }
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) 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) Generalization(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 2 with Generalization

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization in project legend-pure by finos.

the class TestPureRuntimeClass_FunctionExpressionParam method testPureRuntimeClassParameterUsageCleanUp.

@Test
public void testPureRuntimeClassParameterUsageCleanUp() throws Exception {
    RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("sourceId.pure", "function f(c:Class<Any>[1]):Any[1]{$c} function k():Nil[0]{f(A);[];}").createInMemorySource("userId.pure", "Class A{}").compile(), new RuntimeTestScriptBuilder().deleteSource("sourceId.pure").compile().createInMemorySource("sourceId.pure", "function f(c:Class<Any>[1]):Any[1]{$c} function k():Nil[0]{f(A);[];}").compile(), this.runtime, this.functionExecution, this.getAdditionalVerifiers());
    Assert.assertEquals("A instance Class\n" + "    classifierGenericType(Property):\n" + "        Anonymous_StripedId instance GenericType\n" + "            [... >0]\n" + "    generalizations(Property):\n" + "        Anonymous_StripedId instance Generalization\n" + "            [... >0]\n" + "    name(Property):\n" + "        A instance String\n" + "    package(Property):\n" + "        Root instance Package\n" + "    referenceUsages(Property):\n" + "        Anonymous_StripedId instance ReferenceUsage\n" + "            [... >0]", this.runtime.getCoreInstance("A").printWithoutDebug("", 0));
}
Also used : RuntimeTestScriptBuilder(org.finos.legend.pure.m3.RuntimeTestScriptBuilder) Test(org.junit.Test)

Example 3 with Generalization

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization in project legend-pure by finos.

the class AntlrContextToM3CoreInstance method classParser.

private CoreInstance classParser(ClassDefinitionContext ctx, ImportGroup importId, boolean addLines) throws PureParserException {
    MutableList<Property<? extends CoreInstance, ?>> properties = Lists.mutable.empty();
    MutableList<QualifiedProperty<? extends CoreInstance>> qualifiedProperties = Lists.mutable.empty();
    MutableList<GenericType> superTypesGenericTypes = Lists.mutable.empty();
    boolean isDirectSubTypeofAny = false;
    MutableList<String> typeParameterNames = Lists.mutable.empty();
    MutableList<Boolean> contravariants = Lists.mutable.empty();
    MutableList<String> multiplicityParameterNames = Lists.mutable.empty();
    ImportStubInstance ownerType;
    ListIterable<CoreInstance> stereotypes = null;
    ListIterable<TaggedValue> tags = null;
    ClassInstance classInstance;
    if (ctx.stereotypes() != null) {
        stereotypes = this.stereotypes(ctx.stereotypes(), importId);
    }
    if (ctx.taggedValues() != null) {
        tags = this.taggedValues(ctx.taggedValues(), importId);
    }
    this.checkExists(ctx.qualifiedName().packagePath(), ctx.qualifiedName().identifier(), null);
    if (ctx.typeParametersWithContravarianceAndMultiplicityParameters() != null) {
        this.typeParametersWithContravarianceAndMultiplicityParameters(ctx.typeParametersWithContravarianceAndMultiplicityParameters(), typeParameterNames, contravariants, multiplicityParameterNames);
    }
    if (ctx.projection() != null) {
        return this.projectionParser(ctx, importId, addLines, stereotypes, tags);
    } else {
        if (ctx.EXTENDS() != null) {
            for (TypeContext typeCtx : ctx.type()) {
                superTypesGenericTypes.add(this.type(typeCtx, typeParameterNames, "", importId, addLines));
            }
        }
        String className = ctx.qualifiedName().identifier().getText();
        classInstance = ClassInstance.createPersistent(this.repository, className);
        PackageInstance packageInstance = this.buildPackage(ctx.qualifiedName().packagePath());
        classInstance._package(packageInstance);
        packageInstance._childrenAdd(classInstance);
        String fullName = this.getQualifiedNameString(ctx.qualifiedName());
        ownerType = ImportStubInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(ctx.qualifiedName().identifier().getStart()), fullName, importId);
        LambdaContext lambdaContext = new LambdaContext(fullName.replace("::", "_"));
        MutableList<Constraint> constraints = this.constraints(classInstance, ctx.constraints(), importId, lambdaContext, addLines);
        this.propertyParser(ctx.classBody().properties(), properties, qualifiedProperties, typeParameterNames, multiplicityParameterNames, ownerType, importId, 0);
        classInstance.setSourceInformation(this.sourceInformation.getPureSourceInformation(ctx.getStart(), ctx.qualifiedName().identifier().getStart(), ctx.getStop()));
        if (superTypesGenericTypes.isEmpty()) {
            isDirectSubTypeofAny = true;
            GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
            genericTypeInstance._rawTypeCoreInstance(this.processorSupport.package_getByUserPath(M3Paths.Any));
            superTypesGenericTypes.add(genericTypeInstance);
        }
        GenericTypeInstance classifierGT = GenericTypeInstance.createPersistent(this.repository);
        ClassInstance classType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Class);
        classifierGT._rawTypeCoreInstance(classType);
        GenericTypeInstance classifierGTTA = GenericTypeInstance.createPersistent(this.repository);
        classifierGTTA._rawTypeCoreInstance(classInstance);
        if (!typeParameterNames.isEmpty()) {
            MutableList<TypeParameter> typeParameters = Lists.mutable.of();
            MutableList<Pair<String, Boolean>> tps = typeParameterNames.zip(contravariants);
            for (Pair<String, Boolean> typeParam : tps) {
                TypeParameterInstance tp = TypeParameterInstance.createPersistent(this.repository, typeParam.getOne());
                tp._contravariant(typeParam.getTwo());
                typeParameters.add(tp);
            }
            classInstance._typeParameters(typeParameters);
            MutableList<GenericType> typeArgs = Lists.mutable.of();
            for (String typeParamName : typeParameterNames) {
                TypeParameterInstance tp = TypeParameterInstance.createPersistent(this.repository, typeParamName);
                GenericTypeInstance gt = GenericTypeInstance.createPersistent(this.repository);
                gt._typeParameter(tp);
                typeArgs.add(gt);
            }
            classifierGTTA._typeArguments(typeArgs);
        }
        if (!multiplicityParameterNames.isEmpty()) {
            MutableList<Multiplicity> multParameters = Lists.mutable.of();
            for (String multiplicityParam : multiplicityParameterNames) {
                MultiplicityInstance mult = MultiplicityInstance.createPersistent(this.repository, null, null);
                mult._multiplicityParameter(multiplicityParam);
                multParameters.add(mult);
            }
            classInstance._multiplicityParameters(this.processMultiplicityParametersInstance(multiplicityParameterNames));
            classifierGTTA._multiplicityArguments(multParameters);
        }
        classifierGT._typeArguments(Lists.mutable.<GenericType>of(classifierGTTA));
        classInstance._classifierGenericType(classifierGT);
        if (properties.notEmpty()) {
            classInstance._properties(properties);
        }
        if (qualifiedProperties.notEmpty()) {
            classInstance._qualifiedProperties(qualifiedProperties);
        }
        classInstance._name(ctx.qualifiedName().identifier().getText());
        if (stereotypes != null) {
            classInstance._stereotypesCoreInstance(stereotypes);
        }
        if (tags != null) {
            classInstance._taggedValues(tags);
        }
        if (constraints.notEmpty()) {
            classInstance._constraints(constraints);
        }
        MutableList<Generalization> generalizations = Lists.mutable.empty();
        for (GenericType superType : superTypesGenericTypes) {
            GeneralizationInstance generalizationInstance = GeneralizationInstance.createPersistent(this.repository, superType, classInstance);
            generalizations.add(generalizationInstance);
        }
        classInstance._generalizations(generalizations);
        if (isDirectSubTypeofAny) {
            MilestoningClassProcessor.addMilestoningProperty(classInstance, this.context, this.processorSupport, this.repository);
        }
        return classInstance;
    }
}
Also used : TypeParameter(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.TypeParameter) Constraint(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.constraint.Constraint) Generalization(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization) LambdaParamTypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.LambdaParamTypeContext) TypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TypeContext) TreePathPropertyParameterTypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TreePathPropertyParameterTypeContext) FunctionTypePureTypeContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.FunctionTypePureTypeContext) Multiplicity(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity) MultiplicityInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.MultiplicityInstance) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) ClassInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance) Pair(org.eclipse.collections.api.tuple.Pair) GenericTypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) TypeParameterInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.TypeParameterInstance) TaggedValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue) PackageInstance(org.finos.legend.pure.m3.coreinstance.PackageInstance) GeneralizationInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.GeneralizationInstance) PrimitiveCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ImportStubInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStubInstance) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)

Example 4 with Generalization

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization in project legend-pure by finos.

the class AntlrContextToM3CoreInstance method enumParser.

private Enumeration<?> enumParser(EnumDefinitionContext ctx, ImportGroup importId) throws PureParserException {
    EnumerationInstance enumerationInstance;
    CoreInstance value;
    MutableList<CoreInstance> values = Lists.mutable.empty();
    ListIterable<CoreInstance> stereotypes = Lists.mutable.empty();
    ListIterable<TaggedValue> tags = Lists.mutable.empty();
    if (ctx.stereotypes() != null) {
        stereotypes = this.stereotypes(ctx.stereotypes(), importId);
    }
    if (ctx.taggedValues() != null) {
        tags = this.taggedValues(ctx.taggedValues(), importId);
    }
    this.checkExists(ctx.qualifiedName().packagePath(), ctx.qualifiedName().identifier(), null);
    PackageInstance packageInstance = this.buildPackage(ctx.qualifiedName().packagePath());
    GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
    ClassInstance enumerationType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Enumeration);
    genericTypeInstance._rawTypeCoreInstance(enumerationType);
    enumerationInstance = EnumerationInstance.createPersistent(this.repository, ctx.qualifiedName().identifier().getText());
    enumerationInstance._name(ctx.qualifiedName().identifier().getText());
    enumerationInstance._package(packageInstance);
    GenericTypeInstance taGenericType = GenericTypeInstance.createPersistent(this.repository);
    taGenericType._rawTypeCoreInstance(enumerationInstance);
    genericTypeInstance._typeArguments(Lists.mutable.<GenericType>of(taGenericType));
    enumerationInstance._classifierGenericType(genericTypeInstance);
    packageInstance._childrenAdd(enumerationInstance);
    if (!tags.isEmpty()) {
        enumerationInstance._taggedValues(tags);
    }
    if (!stereotypes.isEmpty()) {
        enumerationInstance._stereotypesCoreInstance(stereotypes);
    }
    enumerationInstance._classifierGenericType(genericTypeInstance);
    GenericTypeInstance general = GenericTypeInstance.createPersistent(this.repository);
    ClassInstance enumType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Enum);
    general._rawTypeCoreInstance(enumType);
    GeneralizationInstance gen = GeneralizationInstance.createPersistent(this.repository, general, enumerationInstance);
    enumerationInstance._generalizations(Lists.mutable.<Generalization>of(gen));
    for (EnumValueContext evCtx : ctx.enumValue()) {
        value = this.enumValue(evCtx, enumerationInstance, importId);
        values.add(value);
    }
    enumerationInstance.setSourceInformation(this.sourceInformation.getPureSourceInformation(ctx.getStart(), ctx.qualifiedName().identifier().getStart(), ctx.getStop()));
    enumerationInstance._values(values);
    return enumerationInstance;
}
Also used : PackageInstance(org.finos.legend.pure.m3.coreinstance.PackageInstance) GenericTypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance) EnumValueContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.EnumValueContext) GeneralizationInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.GeneralizationInstance) TaggedValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue) PrimitiveCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) EnumerationInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.EnumerationInstance) ClassInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance)

Example 5 with Generalization

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization in project legend-pure by finos.

the class SetImplementationProcessor method buildMappingClassOutOfLocalProperties.

private void buildMappingClassOutOfLocalProperties(final ModelRepository repository, SetImplementation classMapping, ProcessorState state, Matcher matcher, final ProcessorSupport processorSupport) {
    RichIterable<? extends PropertyMapping> localProperties = classMapping instanceof InstanceSetImplementation ? ((InstanceSetImplementation) classMapping)._propertyMappings().select(new Predicate<PropertyMapping>() {

        @Override
        public boolean accept(PropertyMapping propertyMapping) {
            return propertyMapping._localMappingProperty() != null ? propertyMapping._localMappingProperty() : false;
        }
    }) : Lists.immutable.<PropertyMapping>empty();
    CoreInstance _class = ImportStub.withImportStubByPass(classMapping._classCoreInstance(), processorSupport);
    boolean hasAggregateSpecification = classMapping instanceof InstanceSetImplementation && ((InstanceSetImplementation) classMapping)._aggregateSpecification() != null;
    if (localProperties.notEmpty() || hasAggregateSpecification) {
        Mapping mapping = (Mapping) ImportStub.withImportStubByPass(classMapping._parentCoreInstance(), processorSupport);
        final MappingClass newClass = MappingClassCoreInstanceWrapper.toMappingClass(repository.newCoreInstance(_class.getName() + "_" + mapping.getName() + "_" + classMapping._id(), _Package.getByUserPath(M2MappingPaths.MappingClass, processorSupport), classMapping.getSourceInformation()));
        newClass._name(_class.getName() + "_" + mapping.getName() + "_" + classMapping._id());
        ClassInstance genericTypeClass = (ClassInstance) _Package.getByUserPath(M3Paths.GenericType, processorSupport);
        GenericType genericType = (GenericType) repository.newAnonymousCoreInstance(null, genericTypeClass);
        genericType._rawTypeCoreInstance(_Package.getByUserPath(M2MappingPaths.MappingClass, processorSupport));
        GenericType typeArg = (GenericType) repository.newAnonymousCoreInstance(null, genericTypeClass);
        typeArg._rawTypeCoreInstance(newClass);
        genericType._typeArguments(((ImmutableList<GenericType>) Lists.immutable.withAll(genericType._typeArguments())).newWithAll(Lists.immutable.with(typeArg)));
        newClass._classifierGenericType(genericType);
        GenericType superType = (GenericType) repository.newAnonymousCoreInstance(null, genericTypeClass);
        superType._rawTypeCoreInstance(_class);
        Generalization newGeneralization = (Generalization) repository.newAnonymousCoreInstance(null, _Package.getByUserPath(M3Paths.Generalization, processorSupport));
        newGeneralization._specific(newClass);
        newGeneralization._general(superType);
        newClass._generalizations(Lists.immutable.with(newGeneralization));
        newClass._properties(Lists.immutable.withAll(newClass._properties()).newWithAll(localProperties.collect(new Function<PropertyMapping, CoreInstance>() {

            @Override
            public CoreInstance valueOf(PropertyMapping propertyMapping) {
                Property property = (Property) ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport);
                property._owner(newClass);
                GenericType src = property._classifierGenericType()._typeArguments().toList().get(0);
                src._rawTypeCoreInstance(newClass);
                return property;
            }
        })));
        SpecializationProcessor.process(newClass, processorSupport);
        PostProcessor.processElement(matcher, newClass, state, processorSupport);
        ((InstanceSetImplementation) classMapping)._mappingClass(newClass);
    }
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) Mapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) Generalization(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization) Predicate(org.eclipse.collections.api.block.predicate.Predicate) InstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.InstanceSetImplementation) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) MappingClass(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.MappingClass) ClassInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)

Aggregations

CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)19 Generalization (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization)17 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)16 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)9 RichIterable (org.eclipse.collections.api.RichIterable)8 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)7 MutableList (org.eclipse.collections.api.list.MutableList)6 Pair (org.eclipse.collections.api.tuple.Pair)6 ClassInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance)6 PackageInstance (org.finos.legend.pure.m3.coreinstance.PackageInstance)5 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)5 Objects (java.util.Objects)4 MutableSet (org.eclipse.collections.api.set.MutableSet)4 SetIterable (org.eclipse.collections.api.set.SetIterable)4 Lists (org.eclipse.collections.impl.factory.Lists)4 MapIterable (org.eclipse.collections.api.map.MapIterable)3 FastList (org.eclipse.collections.impl.list.mutable.FastList)3 Tuples (org.eclipse.collections.impl.tuple.Tuples)3 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)3 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)3