Search in sources :

Example 1 with Stereotype

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

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

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

Example 4 with Stereotype

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

Example 5 with Stereotype

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

Aggregations

Stereotype (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype)11 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)8 Tag (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag)6 ListIterable (org.eclipse.collections.api.list.ListIterable)4 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)4 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)4 Root_meta_pure_metamodel_function_LambdaFunction_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_function_LambdaFunction_Impl)3 Root_meta_pure_metamodel_type_generics_GenericType_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl)3 Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl)3 Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl)3 Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl)3 ElementWithStereotypes (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.ElementWithStereotypes)3 Profile (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Profile)3 TaggedValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue)3 LambdaFunction (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction)3 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)3 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)3 SimpleFunctionExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression)3 Pair (org.eclipse.collections.api.tuple.Pair)2 MilestoningStereotype (org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningStereotype)2