Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / javax / swing / text / html / parser / support / low / Token.java
blobd91adf47ab8689538dee6ccd6e363c2010dcfdea
1 /* Token.java --
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)
9 any later version.
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
19 02110-1301 USA.
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
24 combination.
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;
41 /**
42 * A token.
43 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
45 public class Token
47 /**
48 * The place of this token in the document.
50 public Location where;
52 /**
53 * The additional category of token.
55 public int category;
57 /**
58 * An integer that describes the kind of this token.
60 public int kind;
62 /**
63 * The string image of the token, null if the char image must be used.
65 private String stringImage;
67 /**
68 * The char image of the token.
70 private char charImage;
72 /**
73 * Creates a new token with fields, initialized to the default values.
75 public Token()
79 /**
80 * Creates a new token of the given kind.
82 public Token(int _kind, Location _where)
84 kind = _kind;
85 where = _where;
88 /**
89 * Creates a new token of the given kind and given single char image.
91 public Token(int _kind, char _image, Location _where)
93 kind = _kind;
94 charImage = _image;
95 where = _where;
98 /**
99 * Creates a new token of the given kind and given string image.
101 public Token(int _kind, String _image, Location _where)
103 kind = _kind;
104 stringImage = _image;
105 where = _where;
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)
113 kind = _kind;
114 category = _category;
115 stringImage = _image;
116 where = _where;
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()
136 if (kind == 3)
137 return "#";
138 if (stringImage == null)
140 if (charImage == 0)
141 return null;
142 stringImage = new String(new char[] { charImage });
144 return stringImage;
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)
154 if (charImage == 0)
155 buffer.append(getImage());
156 else
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 + ">";