use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag 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.Tag 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.Tag 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.Tag in project legend-pure by finos.
the class Tag 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 tagName = Instance.getValueForMetaPropertyToOneResolved(params.get(1), M3Properties.values, processorSupport).getName();
CoreInstance profile = Instance.getValueForMetaPropertyToOneResolved(params.get(0), M3Properties.values, processorSupport);
CoreInstance tag = Profile.findTag(profile, tagName);
if (tag == null) {
throw new PureExecutionException(functionExpressionToUseInStack.getSourceInformation(), "The tag '" + tagName + "' can't be found in the profile '" + profile.getName() + "'");
}
return ValueSpecificationBootstrap.wrapValueSpecification(tag, ValueSpecification.isExecutable(params.get(0), processorSupport), processorSupport);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag in project legend-pure by finos.
the class TestProfile method testTags.
@Test
public void testTags() {
compileTestSource("/test/testSource.pure", "Profile test::myProfile\n" + "{\n" + " stereotypes: [st1, st2];\n" + " tags: [t1, t2, t3];\n" + "}");
Profile profile = (Profile) this.runtime.getCoreInstance("test::myProfile");
Assert.assertNotNull(profile);
ListIterable<Tag> tags = (ListIterable<Tag>) profile._p_tags();
Verify.assertSize(3, tags);
Tag t1 = (Tag) org.finos.legend.pure.m3.navigation.profile.Profile.findTag(profile, "t1");
Assert.assertNotNull(t1);
Assert.assertEquals("t1", t1._value());
Assert.assertSame(profile, t1._profile());
assertSourceInformation("/test/testSource.pure", 4, 10, 4, 10, 4, 11, t1.getSourceInformation());
Tag t2 = (Tag) org.finos.legend.pure.m3.navigation.profile.Profile.findTag(profile, "t2");
Assert.assertNotNull(t2);
Assert.assertEquals("t2", t2._value());
Assert.assertSame(profile, t2._profile());
assertSourceInformation("/test/testSource.pure", 4, 14, 4, 14, 4, 15, t2.getSourceInformation());
Tag t3 = (Tag) org.finos.legend.pure.m3.navigation.profile.Profile.findTag(profile, "t3");
Assert.assertNotNull(t3);
Assert.assertEquals("t3", t3._value());
Assert.assertSame(profile, t3._profile());
assertSourceInformation("/test/testSource.pure", 4, 18, 4, 18, 4, 19, t3.getSourceInformation());
}
Aggregations