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
53 public Comment(final String[] text, final int firstCol,
54 final int lastLine, final int lastCol) {
55 this.text = text.clone();
56 startLineNo = lastLine - text.length + 1;
57 endLineNo = lastLine;
58 startColNo = firstCol;
59 endColNo = lastCol;
60 }
61
62 @Override
63 public final String[] getText() {
64 return text.clone();
65 }
66
67 @Override
68 public final int getStartLineNo() {
69 return startLineNo;
70 }
71
72 @Override
73 public final int getEndLineNo() {
74 return endLineNo;
75 }
76
77 @Override
78 public int getStartColNo() {
79 return startColNo;
80 }
81
82 @Override
83 public int getEndColNo() {
84 return endColNo;
85 }
86
87 @Override
88 public boolean intersects(int startLine, int startCol,
89 int endLine, int endCol) {
90
91
92 final long multiplier = Integer.MAX_VALUE;
93 final long thisStart = startLineNo * multiplier + startColNo;
94 final long thisEnd = endLineNo * multiplier + endColNo;
95 final long inStart = startLine * multiplier + startCol;
96 final long inEnd = endLine * multiplier + endCol;
97
98 return thisEnd >= inStart && inEnd >= thisStart;
99 }
100
101 @Override
102 public String toString() {
103 return "Comment[text=" + Arrays.toString(text)
104 + ", startLineNo=" + startLineNo
105 + ", endLineNo=" + endLineNo
106 + ", startColNo=" + startColNo
107 + ", endColNo=" + endColNo + ']';
108 }
109
110 }