use of org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException in project legend-pure by finos.
the class AbstractTestMeasure method testInstantiateBooleanValuedUnitThrowsParserError.
@Test
public void testInstantiateBooleanValuedUnitThrowsParserError() {
compileTestSource("testModel.pure", massDefinition);
PureParserException e = Assert.assertThrows(PureParserException.class, () -> compileTestSource("testFunc.pure", "import pkg::*;\n" + "function testFunc():Any[*]\n" + "{\n" + " let a = false Mass~Pound;" + "}"));
assertPureException(PureParserException.class, "expected: one of {'->', '}', '.', ';', '&&', '||', '==', '!=', '+', '*', '-', '/', '<', '<=', '>', '>='} found: 'Mass'", e);
}
use of org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException 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.m4.serialization.grammar.antlr.PureParserException in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method definition.
public CoreInstance definition(DefinitionContext ctx, boolean useImportStubsInInstanceParser) throws PureParserException {
CoreInstance result = null;
ImportGroup importId = null;
if (ctx.imports() != null) {
importId = this.imports(ctx.imports());
if (this.oldState == null) {
this.hasImportChanged = true;
} else {
String importGroupID = importId._name();
RichIterable<? extends PackageableElement> oldImportGroups = this.oldState.getImportGroups().select(e -> importGroupID.equals(e._name()));
if (oldImportGroups.size() == 1) {
ImportGroup oldImportGroup = (ImportGroup) oldImportGroups.toList().get(0);
MutableSet<String> oldPaths = oldImportGroup._imports().collect(Import::_path, Sets.mutable.empty());
MutableSet<String> newPaths = importId._imports().collect(Import::_path, Sets.mutable.empty());
if (oldPaths.equals(newPaths)) {
this.hasImportChanged = false;
PackageInstance parent = (PackageInstance) this.processorSupport.package_getByUserPath("system::imports");
parent._children(parent._children().reject(e -> importGroupID.equals(e._name())));
parent._childrenAdd(oldImportGroup);
oldImportGroup._package(parent);
oldImportGroup.setSourceInformation(importId.getSourceInformation());
oldImportGroup._imports(importId._imports());
importId = oldImportGroup;
} else {
this.hasImportChanged = true;
}
} else {
this.hasImportChanged = true;
}
}
}
if (ctx.profile() != null) {
for (ProfileContext pCtx : ctx.profile()) {
if (this.hasImportChanged) {
result = this.profile(pCtx);
} else {
String importGroupID = importId._name();
String newContent = Lists.mutable.with(pCtx.start.getInputStream().getText(new Interval(pCtx.start.getStartIndex(), pCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
MutableList<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
if (oldInstances.size() == 1) {
CoreInstance thisInstance = oldInstances.get(0);
this.oldInstances.remove(thisInstance);
SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(pCtx.getStart(), pCtx.qualifiedName().getStop(), pCtx.getStop());
if (thisInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
this.offsetSourceInformationForInstanceAndChildren(thisInstance, newSourceInfo.getStartLine() - thisInstance.getSourceInformation().getStartLine());
PackageInstance packageInstance = this.buildPackage(pCtx.qualifiedName().packagePath());
((PackageableElement) thisInstance)._package(packageInstance);
packageInstance._childrenAdd((PackageableElement) thisInstance);
result = thisInstance;
} else {
result = this.profile(pCtx);
}
} else {
result = this.profile(pCtx);
}
}
this.coreInstancesResult.add(result);
}
}
if (ctx.classDefinition() != null) {
for (ClassDefinitionContext dCtx : ctx.classDefinition()) {
if (this.hasImportChanged) {
result = this.classParser(dCtx, importId, this.addLines);
} else {
String importGroupID = importId._name();
String newContent = Lists.mutable.with(dCtx.start.getInputStream().getText(new Interval(dCtx.start.getStartIndex(), dCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
List<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
if (oldInstances.size() == 1) {
CoreInstance thisInstance = oldInstances.get(0);
this.oldInstances.remove(thisInstance);
SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(dCtx.getStart(), dCtx.qualifiedName().identifier().getStart(), dCtx.getStop());
if (thisInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
this.offsetSourceInformationForInstanceAndChildren(thisInstance, newSourceInfo.getStartLine() - thisInstance.getSourceInformation().getStartLine());
PackageInstance packageInstance = this.buildPackage(dCtx.qualifiedName().packagePath());
((PackageableElement) thisInstance)._package(packageInstance);
packageInstance._childrenAdd((PackageableElement) thisInstance);
result = thisInstance;
} else {
result = this.classParser(dCtx, importId, this.addLines);
}
} else {
result = this.classParser(dCtx, importId, this.addLines);
}
}
this.coreInstancesResult.add(result);
}
}
if (ctx.measureDefinition() != null) {
for (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.MeasureDefinitionContext dCtx : ctx.measureDefinition()) {
if (this.hasImportChanged) {
result = this.measureParser(dCtx, importId, this.addLines);
} else {
String importGroupID = importId._name();
String newContent = Lists.mutable.with(dCtx.start.getInputStream().getText(new Interval(dCtx.start.getStartIndex(), dCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
List<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
Predicate2<CoreInstance, SourceInformation> matchesOldInstance = (oldMeasureInstance, newSourceInfo) -> {
if (newSourceInfo == null || oldMeasureInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
PackageInstance packageInstance;
if (newSourceInfo != null) {
offsetSourceInformationForInstanceAndChildren(oldMeasureInstance, newSourceInfo.getStartLine() - oldMeasureInstance.getSourceInformation().getStartLine());
}
Function<String, IdentifierContext> newIdentifierContext = s -> new IdentifierContext(null, 1) {
@Override
public String getText() {
return s;
}
};
packageInstance = buildPackage(Lists.mutable.with(newIdentifierContext.valueOf(oldMeasureInstance.getValueForMetaPropertyToOne(M3Properties._package).getName())));
((PackageableElement) oldMeasureInstance)._package(packageInstance);
packageInstance._childrenAdd((PackageableElement) oldMeasureInstance);
return true;
}
return false;
};
CoreInstance oldMeasureInstance = ListIterate.detect(oldInstances, i -> Instance.instanceOf(i, M3Paths.Measure, this.processorSupport));
if (oldMeasureInstance != null) {
this.oldInstances.remove(oldMeasureInstance);
SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(dCtx.getStart(), dCtx.qualifiedName().identifier().getStart(), dCtx.getStop());
if (matchesOldInstance.accept(oldMeasureInstance, newSourceInfo)) {
MeasureInstance mI = (MeasureInstance) oldMeasureInstance;
result = mI;
MutableList<Unit> units = Lists.mutable.with(mI._canonicalUnit()).withAll(mI._nonCanonicalUnits());
for (Unit unit : units) {
PackageInstance packageInstance = buildPackage(Lists.mutable.withAll(dCtx.qualifiedName().packagePath() == null ? Lists.mutable.empty() : ListAdapter.adapt(dCtx.qualifiedName().packagePath().identifier())));
unit._package(packageInstance);
packageInstance._childrenAdd(unit);
}
} else {
result = this.measureParser(dCtx, importId, this.addLines);
}
} else {
result = this.measureParser(dCtx, importId, this.addLines);
}
}
MeasureInstance mI = (MeasureInstance) result;
List<Unit> allMeasureUnitInstances = Lists.mutable.<Unit>withAll(mI._nonCanonicalUnits()).with(mI._canonicalUnit()).toList();
this.coreInstancesResult.add(result);
this.coreInstancesResult.addAll(allMeasureUnitInstances);
}
}
if (ctx.association() != null) {
for (AssociationContext pCtx : ctx.association()) {
if (this.hasImportChanged) {
result = this.associationParser(pCtx, importId);
} else {
String importGroupID = importId._name();
String newContent = Lists.mutable.with(pCtx.start.getInputStream().getText(new Interval(pCtx.start.getStartIndex(), pCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
List<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
if (oldInstances.size() == 1) {
CoreInstance thisInstance = oldInstances.get(0);
this.oldInstances.remove(thisInstance);
SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(pCtx.ASSOCIATION().getSymbol(), pCtx.qualifiedName().identifier().getStart(), pCtx.getStop());
if (thisInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
this.offsetSourceInformationForInstanceAndChildren(thisInstance, newSourceInfo.getStartLine() - thisInstance.getSourceInformation().getStartLine());
PackageInstance packageInstance = this.buildPackage(pCtx.qualifiedName().packagePath());
((PackageableElement) thisInstance)._package(packageInstance);
packageInstance._childrenAdd((PackageableElement) thisInstance);
result = thisInstance;
} else {
result = this.associationParser(pCtx, importId);
}
} else {
result = this.associationParser(pCtx, importId);
}
}
this.coreInstancesResult.add(result);
}
}
if (ctx.enumDefinition() != null) {
for (EnumDefinitionContext pCtx : ctx.enumDefinition()) {
if (this.hasImportChanged) {
result = this.enumParser(pCtx, importId);
} else {
String importGroupID = importId._name();
String newContent = Lists.mutable.with(pCtx.start.getInputStream().getText(new Interval(pCtx.start.getStartIndex(), pCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
List<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
if (oldInstances.size() == 1) {
CoreInstance thisInstance = oldInstances.get(0);
this.oldInstances.remove(thisInstance);
SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(pCtx.getStart(), pCtx.qualifiedName().identifier().getStart(), pCtx.getStop());
if (thisInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
this.offsetSourceInformationForInstanceAndChildren(thisInstance, newSourceInfo.getStartLine() - thisInstance.getSourceInformation().getStartLine());
PackageInstance packageInstance = this.buildPackage(pCtx.qualifiedName().packagePath());
((PackageableElement) thisInstance)._package(packageInstance);
packageInstance._childrenAdd((PackageableElement) thisInstance);
result = thisInstance;
} else {
result = this.enumParser(pCtx, importId);
}
} else {
result = this.enumParser(pCtx, importId);
}
}
this.coreInstancesResult.add(result);
}
}
if (ctx.nativeFunction() != null) {
for (NativeFunctionContext pCtx : ctx.nativeFunction()) {
if (this.hasImportChanged) {
this.nativeFunction(pCtx, importId, "", this.coreInstancesResult);
} else {
String importGroupID = importId._name();
String newContent = Lists.mutable.with(pCtx.start.getInputStream().getText(new Interval(pCtx.start.getStartIndex(), pCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
List<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
if (oldInstances.size() == 1) {
CoreInstance thisInstance = oldInstances.get(0);
this.oldInstances.remove(thisInstance);
SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(pCtx.NATIVE().getSymbol(), pCtx.qualifiedName().identifier().getStart(), pCtx.END_LINE().getSymbol());
if (thisInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
this.functionCounter++;
this.offsetSourceInformationForInstanceAndChildren(thisInstance, newSourceInfo.getStartLine() - thisInstance.getSourceInformation().getStartLine());
PackageInstance packageInstance = this.buildPackage(pCtx.qualifiedName().packagePath());
((PackageableElement) thisInstance)._package(packageInstance);
packageInstance._childrenAdd((PackageableElement) thisInstance);
this.coreInstancesResult.add(thisInstance);
} else {
this.nativeFunction(pCtx, importId, "", this.coreInstancesResult);
}
} else {
this.nativeFunction(pCtx, importId, "", this.coreInstancesResult);
}
}
}
}
if (ctx.functionDefinition() != null) {
for (FunctionDefinitionContext pCtx : ctx.functionDefinition()) {
if (this.hasImportChanged) {
result = this.concreteFunctionDefinition(pCtx, importId, true, "", this.coreInstancesResult);
} else {
String importGroupID = importId._name();
String newContent = Lists.mutable.with(pCtx.start.getInputStream().getText(new Interval(pCtx.start.getStartIndex(), pCtx.stop.getStopIndex())).split("\\r?\\n")).makeString("", System.lineSeparator(), System.lineSeparator());
List<CoreInstance> oldInstances = this.oldInstances.select(i -> (this.oldState != null) && this.oldState.instanceImportGroupInSourceEqualsNewImportGroup(i, importGroupID) && this.oldState.instanceContentInSourceEqualsNewContent(i, newContent), Lists.mutable.empty());
if (oldInstances.size() == 1) {
CoreInstance thisInstance = oldInstances.get(0);
this.oldInstances.remove(thisInstance);
SourceInformation newSourceInfo = this.sourceInformation.getPureSourceInformation(pCtx.FUNCTION().getSymbol(), pCtx.qualifiedName().identifier().getStart(), pCtx.getStop());
if (thisInstance.getSourceInformation().getStartColumn() == newSourceInfo.getStartColumn()) {
this.functionCounter++;
this.offsetSourceInformationForInstanceAndChildren(thisInstance, newSourceInfo.getStartLine() - thisInstance.getSourceInformation().getStartLine());
PackageInstance packageInstance = this.buildPackage(pCtx.qualifiedName().packagePath());
((PackageableElement) thisInstance)._package(packageInstance);
packageInstance._childrenAdd((PackageableElement) thisInstance);
this.coreInstancesResult.add(thisInstance);
result = thisInstance;
} else {
result = this.concreteFunctionDefinition(pCtx, importId, true, "", this.coreInstancesResult);
}
} else {
result = this.concreteFunctionDefinition(pCtx, importId, true, "", this.coreInstancesResult);
}
}
}
}
if (ctx.instance() != null) {
for (InstanceContext pCtx : ctx.instance()) {
result = this.instanceParser(pCtx, true, importId, this.addLines, "", true, useImportStubsInInstanceParser);
this.coreInstancesResult.add(result);
}
}
this.newSourceInfoMap.forEachKeyValue(CoreInstance::setSourceInformation);
return result;
}
use of org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method constraint.
private Constraint constraint(CoreInstance owner, ConstraintContext ctx, int position, ImportGroup importId, LambdaContext lambdaContext, boolean addLines, boolean postConstraint) {
String constraintName;
String constraintOwner = null;
String constraintExternalId = null;
CoreInstance constraintFunctionDefinition;
String constraintLevel = null;
LambdaFunction<?> constraintMessageFunction = null;
SourceInformation constraintSourceInformation;
if (ctx.simpleConstraint() != null) {
org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.SimpleConstraintContext simpleConstraintContext = ctx.simpleConstraint();
constraintName = simpleConstraintContext.constraintId() != null ? simpleConstraintContext.constraintId().VALID_STRING().getText() : String.valueOf(position);
constraintFunctionDefinition = this.combinedExpression(simpleConstraintContext.combinedExpression(), "", Lists.mutable.empty(), lambdaContext, "", true, importId, addLines);
constraintSourceInformation = this.sourceInformation.getPureSourceInformation(simpleConstraintContext.getStart(), simpleConstraintContext.getStart(), simpleConstraintContext.getStop());
} else {
org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ComplexConstraintContext complexConstraintContext = ctx.complexConstraint();
constraintSourceInformation = this.sourceInformation.getPureSourceInformation(complexConstraintContext.getStart(), complexConstraintContext.VALID_STRING().getSymbol(), complexConstraintContext.getStop());
if (this.processorSupport.instance_instanceOf(owner, M3Paths.Class)) {
constraintName = complexConstraintContext.VALID_STRING().getText();
if (complexConstraintContext.constraintOwner() != null) {
constraintOwner = complexConstraintContext.constraintOwner().VALID_STRING().getText();
}
if (complexConstraintContext.constraintExternalId() != null) {
constraintExternalId = this.removeQuotes(complexConstraintContext.constraintExternalId().STRING());
}
constraintFunctionDefinition = this.combinedExpression(complexConstraintContext.constraintFunction().combinedExpression(), "", Lists.mutable.empty(), lambdaContext, "", true, importId, addLines);
if (complexConstraintContext.constraintEnforcementLevel() != null) {
constraintLevel = complexConstraintContext.constraintEnforcementLevel().ENFORCEMENT_LEVEL().getText();
}
if (complexConstraintContext.constraintMessage() != null) {
CoreInstance messageFunction = this.combinedExpression(complexConstraintContext.constraintMessage().combinedExpression(), "", Lists.mutable.empty(), lambdaContext, "", true, importId, addLines);
SourceInformation messageSourceInformation = messageFunction.getSourceInformation();
CoreInstance messageFunctionType = this.repository.newAnonymousCoreInstance(messageSourceInformation, this.processorSupport.package_getByUserPath(M3Paths.FunctionType), true);
CoreInstance param = VariableExpressionInstance.createPersistent(this.repository, messageSourceInformation, (GenericType) org.finos.legend.pure.m3.navigation.type.Type.wrapGenericType(owner, this.processorSupport), this.pureOne, "this");
Instance.addValueToProperty(messageFunctionType, M3Properties.parameters, param, this.processorSupport);
Instance.setValueForProperty(messageFunctionType, M3Properties.returnMultiplicity, this.getPureOne(), this.processorSupport);
Instance.setValueForProperty(messageFunctionType, M3Properties.returnType, org.finos.legend.pure.m3.navigation.type.Type.wrapGenericType(this.processorSupport.package_getByUserPath(M3Paths.String), this.processorSupport), this.processorSupport);
CoreInstance messageFunctionTypeGt = this.repository.newAnonymousCoreInstance(messageSourceInformation, this.processorSupport.package_getByUserPath(M3Paths.GenericType), true);
Instance.setValueForProperty(messageFunctionTypeGt, M3Properties.rawType, messageFunctionType, this.processorSupport);
CoreInstance lambdaFunctionClass = this.processorSupport.package_getByUserPath(M3Paths.LambdaFunction);
CoreInstance lambdaGenericType = org.finos.legend.pure.m3.navigation.type.Type.wrapGenericType(lambdaFunctionClass, this.processorSupport);
Instance.setValueForProperty(lambdaGenericType, M3Properties.typeArguments, messageFunctionTypeGt, this.processorSupport);
constraintMessageFunction = LambdaFunctionInstance.createPersistent(this.repository, lambdaContext.getLambdaFunctionUniqueName(), messageSourceInformation);
Instance.setValueForProperty(constraintMessageFunction, M3Properties.expressionSequence, messageFunction, this.processorSupport);
Instance.setValueForProperty(constraintMessageFunction, M3Properties.classifierGenericType, lambdaGenericType, this.processorSupport);
Instance.setValueForProperty(messageFunctionType, M3Properties.function, constraintMessageFunction, this.processorSupport);
}
} else {
throw new PureParserException(constraintSourceInformation, "Complex constraint specifications are supported only for class definitions");
}
}
SourceInformation functionSourceInformation = constraintFunctionDefinition.getSourceInformation();
CoreInstance functionType = this.repository.newAnonymousCoreInstance(functionSourceInformation, this.processorSupport.package_getByUserPath(M3Paths.FunctionType), true);
if (this.processorSupport.instance_instanceOf(owner, M3Paths.ElementWithConstraints)) {
CoreInstance param = VariableExpressionInstance.createPersistent(this.repository, functionSourceInformation, (GenericType) org.finos.legend.pure.m3.navigation.type.Type.wrapGenericType(owner, this.processorSupport), this.pureOne, "this");
Instance.addValueToProperty(functionType, M3Properties.parameters, param, this.processorSupport);
}
if (this.processorSupport.instance_instanceOf(owner, M3Paths.FunctionDefinition)) {
FunctionType ft = (FunctionType) this.processorSupport.function_getFunctionType(owner);
MutableList<CoreInstance> params = Lists.mutable.empty();
params.addAll(Instance.getValueForMetaPropertyToManyResolved(ft, M3Properties.parameters, this.processorSupport).toList());
if (postConstraint) {
CoreInstance returnParam = VariableExpressionInstance.createPersistent(this.repository, functionSourceInformation, (GenericType) ft.getValueForMetaPropertyToOne(M3Properties.returnType), (Multiplicity) ft.getValueForMetaPropertyToOne(M3Properties.returnMultiplicity), "return");
params.add(returnParam);
}
Instance.addValueToProperty(functionType, M3Properties.parameters, params, this.processorSupport);
}
Instance.setValueForProperty(functionType, M3Properties.returnMultiplicity, this.getPureOne(), this.processorSupport);
Instance.setValueForProperty(functionType, M3Properties.returnType, org.finos.legend.pure.m3.navigation.type.Type.wrapGenericType(this.processorSupport.package_getByUserPath(M3Paths.Boolean), this.processorSupport), this.processorSupport);
CoreInstance functionTypeGt = this.repository.newAnonymousCoreInstance(functionSourceInformation, this.processorSupport.package_getByUserPath(M3Paths.GenericType), true);
Instance.setValueForProperty(functionTypeGt, M3Properties.rawType, functionType, this.processorSupport);
CoreInstance lambdaFunctionClass = this.processorSupport.package_getByUserPath(M3Paths.LambdaFunction);
CoreInstance lambdaGenericType = org.finos.legend.pure.m3.navigation.type.Type.wrapGenericType(lambdaFunctionClass, this.processorSupport);
Instance.setValueForProperty(lambdaGenericType, M3Properties.typeArguments, functionTypeGt, this.processorSupport);
LambdaFunction<?> constraintFunctionLambda = LambdaFunctionInstance.createPersistent(this.repository, lambdaContext.getLambdaFunctionUniqueName(), functionSourceInformation);
Instance.setValueForProperty(constraintFunctionLambda, M3Properties.expressionSequence, constraintFunctionDefinition, this.processorSupport);
Instance.setValueForProperty(constraintFunctionLambda, M3Properties.classifierGenericType, lambdaGenericType, this.processorSupport);
Instance.setValueForProperty(functionType, M3Properties.function, constraintFunctionLambda, this.processorSupport);
Constraint constraint = ConstraintInstance.createPersistent(this.repository, null, null, null);
constraint.setSourceInformation(constraintSourceInformation);
constraint._name(constraintName);
if (constraintOwner != null) {
constraint._owner(constraintOwner);
}
if (constraintExternalId != null) {
constraint._externalId(constraintExternalId);
}
constraint._functionDefinition(constraintFunctionLambda);
if (constraintLevel != null) {
constraint._enforcementLevel(constraintLevel);
}
if (constraintMessageFunction != null) {
constraint._messageFunction(constraintMessageFunction);
}
return constraint;
}
use of org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method checkExists.
private void checkExists(PackagePathContext pkgCtx, IdentifierContext identifierCtx, SourceInformation sourceInfo) throws PureParserException {
boolean exists;
MutableList<String> allPaths = Lists.mutable.empty();
MutableList<String> packagePaths = this.packageToList(pkgCtx);
allPaths.addAll(packagePaths);
allPaths.add(identifierCtx.getText());
try {
exists = this.userPathDefined(allPaths);
} catch (Exception e) {
if (sourceInfo == null) {
sourceInfo = this.sourceInformation.getPureSourceInformation(identifierCtx.getStart(), identifierCtx.getStart(), identifierCtx.getStop());
}
throw new PureParserException(sourceInfo, allPaths.makeString("Error determining whether the path ", "::", " exists"), e);
}
if (exists) {
if (sourceInfo == null) {
sourceInfo = this.sourceInformation.getPureSourceInformation(identifierCtx.getStart(), identifierCtx.getStart(), identifierCtx.getStop());
}
throw new PureParserException(sourceInfo, "The element '" + identifierCtx.getText() + "' already exists in the package '" + (pkgCtx == null ? "::" : this.packageToString(pkgCtx)) + "'");
}
}
Aggregations