01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2004, 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 pragma.
23: *
24: * @author Robert Grimm
25: * @version $Revision: 1.3 $
26: */
27: public class Pragma extends Annotation {
28:
29: /** The text of the pragma. */
30: public String directive;
31:
32: /**
33: * Create a new pragma.
34: *
35: * @param directive The actual directive.
36: * @param node The node.
37: */
38: public Pragma(String directive, Node node) {
39: super (node);
40: this .directive = directive;
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 directive;
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 = directive;
69: directive = (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 directive.hashCode();
83: }
84:
85: public boolean equals(Object o) {
86: if (this == o)
87: return true;
88: if (!(o instanceof Pragma))
89: return false;
90: Pragma other = (Pragma) o;
91: if (!directive.equals(other.directive))
92: return false;
93: if (null == node)
94: return (null == other.node);
95: return node.equals(other.node);
96: }
97:
98: }
|