Search in sources :

Example 1 with AptException

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

the class ExpressionValidatorTest method testStaticMethod_classNotFound.

@Test
void testStaticMethod_classNotFound() 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("@Xxx@staticMethod(\"aaa\")").parse();
            try {
                validator.validate(node);
                fail();
            } catch (AptException expected) {
                System.out.println(expected);
                assertEquals(Message.DOMA4145, expected.getMessageResource());
            }
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExpressionNode(org.seasar.doma.internal.expr.node.ExpressionNode) ExecutableElement(javax.lang.model.element.ExecutableElement) AptException(org.seasar.doma.internal.apt.AptException) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) ExpressionParser(org.seasar.doma.internal.expr.ExpressionParser) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 2 with AptException

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

the class SqlValidatorTest method testFor_identifier.

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

        @Override
        protected void run() {
            ExecutableElement methodElement = createMethodElement(target, "testFor", List.class);
            LinkedHashMap<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
            SqlValidator validator = new SqlValidator(ctx, methodElement, parameterTypeMap, "aaa/bbbDao/ccc.sql", false, false);
            SqlParser parser = new SqlParser("select * from emp where name = /*%for e : names*/ /*x*/'aaa' /*%if e_has_next*/or/*%end*//*%end*/");
            SqlNode sqlNode = parser.parse();
            try {
                sqlNode.accept(validator, null);
                fail();
            } catch (AptException expected) {
                System.out.println(expected.getMessage());
                assertEquals(Message.DOMA4092, expected.getMessageResource());
            }
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) AptException(org.seasar.doma.internal.apt.AptException) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 3 with AptException

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

the class SqlValidatorTest method testFor_noTypeArgument.

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

        @Override
        protected void run() {
            ExecutableElement methodElement = createMethodElement(target, "testFor_noTypeArgument", List.class);
            LinkedHashMap<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
            SqlValidator validator = new SqlValidator(ctx, methodElement, parameterTypeMap, "aaa/bbbDao/ccc.sql", false, false);
            SqlParser parser = new SqlParser("select * from emp where name = /*%for e : names*/ /*e*/'aaa' /*%if e_has_next*/or/*%end*//*%end*/");
            SqlNode sqlNode = parser.parse();
            try {
                sqlNode.accept(validator, null);
                fail();
            } catch (AptException expected) {
                System.out.println(expected.getMessage());
                assertEquals(Message.DOMA4150, expected.getMessageResource());
            }
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) AptException(org.seasar.doma.internal.apt.AptException) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 4 with AptException

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

the class SqlValidatorTest method testPopulate_notPopulatable.

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

        @Override
        protected void run() {
            ExecutableElement methodElement = createMethodElement(target, "testPopulate", String.class);
            LinkedHashMap<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
            SqlValidator validator = new SqlValidator(ctx, methodElement, parameterTypeMap, "aaa/bbbDao/ccc.sql", false, false);
            SqlParser parser = new SqlParser("update emp set /*%populate*/ id = id");
            SqlNode sqlNode = parser.parse();
            try {
                sqlNode.accept(validator, null);
                fail();
            } catch (AptException expected) {
                System.out.println(expected.getMessage());
                assertEquals(Message.DOMA4270, expected.getMessageResource());
            }
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) AptException(org.seasar.doma.internal.apt.AptException) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) LinkedHashMap(java.util.LinkedHashMap) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 5 with AptException

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

the class ExpressionValidatorTest method testStaticField_classNotFound.

@Test
void testStaticField_classNotFound() 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("@Xxx@staticField").parse();
            try {
                validator.validate(node);
                fail();
            } catch (AptException expected) {
                System.out.println(expected);
                assertEquals(Message.DOMA4145, expected.getMessageResource());
            }
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExpressionNode(org.seasar.doma.internal.expr.node.ExpressionNode) ExecutableElement(javax.lang.model.element.ExecutableElement) AptException(org.seasar.doma.internal.apt.AptException) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) ExpressionParser(org.seasar.doma.internal.expr.ExpressionParser) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

AptException (org.seasar.doma.internal.apt.AptException)72 ExecutableElement (javax.lang.model.element.ExecutableElement)25 Test (org.junit.jupiter.api.Test)19 TestProcessor (org.seasar.doma.internal.apt.TestProcessor)19 TypeDeclaration (org.seasar.doma.internal.apt.decl.TypeDeclaration)15 TypeElement (javax.lang.model.element.TypeElement)14 Map (java.util.Map)13 ExpressionParser (org.seasar.doma.internal.expr.ExpressionParser)13 ExpressionLocation (org.seasar.doma.internal.expr.node.ExpressionLocation)13 ExpressionNode (org.seasar.doma.internal.expr.node.ExpressionNode)13 EntityCtType (org.seasar.doma.internal.apt.cttype.EntityCtType)9 TypeMirror (javax.lang.model.type.TypeMirror)8 SqlNode (org.seasar.doma.jdbc.SqlNode)8 AptIllegalStateException (org.seasar.doma.internal.apt.AptIllegalStateException)7 LinkedHashMap (java.util.LinkedHashMap)6 CtType (org.seasar.doma.internal.apt.cttype.CtType)6 SqlParser (org.seasar.doma.internal.jdbc.sql.SqlParser)6 SqlLocation (org.seasar.doma.internal.jdbc.sql.node.SqlLocation)6 File (java.io.File)5 VariableElement (javax.lang.model.element.VariableElement)5