use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization in project legend-pure by finos.
the class TypeUnbind method run.
@Override
public void run(Type type, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ProcessorSupport processorSupport = state.getProcessorSupport();
for (Generalization generalization : type._generalizations()) {
GenericType general = generalization._general();
Type generalRawType = null;
try {
generalRawType = (Type) ImportStub.withImportStubByPass(general._rawTypeCoreInstance(), processorSupport);
} catch (PureCompilationException ex) {
// Ignore - if we can't resolve this type was probably already unbound
}
if (generalRawType != null) {
ListIterable<? extends CoreInstance> specializationsToRemove = generalRawType.getValueInValueForMetaPropertyToManyByIndex(M3Properties.specializations, IndexSpecifications.getPropertyValueIndexSpec(M3Properties.specific), type);
for (CoreInstance specialization : specializationsToRemove.toList()) {
generalRawType._specializationsRemove((Generalization) specialization);
}
if (generalRawType.getValueForMetaPropertyToMany(M3Properties.specializations).isEmpty()) {
generalRawType._specializationsRemove();
}
}
Shared.cleanUpGenericType(general, (UnbindState) state, processorSupport);
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization in project legend-pure by finos.
the class TestPureRuntimeClass_FunctionExpressionParam method testPureRuntimeClassParameterUsageCleanUp.
@Test
public void testPureRuntimeClassParameterUsageCleanUp() throws Exception {
RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("sourceId.pure", "function f(c:Class<Any>[1]):Any[1]{$c} function k():Nil[0]{f(A);[];}").createInMemorySource("userId.pure", "Class A{}").compile(), new RuntimeTestScriptBuilder().deleteSource("sourceId.pure").compile().createInMemorySource("sourceId.pure", "function f(c:Class<Any>[1]):Any[1]{$c} function k():Nil[0]{f(A);[];}").compile(), this.runtime, this.functionExecution, this.getAdditionalVerifiers());
Assert.assertEquals("A instance Class\n" + " classifierGenericType(Property):\n" + " Anonymous_StripedId instance GenericType\n" + " [... >0]\n" + " generalizations(Property):\n" + " Anonymous_StripedId instance Generalization\n" + " [... >0]\n" + " name(Property):\n" + " A instance String\n" + " package(Property):\n" + " Root instance Package\n" + " referenceUsages(Property):\n" + " Anonymous_StripedId instance ReferenceUsage\n" + " [... >0]", this.runtime.getCoreInstance("A").printWithoutDebug("", 0));
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization 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.coreinstance.meta.pure.metamodel.relationship.Generalization in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method enumParser.
private Enumeration<?> enumParser(EnumDefinitionContext ctx, ImportGroup importId) throws PureParserException {
EnumerationInstance enumerationInstance;
CoreInstance value;
MutableList<CoreInstance> values = Lists.mutable.empty();
ListIterable<CoreInstance> stereotypes = Lists.mutable.empty();
ListIterable<TaggedValue> tags = Lists.mutable.empty();
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);
PackageInstance packageInstance = this.buildPackage(ctx.qualifiedName().packagePath());
GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
ClassInstance enumerationType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Enumeration);
genericTypeInstance._rawTypeCoreInstance(enumerationType);
enumerationInstance = EnumerationInstance.createPersistent(this.repository, ctx.qualifiedName().identifier().getText());
enumerationInstance._name(ctx.qualifiedName().identifier().getText());
enumerationInstance._package(packageInstance);
GenericTypeInstance taGenericType = GenericTypeInstance.createPersistent(this.repository);
taGenericType._rawTypeCoreInstance(enumerationInstance);
genericTypeInstance._typeArguments(Lists.mutable.<GenericType>of(taGenericType));
enumerationInstance._classifierGenericType(genericTypeInstance);
packageInstance._childrenAdd(enumerationInstance);
if (!tags.isEmpty()) {
enumerationInstance._taggedValues(tags);
}
if (!stereotypes.isEmpty()) {
enumerationInstance._stereotypesCoreInstance(stereotypes);
}
enumerationInstance._classifierGenericType(genericTypeInstance);
GenericTypeInstance general = GenericTypeInstance.createPersistent(this.repository);
ClassInstance enumType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.Enum);
general._rawTypeCoreInstance(enumType);
GeneralizationInstance gen = GeneralizationInstance.createPersistent(this.repository, general, enumerationInstance);
enumerationInstance._generalizations(Lists.mutable.<Generalization>of(gen));
for (EnumValueContext evCtx : ctx.enumValue()) {
value = this.enumValue(evCtx, enumerationInstance, importId);
values.add(value);
}
enumerationInstance.setSourceInformation(this.sourceInformation.getPureSourceInformation(ctx.getStart(), ctx.qualifiedName().identifier().getStart(), ctx.getStop()));
enumerationInstance._values(values);
return enumerationInstance;
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization in project legend-pure by finos.
the class SetImplementationProcessor method buildMappingClassOutOfLocalProperties.
private void buildMappingClassOutOfLocalProperties(final ModelRepository repository, SetImplementation classMapping, ProcessorState state, Matcher matcher, final ProcessorSupport processorSupport) {
RichIterable<? extends PropertyMapping> localProperties = classMapping instanceof InstanceSetImplementation ? ((InstanceSetImplementation) classMapping)._propertyMappings().select(new Predicate<PropertyMapping>() {
@Override
public boolean accept(PropertyMapping propertyMapping) {
return propertyMapping._localMappingProperty() != null ? propertyMapping._localMappingProperty() : false;
}
}) : Lists.immutable.<PropertyMapping>empty();
CoreInstance _class = ImportStub.withImportStubByPass(classMapping._classCoreInstance(), processorSupport);
boolean hasAggregateSpecification = classMapping instanceof InstanceSetImplementation && ((InstanceSetImplementation) classMapping)._aggregateSpecification() != null;
if (localProperties.notEmpty() || hasAggregateSpecification) {
Mapping mapping = (Mapping) ImportStub.withImportStubByPass(classMapping._parentCoreInstance(), processorSupport);
final MappingClass newClass = MappingClassCoreInstanceWrapper.toMappingClass(repository.newCoreInstance(_class.getName() + "_" + mapping.getName() + "_" + classMapping._id(), _Package.getByUserPath(M2MappingPaths.MappingClass, processorSupport), classMapping.getSourceInformation()));
newClass._name(_class.getName() + "_" + mapping.getName() + "_" + classMapping._id());
ClassInstance genericTypeClass = (ClassInstance) _Package.getByUserPath(M3Paths.GenericType, processorSupport);
GenericType genericType = (GenericType) repository.newAnonymousCoreInstance(null, genericTypeClass);
genericType._rawTypeCoreInstance(_Package.getByUserPath(M2MappingPaths.MappingClass, processorSupport));
GenericType typeArg = (GenericType) repository.newAnonymousCoreInstance(null, genericTypeClass);
typeArg._rawTypeCoreInstance(newClass);
genericType._typeArguments(((ImmutableList<GenericType>) Lists.immutable.withAll(genericType._typeArguments())).newWithAll(Lists.immutable.with(typeArg)));
newClass._classifierGenericType(genericType);
GenericType superType = (GenericType) repository.newAnonymousCoreInstance(null, genericTypeClass);
superType._rawTypeCoreInstance(_class);
Generalization newGeneralization = (Generalization) repository.newAnonymousCoreInstance(null, _Package.getByUserPath(M3Paths.Generalization, processorSupport));
newGeneralization._specific(newClass);
newGeneralization._general(superType);
newClass._generalizations(Lists.immutable.with(newGeneralization));
newClass._properties(Lists.immutable.withAll(newClass._properties()).newWithAll(localProperties.collect(new Function<PropertyMapping, CoreInstance>() {
@Override
public CoreInstance valueOf(PropertyMapping propertyMapping) {
Property property = (Property) ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport);
property._owner(newClass);
GenericType src = property._classifierGenericType()._typeArguments().toList().get(0);
src._rawTypeCoreInstance(newClass);
return property;
}
})));
SpecializationProcessor.process(newClass, processorSupport);
PostProcessor.processElement(matcher, newClass, state, processorSupport);
((InstanceSetImplementation) classMapping)._mappingClass(newClass);
}
}
Aggregations