Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/puppycrawl/tools/checkstyle/checks/javadoc/HtmlTag.java


1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2003  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 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 mText;
42  
43      /**
44       * Construct the HtmlTag.
45       * @param aId the HTML tag name.
46       * @param aLineNo the source line number of this tag.
47       * @param aPosition the position within the text of this tag.
48       * @param aText the line of comment text for this tag.
49       */
50      HtmlTag(String aId, int aLineNo, int aPosition, String aText)
51      {
52          mId = (aId.charAt(0) == '/') ? aId.substring(1) : aId;
53          mLineNo = aLineNo;
54          mPosition = aPosition;
55          mText = aText;
56      }
57  
58      /**
59       * Returns the id (name) of this tag.
60       * @return a String id.
61       */
62      public String getId()
63      {
64          return mId;
65      }
66  
67      /**
68       * Indicates if this tag is a close (end) tag.
69       * @return <code>true</code> is this is a close tag.
70       */
71      public boolean isCloseTag()
72      {
73          return (mText.charAt(mPosition + 1) == '/');
74      }
75  
76      /**
77       * Returns the source line number where this tag was found.
78       * Used for displaying a Checkstyle error.
79       * @return an int line number.
80       */
81      public int getLineno()
82      {
83          return mLineNo;
84      }
85  
86      /**
87       * Returns the position with in the comment line where this tag
88       * was found.  Used for displaying a Checkstyle error.
89       * @return an int relative to zero.
90       */
91      public int getPosition()
92      {
93          return mPosition;
94      }
95  
96      /**
97       * Returns this HTML tag and trailing text.
98       * Used for displaying a Checkstyle error.
99       * @return the String text of this tag.
100      */
101     public String toString()
102     {
103         final int startOfText = mPosition;
104         final int endOfText =
105             Math.min(startOfText + HtmlTag.MAX_TEXT_LEN, mText.length());
106         return mText.substring(startOfText, endOfText);
107     }
108 }