Search in sources :

Example 1 with FieldDeclaration

use of org.whole.lang.java.model.FieldDeclaration 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 2 with FieldDeclaration

use of org.whole.lang.java.model.FieldDeclaration in project whole by wholeplatform.

the class SelectQueriesTest method testSelectTemplateWithJavaHelpers.

@Test
public void testSelectTemplateWithJavaHelpers() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithJavaHelpers");
    for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
        assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
        String cname = t.getName().wStringValue();
        assertTrue(Character.isUpperCase(cname.charAt(0)) && cname.endsWith("Impl"));
        for (int i = 0; i < t.getBodyDeclarations().wSize(); i++) {
            FieldDeclaration fd = (FieldDeclaration) t.getBodyDeclarations().wGet(i);
            assertTrue(Character.isUpperCase(fd.getType().wStringValue().charAt(0)));
        }
    }
}
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) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Example 3 with FieldDeclaration

use of org.whole.lang.java.model.FieldDeclaration in project whole by wholeplatform.

the class SelectQueriesTest method testSelectTemplateFromPatternWithWhere.

@Test
public void testSelectTemplateFromPatternWithWhere() {
    Model m = new XmlModel().create();
    Feature feature = (Feature) ((SimpleEntity) m.getDeclarations().wGet(0)).getFeatures().wGet(0);
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateFromPatternWithWhere");
    for (FieldDeclaration field : BehaviorUtils.<FieldDeclaration>compileAndLazyEvaluate(pe1, feature)) {
        assertEquals(feature.getName().wStringValue(), field.getFragments().wGet(0).wGet(0).wStringValue());
        assertEquals(StringUtils.toUpperCap(feature.getType().wStringValue()), field.getType().wStringValue());
    }
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) SimpleEntity(org.whole.lang.models.model.SimpleEntity) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) 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 4 with FieldDeclaration

use of org.whole.lang.java.model.FieldDeclaration 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 5 with FieldDeclaration

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

Aggregations

FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)8 Test (org.junit.Test)7 PathExpression (org.whole.lang.queries.model.PathExpression)7 ITemplateManager (org.whole.lang.templates.ITemplateManager)7 XmlModel (org.whole.lang.models.codebase.XmlModel)6 Model (org.whole.lang.models.model.Model)6 IEntity (org.whole.lang.model.IEntity)5 Feature (org.whole.lang.models.model.Feature)5 IBindingManager (org.whole.lang.bindings.IBindingManager)4 ArrayList (java.util.ArrayList)1 As (org.whole.lang.grammars.model.As)1 Grammar (org.whole.lang.grammars.model.Grammar)1 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)1 Assignment (org.whole.lang.java.model.Assignment)1 ClassDeclaration (org.whole.lang.java.model.ClassDeclaration)1 ExpressionStatement (org.whole.lang.java.model.ExpressionStatement)1 SingleVariableDeclaration (org.whole.lang.java.model.SingleVariableDeclaration)1 SimpleEntity (org.whole.lang.models.model.SimpleEntity)1