Search in sources :

Example 6 with MissingVariableException

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

the class QueriesDynamicCompilerVisitor method visitAdapter.

@Override
public boolean visitAdapter(IEntityAdapter entity) {
    IEntity adaptee = entity.wGetAdaptee(false);
    @Deprecated EntityDescriptor<?> adapteeEd = adaptee.wGetEntityDescriptor();
    if (adapteeEd.getLanguageKit().getURI().equals(CommonsLanguageKit.URI)) {
        switch(adapteeEd.getOrdinal()) {
            case CommonsEntityDescriptorEnum.Resolver_ord:
                setResultIterator(IteratorFactory.emptyIterator().withSourceEntity(adaptee));
                return false;
            case CommonsEntityDescriptorEnum.Variable_ord:
            case CommonsEntityDescriptorEnum.InlineVariable_ord:
                throw new MissingVariableException(((Variable) adaptee).getVarName().toString()).withSourceEntity(adaptee).withBindings(getBindings());
            case CommonsEntityDescriptorEnum.RootFragment_ord:
            case CommonsEntityDescriptorEnum.StageDownFragment_ord:
                setResultIterator(IteratorFactory.templateInterpreterIterator(GenericEntityFactory.instance.create(CommonsEntityDescriptorEnum.StageDownFragment, EntityUtils.clone(entity))).withSourceEntity(adaptee));
                return false;
        }
    }
    stagedVisit(adaptee, 0);
    return false;
}
Also used : Variable(org.whole.lang.commons.model.Variable) IEntity(org.whole.lang.model.IEntity) MissingVariableException(org.whole.lang.visitors.MissingVariableException)

Example 7 with MissingVariableException

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

the class SelectIterator method lookahead.

public E lookahead() {
    if (nextEntity != null)
        return nextEntity;
    IEntity selfEntityOld = getBindings().wGet("self");
    lookaheadScope().setFilterEnabled(false);
    clearLookaheadScope();
    IEntity selfEntity = getFromIterator().lookahead();
    if (selfEntity == null) {
        lookaheadScope().setFilterEnabled(true);
        return null;
    }
    getBindings().wEnterScope(lookaheadScope(), true);
    getSelectIterator().reset(selfEntity);
    lookaheadScope().wAddAll(getFromIterator().lookaheadScope());
    Set<String> filterNames = lookaheadScope().getFilterNames();
    for (String name : getFromIterator().lookaheadScope().wLocalNames()) filterNames.add(name);
    lookaheadScope().wDef("self", selfEntity);
    filterNames.add("self");
    try {
        nextEntity = getSelectIterator().next();
    } catch (NoSuchElementException e) {
        throw new WholeIllegalStateException("Select clause must return a value", e).withSourceEntity(getSourceEntity()).withBindings(getBindings());
    }
    lookaheadScope().wAddAll(getSelectIterator().lookaheadScope());
    // enable select names hidden by from iterator
    filterNames.removeAll(getSelectIterator().lookaheadScope().wLocalNames());
    applyWhereClause(nextEntity, selfEntity, getBindings());
    filterNames.addAll(getWhereIterator().lookaheadScope().wLocalNames());
    lookaheadScope().setFilterEnabled(true);
    getBindings().wExitScope();
    if (!Matcher.removeVars(nextEntity, namesToBind(), withNamesComplement())) {
        Set<String> unboundedNames = Matcher.vars(nextEntity, false);
        if (withNamesComplement())
            unboundedNames.removeAll(namesToBind());
        else
            unboundedNames.retainAll(namesToBind());
        throw new MissingVariableException("Unbounded names in select clause: ", null, unboundedNames.toArray(new String[unboundedNames.size()])).withSourceEntity(getSourceEntity()).withBindings(getBindings());
    }
    if (selfEntityOld != null)
        getBindings().wDef("self", selfEntityOld);
    return nextEntity;
}
Also used : WholeIllegalStateException(org.whole.lang.exceptions.WholeIllegalStateException) IEntity(org.whole.lang.model.IEntity) NoSuchElementException(java.util.NoSuchElementException) MissingVariableException(org.whole.lang.visitors.MissingVariableException)

Example 8 with MissingVariableException

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

the class QueriesInterpreterVisitor method visit.

@Override
public void visit(VariableRefStep entity) {
    String varName = entity.getValue();
    IEntity value = BindingUtils.wGet(getBindings(), varName);
    if (value == null)
        throw new MissingVariableException(varName).withSourceEntity(entity).withBindings(getBindings());
    setResult(value);
}
Also used : IEntity(org.whole.lang.model.IEntity) MissingVariableException(org.whole.lang.visitors.MissingVariableException)

Example 9 with MissingVariableException

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

the class WorkflowsInterpreterVisitor method visit.

@Override
public void visit(Variable entity) {
    IEntity result = getBindings().wGet(entity.getValue());
    if (result == null)
        throw new MissingVariableException(entity.getValue()).withSourceEntity(entity).withBindings(getBindings());
    setResult(result);
}
Also used : IEntity(org.whole.lang.model.IEntity) MissingVariableException(org.whole.lang.visitors.MissingVariableException)

Example 10 with MissingVariableException

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

the class CommonsInterpreterVisitor method evaluate.

public static final IEntity evaluate(Variable variable, IBindingManager bm) {
    String varName = variable.getVarName().getValue();
    IEntity value = BindingUtils.wGet(bm, varName);
    if (value != null) {
        if (Matcher.match(CommonsEntityDescriptorEnum.InlineVariable, variable)) {
            bm.setResultIterator(IteratorFactory.constantChildIterator(value));
            value = null;
        } else {
            EntityDescriptor<?> varType = variable.getVarType().getValue();
            try {
                bm.setResult(value = EntityUtils.convertCloneIfParented(value, varType));
            } catch (IllegalArgumentException e) {
                throw new SubstituteException(variable, value.wGetEntityDescriptor());
            }
        }
        return value;
    } else
        throw new VisitException(new MissingVariableException(varName).withSourceEntity(variable).withBindings(bm));
}
Also used : SubstituteException(org.whole.lang.matchers.SubstituteException) IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException) 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