Search in sources :

Example 41 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager 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 42 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.

the class SelectQueriesTest method testSelectPathExpression2.

@Test
public void testSelectPathExpression2() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar model = new TestXmlGrammar().create();
    PathExpression query = (PathExpression) tm.create("selectPath2");
    StringBuilder names = new StringBuilder();
    for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(query, model)) names.append(nt.getValue());
    assertEquals("DocumentElementINameIContent", names.toString());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) 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) Test(org.junit.Test)

Example 43 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.

the class SelectQueriesTest method testSelectTemplateFromPattern.

@Test
public void testSelectTemplateFromPattern() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    JavaEntityFactory ef = JavaEntityFactory.instance;
    IfStatement ifStm = ef.createIfStatement(ef.createPrefixExpression(ef.createPrefixOperator(PrefixOperatorEnum.not), ef.createInfixExpression(ef.createSimpleName("x"), ef.createInfixOperator(InfixOperatorEnum.less), ef.createIntLiteral(3), ef.createExpressions(0))), ef.createEmptyStatement(), ef.createBlock(ef.createExpressionStatement(ef.createAssignment()), ef.createExpressionStatement(ef.createAssignment())));
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateFromPattern");
    IfStatement t = BehaviorUtils.<IfStatement>evaluateFirstResult(pe1, ifStm);
    assertEquals(JavaEntityDescriptorEnum.PrefixExpression, t.getExpression().wGetEntityDescriptor());
    assertTrue(Matcher.match(ifStm.getElseStatement(), t.getThenStatement()));
    assertTrue(Matcher.match(ifStm.getThenStatement(), t.getElseStatement()));
}
Also used : IfStatement(org.whole.lang.java.model.IfStatement) JavaEntityFactory(org.whole.lang.java.factories.JavaEntityFactory) PathExpression(org.whole.lang.queries.model.PathExpression) ITemplateManager(org.whole.lang.templates.ITemplateManager) Test(org.junit.Test)

Example 44 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.

the class SelectQueriesTest method testSelectPathExpression1.

@Test
public void testSelectPathExpression1() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("selectPath1");
    StringBuilder names = new StringBuilder();
    for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(pe1, g)) names.append(nt.getValue());
    assertEquals("DocumentElementINameIContent", names.toString());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) 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) Test(org.junit.Test)

Example 45 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager 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)

Aggregations

Test (org.junit.Test)96 ITemplateManager (org.whole.lang.templates.ITemplateManager)96 PathExpression (org.whole.lang.queries.model.PathExpression)87 IEntity (org.whole.lang.model.IEntity)61 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)47 Grammar (org.whole.lang.grammars.model.Grammar)46 Model (org.whole.lang.models.model.Model)41 IBindingManager (org.whole.lang.bindings.IBindingManager)40 XmlModel (org.whole.lang.models.codebase.XmlModel)27 Production (org.whole.lang.grammars.model.Production)26 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)25 ModelsModel (org.whole.lang.models.codebase.ModelsModel)23 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 NonTerminal (org.whole.lang.grammars.model.NonTerminal)9 Feature (org.whole.lang.models.model.Feature)9 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)7 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)7