Search in sources :

Example 1 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class PojoMappingUtils method getLibrary.

public static Library getLibrary(Misc compilationUnits, IBindingManager bindings) {
    PathExpression javaModelToPojoModel = new JavaModelToPojoModelQuery().create();
    Library library = BehaviorUtils.<Library>evaluateFirstResult(javaModelToPojoModel, compilationUnits, bindings);
    Matcher.removeVars(library, true);
    return library;
}
Also used : JavaModelToPojoModelQuery(org.whole.lang.pojo.templates.JavaModelToPojoModelQuery) PathExpression(org.whole.lang.queries.model.PathExpression) Library(org.whole.lang.pojo.model.Library)

Example 2 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class PojoMappingUtils method getModel.

public static Model getModel(Library library) {
    IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
    PathExpression pojoModelToModels = new PojoModelToModelsQuery().create();
    Library normalizedLibrary = NormalizerOperation.normalize(EntityUtils.clone(library));
    Model model = BehaviorUtils.<Model>evaluateFirstResult(pojoModelToModels, normalizedLibrary, bindings);
    Matcher.removeVars(model, true);
    return model;
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) PojoModelToModelsQuery(org.whole.lang.pojo.templates.PojoModelToModelsQuery) IBindingManager(org.whole.lang.bindings.IBindingManager) Model(org.whole.lang.models.model.Model) Library(org.whole.lang.pojo.model.Library)

Example 3 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class BindVariablesInPathTest method testBindVariablesInPathOK2.

@Test
public void testBindVariablesInPathOK2() throws Exception {
    IBindingManager bindings = BindingManagerFactory.instance.createArguments();
    IEntity compilationUnits = BindVariablesInPathTemplateManager.instance().create("compilationUnit");
    PathExpression findClassDeclarationsOK2 = (PathExpression) BindVariablesInPathTemplateManager.instance().create("findClassDeclarationsOK2");
    IEntityIterator<IEntity> iterator;
    iterator = BehaviorUtils.<IEntity>compileAndLazyEvaluate(findClassDeclarationsOK2, compilationUnits, bindings);
    while (iterator.hasNext()) {
        assertNotNull(iterator.next());
        assertTrue(bindings.wIsSet("methodDeclaration"));
    }
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Test(org.junit.Test)

Example 4 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class BindVariablesInPathTest method testBindVariablesInPathOK1.

@Test
public void testBindVariablesInPathOK1() throws Exception {
    IBindingManager bindings = BindingManagerFactory.instance.createArguments();
    IEntity compilationUnits = BindVariablesInPathTemplateManager.instance().create("compilationUnit");
    PathExpression findClassDeclarationsOK1 = (PathExpression) BindVariablesInPathTemplateManager.instance().create("findClassDeclarationsOK1");
    IEntityIterator<IEntity> iterator;
    iterator = BehaviorUtils.<IEntity>compileAndLazyEvaluate(findClassDeclarationsOK1, compilationUnits, bindings);
    while (iterator.hasNext()) {
        assertNotNull(iterator.next());
        assertTrue(bindings.wIsSet("methodDeclaration"));
    }
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Test(org.junit.Test)

Example 5 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class ControlQueriesTest method testIf4.

@Test
public void testIf4() {
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("if4");
    QueriesEntityFactory qef = QueriesEntityFactory.instance;
    IEntity queryExp1 = qef.createDivision(qef.createIntLiteral(10), qef.createIntLiteral(8));
    IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, queryExp1, bm);
    assertTrue(iterator.hasNext());
    IEntity exp1 = iterator.next();
    assertSame(queryExp1.wGet(0), exp1);
    assertTrue(bm.wIsSet("a"));
    assertFalse(bm.wIsSet("b"));
    assertFalse(bm.wIsSet("exp1"));
    assertFalse(bm.wIsSet("exp2"));
    assertTrue(iterator.hasNext());
    IEntity exp2 = iterator.next();
    assertSame(queryExp1.wGet(1), exp2);
    assertFalse(bm.wIsSet("a"));
    assertTrue(bm.wIsSet("b"));
    assertFalse(bm.wIsSet("exp1"));
    assertFalse(bm.wIsSet("exp2"));
    assertFalse(iterator.hasNext());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) Test(org.junit.Test)

Aggregations

PathExpression (org.whole.lang.queries.model.PathExpression)97 Test (org.junit.Test)94 ITemplateManager (org.whole.lang.templates.ITemplateManager)87 IEntity (org.whole.lang.model.IEntity)67 IBindingManager (org.whole.lang.bindings.IBindingManager)45 Model (org.whole.lang.models.model.Model)43 Grammar (org.whole.lang.grammars.model.Grammar)40 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)39 XmlModel (org.whole.lang.models.codebase.XmlModel)28 ModelsModel (org.whole.lang.models.codebase.ModelsModel)23 Production (org.whole.lang.grammars.model.Production)20 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)18 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 Feature (org.whole.lang.models.model.Feature)9 NonTerminal (org.whole.lang.grammars.model.NonTerminal)8 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)7 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)6