use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype 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.Stereotype 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.Stereotype in project legend-pure by finos.
the class MilestoningFunctions method isGeneratedMilestoningProperty.
public static boolean isGeneratedMilestoningProperty(CoreInstance property, ProcessorSupport processorSupport, String stereotype, String milestoningPathSuffix) {
if (property instanceof ElementWithStereotypes) {
RichIterable<? extends CoreInstance> stereotypes = ((ElementWithStereotypes) property)._stereotypesCoreInstance();
if (stereotypes.notEmpty()) {
CoreInstance profile = processorSupport.package_getByUserPath(M3Paths.Milestoning);
CoreInstance milestoningStereotype = Profile.findStereotype(profile, stereotype);
return stereotypes.anySatisfy(st -> (st instanceof ImportStub) ? ((ImportStub) st)._idOrPath().endsWith(milestoningPathSuffix) : milestoningStereotype.equals(st));
}
}
return false;
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype in project legend-pure by finos.
the class Stereotype method execute.
@Override
public CoreInstance execute(ListIterable<? extends CoreInstance> params, Stack<MutableMap<String, CoreInstance>> resolvedTypeParameters, Stack<MutableMap<String, CoreInstance>> resolvedMultiplicityParameters, VariableContext variableContext, CoreInstance functionExpressionToUseInStack, Profiler profiler, InstantiationContext instantiationContext, ExecutionSupport executionSupport, Context context, ProcessorSupport processorSupport) throws PureExecutionException {
String stereotypeName = Instance.getValueForMetaPropertyToOneResolved(params.get(1), M3Properties.values, processorSupport).getName();
CoreInstance profile = Instance.getValueForMetaPropertyToOneResolved(params.get(0), M3Properties.values, processorSupport);
CoreInstance stereotype = Profile.findStereotype(profile, stereotypeName);
if (stereotype == null) {
throw new PureExecutionException(params.get(1).getSourceInformation(), "The stereotype '" + stereotypeName + "' can't be found in the profile '" + profile.getName() + "'");
}
return ValueSpecificationBootstrap.wrapValueSpecification(stereotype, ValueSpecification.isExecutable(params.get(0), processorSupport), processorSupport);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype in project legend-pure by finos.
the class StereotypeReferenceSerializer method serialize.
@Override
public void serialize(CoreInstance instance, ExternalReferenceSerializationHelper helper) {
Stereotype stereotype = (Stereotype) instance;
helper.writeElementReference(stereotype._profile());
helper.writeString(PrimitiveUtilities.getStringValue(instance));
}
Aggregations