use of org.jooq.PlainSQL in project jOOQ by jOOQ.
the class PlainSQLChecker method createSourceVisitor.
@Override
protected SourceVisitor<Void, Void> createSourceVisitor() {
return new SourceVisitor<Void, Void>(getChecker()) {
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
try {
ExecutableElement elementFromUse = elementFromUse(node);
PlainSQL plainSQL = elementFromUse.getAnnotation(PlainSQL.class);
// all jOOQ API method calls will type check.
if (plainSQL != null) {
Element enclosing = elementFromDeclaration(enclosingMethod(getPath(root, node)));
boolean allowed = false;
moveUpEnclosingLoop: while (enclosing != null) {
if (enclosing.getAnnotation(Allow.PlainSQL.class) != null) {
allowed = true;
break moveUpEnclosingLoop;
}
enclosing = enclosing.getEnclosingElement();
}
if (!allowed)
error(node, "Plain SQL usage not allowed at current scope. Use @Allow.PlainSQL.");
}
} catch (final Exception e) {
print(new Printer() {
@Override
public void print(PrintWriter t) {
e.printStackTrace(t);
}
});
}
return super.visitMethodInvocation(node, p);
}
};
}
Aggregations