01: /*
02: * Created on Oct 21, 2004
03: *
04: */
05: package org.hammurapi.inspectors;
06:
07: import org.hammurapi.InspectorBase;
08:
09: import com.pavelvlasov.jsel.Code;
10: import com.pavelvlasov.jsel.JselException;
11: import com.pavelvlasov.jsel.LanguageElement;
12: import com.pavelvlasov.jsel.Operation;
13: import com.pavelvlasov.jsel.OperationInfo;
14: import com.pavelvlasov.jsel.TypeBody;
15: import com.pavelvlasov.jsel.expressions.MethodCall;
16: import com.pavelvlasov.jsel.statements.DoStatement;
17: import com.pavelvlasov.jsel.statements.ForStatement;
18: import com.pavelvlasov.jsel.statements.WhileStatement;
19: import com.pavelvlasov.review.SourceMarker;
20:
21: /**
22: * @author Johannes Bellert
23: *
24: */
25: public class SqlCreateStatementWithinLoop extends InspectorBase {
26:
27: public boolean visit(MethodCall target) throws JselException {
28: if (context.getVisitorStack().isIn(
29: new Class[] { ForStatement.class, DoStatement.class,
30: WhileStatement.class })) {
31: context.verbose((SourceMarker) target, " target "
32: + target.toString());
33: if ("createStatement".equals(target.getMethodName())
34: || "prepareStatement"
35: .equals(target.getMethodName())) {
36: Code code = ((LanguageElement) target)
37: .getEnclosingCode();
38: if (code != null) {
39: Operation op = (Operation) code;
40: TypeBody tb = code.getEnclosingType();
41:
42: String key = tb.getFcn() + ">>"
43: + op.getOperationSignature();
44:
45: OperationInfo opi = target.getProvider();
46: context.verbose((SourceMarker) target, "opi "
47: + opi.getDeclaringType().getName());
48:
49: if ("java.sql.Connection".equals(opi
50: .getDeclaringType().getName())) {
51: context.reportViolation((SourceMarker) target);
52: }
53: }
54: }
55: }
56: return true;
57: }
58: }
|