Token.java

biz/hammurapi/antlr/Token.java

Violations

Inspector Message Severity Location
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 086 Use equals() instead of == or != to compare objects. 1 55:22
Java Inspector 086 Use equals() instead of == or != to compare objects. 1 72:22
Java Inspector 082 Parenthesis are redundant. 2 169:37
Java Inspector 082 Parenthesis are redundant. 2 170:44
Java Inspector 089 Type is not documented 2 38:1
Java Inspector 089 Undocumented constructor 2 39:5
Java Inspector 089 Undocumented constructor 2 43:5
Java Inspector 089 Undocumented constructor 2 47:5
Java Inspector 089 Undocumented method 2 54:5
Java Inspector 089 Undocumented method 2 67:5
Java Inspector 089 Undocumented method 2 71:5
Java Inspector 089 Undocumented method 2 84:5
Java Inspector 089 Method is not properly documented 2 93:9
Java Inspector 089 Method is not properly documented 2 100:9
Java Inspector 089 Undocumented method 2 107:9
Java Inspector 089 Undocumented method 2 116:9
Java Inspector 089 Parameter sourceURL is not documented 2 124:9
Java Inspector 089 Undocumented method 2 128:9
Java Inspector 089 Undocumented method 2 157:9
Java Inspector 089 Undocumented method 2 178:9
Java Inspector 089 Undocumented method 2 188:9
Java Inspector 089 Undocumented method 2 201:9

Source code

1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23
24package biz.hammurapi.antlr;
25
26import antlr.CommonToken;
27import biz.hammurapi.legacy.review.SourceMarker;
28import biz.hammurapi.util.PoliteVisitor;
29import biz.hammurapi.util.Visitable;
30import biz.hammurapi.util.Visitor;
31
32
33/**
34 *
35 * @author Pavel Vlasov
36 * @version $Revision: 1.4 $
37 */
38public class Token extends CommonToken implements SourceMarker, Comparable, Visitable {
39 public Token() {
40 super();
41 }
42
43 public Token(String s) {
44 super(s);
45 }
46
47 public Token(int t, String txt) {
48 super(t,txt);
49 }
50
51 private Token nextToken;
52 private Token prevToken;
53
54 public void setNextToken(Token token) {
55 if (nextToken!=token) {
56 nextToken=token;
57 if (nextToken!=null) {
58 nextToken.prevToken=this;
59 }
60
61 if (listener!=null) {
62 listener.onNextTokenChanged(this);
63 }
64 }
65 }
66
67 public Token getNextToken() {
68 return nextToken;
69 }
70
71 public void setPrevToken(Token token) {
72 if (prevToken!=token) {
73 prevToken=token;
74 if (prevToken!=null) {
75 prevToken.nextToken=this;
76 }
77
78 if (listener!=null) {
79 listener.onPrevTokenChanged(this);
80 }
81 }
82 }
83
84 public Token getPrevToken() {
85 return prevToken;
86 }
87
88 private TokenListener listener;
89
90 /**
91 * @return Returns the listener.
92 */
93 public TokenListener getListener() {
94 return listener;
95 }
96
97 /**
98 * @param listener The listener to set.
99 */
100 public void setListener(TokenListener listener) {
101 this.listener = listener;
102 }
103
104 /* (non-Javadoc)
105 * @see antlr.Token#setText(java.lang.String)
106 */
107 public void setText(String newText) {
108 super.setText(newText);
109 if (listener!=null) {
110 listener.onTextChanged(this);
111 }
112 }
113
114 private String sourceURL;
115
116 public String getSourceURL() {
117 return sourceURL;
118 }
119
120 /**
121 * Sets source URL for this and all subsequent tokens.
122 * @param sourceURL
123 */
124 public void setSourceURL(String sourceURL) {
125 this.sourceURL=sourceURL;
126 }
127
128 public int compareTo(Object o) {
129 if (o==this) {
130 return 0;
131 }
132
133 if (o==null) {
134 return -1;
135 }
136
137 if (o instanceof Token) {
138 Token t=(Token) o;
139 if (t.getLine()==getLine()) {
140 if (t.getColumn()==getColumn()) {
141 if (getText()==null) {
142 return t.getText()==null ? 0 : 1;
143 }
144
145 return t.getText()==null ? -1 : getText().compareTo(t.getText());
146 }
147
148 return getColumn()-t.getColumn();
149 }
150
151 return getLine()-t.getLine();
152 }
153
154 return hashCode() - o.hashCode();
155 }
156
157 public boolean equals(Object obj) {
158 if (obj==this) {
159 return true;
160 }
161
162 if (obj==null) {
163 return false;
164 }
165
166 if (obj instanceof Token && getClass().equals(obj.getClass())) {
167 Token t=(Token) obj;
168 return getType() == t.getType()
169 && ((getText() == null && t.getText() == null)
170 || (getText() != null
171 && t.getText() != null
172 && getText().equals(t.getText())));
173 }
174
175 return super.equals(obj);
176 }
177
178 public int hashCode() {
179 int ret=getType();
180 ret^=getClass().getName().hashCode();
181
182 if (getText()!=null) {
183 ret^=getText().hashCode();
184 }
185 return ret;
186 }
187
188 public boolean accept(Visitor visitor) {
189 for (Token t=this; t!=null; t=t.getNextToken()) {
190 if (visitor.visit(t)) {
191 if (visitor instanceof PoliteVisitor) {
192 ((PoliteVisitor) visitor).leave(t);
193 }
194 } else {
195 return false;
196 }
197 }
198 return true;
199 }
200
201 public Integer getSourceId() {
202 return null;
203 }
204}
205