KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > retouche > source > Comment


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.retouche.source;
21
22 //import org.netbeans.jackpot.query.Query;
23

24 /**
25  * This file is originally from Retouche, the Java Support
26  * infrastructure in NetBeans. I have modified the file as little
27  * as possible to make merging Retouche fixes back as simple as
28  * possible.
29  *
30  * An individual comment, consisting of a style, begin and end source
31  * file position, the indention (column) of its first character, and its text.
32  */

33 public final class Comment {
34     private Style style;
35     private int pos;
36     private int endPos;
37     private int indent;
38     private String JavaDoc text;
39
40     /**
41      * The set of different comment types.
42      */

43     public enum Style {
44         /**
45          * A line (double-slash) comment.
46          */

47         LINE,
48         
49         /**
50          * A block comment.
51          */

52         BLOCK,
53         
54         /**
55          * A JavaDoc comment.
56          */

57         JAVADOC,
58     }
59
60     /**
61      * Define a new block comment from a string. This comment does not
62      * have source file positions.
63      */

64 // public static Comment create(String s) {
65
// return new Comment(Style.BLOCK, Query.NOPOS, Query.NOPOS, Query.NOPOS, s);
66
// }
67

68     public static Comment create(Style style, int pos, int endPos, int indent, String JavaDoc text) {
69         return new Comment(style, pos, endPos, indent, text);
70     }
71     
72     /**
73      * Define a comment, using source file positions.
74      */

75     private Comment(Style style, int pos, int endPos, int indent, String JavaDoc text) {
76         this.style = style;
77         this.pos = pos;
78         this.endPos = endPos;
79         this.indent = indent;
80         this.text = text;
81     }
82     
83     public Style style() {
84         return style;
85     }
86
87     /**
88      * The start position in the source file, or Query.NOPOS if the
89      * comment was added by a translation operation.
90      */

91     public int pos() {
92         return pos;
93     }
94
95     /**
96      * The end position in the source file, or Query.NOPOS if the
97      * comment was added by a translation operation.
98      */

99     public int endPos() {
100         return endPos;
101     }
102
103     /**
104      * Returns the line indention for this comment, or Query.NOPOS if the
105      * comment was added by a translation operation.
106      */

107     public int indent() {
108         return indent;
109     }
110     
111     /** Returns true if this is a JavaDoc comment. */
112     public boolean isDocComment() {
113         return style == Style.JAVADOC;
114     }
115
116     /**
117      * Returns the comment text.
118      */

119     public String JavaDoc getText() {
120         return text;
121     }
122     
123 // public boolean isNew() {
124
// return pos == Query.NOPOS;
125
// }
126
//
127
public String JavaDoc toString() {
128         StringBuilder JavaDoc sb = new StringBuilder JavaDoc(style.toString());
129         sb.append(" pos=");
130         sb.append(pos);
131         sb.append(" endPos=");
132         sb.append(endPos);
133         sb.append(" indent=");
134         sb.append(indent);
135         sb.append(' ');
136         sb.append(text);
137         return sb.toString();
138     }
139
140     public boolean equals(Object JavaDoc obj) {
141         if (!(obj instanceof Comment))
142             return false;
143         Comment c = (Comment)obj;
144         return c.style == style && c.pos == pos && c.endPos == endPos &&
145             c.indent == indent && c.text.equals(text);
146     }
147
148     public int hashCode() {
149         return style.hashCode() + pos + endPos + indent + text.hashCode();
150     }
151 }
152
Popular Tags