Search in sources :

Example 6 with ClassDeclaration

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

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

the class SelectQueriesTest method testTemplateFromWhere.

@Test
public void testTemplateFromWhere() {
    Model m = new XmlModel().create();
    SimpleEntity simpleEntity = (SimpleEntity) m.getDeclarations().wGet(0);
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateFromWhere");
    for (ClassDeclaration classDecl : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, simpleEntity)) {
        assertEquals(StringUtils.toUpperCap(simpleEntity.getName().getValue()), classDecl.getName().wStringValue());
        int featuresSize = simpleEntity.getFeatures().wSize();
        assertEquals(featuresSize * 2, classDecl.getBodyDeclarations().wSize());
    }
}
Also used : ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) 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) Test(org.junit.Test)

Example 8 with ClassDeclaration

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

the class SelectQueriesTest method testSelectTemplateWithNestedRelativeQuery.

@Test
public void testSelectTemplateWithNestedRelativeQuery() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithNestedRelativeQuery");
    PathExpression pe2 = (PathExpression) tm.create("selectTemplateWithNestedQuery");
    IEntityIterator<ClassDeclaration> i2 = BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe2, m);
    for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
        assertTrue(i2.hasNext());
        assertTrue(Matcher.match(i2.next(), t));
    }
}
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)

Example 9 with ClassDeclaration

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

the class SelectQueriesTest method testSelectTemplateWithNestedQuery.

@Test
public void testSelectTemplateWithNestedQuery() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithNestedQuery");
    for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
        assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
        assertTrue(t.getBodyDeclarations().wSize() >= 2);
    }
}
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)

Example 10 with ClassDeclaration

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

the class SelectQueriesTest method testSelectTemplateWithFreeVariable.

@Test
public void testSelectTemplateWithFreeVariable() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithFreeVariable");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m, bm)) {
        assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
        if (bm.wIsSet("freeVariable")) {
            assertEquals(bm.wStringValue("freeVariable"), t.getName().wStringValue());
            bm.wUnset("freeVariable");
        } else {
            assertTrue(t.getName().wIsAdapter());
            bm.wDefValue("freeVariable", "MyClassName");
        }
    }
}
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) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) XmlModel(org.whole.lang.models.codebase.XmlModel) Test(org.junit.Test)

Aggregations

ClassDeclaration (org.whole.lang.java.model.ClassDeclaration)15 Test (org.junit.Test)12 XmlModel (org.whole.lang.models.codebase.XmlModel)11 Model (org.whole.lang.models.model.Model)11 PathExpression (org.whole.lang.queries.model.PathExpression)11 ITemplateManager (org.whole.lang.templates.ITemplateManager)11 IEntity (org.whole.lang.model.IEntity)7 IBindingManager (org.whole.lang.bindings.IBindingManager)4 ModelsModel (org.whole.lang.models.codebase.ModelsModel)4 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 SimpleEntity (org.whole.lang.models.model.SimpleEntity)2 ArrayList (java.util.ArrayList)1 AnonymousClassDeclaration (org.eclipse.jdt.core.dom.AnonymousClassDeclaration)1 SimpleName (org.eclipse.jdt.core.dom.SimpleName)1 BodyDeclarations (org.whole.lang.java.model.BodyDeclarations)1 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)1 IJavaEntity (org.whole.lang.java.model.IJavaEntity)1 InterfaceDeclaration (org.whole.lang.java.model.InterfaceDeclaration)1 MethodDeclaration (org.whole.lang.java.model.MethodDeclaration)1 MethodInvocation (org.whole.lang.java.model.MethodInvocation)1