use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method simpleProperty.
private void simpleProperty(PropertyContext ctx, MutableList<Property<? extends CoreInstance, ?>> properties, MutableList<String> typeParameterNames, MutableList<String> multiplicityParameterNames, ImportStub isOwner, ImportGroup importId, boolean addLines) {
ListIterable<CoreInstance> stereotypes = null;
ListIterable<TaggedValue> tags = null;
DefaultValue defaultValue = null;
GenericType genericType;
Multiplicity multiplicity;
String aggregation;
String propertyName = ctx.identifier().getText();
if (ctx.stereotypes() != null) {
stereotypes = this.stereotypes(ctx.stereotypes(), importId);
}
if (ctx.taggedValues() != null) {
tags = this.taggedValues(ctx.taggedValues(), importId);
}
if (ctx.aggregation() != null) {
if ("(composite)".equals(ctx.aggregation().getText())) {
aggregation = "Composite";
} else if ("(shared)".equals(ctx.aggregation().getText())) {
aggregation = "Shared";
} else {
aggregation = "None";
}
} else {
aggregation = "None";
}
if (ctx.defaultValue() != null) {
defaultValue = defaultValue(ctx.defaultValue(), importId, propertyName);
}
genericType = this.type(ctx.propertyReturnType().type(), typeParameterNames, "", importId, addLines);
multiplicity = this.buildMultiplicity(ctx.propertyReturnType().multiplicity().multiplicityArgument());
Enumeration<?> agg = (Enumeration<?>) this.processorSupport.package_getByUserPath(M3Paths.AggregationKind);
Enum aggKind = (Enum) agg._values().detect(v -> aggregation.equals(((Enum) v).getName()));
SourceInformation propertySourceInfo = this.sourceInformation.getPureSourceInformation(ctx.identifier().getStart(), ctx.identifier().getStart(), ctx.getStop());
PropertyInstance propertyInstance = PropertyInstance.createPersistent(this.repository, propertyName, propertySourceInfo, aggKind, genericType, multiplicity, null);
propertyInstance._stereotypesCoreInstance(stereotypes);
propertyInstance._taggedValues(tags);
propertyInstance._name(propertyName);
propertyInstance._defaultValue(defaultValue);
GenericTypeInstance classifierGT = GenericTypeInstance.createPersistent(this.repository, propertySourceInfo);
ClassInstance propertyType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Property);
classifierGT._rawTypeCoreInstance(propertyType);
classifierGT._multiplicityArguments(Lists.mutable.of(multiplicity));
GenericTypeInstance classifierGTTA = GenericTypeInstance.createPersistent(this.repository);
classifierGTTA._rawTypeCoreInstance(isOwner);
if (!typeParameterNames.isEmpty()) {
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);
}
classifierGTTA._multiplicityArguments(multParameters);
}
// Clone generic type
// TODO - do we need a deep clone?
GenericTypeInstance ngt = GenericTypeInstance.createPersistent(this.repository, genericType.getSourceInformation());
CoreInstance rawType = genericType._rawTypeCoreInstance();
if (rawType != null) {
if (rawType instanceof ImportStub) {
ImportStub gtis = (ImportStub) rawType;
ImportStubInstance is = ImportStubInstance.createPersistent(this.repository, gtis.getSourceInformation(), gtis._idOrPath(), gtis._importGroup());
// ImportStubInstance is = ImportStubInstance.createPersistent(this.repository, gtis.getSourceInformation(), ((ImportStubInstance)gtis)._idOrPathAsCoreInstance().getName(), (ImportGroup)gtis._importGroup());
ngt._rawTypeCoreInstance(is);
} else {
ngt._rawTypeCoreInstance(rawType);
}
}
if (!genericType._typeArguments().isEmpty()) {
ngt._typeArguments(genericType._typeArguments());
}
ngt._typeParameter(genericType._typeParameter());
if (!genericType._multiplicityArguments().isEmpty()) {
ngt._multiplicityArguments(genericType._multiplicityArguments());
}
classifierGT._typeArguments(Lists.mutable.<GenericType>of(classifierGTTA, ngt));
propertyInstance._classifierGenericType(classifierGT);
properties.add(propertyInstance);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method nativeFunction.
private void nativeFunction(NativeFunctionContext ctx, ImportGroup importId, String space, MutableList<CoreInstance> coreInstancesResult) {
this.functionCounter++;
NativeFunctionInstance function = NativeFunctionInstance.createPersistent(this.repository, ctx.qualifiedName().identifier().getText() + this.functionCounter, this.sourceInformation.getPureSourceInformation(ctx.NATIVE().getSymbol(), ctx.qualifiedName().identifier().getStart(), ctx.END_LINE().getSymbol()));
MutableList<String> typeParametersNames = Lists.mutable.empty();
MutableList<String> multiplicityParametersNames = Lists.mutable.empty();
if (ctx.typeAndMultiplicityParameters() != null) {
this.typeParametersAndMultiplicityParameters(ctx.typeAndMultiplicityParameters(), typeParametersNames, multiplicityParametersNames);
}
FunctionType signature = functionTypeSignature(ctx.functionTypeSignature(), function, typeParametersNames, multiplicityParametersNames, importId, spacePlusTabs(space, 1));
function._functionName(ctx.qualifiedName().identifier().getText());
PackageInstance packageInstance = this.buildPackage(ctx.qualifiedName().packagePath());
function._package(packageInstance);
packageInstance._childrenAdd(function);
GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
Type type = (Type) this.processorSupport.package_getByUserPath(M3Paths.NativeFunction);
genericTypeInstance._rawTypeCoreInstance(type);
GenericTypeInstance genericTypeInstanceTa = GenericTypeInstance.createPersistent(this.repository);
genericTypeInstanceTa._rawTypeCoreInstance(signature);
genericTypeInstance._typeArguments(Lists.mutable.<GenericType>of(genericTypeInstanceTa));
function._classifierGenericType(genericTypeInstance);
coreInstancesResult.add(function);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method propertyExpression.
private CoreInstance propertyExpression(PropertyExpressionContext ctx, CoreInstance result, MutableList<ValueSpecification> parameters, MutableList<String> typeParametersNames, LambdaContext lambdaContext, String space, ImportGroup importId) {
parameters.clear();
boolean function = false;
IdentifierContext property = ctx.identifier();
CoreInstance parameter;
if (ctx.functionExpressionParameters() != null) {
function = true;
FunctionExpressionParametersContext fepCtx = ctx.functionExpressionParameters();
if (fepCtx.combinedExpression() != null) {
for (CombinedExpressionContext ceCtx : fepCtx.combinedExpression()) {
parameter = this.combinedExpression(ceCtx, "param", typeParametersNames, lambdaContext, spacePlusTabs(space, 4), true, importId, addLines);
parameters.add((ValueSpecification) parameter);
}
}
} else if (ctx.functionExpressionLatestMilestoningDateParameter() != null) {
function = true;
ListIterate.collect(ctx.functionExpressionLatestMilestoningDateParameter().LATEST_DATE(), terminalNode -> InstanceValueInstance.createPersistent(repository, sourceInformation.getPureSourceInformation(terminalNode.getSymbol()), null, null)._values(Lists.immutable.with(repository.newLatestDateCoreInstance())), parameters);
}
if (!function) {
SimpleFunctionExpressionInstance sfe = SimpleFunctionExpressionInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(property.getStart()), null, null, importId, null);
InstanceValue instanceValue = this.doWrap(property, false);
// Going to become an auto-map lambda so set a name to be used for the lambda
instanceValue.setName(lambdaContext.getLambdaFunctionUniqueName());
instanceValue._multiplicity(this.getPureOne());
GenericTypeInstance gt = GenericTypeInstance.createPersistent(this.repository);
Type ti = (Type) this.processorSupport.package_getByUserPath("String");
gt._rawTypeCoreInstance(ti);
instanceValue._genericType(gt);
sfe._propertyName(instanceValue);
sfe._parametersValues(Lists.mutable.of((ValueSpecification) result));
result = sfe;
} else {
SimpleFunctionExpressionInstance sfe = SimpleFunctionExpressionInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(property.getStart()), null, null, importId, null);
InstanceValue instanceValue = this.doWrap(property, false);
// Going to become an auto-map lambda so set a name to be used for the lambda
instanceValue.setName(lambdaContext.getLambdaFunctionUniqueName());
instanceValue._multiplicity(this.getPureOne());
GenericTypeInstance gt = GenericTypeInstance.createPersistent(this.repository);
Type ti = (Type) this.processorSupport.package_getByUserPath("String");
gt._rawTypeCoreInstance(ti);
instanceValue._genericType(gt);
sfe._qualifiedPropertyName(instanceValue);
sfe._parametersValues(Lists.mutable.of((ValueSpecification) result).withAll(parameters));
result = sfe;
}
return result;
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method qualifiedProperty.
private void qualifiedProperty(QualifiedPropertyContext ctx, MutableList<QualifiedProperty<? extends CoreInstance>> qualifiedProperties, MutableList<String> typeParameterNames, MutableList<String> multiplicityParameterNames, ImportStub isOwner, ImportGroup importId, boolean addLines, int qualifiedPropertyIndex) {
ListIterable<CoreInstance> stereotypes = (ctx.stereotypes() == null) ? null : stereotypes(ctx.stereotypes(), importId);
ListIterable<TaggedValue> tags = (ctx.taggedValues() == null) ? null : taggedValues(ctx.taggedValues(), importId);
MutableList<VariableExpression> vars = Lists.mutable.of();
ListIterable<ValueSpecification> code = Lists.fixedSize.empty();
GenericType genericType = this.type(ctx.propertyReturnType().type(), typeParameterNames, "", importId, addLines);
Multiplicity multiplicity = this.buildMultiplicity(ctx.propertyReturnType().multiplicity().multiplicityArgument());
String propertyName = ctx.identifier().getText();
final String qualifiedPropertyName = propertyName + "_" + qualifiedPropertyIndex;
if (ctx.qualifiedPropertyBody() != null) {
if (ctx.qualifiedPropertyBody().functionVariableExpression() != null) {
ListIterate.collect(ctx.qualifiedPropertyBody().functionVariableExpression(), fveCtx -> functionVariableExpression(fveCtx, typeParameterNames, importId, ""), vars);
}
if (ctx.qualifiedPropertyBody().codeBlock() != null) {
LambdaContext lambdaContext = new LambdaContext(isOwner._idOrPath().replace("::", "_") + "_" + qualifiedPropertyName);
code = this.codeBlock(ctx.qualifiedPropertyBody().codeBlock(), typeParameterNames, importId, lambdaContext, addLines, "");
}
}
GenericTypeInstance variableGenericType = GenericTypeInstance.createPersistent(this.repository);
variableGenericType._rawTypeCoreInstance(isOwner);
if (typeParameterNames.notEmpty()) {
MutableList<GenericType> typeArgs = typeParameterNames.collect(n -> GenericTypeInstance.createPersistent(this.repository)._typeParameter(TypeParameterInstance.createPersistent(this.repository, n)));
variableGenericType._typeArguments(typeArgs);
}
if (multiplicityParameterNames.notEmpty()) {
MutableList<Multiplicity> multParameters = multiplicityParameterNames.collect(n -> MultiplicityInstance.createPersistent(this.repository, null, null)._multiplicityParameter(n));
variableGenericType._multiplicityArguments(multParameters);
}
VariableExpressionInstance vei = VariableExpressionInstance.createPersistent(this.repository, variableGenericType, this.getPureOne(), "this");
GenericTypeInstance ngt = GenericTypeInstance.createPersistent(this.repository);
CoreInstance rawType = genericType._rawTypeCoreInstance();
if (rawType != null) {
if (rawType instanceof ImportStub) {
ImportStub gtis = (ImportStub) rawType;
ImportStubInstance is = ImportStubInstance.createPersistent(this.repository, gtis.getSourceInformation(), gtis._idOrPath(), gtis._importGroup());
// ImportStubInstance is = ImportStubInstance.createPersistent(this.repository, gtis.getSourceInformation(), ((ImportStubInstance)gtis)._idOrPathAsCoreInstance().getName(), (ImportGroup)gtis._importGroup());
ngt._rawTypeCoreInstance(is);
} else {
ngt._rawTypeCoreInstance(rawType);
}
}
if (!genericType._typeArguments().isEmpty()) {
ngt._typeArguments(genericType._typeArguments());
}
ngt._typeParameter(genericType._typeParameter());
if (!genericType._multiplicityArguments().isEmpty()) {
ngt._multiplicityArguments(genericType._multiplicityArguments());
}
QualifiedPropertyInstance qpi = QualifiedPropertyInstance.createPersistent(this.repository, qualifiedPropertyName, this.sourceInformation.getPureSourceInformation(ctx.identifier().getStart(), ctx.identifier().getStart(), ctx.getStop()), genericType, multiplicity, null);
qpi._name(propertyName);
qpi._functionName(propertyName);
qpi._expressionSequence(code);
qpi._stereotypesCoreInstance(stereotypes);
qpi._taggedValues(tags);
FunctionTypeInstance ft = FunctionTypeInstance.createPersistent(this.repository, qpi.getSourceInformation(), multiplicity, ngt);
if (!typeParameterNames.isEmpty()) {
ft._typeParameters(this.processTypeParametersInstance(this.repository, typeParameterNames));
}
ft._parameters(Lists.mutable.<VariableExpression>of(vei).withAll(vars));
GenericTypeInstance ftGenericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
ftGenericTypeInstance._rawTypeCoreInstance(ft);
GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
genericTypeInstance._rawTypeCoreInstance(this.processorSupport.package_getByUserPath(M3Paths.QualifiedProperty));
genericTypeInstance._typeArguments(Lists.fixedSize.<GenericType>of(ftGenericTypeInstance));
qpi._classifierGenericType(genericTypeInstance);
qualifiedProperties.add(qpi);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method unitInstanceParser.
/**
* Parse the instantiation of an instance of UNIT.
*/
private InstanceValueInstance unitInstanceParser(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.UnitInstanceContext ctx, ImportGroup importId) {
org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.UnitInstanceLiteralContext uctx = ctx.unitInstanceLiteral();
GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
CoreInstance typeImportStub = ImportStubInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(ctx.unitName().identifier().getStart()), this.getUnitNameWithMeasure(ctx.unitName()), importId);
genericTypeInstance._rawTypeCoreInstance(typeImportStub);
InstanceValueInstance iv = InstanceValueInstance.createPersistent(this.repository, genericTypeInstance, this.getPureOne());
PrimitiveCoreInstance<?> result;
if (uctx.MINUS() != null) {
if (uctx.INTEGER() != null) {
result = this.repository.newIntegerCoreInstance("-" + uctx.INTEGER().getText());
} else if (uctx.DECIMAL() != null) {
result = this.repository.newDecimalCoreInstance("-" + uctx.DECIMAL().getText());
} else {
result = this.repository.newFloatCoreInstance("-" + uctx.FLOAT().getText());
}
} else {
if (uctx.INTEGER() != null) {
result = this.repository.newIntegerCoreInstance("+" + uctx.INTEGER().getText());
} else if (uctx.DECIMAL() != null) {
result = this.repository.newDecimalCoreInstance("+" + uctx.DECIMAL().getText());
} else {
result = this.repository.newFloatCoreInstance("+" + uctx.FLOAT().getText());
}
}
iv._genericType(genericTypeInstance);
iv._multiplicity(this.getPureOne());
iv._values(Lists.mutable.with(result.getValue()));
InstanceValueInstance wrapperIv = InstanceValueInstance.createPersistent(this.repository, genericTypeInstance, this.getPureOne());
wrapperIv._genericType(genericTypeInstance);
wrapperIv._multiplicity(this.getPureOne());
wrapperIv._values(Lists.mutable.with(iv));
return wrapperIv;
}
Aggregations