Search in sources :

Example 51 with Model

use of org.whole.lang.models.model.Model in project whole by wholeplatform.

the class SelectQueriesTest method testSelectTemplateAs.

@Test
public void testSelectTemplateAs() {
    Model model = new XmlModel().create();
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("selectTemplateAs");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        FieldDeclaration f = (FieldDeclaration) tuple.wGet(0);
        Feature e = (Feature) tuple.wGet(1);
        FieldDeclaration field = (FieldDeclaration) bm.wGet("field");
        assertSame(f, field);
        String ptype = e.getType().wStringValue();
        assertEquals(ptype, field.getType().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) XmlModel(org.whole.lang.models.codebase.XmlModel) ITemplateManager(org.whole.lang.templates.ITemplateManager) Feature(org.whole.lang.models.model.Feature) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Example 52 with Model

use of org.whole.lang.models.model.Model in project whole by wholeplatform.

the class SelectQueriesTest method testSelectTemplateFromPathWithPattern.

@Test
public void testSelectTemplateFromPathWithPattern() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateFromPathWithPattern");
    IEntityIterator<Feature> featureIterator = IteratorFactory.<Feature>descendantOrSelfMatcherIterator().withPattern(ModelsEntityDescriptorEnum.Feature);
    featureIterator.reset(m);
    for (FieldDeclaration field : BehaviorUtils.<FieldDeclaration>compileAndLazyEvaluate(pe1, m)) {
        Feature feature = featureIterator.next();
        assertEquals(feature.getType().wStringValue(), field.getType().wStringValue());
        assertEquals(feature.getName().wStringValue(), field.getFragments().wGet(0).wGet(0).wStringValue());
    }
}
Also used : 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) Feature(org.whole.lang.models.model.Feature) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Example 53 with Model

use of org.whole.lang.models.model.Model in project whole by wholeplatform.

the class SelectQueriesTest method testSelectTupleOfTemplatesAs.

@Test
public void testSelectTupleOfTemplatesAs() {
    Model model = new XmlModel().create();
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("selectTupleOfTemplatesAs");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        FieldDeclaration f = (FieldDeclaration) tuple.wGet(0);
        SingleVariableDeclaration p = (SingleVariableDeclaration) tuple.wGet(1);
        ExpressionStatement s = (ExpressionStatement) tuple.wGet(2);
        Feature e = (Feature) tuple.wGet(3);
        String ptype = e.getType().wStringValue();
        String pname = e.getName().wStringValue();
        assertSame(f, bm.wGet("field"));
        assertEquals(ptype, f.getType().wStringValue());
        assertSame(p, bm.wGet("param"));
        assertEquals(ptype, p.getType().wStringValue());
        assertEquals(pname, p.getName().wStringValue());
        assertSame(s, bm.wGet("init"));
        assertEquals(pname, ((Assignment) s.getExpression()).getRightHandSide().wStringValue());
    }
}
Also used : Assignment(org.whole.lang.java.model.Assignment) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) SingleVariableDeclaration(org.whole.lang.java.model.SingleVariableDeclaration) ExpressionStatement(org.whole.lang.java.model.ExpressionStatement) 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) Feature(org.whole.lang.models.model.Feature) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Example 54 with Model

use of org.whole.lang.models.model.Model 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 55 with Model

use of org.whole.lang.models.model.Model 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)

Aggregations

Model (org.whole.lang.models.model.Model)62 Test (org.junit.Test)55 PathExpression (org.whole.lang.queries.model.PathExpression)43 ITemplateManager (org.whole.lang.templates.ITemplateManager)41 IEntity (org.whole.lang.model.IEntity)40 XmlModel (org.whole.lang.models.codebase.XmlModel)30 ModelsModel (org.whole.lang.models.codebase.ModelsModel)25 ModelDeclarations (org.whole.lang.models.model.ModelDeclarations)19 IBindingManager (org.whole.lang.bindings.IBindingManager)15 SimpleEntity (org.whole.lang.models.model.SimpleEntity)14 ClassDeclaration (org.whole.lang.java.model.ClassDeclaration)12 DataEntity (org.whole.lang.models.model.DataEntity)10 Feature (org.whole.lang.models.model.Feature)9 ArrayList (java.util.ArrayList)6 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)6 CompositeEntity (org.whole.lang.models.model.CompositeEntity)4 Features (org.whole.lang.models.model.Features)4 EditorsModel (org.whole.lang.models.codebase.EditorsModel)3 EnumEntity (org.whole.lang.models.model.EnumEntity)3 SimpleName (org.whole.lang.models.model.SimpleName)3