2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu
.javax
.swing
.text
.html
.parser
.support
.low
;
43 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
48 * The place of this token in the document.
50 public Location where
;
53 * The additional category of token.
58 * An integer that describes the kind of this token.
63 * The string image of the token, null if the char image must be used.
65 private String stringImage
;
68 * The char image of the token.
70 private char charImage
;
73 * Creates a new token with fields, initialized to the default values.
80 * Creates a new token of the given kind.
82 public Token(int _kind
, Location _where
)
89 * Creates a new token of the given kind and given single char image.
91 public Token(int _kind
, char _image
, Location _where
)
99 * Creates a new token of the given kind and given string image.
101 public Token(int _kind
, String _image
, Location _where
)
104 stringImage
= _image
;
109 * Creates a new token of the given kind, category and given string image.
111 public Token(int _kind
, int _category
, String _image
, Location _where
)
114 category
= _category
;
115 stringImage
= _image
;
120 * Creates a new token, where location fields are set as for token,
121 * spanning over two provided tokens and any tokens between them.
122 * The image field is initialized to null, the kind field is set to -1.
124 public Token(Token fromInclusive
, Token toInclusive
)
126 where
= new Location();
127 where
.beginLine
= fromInclusive
.where
.beginLine
;
128 where
.startPosition
= fromInclusive
.where
.startPosition
;
130 where
.endLine
= toInclusive
.where
.endLine
;
131 where
.endPosition
= toInclusive
.where
.endPosition
;
134 public String
getImage()
138 if (stringImage
== null)
142 stringImage
= new String(new char[] { charImage
});
148 * Append the token image to the given string buffer.
149 * This may be more effective that buffer.append(this.getImage()).
150 * @param buffer A buffer to append.
152 public void appendTo(StringBuffer buffer
)
155 buffer
.append(getImage());
157 buffer
.append(charImage
);
161 * Returns the string image or, if null, the bounding positions.
163 public String
toString()
165 return getImage() != null ? kind
+ "'" + getImage()
166 : "<line " + where
.beginLine
+ ", abs pos " + where
.startPosition
+
167 ".." + where
.endPosition
+ ">";