01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2005-2006 Robert Grimm
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * version 2 as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.tree;
20:
21: /**
22: * A source identity marker.
23: *
24: * @author Robert Grimm
25: * @version $Revision: 1.4 $
26: */
27: public class SourceIdentity extends Annotation {
28:
29: /** The text of the source identity marker. */
30: public String ident;
31:
32: /**
33: * Create a new source identity marker.
34: *
35: * @param ident The actual identity.
36: * @param node The node.
37: */
38: public SourceIdentity(String ident, Node node) {
39: super (node);
40: this .ident = ident;
41: }
42:
43: public boolean hasTraversal() {
44: return true;
45: }
46:
47: public int size() {
48: return 2;
49: }
50:
51: public Object get(int index) {
52: switch (index) {
53: case 0:
54: return ident;
55: case 1:
56: return node;
57: default:
58: throw new IndexOutOfBoundsException("Index: " + index
59: + ", Size: 2");
60: }
61: }
62:
63: public Object set(int index, Object value) {
64: Object old;
65:
66: switch (index) {
67: case 0:
68: old = ident;
69: ident = (String) value;
70: return old;
71: case 1:
72: old = node;
73: node = (Node) value;
74: return old;
75: default:
76: throw new IndexOutOfBoundsException("Index: " + index
77: + ", Size: 2");
78: }
79: }
80:
81: public int hashCode() {
82: return ident.hashCode();
83: }
84:
85: public boolean equals(Object o) {
86: if (this == o)
87: return true;
88: if (!(o instanceof SourceIdentity))
89: return false;
90: SourceIdentity other = (SourceIdentity) o;
91: if (!ident.equals(other.ident))
92: return false;
93: if (null == node)
94: return (null == other.node);
95: return node.equals(other.node);
96: }
97:
98: }
|