Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Comment |
|
| 1.125;1.125 |
1 | //////////////////////////////////////////////////////////////////////////////// | |
2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
3 | // Copyright (C) 2001-2014 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 | public class Comment implements TextBlock | |
27 | { | |
28 | /** text of the comment. */ | |
29 | private final String[] 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[] aText, final int aFirstCol, | |
51 | final int aLastLine, final int aLastCol) | |
52 | 10080 | { |
53 | 10080 | mText = new String[aText.length]; |
54 | 10080 | System.arraycopy(aText, 0, mText, 0, mText.length); |
55 | 10080 | mFirstLine = aLastLine - mText.length + 1; |
56 | 10080 | mLastLine = aLastLine; |
57 | 10080 | mFirstCol = aFirstCol; |
58 | 10080 | mLastCol = aLastCol; |
59 | 10080 | } |
60 | ||
61 | /** {@inheritDoc} */ | |
62 | public final String[] getText() | |
63 | { | |
64 | 1245 | return mText.clone(); |
65 | } | |
66 | ||
67 | /** {@inheritDoc} */ | |
68 | public final int getStartLineNo() | |
69 | { | |
70 | 858 | return mFirstLine; |
71 | } | |
72 | ||
73 | /** {@inheritDoc} */ | |
74 | public final int getEndLineNo() | |
75 | { | |
76 | 6 | return mLastLine; |
77 | } | |
78 | ||
79 | /** {@inheritDoc} */ | |
80 | public int getStartColNo() | |
81 | { | |
82 | 253 | return mFirstCol; |
83 | } | |
84 | ||
85 | /** {@inheritDoc} */ | |
86 | public int getEndColNo() | |
87 | { | |
88 | 14 | 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 | 1144 | final long multiplier = Integer.MAX_VALUE; |
98 | 1144 | final long thisStart = mFirstLine * multiplier + mFirstCol; |
99 | 1144 | final long thisEnd = mLastLine * multiplier + mLastCol; |
100 | 1144 | final long inStart = aStartLineNo * multiplier + aStartColNo; |
101 | 1144 | final long inEnd = aEndLineNo * multiplier + aEndColNo; |
102 | ||
103 | 1144 | return !((thisEnd < inStart) || (inEnd < thisStart)); |
104 | } | |
105 | ||
106 | @Override | |
107 | public String toString() | |
108 | { | |
109 | 0 | return "Comment[" + mFirstLine + ":" + mFirstCol + "-" |
110 | + mLastLine + ":" + mLastCol + "]"; | |
111 | } | |
112 | } |