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