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;
}
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;
}
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);
}
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);
}
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));
}
Aggregations