1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.puppycrawl.tools.checkstyle.api;
20
21
22
23
24
25
26 public class Comment implements TextBlock
27 {
28
29 private final String[] text;
30
31
32 private final int firstLine;
33
34
35 private final int lastLine;
36
37
38 private final int firstCol;
39
40
41 private final int lastCol;
42
43
44
45
46
47
48
49
50 public Comment(final String[] text, final int firstCol,
51 final int lastLine, final int lastCol)
52 {
53 this.text = new String[text.length];
54 System.arraycopy(text, 0, this.text, 0, this.text.length);
55 firstLine = lastLine - this.text.length + 1;
56 this.lastLine = lastLine;
57 this.firstCol = firstCol;
58 this.lastCol = lastCol;
59 }
60
61
62 @Override
63 public final String[] getText()
64 {
65 return text.clone();
66 }
67
68
69 @Override
70 public final int getStartLineNo()
71 {
72 return firstLine;
73 }
74
75
76 @Override
77 public final int getEndLineNo()
78 {
79 return lastLine;
80 }
81
82
83 @Override
84 public int getStartColNo()
85 {
86 return firstCol;
87 }
88
89
90 @Override
91 public int getEndColNo()
92 {
93 return lastCol;
94 }
95
96
97 @Override
98 public boolean intersects(int startLineNo, int startColNo,
99 int endLineNo, int endColNo)
100 {
101
102
103 final long multiplier = Integer.MAX_VALUE;
104 final long thisStart = firstLine * multiplier + firstCol;
105 final long thisEnd = lastLine * multiplier + lastCol;
106 final long inStart = startLineNo * multiplier + startColNo;
107 final long inEnd = endLineNo * multiplier + endColNo;
108
109 return !((thisEnd < inStart) || (inEnd < thisStart));
110 }
111
112 @Override
113 public String toString()
114 {
115 return "Comment[" + firstLine + ":" + firstCol + "-"
116 + lastLine + ":" + lastCol + "]";
117 }
118 }