KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > javadoc > HtmlTag


1 ////////////////////////////////////////////////////////////////////////////////
2
// checkstyle: Checks Java source code for adherence to a set of rules.
3
// Copyright (C) 2001-2005 Oliver Burn
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation; either
8
// version 2.1 of the License, or (at your option) any later version.
9
//
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// Lesser General Public License for more details.
14
//
15
// You should have received a copy of the GNU Lesser General Public
16
// License along with this library; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
////////////////////////////////////////////////////////////////////////////////
19
package com.puppycrawl.tools.checkstyle.checks.javadoc;
20
21 /**
22  * Used to keep track of a tag and the text that follows it.
23  *
24  * @author Chris Stillwell
25  */

26 class HtmlTag
27 {
28     /** The maximum length of text to display with this tag. */
29     private static final int MAX_TEXT_LEN = 60;
30
31     /** The HTML tag name. */
32     private final String JavaDoc mId;
33
34     /** The line number in the source file where this tag was found. */
35     private final int mLineNo;
36
37     /** The position within the line where this tag was found. */
38     private final int mPosition;
39
40     /** The comment line of text where this tag appears. */
41     private final String JavaDoc mText;
42
43     /** if this tag is self-closed. */
44     private final boolean mClosedTag;
45
46     /** if the tag is inomplete. */
47     private final boolean mIncomplete;
48
49     /**
50      * Construct the HtmlTag.
51      * @param aId the HTML tag name.
52      * @param aLineNo the source line number of this tag.
53      * @param aPosition the position within the text of this tag.
54      * @param aClosedTag if this tag is self-closed (XHTML style)
55      * @param aIncomplete is the tag is incomplete.
56      * @param aText the line of comment text for this tag.
57      */

58     HtmlTag(String JavaDoc aId, int aLineNo, int aPosition, boolean aClosedTag,
59             boolean aIncomplete, String JavaDoc aText)
60     {
61         mId = (!"".equals(aId) && (aId.charAt(0) == '/'))
62             ? aId.substring(1) : aId;
63         mLineNo = aLineNo;
64         mPosition = aPosition;
65         mText = aText;
66         mClosedTag = aClosedTag;
67         mIncomplete = aIncomplete;
68     }
69
70     /**
71      * Returns the id (name) of this tag.
72      * @return a String id.
73      */

74     public String JavaDoc getId()
75     {
76         return mId;
77     }
78
79     /**
80      * Indicates if this tag is a close (end) tag.
81      * @return <code>true</code> is this is a close tag.
82      */

83     public boolean isCloseTag()
84     {
85         if (mPosition == (mText.length() - 1)) {
86             return false;
87         }
88         return (mText.charAt(mPosition + 1) == '/');
89     }
90
91     /**
92      * Indicates if this tag is a self-closed XHTML style.
93      * @return <code>true</code> is this is a self-closed tag.
94      */

95     public boolean isClosedTag()
96     {
97         return mClosedTag;
98     }
99
100     /**
101      * Indicates if this tag is incomplete (has no close &gt;).
102      * @return <code>true</code> if the tag is incomplete.
103      */

104     public boolean isIncompleteTag()
105     {
106         return mIncomplete;
107     }
108
109     /**
110      * Returns the source line number where this tag was found.
111      * Used for displaying a Checkstyle error.
112      * @return an int line number.
113      */

114     public int getLineno()
115     {
116         return mLineNo;
117     }
118
119     /**
120      * Returns the position with in the comment line where this tag
121      * was found. Used for displaying a Checkstyle error.
122      * @return an int relative to zero.
123      */

124     public int getPosition()
125     {
126         return mPosition;
127     }
128
129     /**
130      * Returns this HTML tag and trailing text.
131      * Used for displaying a Checkstyle error.
132      * @return the String text of this tag.
133      */

134     public String JavaDoc toString()
135     {
136         final int startOfText = mPosition;
137         final int endOfText =
138             Math.min(startOfText + HtmlTag.MAX_TEXT_LEN, mText.length());
139         return mText.substring(startOfText, endOfText);
140     }
141 }
142
Popular Tags