Search in sources :

Example 51 with IBindingManager

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

the class PathExpressionsQueriesTest method testSingleVariableTestInPathExpPredicateOfPathInternalStep.

@Test
public void testSingleVariableTestInPathExpPredicateOfPathInternalStep() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("findAllNonTerminalsUsed");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    // FIXME bm.wDefValue("pname", "Element");
    bm.wDef("pname", GrammarsEntityFactory.instance.createNonTerminal("IName"));
    int count = 0;
    for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(pe1, g, bm)) count++;
    Assert.assertEquals(4, count);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) NonTerminal(org.whole.lang.grammars.model.NonTerminal) 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 52 with IBindingManager

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

the class SelectQueriesTest method testVariableScopes.

@Test
public void testVariableScopes() {
    Model model = new XmlModel().create();
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("selectVariableScopes");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        Document d = (Document) tuple.wGet(0);
        SimpleEntity se = (SimpleEntity) tuple.wGet(1);
        assertFalse(bm.wIsSet("fromName"));
        assertFalse(bm.wIsSet("oneTime"));
        assertFalse(bm.wIsSet("featuresTimes"));
        assertFalse(bm.wIsSet("featuresTimesInLine"));
        assertFalse(bm.wIsSet("fTimes"));
        assertFalse(bm.wIsSet("siblingTimes"));
        // changed semantics: from variables are substituted multiple times
        assertTrue(1 < d.wGet(0).wSize() - 1);
        assertEquals(1, d.wGet(1).wSize() - 1);
        assertEquals(se.getFeatures().wSize(), d.wGet(2).wSize() - 1);
        assertEquals(se.getFeatures().wSize(), d.wGet(3).wSize() - 1);
        assertEquals(model.getDeclarations().wSize() - 1 - model.getDeclarations().wIndexOf(se), d.wGet(4).wSize() - 1);
    }
}
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 53 with IBindingManager

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

the class SelectQueriesTest method testSelectTemplate1.

@Test
public void testSelectTemplate1() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar model = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    PathExpression query = (PathExpression) tm.create("selectTemplate1");
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        Feature f = (Feature) tuple.wGet(0);
        As e = (As) tuple.wGet(1);
        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) Test(org.junit.Test)

Example 54 with IBindingManager

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

the class SelectQueriesTest method testBindingScopes3.

@Test
public void testBindingScopes3() {
    Model model = new XmlModel().create();
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("selectBindingScopes3");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        Document d = (Document) tuple.wGet(0);
        IEntity nameData = tuple.wGet(1);
        String name = nameData.wStringValue();
        String entityName = bm.wStringValue("entityName");
        assertEquals(name, d.wGet(0).wGet(1).wStringValue());
        assertEquals(name, entityName);
        assertFalse(bm.wIsSet("fromName"));
    }
}
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) 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 55 with IBindingManager

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

the class SelectQueriesTest method testBindingScopes2.

@Test
public void testBindingScopes2() {
    Model model = new XmlModel().create();
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("selectBindingScopes2");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, 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, d.wGet(0).wGet(2).wStringValue());
        assertEquals(eName + eName, d.wGet(1).wGet(1).wStringValue());
    }
}
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)

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