use of org.whole.lang.bindings.IBindingScope in project whole by wholeplatform.
the class TemplateInterpreterIterator method lookahead.
public E lookahead() {
if (nextEntityIterator != null)
return nextEntityIterator.lookahead();
clearLookaheadScope();
getBindings().wEnterScope(lookaheadScope(), true);
IEntity selfEntity = getBindings().wGet("self");
if (selfEntity != resetEntity)
getBindings().wDef("self", resetEntity);
IBindingScope results = InterpreterOperation.interpret(pattern, getBindings(), true);
getBindings().wExitScope();
nextEntityIterator = results.getResultIterator();
if (results.hasResultIterator()) {
results.setResultIterator(null);
selfEntity = getBindings().wGet("self");
if (selfEntity != resetEntity)
getBindings().wDef("self", resetEntity);
nextEntityIterator.reset(resetEntity);
lookaheadScope = null;
}
return nextEntityIterator.lookahead();
}
use of org.whole.lang.bindings.IBindingScope in project whole by wholeplatform.
the class BindingUtils method wOuterScope.
// public static IBindingManager getEnvironment(IBindingManager bm, String variable) {
// String environmentName = getEnvironmentName(variable);
// if (environmentName != null) {
// if (!bm.wIsSet(environmentName)) {
// IBindingManager environment = bm.wGetEnvironmentManager().getEnvironment(environmentName);
// bm.wDefValue(environmentName, environment);
// }
// bm = (IBindingManager) bm.wGetValue(environmentName);
// }
// return bm;
// }
//
// public static boolean wIsSet(IBindingManager bm, String variable) {
// return getEnvironment(bm, variable).wIsSet(getVariableName(variable));
// }
// public static IEntity wGet(IBindingManager bm, String variable) {
// return getEnvironment(bm, variable).wGet(getVariableName(variable));
// }
// public static void wSet(IBindingManager bm, String variable, IEntity value) {
// getEnvironment(bm, variable).wSet(getVariableName(variable), value);
// }
// public static void wDef(IBindingManager bm, String variable, IEntity value) {
// getEnvironment(bm, variable).wDef(getVariableName(variable), value);
// }
public static IBindingScope wOuterScope(IBindingScope scope, boolean preceding) {
IBindingScope precedingScope = scope;
switch(scope.getKind()) {
case OUTER_GROUP_ADAPTER:
return wOuterScope(scope.wTargetScope(), preceding);
case OUTER_SCOPE_ADAPTER:
do {
precedingScope = scope;
scope = scope.wEnclosingScope();
} while (scope.getKind().equals(IBindingScope.Kind.OUTER_SCOPE_ADAPTER));
if (scope == NullScope.instance)
break;
case SCOPE:
case INNER_SCOPE_ADAPTER:
do {
precedingScope = scope;
scope = scope.wEnclosingScope();
} while (scope.getKind().equals(IBindingScope.Kind.INNER_SCOPE_ADAPTER));
break;
}
return preceding ? precedingScope : scope;
}
use of org.whole.lang.bindings.IBindingScope in project whole by wholeplatform.
the class TestsHelpers method applyFilter.
public static IEntity applyFilter(IEntity filter, IEntity subject, IBindingManager bm) {
bm.wDef("self", subject);
IBindingScope bs = InterpreterOperation.interpret(EntityUtils.isFragment(filter) ? filter.wGetRoot() : filter, bm);
if (bs.hasResultIterator()) {
IEntityIterator<?> iterator = bs.getResultIterator();
bs.setResultIterator(null);
iterator.reset(subject);
while (iterator.hasNext()) iterator.next();
return subject;
} else {
IEntity result = bs.getResult();
return result != null ? result : subject;
}
}
use of org.whole.lang.bindings.IBindingScope in project whole by wholeplatform.
the class ActionCallIterator method lookahead.
public IEntity lookahead() {
if (nextEntity != null)
return nextEntity;
if (functionIterator == null && resetEntity == null)
return null;
IBindingScope laScope = lookaheadScope();
for (String name : laScope.wLocalNames()) getBindings().wUnset(name);
getBindings().wEnterScope();
nextEntity = functionIterator().lookahead();
getBindings().wExitScope();
return nextEntity;
}
use of org.whole.lang.bindings.IBindingScope in project whole by wholeplatform.
the class MatcherTest method testMultipleSubstitute.
@Test
public void testMultipleSubstitute() {
Model modelPattern = new ModelPattern().create();
IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
bindings.wDefValue("dataEntity", "DE");
IBindingScope args = BindingManagerFactory.instance.createSimpleScope();
args.wDefValue("dataEntity", "DE");
Matcher.substitute(modelPattern, args, false);
SimpleName var1 = (SimpleName) modelPattern.getDeclarations().wGet(0).wGet(ModelsFeatureDescriptorEnum.features).wGet(0).wGet(ModelsFeatureDescriptorEnum.type);
SimpleName var2 = (SimpleName) modelPattern.getDeclarations().wGet(1).wGet(ModelsFeatureDescriptorEnum.name);
assertEquals("DE", var1.wStringValue());
assertEquals("DE", var2.wStringValue());
assertNotSame(var1, var2);
}
Aggregations