Search in sources :

Example 1 with TypeDeclaration

use of org.seasar.doma.internal.apt.decl.TypeDeclaration in project doma by domaframework.

the class ExpressionValidatorTest method testMethod_foundFromCandidates.

@Test
void testMethod_foundFromCandidates() throws Exception {
    Class<?> target = ExpressionValidationDao.class;
    addCompilationUnit(target);
    addProcessor(new TestProcessor() {

        @Override
        protected void run() {
            ExecutableElement methodElement = createMethodElement(target, "testEmp", Emp.class);
            Map<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
            ExpressionValidator validator = new ExpressionValidator(ctx, methodElement, parameterTypeMap);
            ExpressionNode node = new ExpressionParser("emp.hoge(\"aaa\")").parse();
            TypeDeclaration result = validator.validate(node);
            assertTrue(result.isNumberType());
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExpressionNode(org.seasar.doma.internal.expr.node.ExpressionNode) ExecutableElement(javax.lang.model.element.ExecutableElement) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) ExpressionParser(org.seasar.doma.internal.expr.ExpressionParser) Map(java.util.Map) TypeDeclaration(org.seasar.doma.internal.apt.decl.TypeDeclaration) Test(org.junit.jupiter.api.Test)

Example 2 with TypeDeclaration

use of org.seasar.doma.internal.apt.decl.TypeDeclaration in project doma by domaframework.

the class ExpressionValidatorTest method testAddOperator_text_text.

@Test
void testAddOperator_text_text() throws Exception {
    Class<?> target = ExpressionValidationDao.class;
    addCompilationUnit(target);
    addProcessor(new TestProcessor() {

        @Override
        protected void run() {
            ExecutableElement methodElement = createMethodElement(target, "testEmp", Emp.class);
            Map<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
            ExpressionValidator validator = new ExpressionValidator(ctx, methodElement, parameterTypeMap);
            ExpressionNode node = new ExpressionParser("\"1\" + \"2\"").parse();
            TypeDeclaration result = validator.validate(node);
            assertTrue(result.isTextType());
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExpressionNode(org.seasar.doma.internal.expr.node.ExpressionNode) ExecutableElement(javax.lang.model.element.ExecutableElement) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) ExpressionParser(org.seasar.doma.internal.expr.ExpressionParser) Map(java.util.Map) TypeDeclaration(org.seasar.doma.internal.apt.decl.TypeDeclaration) Test(org.junit.jupiter.api.Test)

Example 3 with TypeDeclaration

use of org.seasar.doma.internal.apt.decl.TypeDeclaration in project doma by domaframework.

the class ExpressionValidatorTest method testFieldAccess_static_optional.

@Test
void testFieldAccess_static_optional() throws Exception {
    Class<?> target = ExpressionValidationDao.class;
    addCompilationUnit(target);
    addProcessor(new TestProcessor() {

        @Override
        protected void run() {
            ExecutableElement methodElement = createMethodElement(target, "testPerson", Person.class);
            Map<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
            ExpressionValidator validator = new ExpressionValidator(ctx, methodElement, parameterTypeMap);
            ExpressionNode node = new ExpressionParser("person.staticName").parse();
            TypeDeclaration result = validator.validate(node);
            assertTrue(result.isTextType());
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExpressionNode(org.seasar.doma.internal.expr.node.ExpressionNode) ExecutableElement(javax.lang.model.element.ExecutableElement) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) ExpressionParser(org.seasar.doma.internal.expr.ExpressionParser) Map(java.util.Map) TypeDeclaration(org.seasar.doma.internal.apt.decl.TypeDeclaration) Test(org.junit.jupiter.api.Test)

Example 4 with TypeDeclaration

use of org.seasar.doma.internal.apt.decl.TypeDeclaration in project doma by domaframework.

the class ExpressionValidatorTest method testMethod_foundWithSupertype.

@Test
void testMethod_foundWithSupertype() throws Exception {
    Class<?> target = ExpressionValidationDao.class;
    addCompilationUnit(target);
    addProcessor(new TestProcessor() {

        @Override
        protected void run() {
            ExecutableElement methodElement = createMethodElement(target, "testEmp", Emp.class);
            Map<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
            ExpressionValidator validator = new ExpressionValidator(ctx, methodElement, parameterTypeMap);
            ExpressionNode node = new ExpressionParser("emp.hoge(new java.lang.Integer(1))").parse();
            TypeDeclaration result = validator.validate(node);
            assertTrue(result.isNumberType());
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExpressionNode(org.seasar.doma.internal.expr.node.ExpressionNode) ExecutableElement(javax.lang.model.element.ExecutableElement) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) ExpressionParser(org.seasar.doma.internal.expr.ExpressionParser) Map(java.util.Map) TypeDeclaration(org.seasar.doma.internal.apt.decl.TypeDeclaration) Test(org.junit.jupiter.api.Test)

Example 5 with TypeDeclaration

use of org.seasar.doma.internal.apt.decl.TypeDeclaration in project doma by domaframework.

the class ExpressionValidatorTest method testCustomFunction_superClassMethodFound.

@Test
void testCustomFunction_superClassMethodFound() throws Exception {
    Class<?> target = ExpressionValidationDao.class;
    addCompilationUnit(target);
    addProcessor(new TestProcessor() {

        @Override
        protected void run() {
            ExecutableElement methodElement = createMethodElement(target, "testEmp", Emp.class);
            Map<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
            ExpressionValidator validator = new ExpressionValidator(ctx, methodElement, parameterTypeMap, MyExpressionFunctions.class.getName());
            ExpressionNode node = new ExpressionParser("@prefix(emp.name)").parse();
            TypeDeclaration result = validator.validate(node);
            assertTrue(result.isTextType());
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExpressionNode(org.seasar.doma.internal.expr.node.ExpressionNode) ExecutableElement(javax.lang.model.element.ExecutableElement) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) ExpressionParser(org.seasar.doma.internal.expr.ExpressionParser) Map(java.util.Map) TypeDeclaration(org.seasar.doma.internal.apt.decl.TypeDeclaration) Test(org.junit.jupiter.api.Test)

Aggregations

TypeDeclaration (org.seasar.doma.internal.apt.decl.TypeDeclaration)49 Map (java.util.Map)28 ExecutableElement (javax.lang.model.element.ExecutableElement)28 Test (org.junit.jupiter.api.Test)28 TestProcessor (org.seasar.doma.internal.apt.TestProcessor)28 ExpressionParser (org.seasar.doma.internal.expr.ExpressionParser)28 ExpressionNode (org.seasar.doma.internal.expr.node.ExpressionNode)28 AptException (org.seasar.doma.internal.apt.AptException)15 ExpressionLocation (org.seasar.doma.internal.expr.node.ExpressionLocation)11 SqlLocation (org.seasar.doma.internal.jdbc.sql.node.SqlLocation)4 TypeElement (javax.lang.model.element.TypeElement)3 MethodDeclaration (org.seasar.doma.internal.apt.decl.MethodDeclaration)3 FieldDeclaration (org.seasar.doma.internal.apt.decl.FieldDeclaration)2 ArrayType (javax.lang.model.type.ArrayType)1 DeclaredType (javax.lang.model.type.DeclaredType)1 TypeMirror (javax.lang.model.type.TypeMirror)1 ConstructorDeclaration (org.seasar.doma.internal.apt.decl.ConstructorDeclaration)1