Search in sources :

Example 11 with MissingVariableException

use of org.whole.lang.visitors.MissingVariableException in project whole by wholeplatform.

the class WorkflowsDynamicCompilerVisitor method visit.

@Override
public void visit(InvokeJavaInstanceMethod entity) {
    final Variable resultVariable = entity.getResult();
    final Variable instanceVariable = entity.getObject();
    Expressions arguments = entity.getArguments();
    int size = arguments.wSize();
    IEntityIterator<?>[] runnableIterators = new IEntityIterator<?>[2 + size];
    entity.getClassName().accept(this);
    runnableIterators[0] = getResultIterator();
    entity.getMethod().accept(this);
    runnableIterators[1] = getResultIterator();
    for (int i = 0; i < size; i++) {
        arguments.get(i).accept(this);
        runnableIterators[2 + i] = getResultIterator();
    }
    setResultIterator(IteratorFactory.multiValuedRunnableIterator(new AbstractWorkflowsRunnable() {

        public void run(IEntity selfEntity, IBindingManager bm, IEntity... argsEntities) {
            String className = argsEntities[0].wStringValue();
            IEntity methodData = argsEntities[1];
            Method method;
            if (DataTypeUtils.getDataKind(methodData).isString())
                method = JavaReflectUtils.getMethod(className, methodData.wStringValue(), ReflectionFactory.getClassLoader(bm));
            else
                method = (Method) methodData.wGetValue();
            IEntity instanceEntity = bm.wGet(instanceVariable.getValue());
            if (instanceEntity == null)
                throw new MissingVariableException(instanceVariable.getValue()).withSourceEntity(getSourceEntity()).withBindings(getBindings());
            Object instance = DataTypeUtils.unbox(instanceEntity, method.getDeclaringClass(), false);
            Object[] arguments = toArguments(method.getParameterTypes(), method.isVarArgs(), argsEntities);
            Object resultValue = JavaReflectUtils.invokeMethod(instance, method, arguments);
            setResult(bm, resultVariable, resultValue, method.getReturnType());
        }
    }, runnableIterators).withSourceEntity(entity));
}
Also used : Variable(org.whole.lang.workflows.model.Variable) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Expressions(org.whole.lang.workflows.model.Expressions) InvokeJavaClassMethod(org.whole.lang.workflows.model.InvokeJavaClassMethod) InvokeJavaInstanceMethod(org.whole.lang.workflows.model.InvokeJavaInstanceMethod) Method(java.lang.reflect.Method) IEntityIterator(org.whole.lang.iterators.IEntityIterator) MissingVariableException(org.whole.lang.visitors.MissingVariableException)

Example 12 with MissingVariableException

use of org.whole.lang.visitors.MissingVariableException in project whole by wholeplatform.

the class ImpInterpreterVisitor method visit.

public void visit(NameExpression entity) {
    IEntity value = getBindings().wGet(entity.getValue());
    if (value == null)
        throw new MissingVariableException(entity.getValue()).withSourceEntity(entity).withBindings(getBindings());
    setLiteral(value);
}
Also used : IEntity(org.whole.lang.model.IEntity) MissingVariableException(org.whole.lang.visitors.MissingVariableException)

Aggregations

IEntity (org.whole.lang.model.IEntity)12 MissingVariableException (org.whole.lang.visitors.MissingVariableException)12 IBindingManager (org.whole.lang.bindings.IBindingManager)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 NoSuchElementException (java.util.NoSuchElementException)1 TreeSet (java.util.TreeSet)1 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)1 ActionsEntityFactory (org.whole.lang.actions.factories.ActionsEntityFactory)1 ActionCall (org.whole.lang.actions.model.ActionCall)1 ITransactionScope (org.whole.lang.bindings.ITransactionScope)1 Variable (org.whole.lang.commons.model.Variable)1 EnvironmentEntityFactory (org.whole.lang.environment.factories.EnvironmentEntityFactory)1 WholeIllegalStateException (org.whole.lang.exceptions.WholeIllegalStateException)1 IEntityIterator (org.whole.lang.iterators.IEntityIterator)1 SubstituteException (org.whole.lang.matchers.SubstituteException)1 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)1 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)1 IVisitor (org.whole.lang.visitors.IVisitor)1 VisitException (org.whole.lang.visitors.VisitException)1