use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class ControlQueriesTest method testDo1.
@Test
public void testDo1() {
Model model = new XmlModel().create();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("do1");
IEntity result = BehaviorUtils.evaluateFirstResult(query, model);
assertTrue(result instanceof ClassDeclaration);
assertEquals("HelloWorld", ((ClassDeclaration) result).getName().getValue());
}
use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class ControlQueriesTest method testIf2.
@Test
public void testIf2() {
Model model = new XmlModel().create();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("if2");
IEntity result = BehaviorUtils.evaluateFirstResult(query, model);
assertTrue(result instanceof ClassDeclaration);
assertEquals(model.getName().getValue(), ((ClassDeclaration) result).getName().getValue());
}
use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class ControlQueriesTest method testQueryDecl9.
@Test
public void testQueryDecl9() {
QueriesEntityFactory qef = QueriesEntityFactory.instance;
IEntity queryExp1 = qef.createAddition(qef.createAddition(qef.createIntLiteral(10), qef.createIntLiteral(8)), qef.createAddition(qef.createIntLiteral(2), qef.createIntLiteral(1)));
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("queryDecl9");
assertTrue(Matcher.match(queryExp1, BehaviorUtils.evaluateFirstResult(query, queryExp1)));
}
use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class ControlQueriesTest method testCall4.
@Test
public void testCall4() {
Grammar grammar = new TestXmlGrammar().create();
IBindingManager bm = BindingManagerFactory.instance.createArguments();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("call4");
int count = 0;
for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, grammar, bm)) {
assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.Production, p));
assertEquals("IContent", ((Production) p).getName().getValue());
count++;
}
assertEquals(1, count);
}
use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class ControlQueriesTest method testChoose4.
@Test
public void testChoose4() {
Model model = new ModelsModel().create();
ModelDeclarations decls = model.getDeclarations();
IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("choose4");
int i = 0;
IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model, bm);
while (iterator.hasNext()) {
IEntity result = iterator.next();
assertSame(result, bm.wGet("type"));
assertTrue(result instanceof ClassDeclaration);
ClassDeclaration classDecl = (ClassDeclaration) result;
IEntity decl = decls.wGet(i++);
String name = "", superClassName = "";
switch(decl.wGetEntityOrd()) {
case ModelsEntityDescriptorEnum.SimpleEntity_ord:
SimpleEntity simpleEntity = (SimpleEntity) decl;
name = simpleEntity.getName().wStringValue();
superClassName = "AbstractSimpleEntity";
break;
case ModelsEntityDescriptorEnum.CompositeEntity_ord:
CompositeEntity compositeEntity = (CompositeEntity) decl;
name = compositeEntity.getName().wStringValue();
superClassName = "AbstractCompositeEntity";
break;
case ModelsEntityDescriptorEnum.DataEntity_ord:
DataEntity dataEntity = (DataEntity) decl;
name = dataEntity.getName().wStringValue();
superClassName = "AbstractDataEntity";
break;
case ModelsEntityDescriptorEnum.EnumEntity_ord:
EnumEntity enumEntity = (EnumEntity) decl;
name = enumEntity.getName().wStringValue();
superClassName = "AbstractEnumEntity";
break;
}
assertEquals(name, classDecl.getName().wStringValue());
assertEquals(superClassName, classDecl.getSuperclassType().wStringValue());
}
}
Aggregations