Search in sources :

Example 1 with Tag

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);
    }
}
Also used : TaggedValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Stereotype(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype) Tag(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag)

Example 2 with Tag

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);
    }
}
Also used : TaggedValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue) Stereotype(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype) ListIterable(org.eclipse.collections.api.list.ListIterable) RichIterable(org.eclipse.collections.api.RichIterable) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Tag(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag)

Example 3 with Tag

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();
            }
        }
    }
}
Also used : ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) TaggedValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Tag(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag) ElementWithTaggedValues(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.ElementWithTaggedValues) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 4 with Tag

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);
}
Also used : PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance)

Example 5 with Tag

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());
}
Also used : ListIterable(org.eclipse.collections.api.list.ListIterable) Tag(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag) Profile(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Profile) Test(org.junit.Test)

Aggregations

Tag (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag)9 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)6 Stereotype (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype)5 TaggedValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue)5 ListIterable (org.eclipse.collections.api.list.ListIterable)4 Profile (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Profile)3 Test (org.junit.Test)3 PureExecutionException (org.finos.legend.pure.m3.exception.PureExecutionException)2 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)2 Scope (io.opentracing.Scope)1 Span (io.opentracing.Span)1 Entry (java.util.Map.Entry)1 TimeoutException (java.util.concurrent.TimeoutException)1 RichIterable (org.eclipse.collections.api.RichIterable)1 MutableMap (org.eclipse.collections.api.map.MutableMap)1 RuntimeTestScriptBuilder (org.finos.legend.pure.m3.RuntimeTestScriptBuilder)1 AnnotatedElement (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.AnnotatedElement)1 Annotation (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Annotation)1 ElementWithTaggedValues (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.ElementWithTaggedValues)1 ConcreteFunctionDefinition (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinition)1