KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > incava > analysis > Analyzer


1 package org.incava.analysis;
2
3 import net.sourceforge.pmd.ast.Token;
4 import org.incava.text.Location;
5
6
7 /**
8  * Bridge between violations and reports.
9  */

10 public class Analyzer
11 {
12     /**
13      * The report to which violations will be sent.
14      */

15     private Report report;
16
17     /**
18      * Creates an analyzer with a report.
19      *
20      * @param r The report that this analyzer sends violations to.
21      */

22     public Analyzer(Report r)
23     {
24         report = r;
25     }
26
27     /**
28      * Adds a violation with a single token.
29      *
30      * @param message The violation message.
31      * @param token The token to which the violation applies.
32      */

33     public void addViolation(String JavaDoc message, Token token)
34     {
35         tr.Ace.log("adding violation for " + token + ", " + message);
36         report.addViolation(new Violation(message, token));
37     }
38
39     /**
40      * Adds a violation spanning from one token to another.
41      *
42      * @param message The violation message.
43      * @param firstToken The first token this violation spans.
44      * @param lastToken The last token this violation spans, inclusive.
45      */

46     public void addViolation(String JavaDoc message, Token firstToken, Token lastToken)
47     {
48         tr.Ace.log("adding violation for " + firstToken + ", " + message);
49         report.addViolation(new Violation(message, firstToken, lastToken));
50     }
51
52     /**
53      * Adds a violation from one location to another.
54      *
55      * @param message The violation message.
56      * @param start Where this violation begins.
57      * @param end Where this violation ends, inclusive.
58      */

59     public void addViolation(String JavaDoc message, Location start, Location end)
60     {
61         tr.Ace.log("adding violation for " + message + ", " + start + ", " + end);
62         report.addViolation(new Violation(message, start.line, 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 JavaDoc message, int beginLine, int beginColumn, int endLine, int endColumn)
75     {
76         tr.Ace.log("adding violation for " + message + ", " + beginLine + ":" + beginColumn + ", " + endLine + ":" + endColumn);
77         report.addViolation(new Violation(message, beginLine, beginColumn, endLine, endColumn));
78     }
79
80     /**
81      * Returns the report used by this analyzer.
82      */

83     protected Report getReport()
84     {
85         return report;
86     }
87
88 }
89
Popular Tags