Search in sources :

Example 1 with ElementWithStereotypes

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

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

the class AntlrContextToM3CoreInstance method enumValue.

private CoreInstance enumValue(EnumValueContext ctx, CoreInstance enumeration, ImportGroup importId) {
    ListIterable<CoreInstance> stereotypes = null;
    ListIterable<TaggedValue> tags = null;
    if (ctx.stereotypes() != null) {
        stereotypes = this.stereotypes(ctx.stereotypes(), importId);
    }
    if (ctx.taggedValues() != null) {
        tags = this.taggedValues(ctx.taggedValues(), importId);
    }
    CoreInstance enumValue = this.repository.newCoreInstance(ctx.identifier().getText(), enumeration, this.sourceInformation.getPureSourceInformation(ctx.identifier().getStart()), true);
    enumValue.addKeyValue(Lists.immutable.of("Root", "children", "meta", "children", "pure", "children", "metamodel", "children", "type", "children", "Enum", "properties", "name"), this.repository.newStringCoreInstance_cached(ctx.identifier().getText()));
    if (stereotypes != null) {
        enumValue.setKeyValues(Lists.immutable.of("Root", "children", "meta", "children", "pure", "children", "metamodel", "children", "extension", "children", "ElementWithStereotypes", "properties", "stereotypes"), Lists.mutable.withAll(stereotypes));
    }
    if (tags != null) {
        enumValue.setKeyValues(Lists.immutable.of("Root", "children", "meta", "children", "pure", "children", "metamodel", "children", "extension", "children", "ElementWithTaggedValues", "properties", "taggedValues"), Lists.mutable.<CoreInstance>withAll(tags));
    }
    return enumValue;
}
Also used : TaggedValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue) PrimitiveCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance)

Example 3 with ElementWithStereotypes

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

the class AccessLevelValidator method run.

@Override
public void run(CoreInstance instance, MatcherState state, Matcher matcher, ModelRepository repository, Context context) throws PureCompilationException {
    ElementWithStereotypes elementWithStereotypes = ElementWithStereotypesCoreInstanceWrapper.toElementWithStereotypes(instance);
    ProcessorSupport processorSupport = state.getProcessorSupport();
    ListIterable<Stereotype> stereotypes = AccessLevel.getAccessLevelStereotypes(elementWithStereotypes, processorSupport);
    switch(stereotypes.size()) {
        case 0:
            {
                // Do nothing
                break;
            }
        case 1:
            {
                this.validateExplicitAccessLevel(elementWithStereotypes, AccessLevel.getAccessLevel(elementWithStereotypes, context, processorSupport), processorSupport);
                break;
            }
        default:
            {
                StringBuilder message = new StringBuilder();
                if (Instance.instanceOf(instance, M3Paths.Function, processorSupport)) {
                    FunctionDescriptor.writeFunctionDescriptor(message, instance, processorSupport);
                } else {
                    org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.writeUserPathForPackageableElement(message, instance);
                }
                message.append(" has multiple access level stereotypes");
                throw new PureCompilationException(instance.getSourceInformation(), message.toString());
            }
    }
}
Also used : ElementWithStereotypes(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.ElementWithStereotypes) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) Stereotype(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 4 with ElementWithStereotypes

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

the class AccessLevelValidator method validateExplicitAccessLevel.

private void validateExplicitAccessLevel(ElementWithStereotypes instance, AccessLevel accessLevel, ProcessorSupport processorSupport) {
    if (accessLevel == AccessLevel.EXTERNALIZABLE) {
        // Validate that instance is a non-property concrete function definition
        if (!(instance instanceof ConcreteFunctionDefinition) || instance instanceof AbstractProperty) {
            throw new PureCompilationException(instance.getSourceInformation(), "Only functions may have an access level of " + accessLevel.getName());
        }
        // Validate that the function has a name and package
        String functionName = ((ConcreteFunctionDefinition) instance)._functionName();
        if (functionName == null) {
            throw new PureCompilationException(instance.getSourceInformation(), "Functions with access level " + accessLevel.getName() + " must have a function name");
        }
        if (((ConcreteFunctionDefinition) instance)._package() == null) {
            throw new PureCompilationException(instance.getSourceInformation(), "Functions with access level " + accessLevel.getName() + " must have a package");
        }
        // Validate parameter types and multiplicities
        FunctionType functionType = (FunctionType) processorSupport.function_getFunctionType(instance);
        int i = 1;
        for (VariableExpression parameter : functionType._parameters()) {
            GenericType genericType = parameter._genericType();
            CoreInstance rawType = ImportStub.withImportStubByPass(genericType._rawTypeCoreInstance(), processorSupport);
            if (!(rawType instanceof PrimitiveType || M3Paths.Map.equals(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(rawType)))) {
                StringBuilder message = new StringBuilder("Functions with access level ");
                message.append(accessLevel.getName());
                message.append(" may only have primitive types or 'Maps' as parameter types; found ");
                org.finos.legend.pure.m3.navigation.generictype.GenericType.print(message, genericType, processorSupport);
                message.append(" for the type of parameter ");
                String name = parameter._name();
                if (name.isEmpty()) {
                    message.append(i);
                } else {
                    message.append("'");
                    message.append(name);
                    message.append("'");
                }
                throw new PureCompilationException(instance.getSourceInformation(), message.toString());
            }
            Multiplicity multiplicity = parameter._multiplicity();
            if (!org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.isToOne(multiplicity, false) && !org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.isZeroToMany(multiplicity)) {
                StringBuilder message = new StringBuilder("Functions with access level ");
                message.append(accessLevel.getName());
                message.append(" may only have parameters with multiplicity 0..1, 1, or *; found ");
                org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.print(message, multiplicity, false);
                message.append(" for the multiplicity of parameter ");
                String name = PrimitiveUtilities.getStringValue(parameter.getValueForMetaPropertyToOne(M3Properties.name));
                if (name.isEmpty()) {
                    message.append(i);
                } else {
                    message.append("'");
                    message.append(name);
                    message.append("'");
                }
                throw new PureCompilationException(instance.getSourceInformation(), message.toString());
            }
            i++;
        }
        // Validate return type and multiplicity
        GenericType returnType = functionType._returnType();
        CoreInstance returnRawType = ImportStub.withImportStubByPass(returnType._rawTypeCoreInstance(), processorSupport);
        if ((returnRawType == null) || !(returnRawType instanceof PrimitiveType)) {
            StringBuilder message = new StringBuilder("Functions with access level ").append(accessLevel.getName()).append(" may only have primitive types as return types; found ");
            org.finos.legend.pure.m3.navigation.generictype.GenericType.print(message, returnType, processorSupport);
            throw new PureCompilationException(instance.getSourceInformation(), message.toString());
        }
        // Validate no function name conflict
        Stereotype stereotype = (Stereotype) accessLevel.getStereotype(processorSupport);
        ListIterable<? extends CoreInstance> functionsWithSameName = stereotype.getValueInValueForMetaPropertyToManyByIndex(M3Properties.modelElements, IndexSpecifications.getPropertyValueNameIndexSpec(M3Properties.functionName), functionName);
        if (functionsWithSameName.size() > 1) {
            StringBuilder message = new StringBuilder("Externalizable function name conflict - multiple functions with the name '");
            message.append(functionName).append("':");
            for (CoreInstance func : functionsWithSameName.toSortedListBy(CoreInstance::getSourceInformation)) {
                FunctionDescriptor.writeFunctionDescriptor(message.append("\n\t"), func, processorSupport);
                func.getSourceInformation().appendMessage(message.append(" (")).append(')');
            }
            throw new PureCompilationException(instance.getSourceInformation(), message.toString());
        }
    } else {
        // Check that instance is either a class or a non-property function
        if (instance instanceof AbstractProperty || !(instance instanceof Function || instance instanceof Class)) {
            throw new PureCompilationException(instance.getSourceInformation(), "Only classes and functions may have an access level");
        }
    }
    // Check that instance has a package
    if (((PackageableElement) instance)._package() == null) {
        throw new PureCompilationException(instance.getSourceInformation(), "Element '" + instance + "' has an access level but no package");
    }
}
Also used : ConcreteFunctionDefinition(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinition) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Stereotype(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) Function(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.Function) Multiplicity(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) PrimitiveType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 5 with ElementWithStereotypes

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

the class ElementWithStereotypesValidator method run.

@Override
public void run(CoreInstance instanceValue, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    ElementWithStereotypes elementWithStereotypes = ElementWithStereotypesCoreInstanceWrapper.toElementWithStereotypes(instanceValue);
    ImportStub.withImportStubByPasses(elementWithStereotypes._stereotypesCoreInstance().toList(), state.getProcessorSupport());
}
Also used : ElementWithStereotypes(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.ElementWithStereotypes)

Aggregations

ElementWithStereotypes (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.ElementWithStereotypes)4 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)4 Stereotype (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Stereotype)3 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)3 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)2 ImportStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub)1 TaggedValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.TaggedValue)1 ConcreteFunctionDefinition (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinition)1 Function (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.Function)1 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)1 Multiplicity (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity)1 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)1 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)1 PrimitiveType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType)1 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)1 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)1 PrimitiveCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance)1