Search in sources :

Example 1 with PathElement

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PathElement in project legend-pure by finos.

the class AbstractTestMatch method testMatchPureObjectTypeFail.

@Test
public void testMatchPureObjectTypeFail() {
    Pattern expectedInfo = Pattern.compile("^Match failure: (\\W*\\d*\\w*)\\(?\\d*\\)? instanceOf PathElement$");
    assertExpressionRaisesPureException(expectedInfo, "^meta::pure::metamodel::path::PathElement() ->match([i:Integer[1] | $i])");
}
Also used : Pattern(java.util.regex.Pattern) PureExpressionTest(org.finos.legend.pure.m3.tests.function.base.PureExpressionTest) Test(org.junit.Test)

Example 2 with PathElement

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PathElement in project legend-pure by finos.

the class NavigationGraphBuilder method visitPropertyWithParametersBlock.

private void visitPropertyWithParametersBlock(PropertyWithParametersContext ctx, MutableList<PathElement> props, Token firstChar) {
    MutableList<ValueSpecification> parameters = FastList.newList();
    Token property = ctx.VALID_STRING().getSymbol();
    ClassInstance ppeType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.PropertyPathElement);
    PropertyPathElement propertyPathElement = (PropertyPathElement) this.repository.newAnonymousCoreInstance(this.sourceInformation.getPureSourceInformation(property), ppeType, true);
    GenericType classifierGT = GenericTypeInstance.createPersistent(this.repository);
    classifierGT._rawTypeCoreInstance(ppeType);
    propertyPathElement._classifierGenericType(classifierGT);
    PropertyStub propStub = PropertyStubInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(property), null, property.getText());
    propertyPathElement._propertyCoreInstance(propStub);
    if (ctx.parameter() != null) {
        for (ParameterContext parameterContext : ctx.parameter()) {
            parameters.add(visitParameterBlock(parameterContext));
        }
    }
    if (!parameters.isEmpty()) {
        propertyPathElement._parameters(parameters);
    }
    props.add(propertyPathElement);
}
Also used : PropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) Token(org.antlr.v4.runtime.Token) ParameterContext(org.finos.legend.pure.m3.inlinedsl.path.serialization.grammar.NavigationParser.ParameterContext) ClassInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance) PropertyPathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement)

Example 3 with PathElement

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PathElement in project legend-pure by finos.

the class NavigationGraphBuilder method visitDefinition.

@Override
public CoreInstance visitDefinition(DefinitionContext ctx) {
    GenericType owner;
    MutableList<PathElement> props = FastList.newList();
    Token firstChar = ctx.SEPARATOR().getSymbol();
    owner = visitGenericTypeBlock(ctx.genericType());
    String name = ctx.name() != null ? ctx.name().VALID_STRING().getText() : "";
    if (ctx.propertyWithParameters() != null) {
        for (PropertyWithParametersContext propertyWithParametersContext : ctx.propertyWithParameters()) {
            visitPropertyWithParametersBlock(propertyWithParametersContext, props, firstChar);
        }
    }
    Token end = ctx.EOF().getSymbol();
    if (props.isEmpty()) {
        throw new PureParserException(this.sourceInformation.getPureSourceInformation(firstChar, firstChar, end), "A path must contain at least one navigation");
    }
    ClassInstance ppeType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Path);
    Path propertyPath = (Path) this.repository.newAnonymousCoreInstance(this.sourceInformation.getPureSourceInformation(firstChar, firstChar, end), ppeType, true);
    GenericType classifierGT = GenericTypeInstance.createPersistent(this.repository);
    classifierGT._rawTypeCoreInstance(ppeType);
    propertyPath._classifierGenericType(classifierGT);
    propertyPath._start(owner);
    propertyPath._name(name);
    propertyPath._path(props);
    return propertyPath;
}
Also used : Path(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.Path) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) PathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PathElement) PropertyPathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement) PropertyWithParametersContext(org.finos.legend.pure.m3.inlinedsl.path.serialization.grammar.NavigationParser.PropertyWithParametersContext) PureParserException(org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException) Token(org.antlr.v4.runtime.Token) ClassInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance)

Example 4 with PathElement

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PathElement in project legend-pure by finos.

the class TestM3AntlrParser method testGenericClass.

@Test
public void testGenericClass() {
    String code = "import meta::pure::metamodel::path::*;\n" + "\n" + "Class meta::pure::metamodel::path::test::Path<-U,V|m> extends Function<{U[1]->V[m]}>\n" + "{\n" + "   start : GenericType[1];\n" + "   path : PathElement[1..*];\n" + "   referenceUsages : ReferenceUsage[*];\n" + "   name : String[0..1];\n" + "}";
    new M3AntlrParser(null).parse(code, "test", true, 0, this.repository, this.newInstances, this.stateListener, this.context, 0, null);
}
Also used : M3AntlrParser(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser) Test(org.junit.Test)

Example 5 with PathElement

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PathElement in project legend-pure by finos.

the class PathProcessor method process.

@Override
public void process(Path instance, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
    CoreInstance _class = ImportStub.withImportStubByPass(instance._start()._rawTypeCoreInstance(), processorSupport);
    CoreInstance source = _class;
    boolean possiblyZero = false;
    boolean toMany = false;
    MilestoningDates propagatedDates = state.getMilestoningDates(MilestoningDatesPropagationFunctions.PATH_MILESTONING_DATES_VARIABLE_NAME);
    for (PathElement pathElement : (RichIterable<PathElement>) instance._path()) {
        PostProcessor.processElement(matcher, _class, state, processorSupport);
        if (pathElement instanceof PropertyPathElement) {
            PropertyStub propertyStubNonResolved = (PropertyStub) ((PropertyPathElement) pathElement)._propertyCoreInstance();
            propertyStubNonResolved._ownerCoreInstance(_class);
            AbstractProperty property = (AbstractProperty) ImportStub.withImportStubByPass(((PropertyPathElement) pathElement)._propertyCoreInstance(), processorSupport);
            FunctionType functionType = (FunctionType) processorSupport.function_getFunctionType(property);
            _class = ImportStub.withImportStubByPass(functionType._returnType()._rawTypeCoreInstance(), processorSupport);
            toMany = toMany || !org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.isToOne(functionType._returnMultiplicity(), false);
            possiblyZero = possiblyZero || org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.isLowerZero(functionType._returnMultiplicity());
            for (ValueSpecification vs : ((PropertyPathElement) pathElement)._parameters()) {
                if (vs instanceof InstanceValue) {
                    InstanceValueProcessor.updateInstanceValue(vs, processorSupport);
                }
            }
            propagatedDates = processMilestoningQualifiedProperty(_class, state, propagatedDates, (PropertyPathElement) pathElement, propertyStubNonResolved, property, repository, processorSupport);
        }
    }
    GenericType classifierGenericType = (GenericType) processorSupport.newEphemeralAnonymousCoreInstance(M3Paths.GenericType);
    classifierGenericType._rawTypeCoreInstance(instance.getClassifier());
    classifierGenericType._typeArgumentsAdd((GenericType) Type.wrapGenericType(source, processorSupport));
    classifierGenericType._typeArgumentsAdd((GenericType) Type.wrapGenericType(_class, processorSupport));
    CoreInstance multiplicity = null;
    if (possiblyZero && !toMany) {
        multiplicity = processorSupport.package_getByUserPath(M3Paths.ZeroOne);
    }
    if (possiblyZero && toMany) {
        multiplicity = processorSupport.package_getByUserPath(M3Paths.ZeroMany);
    }
    if (!possiblyZero && toMany) {
        multiplicity = processorSupport.package_getByUserPath(M3Paths.OneMany);
    }
    if (!possiblyZero && !toMany) {
        multiplicity = processorSupport.package_getByUserPath(M3Paths.PureOne);
    }
    classifierGenericType._multiplicityArgumentsAdd((Multiplicity) multiplicity);
    instance._classifierGenericType(classifierGenericType);
}
Also used : RichIterable(org.eclipse.collections.api.RichIterable) PropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) PathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PathElement) PropertyPathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) PropertyPathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement) MilestoningDates(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningDates)

Aggregations

PropertyPathElement (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement)6 RichIterable (org.eclipse.collections.api.RichIterable)5 PathElement (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PathElement)5 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)5 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)5 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)5 PropertyStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub)3 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)3 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)3 Token (org.antlr.v4.runtime.Token)2 MilestoningDates (org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningDates)2 ClassInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance)2 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)2 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Pattern (java.util.regex.Pattern)1 Function (org.eclipse.collections.api.block.function.Function)1 ListIterable (org.eclipse.collections.api.list.ListIterable)1 MutableList (org.eclipse.collections.api.list.MutableList)1