use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement in project legend-pure by finos.
the class NavigationGraphBuilder method visitPropertyWithParametersBlock.
private void visitPropertyWithParametersBlock(PropertyWithParametersContext ctx, MutableList<PathElement> props, Token firstChar) {
MutableList<ValueSpecification> parameters = FastList.newList();
Token property = ctx.VALID_STRING().getSymbol();
ClassInstance ppeType = (ClassInstance) this.processorSupport.package_getByUserPath(M3Paths.PropertyPathElement);
PropertyPathElement propertyPathElement = (PropertyPathElement) this.repository.newAnonymousCoreInstance(this.sourceInformation.getPureSourceInformation(property), ppeType, true);
GenericType classifierGT = GenericTypeInstance.createPersistent(this.repository);
classifierGT._rawTypeCoreInstance(ppeType);
propertyPathElement._classifierGenericType(classifierGT);
PropertyStub propStub = PropertyStubInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(property), null, property.getText());
propertyPathElement._propertyCoreInstance(propStub);
if (ctx.parameter() != null) {
for (ParameterContext parameterContext : ctx.parameter()) {
parameters.add(visitParameterBlock(parameterContext));
}
}
if (!parameters.isEmpty()) {
propertyPathElement._parameters(parameters);
}
props.add(propertyPathElement);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement in project legend-pure by finos.
the class Pure method findSharedPureFunction.
public static SharedPureFunction<?> findSharedPureFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.Function<?> func, Bridge bridge, ExecutionSupport es) {
if (func instanceof Property) {
Type srcType = func._classifierGenericType()._typeArguments().getFirst()._rawType();
return ((CompiledExecutionSupport) es).getFunctionCache().getIfAbsentPutFunctionForClassProperty(srcType, func, ((CompiledExecutionSupport) es).getClassLoader());
}
if (func instanceof Path) {
return new PureFunction1<Object, Object>() {
@Override
public Object execute(ListIterable vars, ExecutionSupport es) {
return value(vars.getFirst(), es);
}
@Override
public Object value(Object o, ExecutionSupport es) {
RichIterable<?> result = ((Path<?, ?>) func)._path().injectInto(CompiledSupport.toPureCollection(o), (mutableList, path) -> {
if (!(path instanceof PropertyPathElement)) {
throw new PureExecutionException("Only PropertyPathElement is supported yet!");
}
return mutableList.flatCollect(instance -> {
MutableList<Object> parameters = ((PropertyPathElement) path)._parameters().collect(o1 -> o1 instanceof InstanceValue ? ((InstanceValue) o1)._values() : null, Lists.mutable.with(instance));
return CompiledSupport.toPureCollection(evaluate(es, ((PropertyPathElement) path)._property(), bridge, parameters.toArray()));
});
});
Multiplicity mult = func._classifierGenericType()._multiplicityArguments().getFirst();
return bridge.hasToOneUpperBound().apply(mult, es) ? result.getFirst() : result;
}
};
}
if (func instanceof LambdaCompiledExtended) {
return ((LambdaCompiledExtended) func).pureFunction();
}
if (func instanceof LambdaFunction) {
LambdaFunction<?> lambda = (LambdaFunction<?>) func;
if (canFindNativeOrLambdaFunction(es, func)) {
return getNativeOrLambdaFunction(es, func);
}
if (Reactivator.canReactivateWithoutJavaCompilation(lambda, es, getOpenVariables(func, bridge), bridge)) {
PureMap openVariablesMap = getOpenVariables(func, bridge);
return DynamicPureLambdaFunctionImpl.createPureLambdaFunction(lambda, openVariablesMap.getMap(), bridge);
}
return ((LambdaCompiledExtended) CompiledSupport.dynamicallyBuildLambdaFunction(func, es)).pureFunction();
}
if (func instanceof ConcreteFunctionDefinition) {
return ((CompiledExecutionSupport) es).getFunctionCache().getIfAbsentPutJavaFunctionForPureFunction(func, () -> {
try {
RichIterable<? extends VariableExpression> params = ((FunctionType) func._classifierGenericType()._typeArguments().getFirst()._rawType())._parameters();
Class<?>[] paramClasses = new Class[params.size() + 1];
int index = 0;
for (VariableExpression o : params) {
paramClasses[index] = pureTypeToJavaClassForExecution(o, bridge, es);
index++;
}
paramClasses[params.size()] = ExecutionSupport.class;
Method method = ((CompiledExecutionSupport) es).getClassLoader().loadClass(JavaPackageAndImportBuilder.rootPackage() + "." + IdBuilder.sourceToId(func.getSourceInformation())).getMethod(FunctionProcessor.functionNameToJava(func), paramClasses);
return new JavaMethodWithParamsSharedPureFunction(method, paramClasses, func.getSourceInformation());
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
MutableMap<String, SharedPureFunction<?>> functions;
try {
Class<?> myClass = ((CompiledExecutionSupport) es).getClassLoader().loadClass(JavaPackageAndImportBuilder.rootPackage() + "." + IdBuilder.sourceToId(func.getSourceInformation()));
functions = (MutableMap<String, SharedPureFunction<?>>) myClass.getDeclaredField("__functions").get(null);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
return functions.get(func.getName());
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement in project legend-pure by finos.
the class PathProcessor method process.
@Override
public void process(Path instance, ProcessorState state, Matcher matcher, ModelRepository repository, Context context, ProcessorSupport processorSupport) {
CoreInstance _class = ImportStub.withImportStubByPass(instance._start()._rawTypeCoreInstance(), processorSupport);
CoreInstance source = _class;
boolean possiblyZero = false;
boolean toMany = false;
MilestoningDates propagatedDates = state.getMilestoningDates(MilestoningDatesPropagationFunctions.PATH_MILESTONING_DATES_VARIABLE_NAME);
for (PathElement pathElement : (RichIterable<PathElement>) instance._path()) {
PostProcessor.processElement(matcher, _class, state, processorSupport);
if (pathElement instanceof PropertyPathElement) {
PropertyStub propertyStubNonResolved = (PropertyStub) ((PropertyPathElement) pathElement)._propertyCoreInstance();
propertyStubNonResolved._ownerCoreInstance(_class);
AbstractProperty property = (AbstractProperty) ImportStub.withImportStubByPass(((PropertyPathElement) pathElement)._propertyCoreInstance(), processorSupport);
FunctionType functionType = (FunctionType) processorSupport.function_getFunctionType(property);
_class = ImportStub.withImportStubByPass(functionType._returnType()._rawTypeCoreInstance(), processorSupport);
toMany = toMany || !org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.isToOne(functionType._returnMultiplicity(), false);
possiblyZero = possiblyZero || org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.isLowerZero(functionType._returnMultiplicity());
for (ValueSpecification vs : ((PropertyPathElement) pathElement)._parameters()) {
if (vs instanceof InstanceValue) {
InstanceValueProcessor.updateInstanceValue(vs, processorSupport);
}
}
propagatedDates = processMilestoningQualifiedProperty(_class, state, propagatedDates, (PropertyPathElement) pathElement, propertyStubNonResolved, property, repository, processorSupport);
}
}
GenericType classifierGenericType = (GenericType) processorSupport.newEphemeralAnonymousCoreInstance(M3Paths.GenericType);
classifierGenericType._rawTypeCoreInstance(instance.getClassifier());
classifierGenericType._typeArgumentsAdd((GenericType) Type.wrapGenericType(source, processorSupport));
classifierGenericType._typeArgumentsAdd((GenericType) Type.wrapGenericType(_class, processorSupport));
CoreInstance multiplicity = null;
if (possiblyZero && !toMany) {
multiplicity = processorSupport.package_getByUserPath(M3Paths.ZeroOne);
}
if (possiblyZero && toMany) {
multiplicity = processorSupport.package_getByUserPath(M3Paths.ZeroMany);
}
if (!possiblyZero && toMany) {
multiplicity = processorSupport.package_getByUserPath(M3Paths.OneMany);
}
if (!possiblyZero && !toMany) {
multiplicity = processorSupport.package_getByUserPath(M3Paths.PureOne);
}
classifierGenericType._multiplicityArgumentsAdd((Multiplicity) multiplicity);
instance._classifierGenericType(classifierGenericType);
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement in project legend-pure by finos.
the class PathProcessor method processMilestoningQualifiedProperty.
private MilestoningDates processMilestoningQualifiedProperty(CoreInstance _class, ProcessorState state, MilestoningDates propagatedDates, PropertyPathElement pathElement, PropertyStub propertyStubNonResolved, AbstractProperty property, ModelRepository repository, ProcessorSupport processorSupport) {
if (MilestoningFunctions.isGeneratedQualifiedProperty(property, processorSupport)) {
MilestoningStereotype milestoningStereotype = MilestoningFunctions.getTemporalStereoTypesFromTopMostNonTopTypeGeneralizations(_class, processorSupport).getFirst();
CoreInstance milestonedPropertyWithArg = MilestoningDatesPropagationFunctions.getMatchingMilestoningQualifiedPropertyWithDateArg(property, property._functionName(), processorSupport);
propertyStubNonResolved._resolvedPropertyCoreInstance(milestonedPropertyWithArg);
if (milestoningStereotype == MilestoningStereotypeEnum.businesstemporal) {
if (pathElement._parameters().isEmpty()) {
if (propagatedDates != null) {
pathElement._parameters(Lists.fixedSize.of((ValueSpecification) propagatedDates.getBusinessDate()));
} else {
throwMilestoningPropertyPathValidationException(property, pathElement.getSourceInformation(), processorSupport);
}
} else {
ValueSpecification businessDate = pathElement._parameters().getFirst();
propagatedDates = new MilestoningDates(businessDate, null);
}
}
} else {
propagatedDates = null;
}
return propagatedDates;
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement in project legend-pure by finos.
the class PathProcessor method populateReferenceUsages.
@Override
public void populateReferenceUsages(Path path, ModelRepository repository, ProcessorSupport processorSupport) {
GenericTypeTraceability.addTraceForPath(path, repository, processorSupport);
int i = 0;
for (PathElement pathElement : (RichIterable<PathElement>) path._path()) {
if (pathElement instanceof PropertyPathElement) {
AbstractProperty property = (AbstractProperty) ImportStub.withImportStubByPass(((PropertyPathElement) pathElement)._propertyCoreInstance(), processorSupport);
this.addReferenceUsage(path, property, "path", i, repository, processorSupport, pathElement.getSourceInformation());
}
i++;
}
}
Aggregations