KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > api > Comment


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.api;
20
21 /**
22  * Representation of the comment block.
23  *
24  * @author o_sukhodolsky
25  */

26 class Comment implements TextBlock
27 {
28     /** text of the comment. */
29     private final String JavaDoc[] mText;
30
31     /** number of first line of the comment. */
32     private final int mFirstLine;
33
34     /** number of last line of the comment. */
35     private final int mLastLine;
36
37     /** number of first column of the comment. */
38     private final int mFirstCol;
39
40     /** number of last column of the comment. */
41     private final int mLastCol;
42
43     /**
44      * Creates new instance.
45      * @param aText the lines that make up the comment.
46      * @param aFirstCol number of the first column of the comment.
47      * @param aLastLine number of the last line of the comment.
48      * @param aLastCol number of the last column of the comment.
49      */

50     public Comment(final String JavaDoc[] aText, final int aFirstCol,
51             final int aLastLine, final int aLastCol)
52     {
53         mText = new String JavaDoc[aText.length];
54         System.arraycopy(aText, 0, mText, 0, mText.length);
55         mFirstLine = aLastLine - mText.length + 1;
56         mLastLine = aLastLine;
57         mFirstCol = aFirstCol;
58         mLastCol = aLastCol;
59     }
60
61     /** {@inheritDoc} */
62     public final String JavaDoc[] getText()
63     {
64         return (String JavaDoc[]) mText.clone();
65     }
66
67     /** {@inheritDoc} */
68     public final int getStartLineNo()
69     {
70         return mFirstLine;
71     }
72
73     /** {@inheritDoc} */
74     public final int getEndLineNo()
75     {
76         return mLastLine;
77     }
78
79     /** {@inheritDoc} */
80     public int getStartColNo()
81     {
82         return mFirstCol;
83     }
84
85     /** {@inheritDoc} */
86     public int getEndColNo()
87     {
88         return mLastCol;
89     }
90
91     /** {@inheritDoc} */
92     public boolean intersects(int aStartLineNo, int aStartColNo,
93                               int aEndLineNo, int aEndColNo)
94     {
95         // compute a single number for start and end
96
// to simpify conditional logic
97
final long multiplier = Integer.MAX_VALUE;
98         final long thisStart = mFirstLine * multiplier + mFirstCol;
99         final long thisEnd = mLastLine * multiplier + mLastCol;
100         final long inStart = aStartLineNo * multiplier + aStartColNo;
101         final long inEnd = aEndLineNo * multiplier + aEndColNo;
102
103         return !((thisEnd < inStart) || (inEnd < thisStart));
104     }
105
106     /** {@inheritDoc} */
107     public String JavaDoc toString()
108     {
109         return "Comment[" + mFirstLine + ":" + mFirstCol + "-"
110             + mLastLine + ":" + mLastCol + "]";
111     }
112 }
113
Popular Tags