1 /*******************************************************************************
2 * Copyright (c) 2004, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.core.dom;
14 * Abstract base class for all AST nodes that represent comments.
15 * There are exactly three kinds of comment:
16 * line comments ({@link LineComment}),
17 * block comments ({@link BlockComment}), and
18 * doc comments ({@link Javadoc}).
30 public abstract class Comment extends ASTNode {
33 * Alternate root node, or <code>null</code> if none.
34 * Initially <code>null</code>.
36 private ASTNode alternateRoot = null;
39 * Creates a new AST node for a comment owned by the given AST.
41 * N.B. This constructor is package-private.
44 * @param ast the AST that is to own this node
51 * Returns whether this comment is a block comment
52 * (<code>BlockComment</code>).
54 * @return <code>true</code> if this is a block comment, and
55 * <code>false</code> otherwise
57 public final boolean isBlockComment() {
58 return (this instanceof BlockComment);
62 * Returns whether this comment is a line comment
63 * (<code>LineComment</code>).
65 * @return <code>true</code> if this is a line comment, and
66 * <code>false</code> otherwise
68 public final boolean isLineComment() {
69 return (this instanceof LineComment);
73 * Returns whether this comment is a doc comment
74 * (<code>Javadoc</code>).
76 * @return <code>true</code> if this is a doc comment, and
77 * <code>false</code> otherwise
79 public final boolean isDocComment() {
80 return (this instanceof Javadoc);
84 * Returns the root AST node that this comment occurs
85 * within, or <code>null</code> if none (or not recorded).
87 * Typically, the comment nodes created while parsing a compilation
88 * unit are not considered descendents of the normal AST
89 * root, namely an {@link CompilationUnit}. Instead, these
90 * comment nodes exist outside the normal AST and each is
91 * a root in its own right. This optional property provides
92 * a well-known way to navigate from the comment to the
93 * compilation unit in such cases. Note that the alternate root
94 * property is not one of the comment node's children. It is simply a
95 * reference to a node.
98 * @return the alternate root node, or <code>null</code>
100 * @see #setAlternateRoot(ASTNode)
102 public final ASTNode getAlternateRoot() {
103 return this.alternateRoot;
107 * Returns the root AST node that this comment occurs
108 * within, or <code>null</code> if none (or not recorded).
112 * @param root the alternate root node, or <code>null</code>
114 * @see #getAlternateRoot()
116 public final void setAlternateRoot(ASTNode root) {
117 // alternate root is *not* considered a structural property
118 // but we protect them nevertheless
120 this.alternateRoot = root;
123 /* (omit javadoc for this method)
124 * Method declared on ASTNode.
127 return BASE_NODE_SIZE + 1 * 4;