Search in sources :

Example 1 with AnnotatedElement

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.AnnotatedElement 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 AnnotatedElement

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.AnnotatedElement 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 AnnotatedElement

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.AnnotatedElement in project legend-pure by finos.

the class VisibilityValidation method validateAnnotatedElement.

private static void validateAnnotatedElement(AnnotatedElement element, String sourceId, ValidatorState validatorState, ProcessorSupport processorSupport) throws PureCompilationException {
    // Check stereotypes
    ImportStub.withImportStubByPasses(ListHelper.wrapListIterable(element._stereotypesCoreInstance()), processorSupport).forEach(stereotype -> {
        Profile profile = ((Annotation) stereotype)._profile();
        if (!Visibility.isVisibleInSource(profile, sourceId, validatorState.getCodeStorage().getAllRepositories(), processorSupport)) {
            throwRepoVisibilityException(element.getSourceInformation(), profile, sourceId, processorSupport);
        }
    });
    // Check tagged values
    element._taggedValues().forEach(taggedValue -> {
        Tag tag = (Tag) ImportStub.withImportStubByPass(taggedValue._tagCoreInstance(), processorSupport);
        Profile profile = (tag == null) ? null : tag._profile();
        if (!Visibility.isVisibleInSource(profile, sourceId, validatorState.getCodeStorage().getAllRepositories(), processorSupport)) {
            throwRepoVisibilityException(element.getSourceInformation(), profile, sourceId, processorSupport);
        }
    });
}
Also used : Tag(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag) Profile(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Profile) Annotation(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Annotation)

Example 4 with AnnotatedElement

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.AnnotatedElement in project legend-pure by finos.

the class ProfileUnloaderWalk method run.

@Override
public void run(Profile profile, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    WalkerState walkerState = (WalkerState) state;
    walkerState.addInstance(profile);
    for (Tag tag : profile._p_tags()) {
        for (AnnotatedElement modelElement : tag._modelElements()) {
            matcher.fullMatch(modelElement, state);
        }
    }
    for (Stereotype stereotype : profile._p_stereotypes()) {
        for (AnnotatedElement modelElement : stereotype._modelElements()) {
            matcher.fullMatch(modelElement, state);
        }
    }
}
Also used : AnnotatedElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.AnnotatedElement) 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 5 with AnnotatedElement

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.AnnotatedElement in project legend-pure by finos.

the class ProjectionUtil method copyAnnotations.

public static void copyAnnotations(AnnotatedElement originalOwner, AnnotatedElement newOwner, SourceInformation newSourceInfo, boolean updateModelElements, ProcessorSupport processorSupport) {
    ListIterable<? extends CoreInstance> stereotypes = ImportStub.withImportStubByPasses((ListIterable<? extends CoreInstance>) originalOwner._stereotypesCoreInstance(), processorSupport);
    if (stereotypes.notEmpty()) {
        newOwner._stereotypesAddAllCoreInstance((ListIterable<CoreInstance>) stereotypes);
        if (updateModelElements) {
            for (Stereotype stereotype : (ListIterable<Stereotype>) stereotypes) {
                stereotype._modelElementsAdd(newOwner);
            }
        }
    }
    RichIterable<? extends TaggedValue> taggedValues = originalOwner._taggedValues();
    if (taggedValues.notEmpty()) {
        MutableList<TaggedValue> taggedValueCopies = FastList.newList(taggedValues.size());
        for (TaggedValue taggedValue : taggedValues) {
            Tag tag = (Tag) ImportStub.withImportStubByPass(taggedValue._tagCoreInstance(), processorSupport);
            String value = taggedValue._value();
            TaggedValue taggedValueCopy = (TaggedValue) processorSupport.newAnonymousCoreInstance(newSourceInfo, M3Paths.TaggedValue);
            taggedValueCopy._tagCoreInstance(tag);
            taggedValueCopy._value(value);
            taggedValueCopies.add(taggedValueCopy);
        }
        newOwner._taggedValuesAddAll(taggedValueCopies);
        if (updateModelElements) {
            MutableSet<CoreInstance> tags = Sets.mutable.empty();
            for (TaggedValue taggedValue : taggedValues) {
                Tag tag = (Tag) ImportStub.withImportStubByPass(taggedValue._tagCoreInstance(), processorSupport);
                if (tags.add(tag)) {
                    tag._modelElementsAdd(newOwner);
                }
            }
        }
    }
}
Also used : ListIterable(org.eclipse.collections.api.list.ListIterable) 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)

Aggregations

Tag (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag)5 Stereotype (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype)4 TaggedValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue)3 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)3 ListIterable (org.eclipse.collections.api.list.ListIterable)2 RichIterable (org.eclipse.collections.api.RichIterable)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 Profile (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Profile)1