Search in sources :

Example 76 with PathExpression

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

the class SelectQueriesTest method testBindingScopes.

@Test
public void testBindingScopes() {
    Model m = new XmlModel().create();
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("selectBindingScopes");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    BindingsTester bt = new BindingsTester(bm);
    bm.wDefValue("bindingsTester", bt);
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, m, bm)) {
        Document d = (Document) tuple.wGet(0);
        SimpleEntity e = (SimpleEntity) tuple.wGet(1);
        String eName = e.getName().getValue();
        assertEquals(eName, d.wGet(0).wGet(1).wStringValue());
        assertEquals(eName + eName, d.wGet(1).wGet(1).wStringValue());
        assertEquals(eName + eName + eName + eName, d.wGet(2).wGet(1).wStringValue());
        for (int f = 0; f < e.getFeatures().wSize(); f++) {
            assertEquals(eName + eName + eName + eName + eName + eName + eName + eName, d.wGet(3).wGet(1 + f).wStringValue());
            assertEquals("true", d.wGet(4).wGet(1 + f).wStringValue());
            assertEquals("true", d.wGet(5).wGet(1 + f).wStringValue());
        }
        assertEquals(3, d.wGet(6).wSize());
        assertTrue(EntityUtils.isVariable(d.wGet(6).wGet(1)));
        assertTrue(EntityUtils.isVariable(d.wGet(6).wGet(2)));
    }
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) SimpleEntity(org.whole.lang.models.model.SimpleEntity) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) IBindingManager(org.whole.lang.bindings.IBindingManager) XmlModel(org.whole.lang.models.codebase.XmlModel) ITemplateManager(org.whole.lang.templates.ITemplateManager) Document(org.whole.lang.text.model.Document) Test(org.junit.Test)

Example 77 with PathExpression

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

the class SelectQueriesTest method testSelectTemplateWithNestedEmptyQuery.

@Test
public void testSelectTemplateWithNestedEmptyQuery() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithNestedEmptyQuery");
    for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
        assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
        assertEquals(2, t.getBodyDeclarations().wSize());
    }
}
Also used : ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) PathExpression(org.whole.lang.queries.model.PathExpression) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) ITemplateManager(org.whole.lang.templates.ITemplateManager) XmlModel(org.whole.lang.models.codebase.XmlModel) Test(org.junit.Test)

Example 78 with PathExpression

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

the class SelectQueriesTest method testSelectTupleWithTemplates.

@Test
public void testSelectTupleWithTemplates() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar model = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    PathExpression query = (PathExpression) tm.create("selectTupleWithTemplates");
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        FieldDeclaration fd = (FieldDeclaration) tuple.wGet(0);
        Feature f = (Feature) tuple.wGet(1);
        As e = (As) tuple.wGet(2);
        assertEquals(e.getName().getValue(), fd.getFragments().wGet(0).wGet(0).wStringValue());
        assertEquals(e.getRule().wStringValue(), fd.getType().wStringValue());
        assertEquals(e.getName().getValue(), f.getName().wStringValue());
        assertEquals(e.getRule().wStringValue(), f.getType().wStringValue());
    }
}
Also used : As(org.whole.lang.grammars.model.As) 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) Feature(org.whole.lang.models.model.Feature) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Example 79 with PathExpression

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

the class BindVariablesInPathTest method testBindVariablesInPathBAD2.

@Test
public void testBindVariablesInPathBAD2() throws Exception {
    IBindingManager bindings = BindingManagerFactory.instance.createArguments();
    IEntity compilationUnits = BindVariablesInPathTemplateManager.instance().create("compilationUnit");
    PathExpression findClassDeclarationsBAD2 = (PathExpression) BindVariablesInPathTemplateManager.instance().create("findClassDeclarationsBAD2");
    IEntityIterator<IEntity> iterator;
    iterator = BehaviorUtils.<IEntity>compileAndLazyEvaluate(findClassDeclarationsBAD2, compilationUnits, bindings);
    while (iterator.hasNext()) {
        assertNotNull(iterator.next());
        assertTrue(bindings.wIsSet("methodDeclaration"));
    }
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Test(org.junit.Test)

Example 80 with PathExpression

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

the class BindVariablesInPathTest method testBindVariablesInPathBAD1.

@Test
public void testBindVariablesInPathBAD1() throws Exception {
    IBindingManager bindings = BindingManagerFactory.instance.createArguments();
    IEntity compilationUnits = BindVariablesInPathTemplateManager.instance().create("compilationUnit");
    PathExpression findClassDeclarationsBAD1 = (PathExpression) BindVariablesInPathTemplateManager.instance().create("findClassDeclarationsBAD1");
    IEntityIterator<IEntity> iterator;
    iterator = BehaviorUtils.<IEntity>compileAndLazyEvaluate(findClassDeclarationsBAD1, compilationUnits, bindings);
    while (iterator.hasNext()) {
        assertNotNull(iterator.next());
        assertTrue(bindings.wIsSet("methodDeclaration"));
    }
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) 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