Search in sources :

Example 1 with JavaEntityFactory

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

use of org.whole.lang.java.factories.JavaEntityFactory in project whole by wholeplatform.

the class FactoriesTest method testUniqueConstraint.

// TODO replace test language with one having unique constraints
@Test
public void testUniqueConstraint() {
    JavaEntityFactory ef = JavaEntityFactory.instance;
    JavaEntityFactory sef = JavaEntityFactory.instance(RegistryConfigurations.STRICT);
    ExtendedModifiers e = ef.createExtendedModifiers(ef.createModifier(ModifierEnum._abstract), ef.createModifier(ModifierEnum._abstract));
    e.wAdd(ef.createModifier(ModifierEnum._abstract));
    Assert.assertEquals(3, e.wSize());
    ExtendedModifiers se = sef.createExtendedModifiers(sef.createModifier(ModifierEnum._abstract), sef.createModifier(ModifierEnum._abstract));
    se.wAdd(ef.createModifier(ModifierEnum._abstract));
    // TODO was 1
    Assert.assertEquals(3, se.wSize());
    // TODO was false
    Assert.assertTrue(Matcher.match(se, e));
    Assert.assertFalse(Matcher.match(se, ef.createExtendedModifiers(// TODO was true
    ef.createModifier(ModifierEnum._abstract))));
}
Also used : JavaEntityFactory(org.whole.lang.java.factories.JavaEntityFactory) ExtendedModifiers(org.whole.lang.java.model.ExtendedModifiers) Test(org.junit.Test)

Example 3 with JavaEntityFactory

use of org.whole.lang.java.factories.JavaEntityFactory in project whole by wholeplatform.

the class ControlQueriesTest method testQueryDecl7.

@Test
public void testQueryDecl7() {
    QueriesEntityFactory qef = QueriesEntityFactory.instance;
    JavaEntityFactory jef = JavaEntityFactory.instance;
    IEntity queryExp1 = qef.createDivision(qef.createMultiplication(qef.createIntLiteral(10), qef.createIntLiteral(8)), qef.createAddition(qef.createIntLiteral(2), qef.createIntLiteral(1)));
    IEntity queryExp2 = qef.createDivision(qef.createIntLiteral(10), qef.createAddition(qef.createIntLiteral(2), qef.createIntLiteral(1)));
    IEntity javaExp1 = jef.createInfixExpression(jef.createInfixExpression(jef.createIntLiteral(10), jef.createInfixOperator(InfixOperatorEnum.times), jef.createIntLiteral(8), jef.createExpressions(0)), jef.createInfixOperator(InfixOperatorEnum.divide), jef.createInfixExpression(jef.createIntLiteral(2), jef.createInfixOperator(InfixOperatorEnum.plus), jef.createIntLiteral(1), jef.createExpressions(0)), jef.createExpressions(0));
    IEntity javaExp2 = EntityUtils.clone(javaExp1);
    javaExp2.wSet(JavaFeatureDescriptorEnum.leftOperand, jef.createIntLiteral(10));
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("queryDecl7");
    assertTrue(Matcher.match(javaExp2, BehaviorUtils.evaluateFirstResult(query, queryExp2)));
    assertTrue(Matcher.match(javaExp1, BehaviorUtils.evaluateFirstResult(query, queryExp1)));
}
Also used : JavaEntityFactory(org.whole.lang.java.factories.JavaEntityFactory) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ITemplateManager(org.whole.lang.templates.ITemplateManager) Test(org.junit.Test)

Example 4 with JavaEntityFactory

use of org.whole.lang.java.factories.JavaEntityFactory in project whole by wholeplatform.

the class FactoriesTest method testSimpleEntityFactoryMethodWithObjects.

@Test
public void testSimpleEntityFactoryMethodWithObjects() {
    JavaEntityFactory ef = JavaEntityFactory.instance;
    ef.buildMethodInvocation().set(JavaFeatureDescriptorEnum.name, "methodName").getResult();
    ef.create(JavaEntityDescriptorEnum.MethodInvocation, ef.createThisExpression(), ef.createTypes(), "methodName", ef.createArguments());
    ef.create(JavaEntityDescriptorEnum.MethodInvocation, ef.createThisExpression(), ef.createTypes(), // with less arguments
    "methodName");
}
Also used : JavaEntityFactory(org.whole.lang.java.factories.JavaEntityFactory) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 JavaEntityFactory (org.whole.lang.java.factories.JavaEntityFactory)4 PathExpression (org.whole.lang.queries.model.PathExpression)2 ITemplateManager (org.whole.lang.templates.ITemplateManager)2 ExtendedModifiers (org.whole.lang.java.model.ExtendedModifiers)1 IfStatement (org.whole.lang.java.model.IfStatement)1 IEntity (org.whole.lang.model.IEntity)1 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)1