use of org.finos.legend.pure.m3.navigation._class._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.navigation._class._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;
}
use of org.finos.legend.pure.m3.navigation._class._Class in project legend-pure by finos.
the class FunctionExpressionMatcher method getFunctionsWithMatchingName.
private static RichIterable<Function<?>> getFunctionsWithMatchingName(String functionName, ListIterable<String> functionPackage, FunctionExpression functionExpression, ProcessorSupport processorSupport) {
SetIterable<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement> packages = getValidPackages(functionPackage, functionExpression, processorSupport);
MutableList<Function<?>> functions = Lists.mutable.empty();
for (CoreInstance function : processorSupport.function_getFunctionsForName(functionName)) {
if (packages.contains(((Function<?>) function)._package())) {
functions.add((Function<?>) function);
}
}
return functions;
}
use of org.finos.legend.pure.m3.navigation._class._Class in project legend-pure by finos.
the class CompiledProcessorSupport method valueSpecification_instanceOf.
@Override
public boolean valueSpecification_instanceOf(CoreInstance valueSpecification, String type) {
try {
ValueSpecification valueSpec = ValueSpecificationCoreInstanceWrapper.toValueSpecification(valueSpecification);
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type rawType = valueSpec._genericType()._rawType();
Class<?> valueSpecType = (rawType instanceof Enumeration) ? this.globalClassLoader.loadClass(FullJavaPaths.Enum) : this.pureClassToJavaClass(fullName(rawType));
Class<?> typeCl = this.pureClassToJavaClass(type);
return typeCl.isAssignableFrom(valueSpecType);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
use of org.finos.legend.pure.m3.navigation._class._Class in project legend-pure by finos.
the class FunctionExecutionCompiled method executeFunction.
private Object executeFunction(CoreInstance functionDefinition, ListIterable<? extends CoreInstance> arguments, CompiledExecutionSupport executionSupport) {
ProcessorSupport processorSupport = new M3ProcessorSupport(this.context, this.repository);
Object result;
try {
result = this.executeFunction(functionDefinition, arguments, executionSupport, this.javaCompilerEventHandler.getJavaCompiler().getClassLoader(), processorSupport);
} catch (PureException pe) {
// Rethrow as is to keep the original error
throw pe;
} catch (Exception e) {
StringBuilder builder = new StringBuilder("Error executing ");
try {
org.finos.legend.pure.m3.navigation.function.Function.print(builder, functionDefinition, processorSupport);
} catch (Exception ignore) {
builder = new StringBuilder("Error executing ");
builder.append(functionDefinition);
}
builder.append(". ");
if (e.getMessage() != null) {
builder.append(e.getMessage());
}
throw new RuntimeException(builder.toString(), e);
}
if (result == null) {
result = Lists.immutable.empty();
}
return result;
}
Aggregations