01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2004-2007 Robert Grimm
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public License
07: * version 2.1 as published by the Free Software Foundation.
08: *
09: * This library 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 GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; 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: * The superclass of all annotations. An annotation adds information
23: * (such as comments) to an abstract syntax tree node; it is usually
24: * ignored while processing the AST.
25: *
26: * @author Robert Grimm
27: * @version $Revision: 1.17 $
28: */
29: public abstract class Annotation extends Node {
30:
31: /** The annotated node. */
32: Node node;
33:
34: /** Create a new, empty annotation. */
35: public Annotation() {
36: node = null;
37: }
38:
39: /**
40: * Create a new annotation for the specified node.
41: *
42: * @param node The node.
43: */
44: public Annotation(Node node) {
45: this .node = node;
46: }
47:
48: public String getTokenText() {
49: return node.getTokenText();
50: }
51:
52: public boolean isAnnotation() {
53: return true;
54: }
55:
56: public Annotation toAnnotation() {
57: return this ;
58: }
59:
60: /**
61: * Get the annotated node.
62: *
63: * @return The annotated node.
64: */
65: public Node getNode() {
66: return node;
67: }
68:
69: /**
70: * Set the annotated node.
71: *
72: * @param node The new node.
73: */
74: public void setNode(Node node) {
75: this .node = node;
76: }
77:
78: public Node strip() {
79: return null == node ? null : node.strip();
80: }
81:
82: /**
83: * Return the inner-most annotation. This method strips all nested
84: * annotations, starting with this annotation, until it reaches the
85: * inner-most annotation.
86: *
87: * @return The inner-most annotation.
88: */
89: public Annotation innerMost() {
90: Annotation n = this ;
91:
92: while (n.node instanceof Annotation) {
93: n = (Annotation) n.node;
94: }
95:
96: return n;
97: }
98:
99: }
|