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