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);
}
}
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);
}
}
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);
}
});
}
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);
}
}
}
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);
}
}
}
}
}
Aggregations