Search in sources :

Example 41 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class ControlQueriesTest method testQueryDecl2.

@Test
public void testQueryDecl2() {
    Grammar grammar = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("queryDecl2");
    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);
}
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) Test(org.junit.Test)

Example 42 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class ControlQueriesTest method testQueryDecl6.

@Test
public void testQueryDecl6() {
    // not used
    Grammar grammar = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("queryDecl6");
    int count = 0;
    for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, grammar, bm)) {
        if (++count == 1)
            assertEquals(5, p.wIntValue());
        else if (count == 2)
            assertEquals(10, p.wIntValue());
        else if (count == 3)
            assertEquals(8, p.wIntValue());
    }
    assertEquals(3, 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) Test(org.junit.Test)

Example 43 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class ControlQueriesTest method testQueryDecl1.

@Test
public void testQueryDecl1() {
    Grammar grammar = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("queryDecl1");
    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);
}
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) Test(org.junit.Test)

Example 44 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testPatternWithVariablePredicate.

@Test
public void testPatternWithVariablePredicate() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    StringBuilder names = new StringBuilder();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    IEntityIterator<Production> iterator = BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("path8"), g, bm);
    for (Production p : iterator) {
        Assert.assertEquals(bm.wStringValue("name"), p.getName().getValue());
        names.append(p.getName().getValue());
    }
    Assert.assertEquals("VersionEncodingValueNameNameSpaceCharDataCDataSectDataCommentText", names.toString());
}
Also used : 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)

Example 45 with IBindingManager

use of org.whole.lang.bindings.IBindingManager 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)

Aggregations

IBindingManager (org.whole.lang.bindings.IBindingManager)223 IEntity (org.whole.lang.model.IEntity)141 Test (org.junit.Test)91 PathExpression (org.whole.lang.queries.model.PathExpression)49 ITemplateManager (org.whole.lang.templates.ITemplateManager)40 Grammar (org.whole.lang.grammars.model.Grammar)28 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)27 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)17 Model (org.whole.lang.models.model.Model)15 Production (org.whole.lang.grammars.model.Production)14 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)14 File (java.io.File)12 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)12 XmlModel (org.whole.lang.models.codebase.XmlModel)11 SimpleEntity (org.whole.lang.models.model.SimpleEntity)10 VisitException (org.whole.lang.visitors.VisitException)9 IBindingScope (org.whole.lang.bindings.IBindingScope)6 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)6 HashMap (java.util.HashMap)5 IFile (org.eclipse.core.resources.IFile)5