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