Search in sources :

Example 1 with Class

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class in project legend-pure by finos.

the class AssociationProcessor method updateClassifierGenericTypeForQualifiedPropertiesThisVarExprParams.

private static void updateClassifierGenericTypeForQualifiedPropertiesThisVarExprParams(Association association, QualifiedProperty qualifiedProperty, final Class qualifiedPropertyReturnType, ListIterable<? extends Property> assnProperties, final Context context, final ProcessorSupport processorSupport) {
    validateQualifiedPropertyLeftSideOfFilterByPropertyName(association, qualifiedProperty, qualifiedPropertyReturnType, assnProperties, context, processorSupport);
    Property leftSideOfFilterProperty = getQualifiedPropertiesFilterLeftSideParam(qualifiedPropertyReturnType, assnProperties, processorSupport);
    Property leftSideOfFilterOtherProperty = assnProperties.detect(Predicates.notEqual(leftSideOfFilterProperty));
    GenericType leftSideOfFilterOtherPropertyGenericType = leftSideOfFilterOtherProperty._genericType();
    FunctionType functionType = (FunctionType) qualifiedProperty._classifierGenericType()._typeArguments().toList().getFirst()._rawTypeCoreInstance();
    Iterable<? extends VariableExpression> functionTypeParams = functionType._parameters();
    for (VariableExpression functionTypeParam : functionTypeParams) {
        if (functionTypeParam != null && "this".equals(functionTypeParam._name())) {
            GenericType genericTypeCopy = (GenericType) org.finos.legend.pure.m3.navigation.generictype.GenericType.copyGenericType(leftSideOfFilterOtherPropertyGenericType, processorSupport);
            functionTypeParam._genericType(genericTypeCopy);
            context.update(functionTypeParam);
            if (functionTypeParam.hasBeenValidated()) {
                functionTypeParam.markNotValidated();
                context.update(functionTypeParam);
            }
        }
    }
}
Also used : 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) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)

Example 2 with Class

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class in project legend-pure by finos.

the class AssociationProcessor method processAssociationQualifiedProperty_internal.

private static void processAssociationQualifiedProperty_internal(Association association, QualifiedProperty qualifiedProperty, Class sourceRawType, Context context, ProcessorSupport processorSupport) {
    addQualifiedPropertyToRawType(qualifiedProperty, sourceRawType, context);
    Class qualifiedPropertyReturnType = (Class) ImportStub.withImportStubByPass(qualifiedProperty._genericType()._rawTypeCoreInstance(), processorSupport);
    ListIterable<? extends Property<?, ?>> assnProperties = association._properties().toList();
    updateClassifierGenericTypeForQualifiedPropertiesThisVarExprParams(association, qualifiedProperty, qualifiedPropertyReturnType, assnProperties, context, processorSupport);
    context.update(qualifiedProperty);
}
Also used : Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)

Example 3 with Class

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class in project legend-pure by finos.

the class AssociationProcessor method processNonMilestonedQualifiedProperties.

private static void processNonMilestonedQualifiedProperties(Association association, Class leftRawType, Class rightRawType, Context context, ProcessorSupport processorSupport) {
    RichIterable<? extends QualifiedProperty> qualifiedProperties = association._qualifiedProperties();
    if (qualifiedProperties.notEmpty()) {
        SetIterable<? extends Class> validReturnTypes = Sets.immutable.with(leftRawType, rightRawType);
        ListIterable<? extends Property<?, ?>> assnProperties = association._properties().toList();
        for (QualifiedProperty qualifiedProperty : qualifiedProperties) {
            Class qualifiedPropertyReturnType = (Class) ImportStub.withImportStubByPass(qualifiedProperty._genericType()._rawTypeCoreInstance(), processorSupport);
            validateQualifiedPropertyReturnType(association, qualifiedProperty, qualifiedPropertyReturnType, validReturnTypes);
            Class sourceType = (leftRawType == qualifiedPropertyReturnType) ? rightRawType : leftRawType;
            addQualifiedPropertyToRawType(qualifiedProperty, sourceType, context);
            updateClassifierGenericTypeForQualifiedPropertiesThisVarExprParams(association, qualifiedProperty, qualifiedPropertyReturnType, assnProperties, context, processorSupport);
            context.update(qualifiedProperty);
        }
    }
}
Also used : Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)

Example 4 with Class

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class in project legend-pure by finos.

the class AssociationProcessor method processAssociationProperty.

private static ListIterable<AbstractProperty<?>> processAssociationProperty(Association association, Property property, GenericType sourceGenericType, Class sourceRawType, ModelRepository modelRepository, Context context, ProcessorSupport processorSupport) {
    GeneratedMilestonedProperties generatedMilestonedProperties = MilestoningPropertyProcessor.processAssociationProperty(association, sourceRawType, property, context, processorSupport, modelRepository);
    if (generatedMilestonedProperties.hasGeneratedProperties()) {
        processOriginalMilestonedProperty(association, property, sourceGenericType, context, processorSupport);
        Property edgePointProperty = (Property) generatedMilestonedProperties.getEdgePointProperty();
        processAssociationProperty_internal(edgePointProperty, sourceGenericType, sourceRawType, context);
        for (CoreInstance qualifiedProperty : generatedMilestonedProperties.getQualifiedProperties()) {
            processAssociationQualifiedProperty_internal(association, (QualifiedProperty) qualifiedProperty, sourceRawType, context, processorSupport);
        }
        if (association.hasBeenValidated()) {
            association.markNotValidated();
        }
        return generatedMilestonedProperties.getAllGeneratedProperties();
    } else {
        processAssociationProperty_internal(property, sourceGenericType, sourceRawType, context);
        return Lists.immutable.empty();
    }
}
Also used : CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) GeneratedMilestonedProperties(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.GeneratedMilestonedProperties) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)

Example 5 with Class

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class in project legend-pure by finos.

the class M3ToJavaGenerator method createWrapperClass.

private String createWrapperClass(final CoreInstance instance, String javaPackage, MutableSet<CoreInstance> properties, MutableSet<CoreInstance> propertiesFromAssociations, MutableSet<CoreInstance> qualifiedProperties, Imports imports, MutableMap<String, CoreInstance> propertyOwners) {
    imports.addImports(Lists.mutable.of("org.finos.legend.pure.m4.coreinstance.simple.ValueHolder", "org.finos.legend.pure.m3.coreinstance.helper.PrimitiveHelper"));
    final String interfaceName = getInterfaceName(instance);
    String wrapperName = getWrapperName(instance);
    String typeParamsWithExtendsCoreInstance = getTypeParams(instance, true);
    final CoreInstance classGenericType = getClassGenericType(instance);
    imports.setThisClassName(wrapperName);
    PartitionIterable<CoreInstance> partition = properties.partition(M3ToJavaGenerator::isToOne);
    RichIterable<CoreInstance> toOneProperties = partition.getSelected();
    RichIterable<CoreInstance> toManyProperties = partition.getRejected();
    RichIterable<CoreInstance> mandatoryToOneProps = toOneProperties.select(M3ToJavaGenerator::isMandatoryProperty);
    RichIterable<Pair<String, String>> typesForMandatoryProps = buildMandatoryProperties(classGenericType, mandatoryToOneProps, imports).toSortedSetBy(Pair::getOne);
    MutableList<String> mandatoryTypes = Lists.mutable.of();
    MutableList<String> mandatoryProps = Lists.mutable.of();
    for (Pair<String, String> pair : typesForMandatoryProps) {
        mandatoryTypes.add(pair.getTwo() + " " + pair.getOne());
        mandatoryProps.add(pair.getOne());
    }
    final String maybeFullyQualifiedInterfaceName = (imports.shouldFullyQualify(javaPackage + "." + interfaceName) ? javaPackage + "." + interfaceName : interfaceName);
    String maybeFullyQualifiedInterfaceNameWithTypeParams = maybeFullyQualifiedInterfaceName + typeParamsWithExtendsCoreInstance;
    String systemPathForPackageableElement = getUserObjectPathForPackageableElement(instance, true).makeString("::");
    String value = "\n" + "package " + javaPackage + ";\n" + "\n" + "import org.eclipse.collections.api.RichIterable;\n" + "import org.eclipse.collections.api.block.predicate.Predicate;\n" + "import org.eclipse.collections.api.list.ListIterable;\n" + "import org.eclipse.collections.api.list.MutableList;\n" + "import org.eclipse.collections.api.set.SetIterable;\n" + "import org.eclipse.collections.impl.factory.Lists;\n" + "import org.eclipse.collections.impl.factory.Sets;\n" + "import org.finos.legend.pure.m3.coreinstance.BaseCoreInstance;\n" + "import org.finos.legend.pure.m4.coreinstance.AbstractCoreInstanceWrapper;\n" + "import org.finos.legend.pure.m3.coreinstance.BaseM3CoreInstanceFactory;\n" + "import org.finos.legend.pure.m4.coreinstance.AbstractCoreInstance;\n" + imports.toImportString() + "\n" + getPrimitiveImports() + "\n" + "import org.finos.legend.pure.m4.coreinstance.CoreInstance;\n" + "\n" + "public class " + wrapperName + " extends AbstractCoreInstanceWrapper implements " + maybeFullyQualifiedInterfaceNameWithTypeParams + "\n" + "{\n" + "    public static final CoreInstanceFunction FROM_CORE_INSTANCE_FN = new CoreInstanceFunction();\n" + "    public " + wrapperName + "(CoreInstance instance)\n" + "    {\n" + "        super(instance);\n" + "    }\n" + "\n" + toOneProperties.collect(property -> {
        CoreInstance propertyReturnGenericType = this.propertyTypeResolver.getPropertyReturnType(classGenericType, property);
        return createWrapperPropertyGetterToOne(interfaceName, property, propertyReturnGenericType, imports);
    }).makeString("") + toManyProperties.collect(property -> {
        CoreInstance propertyReturnGenericType = this.propertyTypeResolver.getPropertyReturnType(classGenericType, property);
        return createWrapperPropertyGetterToMany(interfaceName, property, propertyReturnGenericType, imports);
    }).makeString("") + "\n" + toOneProperties.collect(property -> {
        CoreInstance propertyReturnGenericType = this.propertyTypeResolver.getPropertyReturnType(classGenericType, property);
        String sub = getSubstituteType(property, propertyReturnGenericType);
        return sub == null ? "" : "    public " + maybeFullyQualifiedInterfaceName + " " + getUnifiedMethodName(property) + "(" + sub + " value)\n" + "    {\n" + "        instance.setKeyValues(" + createPropertyKeyNameReference(property.getName(), propertyOwners.get(property.getName()), instance) + ", Lists.immutable.<CoreInstance>with((CoreInstance)value));\n" + "        return this;\n" + "    }\n" + "\n";
    }).makeString("") + properties.collect(property -> {
        CoreInstance propertyReturnGenericType = this.propertyTypeResolver.getPropertyReturnType(classGenericType, property);
        return createWrapperPropertySetter(property, propertyReturnGenericType, imports, maybeFullyQualifiedInterfaceName, propertyOwners, instance);
    }).makeString("") + propertiesFromAssociations.collect(property -> {
        CoreInstance propertyReturnGenericType = this.propertyTypeResolver.getPropertyReturnType(classGenericType, property);
        return createPropertyReverse(property, propertyReturnGenericType, imports, false, true) + createPropertyReverse(property, propertyReturnGenericType, imports, true, true);
    }).makeString("") + qualifiedProperties.collect(property -> {
        CoreInstance propertyReturnGenericType = this.propertyTypeResolver.getPropertyReturnType(classGenericType, property);
        return createWrapperQualifiedPropertyGetter(property, propertyReturnGenericType, imports);
    }).makeString("") + "\n" + "    public static " + maybeFullyQualifiedInterfaceName + " to" + interfaceName + "(CoreInstance instance)\n" + "    {\n" + "        if (instance == null) { return null; }\n" + "        return " + maybeFullyQualifiedInterfaceName + ".class.isInstance(instance) ? (" + maybeFullyQualifiedInterfaceName + ") instance : new " + wrapperName + "(instance);\n" + "    }\n" + createWrapperStaticConversionFunction(interfaceName, wrapperName, maybeFullyQualifiedInterfaceNameWithTypeParams, getTypeParams(instance, false)) + createWrapperClassCopyMethod(instance, maybeFullyQualifiedInterfaceName) + createClassPackageableElement(systemPathForPackageableElement) + "}\n";
    return value;
}
Also used : ArrayAdapter(org.eclipse.collections.impl.list.fixed.ArrayAdapter) Lists(org.eclipse.collections.api.factory.Lists) SetIterable(org.eclipse.collections.api.set.SetIterable) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) Maps(org.eclipse.collections.api.factory.Maps) MutableSet(org.eclipse.collections.api.set.MutableSet) RichIterable(org.eclipse.collections.api.RichIterable) MutableMap(org.eclipse.collections.api.map.MutableMap) Map(java.util.Map) Tuples(org.eclipse.collections.impl.tuple.Tuples) Pair(org.eclipse.collections.api.tuple.Pair) StringIterate(org.eclipse.collections.impl.utility.StringIterate) Path(java.nio.file.Path) Sets(org.eclipse.collections.api.factory.Sets) JavaTools(org.finos.legend.pure.m3.tools.JavaTools) ArrayIterate(org.eclipse.collections.impl.utility.ArrayIterate) ModelRepository(org.finos.legend.pure.m4.ModelRepository) Files(java.nio.file.Files) Collection(java.util.Collection) IOException(java.io.IOException) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) Paths(java.nio.file.Paths) ListIterable(org.eclipse.collections.api.list.ListIterable) MapIterable(org.eclipse.collections.api.map.MapIterable) PartitionIterable(org.eclipse.collections.api.partition.PartitionIterable) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Pair(org.eclipse.collections.api.tuple.Pair)

Aggregations

Test (org.junit.Test)160 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)104 M3AntlrParser (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser)53 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)53 RuntimeTestScriptBuilder (org.finos.legend.pure.m3.RuntimeTestScriptBuilder)46 ParserLibrary (org.finos.legend.pure.m3.serialization.grammar.ParserLibrary)45 RelationalParser (org.finos.legend.pure.m2.relational.serialization.grammar.v1.RelationalParser)44 PureExecutionException (org.finos.legend.pure.m3.exception.PureExecutionException)44 MappingParser (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.MappingParser)43 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)42 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)37 RichIterable (org.eclipse.collections.api.RichIterable)31 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)31 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)28 PureParserException (org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException)26 QualifiedProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty)22 MutableList (org.eclipse.collections.api.list.MutableList)20 SetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation)20 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)20 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)20