Search in sources :

Example 21 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class ControlQueriesTest method testIf3.

@Test
public void testIf3() {
    Model model = new XmlModel().create();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("if3");
    IEntity result = BehaviorUtils.evaluateFirstResult(query, model);
    assertTrue(result instanceof ClassDeclaration);
    assertEquals(StringUtils.toUpperCap(model.getName().getValue()), ((ClassDeclaration) result).getName().getValue());
}
Also used : ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) XmlModel(org.whole.lang.models.codebase.XmlModel) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) XmlModel(org.whole.lang.models.codebase.XmlModel) ITemplateManager(org.whole.lang.templates.ITemplateManager) Test(org.junit.Test)

Example 22 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testHelperResultAs.

@Test
public void testHelperResultAs() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression query = (PathExpression) tm.create("helperResultAs");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    bm.wDefValue("ftype", "firstName");
    IEntityIterator<?> iterator = BehaviorUtils.<FieldDeclaration>compileAndLazyEvaluate(query, m, bm);
    Assert.assertTrue(iterator.hasNext());
    IEntity result = iterator.next();
    IEntity as = bm.wGet("jtype");
    Assert.assertEquals("FirstName", result.wStringValue());
    Assert.assertEquals("FirstName", as.wStringValue());
    Assert.assertFalse(iterator.hasNext());
    iterator.reset(m);
    bm.wDefValue("ftype", "secondName");
    Assert.assertTrue(iterator.hasNext());
    IEntity result2 = iterator.next();
    IEntity as2 = bm.wGet("jtype");
    Assert.assertEquals("SecondName", result2.wStringValue());
    Assert.assertEquals("SecondName", as2.wStringValue());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) XmlModel(org.whole.lang.models.codebase.XmlModel) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Example 23 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testProduct2.

@Test
public void testProduct2() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("testProduct2");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    int count = 0;
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
        String prodname = ((Production) bm.wGet("prod")).getName().getValue();
        Assert.assertEquals(prodname, tuple.wGet(0).wStringValue());
        count++;
    }
    Assert.assertEquals(g.getPhraseStructure().wSize(), count);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) PrettyPrinterOperation.toPrettyPrintString(org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString) Test(org.junit.Test)

Example 24 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testVariableJoinTest3.

@Test
public void testVariableJoinTest3() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new QueriesGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("recursiveProduction3");
    StringBuilder names = new StringBuilder();
    for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g)) names.append(p.getName().getValue());
    Assert.assertEquals("ExpressionPathExpressionStepExpressionPredicate", names.toString());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) Production(org.whole.lang.grammars.model.Production) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 25 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testSingleVariableTestInPathExpPredicate.

@Test
public void testSingleVariableTestInPathExpPredicate() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    Production p = (Production) g.getPhraseStructure().wGet(1);
    PathExpression pe1 = (PathExpression) tm.create("findProduction");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    // FIXME bm.wDefValue("pname", "Element");
    bm.wDef("pname", GrammarsEntityFactory.instance.createNonTerminal("Element"));
    IEntity p1 = BehaviorUtils.evaluateFirstResult(pe1, g, bm);
    Assert.assertSame(p, p1);
    bm.wDef("pname", GrammarsEntityFactory.instance.createNonTerminal("invented"));
    p1 = BehaviorUtils.evaluateFirstResult(pe1, g, bm);
    Assert.assertNull(p1);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Aggregations

PathExpression (org.whole.lang.queries.model.PathExpression)97 Test (org.junit.Test)94 ITemplateManager (org.whole.lang.templates.ITemplateManager)87 IEntity (org.whole.lang.model.IEntity)67 IBindingManager (org.whole.lang.bindings.IBindingManager)45 Model (org.whole.lang.models.model.Model)43 Grammar (org.whole.lang.grammars.model.Grammar)40 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)39 XmlModel (org.whole.lang.models.codebase.XmlModel)28 ModelsModel (org.whole.lang.models.codebase.ModelsModel)23 Production (org.whole.lang.grammars.model.Production)20 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)18 ModelDeclarations (org.whole.lang.models.model.ModelDeclarations)18 SimpleEntity (org.whole.lang.models.model.SimpleEntity)13 ClassDeclaration (org.whole.lang.java.model.ClassDeclaration)11 DataEntity (org.whole.lang.models.model.DataEntity)10 Feature (org.whole.lang.models.model.Feature)9 NonTerminal (org.whole.lang.grammars.model.NonTerminal)8 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)7 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)6