01: package org.incava.analysis;
02:
03: import net.sourceforge.pmd.ast.Token;
04: import org.incava.text.Location;
05:
06: /**
07: * Bridge between violations and reports.
08: */
09: public class Analyzer {
10: /**
11: * The report to which violations will be sent.
12: */
13: private Report report;
14:
15: /**
16: * Creates an analyzer with a report.
17: *
18: * @param r The report that this analyzer sends violations to.
19: */
20: public Analyzer(Report r) {
21: report = r;
22: }
23:
24: /**
25: * Adds a violation with a single token.
26: *
27: * @param message The violation message.
28: * @param token The token to which the violation applies.
29: */
30: public void addViolation(String message, Token token) {
31: tr.Ace.log("adding violation for " + token + ", " + message);
32: report.addViolation(new Violation(message, token));
33: }
34:
35: /**
36: * Adds a violation spanning from one token to another.
37: *
38: * @param message The violation message.
39: * @param firstToken The first token this violation spans.
40: * @param lastToken The last token this violation spans, inclusive.
41: */
42: public void addViolation(String message, Token firstToken,
43: Token lastToken) {
44: tr.Ace.log("adding violation for " + firstToken + ", "
45: + message);
46: report.addViolation(new Violation(message, firstToken,
47: lastToken));
48: }
49:
50: /**
51: * Adds a violation from one location to another.
52: *
53: * @param message The violation message.
54: * @param start Where this violation begins.
55: * @param end Where this violation ends, inclusive.
56: */
57: public void addViolation(String message, Location start,
58: Location end) {
59: tr.Ace.log("adding violation for " + message + ", " + start
60: + ", " + end);
61: report.addViolation(new Violation(message, start.line,
62: start.column, end.line, end.column));
63: }
64:
65: /**
66: * Adds a violation from a beginning position to an ending position.
67: *
68: * @param message The violation message.
69: * @param beginLine The line where this violation begins.
70: * @param beginColumn The column where this violation begins.
71: * @param endLine The line where this violation ends.
72: * @param endColumn The column where this violation ends.
73: */
74: public void addViolation(String message, int beginLine,
75: int beginColumn, int endLine, int endColumn) {
76: tr.Ace.log("adding violation for " + message + ", " + beginLine
77: + ":" + beginColumn + ", " + endLine + ":" + endColumn);
78: report.addViolation(new Violation(message, beginLine,
79: beginColumn, endLine, endColumn));
80: }
81:
82: /**
83: * Returns the report used by this analyzer.
84: */
85: protected Report getReport() {
86: return report;
87: }
88:
89: }
|