Search in sources :

Example 1 with PropertyPathElement

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);
}
Also used : PropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) Token(org.antlr.v4.runtime.Token) ParameterContext(org.finos.legend.pure.m3.inlinedsl.path.serialization.grammar.NavigationParser.ParameterContext) ClassInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassInstance) PropertyPathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement)

Example 2 with 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());
}
Also used : ConcreteFunctionDefinition(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinition) JavaMethodWithParamsSharedPureFunction(org.finos.legend.pure.runtime.java.compiled.metadata.JavaMethodWithParamsSharedPureFunction) SharedPureFunction(org.finos.legend.pure.runtime.java.compiled.generation.processors.support.function.SharedPureFunction) JavaMethodWithParamsSharedPureFunction(org.finos.legend.pure.runtime.java.compiled.metadata.JavaMethodWithParamsSharedPureFunction) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) Multiplicity(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity) CompiledExecutionSupport(org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport) ExecutionSupport(org.finos.legend.pure.m3.execution.ExecutionSupport) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) PropertyPathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement) Path(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.Path) PureFunction1(org.finos.legend.pure.runtime.java.compiled.generation.processors.support.function.PureFunction1) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) PureLambdaFunction(org.finos.legend.pure.runtime.java.compiled.generation.processors.support.function.PureLambdaFunction) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) PureMap(org.finos.legend.pure.runtime.java.compiled.generation.processors.support.map.PureMap) Method(java.lang.reflect.Method) PureDynamicReactivateException(org.finos.legend.pure.runtime.java.compiled.compiler.PureDynamicReactivateException) TimeoutException(java.util.concurrent.TimeoutException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) ListIterable(org.eclipse.collections.api.list.ListIterable) PrimitiveType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType) GenericType(org.finos.legend.pure.m3.navigation.generictype.GenericType) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) HashType(org.finos.legend.pure.runtime.java.shared.hash.HashType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) CompiledExecutionSupport(org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport) JSONObject(org.json.simple.JSONObject)

Example 3 with PropertyPathElement

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);
}
Also used : RichIterable(org.eclipse.collections.api.RichIterable) PropertyStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) PathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PathElement) PropertyPathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) PropertyPathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement) MilestoningDates(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningDates)

Example 4 with PropertyPathElement

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;
}
Also used : MilestoningStereotype(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningStereotype) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) MilestoningDates(org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningDates)

Example 5 with PropertyPathElement

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++;
    }
}
Also used : RichIterable(org.eclipse.collections.api.RichIterable) PathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PathElement) PropertyPathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) PropertyPathElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement)

Aggregations

PropertyPathElement (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement)6 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)6 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)5 RichIterable (org.eclipse.collections.api.RichIterable)4 PathElement (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PathElement)4 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)4 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)4 PropertyStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.PropertyStub)3 AbstractProperty (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty)3 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)3 MilestoningDates (org.finos.legend.pure.m3.compiler.postprocessing.processor.milestoning.MilestoningDates)2 Multiplicity (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity)2 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)2 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)2 Method (java.lang.reflect.Method)1 TimeoutException (java.util.concurrent.TimeoutException)1 Token (org.antlr.v4.runtime.Token)1 Function (org.eclipse.collections.api.block.function.Function)1 ListIterable (org.eclipse.collections.api.list.ListIterable)1 PropertyPathElement (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.path.PropertyPathElement)1