KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > groovy > antlr > GroovySourceAST


1 package org.codehaus.groovy.antlr;
2
3 import antlr.collections.AST;
4 import antlr.*;
5
6 /**
7  * We have an AST subclass so we can track source information.
8  * Very odd that ANTLR doesn't do this by default.
9  *
10  * @author Mike Spille
11  * @author Jeremy Rayner <groovy@ross-rayner.com>
12  */

13 public class GroovySourceAST extends CommonAST implements Comparable JavaDoc {
14     private int line;
15     private int col;
16     private int lineLast;
17     private int colLast;
18     private String JavaDoc snippet;
19
20     public GroovySourceAST() {
21     }
22
23     public GroovySourceAST(Token t) {
24         super(t);
25     }
26
27     public void initialize(AST ast) {
28         super.initialize(ast);
29         line = ast.getLine();
30         col = ast.getColumn();
31     }
32
33     public void initialize(Token t) {
34         super.initialize(t);
35         line = t.getLine();
36         col = t.getColumn();
37     }
38
39     public void setLast(Token last) {
40         lineLast = last.getLine();
41         colLast = last.getColumn();
42     }
43
44     public int getLineLast() {
45         return lineLast;
46     }
47
48     public void setLineLast(int lineLast) {
49         this.lineLast = lineLast;
50     }
51
52     public int getColumnLast() {
53         return colLast;
54     }
55
56     public void setColumnLast(int colLast) {
57         this.colLast = colLast;
58     }
59
60     public void setLine(int line) {
61         this.line = line;
62     }
63
64     public int getLine() {
65         return (line);
66     }
67
68     public void setColumn(int column) {
69         this.col = column;
70     }
71
72     public int getColumn() {
73         return (col);
74     }
75
76     public void setSnippet(String JavaDoc snippet) {
77         this.snippet = snippet;
78     }
79
80     public String JavaDoc getSnippet() {
81         return snippet;
82     }
83
84     public int compareTo(Object JavaDoc object) {
85         if (object == null) {
86             return 0;
87         }
88         if (!(object instanceof AST)) {
89             return 0;
90         }
91         AST that = (AST) object;
92
93         // todo - possibly check for line/col with values of 0 or less...
94

95         if (this.getLine() < that.getLine()) {
96             return -1;
97         }
98         if (this.getLine() > that.getLine()) {
99             return 1;
100         }
101
102         if (this.getColumn() < that.getColumn()) {
103             return -1;
104         }
105         if (this.getColumn() > that.getColumn()) {
106             return 1;
107         }
108
109         return 0;
110     }
111 }
112
Popular Tags