use of org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TypeContext 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;
}
}
use of org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.TypeContext in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method type.
public GenericType type(TypeContext ctx, MutableList<String> typeParametersNames, String space, ImportGroup importId, boolean addLines) {
if (ctx.qualifiedName() != null) {
ListIterable<GenericType> renderedTypeArguments = this.typeArguments(ctx.typeArguments(), typeParametersNames, importId, addLines);
ListIterable<Multiplicity> renderedMultiplicityArguments = this.multiplicityArguments(ctx.multiplicityArguments());
return this.processType(ctx.qualifiedName(), typeParametersNames, renderedTypeArguments, renderedMultiplicityArguments, importId);
}
if (ctx.unitName() != null) {
return this.processUnitType(ctx.unitName(), importId);
}
GenericType returnType = this.type(ctx.type(), typeParametersNames, spacePlusTabs(space, 5), importId, addLines);
Multiplicity returnMultiplicity = this.buildMultiplicity(ctx.multiplicity().multiplicityArgument());
SourceInformation sourceInfo = this.sourceInformation.getPureSourceInformation(ctx.getStart(), ctx.getStart(), ctx.getStop());
FunctionTypeInstance functionTypeInstance = FunctionTypeInstance.createPersistent(this.repository, sourceInfo, returnMultiplicity, returnType);
MutableList<VariableExpression> params = ListIterate.collect(ctx.functionTypePureType(), fCtx -> typeFunctionTypePureType(fCtx, typeParametersNames, space, importId, addLines));
if (params.notEmpty()) {
functionTypeInstance._parameters(params);
}
GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
genericTypeInstance._rawTypeCoreInstance(functionTypeInstance);
return genericTypeInstance;
}
Aggregations