001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.napi.gsfret.source;
043:
044: //import org.netbeans.jackpot.query.Query;
045:
046: /**
047: * This file is originally from Retouche, the Java Support
048: * infrastructure in NetBeans. I have modified the file as little
049: * as possible to make merging Retouche fixes back as simple as
050: * possible.
051: *
052: * An individual comment, consisting of a style, begin and end source
053: * file position, the indention (column) of its first character, and its text.
054: */
055: public final class Comment {
056: private Style style;
057: private int pos;
058: private int endPos;
059: private int indent;
060: private String text;
061:
062: /**
063: * The set of different comment types.
064: */
065: public enum Style {
066: /**
067: * A line (double-slash) comment.
068: */
069: LINE,
070:
071: /**
072: * A block comment.
073: */
074: BLOCK,
075:
076: /**
077: * A JavaDoc comment.
078: */
079: JAVADOC,
080: }
081:
082: /**
083: * Define a new block comment from a string. This comment does not
084: * have source file positions.
085: */
086: // public static Comment create(String s) {
087: // return new Comment(Style.BLOCK, Query.NOPOS, Query.NOPOS, Query.NOPOS, s);
088: // }
089: public static Comment create(Style style, int pos, int endPos,
090: int indent, String text) {
091: return new Comment(style, pos, endPos, indent, text);
092: }
093:
094: /**
095: * Define a comment, using source file positions.
096: */
097: private Comment(Style style, int pos, int endPos, int indent,
098: String text) {
099: this .style = style;
100: this .pos = pos;
101: this .endPos = endPos;
102: this .indent = indent;
103: this .text = text;
104: }
105:
106: public Style style() {
107: return style;
108: }
109:
110: /**
111: * The start position in the source file, or Query.NOPOS if the
112: * comment was added by a translation operation.
113: */
114: public int pos() {
115: return pos;
116: }
117:
118: /**
119: * The end position in the source file, or Query.NOPOS if the
120: * comment was added by a translation operation.
121: */
122: public int endPos() {
123: return endPos;
124: }
125:
126: /**
127: * Returns the line indention for this comment, or Query.NOPOS if the
128: * comment was added by a translation operation.
129: */
130: public int indent() {
131: return indent;
132: }
133:
134: /** Returns true if this is a JavaDoc comment. */
135: public boolean isDocComment() {
136: return style == Style.JAVADOC;
137: }
138:
139: /**
140: * Returns the comment text.
141: */
142: public String getText() {
143: return text;
144: }
145:
146: // public boolean isNew() {
147: // return pos == Query.NOPOS;
148: // }
149: //
150: public String toString() {
151: StringBuilder sb = new StringBuilder(style.toString());
152: sb.append(" pos=");
153: sb.append(pos);
154: sb.append(" endPos=");
155: sb.append(endPos);
156: sb.append(" indent=");
157: sb.append(indent);
158: sb.append(' ');
159: sb.append(text);
160: return sb.toString();
161: }
162:
163: public boolean equals(Object obj) {
164: if (!(obj instanceof Comment))
165: return false;
166: Comment c = (Comment) obj;
167: return c.style == style && c.pos == pos && c.endPos == endPos
168: && c.indent == indent && c.text.equals(text);
169: }
170:
171: public int hashCode() {
172: return style.hashCode() + pos + endPos + indent
173: + text.hashCode();
174: }
175: }
|