use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue in project legend-pure by finos.
the class AnnotatedElementProcessor method noteModelElementForAnnotations.
public static void noteModelElementForAnnotations(AnnotatedElement annotatedElement, ProcessorSupport processorSupport) {
for (CoreInstance stereotype : ImportStub.withImportStubByPasses(ListHelper.wrapListIterable(annotatedElement._stereotypesCoreInstance()), processorSupport)) {
((Stereotype) stereotype)._modelElementsAdd(annotatedElement);
}
for (TaggedValue taggedValue : annotatedElement._taggedValues()) {
Tag tag = (Tag) ImportStub.withImportStubByPass(taggedValue._tagCoreInstance(), processorSupport);
tag._modelElementsAdd(annotatedElement);
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue in project legend-pure by finos.
the class ProjectionUtil method removedCopiedAnnotations.
public static void removedCopiedAnnotations(AnnotatedElement originalOwner, AnnotatedElement newOwner, final ProcessorSupport processorSupport) {
ListIterable<? extends Stereotype> originalStereotypes = (ListIterable<? extends Stereotype>) ImportStub.withImportStubByPasses((ListIterable<? extends CoreInstance>) originalOwner._stereotypesCoreInstance(), processorSupport);
if (originalStereotypes.notEmpty()) {
RichIterable<? extends CoreInstance> stereotypesToPartition = newOwner._stereotypesCoreInstance();
PartitionIterable<? extends CoreInstance> partition = stereotypesToPartition.partition(Predicates.in(originalStereotypes.toSet()));
RichIterable<? extends Stereotype> stereotypesToRemove = (RichIterable<? extends Stereotype>) partition.getSelected();
RichIterable<? extends CoreInstance> stereotypesToKeep = partition.getRejected();
for (Stereotype st : stereotypesToRemove) {
st._modelElementsRemove(newOwner);
if (st._modelElements().isEmpty()) {
st._modelElementsRemove();
}
}
newOwner._stereotypesCoreInstance((RichIterable<CoreInstance>) stereotypesToKeep);
}
RichIterable<? extends TaggedValue> originalTaggedValues = originalOwner._taggedValues();
if (originalTaggedValues.notEmpty()) {
final RichIterable<String> originalTaggedValuesAsString = originalTaggedValues.collect(new Function<TaggedValue, String>() {
@Override
public String valueOf(TaggedValue tv) {
Tag tag = (Tag) ImportStub.withImportStubByPass(tv._tagCoreInstance(), processorSupport);
String value = tv._value();
return tag.getName() + value;
}
});
RichIterable<? extends TaggedValue> taggedValuesToPartition = newOwner._taggedValues();
PartitionIterable<? extends TaggedValue> partition = taggedValuesToPartition.partition(new Predicate<TaggedValue>() {
@Override
public boolean accept(TaggedValue tv) {
Tag tag = (Tag) ImportStub.withImportStubByPass(tv._tagCoreInstance(), processorSupport);
String value = tv._value();
return originalTaggedValuesAsString.contains(tag.getName() + value);
}
});
RichIterable<? extends TaggedValue> taggedValuesToRemove = partition.getSelected();
RichIterable<? extends TaggedValue> taggedValuesToKeep = partition.getRejected();
for (TaggedValue taggedValue : taggedValuesToRemove) {
Tag tag = (Tag) ImportStub.withImportStubByPass(taggedValue._tagCoreInstance(), processorSupport);
tag._modelElementsRemove(newOwner);
if (tag._modelElements().isEmpty()) {
tag._modelElementsRemove();
}
}
newOwner._taggedValues(taggedValuesToKeep);
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue in project legend-pure by finos.
the class ElementWithTaggedValuesUnbind method run.
@Override
public void run(CoreInstance element, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ElementWithTaggedValues elementWithTaggedValues = ElementWithTaggedValuesCoreInstanceWrapper.toElementWithTaggedValues(element);
UnbindState unbindState = (UnbindState) state;
ProcessorSupport processorSupport = unbindState.getProcessorSupport();
for (TaggedValue taggedValue : elementWithTaggedValues._taggedValues()) {
unbindState.freeValidated(taggedValue);
CoreInstance embeddedTag = taggedValue._tagCoreInstance();
Tag tag;
try {
tag = (Tag) ImportStub.withImportStubByPass(embeddedTag, processorSupport);
} catch (PureCompilationException e) {
// Exception is ok here
tag = null;
}
if (tag != null) {
Shared.cleanImportStub(embeddedTag, processorSupport);
tag._modelElementsRemove(AnnotatedElementCoreInstanceWrapper.toAnnotatedElement(elementWithTaggedValues));
if (tag._modelElements().isEmpty()) {
tag._modelElementsRemove();
}
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue 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.extension.TaggedValue 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);
}
Aggregations