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.checks.indentation;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_CHILD_ERROR;
24 import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_CHILD_ERROR_MULTI;
25 import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_ERROR;
26 import static com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck.MSG_ERROR_MULTI;
27
28 import java.io.BufferedReader;
29 import java.io.IOException;
30 import java.nio.charset.StandardCharsets;
31 import java.nio.file.Files;
32 import java.nio.file.Path;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.List;
36 import java.util.Locale;
37 import java.util.regex.Matcher;
38 import java.util.regex.Pattern;
39
40 import org.junit.jupiter.api.Test;
41
42 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
43 import com.puppycrawl.tools.checkstyle.Checker;
44 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
45 import com.puppycrawl.tools.checkstyle.api.AuditEvent;
46 import com.puppycrawl.tools.checkstyle.api.AuditListener;
47 import com.puppycrawl.tools.checkstyle.api.Configuration;
48 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
49
50
51
52
53 public class IndentationCheckTest extends AbstractModuleTestSupport {
54
55 private static final Pattern LINE_WITH_COMMENT_REGEX =
56 Pattern.compile(".*?//indent:(\\d+)(?: ioffset:(\\d+))?"
57 + " exp:(>=)?(\\d+(?:,\\d+)*?)( warn)?$");
58
59 private static final IndentComment[] EMPTY_INDENT_COMMENT_ARRAY = new IndentComment[0];
60
61 private static IndentComment[] getLinesWithWarnAndCheckComments(String aFileName,
62 final int tabWidth)
63 throws IOException {
64 final List<IndentComment> result = new ArrayList<>();
65 try (BufferedReader br = Files.newBufferedReader(Path.of(aFileName),
66 StandardCharsets.UTF_8)) {
67 int lineNumber = 1;
68 for (String line = br.readLine(); line != null; line = br.readLine()) {
69 final Matcher match = LINE_WITH_COMMENT_REGEX.matcher(line);
70 if (match.matches()) {
71 final IndentComment warn = new IndentComment(match, lineNumber);
72 final int actualIndent = getLineStart(line, tabWidth);
73
74 if (actualIndent != warn.getIndent()) {
75 throw new IllegalStateException(String.format(Locale.ROOT,
76 "File \"%1$s\" has incorrect indentation in comment. "
77 + "Line %2$d: comment:%3$d, actual:%4$d.",
78 aFileName,
79 lineNumber,
80 warn.getIndent(),
81 actualIndent));
82 }
83
84 if (!isCommentConsistent(warn)) {
85 throw new IllegalStateException(String.format(Locale.ROOT,
86 "File \"%1$s\" has inconsistent comment on line %2$d",
87 aFileName,
88 lineNumber));
89 }
90
91 if (warn.isWarning()) {
92 result.add(warn);
93 }
94 }
95 else if (!line.isEmpty()) {
96 throw new IllegalStateException(String.format(Locale.ROOT,
97 "File \"%1$s\" has no indentation comment or its format "
98 + "malformed. Error on line: %2$d",
99 aFileName,
100 lineNumber));
101 }
102 lineNumber++;
103 }
104 }
105 return result.toArray(EMPTY_INDENT_COMMENT_ARRAY);
106 }
107
108 private static boolean isCommentConsistent(IndentComment comment) {
109 final String[] levels = comment.getExpectedWarning().split(", ");
110 final int indent = comment.getIndent() + comment.getIndentOffset();
111 final boolean result;
112 if (levels.length > 1) {
113
114 final boolean containsActualLevel =
115 Arrays.asList(levels).contains(String.valueOf(indent));
116
117 result = containsActualLevel != comment.isWarning();
118 }
119 else {
120 final int expectedWarning = Integer.parseInt(comment.getExpectedWarning());
121
122 final boolean test;
123 if (comment.isExpectedNonStrict()) {
124
125 test = indent >= expectedWarning;
126 }
127 else {
128
129 test = expectedWarning == indent;
130 }
131 result = test != comment.isWarning();
132
133 }
134 return result;
135 }
136
137 private static int getLineStart(String line, final int tabWidth) {
138 int lineStart = 0;
139 for (int index = 0; index < line.length(); ++index) {
140 if (!Character.isWhitespace(line.charAt(index))) {
141 lineStart = CommonUtil.lengthExpandedTabs(line, index, tabWidth);
142 break;
143 }
144 }
145 return lineStart;
146 }
147
148 private void verifyWarns(Configuration config, String filePath,
149 String... expected)
150 throws Exception {
151 final int tabWidth = Integer.parseInt(config.getProperty("tabWidth"));
152 final IndentComment[] linesWithWarn =
153 getLinesWithWarnAndCheckComments(filePath, tabWidth);
154 verify(config, filePath, expected, linesWithWarn);
155 assertWithMessage("Expected warning count in UT does not match warn comment count "
156 + "in input file")
157 .that(expected.length)
158 .isEqualTo(linesWithWarn.length);
159 }
160
161 private void verify(Configuration config, String filePath, String[] expected,
162 final IndentComment... linesWithWarn) throws Exception {
163 final Checker checker = createChecker(config);
164 checker.addListener(new IndentAudit(linesWithWarn));
165 verify(checker, filePath, expected);
166 }
167
168 @Override
169 protected String getPackageLocation() {
170 return "com/puppycrawl/tools/checkstyle/checks/indentation/indentation";
171 }
172
173 @Test
174 public void testGetRequiredTokens() {
175 final IndentationCheck checkObj = new IndentationCheck();
176 final int[] requiredTokens = checkObj.getRequiredTokens();
177 final HandlerFactory handlerFactory = new HandlerFactory();
178 final int[] expected = handlerFactory.getHandledTypes();
179 Arrays.sort(expected);
180 Arrays.sort(requiredTokens);
181 assertWithMessage("Default required tokens are invalid")
182 .that(requiredTokens)
183 .isEqualTo(expected);
184 }
185
186 @Test
187 public void testGetAcceptableTokens() {
188 final IndentationCheck checkObj = new IndentationCheck();
189 final int[] acceptableTokens = checkObj.getAcceptableTokens();
190 final HandlerFactory handlerFactory = new HandlerFactory();
191 final int[] expected = handlerFactory.getHandledTypes();
192 Arrays.sort(expected);
193 Arrays.sort(acceptableTokens);
194 assertWithMessage("Default acceptable tokens are invalid")
195 .that(acceptableTokens)
196 .isEqualTo(expected);
197 }
198
199 @Test
200 public void testThrowsIndentProperty() {
201 final IndentationCheck indentationCheck = new IndentationCheck();
202
203 indentationCheck.setThrowsIndent(1);
204
205 assertWithMessage("Invalid throws indent")
206 .that(indentationCheck.getThrowsIndent())
207 .isEqualTo(1);
208 }
209
210 @Test
211 public void testStrictCondition() throws Exception {
212 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
213 checkConfig.addProperty("arrayInitIndent", "4");
214 checkConfig.addProperty("basicOffset", "4");
215 checkConfig.addProperty("braceAdjustment", "4");
216 checkConfig.addProperty("caseIndent", "4");
217 checkConfig.addProperty("forceStrictCondition", "true");
218 checkConfig.addProperty("lineWrappingIndentation", "8");
219 checkConfig.addProperty("tabWidth", "4");
220 checkConfig.addProperty("throwsIndent", "8");
221 final String[] expected = {
222 "10:29: " + getCheckMessage(MSG_ERROR_MULTI, "method def rcurly", 28, "16, 20, 24"),
223 "13:9: " + getCheckMessage(MSG_ERROR, "method def rcurly", 8, 4),
224 "14:5: " + getCheckMessage(MSG_ERROR, "class def rcurly", 4, 0),
225 };
226 verifyWarns(checkConfig, getPath("InputIndentationStrictCondition.java"), expected);
227 }
228
229 @Test
230 public void forbidOldStyle() throws Exception {
231 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
232 checkConfig.addProperty("arrayInitIndent", "4");
233 checkConfig.addProperty("basicOffset", "4");
234 checkConfig.addProperty("braceAdjustment", "0");
235 checkConfig.addProperty("caseIndent", "4");
236 checkConfig.addProperty("forceStrictCondition", "true");
237 checkConfig.addProperty("lineWrappingIndentation", "8");
238 checkConfig.addProperty("tabWidth", "4");
239 checkConfig.addProperty("throwsIndent", "8");
240 final String[] expected = {
241 "20:30: " + getCheckMessage(MSG_ERROR, "int", 29, 12),
242 "21:30: " + getCheckMessage(MSG_ERROR, "int", 29, 12),
243 };
244 verifyWarns(checkConfig, getPath("InputIndentationMethodCStyle.java"), expected);
245 }
246
247 @Test
248 public void testZeroCaseLevel() throws Exception {
249 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
250 checkConfig.addProperty("arrayInitIndent", "4");
251 checkConfig.addProperty("basicOffset", "4");
252 checkConfig.addProperty("braceAdjustment", "0");
253 checkConfig.addProperty("caseIndent", "0");
254 checkConfig.addProperty("forceStrictCondition", "false");
255 checkConfig.addProperty("lineWrappingIndentation", "4");
256 checkConfig.addProperty("tabWidth", "4");
257 checkConfig.addProperty("throwsIndent", "4");
258 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
259 verifyWarns(checkConfig, getPath("InputIndentationZeroCaseLevel.java"), expected);
260 }
261
262 @Test
263 public void testAndroidStyle() throws Exception {
264 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
265 checkConfig.addProperty("arrayInitIndent", "4");
266 checkConfig.addProperty("basicOffset", "4");
267 checkConfig.addProperty("braceAdjustment", "0");
268 checkConfig.addProperty("caseIndent", "4");
269 checkConfig.addProperty("forceStrictCondition", "false");
270 checkConfig.addProperty("lineWrappingIndentation", "8");
271 checkConfig.addProperty("tabWidth", "4");
272 checkConfig.addProperty("throwsIndent", "8");
273 final String[] expected = {
274 "42:4: " + getCheckMessage(MSG_ERROR, "extends", 3, 8),
275 "44:4: " + getCheckMessage(MSG_ERROR, "member def type", 3, 4),
276 "47:9: " + getCheckMessage(MSG_ERROR, "foo", 8, 12),
277 "50:9: " + getCheckMessage(MSG_ERROR, "int", 8, 12),
278 "53:14: " + getCheckMessage(MSG_ERROR, "true", 13, 16),
279 "56:17: " + getCheckMessage(MSG_ERROR, "+", 16, 20),
280 "57:9: " + getCheckMessage(MSG_ERROR, "if", 8, 12),
281 "60:12: " + getCheckMessage(MSG_ERROR, "if rcurly", 11, 12),
282 "62:8: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 7, 8),
283 };
284 verifyWarns(checkConfig, getPath("InputIndentationAndroidStyle.java"), expected);
285 }
286
287 @Test
288 public void testMethodCallLineWrap() throws Exception {
289 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
290
291 checkConfig.addProperty("arrayInitIndent", "4");
292 checkConfig.addProperty("basicOffset", "4");
293 checkConfig.addProperty("braceAdjustment", "0");
294 checkConfig.addProperty("caseIndent", "4");
295 checkConfig.addProperty("forceStrictCondition", "false");
296 checkConfig.addProperty("lineWrappingIndentation", "4");
297 checkConfig.addProperty("tabWidth", "4");
298 checkConfig.addProperty("throwsIndent", "4");
299 final String[] expected = {
300 "53:19: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 18, 20),
301 "54:15: " + getCheckMessage(MSG_ERROR, "method call rparen", 14, 16),
302 "75:13: " + getCheckMessage(MSG_ERROR, "lambda arguments", 12, 16),
303 };
304 verifyWarns(checkConfig, getPath("InputIndentationMethodCallLineWrap.java"), expected);
305 }
306
307 @Test
308 public void testDifficultAnnotations() throws Exception {
309 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
310
311 checkConfig.addProperty("arrayInitIndent", "4");
312 checkConfig.addProperty("basicOffset", "4");
313 checkConfig.addProperty("braceAdjustment", "0");
314 checkConfig.addProperty("caseIndent", "4");
315 checkConfig.addProperty("forceStrictCondition", "false");
316 checkConfig.addProperty("lineWrappingIndentation", "4");
317 checkConfig.addProperty("tabWidth", "4");
318 checkConfig.addProperty("throwsIndent", "4");
319 final String[] expected = {
320 "40:1: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
321 "annotation array initialization", 0, "4, 23, 25"),
322 "41:1: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
323 "annotation array initialization", 0, "4, 23, 25"),
324 "50:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
325 "annotation array initialization", 6, "8, 27, 29"),
326 };
327 verifyWarns(checkConfig, getPath("InputIndentationDifficultAnnotations.java"), expected);
328 }
329
330 @Test
331 public void testAnnotationClosingParenthesisEndsInSameIndentationAsOpening() throws Exception {
332 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
333
334 checkConfig.addProperty("basicOffset", "4");
335 checkConfig.addProperty("forceStrictCondition", "true");
336 checkConfig.addProperty("tabWidth", "4");
337
338 final String[] expected = {
339 "34:17: " + getCheckMessage(MSG_ERROR, ")", 16, 0),
340 "36:17: " + getCheckMessage(MSG_ERROR, ")", 16, 0),
341 "40:9: " + getCheckMessage(MSG_ERROR, ")", 8, 4),
342 "42:9: " + getCheckMessage(MSG_ERROR, ")", 8, 4),
343 "46:9: " + getCheckMessage(MSG_ERROR, ")", 8, 4),
344 };
345
346 verifyWarns(checkConfig,
347 getPath("InputIndentation"
348 + "AnnotationClosingParenthesisEndsInSameIndentationAsOpening.java"),
349 expected);
350 }
351
352 @Test
353 public void testAnnotationsFromGuava() throws Exception {
354 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
355
356 checkConfig.addProperty("arrayInitIndent", "4");
357 checkConfig.addProperty("basicOffset", "2");
358 checkConfig.addProperty("braceAdjustment", "0");
359 checkConfig.addProperty("caseIndent", "4");
360 checkConfig.addProperty("forceStrictCondition", "false");
361 checkConfig.addProperty("lineWrappingIndentation", "4");
362 checkConfig.addProperty("tabWidth", "4");
363 checkConfig.addProperty("throwsIndent", "4");
364 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
365 verifyWarns(checkConfig, getPath("InputIndentationFromGuava.java"), expected);
366 }
367
368 @Test
369 public void testAnnotationsFromGuava1() throws Exception {
370 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
371
372 checkConfig.addProperty("arrayInitIndent", "4");
373 checkConfig.addProperty("basicOffset", "2");
374 checkConfig.addProperty("braceAdjustment", "0");
375 checkConfig.addProperty("caseIndent", "4");
376 checkConfig.addProperty("forceStrictCondition", "false");
377 checkConfig.addProperty("lineWrappingIndentation", "4");
378 checkConfig.addProperty("tabWidth", "4");
379 checkConfig.addProperty("throwsIndent", "4");
380 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
381 verifyWarns(checkConfig, getPath("InputIndentationFromGuava1.java"), expected);
382 }
383
384 @Test
385 public void testAnnotationsFromGuava2() throws Exception {
386 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
387
388 checkConfig.addProperty("arrayInitIndent", "4");
389 checkConfig.addProperty("basicOffset", "2");
390 checkConfig.addProperty("braceAdjustment", "0");
391 checkConfig.addProperty("caseIndent", "4");
392 checkConfig.addProperty("forceStrictCondition", "false");
393 checkConfig.addProperty("lineWrappingIndentation", "4");
394 checkConfig.addProperty("tabWidth", "4");
395 checkConfig.addProperty("throwsIndent", "4");
396 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
397 verifyWarns(checkConfig, getPath("InputIndentationFromGuava2.java"), expected);
398 }
399
400 @Test
401 public void testAnnotationsFromGuava3() throws Exception {
402 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
403
404 checkConfig.addProperty("arrayInitIndent", "4");
405 checkConfig.addProperty("basicOffset", "2");
406 checkConfig.addProperty("braceAdjustment", "0");
407 checkConfig.addProperty("caseIndent", "4");
408 checkConfig.addProperty("forceStrictCondition", "false");
409 checkConfig.addProperty("lineWrappingIndentation", "4");
410 checkConfig.addProperty("tabWidth", "4");
411 checkConfig.addProperty("throwsIndent", "4");
412 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
413 verifyWarns(checkConfig, getPath("InputIndentationFromGuava3.java"), expected);
414 }
415
416 @Test
417 public void testAnnotationsFromGuava4() throws Exception {
418 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
419
420 checkConfig.addProperty("arrayInitIndent", "4");
421 checkConfig.addProperty("basicOffset", "2");
422 checkConfig.addProperty("braceAdjustment", "0");
423 checkConfig.addProperty("caseIndent", "4");
424 checkConfig.addProperty("forceStrictCondition", "false");
425 checkConfig.addProperty("lineWrappingIndentation", "4");
426 checkConfig.addProperty("tabWidth", "4");
427 checkConfig.addProperty("throwsIndent", "4");
428 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
429 verifyWarns(checkConfig, getPath("InputIndentationFromGuava4.java"), expected);
430 }
431
432 @Test
433 public void testCorrectIfAndParameters() throws Exception {
434 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
435
436 checkConfig.addProperty("arrayInitIndent", "4");
437 checkConfig.addProperty("basicOffset", "2");
438 checkConfig.addProperty("braceAdjustment", "0");
439 checkConfig.addProperty("caseIndent", "4");
440 checkConfig.addProperty("forceStrictCondition", "false");
441 checkConfig.addProperty("lineWrappingIndentation", "4");
442 checkConfig.addProperty("tabWidth", "4");
443 checkConfig.addProperty("throwsIndent", "4");
444 final String[] expected = {
445 "65:11: " + getCheckMessage(MSG_ERROR_MULTI, "new", 10, "12, 14"),
446 "72:13: " + getCheckMessage(MSG_ERROR_MULTI, "new", 12, "14, 16"),
447 "94:13: " + getCheckMessage(MSG_ERROR_MULTI, "new", 12, "14, 16"),
448 "101:15: " + getCheckMessage(MSG_ERROR_MULTI, "new", 14, "16, 18"),
449 };
450 verifyWarns(checkConfig, getPath("InputIndentationCorrectIfAndParameter.java"), expected);
451 }
452
453 @Test
454 public void testCorrectIfAndParameters1() throws Exception {
455 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
456
457 checkConfig.addProperty("arrayInitIndent", "4");
458 checkConfig.addProperty("basicOffset", "2");
459 checkConfig.addProperty("braceAdjustment", "0");
460 checkConfig.addProperty("caseIndent", "4");
461 checkConfig.addProperty("forceStrictCondition", "false");
462 checkConfig.addProperty("lineWrappingIndentation", "4");
463 checkConfig.addProperty("tabWidth", "4");
464 checkConfig.addProperty("throwsIndent", "4");
465 final String[] expected = {
466 "38:9: " + getCheckMessage(MSG_ERROR_MULTI, "new", 8, "10, 12"),
467 "45:9: " + getCheckMessage(MSG_ERROR_MULTI, "new", 8, "10, 12"),
468 };
469 verifyWarns(checkConfig, getPath("InputIndentationCorrectIfAndParameter1.java"), expected);
470 }
471
472 @Test
473 public void testAnonymousClasses() throws Exception {
474 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
475
476 checkConfig.addProperty("arrayInitIndent", "4");
477 checkConfig.addProperty("basicOffset", "2");
478 checkConfig.addProperty("braceAdjustment", "0");
479 checkConfig.addProperty("caseIndent", "4");
480 checkConfig.addProperty("forceStrictCondition", "false");
481 checkConfig.addProperty("lineWrappingIndentation", "4");
482 checkConfig.addProperty("tabWidth", "4");
483 checkConfig.addProperty("throwsIndent", "4");
484 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
485 verifyWarns(checkConfig, getPath("InputIndentationAnonymousClasses.java"), expected);
486 }
487
488 @Test
489 public void testArrays() throws Exception {
490 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
491
492 checkConfig.addProperty("arrayInitIndent", "2");
493 checkConfig.addProperty("basicOffset", "2");
494 checkConfig.addProperty("braceAdjustment", "0");
495 checkConfig.addProperty("caseIndent", "4");
496 checkConfig.addProperty("forceStrictCondition", "false");
497 checkConfig.addProperty("lineWrappingIndentation", "4");
498 checkConfig.addProperty("tabWidth", "4");
499 checkConfig.addProperty("throwsIndent", "4");
500 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
501 verifyWarns(checkConfig, getPath("InputIndentationArrays.java"), expected);
502 }
503
504 @Test
505 public void testLabels() throws Exception {
506 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
507
508 checkConfig.addProperty("arrayInitIndent", "4");
509 checkConfig.addProperty("basicOffset", "2");
510 checkConfig.addProperty("braceAdjustment", "0");
511 checkConfig.addProperty("caseIndent", "4");
512 checkConfig.addProperty("forceStrictCondition", "false");
513 checkConfig.addProperty("lineWrappingIndentation", "4");
514 checkConfig.addProperty("tabWidth", "4");
515 checkConfig.addProperty("throwsIndent", "4");
516 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
517 verifyWarns(checkConfig, getPath("InputIndentationLabels.java"), expected);
518 }
519
520 @Test
521 public void testLabels1() throws Exception {
522 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
523
524 checkConfig.addProperty("arrayInitIndent", "4");
525 checkConfig.addProperty("basicOffset", "2");
526 checkConfig.addProperty("braceAdjustment", "0");
527 checkConfig.addProperty("caseIndent", "4");
528 checkConfig.addProperty("forceStrictCondition", "false");
529 checkConfig.addProperty("lineWrappingIndentation", "4");
530 checkConfig.addProperty("tabWidth", "4");
531 checkConfig.addProperty("throwsIndent", "4");
532 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
533 verifyWarns(checkConfig, getPath("InputIndentationLabels1.java"), expected);
534 }
535
536 @Test
537 public void testClassesAndMethods() throws Exception {
538 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
539
540 checkConfig.addProperty("arrayInitIndent", "4");
541 checkConfig.addProperty("basicOffset", "2");
542 checkConfig.addProperty("braceAdjustment", "0");
543 checkConfig.addProperty("caseIndent", "4");
544 checkConfig.addProperty("forceStrictCondition", "false");
545 checkConfig.addProperty("lineWrappingIndentation", "4");
546 checkConfig.addProperty("tabWidth", "4");
547 checkConfig.addProperty("throwsIndent", "4");
548 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
549 verifyWarns(checkConfig, getPath("InputIndentationClassesMethods.java"), expected);
550 }
551
552 @Test
553 public void testCtorCall() throws Exception {
554 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
555
556 checkConfig.addProperty("basicOffset", "2");
557 checkConfig.addProperty("braceAdjustment", "0");
558 checkConfig.addProperty("lineWrappingIndentation", "4");
559 checkConfig.addProperty("tabWidth", "4");
560 final String[] expected = {
561 "28:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
562 "29:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 6),
563 "30:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 6),
564 "34:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
565 "35:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 6),
566 "39:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
567 "40:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
568 "41:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
569 "45:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
570 "46:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
571 "50:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
572 "51:5: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
573 "52:5: " + getCheckMessage(MSG_ERROR, "x", 4, 8),
574 "56:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 6),
575 "57:5: " + getCheckMessage(MSG_ERROR, "method call lparen", 4, 6),
576 "62:5: " + getCheckMessage(MSG_ERROR, ".", 4, 10),
577 "63:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
578 "68:5: " + getCheckMessage(MSG_ERROR, "super", 4, 10),
579 "69:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
580 "75:11: " + getCheckMessage(MSG_ERROR_MULTI, "lambda arguments", 10, "12, 14"),
581 };
582 verifyWarns(checkConfig, getPath("InputIndentationCtorCall.java"), expected);
583 }
584
585 @Test
586 public void testCtorCall1() throws Exception {
587 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
588
589 checkConfig.addProperty("basicOffset", "2");
590 checkConfig.addProperty("braceAdjustment", "0");
591 checkConfig.addProperty("lineWrappingIndentation", "4");
592 checkConfig.addProperty("tabWidth", "4");
593 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
594 verifyWarns(checkConfig, getPath("InputIndentationCtorCall1.java"), expected);
595 }
596
597 @Test
598 public void testMembers() throws Exception {
599 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
600
601 checkConfig.addProperty("arrayInitIndent", "4");
602 checkConfig.addProperty("basicOffset", "2");
603 checkConfig.addProperty("braceAdjustment", "0");
604 checkConfig.addProperty("caseIndent", "4");
605 checkConfig.addProperty("forceStrictCondition", "false");
606 checkConfig.addProperty("lineWrappingIndentation", "4");
607 checkConfig.addProperty("tabWidth", "4");
608 checkConfig.addProperty("throwsIndent", "4");
609 final String[] expected = {
610 "22:6: " + getCheckMessage(MSG_ERROR, "=", 5, 6),
611 "57:4: " + getCheckMessage(MSG_ERROR, "class def rcurly", 3, 2),
612 };
613
614 verifyWarns(checkConfig, getPath("InputIndentationMembers.java"), expected);
615 }
616
617 @Test
618 public void testAnnotationArrayInit() throws Exception {
619 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
620
621 checkConfig.addProperty("arrayInitIndent", "6");
622 checkConfig.addProperty("basicOffset", "2");
623 checkConfig.addProperty("braceAdjustment", "0");
624 checkConfig.addProperty("caseIndent", "4");
625 checkConfig.addProperty("forceStrictCondition", "false");
626 checkConfig.addProperty("lineWrappingIndentation", "4");
627 checkConfig.addProperty("tabWidth", "8");
628 checkConfig.addProperty("throwsIndent", "4");
629 final String[] expected = {
630
631 "17:1: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization", 0,
632 "4, 6, 34, 36"),
633 "22:14: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
634 13, "4, 6, 34, 36"),
635 "23:3: " + getCheckMessage(MSG_ERROR_MULTI,
636 "annotation array initialization rcurly", 2, "0, 4"),
637 "35:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization", 6,
638 "8, 10, 31, 33"),
639 "36:3: " + getCheckMessage(MSG_ERROR_MULTI,
640 "annotation array initialization rcurly", 2, "4, 8"),
641
642 "52:6: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
643 "annotation array initialization", 5, "6, 8, 10"),
644 "54:6: " + getCheckMessage(MSG_ERROR_MULTI,
645 "annotation array initialization rcurly", 5, "2, 6"),
646 };
647 final String fileName = getPath("InputIndentationAnnArrInit.java");
648 verifyWarns(checkConfig, fileName, expected);
649 }
650
651 @Test
652 public void testAnnotationArrayInitTwo() throws Exception {
653 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
654
655 checkConfig.addProperty("arrayInitIndent", "0");
656 checkConfig.addProperty("basicOffset", "2");
657 checkConfig.addProperty("braceAdjustment", "0");
658 checkConfig.addProperty("caseIndent", "4");
659 checkConfig.addProperty("forceStrictCondition", "false");
660 checkConfig.addProperty("lineWrappingIndentation", "0");
661 checkConfig.addProperty("tabWidth", "8");
662 checkConfig.addProperty("throwsIndent", "4");
663 final String[] expected = {
664
665 "17:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
666 "annotation array initialization", 4, "0, 33, 35"),
667 "30:9: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
668 "annotation array initialization", 8, "4, 29, 31"),
669 "32:3: " + getCheckMessage(MSG_ERROR,
670 "annotation array initialization rcurly", 2, 4),
671 "47:7: " + getCheckMessage(MSG_ERROR,
672 "annotation array initialization lcurly", 6, 2),
673 "49:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
674 "annotation array initialization", 4, "2, 6, 8"),
675 };
676 final String fileName = getPath("InputIndentationAnnArrInit2.java");
677 verifyWarns(checkConfig, fileName, expected);
678 }
679
680 @Test
681 public void testAnnotationArrayInitWithEmoji() throws Exception {
682 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
683
684 checkConfig.addProperty("arrayInitIndent", "0");
685 checkConfig.addProperty("basicOffset", "2");
686 checkConfig.addProperty("braceAdjustment", "0");
687 checkConfig.addProperty("caseIndent", "4");
688 checkConfig.addProperty("forceStrictCondition", "false");
689 checkConfig.addProperty("lineWrappingIndentation", "0");
690 checkConfig.addProperty("tabWidth", "8");
691 checkConfig.addProperty("throwsIndent", "4");
692 final String[] expected = {
693 "17:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
694 "annotation array initialization", 4, "0, 41, 43"),
695 "30:9: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
696 "annotation array initialization", 8, "4, 29, 31"),
697 "32:3: " + getCheckMessage(MSG_ERROR,
698 "annotation array initialization rcurly", 2, 4),
699 "42:7: " + getCheckMessage(MSG_ERROR,
700 "member def type", 6, "4"),
701 "47:7: " + getCheckMessage(MSG_ERROR,
702 "annotation array initialization lcurly", 6, "2"),
703 "48:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
704 "annotation array initialization", 10, "2, 6, 8"),
705 "49:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
706 "annotation array initialization", 12, "2, 6, 8"),
707 "50:21: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
708 "annotation array initialization", 20, "2, 6, 8"),
709 "52:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
710 "annotation array initialization", 4, "2, 6, 8"),
711 };
712 final String fileName = getPath("InputIndentationAnnArrInitWithEmoji.java");
713 verifyWarns(checkConfig, fileName, expected);
714
715 }
716
717 @Test
718 public void testOddAnnotations()
719 throws Exception {
720 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
721
722 checkConfig.addProperty("arrayInitIndent", "3");
723 checkConfig.addProperty("basicOffset", "4");
724 checkConfig.addProperty("braceAdjustment", "0");
725 checkConfig.addProperty("caseIndent", "4");
726
727 checkConfig.addProperty("forceStrictCondition", "false");
728 checkConfig.addProperty("lineWrappingIndentation", "9");
729 checkConfig.addProperty("tabWidth", "4");
730 checkConfig.addProperty("throwsIndent", "4");
731 final String fileName = getPath("InputIndentationOddLineWrappingAndArrayInit.java");
732 final String[] expected = {
733 "25:17: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
734 16, "11, 17, 47, 54"),
735 };
736 verifyWarns(checkConfig, fileName, expected);
737 }
738
739 @Test
740 public void testAnnotationOddStyles() throws Exception {
741 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
742
743 checkConfig.addProperty("tabWidth", "8");
744
745 final String fileName = getPath("InputIndentationAnnotationArrayInitOldStyle.java");
746
747 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
748
749 verifyWarns(checkConfig, fileName, expected);
750 }
751
752 @Test
753 public void testZeroAnnotationArrayInit()
754 throws Exception {
755 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
756
757 checkConfig.addProperty("arrayInitIndent", "0");
758 checkConfig.addProperty("basicOffset", "4");
759 checkConfig.addProperty("braceAdjustment", "0");
760 checkConfig.addProperty("caseIndent", "4");
761 checkConfig.addProperty("forceStrictCondition", "false");
762 checkConfig.addProperty("lineWrappingIndentation", "4");
763 checkConfig.addProperty("tabWidth", "4");
764 checkConfig.addProperty("throwsIndent", "4");
765 final String fileName = getPath("InputIndentationZeroArrayInit.java");
766
767 final String[] expected = {
768 "22:12: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
769 11, "8, 12, 35, 37"),
770 };
771 verifyWarns(checkConfig, fileName, expected);
772 }
773
774 @Test
775 public void testAnnotationArrayInitGoodCase()
776 throws Exception {
777 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
778
779 checkConfig.addProperty("arrayInitIndent", "4");
780 checkConfig.addProperty("basicOffset", "4");
781 checkConfig.addProperty("braceAdjustment", "0");
782 checkConfig.addProperty("caseIndent", "4");
783 checkConfig.addProperty("forceStrictCondition", "false");
784 checkConfig.addProperty("lineWrappingIndentation", "4");
785 checkConfig.addProperty("tabWidth", "4");
786 checkConfig.addProperty("throwsIndent", "4");
787 final String fileName = getPath("InputIndentationAnnotationArrayInitGood.java");
788 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
789 verifyWarns(checkConfig, fileName, expected);
790 }
791
792 @Test
793 public void testAnnotationArrayInitGoodCaseTwo()
794 throws Exception {
795 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
796
797 checkConfig.addProperty("arrayInitIndent", "4");
798 checkConfig.addProperty("basicOffset", "4");
799 checkConfig.addProperty("braceAdjustment", "2");
800 checkConfig.addProperty("caseIndent", "4");
801 checkConfig.addProperty("forceStrictCondition", "false");
802 checkConfig.addProperty("lineWrappingIndentation", "4");
803 checkConfig.addProperty("tabWidth", "4");
804 checkConfig.addProperty("throwsIndent", "4");
805 final String fileName = getPath("InputIndentationAnnotationArrayInitGood.java");
806 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
807 verifyWarns(checkConfig, fileName, expected);
808 }
809
810 @Test
811 public void testInvalidLabel() throws Exception {
812 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
813
814 checkConfig.addProperty("arrayInitIndent", "4");
815 checkConfig.addProperty("basicOffset", "4");
816 checkConfig.addProperty("braceAdjustment", "0");
817 checkConfig.addProperty("caseIndent", "4");
818 checkConfig.addProperty("forceStrictCondition", "false");
819 checkConfig.addProperty("lineWrappingIndentation", "4");
820 checkConfig.addProperty("tabWidth", "4");
821 checkConfig.addProperty("throwsIndent", "4");
822 final String[] expected = {
823 "24:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 10, "8, 12"),
824 "33:3: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 2, "4, 8"),
825 "36:19: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 18, "8, 12"),
826 "37:19: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 18, 8),
827 "39:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 6, "8, 12"),
828 "41:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 6, "8, 12"),
829 };
830 verifyWarns(checkConfig, getPath("InputIndentationInvalidLabelIndent.java"), expected);
831 }
832
833 @Test
834 public void testInvalidLabelWithWhileLoop() throws Exception {
835 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
836
837 checkConfig.addProperty("arrayInitIndent", "4");
838 checkConfig.addProperty("basicOffset", "4");
839 checkConfig.addProperty("braceAdjustment", "0");
840 checkConfig.addProperty("caseIndent", "4");
841 checkConfig.addProperty("forceStrictCondition", "false");
842 checkConfig.addProperty("lineWrappingIndentation", "4");
843 checkConfig.addProperty("tabWidth", "4");
844 checkConfig.addProperty("throwsIndent", "4");
845 final String[] expected = {
846 "18:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 9, "4, 8"),
847 "19:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "label", 9, "8, 12"),
848 };
849 verifyWarns(checkConfig, getPath("InputIndentationInvalidLabelWithWhileLoopIndent.java"),
850 expected);
851 }
852
853 @Test
854 public void testValidLabel() throws Exception {
855 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
856
857 checkConfig.addProperty("arrayInitIndent", "4");
858 checkConfig.addProperty("basicOffset", "4");
859 checkConfig.addProperty("braceAdjustment", "0");
860 checkConfig.addProperty("caseIndent", "4");
861 checkConfig.addProperty("forceStrictCondition", "false");
862 checkConfig.addProperty("lineWrappingIndentation", "4");
863 checkConfig.addProperty("tabWidth", "4");
864 checkConfig.addProperty("throwsIndent", "4");
865 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
866 verifyWarns(checkConfig, getPath("InputIndentationValidLabelIndent.java"), expected);
867 }
868
869 @Test
870 public void testValidIfWithChecker() throws Exception {
871 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
872
873 checkConfig.addProperty("arrayInitIndent", "4");
874 checkConfig.addProperty("basicOffset", "4");
875 checkConfig.addProperty("braceAdjustment", "0");
876 checkConfig.addProperty("caseIndent", "4");
877 checkConfig.addProperty("forceStrictCondition", "false");
878 checkConfig.addProperty("lineWrappingIndentation", "4");
879 checkConfig.addProperty("tabWidth", "4");
880 checkConfig.addProperty("throwsIndent", "4");
881 final String fileName = getPath("InputIndentationValidIfIndent.java");
882 final String[] expected = {
883 "95:9: " + getCheckMessage(MSG_ERROR, "(", 8, 12),
884 };
885 verifyWarns(checkConfig, fileName, expected);
886 }
887
888 @Test
889 public void testValidIfWithChecker1() throws Exception {
890 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
891
892 checkConfig.addProperty("arrayInitIndent", "4");
893 checkConfig.addProperty("basicOffset", "4");
894 checkConfig.addProperty("braceAdjustment", "0");
895 checkConfig.addProperty("caseIndent", "4");
896 checkConfig.addProperty("forceStrictCondition", "false");
897 checkConfig.addProperty("lineWrappingIndentation", "4");
898 checkConfig.addProperty("tabWidth", "4");
899 checkConfig.addProperty("throwsIndent", "4");
900 final String fileName = getPath("InputIndentationValidIfIndent1.java");
901 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
902 verifyWarns(checkConfig, fileName, expected);
903 }
904
905 @Test
906 public void testValidIfWithChecker2() throws Exception {
907 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
908
909 checkConfig.addProperty("arrayInitIndent", "4");
910 checkConfig.addProperty("basicOffset", "4");
911 checkConfig.addProperty("braceAdjustment", "0");
912 checkConfig.addProperty("caseIndent", "4");
913 checkConfig.addProperty("forceStrictCondition", "false");
914 checkConfig.addProperty("lineWrappingIndentation", "4");
915 checkConfig.addProperty("tabWidth", "4");
916 checkConfig.addProperty("throwsIndent", "4");
917 final String fileName = getPath("InputIndentationValidIfIndent2.java");
918 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
919 verifyWarns(checkConfig, fileName, expected);
920 }
921
922 @Test
923 public void testValidDotWithChecker()
924 throws Exception {
925 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
926
927 checkConfig.addProperty("arrayInitIndent", "4");
928 checkConfig.addProperty("basicOffset", "4");
929 checkConfig.addProperty("braceAdjustment", "0");
930 checkConfig.addProperty("caseIndent", "4");
931 checkConfig.addProperty("forceStrictCondition", "false");
932 checkConfig.addProperty("lineWrappingIndentation", "4");
933 checkConfig.addProperty("tabWidth", "4");
934 checkConfig.addProperty("throwsIndent", "4");
935 final String fileName = getPath("InputIndentationValidDotIndent.java");
936 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
937 verifyWarns(checkConfig, fileName, expected);
938 }
939
940 @Test
941 public void testValidMethodWithChecker()
942 throws Exception {
943 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
944
945 checkConfig.addProperty("arrayInitIndent", "4");
946 checkConfig.addProperty("basicOffset", "4");
947 checkConfig.addProperty("braceAdjustment", "0");
948 checkConfig.addProperty("caseIndent", "4");
949 checkConfig.addProperty("forceStrictCondition", "false");
950 checkConfig.addProperty("lineWrappingIndentation", "4");
951 checkConfig.addProperty("tabWidth", "4");
952 checkConfig.addProperty("throwsIndent", "4");
953 final String fileName = getPath("InputIndentationValidMethodIndent.java");
954 final String[] expected = {
955 "76:5: " + getCheckMessage(MSG_ERROR, "void", 4, 8),
956 "77:5: " + getCheckMessage(MSG_ERROR, "method5", 4, 8),
957 };
958 verifyWarns(checkConfig, fileName, expected);
959 }
960
961 @Test
962 public void testValidMethodWithChecker1()
963 throws Exception {
964 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
965
966 checkConfig.addProperty("arrayInitIndent", "4");
967 checkConfig.addProperty("basicOffset", "4");
968 checkConfig.addProperty("braceAdjustment", "0");
969 checkConfig.addProperty("caseIndent", "4");
970 checkConfig.addProperty("forceStrictCondition", "false");
971 checkConfig.addProperty("lineWrappingIndentation", "4");
972 checkConfig.addProperty("tabWidth", "4");
973 checkConfig.addProperty("throwsIndent", "4");
974 final String fileName = getPath("InputIndentationValidMethodIndent1.java");
975 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
976 verifyWarns(checkConfig, fileName, expected);
977 }
978
979 @Test
980 public void testInvalidMethodWithChecker1()
981 throws Exception {
982 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
983
984 checkConfig.addProperty("arrayInitIndent", "4");
985 checkConfig.addProperty("basicOffset", "4");
986 checkConfig.addProperty("braceAdjustment", "0");
987 checkConfig.addProperty("caseIndent", "4");
988 checkConfig.addProperty("forceStrictCondition", "false");
989 checkConfig.addProperty("lineWrappingIndentation", "4");
990 checkConfig.addProperty("tabWidth", "4");
991 checkConfig.addProperty("throwsIndent", "4");
992 final String fileName = getPath("InputIndentationInvalidMethodIndent1.java");
993 final String[] expected = {
994 "23:7: " + getCheckMessage(MSG_ERROR, "ctor def rcurly", 6, 4),
995 "26:7: " + getCheckMessage(MSG_ERROR, "ctor def modifier", 6, 4),
996 "27:3: " + getCheckMessage(MSG_ERROR, "ctor def lcurly", 2, 4),
997 "28:7: " + getCheckMessage(MSG_ERROR, "ctor def rcurly", 6, 4),
998 "31:3: " + getCheckMessage(MSG_ERROR, "method def modifier", 2, 4),
999 "32:7: " + getCheckMessage(MSG_ERROR, "method def rcurly", 6, 4),
1000 "69:6: " + getCheckMessage(MSG_ERROR, "method def modifier", 5, 4),
1001 "70:6: " + getCheckMessage(MSG_ERROR, "final", 5, 9),
1002 "71:6: " + getCheckMessage(MSG_ERROR, "void", 5, 9),
1003 "72:5: " + getCheckMessage(MSG_ERROR, "method5", 4, 9),
1004 "86:11: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 10, 12),
1005 "89:11: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 10, 12),
1006 "99:7: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 6, 12),
1007 };
1008 verifyWarns(checkConfig, fileName, expected);
1009 }
1010
1011 @Test
1012 public void testInvalidMethodWithChecker2()
1013 throws Exception {
1014 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1015
1016 checkConfig.addProperty("arrayInitIndent", "4");
1017 checkConfig.addProperty("basicOffset", "4");
1018 checkConfig.addProperty("braceAdjustment", "0");
1019 checkConfig.addProperty("caseIndent", "4");
1020 checkConfig.addProperty("forceStrictCondition", "false");
1021 checkConfig.addProperty("lineWrappingIndentation", "4");
1022 checkConfig.addProperty("tabWidth", "4");
1023 checkConfig.addProperty("throwsIndent", "4");
1024 final String fileName = getPath("InputIndentationInvalidMethodIndent2.java");
1025 final String[] expected = {
1026 "23:5: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 4, 8),
1027 "26:4: " + getCheckMessage(MSG_ERROR, "method def modifier", 3, 4),
1028 "27:4: " + getCheckMessage(MSG_ERROR, "final", 3, 7),
1029 "28:4: " + getCheckMessage(MSG_ERROR, "void", 3, 7),
1030 "29:6: " + getCheckMessage(MSG_ERROR, "method6", 5, 7),
1031 "39:7: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 6, 8),
1032 "40:7: " + getCheckMessage(MSG_ERROR, "if", 6, 8),
1033 "41:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
1034 "42:7: " + getCheckMessage(MSG_ERROR, "if rcurly", 6, 8),
1035 "45:11: " + getCheckMessage(MSG_ERROR, "Arrays", 10, 12),
1036 "51:15: " + getCheckMessage(MSG_ERROR, "new", 14, 16),
1037 "54:11: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 10, 12),
1038 "59:15: " + getCheckMessage(MSG_ERROR, "new", 14, 16),
1039 "63:11: " + getCheckMessage(MSG_ERROR, "new", 10, 12),
1040 "67:11: " + getCheckMessage(MSG_ERROR, "new", 10, 12),
1041 "68:7: " + getCheckMessage(MSG_ERROR, ")", 6, 8),
1042 "72:7: " + getCheckMessage(MSG_ERROR, "method call rparen", 6, 8),
1043 "86:5: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 4, 8),
1044 "91:5: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 4, 8),
1045 "95:1: " + getCheckMessage(MSG_ERROR, "int", 0, 8),
1046 "96:5: " + getCheckMessage(MSG_ERROR, "method9", 4, 8),
1047 "106:13: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 12, 8),
1048 };
1049 verifyWarns(checkConfig, fileName, expected);
1050 }
1051
1052 @Test
1053 public void testAlternativeGoogleStyleSwitchCaseAndEnums()
1054 throws Exception {
1055 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1056
1057 checkConfig.addProperty("arrayInitIndent", "4");
1058 checkConfig.addProperty("basicOffset", "2");
1059 checkConfig.addProperty("braceAdjustment", "2");
1060 checkConfig.addProperty("caseIndent", "2");
1061 checkConfig.addProperty("forceStrictCondition", "false");
1062 checkConfig.addProperty("lineWrappingIndentation", "4");
1063 checkConfig.addProperty("tabWidth", "4");
1064 checkConfig.addProperty("throwsIndent", "4");
1065 final String fileName = getPath("InputIndentationSwitchCasesAndEnums.java");
1066 final String[] expected = {
1067 "18:7: " + getCheckMessage(MSG_CHILD_ERROR, "block", 6, 4),
1068 "35:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
1069 "38:11: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 8),
1070 "54:5: " + getCheckMessage(MSG_ERROR, "block lcurly", 4, 2),
1071 "55:3: " + getCheckMessage(MSG_CHILD_ERROR, "block", 2, 4),
1072 };
1073 verifyWarns(checkConfig, fileName, expected);
1074 }
1075
1076 @Test
1077 public void testInvalidSwitchWithChecker()
1078 throws Exception {
1079 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1080
1081 checkConfig.addProperty("arrayInitIndent", "4");
1082 checkConfig.addProperty("basicOffset", "4");
1083 checkConfig.addProperty("braceAdjustment", "0");
1084 checkConfig.addProperty("caseIndent", "4");
1085 checkConfig.addProperty("forceStrictCondition", "false");
1086 checkConfig.addProperty("lineWrappingIndentation", "4");
1087 checkConfig.addProperty("tabWidth", "4");
1088 checkConfig.addProperty("throwsIndent", "4");
1089 final String fileName = getPath("InputIndentationInvalidSwitchIndent.java");
1090 final String[] expected = {
1091 "30:7: " + getCheckMessage(MSG_ERROR, "switch", 6, 8),
1092 "32:11: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 12),
1093 "33:15: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
1094 "37:15: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
1095 "39:15: " + getCheckMessage(MSG_CHILD_ERROR, "case", 14, 12),
1096 "40:11: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 12),
1097 "43:11: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 12),
1098 "44:15: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
1099 "45:15: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
1100 "53:15: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
1101 "54:19: " + getCheckMessage(MSG_CHILD_ERROR, "block", 18, 16),
1102 "55:11: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 12),
1103 "59:11: " + getCheckMessage(MSG_ERROR, "block lcurly", 10, 12),
1104 "62:15: " + getCheckMessage(MSG_ERROR, "block rcurly", 14, 12),
1105 "66:15: " + getCheckMessage(MSG_ERROR, "block lcurly", 14, 12),
1106 "69:11: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 12),
1107 "76:15: " + getCheckMessage(MSG_CHILD_ERROR, "case", 14, 16),
1108 "81:15: " + getCheckMessage(MSG_CHILD_ERROR, "case", 14, 16),
1109 "89:7: " + getCheckMessage(MSG_ERROR, "switch rcurly", 6, 8),
1110 "92:7: " + getCheckMessage(MSG_ERROR, "switch lcurly", 6, 8),
1111 "93:11: " + getCheckMessage(MSG_ERROR, "switch rcurly", 10, 8),
1112 "95:11: " + getCheckMessage(MSG_ERROR, "switch lcurly", 10, 8),
1113 "96:7: " + getCheckMessage(MSG_ERROR, "switch rcurly", 6, 8),
1114 "99:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
1115 "100:13: " + getCheckMessage(MSG_ERROR, "if", 12, 16),
1116 "101:17: " + getCheckMessage(MSG_CHILD_ERROR, "if", 16, 20),
1117 "102:13: " + getCheckMessage(MSG_ERROR, "else", 12, 16),
1118 "103:17: " + getCheckMessage(MSG_CHILD_ERROR, "else", 16, 20),
1119 "106:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 4, 12),
1120 };
1121 verifyWarns(checkConfig, fileName, expected);
1122 }
1123
1124 @Test
1125 public void testIfElseWithNoCurly()
1126 throws Exception {
1127 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1128
1129 checkConfig.addProperty("arrayInitIndent", "4");
1130 checkConfig.addProperty("basicOffset", "4");
1131 checkConfig.addProperty("braceAdjustment", "0");
1132 checkConfig.addProperty("caseIndent", "4");
1133 checkConfig.addProperty("forceStrictCondition", "false");
1134 checkConfig.addProperty("lineWrappingIndentation", "4");
1135 checkConfig.addProperty("tabWidth", "4");
1136 checkConfig.addProperty("throwsIndent", "4");
1137 final String fileName = getPath("InputIndentationIfElseWithNoCurly.java");
1138 final String[] expected = {
1139 "20:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
1140 "25:5: " + getCheckMessage(MSG_ERROR, "if", 4, 8),
1141 "26:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 12),
1142 "37:13: " + getCheckMessage(MSG_ERROR, "else", 12, 8),
1143 "39:9: " + getCheckMessage(MSG_ERROR, "if", 8, 12),
1144 "43:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 16),
1145 };
1146 verifyWarns(checkConfig, fileName, expected);
1147 }
1148
1149 @Test
1150 public void testWhileWithNoCurly()
1151 throws Exception {
1152 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1153
1154 checkConfig.addProperty("arrayInitIndent", "4");
1155 checkConfig.addProperty("basicOffset", "4");
1156 checkConfig.addProperty("braceAdjustment", "0");
1157 checkConfig.addProperty("caseIndent", "4");
1158 checkConfig.addProperty("forceStrictCondition", "false");
1159 checkConfig.addProperty("lineWrappingIndentation", "4");
1160 checkConfig.addProperty("tabWidth", "4");
1161 checkConfig.addProperty("throwsIndent", "4");
1162 final String fileName = getPath("InputIndentationWhileNoCurly.java");
1163 final String[] expected = {
1164 "21:1: " + getCheckMessage(MSG_CHILD_ERROR, "while", 0, 12),
1165 "26:5: " + getCheckMessage(MSG_ERROR, "while", 4, 8),
1166 "27:9: " + getCheckMessage(MSG_CHILD_ERROR, "while", 8, 12),
1167 "32:9: " + getCheckMessage(MSG_ERROR, "while", 8, 12),
1168 "36:9: " + getCheckMessage(MSG_CHILD_ERROR, "while", 8, 16),
1169 };
1170 verifyWarns(checkConfig, fileName, expected);
1171 }
1172
1173 @Test
1174 public void testForWithNoCurly()
1175 throws Exception {
1176 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1177
1178 checkConfig.addProperty("arrayInitIndent", "4");
1179 checkConfig.addProperty("basicOffset", "4");
1180 checkConfig.addProperty("braceAdjustment", "0");
1181 checkConfig.addProperty("caseIndent", "4");
1182 checkConfig.addProperty("forceStrictCondition", "false");
1183 checkConfig.addProperty("lineWrappingIndentation", "4");
1184 checkConfig.addProperty("tabWidth", "4");
1185 checkConfig.addProperty("throwsIndent", "4");
1186 final String fileName = getPath("InputIndentationForWithoutCurly.java");
1187 final String[] expected = {
1188 "21:1: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
1189 "26:5: " + getCheckMessage(MSG_ERROR, "for", 4, 8),
1190 "27:9: " + getCheckMessage(MSG_CHILD_ERROR, "for", 8, 12),
1191 "32:9: " + getCheckMessage(MSG_ERROR, "for", 8, 12),
1192 "33:9: " + getCheckMessage(MSG_CHILD_ERROR, "for", 8, 16),
1193 "37:9: " + getCheckMessage(MSG_CHILD_ERROR, "for", 8, 16),
1194
1195 };
1196 verifyWarns(checkConfig, fileName, expected);
1197 }
1198
1199 @Test
1200 public void testDoWhileWithoutCurly()
1201 throws Exception {
1202 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1203
1204 checkConfig.addProperty("arrayInitIndent", "4");
1205 checkConfig.addProperty("basicOffset", "4");
1206 checkConfig.addProperty("braceAdjustment", "0");
1207 checkConfig.addProperty("caseIndent", "4");
1208 checkConfig.addProperty("forceStrictCondition", "false");
1209 checkConfig.addProperty("lineWrappingIndentation", "4");
1210 checkConfig.addProperty("tabWidth", "4");
1211 checkConfig.addProperty("throwsIndent", "4");
1212 final String fileName = getPath("InputIndentationDoWhile.java");
1213 final String[] expected = {
1214 "23:9: " + getCheckMessage(MSG_CHILD_ERROR, "do..while", 8, 12),
1215 "30:5: " + getCheckMessage(MSG_ERROR, "do..while while", 4, 8),
1216 "33:13: " + getCheckMessage(MSG_ERROR, "do..while while", 12, 8),
1217 };
1218 verifyWarns(checkConfig, fileName, expected);
1219 }
1220
1221 @Test
1222 public void testValidSwitchWithChecker()
1223 throws Exception {
1224 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1225
1226 checkConfig.addProperty("arrayInitIndent", "4");
1227 checkConfig.addProperty("basicOffset", "4");
1228 checkConfig.addProperty("braceAdjustment", "0");
1229 checkConfig.addProperty("caseIndent", "4");
1230 checkConfig.addProperty("forceStrictCondition", "false");
1231 checkConfig.addProperty("lineWrappingIndentation", "4");
1232 checkConfig.addProperty("tabWidth", "4");
1233 checkConfig.addProperty("throwsIndent", "4");
1234 final String fileName = getPath("InputIndentationValidSwitchIndent.java");
1235 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1236 verifyWarns(checkConfig, fileName, expected);
1237 }
1238
1239 @Test
1240 public void testNewKeyword() throws Exception {
1241 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1242
1243 checkConfig.addProperty("basicOffset", "4");
1244 checkConfig.addProperty("forceStrictCondition", "false");
1245 checkConfig.addProperty("lineWrappingIndentation", "8");
1246 checkConfig.addProperty("tabWidth", "4");
1247 checkConfig.addProperty("throwsIndent", "8");
1248 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1249 verifyWarns(checkConfig, getPath("InputIndentationNew.java"), expected);
1250 }
1251
1252 @Test
1253 public void testNewKeyword2() throws Exception {
1254 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1255
1256 checkConfig.addProperty("basicOffset", "4");
1257 checkConfig.addProperty("forceStrictCondition", "true");
1258 checkConfig.addProperty("lineWrappingIndentation", "8");
1259 checkConfig.addProperty("tabWidth", "4");
1260 checkConfig.addProperty("throwsIndent", "8");
1261 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1262 verifyWarns(checkConfig, getPath("InputIndentationNew.java"), expected);
1263 }
1264
1265 @Test
1266 public void testTextBlockLiteral() throws Exception {
1267 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1268
1269 checkConfig.addProperty("lineWrappingIndentation", "4");
1270 checkConfig.addProperty("forceStrictCondition", "true");
1271 checkConfig.addProperty("tabWidth", "4");
1272 final String[] expected = {
1273 "18:1: " + getCheckMessage(MSG_ERROR, "\"\"\"", 0, 8),
1274 "28:17: " + getCheckMessage(MSG_ERROR, "\"\"\"", 16, 12),
1275 "44:1: " + getCheckMessage(MSG_ERROR, "\"\"\"", 0, 12),
1276 "50:1: " + getCheckMessage(MSG_ERROR, "\"\"\"", 0, 12),
1277 "55:9: " + getCheckMessage(MSG_ERROR, "\"\"\"", 8, 12),
1278 "73:15: " + getCheckMessage(MSG_ERROR, "\"\"\"", 14, 12),
1279 };
1280 verify(checkConfig, getNonCompilablePath("InputIndentationTextBlock.java"),
1281 expected);
1282 }
1283
1284 @Test
1285 public void testValidNewKeywordWithForceStrictCondition() throws Exception {
1286 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1287
1288 checkConfig.addProperty("basicOffset", "4");
1289 checkConfig.addProperty("forceStrictCondition", "true");
1290 checkConfig.addProperty("lineWrappingIndentation", "8");
1291 checkConfig.addProperty("tabWidth", "4");
1292 checkConfig.addProperty("throwsIndent", "8");
1293 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1294 verifyWarns(checkConfig, getPath("InputIndentationNew.java"), expected);
1295 }
1296
1297 @Test
1298 public void testInvalidNewKeywordWithForceStrictCondition() throws Exception {
1299 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1300
1301 checkConfig.addProperty("basicOffset", "4");
1302 checkConfig.addProperty("forceStrictCondition", "true");
1303 checkConfig.addProperty("lineWrappingIndentation", "8");
1304 checkConfig.addProperty("tabWidth", "4");
1305 checkConfig.addProperty("throwsIndent", "8");
1306 final String[] expected = {
1307 "21:12: " + getCheckMessage(MSG_ERROR, "]", 11, 12),
1308 "25:5: " + getCheckMessage(MSG_ERROR, "[", 4, 12),
1309 "32:17: " + getCheckMessage(MSG_ERROR, "new", 16, 24),
1310 "33:21: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "object def", 20, "28, 32, 36"),
1311 "34:17: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 16, "24, 28, 32"),
1312 "37:36: " + getCheckMessage(MSG_ERROR, "+", 35, 16),
1313 "41:35: " + getCheckMessage(MSG_ERROR, "]", 34, 16),
1314 "45:36: " + getCheckMessage(MSG_ERROR, "42", 35, 16),
1315 "49:36: " + getCheckMessage(MSG_ERROR, "+", 35, 16),
1316 "50:36: " + getCheckMessage(MSG_ERROR, "+", 35, 16),
1317 "55:21: " + getCheckMessage(MSG_ERROR, "1", 20, 16),
1318 "59:13: " + getCheckMessage(MSG_ERROR, "fun2", 12, 16),
1319 "78:11: " + getCheckMessage(MSG_ERROR, "Object", 10, 12),
1320 "82:16: " + getCheckMessage(MSG_ERROR, "]", 15, 12),
1321 };
1322 verifyWarns(checkConfig,
1323 getPath("InputIndentationNewWithForceStrictCondition.java"), expected);
1324 }
1325
1326 @Test
1327 public void testValidArrayInitDefaultIndentWithChecker()
1328 throws Exception {
1329 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1330
1331 checkConfig.addProperty("arrayInitIndent", "4");
1332 checkConfig.addProperty("basicOffset", "4");
1333 checkConfig.addProperty("braceAdjustment", "0");
1334 checkConfig.addProperty("caseIndent", "4");
1335 checkConfig.addProperty("forceStrictCondition", "false");
1336 checkConfig.addProperty("lineWrappingIndentation", "4");
1337 checkConfig.addProperty("tabWidth", "4");
1338 checkConfig.addProperty("throwsIndent", "4");
1339 final String fileName = getPath("InputIndentationValidArrayInitDefaultIndent.java");
1340 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1341 verifyWarns(checkConfig, fileName, expected);
1342 }
1343
1344 @Test
1345 public void testValidArrayInitWithChecker()
1346 throws Exception {
1347 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1348
1349 checkConfig.addProperty("arrayInitIndent", "8");
1350 checkConfig.addProperty("basicOffset", "4");
1351 checkConfig.addProperty("braceAdjustment", "0");
1352 checkConfig.addProperty("caseIndent", "4");
1353 checkConfig.addProperty("forceStrictCondition", "false");
1354 checkConfig.addProperty("lineWrappingIndentation", "4");
1355 checkConfig.addProperty("tabWidth", "4");
1356 checkConfig.addProperty("throwsIndent", "4");
1357 final String fileName = getPath("InputIndentationValidArrayInitIndent.java");
1358 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1359 verifyWarns(checkConfig, fileName, expected);
1360 }
1361
1362 @Test
1363 public void testValidArrayInitTwoDimensional() throws Exception {
1364 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1365
1366 checkConfig.addProperty("arrayInitIndent", "2");
1367 checkConfig.addProperty("basicOffset", "4");
1368 checkConfig.addProperty("braceAdjustment", "4");
1369 checkConfig.addProperty("caseIndent", "4");
1370 checkConfig.addProperty("forceStrictCondition", "false");
1371 checkConfig.addProperty("lineWrappingIndentation", "4");
1372 checkConfig.addProperty("tabWidth", "4");
1373 checkConfig.addProperty("throwsIndent", "4");
1374 final String fileName = getPath("InputIndentationValidArrayInitIndentTwoDimensional.java");
1375 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1376 verifyWarns(checkConfig, fileName, expected);
1377 }
1378
1379 @Test
1380 public void testInvalidArrayInitTwoDimensional() throws Exception {
1381 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1382
1383 checkConfig.addProperty("arrayInitIndent", "2");
1384 checkConfig.addProperty("basicOffset", "4");
1385 checkConfig.addProperty("braceAdjustment", "4");
1386 checkConfig.addProperty("caseIndent", "4");
1387 checkConfig.addProperty("forceStrictCondition", "false");
1388 checkConfig.addProperty("lineWrappingIndentation", "4");
1389 checkConfig.addProperty("tabWidth", "4");
1390 checkConfig.addProperty("throwsIndent", "4");
1391 final String fileName =
1392 getPath("InputIndentationInvalidArrayInitIndentTwoDimensional.java");
1393 final String[] expected = {
1394 "18:5: " + getCheckMessage(MSG_ERROR_MULTI,
1395 "array initialization lcurly", 4, "6, 8, 18, 20, 24"),
1396 "23:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
1397 "array initialization", 9, "8, 10, 12, 20, 22, 24"),
1398 "26:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI,
1399 "array initialization", 6, "8, 10, 12, 20, 22, 24"),
1400 "28:5: " + getCheckMessage(MSG_ERROR_MULTI,
1401 "array initialization lcurly", 4, "6, 8, 18, 20, 24"),
1402 "30:5: " + getCheckMessage(MSG_ERROR_MULTI,
1403 "array initialization rcurly", 4, "6, 8, 18, 20, 24"),
1404
1405 };
1406 verifyWarns(checkConfig, fileName, expected);
1407 }
1408
1409 @Test
1410 public void testValidArrayInit()
1411 throws Exception {
1412 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1413
1414 checkConfig.addProperty("arrayInitIndent", "2");
1415 checkConfig.addProperty("basicOffset", "2");
1416 checkConfig.addProperty("braceAdjustment", "2");
1417 checkConfig.addProperty("caseIndent", "2");
1418 checkConfig.addProperty("forceStrictCondition", "false");
1419 checkConfig.addProperty("lineWrappingIndentation", "4");
1420 checkConfig.addProperty("tabWidth", "4");
1421 checkConfig.addProperty("throwsIndent", "4");
1422 final String fileName = getPath("InputIndentationValidArrayInitIndentTwo.java");
1423 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1424 verifyWarns(checkConfig, fileName, expected);
1425 }
1426
1427 @Test
1428 public void testArrayInitWithEmoji() throws Exception {
1429 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1430
1431 checkConfig.addProperty("arrayInitIndent", "2");
1432 checkConfig.addProperty("basicOffset", "2");
1433 checkConfig.addProperty("braceAdjustment", "2");
1434 checkConfig.addProperty("caseIndent", "2");
1435 checkConfig.addProperty("forceStrictCondition", "false");
1436 checkConfig.addProperty("lineWrappingIndentation", "4");
1437 checkConfig.addProperty("tabWidth", "4");
1438 checkConfig.addProperty("throwsIndent", "4");
1439 final String fileName = getPath("InputIndentationArrayInitIndentWithEmoji.java");
1440 final String[] expected = {
1441 "19:6: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1442 5, "4, 6, 52, 54"),
1443 "24:9: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1444 8, "4, 6, 35, 37"),
1445 "25:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1446 10, "4, 6, 35, 37"),
1447 "30:11: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly",
1448 10, "4, 6, 19, 21, 25"),
1449 };
1450 verifyWarns(checkConfig, fileName, expected);
1451 }
1452
1453 @Test
1454 public void testYieldKeywordWithForceStrictCondition() throws Exception {
1455 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1456 checkConfig.addProperty("forceStrictCondition", "true");
1457 checkConfig.addProperty("tabWidth", "4");
1458 final String[] expected = {
1459 "15:13: " + getCheckMessage(MSG_CHILD_ERROR, "block", 12, 16),
1460 "16:13: " + getCheckMessage(MSG_ERROR, "yield", 12, 16),
1461 "44:13: " + getCheckMessage(MSG_CHILD_ERROR, "block", 12, 16),
1462 "45:13: " + getCheckMessage(MSG_ERROR, "yield", 12, 16),
1463 "50:5: " + getCheckMessage(MSG_ERROR, "yield", 4, 16),
1464 "71:15: " + getCheckMessage(MSG_ERROR, "yield", 14, 16),
1465 "74:20: " + getCheckMessage(MSG_ERROR, "yield", 19, 16),
1466 "77:9: " + getCheckMessage(MSG_ERROR, "yield", 8, 16),
1467 };
1468 verifyWarns(checkConfig,
1469 getNonCompilablePath("InputIndentationYieldForceStrict.java"), expected);
1470 }
1471
1472 @Test
1473 public void testChainedMethodCalling() throws Exception {
1474 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1475
1476 checkConfig.addProperty("arrayInitIndent", "2");
1477 checkConfig.addProperty("basicOffset", "2");
1478 checkConfig.addProperty("braceAdjustment", "2");
1479 checkConfig.addProperty("caseIndent", "2");
1480 checkConfig.addProperty("forceStrictCondition", "false");
1481 checkConfig.addProperty("lineWrappingIndentation", "4");
1482 checkConfig.addProperty("tabWidth", "4");
1483 checkConfig.addProperty("throwsIndent", "4");
1484 final String fileName = getPath("InputIndentationChainedMethodCalls.java");
1485 final String[] expected = {
1486 "32:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 8),
1487 "37:5: " + getCheckMessage(MSG_ERROR, ".", 4, 8),
1488 "38:5: " + getCheckMessage(MSG_ERROR, ".", 4, 8),
1489 "41:5: " + getCheckMessage(MSG_ERROR, "new", 4, 8),
1490 };
1491 verifyWarns(checkConfig, fileName, expected);
1492 }
1493
1494 @Test
1495 public void testInvalidArrayInitWithTrueStrictCondition()
1496 throws Exception {
1497 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1498
1499 checkConfig.addProperty("arrayInitIndent", "4");
1500 checkConfig.addProperty("basicOffset", "4");
1501 checkConfig.addProperty("braceAdjustment", "0");
1502 checkConfig.addProperty("caseIndent", "4");
1503 checkConfig.addProperty("forceStrictCondition", "true");
1504 checkConfig.addProperty("lineWrappingIndentation", "4");
1505 checkConfig.addProperty("tabWidth", "4");
1506 checkConfig.addProperty("throwsIndent", "4");
1507 final String fileName = getPath("InputIndentationInvalidArrayInitIndent.java");
1508 final String[] expected = {
1509 "21:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1510 "22:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1511 "24:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1512 "28:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1513 "29:9: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 8,
1514 "10, 34, 36"),
1515 "30:5: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 4, "6, 10"),
1516 "33:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 9,
1517 "8, 31, 33"),
1518 "34:8: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 7,
1519 "8, 31, 33"),
1520 "35:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 9,
1521 "8, 31, 33"),
1522 "40:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
1523 "44:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "4, 8"),
1524 "48:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
1525 "52:21: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 20,
1526 "8, 31, 33"),
1527 "53:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1528 4, "8, 31, 33"),
1529 "58:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1530 6, "8, 31, 33"),
1531 "63:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1532 "65:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1533 "66:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 2, "6, 10"),
1534 "69:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1535 6, "8, 36, 38"),
1536 "76:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1537 10, "12, 24, 26"),
1538 };
1539
1540 verifyWarns(checkConfig, fileName, expected);
1541 }
1542
1543 @Test
1544 public void testInvalidArrayInitWithTrueStrictCondition1()
1545 throws Exception {
1546 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1547
1548 checkConfig.addProperty("arrayInitIndent", "4");
1549 checkConfig.addProperty("basicOffset", "4");
1550 checkConfig.addProperty("braceAdjustment", "0");
1551 checkConfig.addProperty("caseIndent", "4");
1552 checkConfig.addProperty("forceStrictCondition", "true");
1553 checkConfig.addProperty("lineWrappingIndentation", "4");
1554 checkConfig.addProperty("tabWidth", "4");
1555 checkConfig.addProperty("throwsIndent", "4");
1556 final String fileName = getPath("InputIndentationInvalidArrayInitIndent1.java");
1557 final String[] expected = {
1558 "28:9: " + getCheckMessage(MSG_ERROR, "1", 8, 12),
1559 "39:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 10,
1560 "12, 30, 32"),
1561 "40:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1562 "12, 30, 32"),
1563 "43:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 10,
1564 "12, 31, 32"),
1565 "44:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1566 "12, 31, 32"),
1567 "45:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
1568 "48:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 6, "8, 12"),
1569 "49:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1570 "8, 10, 12"),
1571 "51:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
1572
1573 "59:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1574 12, "16, 46, 48"),
1575 "67:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1576 14, "16, 28, 30"),
1577 "68:9: " + getCheckMessage(MSG_ERROR_MULTI, "annotation array initialization rcurly",
1578 8, "12, 16"),
1579 "70:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1580 12, "16, 29, 31"),
1581 };
1582
1583 verifyWarns(checkConfig, fileName, expected);
1584 }
1585
1586 @Test
1587 public void testInvalidArrayInitWithFalseStrictCondition()
1588 throws Exception {
1589 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1590
1591 checkConfig.addProperty("arrayInitIndent", "4");
1592 checkConfig.addProperty("basicOffset", "4");
1593 checkConfig.addProperty("braceAdjustment", "0");
1594 checkConfig.addProperty("caseIndent", "4");
1595 checkConfig.addProperty("forceStrictCondition", "false");
1596 checkConfig.addProperty("lineWrappingIndentation", "4");
1597 checkConfig.addProperty("tabWidth", "4");
1598 checkConfig.addProperty("throwsIndent", "4");
1599 final String fileName = getPath("InputIndentationInvalidArrayInitIndent.java");
1600 final String[] expected = {
1601 "21:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1602 "22:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1603 "24:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1604 "28:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1605 "29:9: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 8,
1606 "10, 34, 36"),
1607 "30:5: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 4, "6, 10"),
1608 "33:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 9,
1609 "8, 31, 33"),
1610 "34:8: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 7,
1611 "8, 31, 33"),
1612 "35:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 9,
1613 "8, 31, 33"),
1614 "40:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
1615 "44:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "4, 8"),
1616 "48:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
1617 "52:21: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 20,
1618 "8, 31, 33"),
1619 "53:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1620 4, "8, 31, 33"),
1621 "58:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1622 6, "8, 31, 33"),
1623 "63:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1624 "65:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1625 "66:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 2, "6, 10"),
1626 "69:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1627 6, "8, 36, 38"),
1628 "76:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1629 10, "12, 24, 26"),
1630 };
1631
1632 verifyWarns(checkConfig, fileName, expected);
1633 }
1634
1635 @Test
1636 public void testInvalidArrayInitWithFalseStrictCondition1()
1637 throws Exception {
1638 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1639
1640 checkConfig.addProperty("arrayInitIndent", "4");
1641 checkConfig.addProperty("basicOffset", "4");
1642 checkConfig.addProperty("braceAdjustment", "0");
1643 checkConfig.addProperty("caseIndent", "4");
1644 checkConfig.addProperty("forceStrictCondition", "false");
1645 checkConfig.addProperty("lineWrappingIndentation", "4");
1646 checkConfig.addProperty("tabWidth", "4");
1647 checkConfig.addProperty("throwsIndent", "4");
1648 final String fileName = getPath("InputIndentationInvalidArrayInitIndent1.java");
1649 final String[] expected = {
1650 "28:9: " + getCheckMessage(MSG_ERROR, "1", 8, 12),
1651 "39:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 10,
1652 "12, 30, 32"),
1653 "40:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1654 "12, 30, 32"),
1655 "43:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 10,
1656 "12, 31, 32"),
1657 "44:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1658 "12, 31, 32"),
1659 "45:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
1660 "48:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 6, "8, 12"),
1661 "49:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1662 "8, 10, 12"),
1663 "51:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
1664
1665 "59:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1666 12, "16, 46, 48"),
1667 "67:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1668 14, "16, 28, 30"),
1669 "68:9: " + getCheckMessage(MSG_ERROR_MULTI, "annotation array initialization rcurly",
1670 8, "12, 16"),
1671 "70:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1672 12, "16, 29, 31"),
1673 };
1674
1675 verifyWarns(checkConfig, fileName, expected);
1676 }
1677
1678
1679 @Test
1680 public void testInvalidArrayInitIndentNoCommentsTrueStrictCondition()
1681 throws Exception {
1682 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1683
1684 checkConfig.addProperty("arrayInitIndent", "4");
1685 checkConfig.addProperty("basicOffset", "4");
1686 checkConfig.addProperty("braceAdjustment", "0");
1687 checkConfig.addProperty("caseIndent", "4");
1688 checkConfig.addProperty("forceStrictCondition", "true");
1689 checkConfig.addProperty("lineWrappingIndentation", "4");
1690 checkConfig.addProperty("tabWidth", "4");
1691 checkConfig.addProperty("throwsIndent", "4");
1692 final String fileName = getPath(
1693 "InputIndentationInvalidArrayInitIndentWithoutTrailingComments.java");
1694 final String[] expected = {
1695 "28:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1696 12, "16, 46, 48"),
1697 "32:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1698 14, "12, 16"),
1699 "36:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1700 14, "16, 28, 30"),
1701 "37:9: " + getCheckMessage(MSG_ERROR_MULTI, "annotation array initialization rcurly",
1702 8, "12, 16"),
1703 "39:13: " + getCheckMessage(MSG_CHILD_ERROR, "annotation array initialization",
1704 12, 16),
1705 };
1706 verify(checkConfig, fileName, expected);
1707 }
1708
1709
1710 @Test
1711 public void testInvalidArrayInitIndentNoCommentsFalseStrictCondition()
1712 throws Exception {
1713 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1714
1715 checkConfig.addProperty("arrayInitIndent", "4");
1716 checkConfig.addProperty("basicOffset", "4");
1717 checkConfig.addProperty("braceAdjustment", "0");
1718 checkConfig.addProperty("caseIndent", "4");
1719 checkConfig.addProperty("forceStrictCondition", "false");
1720 checkConfig.addProperty("lineWrappingIndentation", "4");
1721 checkConfig.addProperty("tabWidth", "4");
1722 checkConfig.addProperty("throwsIndent", "4");
1723 final String fileName = getPath(
1724 "InputIndentationInvalidArrayInitIndentWithoutTrailingComments.java");
1725 final String[] expected = {
1726 "28:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1727 12, "16, 46, 48"),
1728 "32:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1729 14, "12, 16"),
1730 "36:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1731 14, "16, 28, 30"),
1732 "37:9: " + getCheckMessage(MSG_ERROR_MULTI, "annotation array initialization rcurly",
1733 8, "12, 16"),
1734 "39:13: " + getCheckMessage(MSG_CHILD_ERROR, "annotation array initialization",
1735 12, 16),
1736 };
1737 verify(checkConfig, fileName, expected);
1738 }
1739
1740 @Test
1741 public void testValidTryWithChecker()
1742 throws Exception {
1743 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1744
1745 checkConfig.addProperty("arrayInitIndent", "4");
1746 checkConfig.addProperty("basicOffset", "4");
1747 checkConfig.addProperty("braceAdjustment", "0");
1748 checkConfig.addProperty("caseIndent", "4");
1749 checkConfig.addProperty("forceStrictCondition", "false");
1750 checkConfig.addProperty("lineWrappingIndentation", "4");
1751 checkConfig.addProperty("tabWidth", "4");
1752 checkConfig.addProperty("throwsIndent", "4");
1753 final String fileName = getPath("InputIndentationValidTryIndent.java");
1754 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
1755 verifyWarns(checkConfig, fileName, expected);
1756 }
1757
1758 @Test
1759 public void testInvalidTryWithChecker()
1760 throws Exception {
1761 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1762
1763 checkConfig.addProperty("arrayInitIndent", "4");
1764 checkConfig.addProperty("basicOffset", "4");
1765 checkConfig.addProperty("braceAdjustment", "0");
1766 checkConfig.addProperty("caseIndent", "4");
1767 checkConfig.addProperty("forceStrictCondition", "false");
1768 checkConfig.addProperty("lineWrappingIndentation", "4");
1769 checkConfig.addProperty("tabWidth", "4");
1770 checkConfig.addProperty("throwsIndent", "4");
1771 final String fileName = getPath("InputIndentationInvalidTryIndent.java");
1772 final String[] expected = {
1773 "25:10: " + getCheckMessage(MSG_ERROR, "try", 9, 8),
1774 "26:8: " + getCheckMessage(MSG_ERROR, "try rcurly", 7, 8),
1775 "28:8: " + getCheckMessage(MSG_ERROR, "catch rcurly", 7, 8),
1776 "30:5: " + getCheckMessage(MSG_ERROR, "try", 4, 8),
1777 "31:9: " + getCheckMessage(MSG_CHILD_ERROR, "try", 8, 12),
1778 "32:5: " + getCheckMessage(MSG_ERROR, "try rcurly", 4, 8),
1779 "33:9: " + getCheckMessage(MSG_CHILD_ERROR, "finally", 8, 12),
1780 "38:9: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 8, 12),
1781 "43:11: " + getCheckMessage(MSG_ERROR, "try rcurly", 10, 8),
1782 "45:7: " + getCheckMessage(MSG_ERROR, "catch rcurly", 6, 8),
1783 "52:6: " + getCheckMessage(MSG_ERROR, "catch rcurly", 5, 8),
1784 "59:11: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 10, 12),
1785 "60:15: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 14, 12),
1786 "61:11: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 10, 12),
1787 "63:7: " + getCheckMessage(MSG_ERROR, "catch", 6, 8),
1788 "70:11: " + getCheckMessage(MSG_ERROR, "try lcurly", 10, 8),
1789 "72:11: " + getCheckMessage(MSG_ERROR, "try rcurly", 10, 8),
1790 "74:7: " + getCheckMessage(MSG_ERROR, "catch lcurly", 6, 8),
1791 "77:11: " + getCheckMessage(MSG_ERROR, "catch rcurly", 10, 8),
1792 "80:11: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 10, 12),
1793 "86:1: " + getCheckMessage(MSG_ERROR, "try", 0, 8),
1794 "87:1: " + getCheckMessage(MSG_ERROR, "try rcurly", 0, 8),
1795 "88:1: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 0, 12),
1796 "89:1: " + getCheckMessage(MSG_ERROR, "catch rcurly", 0, 8),
1797 "91:1: " + getCheckMessage(MSG_ERROR, "try", 0, 8),
1798 "92:1: " + getCheckMessage(MSG_ERROR, "try rcurly", 0, 8),
1799 "93:1: " + getCheckMessage(MSG_CHILD_ERROR, "catch", 0, 12),
1800 "94:1: " + getCheckMessage(MSG_ERROR, "catch rcurly", 0, 8),
1801 };
1802 verifyWarns(checkConfig, fileName, expected);
1803 }
1804
1805 @Test
1806 public void testInvalidClassDefWithChecker()
1807 throws Exception {
1808 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1809
1810 checkConfig.addProperty("arrayInitIndent", "4");
1811 checkConfig.addProperty("basicOffset", "4");
1812 checkConfig.addProperty("braceAdjustment", "0");
1813 checkConfig.addProperty("caseIndent", "4");
1814 checkConfig.addProperty("forceStrictCondition", "false");
1815 checkConfig.addProperty("lineWrappingIndentation", "4");
1816 checkConfig.addProperty("tabWidth", "4");
1817 checkConfig.addProperty("throwsIndent", "4");
1818 final String fileName = getPath("InputIndentationInvalidClassDefIndent.java");
1819 final String[] expected = {
1820 "18:3: " + getCheckMessage(MSG_ERROR, "class def modifier", 2, 0),
1821 "24:3: " + getCheckMessage(MSG_ERROR, "class def lcurly", 2, 0),
1822 "27:3: " + getCheckMessage(MSG_ERROR, "class def rcurly", 2, 0),
1823 "30:9: " + getCheckMessage(MSG_ERROR, "class def ident", 2, 0),
1824 "34:3: " + getCheckMessage(MSG_ERROR, "class def rcurly", 2, 0),
1825 "39:3: " + getCheckMessage(MSG_ERROR, "extends", 2, 4),
1826 "40:3: " + getCheckMessage(MSG_ERROR, "implements", 2, 4),
1827 "46:3: " + getCheckMessage(MSG_ERROR, "extends", 2, 4),
1828 "54:3: " + getCheckMessage(MSG_ERROR, "implements", 2, 4),
1829 "55:3: " + getCheckMessage(MSG_ERROR, "java", 2, 4),
1830 "60:3: " + getCheckMessage(MSG_ERROR, "class def modifier", 2, 0),
1831 "61:3: " + getCheckMessage(MSG_ERROR, "class def lcurly", 2, 0),
1832 "69:3: " + getCheckMessage(MSG_ERROR, "class def rcurly", 2, 0),
1833 "73:3: " + getCheckMessage(MSG_ERROR, "extends", 2, 4),
1834 "79:1: " + getCheckMessage(MSG_ERROR, "class", 0, 4),
1835 };
1836 verifyWarns(checkConfig, fileName, expected);
1837 }
1838
1839 @Test
1840 public void testInvalidClassDefWithChecker1()
1841 throws Exception {
1842 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1843
1844 checkConfig.addProperty("arrayInitIndent", "4");
1845 checkConfig.addProperty("basicOffset", "4");
1846 checkConfig.addProperty("braceAdjustment", "0");
1847 checkConfig.addProperty("caseIndent", "4");
1848 checkConfig.addProperty("forceStrictCondition", "false");
1849 checkConfig.addProperty("lineWrappingIndentation", "4");
1850 checkConfig.addProperty("tabWidth", "4");
1851 checkConfig.addProperty("throwsIndent", "4");
1852 final String fileName = getPath("InputIndentationInvalidClassDefIndent1.java");
1853 final String[] expected = {
1854 "22:3: " + getCheckMessage(MSG_ERROR, "class def modifier", 2, 0),
1855 "27:9: " + getCheckMessage(MSG_ERROR, "class def ident", 2, 4),
1856 "29:13: " + getCheckMessage(MSG_ERROR, "class def ident", 6, 4),
1857 "31:9: " + getCheckMessage(MSG_ERROR, "class def ident", 2, 4),
1858 "34:7: " + getCheckMessage(MSG_ERROR, "member def modifier", 6, 8),
1859 "40:11: " + getCheckMessage(MSG_ERROR, "int", 10, 12),
1860 "44:7: " + getCheckMessage(MSG_ERROR, "member def modifier", 6, 8),
1861 "49:7: " + getCheckMessage(MSG_ERROR, "class def rcurly", 6, 4),
1862 "51:13: " + getCheckMessage(MSG_ERROR, "class def ident", 6, 4),
1863 "56:13: " + getCheckMessage(MSG_ERROR, "class def ident", 6, 8),
1864 "59:17: " + getCheckMessage(MSG_ERROR, "class def ident", 10, 8),
1865 "61:11: " + getCheckMessage(MSG_ERROR, "class def rcurly", 10, 8),
1866 "64:11: " + getCheckMessage(MSG_ERROR, "member def type", 10, 12),
1867 "69:11: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 10, 8),
1868 "70:9: " + getCheckMessage(MSG_ERROR_MULTI, "object def lcurly", 8, "10, 14"),
1869 "74:9: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 8, "10, 14"),
1870 "77:7: " + getCheckMessage(MSG_ERROR_MULTI, "object def lcurly", 6, "8, 12"),
1871 "81:7: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 6, "8, 12"),
1872 "85:11: " + getCheckMessage(MSG_ERROR, "method def modifier", 10, 12),
1873 "87:11: " + getCheckMessage(MSG_ERROR, "method def rcurly", 10, 12),
1874 };
1875 verifyWarns(checkConfig, fileName, expected);
1876 }
1877
1878 @Test
1879 public void testInvalidBlockWithChecker()
1880 throws Exception {
1881 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1882
1883 checkConfig.addProperty("arrayInitIndent", "4");
1884 checkConfig.addProperty("basicOffset", "4");
1885 checkConfig.addProperty("braceAdjustment", "0");
1886 checkConfig.addProperty("caseIndent", "4");
1887 checkConfig.addProperty("forceStrictCondition", "false");
1888 checkConfig.addProperty("lineWrappingIndentation", "4");
1889 checkConfig.addProperty("tabWidth", "4");
1890 checkConfig.addProperty("throwsIndent", "4");
1891 final String fileName = getPath("InputIndentationInvalidBlockIndent.java");
1892 final String[] expected = {
1893 "26:8: " + getCheckMessage(MSG_ERROR, "block lcurly", 7, 8),
1894 "27:10: " + getCheckMessage(MSG_ERROR, "block lcurly", 9, 8),
1895 "29:10: " + getCheckMessage(MSG_ERROR, "block lcurly", 9, 8),
1896 "30:8: " + getCheckMessage(MSG_ERROR, "block rcurly", 7, 8),
1897 "32:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
1898 "34:7: " + getCheckMessage(MSG_ERROR, "block rcurly", 6, 8),
1899 "35:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
1900 "38:10: " + getCheckMessage(MSG_ERROR, "block lcurly", 9, 8),
1901 "39:14: " + getCheckMessage(MSG_CHILD_ERROR, "block", 13, 12),
1902 "41:14: " + getCheckMessage(MSG_CHILD_ERROR, "block", 13, 12),
1903 "42:10: " + getCheckMessage(MSG_ERROR, "block rcurly", 9, 8),
1904 "45:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
1905 "46:11: " + getCheckMessage(MSG_CHILD_ERROR, "block", 10, 12),
1906 "48:11: " + getCheckMessage(MSG_CHILD_ERROR, "block", 10, 12),
1907 "49:7: " + getCheckMessage(MSG_ERROR, "block rcurly", 6, 8),
1908 "52:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 8),
1909 "55:11: " + getCheckMessage(MSG_CHILD_ERROR, "block", 10, 12),
1910 "59:11: " + getCheckMessage(MSG_ERROR, "block lcurly", 10, 12),
1911 "63:11: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 12),
1912 "68:11: " + getCheckMessage(MSG_CHILD_ERROR, "block", 10, 12),
1913 "70:11: " + getCheckMessage(MSG_ERROR, "block lcurly", 10, 12),
1914 "71:15: " + getCheckMessage(MSG_CHILD_ERROR, "block", 14, 16),
1915 "86:11: " + getCheckMessage(MSG_ERROR, "block rcurly", 10, 12),
1916 };
1917 verifyWarns(checkConfig, fileName, expected);
1918 }
1919
1920 @Test
1921 public void testInvalidBlockWithChecker1()
1922 throws Exception {
1923 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1924
1925 checkConfig.addProperty("arrayInitIndent", "4");
1926 checkConfig.addProperty("basicOffset", "4");
1927 checkConfig.addProperty("braceAdjustment", "0");
1928 checkConfig.addProperty("caseIndent", "4");
1929 checkConfig.addProperty("forceStrictCondition", "false");
1930 checkConfig.addProperty("lineWrappingIndentation", "4");
1931 checkConfig.addProperty("tabWidth", "4");
1932 checkConfig.addProperty("throwsIndent", "4");
1933 final String fileName = getPath("InputIndentationInvalidBlockIndent1.java");
1934 final String[] expected = {
1935 "27:3: " + getCheckMessage(MSG_ERROR, "static initialization", 2, 4),
1936 "28:7: " + getCheckMessage(MSG_ERROR, "static initialization", 6, 4),
1937 "32:8: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 7, 8),
1938 "35:7: " + getCheckMessage(MSG_ERROR, "static initialization", 6, 4),
1939 "37:3: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 2, 4),
1940 "39:3: " + getCheckMessage(MSG_ERROR, "static initialization", 2, 4),
1941 "41:7: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 6, 4),
1942 "43:3: " + getCheckMessage(MSG_ERROR, "static initialization", 2, 4),
1943 "45:7: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 6, 8),
1944 "48:3: " + getCheckMessage(MSG_ERROR, "static initialization lcurly", 2, 4),
1945 "49:7: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 6, 8),
1946 "50:7: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 6, 4),
1947 "55:7: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 6, 8),
1948 "60:5: " + getCheckMessage(MSG_CHILD_ERROR, "static initialization", 4, 8),
1949 "61:3: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 2, 4),
1950 "66:7: " + getCheckMessage(MSG_ERROR, "static initialization rcurly", 6, 4),
1951 "69:3: " + getCheckMessage(MSG_ERROR, "block lcurly", 2, 4),
1952 "70:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 4),
1953 "73:3: " + getCheckMessage(MSG_ERROR, "block lcurly", 2, 4),
1954 "75:7: " + getCheckMessage(MSG_ERROR, "block rcurly", 6, 4),
1955 "77:7: " + getCheckMessage(MSG_ERROR, "block lcurly", 6, 4),
1956 "79:3: " + getCheckMessage(MSG_ERROR, "block rcurly", 2, 4),
1957 "82:7: " + getCheckMessage(MSG_CHILD_ERROR, "block", 6, 8),
1958 };
1959 verifyWarns(checkConfig, fileName, expected);
1960 }
1961
1962 @Test
1963 public void testInvalidIfWithChecker()
1964 throws Exception {
1965 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1966
1967 checkConfig.addProperty("arrayInitIndent", "4");
1968 checkConfig.addProperty("basicOffset", "4");
1969 checkConfig.addProperty("braceAdjustment", "0");
1970 checkConfig.addProperty("caseIndent", "4");
1971 checkConfig.addProperty("forceStrictCondition", "false");
1972 checkConfig.addProperty("lineWrappingIndentation", "4");
1973 checkConfig.addProperty("tabWidth", "4");
1974 checkConfig.addProperty("throwsIndent", "4");
1975 final String fileName = getPath("InputIndentationInvalidIfIndent.java");
1976 final String[] expected = {
1977 "55:2: " + getCheckMessage(MSG_ERROR, "if", 1, 8),
1978 "60:10: " + getCheckMessage(MSG_ERROR, "if", 9, 8),
1979 "61:10: " + getCheckMessage(MSG_ERROR, "if lcurly", 9, 8),
1980 "62:8: " + getCheckMessage(MSG_ERROR, "if rcurly", 7, 8),
1981 "64:7: " + getCheckMessage(MSG_ERROR, "if", 6, 8),
1982 "65:6: " + getCheckMessage(MSG_ERROR, "if lcurly", 5, 8),
1983 "66:6: " + getCheckMessage(MSG_ERROR, "if rcurly", 5, 8),
1984 "70:11: " + getCheckMessage(MSG_ERROR, "if rcurly", 10, 8),
1985 "71:8: " + getCheckMessage(MSG_ERROR, "else rcurly", 7, 8),
1986 "74:10: " + getCheckMessage(MSG_ERROR, "if", 9, 8),
1987
1988 "75:8: " + getCheckMessage(MSG_ERROR, "if lcurly", 7, 8),
1989 "77:10: " + getCheckMessage(MSG_ERROR, "else", 9, 8),
1990 "79:10: " + getCheckMessage(MSG_ERROR, "else rcurly", 9, 8),
1991 "82:11: " + getCheckMessage(MSG_ERROR, "if", 10, 8),
1992 "83:8: " + getCheckMessage(MSG_ERROR, "if rcurly", 7, 8),
1993 "84:10: " + getCheckMessage(MSG_ERROR, "else", 9, 8),
1994 "85:8: " + getCheckMessage(MSG_ERROR, "else lcurly", 7, 8),
1995 "86:10: " + getCheckMessage(MSG_ERROR, "else rcurly", 9, 8),
1996
1997 "90:10: " + getCheckMessage(MSG_ERROR, "if", 9, 8),
1998 "91:10: " + getCheckMessage(MSG_ERROR, "if lcurly", 9, 8),
1999 "92:10: " + getCheckMessage(MSG_ERROR, "if rcurly", 9, 8),
2000 "93:8: " + getCheckMessage(MSG_ERROR, "else lcurly", 7, 8),
2001 "94:11: " + getCheckMessage(MSG_ERROR, "else rcurly", 10, 8),
2002 "97:7: " + getCheckMessage(MSG_ERROR, "if", 6, 8),
2003 "98:11: " + getCheckMessage(MSG_ERROR, "if lcurly", 10, 8),
2004 "99:11: " + getCheckMessage(MSG_ERROR, "if rcurly", 10, 8),
2005 "100:8: " + getCheckMessage(MSG_ERROR, "else rcurly", 7, 8),
2006 "103:6: " + getCheckMessage(MSG_ERROR, "if", 5, 8),
2007 "104:12: " + getCheckMessage(MSG_ERROR, "if rcurly", 11, 8),
2008 "105:6: " + getCheckMessage(MSG_ERROR, "else", 5, 8),
2009 "106:12: " + getCheckMessage(MSG_ERROR, "else rcurly", 11, 8),
2010 };
2011 verifyWarns(checkConfig, fileName, expected);
2012 }
2013
2014 @Test
2015 public void testInvalidIfWithChecker1()
2016 throws Exception {
2017 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2018
2019 checkConfig.addProperty("arrayInitIndent", "4");
2020 checkConfig.addProperty("basicOffset", "4");
2021 checkConfig.addProperty("braceAdjustment", "0");
2022 checkConfig.addProperty("caseIndent", "4");
2023 checkConfig.addProperty("forceStrictCondition", "false");
2024 checkConfig.addProperty("lineWrappingIndentation", "4");
2025 checkConfig.addProperty("tabWidth", "4");
2026 checkConfig.addProperty("throwsIndent", "4");
2027 final String fileName = getPath("InputIndentationInvalidIfIndent1.java");
2028 final String[] expected = {
2029 "37:15: " + getCheckMessage(MSG_CHILD_ERROR, "if", 14, 12),
2030 "42:11: " + getCheckMessage(MSG_ERROR, "if lcurly", 10, 8),
2031 "43:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
2032 "48:15: " + getCheckMessage(MSG_CHILD_ERROR, "if", 14, 12),
2033 "49:11: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 10, 12),
2034 "51:11: " + getCheckMessage(MSG_CHILD_ERROR, "else", 10, 12),
2035 "52:9: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 8, 12),
2036
2037 "59:17: " + getCheckMessage(MSG_CHILD_ERROR, "if", 16, 12),
2038 "60:10: " + getCheckMessage(MSG_ERROR, "if rcurly", 9, 8),
2039 "63:17: " + getCheckMessage(MSG_CHILD_ERROR, "else", 16, 12),
2040 "69:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
2041 "73:41: " + getCheckMessage(MSG_CHILD_ERROR, "else", 40, 12),
2042 "80:15: " + getCheckMessage(MSG_CHILD_ERROR, "if", 14, 12),
2043
2044 "83:15: " + getCheckMessage(MSG_CHILD_ERROR, "else", 14, 12),
2045 "89:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
2046 "91:11: " + getCheckMessage(MSG_CHILD_ERROR, "else", 10, 12),
2047 "95:11: " + getCheckMessage(MSG_ERROR, "if", 10, 8),
2048 "96:15: " + getCheckMessage(MSG_CHILD_ERROR, "if", 14, 12),
2049 "97:11: " + getCheckMessage(MSG_ERROR, "if rcurly", 10, 8),
2050 "98:11: " + getCheckMessage(MSG_ERROR, "else", 10, 8),
2051 "99:15: " + getCheckMessage(MSG_CHILD_ERROR, "else", 14, 12),
2052 "100:11: " + getCheckMessage(MSG_ERROR, "else rcurly", 10, 8),
2053 };
2054 verifyWarns(checkConfig, fileName, expected);
2055 }
2056
2057 @Test
2058 public void testInvalidIfWithChecker2()
2059 throws Exception {
2060 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2061
2062 checkConfig.addProperty("arrayInitIndent", "4");
2063 checkConfig.addProperty("basicOffset", "4");
2064 checkConfig.addProperty("braceAdjustment", "0");
2065 checkConfig.addProperty("caseIndent", "4");
2066 checkConfig.addProperty("forceStrictCondition", "false");
2067 checkConfig.addProperty("lineWrappingIndentation", "4");
2068 checkConfig.addProperty("tabWidth", "4");
2069 checkConfig.addProperty("throwsIndent", "4");
2070 final String fileName = getPath("InputIndentationInvalidIfIndent2.java");
2071 final String[] expected = {
2072 "26:10: " + getCheckMessage(MSG_CHILD_ERROR, "if", 9, 12),
2073 "27:12: " + getCheckMessage(MSG_CHILD_ERROR, "if", 11, 12),
2074 "31:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
2075 "34:8: " + getCheckMessage(MSG_ERROR, "if rcurly", 7, 8),
2076 "41:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
2077 "43:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
2078
2079 "50:11: " + getCheckMessage(MSG_CHILD_ERROR, "if", 10, 12),
2080 "59:11: " + getCheckMessage(MSG_ERROR, "if", 10, 12),
2081 "63:19: " + getCheckMessage(MSG_CHILD_ERROR, "if", 18, 20),
2082 "74:11: " + getCheckMessage(MSG_ERROR, "if rparen", 10, 8),
2083 "79:7: " + getCheckMessage(MSG_ERROR, "if rparen", 6, 8),
2084 "85:7: " + getCheckMessage(MSG_ERROR, "if lparen", 6, 8),
2085 "87:7: " + getCheckMessage(MSG_ERROR, "if rparen", 6, 8),
2086 "90:1: " + getCheckMessage(MSG_ERROR, "if", 0, 8),
2087 "91:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
2088 "92:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
2089 "93:1: " + getCheckMessage(MSG_ERROR, "if rcurly", 0, 8),
2090 "94:1: " + getCheckMessage(MSG_ERROR, "if", 0, 8),
2091 "95:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
2092 "96:1: " + getCheckMessage(MSG_ERROR, "else", 0, 8),
2093 "97:1: " + getCheckMessage(MSG_CHILD_ERROR, "else", 0, 12),
2094 };
2095 verifyWarns(checkConfig, fileName, expected);
2096 }
2097
2098 @Test
2099 public void testInvalidWhileWithChecker()
2100 throws Exception {
2101 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2102
2103 checkConfig.addProperty("arrayInitIndent", "4");
2104 checkConfig.addProperty("basicOffset", "4");
2105 checkConfig.addProperty("braceAdjustment", "0");
2106 checkConfig.addProperty("caseIndent", "4");
2107 checkConfig.addProperty("forceStrictCondition", "false");
2108 checkConfig.addProperty("lineWrappingIndentation", "4");
2109 checkConfig.addProperty("tabWidth", "4");
2110 checkConfig.addProperty("throwsIndent", "4");
2111 final String fileName = getPath("InputIndentationInvalidWhileIndent.java");
2112 final String[] expected = {
2113 "25:10: " + getCheckMessage(MSG_ERROR, "while", 9, 8),
2114 "26:8: " + getCheckMessage(MSG_ERROR, "while rcurly", 7, 8),
2115 "28:8: " + getCheckMessage(MSG_ERROR, "while", 7, 8),
2116 "29:10: " + getCheckMessage(MSG_ERROR, "while lcurly", 9, 8),
2117 "30:10: " + getCheckMessage(MSG_ERROR, "while rcurly", 9, 8),
2118
2119 "32:10: " + getCheckMessage(MSG_ERROR, "while", 9, 8),
2120 "33:7: " + getCheckMessage(MSG_ERROR, "while lcurly", 6, 8),
2121 "34:15: " + getCheckMessage(MSG_CHILD_ERROR, "while", 14, 12),
2122 "35:7: " + getCheckMessage(MSG_ERROR, "while rcurly", 6, 8),
2123
2124 "37:11: " + getCheckMessage(MSG_ERROR, "while", 10, 8),
2125 "39:11: " + getCheckMessage(MSG_ERROR, "while rcurly", 10, 8),
2126 "41:11: " + getCheckMessage(MSG_ERROR, "while", 10, 8),
2127 "44:11: " + getCheckMessage(MSG_ERROR, "while rcurly", 10, 8),
2128
2129 "46:7: " + getCheckMessage(MSG_ERROR, "while", 6, 8),
2130 "47:11: " + getCheckMessage(MSG_ERROR, "while lcurly", 10, 8),
2131 "50:7: " + getCheckMessage(MSG_ERROR, "while rcurly", 6, 8),
2132 "53:15: " + getCheckMessage(MSG_ERROR, "if", 14, 12),
2133 "54:19: " + getCheckMessage(MSG_CHILD_ERROR, "if", 18, 16),
2134 "55:15: " + getCheckMessage(MSG_ERROR, "if rcurly", 14, 12),
2135 "56:15: " + getCheckMessage(MSG_CHILD_ERROR, "while", 14, 12),
2136 "57:11: " + getCheckMessage(MSG_ERROR, "while rcurly", 10, 8),
2137
2138 "60:11: " + getCheckMessage(MSG_CHILD_ERROR, "while", 10, 12),
2139 "66:11: " + getCheckMessage(MSG_CHILD_ERROR, "while", 10, 12),
2140 "71:11: " + getCheckMessage(MSG_CHILD_ERROR, "while", 10, 12),
2141 "78:6: " + getCheckMessage(MSG_ERROR, "while rparen", 5, 8),
2142 "85:11: " + getCheckMessage(MSG_ERROR, "while rparen", 10, 8),
2143 "92:11: " + getCheckMessage(MSG_ERROR, "while rparen", 10, 8),
2144 "99:9: " + getCheckMessage(MSG_CHILD_ERROR, "while", 8, 12),
2145 };
2146 verifyWarns(checkConfig, fileName, expected);
2147 }
2148
2149 @Test
2150 public void testInvalidInvalidAnonymousClass() throws Exception {
2151 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2152
2153 checkConfig.addProperty("arrayInitIndent", "4");
2154 checkConfig.addProperty("basicOffset", "4");
2155 checkConfig.addProperty("braceAdjustment", "0");
2156 checkConfig.addProperty("caseIndent", "4");
2157 checkConfig.addProperty("forceStrictCondition", "false");
2158 checkConfig.addProperty("lineWrappingIndentation", "4");
2159 checkConfig.addProperty("tabWidth", "4");
2160 checkConfig.addProperty("throwsIndent", "4");
2161 final String fileName = getPath("InputIndentationInvalidAnonymousClassIndent.java");
2162 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2163 verifyWarns(checkConfig, fileName, expected);
2164 }
2165
2166 @Test
2167 public void testInvalidForWithChecker()
2168 throws Exception {
2169 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2170
2171 checkConfig.addProperty("arrayInitIndent", "4");
2172 checkConfig.addProperty("basicOffset", "4");
2173 checkConfig.addProperty("braceAdjustment", "0");
2174 checkConfig.addProperty("caseIndent", "4");
2175 checkConfig.addProperty("forceStrictCondition", "false");
2176 checkConfig.addProperty("lineWrappingIndentation", "4");
2177 checkConfig.addProperty("tabWidth", "4");
2178 checkConfig.addProperty("throwsIndent", "4");
2179 final String fileName = getPath("InputIndentationInvalidForIndent.java");
2180 final String[] expected = {
2181 "26:7: " + getCheckMessage(MSG_ERROR, "for", 6, 8),
2182 "27:11: " + getCheckMessage(MSG_ERROR, "for rcurly", 10, 8),
2183 "29:10: " + getCheckMessage(MSG_ERROR, "for", 9, 8),
2184 "30:7: " + getCheckMessage(MSG_ERROR, "for lcurly", 6, 8),
2185 "31:7: " + getCheckMessage(MSG_ERROR, "for rcurly", 6, 8),
2186 "35:11: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
2187
2188 "36:11: " + getCheckMessage(MSG_ERROR, "for rcurly", 10, 8),
2189 "39:11: " + getCheckMessage(MSG_ERROR, "for lcurly", 10, 8),
2190 "40:11: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
2191 "48:11: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
2192 "54:8: " + getCheckMessage(MSG_ERROR, "for", 7, 8),
2193
2194 "55:11: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
2195 "64:8: " + getCheckMessage(MSG_CHILD_ERROR, "for", 7, 12),
2196
2197 "69:7: " + getCheckMessage(MSG_ERROR, "for", 6, 8),
2198 "70:11: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
2199 "71:15: " + getCheckMessage(MSG_CHILD_ERROR, "for", 14, 16),
2200 "72:11: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
2201 "81:13: " + getCheckMessage(MSG_ERROR, "for rparen", 12, 8),
2202 "86:3: " + getCheckMessage(MSG_ERROR, "method def modifier", 2, 4),
2203 "87:5: " + getCheckMessage(MSG_ERROR, "for", 4, 8),
2204 "88:9: " + getCheckMessage(MSG_CHILD_ERROR, "for", 8, 12),
2205 "89:7: " + getCheckMessage(MSG_CHILD_ERROR, "for", 6, 12),
2206 "90:9: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 8, 16),
2207 "92:1: " + getCheckMessage(MSG_ERROR, "for", 0, 8),
2208 "93:1: " + getCheckMessage(MSG_ERROR, "for lparen", 0, 8),
2209 "94:1: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
2210 "95:1: " + getCheckMessage(MSG_ERROR, ";", 0, 4),
2211 "96:1: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
2212 "97:1: " + getCheckMessage(MSG_ERROR, ";", 0, 4),
2213 "98:1: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
2214 };
2215 verifyWarns(checkConfig, fileName, expected);
2216 }
2217
2218 @Test
2219 public void testValidForWithChecker()
2220 throws Exception {
2221 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2222
2223 checkConfig.addProperty("arrayInitIndent", "4");
2224 checkConfig.addProperty("basicOffset", "4");
2225 checkConfig.addProperty("braceAdjustment", "0");
2226 checkConfig.addProperty("caseIndent", "4");
2227 checkConfig.addProperty("forceStrictCondition", "false");
2228 checkConfig.addProperty("lineWrappingIndentation", "4");
2229 checkConfig.addProperty("tabWidth", "4");
2230 checkConfig.addProperty("throwsIndent", "4");
2231 final String fileName = getPath("InputIndentationValidForIndent.java");
2232 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2233 verifyWarns(checkConfig, fileName, expected);
2234 }
2235
2236 @Test
2237 public void testValidDoWhileWithChecker()
2238 throws Exception {
2239 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2240
2241 checkConfig.addProperty("arrayInitIndent", "4");
2242 checkConfig.addProperty("basicOffset", "4");
2243 checkConfig.addProperty("braceAdjustment", "0");
2244 checkConfig.addProperty("caseIndent", "4");
2245 checkConfig.addProperty("forceStrictCondition", "false");
2246 checkConfig.addProperty("lineWrappingIndentation", "4");
2247 checkConfig.addProperty("tabWidth", "4");
2248 checkConfig.addProperty("throwsIndent", "4");
2249 final String fileName = getPath("InputIndentationValidDoWhileIndent.java");
2250 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2251 verifyWarns(checkConfig, fileName, expected);
2252 }
2253
2254 @Test
2255 public void testInvalidDoWhileWithChecker()
2256 throws Exception {
2257 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2258
2259 checkConfig.addProperty("arrayInitIndent", "4");
2260 checkConfig.addProperty("basicOffset", "4");
2261 checkConfig.addProperty("braceAdjustment", "0");
2262 checkConfig.addProperty("caseIndent", "4");
2263 checkConfig.addProperty("forceStrictCondition", "false");
2264 checkConfig.addProperty("lineWrappingIndentation", "4");
2265 checkConfig.addProperty("tabWidth", "4");
2266 checkConfig.addProperty("throwsIndent", "4");
2267 final String fileName = getPath("InputIndentationInvalidDoWhileIndent.java");
2268 final String[] expected = {
2269 "7:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2270 "8:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2271 "9:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2272 "10:1: " + getCheckMessage(MSG_ERROR, "do..while rcurly", 0, 8),
2273 "11:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2274 "12:1: " + getCheckMessage(MSG_ERROR, "do..while while", 0, 8),
2275 "13:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2276 "14:1: " + getCheckMessage(MSG_ERROR, "do..while lcurly", 0, 8),
2277 "15:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2278 "16:1: " + getCheckMessage(MSG_ERROR, "do..while while", 0, 8),
2279 "17:1: " + getCheckMessage(MSG_ERROR, "do..while lparen", 0, 8),
2280 "18:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2281 "19:1: " + getCheckMessage(MSG_ERROR, "do..while lparen", 0, 8),
2282 "20:1: " + getCheckMessage(MSG_ERROR, "do..while", 0, 8),
2283 "21:1: " + getCheckMessage(MSG_ERROR, "do..while lparen", 0, 8),
2284 "22:1: " + getCheckMessage(MSG_CHILD_ERROR, "do..while", 0, 8),
2285 "23:1: " + getCheckMessage(MSG_ERROR, "do..while rparen", 0, 8),
2286 };
2287 verifyWarns(checkConfig, fileName, expected);
2288 }
2289
2290 @Test
2291 public void testValidBlockWithChecker()
2292 throws Exception {
2293 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2294
2295 checkConfig.addProperty("arrayInitIndent", "4");
2296 checkConfig.addProperty("basicOffset", "4");
2297 checkConfig.addProperty("braceAdjustment", "0");
2298 checkConfig.addProperty("caseIndent", "4");
2299 checkConfig.addProperty("forceStrictCondition", "false");
2300 checkConfig.addProperty("lineWrappingIndentation", "4");
2301 checkConfig.addProperty("tabWidth", "4");
2302 checkConfig.addProperty("throwsIndent", "4");
2303 final String fileName = getPath("InputIndentationValidBlockIndent.java");
2304 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2305 verifyWarns(checkConfig, fileName, expected);
2306 }
2307
2308 @Test
2309 public void testValidBlockWithChecker1()
2310 throws Exception {
2311 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2312
2313 checkConfig.addProperty("arrayInitIndent", "4");
2314 checkConfig.addProperty("basicOffset", "4");
2315 checkConfig.addProperty("braceAdjustment", "0");
2316 checkConfig.addProperty("caseIndent", "4");
2317 checkConfig.addProperty("forceStrictCondition", "false");
2318 checkConfig.addProperty("lineWrappingIndentation", "4");
2319 checkConfig.addProperty("tabWidth", "4");
2320 checkConfig.addProperty("throwsIndent", "4");
2321 final String fileName = getPath("InputIndentationValidBlockIndent1.java");
2322 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2323 verifyWarns(checkConfig, fileName, expected);
2324 }
2325
2326 @Test
2327 public void testValidWhileWithChecker()
2328 throws Exception {
2329 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2330
2331 checkConfig.addProperty("arrayInitIndent", "4");
2332 checkConfig.addProperty("basicOffset", "4");
2333 checkConfig.addProperty("braceAdjustment", "0");
2334 checkConfig.addProperty("caseIndent", "4");
2335 checkConfig.addProperty("forceStrictCondition", "false");
2336 checkConfig.addProperty("lineWrappingIndentation", "4");
2337 checkConfig.addProperty("tabWidth", "4");
2338 checkConfig.addProperty("throwsIndent", "4");
2339 final String fileName = getPath("InputIndentationValidWhileIndent.java");
2340 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2341 verifyWarns(checkConfig, fileName, expected);
2342 }
2343
2344 @Test
2345 public void testValidClassDefWithChecker()
2346 throws Exception {
2347 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2348
2349 checkConfig.addProperty("arrayInitIndent", "4");
2350 checkConfig.addProperty("basicOffset", "4");
2351 checkConfig.addProperty("braceAdjustment", "0");
2352 checkConfig.addProperty("caseIndent", "4");
2353 checkConfig.addProperty("forceStrictCondition", "false");
2354 checkConfig.addProperty("lineWrappingIndentation", "4");
2355 checkConfig.addProperty("tabWidth", "4");
2356 checkConfig.addProperty("throwsIndent", "4");
2357 final String fileName = getPath("InputIndentationValidClassDefIndent.java");
2358 final String[] expected = {
2359 "38:9: " + getCheckMessage(MSG_ERROR, "int", 8, 12),
2360 };
2361 verifyWarns(checkConfig, fileName, expected);
2362 }
2363
2364 @Test
2365 public void testValidClassDefWithChecker1()
2366 throws Exception {
2367 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2368
2369 checkConfig.addProperty("arrayInitIndent", "4");
2370 checkConfig.addProperty("basicOffset", "4");
2371 checkConfig.addProperty("braceAdjustment", "0");
2372 checkConfig.addProperty("caseIndent", "4");
2373 checkConfig.addProperty("forceStrictCondition", "false");
2374 checkConfig.addProperty("lineWrappingIndentation", "4");
2375 checkConfig.addProperty("tabWidth", "4");
2376 checkConfig.addProperty("throwsIndent", "4");
2377 final String fileName = getPath("InputIndentationValidClassDefIndent1.java");
2378 final String[] expected = {
2379 "43:1: " + getCheckMessage(MSG_ERROR, "class", 0, 4),
2380 };
2381 verifyWarns(checkConfig, fileName, expected);
2382 }
2383
2384 @Test
2385 public void testValidInterfaceDefWithChecker()
2386 throws Exception {
2387 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2388
2389 checkConfig.addProperty("arrayInitIndent", "4");
2390 checkConfig.addProperty("basicOffset", "4");
2391 checkConfig.addProperty("braceAdjustment", "0");
2392 checkConfig.addProperty("caseIndent", "4");
2393 checkConfig.addProperty("forceStrictCondition", "false");
2394 checkConfig.addProperty("lineWrappingIndentation", "4");
2395 checkConfig.addProperty("tabWidth", "4");
2396 checkConfig.addProperty("throwsIndent", "4");
2397 final String fileName = getPath("InputIndentationValidInterfaceDefIndent.java");
2398 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2399 verifyWarns(checkConfig, fileName, expected);
2400 }
2401
2402 @Test
2403 public void testValidCommaWithChecker()
2404 throws Exception {
2405 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2406
2407 checkConfig.addProperty("arrayInitIndent", "4");
2408 checkConfig.addProperty("basicOffset", "4");
2409 checkConfig.addProperty("braceAdjustment", "0");
2410 checkConfig.addProperty("caseIndent", "4");
2411 checkConfig.addProperty("forceStrictCondition", "false");
2412 checkConfig.addProperty("lineWrappingIndentation", "4");
2413 checkConfig.addProperty("tabWidth", "4");
2414 checkConfig.addProperty("throwsIndent", "4");
2415 final String fileName = getPath("InputIndentationValidCommaIndent.java");
2416 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2417 verifyWarns(checkConfig, fileName, expected);
2418 }
2419
2420 @Test
2421 public void testTabs() throws Exception {
2422 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2423
2424 checkConfig.addProperty("arrayInitIndent", "4");
2425 checkConfig.addProperty("basicOffset", "4");
2426 checkConfig.addProperty("braceAdjustment", "0");
2427 checkConfig.addProperty("caseIndent", "4");
2428 checkConfig.addProperty("forceStrictCondition", "false");
2429 checkConfig.addProperty("lineWrappingIndentation", "4");
2430 checkConfig.addProperty("tabWidth", "4");
2431 checkConfig.addProperty("throwsIndent", "4");
2432 final String[] expected = {
2433 "29:10: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 9, 8),
2434 };
2435 verifyWarns(checkConfig, getPath("InputIndentationUseTabs.java"), expected);
2436 }
2437
2438 @Test
2439 public void testIndentationLevel() throws Exception {
2440 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2441
2442 checkConfig.addProperty("arrayInitIndent", "4");
2443 checkConfig.addProperty("basicOffset", "2");
2444 checkConfig.addProperty("braceAdjustment", "0");
2445 checkConfig.addProperty("caseIndent", "4");
2446 checkConfig.addProperty("forceStrictCondition", "false");
2447 checkConfig.addProperty("lineWrappingIndentation", "2");
2448 checkConfig.addProperty("tabWidth", "4");
2449 checkConfig.addProperty("throwsIndent", "4");
2450 final String[] expected = {
2451 "29:6: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 5, 4),
2452 };
2453 verifyWarns(checkConfig, getPath("InputIndentationUseTwoSpaces.java"), expected);
2454 }
2455
2456 @Test
2457 public void testThrowsIndentationLevel() throws Exception {
2458 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2459
2460 checkConfig.addProperty("arrayInitIndent", "4");
2461 checkConfig.addProperty("basicOffset", "4");
2462 checkConfig.addProperty("braceAdjustment", "0");
2463 checkConfig.addProperty("caseIndent", "4");
2464 checkConfig.addProperty("forceStrictCondition", "false");
2465 checkConfig.addProperty("lineWrappingIndentation", "4");
2466 checkConfig.addProperty("tabWidth", "4");
2467 checkConfig.addProperty("throwsIndent", "8");
2468 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2469 verifyWarns(checkConfig, getPath("InputIndentationInvalidThrowsIndent.java"), expected);
2470 }
2471
2472 @Test
2473 public void testThrowsIndentationLevel2() throws Exception {
2474 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2475
2476 checkConfig.addProperty("basicOffset", "1");
2477 checkConfig.addProperty("forceStrictCondition", "true");
2478 checkConfig.addProperty("lineWrappingIndentation", "3");
2479 checkConfig.addProperty("tabWidth", "4");
2480 checkConfig.addProperty("throwsIndent", "5");
2481 final String[] expected = {
2482 "7:1: " + getCheckMessage(MSG_ERROR, "Exception", 0, 6),
2483 "10:1: " + getCheckMessage(MSG_ERROR, "NullPointerException", 0, 6),
2484 "13:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2485 "16:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2486 "18:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2487 "19:1: " + getCheckMessage(MSG_ERROR, "Exception", 0, 6),
2488 "22:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2489 "23:1: " + getCheckMessage(MSG_ERROR, "Exception", 0, 6),
2490 "24:1: " + getCheckMessage(MSG_ERROR, "NullPointerException", 0, 6),
2491 "27:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2492 "28:1: " + getCheckMessage(MSG_ERROR, "Exception", 0, 6),
2493 "31:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2494 "37:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 6),
2495 };
2496 verifyWarns(checkConfig, getPath("InputIndentationInvalidThrowsIndent2.java"), expected);
2497 }
2498
2499 @Test
2500 public void testCaseLevel() throws Exception {
2501 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2502
2503 checkConfig.addProperty("arrayInitIndent", "4");
2504 checkConfig.addProperty("basicOffset", "4");
2505 checkConfig.addProperty("braceAdjustment", "0");
2506 checkConfig.addProperty("caseIndent", "0");
2507 checkConfig.addProperty("forceStrictCondition", "false");
2508 checkConfig.addProperty("lineWrappingIndentation", "4");
2509 checkConfig.addProperty("tabWidth", "4");
2510 checkConfig.addProperty("throwsIndent", "4");
2511 final String[] expected = {
2512 "27:11: " + getCheckMessage(MSG_CHILD_ERROR, "case", 10, 8),
2513 };
2514 verifyWarns(checkConfig, getPath("InputIndentationCaseLevel.java"), expected);
2515 }
2516
2517 @Test
2518 public void testBraceAdjustment() throws Exception {
2519 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2520
2521 checkConfig.addProperty("arrayInitIndent", "4");
2522 checkConfig.addProperty("basicOffset", "4");
2523 checkConfig.addProperty("braceAdjustment", "2");
2524 checkConfig.addProperty("caseIndent", "4");
2525 checkConfig.addProperty("forceStrictCondition", "false");
2526 checkConfig.addProperty("lineWrappingIndentation", "4");
2527 checkConfig.addProperty("tabWidth", "4");
2528 checkConfig.addProperty("throwsIndent", "4");
2529 final String[] expected = {
2530 "24:9: " + getCheckMessage(MSG_CHILD_ERROR, "ctor def", 8, 10),
2531 "25:9: " + getCheckMessage(MSG_ERROR, "if", 8, 10),
2532 "26:11: " + getCheckMessage(MSG_ERROR, "if lcurly", 10, 12),
2533 "27:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "if", 12, "14, 16"),
2534 "28:9: " + getCheckMessage(MSG_ERROR, "if rcurly", 8, 12),
2535 };
2536 verifyWarns(checkConfig, getPath("InputIndentationBraceAdjustment.java"), expected);
2537 }
2538
2539 @Test
2540 public void testInvalidAssignWithChecker() throws Exception {
2541 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2542
2543 checkConfig.addProperty("arrayInitIndent", "4");
2544 checkConfig.addProperty("basicOffset", "4");
2545 checkConfig.addProperty("braceAdjustment", "0");
2546 checkConfig.addProperty("caseIndent", "4");
2547 checkConfig.addProperty("forceStrictCondition", "false");
2548 checkConfig.addProperty("lineWrappingIndentation", "4");
2549 checkConfig.addProperty("tabWidth", "4");
2550 checkConfig.addProperty("throwsIndent", "4");
2551 final String[] expected = {
2552 "22:11: " + getCheckMessage(MSG_ERROR, "getLineNo", 10, 12),
2553 "24:11: " + getCheckMessage(MSG_ERROR, "getLine", 10, 12),
2554 "28:10: " + getCheckMessage(MSG_ERROR, "=", 9, 12),
2555 "29:11: " + getCheckMessage(MSG_ERROR, "1", 10, 12),
2556 };
2557 verifyWarns(checkConfig, getPath("InputIndentationInvalidAssignIndent.java"), expected);
2558 }
2559
2560 @Test
2561 public void testInvalidImportIndent() throws Exception {
2562 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2563 checkConfig.addProperty("basicOffset", "8");
2564 checkConfig.addProperty("tabWidth", "4");
2565 final String[] expected = {
2566 "4:3: " + getCheckMessage(MSG_ERROR, ".", 2, 4),
2567 "5:2: " + getCheckMessage(MSG_ERROR, "import", 1, 0),
2568 };
2569 verifyWarns(checkConfig, getPath("InputIndentationInvalidImportIndent.java"), expected);
2570 }
2571
2572 @Test
2573 public void testValidAssignWithChecker() throws Exception {
2574 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2575
2576 checkConfig.addProperty("arrayInitIndent", "4");
2577 checkConfig.addProperty("basicOffset", "4");
2578 checkConfig.addProperty("braceAdjustment", "0");
2579 checkConfig.addProperty("caseIndent", "4");
2580 checkConfig.addProperty("forceStrictCondition", "false");
2581 checkConfig.addProperty("lineWrappingIndentation", "4");
2582 checkConfig.addProperty("tabWidth", "4");
2583 checkConfig.addProperty("throwsIndent", "4");
2584 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2585 verifyWarns(checkConfig, getPath("InputIndentationValidAssignIndent.java"), expected);
2586 }
2587
2588 @Test
2589 public void test15Extensions() throws Exception {
2590 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2591
2592 checkConfig.addProperty("arrayInitIndent", "4");
2593 checkConfig.addProperty("basicOffset", "4");
2594 checkConfig.addProperty("braceAdjustment", "0");
2595 checkConfig.addProperty("caseIndent", "4");
2596 checkConfig.addProperty("forceStrictCondition", "false");
2597 checkConfig.addProperty("lineWrappingIndentation", "4");
2598 checkConfig.addProperty("tabWidth", "4");
2599 checkConfig.addProperty("throwsIndent", "4");
2600 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2601 verifyWarns(checkConfig, getPath("InputIndentation15Extensions.java"), expected);
2602 }
2603
2604 @Test
2605 public void testTryResources() throws Exception {
2606 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2607
2608 checkConfig.addProperty("arrayInitIndent", "4");
2609 checkConfig.addProperty("basicOffset", "4");
2610 checkConfig.addProperty("braceAdjustment", "0");
2611 checkConfig.addProperty("caseIndent", "4");
2612 checkConfig.addProperty("forceStrictCondition", "false");
2613 checkConfig.addProperty("lineWrappingIndentation", "4");
2614 checkConfig.addProperty("tabWidth", "4");
2615 checkConfig.addProperty("throwsIndent", "4");
2616 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2617 verifyWarns(checkConfig, getPath("InputIndentationValidTryResourcesIndent.java"),
2618 expected);
2619 }
2620
2621 @Test
2622 public void testSwitchCustom() throws Exception {
2623 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2624
2625 checkConfig.addProperty("arrayInitIndent", "4");
2626 checkConfig.addProperty("basicOffset", "4");
2627 checkConfig.addProperty("braceAdjustment", "0");
2628 checkConfig.addProperty("caseIndent", "4");
2629 checkConfig.addProperty("forceStrictCondition", "false");
2630 checkConfig.addProperty("lineWrappingIndentation", "8");
2631 checkConfig.addProperty("tabWidth", "4");
2632 checkConfig.addProperty("throwsIndent", "8");
2633 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2634 verifyWarns(checkConfig, getPath("InputIndentationSwitchCustom.java"),
2635 expected);
2636 }
2637
2638 @Test
2639 public void testSynchronizedStatement() throws Exception {
2640 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2641 checkConfig.addProperty("arrayInitIndent", "4");
2642 checkConfig.addProperty("basicOffset", "4");
2643 checkConfig.addProperty("braceAdjustment", "0");
2644 checkConfig.addProperty("caseIndent", "4");
2645 checkConfig.addProperty("forceStrictCondition", "false");
2646 checkConfig.addProperty("lineWrappingIndentation", "8");
2647 checkConfig.addProperty("tabWidth", "4");
2648 checkConfig.addProperty("throwsIndent", "8");
2649 final String[] expected = {
2650 "27:1: " + getCheckMessage(MSG_CHILD_ERROR, "synchronized", 0, 12),
2651 "30:13: " + getCheckMessage(MSG_ERROR, "synchronized lparen", 12, 8),
2652 };
2653 verifyWarns(checkConfig, getPath("InputIndentationSynchronizedStatement.java"), expected);
2654 }
2655
2656 @Test
2657 public void testSynchronizedMethod() throws Exception {
2658 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2659 checkConfig.addProperty("arrayInitIndent", "4");
2660 checkConfig.addProperty("basicOffset", "4");
2661 checkConfig.addProperty("braceAdjustment", "0");
2662 checkConfig.addProperty("caseIndent", "4");
2663 checkConfig.addProperty("forceStrictCondition", "false");
2664 checkConfig.addProperty("lineWrappingIndentation", "8");
2665 checkConfig.addProperty("tabWidth", "4");
2666 checkConfig.addProperty("throwsIndent", "8");
2667 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2668 verifyWarns(checkConfig, getPath("InputIndentationSynchronizedMethod.java"), expected);
2669 }
2670
2671 @Test
2672 public void testAnonymousClassInMethod() throws Exception {
2673 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2674 checkConfig.addProperty("tabWidth", "8");
2675 checkConfig.addProperty("basicOffset", "2");
2676 checkConfig.addProperty("braceAdjustment", "0");
2677 checkConfig.addProperty("caseIndent", "2");
2678 checkConfig.addProperty("lineWrappingIndentation", "4");
2679 checkConfig.addProperty("throwsIndent", "4");
2680 checkConfig.addProperty("arrayInitIndent", "2");
2681 final String[] expected = {
2682 "19:9: " + getCheckMessage(MSG_ERROR, "method def modifier", 8, 2),
2683 "20:17: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 16, 4),
2684 "21:25: " + getCheckMessage(MSG_ERROR_MULTI, "method def modifier", 24, "18, 20, 22"),
2685 "23:33: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "method def", 32, "20, 22, 24"),
2686 "24:25: " + getCheckMessage(MSG_ERROR_MULTI, "method def rcurly", 24, "18, 20, 22"),
2687 "26:9: " + getCheckMessage(MSG_ERROR, "method def rcurly", 8, 2),
2688 };
2689 verifyWarns(checkConfig, getPath("InputIndentationAnonymousClassInMethod.java"), expected);
2690 }
2691
2692 @Test
2693 public void testAnonymousClassInMethodWithCurlyOnNewLine() throws Exception {
2694 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2695 checkConfig.addProperty("tabWidth", "4");
2696 checkConfig.addProperty("basicOffset", "4");
2697 checkConfig.addProperty("braceAdjustment", "0");
2698 checkConfig.addProperty("caseIndent", "4");
2699 checkConfig.addProperty("lineWrappingIndentation", "8");
2700 checkConfig.addProperty("throwsIndent", "4");
2701 checkConfig.addProperty("arrayInitIndent", "4");
2702 final String[] expected = {
2703 "38:19: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 18, "16, 20, 24"),
2704 "40:15: " + getCheckMessage(MSG_ERROR, "new", 14, 16),
2705 "46:15: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 14, "16, 20, 24"),
2706 "58:19: " + getCheckMessage(MSG_ERROR_MULTI, "object def lcurly", 18, "16, 20, 24"),
2707 "64:19: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 18, "16, 20, 24"),
2708 "67:15: " + getCheckMessage(MSG_ERROR_MULTI, "object def lcurly", 14, "16, 20, 24"),
2709 "73:15: " + getCheckMessage(MSG_ERROR_MULTI, "object def rcurly", 14, "16, 20, 24"),
2710 };
2711 verifyWarns(checkConfig,
2712 getPath("InputIndentationAnonymousClassInMethodCurlyOnNewLine.java"), expected);
2713 }
2714
2715 @Test
2716 public void testAnnotationDefinition() throws Exception {
2717 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2718 checkConfig.addProperty("tabWidth", "4");
2719 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2720 verifyWarns(checkConfig, getPath("InputIndentationAnnotationDefinition.java"), expected);
2721 }
2722
2723 @Test
2724 public void testPackageDeclaration() throws Exception {
2725 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2726 checkConfig.addProperty("tabWidth", "4");
2727 final String[] expected = {
2728 "1:2: " + getCheckMessage(MSG_ERROR, "package def", 1, 0),
2729 };
2730 verifyWarns(checkConfig, getPath("InputIndentationPackageDeclaration.java"), expected);
2731 }
2732
2733 @Test
2734 public void testPackageDeclaration2() throws Exception {
2735 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2736 checkConfig.addProperty("tabWidth", "4");
2737 final String[] expected = {
2738 "2:2: " + getCheckMessage(MSG_ERROR, "package def", 1, 0),
2739 };
2740 verifyWarns(checkConfig,
2741 getPath("package-info.java"), expected);
2742 }
2743
2744 @Test
2745 public void testPackageDeclaration3() throws Exception {
2746 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2747 checkConfig.addProperty("tabWidth", "4");
2748 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2749 verifyWarns(checkConfig, getPath("InputIndentationPackageDeclaration3.java"), expected);
2750 }
2751
2752 @Test
2753 public void testPackageDeclaration4() throws Exception {
2754 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2755 checkConfig.addProperty("tabWidth", "4");
2756 final String[] expected = {
2757 "2:1: " + getCheckMessage(MSG_ERROR, "com", 0, 4),
2758 "3:1: " + getCheckMessage(MSG_ERROR, "checks", 0, 4),
2759 };
2760 verifyWarns(checkConfig, getPath("InputIndentationPackageDeclaration4.java"), expected);
2761 }
2762
2763 @Test
2764 public void testLambda() throws Exception {
2765 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2766 checkConfig.addProperty("tabWidth", "2");
2767 checkConfig.addProperty("basicOffset", "2");
2768 checkConfig.addProperty("lineWrappingIndentation", "4");
2769 final String[] expected = {
2770 "37:6: " + getCheckMessage(MSG_ERROR_MULTI, "block lcurly", 5, "4, 8"),
2771 "38:6: " + getCheckMessage(MSG_ERROR_MULTI, "block rcurly", 5, "4, 8"),
2772 "42:12: " + getCheckMessage(MSG_ERROR, "lambda", 11, 12),
2773 "43:10: " + getCheckMessage(MSG_ERROR, "block lcurly", 9, 8),
2774 "55:8: " + getCheckMessage(MSG_CHILD_ERROR, "block", 7, 6),
2775 "56:6: " + getCheckMessage(MSG_ERROR, "block rcurly", 5, 4),
2776 };
2777 verifyWarns(checkConfig, getPath("InputIndentationLambda.java"), expected);
2778 }
2779
2780 @Test
2781 public void testLambda1() throws Exception {
2782 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2783 checkConfig.addProperty("tabWidth", "2");
2784 checkConfig.addProperty("basicOffset", "2");
2785 checkConfig.addProperty("lineWrappingIndentation", "4");
2786 final String[] expected = {
2787 "68:10: " + getCheckMessage(MSG_CHILD_ERROR, "block", 9, 10),
2788 "69:12: " + getCheckMessage(MSG_CHILD_ERROR, "block", 11, 10),
2789 "74:8: " + getCheckMessage(MSG_ERROR, "block rcurly", 7, 8),
2790 };
2791 verifyWarns(checkConfig, getPath("InputIndentationLambda1.java"), expected);
2792 }
2793
2794 @Test
2795 public void testLambda2() throws Exception {
2796 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2797 checkConfig.addProperty("tabWidth", "4");
2798 checkConfig.addProperty("basicOffset", "4");
2799 checkConfig.addProperty("lineWrappingIndentation", "8");
2800 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2801 verifyWarns(checkConfig, getPath("InputIndentationLambda2.java"), expected);
2802 }
2803
2804 @Test
2805 public void testLambda3() throws Exception {
2806 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2807 checkConfig.addProperty("tabWidth", "4");
2808 checkConfig.addProperty("basicOffset", "4");
2809 checkConfig.addProperty("lineWrappingIndentation", "8");
2810 final String[] expected = {
2811 "15:13: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 12, 8),
2812 "29:13: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 12, 8),
2813 "30:13: " + getCheckMessage(MSG_CHILD_ERROR, "block", 12, 16),
2814 "31:9: " + getCheckMessage(MSG_ERROR, "block rcurly", 8, 12),
2815 "65:13: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 12, 8),
2816 "87:13: " + getCheckMessage(MSG_ERROR, "method def rcurly", 12, 8),
2817 };
2818 verifyWarns(checkConfig, getPath("InputIndentationLambda3.java"), expected);
2819 }
2820
2821 @Test
2822 public void testLambda4() throws Exception {
2823 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2824 checkConfig.addProperty("tabWidth", "4");
2825 checkConfig.addProperty("basicOffset", "4");
2826 checkConfig.addProperty("lineWrappingIndentation", "8");
2827 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2828 verifyWarns(checkConfig, getPath("InputIndentationLambda4.java"), expected);
2829 }
2830
2831 @Test
2832 public void testLambda5() throws Exception {
2833 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2834 checkConfig.addProperty("tabWidth", "3");
2835 checkConfig.addProperty("basicOffset", "3");
2836 checkConfig.addProperty("caseIndent", "0");
2837 checkConfig.addProperty("lineWrappingIndentation", "6");
2838 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2839 verifyWarns(checkConfig, getPath("InputIndentationLambda5.java"), expected);
2840 }
2841
2842 @Test
2843 public void testLambdaFalseForceStrictCondition() throws Exception {
2844 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2845 checkConfig.addProperty("tabWidth", "4");
2846 checkConfig.addProperty("basicOffset", "4");
2847 checkConfig.addProperty("braceAdjustment", "0");
2848 checkConfig.addProperty("forceStrictCondition", "false");
2849 checkConfig.addProperty("lineWrappingIndentation", "0");
2850 final String[] expected = {
2851 "34:5: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
2852 "35:5: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 4, 12),
2853 "36:5: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
2854 "47:5: " + getCheckMessage(MSG_ERROR_MULTI, "block rcurly", 4, "8, 16"),
2855 "73:5: " + getCheckMessage(MSG_ERROR, "->", 4, 8),
2856 };
2857
2858 verifyWarns(checkConfig, getPath("InputIndentationLambda6.java"), expected);
2859 }
2860
2861 @Test
2862 public void testLambdaTrueForceStrictCondition() throws Exception {
2863 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2864 checkConfig.addProperty("tabWidth", "4");
2865 checkConfig.addProperty("basicOffset", "4");
2866 checkConfig.addProperty("braceAdjustment", "0");
2867 checkConfig.addProperty("forceStrictCondition", "true");
2868 checkConfig.addProperty("lineWrappingIndentation", "4");
2869 final String[] expected = {
2870 "23:17: " + getCheckMessage(MSG_ERROR, "(", 16, 12),
2871 "24:17: " + getCheckMessage(MSG_ERROR, "->", 16, 12),
2872 "26:27: " + getCheckMessage(MSG_ERROR, "\"SECOND_ARG\"", 26, 12),
2873 "27:26: " + getCheckMessage(MSG_ERROR, "(", 25, 12),
2874 "30:17: " + getCheckMessage(MSG_ERROR, "(", 16, 12),
2875 "31:21: " + getCheckMessage(MSG_ERROR, "if", 20, 16),
2876 "32:25: " + getCheckMessage(MSG_CHILD_ERROR, "if", 24, 20),
2877 "33:21: " + getCheckMessage(MSG_ERROR, "if rcurly", 20, 16),
2878 "34:25: " + getCheckMessage(MSG_CHILD_ERROR, "else", 24, 20),
2879 "35:21: " + getCheckMessage(MSG_ERROR, "else rcurly", 20, 16),
2880 "36:17: " + getCheckMessage(MSG_ERROR, "block rcurly", 16, 12),
2881 "39:17: " + getCheckMessage(MSG_ERROR, "(", 16, 12),
2882 "40:17: " + getCheckMessage(MSG_ERROR, "->", 16, 12),
2883 "41:21: " + getCheckMessage(MSG_ERROR, "if", 20, 16),
2884 "44:1: " + getCheckMessage(MSG_ERROR, "block rcurly", 0, 12),
2885 };
2886
2887 verifyWarns(checkConfig, getPath("InputIndentationLambda7.java"), expected);
2888 }
2889
2890 @Test
2891 public void testLambdaOddConditions() throws Exception {
2892 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2893 checkConfig.addProperty("tabWidth", "4");
2894 checkConfig.addProperty("basicOffset", "3");
2895 checkConfig.addProperty("braceAdjustment", "0");
2896 checkConfig.addProperty("forceStrictCondition", "false");
2897 checkConfig.addProperty("lineWrappingIndentation", "7");
2898 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2899
2900 verifyWarns(checkConfig, getPath("InputIndentationLambda8.java"), expected);
2901 }
2902
2903 @Test
2904 public void testSeparatedStatements() throws Exception {
2905 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2906 checkConfig.addProperty("tabWidth", "4");
2907 final String fileName = getPath("InputIndentationSeparatedStatements.java");
2908 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2909 verifyWarns(checkConfig, fileName, expected);
2910 }
2911
2912 @Test
2913 public void testSeparatedLineWithJustSpaces() throws Exception {
2914 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2915 checkConfig.addProperty("tabWidth", "4");
2916 final String fileName = getPath("InputIndentationSeparatedStatementWithSpaces.java");
2917 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2918 verify(checkConfig, fileName, expected);
2919 }
2920
2921 @Test
2922 public void testTwoStatementsPerLine() throws Exception {
2923 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2924 checkConfig.addProperty("tabWidth", "4");
2925 checkConfig.addProperty("basicOffset", "4");
2926 final String fileName = getPath("InputIndentationTwoStatementsPerLine.java");
2927 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2928 verifyWarns(checkConfig, fileName, expected);
2929 }
2930
2931 @Test
2932 public void testMethodChaining() throws Exception {
2933 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2934 checkConfig.addProperty("tabWidth", "4");
2935 checkConfig.addProperty("basicOffset", "4");
2936 final String fileName = getPath("InputIndentationChainedMethods.java");
2937 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2938 verifyWarns(checkConfig, fileName, expected);
2939 }
2940
2941 @Test
2942 public void testMultipleAnnotationsWithWrappedLines() throws Exception {
2943 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2944 checkConfig.addProperty("tabWidth", "4");
2945 checkConfig.addProperty("basicOffset", "4");
2946 checkConfig.addProperty("forceStrictCondition", "true");
2947 final String fileName =
2948 getPath("InputIndentationCorrectMultipleAnnotationsWithWrappedLines.java");
2949 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2950 verifyWarns(checkConfig, fileName, expected);
2951 }
2952
2953 @Test
2954 public void testMultipleAnnotationsWithWrappedLines1() throws Exception {
2955 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2956 checkConfig.addProperty("tabWidth", "4");
2957 checkConfig.addProperty("basicOffset", "4");
2958 checkConfig.addProperty("forceStrictCondition", "true");
2959 final String fileName =
2960 getPath("InputIndentationCorrectMultipleAnnotationsWithWrappedLines1.java");
2961 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2962 verifyWarns(checkConfig, fileName, expected);
2963 }
2964
2965 @Test
2966 public void testMethodPrecedeByAnnotationsWithParameterOnSeparateLine() throws Exception {
2967 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2968 checkConfig.addProperty("tabWidth", "4");
2969 checkConfig.addProperty("basicOffset", "2");
2970 checkConfig.addProperty("braceAdjustment", "0");
2971 checkConfig.addProperty("caseIndent", "2");
2972 checkConfig.addProperty("throwsIndent", "4");
2973 checkConfig.addProperty("lineWrappingIndentation", "4");
2974 checkConfig.addProperty("arrayInitIndent", "2");
2975 final String fileName =
2976 getPath("InputIndentationMethodPrecededByAnnotationWithParameterOnSeparateLine.java");
2977 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
2978 verify(checkConfig, fileName, expected);
2979 }
2980
2981 @Test
2982 public void testAnnotationIncorrect() throws Exception {
2983 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2984 checkConfig.addProperty("tabWidth", "4");
2985 checkConfig.addProperty("basicOffset", "4");
2986 checkConfig.addProperty("braceAdjustment", "0");
2987 checkConfig.addProperty("lineWrappingIndentation", "4");
2988 final String fileName =
2989 getPath("InputIndentationAnnotationIncorrect.java");
2990 final String[] expected = {
2991 "11:5: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
2992 "14:9: " + getCheckMessage(MSG_ERROR, "(", 8, 12),
2993 "19:5: " + getCheckMessage(MSG_ERROR, "(", 4, 8),
2994 };
2995 verify(checkConfig, fileName, expected);
2996 }
2997
2998 @Test
2999 public void testInputAnnotationScopeIndentationCheck() throws Exception {
3000 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3001 checkConfig.addProperty("tabWidth", "4");
3002 checkConfig.addProperty("basicOffset", "4");
3003 checkConfig.addProperty("forceStrictCondition", "true");
3004 final String fileName = getPath("InputIndentationAnnotationScopeIndentationCheck.java");
3005 final String[] expected = {
3006 "9:9: " + getCheckMessage(MSG_ERROR_MULTI,
3007 "annotation array initialization rcurly", 8, "0, 4"),
3008 };
3009 verifyWarns(checkConfig, fileName, expected);
3010 }
3011
3012 @Test
3013 public void testInputAnnotationDefIndentationCheck() throws Exception {
3014 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3015 checkConfig.addProperty("tabWidth", "4");
3016 checkConfig.addProperty("arrayInitIndent", "4");
3017 checkConfig.addProperty("basicOffset", "4");
3018 checkConfig.addProperty("braceAdjustment", "0");
3019 checkConfig.addProperty("lineWrappingIndentation", "4");
3020 checkConfig.addProperty("forceStrictCondition", "true");
3021 final String fileName = getPath("InputIndentationCustomAnnotation.java");
3022 final String[] expected = {
3023 "14:6: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 5, 0),
3024 "15:6: " + getCheckMessage(MSG_ERROR, "annotation def rcurly", 5, 0),
3025 "16:6: " + getCheckMessage(MSG_ERROR, "@", 5, 0),
3026 "17:1: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 0, 4),
3027 "18:6: " + getCheckMessage(MSG_ERROR, "annotation def rcurly", 5, 0),
3028 "20:4: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 3, 0),
3029 "22:1: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 0, 4),
3030 "23:6: " + getCheckMessage(MSG_ERROR, "annotation def rcurly", 5, 0),
3031 "25:6: " + getCheckMessage(MSG_ERROR, "@", 5, 0),
3032 "26:6: " + getCheckMessage(MSG_ERROR, "AnnotationWithLineWrap", 5, 0),
3033 "30:6: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 5, 0),
3034 "31:4: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 3, 0),
3035 "34:6: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 5, 4),
3036 "35:4: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 3, 4),
3037 "36:1: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 0, 4),
3038 "37:1: " + getCheckMessage(MSG_ERROR, "@", 0, 4),
3039 "38:9: " + getCheckMessage(MSG_ERROR, "AnnotationInnerLineWrap", 8, 4),
3040 "41:8: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 7, 8),
3041 "58:5: " + getCheckMessage(MSG_ERROR, "AnnotationInnerLineWrap2", 4, 0),
3042 "59:4: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 3, 4),
3043 "60:8: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 7, 4),
3044 "61:5: " + getCheckMessage(MSG_ERROR, "annotation def rcurly", 4, 0),
3045 "72:4: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 3, 4),
3046 "87:29: " + getCheckMessage(MSG_ERROR_MULTI, "new", 28, "20, 24"),
3047 };
3048 verifyWarns(checkConfig, fileName, expected);
3049 }
3050
3051 @Test
3052 public void testInputAnnotationDefIndentationCheck1() throws Exception {
3053 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3054 checkConfig.addProperty("tabWidth", "4");
3055 checkConfig.addProperty("arrayInitIndent", "4");
3056 checkConfig.addProperty("basicOffset", "4");
3057 checkConfig.addProperty("braceAdjustment", "0");
3058 checkConfig.addProperty("lineWrappingIndentation", "4");
3059 checkConfig.addProperty("forceStrictCondition", "true");
3060 final String fileName = getPath("InputIndentationCustomAnnotation1.java");
3061 final String[] expected = {
3062 "36:6: " + getCheckMessage(MSG_ERROR, "annotation def modifier", 5, 4),
3063 "47:2: " + getCheckMessage(MSG_ERROR, "interface", 1, 0),
3064 "53:12: " + getCheckMessage(MSG_ERROR, "@", 11, 0),
3065 "56:17: " + getCheckMessage(MSG_ERROR, "@", 16, 0),
3066 "63:13: " + getCheckMessage(MSG_ERROR, "@", 12, 4),
3067 "67:23: " + getCheckMessage(MSG_ERROR, "class def ident", 16, 0),
3068 };
3069 verifyWarns(checkConfig, fileName, expected);
3070 }
3071
3072 @Test
3073 public void testTryResourcesStrict() throws Exception {
3074 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3075 checkConfig.addProperty("tabWidth", "4");
3076 checkConfig.addProperty("forceStrictCondition", "true");
3077 checkConfig.addProperty("braceAdjustment", "0");
3078 checkConfig.addProperty("lineWrappingIndentation", "4");
3079 final String fileName = getPath("InputIndentationTryWithResourcesStrict.java");
3080 final String[] expected = {
3081 "26:1: " + getCheckMessage(MSG_ERROR, "try resource", 0, 12),
3082 "28:14: " + getCheckMessage(MSG_ERROR_MULTI, "try rparen", 13, "8, 12"),
3083 "33:1: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 0, 16),
3084 "39:1: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 0, 12),
3085 "59:21: " + getCheckMessage(MSG_ERROR, "try resource", 20, 16),
3086 "79:14: " + getCheckMessage(MSG_ERROR, ".", 13, 12),
3087 "85:12: " + getCheckMessage(MSG_ERROR, ".", 11, 12),
3088 };
3089 verifyWarns(checkConfig, fileName, expected);
3090 }
3091
3092 @Test
3093 public void testTryResourcesStrict1() throws Exception {
3094 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3095 checkConfig.addProperty("tabWidth", "4");
3096 checkConfig.addProperty("forceStrictCondition", "true");
3097 checkConfig.addProperty("braceAdjustment", "0");
3098 checkConfig.addProperty("lineWrappingIndentation", "4");
3099 final String fileName = getPath("InputIndentationTryWithResourcesStrict1.java");
3100 final String[] expected = {
3101 "31:20: " + getCheckMessage(MSG_ERROR, "writ", 19, 12),
3102 "38:20: " + getCheckMessage(MSG_ERROR, "writ", 19, 16),
3103 "45:22: " + getCheckMessage(MSG_ERROR, "writ", 21, 16),
3104 "60:18: " + getCheckMessage(MSG_ERROR, "zipFileName", 17, 16),
3105 "67:16: " + getCheckMessage(MSG_ERROR, "zipFileName", 15, 16),
3106 "77:8: " + getCheckMessage(MSG_ERROR, "try", 7, 8),
3107 "82:16: " + getCheckMessage(MSG_CHILD_ERROR, "try", 15, 12),
3108 "88:12: " + getCheckMessage(MSG_ERROR, "try resource", 11, 12),
3109 "89:10: " + getCheckMessage(MSG_CHILD_ERROR, "try", 9, 12),
3110 "93:12: " + getCheckMessage(MSG_ERROR, "try resource", 11, 12),
3111 "94:12: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 11, 16),
3112 "95:14: " + getCheckMessage(MSG_CHILD_ERROR, "try", 13, 12),
3113 "97:8: " + getCheckMessage(MSG_ERROR, "try", 7, 8),
3114 "98:8: " + getCheckMessage(MSG_ERROR_MULTI, "try rparen", 7, "8, 12"),
3115 "102:10: " + getCheckMessage(MSG_ERROR, "try", 9, 8),
3116 };
3117 verifyWarns(checkConfig, fileName, expected);
3118 }
3119
3120 @Test
3121 public void testTryResourcesNotStrict() throws Exception {
3122 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3123 checkConfig.addProperty("tabWidth", "4");
3124 checkConfig.addProperty("braceAdjustment", "0");
3125 checkConfig.addProperty("lineWrappingIndentation", "4");
3126 final String fileName = getPath("InputIndentationTryResourcesNotStrict.java");
3127 final String[] expected = {
3128 "26:1: " + getCheckMessage(MSG_ERROR, "try resource", 0, 12),
3129 "32:1: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 0, 16),
3130 "38:1: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 0, 12),
3131 };
3132 verifyWarns(checkConfig, fileName, expected);
3133 }
3134
3135 @Test
3136 public void testTryResourcesNotStrict1() throws Exception {
3137 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3138 checkConfig.addProperty("tabWidth", "4");
3139 checkConfig.addProperty("braceAdjustment", "0");
3140 checkConfig.addProperty("lineWrappingIndentation", "4");
3141 final String fileName = getPath("InputIndentationTryResourcesNotStrict1.java");
3142 final String[] expected = {
3143 "44:16: " + getCheckMessage(MSG_ERROR, "zipFileName", 15, 16),
3144 "54:8: " + getCheckMessage(MSG_ERROR, "try", 7, 8),
3145 "59:16: " + getCheckMessage(MSG_CHILD_ERROR, "try", 15, 12),
3146 "65:12: " + getCheckMessage(MSG_ERROR, "try resource", 11, 12),
3147 "66:10: " + getCheckMessage(MSG_CHILD_ERROR, "try", 9, 12),
3148 "70:12: " + getCheckMessage(MSG_ERROR, "try resource", 11, 12),
3149 "71:12: " + getCheckMessage(MSG_ERROR, "newBufferedWriter", 11, 16),
3150 "72:14: " + getCheckMessage(MSG_CHILD_ERROR, "try", 13, 12),
3151 "74:8: " + getCheckMessage(MSG_ERROR, "try", 7, 8),
3152 "75:8: " + getCheckMessage(MSG_ERROR_MULTI, "try rparen", 7, "8, 12"),
3153 "88:9: " + getCheckMessage(MSG_ERROR, ".", 8, 12),
3154 "96:12: " + getCheckMessage(MSG_ERROR, "new", 11, 12),
3155 };
3156 verifyWarns(checkConfig, fileName, expected);
3157 }
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171 @Test
3172 public void testArgumentOrderOfErrorMessages() {
3173 final Object[] arguments = {"##0##", "##1##", "##2##"};
3174 final String[] messages = {
3175 getCheckMessage(MSG_ERROR, arguments),
3176 getCheckMessage(MSG_CHILD_ERROR, arguments),
3177 getCheckMessage(MSG_ERROR_MULTI, arguments),
3178 getCheckMessage(MSG_CHILD_ERROR_MULTI, arguments),
3179 };
3180 final boolean isInOrder = Arrays.stream(messages).allMatch(msg -> {
3181 final int indexOfArgumentZero = msg.indexOf((String) arguments[0]);
3182 return Arrays.stream(arguments)
3183 .map(String.class::cast)
3184 .mapToInt(msg::indexOf)
3185 .allMatch(index -> index >= indexOfArgumentZero);
3186 });
3187 assertWithMessage(
3188 "the argument 0 of error messages (indentation.error, indentation.child.error,"
3189 + " indentation.error.multi, indentation.child.error.multi)"
3190 + " is required to be the first argument of them")
3191 .that(isInOrder)
3192 .isTrue();
3193 }
3194
3195 @Test
3196 public void testEmptyArray() throws Exception {
3197 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3198 checkConfig.addProperty("tabWidth", "4");
3199 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3200 verifyWarns(checkConfig, getPath("InputIndentationEmptyArray.java"), expected);
3201 }
3202
3203 @Test
3204 public void testNewHandler() throws Exception {
3205 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3206 checkConfig.addProperty("tabWidth", "4");
3207 final String[] expected = {
3208 "10:1: " + getCheckMessage(MSG_ERROR, "Object", 0, 12),
3209 "12:1: " + getCheckMessage(MSG_ERROR, "(", 0, 12),
3210 "15:1: " + getCheckMessage(MSG_CHILD_ERROR, "new", 0, 8),
3211 "17:1: " + getCheckMessage(MSG_ERROR, "new lparen", 0, 8),
3212 "25:1: " + getCheckMessage(MSG_ERROR, "=", 0, 8),
3213 };
3214 verifyWarns(checkConfig, getPath("InputIndentationNewHandler.java"), expected);
3215 }
3216
3217 @Test
3218 public void testTryHandler() throws Exception {
3219 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3220 checkConfig.addProperty("tabWidth", "4");
3221 checkConfig.addProperty("braceAdjustment", "0");
3222 checkConfig.addProperty("lineWrappingIndentation", "8");
3223 checkConfig.addProperty("forceStrictCondition", "true");
3224 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3225 verifyWarns(checkConfig, getPath("InputIndentationTryBlockWithResources.java"), expected);
3226 }
3227
3228 @Test
3229 public void testTryHandler2() throws Exception {
3230 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3231 checkConfig.addProperty("tabWidth", "4");
3232 checkConfig.addProperty("braceAdjustment", "0");
3233 checkConfig.addProperty("lineWrappingIndentation", "8");
3234 checkConfig.addProperty("forceStrictCondition", "true");
3235 final String[] expected = {
3236 "25:17: " + getCheckMessage(MSG_ERROR, "new", 16, 20),
3237 "27:13: " + getCheckMessage(MSG_ERROR, "new", 12, 20),
3238 };
3239 verifyWarns(checkConfig, getPath("InputIndentationTryBlock.java"), expected);
3240 }
3241
3242 @Test
3243 public void testChainedMethodWithBracketOnNewLine() throws Exception {
3244 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3245
3246 checkConfig.addProperty("arrayInitIndent", "2");
3247 checkConfig.addProperty("basicOffset", "2");
3248 checkConfig.addProperty("braceAdjustment", "0");
3249 checkConfig.addProperty("caseIndent", "2");
3250 checkConfig.addProperty("forceStrictCondition", "false");
3251 checkConfig.addProperty("lineWrappingIndentation", "4");
3252 checkConfig.addProperty("tabWidth", "2");
3253 checkConfig.addProperty("throwsIndent", "2");
3254 final String[] expected = {
3255 "44:7: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 6, 8),
3256 "45:9: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 8, 10),
3257 "47:7: " + getCheckMessage(MSG_ERROR, "method call rparen", 6, 8),
3258 "61:6: " + getCheckMessage(MSG_ERROR, "foo", 5, 8),
3259 "82:5: " + getCheckMessage(MSG_ERROR, "if rcurly", 4, 6),
3260 "84:3: " + getCheckMessage(MSG_CHILD_ERROR, "method def", 2, 4),
3261 };
3262 final String fileName = "InputIndentationChainedMethodWithBracketOnNewLine.java";
3263 verifyWarns(checkConfig, getPath(fileName), expected);
3264 }
3265
3266 @Test
3267 public void testIndentationSwitchExpression() throws Exception {
3268 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3269 checkConfig.addProperty("tabWidth", "4");
3270 final String[] expected = {
3271 "17:1: " + getCheckMessage(MSG_CHILD_ERROR, "case", 0, 12),
3272 "18:9: " + getCheckMessage(MSG_CHILD_ERROR, "block", 8, 16),
3273 "21:25: " + getCheckMessage(MSG_CHILD_ERROR, "case", 24, 12),
3274 "22:9: " + getCheckMessage(MSG_CHILD_ERROR, "block", 8, 16),
3275 "27:9: " + getCheckMessage(MSG_CHILD_ERROR, "block", 8, 20),
3276 "29:1: " + getCheckMessage(MSG_CHILD_ERROR, "block", 0, 16),
3277 "30:1: " + getCheckMessage(MSG_ERROR, "yield", 0, 16),
3278 "34:5: " + getCheckMessage(MSG_CHILD_ERROR, "block", 4, 20),
3279 "44:1: " + getCheckMessage(MSG_CHILD_ERROR, "block", 0, 16),
3280 "46:21: " + getCheckMessage(MSG_CHILD_ERROR, "case", 20, 12),
3281 "47:1: " + getCheckMessage(MSG_CHILD_ERROR, "block", 0, 16),
3282 "51:9: " + getCheckMessage(MSG_CHILD_ERROR, "block", 8, 20),
3283 "56:33: " + getCheckMessage(MSG_CHILD_ERROR, "block", 32, 20),
3284 };
3285
3286 verifyWarns(checkConfig,
3287 getNonCompilablePath("InputIndentationCheckSwitchExpression.java"),
3288 expected);
3289 }
3290
3291 @Test
3292 public void testIndentationYieldStatement() throws Exception {
3293 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3294 checkConfig.addProperty("tabWidth", "4");
3295 final String[] expected = {
3296 "23:13: " + getCheckMessage(MSG_ERROR, "yield", 12, 16),
3297 "28:9: " + getCheckMessage(MSG_CHILD_ERROR, "yield", 8, 16),
3298 "40:5: " + getCheckMessage(MSG_ERROR, "yield", 4, 16),
3299 "41:9: " + getCheckMessage(MSG_CHILD_ERROR, "yield", 8, 16),
3300 "71:1: " + getCheckMessage(MSG_ERROR, "yield", 0, 16),
3301 "74:37: " + getCheckMessage(MSG_ERROR, "yield", 36, 16),
3302 };
3303
3304 verifyWarns(checkConfig,
3305 getNonCompilablePath("InputIndentationYieldStatement.java"),
3306 expected);
3307 }
3308
3309 @Test
3310 public void testIndentationSwitchExpressionCorrect() throws Exception {
3311 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3312 checkConfig.addProperty("tabWidth", "4");
3313 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3314 verifyWarns(checkConfig,
3315 getNonCompilablePath("InputIndentationCheckSwitchExpressionCorrect.java"),
3316 expected);
3317 }
3318
3319 @Test
3320 public void testIndentationSwitchExpressionDeclaration() throws Exception {
3321 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3322 checkConfig.addProperty("tabWidth", "4");
3323 checkConfig.addProperty("caseIndent", "4");
3324 checkConfig.addProperty("lineWrappingIndentation", "8");
3325 final String[] expected = {
3326 "33:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
3327 "34:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
3328 "41:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
3329 "42:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
3330 "49:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
3331 "50:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
3332 "57:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
3333 "58:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
3334 };
3335 verifyWarns(checkConfig,
3336 getNonCompilablePath("InputIndentationCheckSwitchExpressionDeclaration.java"),
3337 expected);
3338 }
3339
3340 @Test
3341 public void testIndentationSwitchExpressionDeclarationLeftCurlyNewLine() throws Exception {
3342 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3343 checkConfig.addProperty("tabWidth", "4");
3344 final String[] expected = {
3345 "34:5: " + getCheckMessage(MSG_ERROR, "switch lcurly", 4, 8),
3346 "42:5: " + getCheckMessage(MSG_ERROR, "switch lcurly", 4, 8),
3347 "50:13: " + getCheckMessage(MSG_ERROR, "switch lcurly", 12, 8),
3348 "58:13: " + getCheckMessage(MSG_ERROR, "switch lcurly", 12, 8),
3349 };
3350 verifyWarns(checkConfig,
3351 getNonCompilablePath(
3352 "InputIndentationCheckSwitchExpressionDeclarationLCurlyNewLine.java"),
3353 expected);
3354 }
3355
3356 @Test
3357 public void testIndentationRecords() throws Exception {
3358 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3359 checkConfig.addProperty("tabWidth", "4");
3360 checkConfig.addProperty("basicOffset", "4");
3361 checkConfig.addProperty("braceAdjustment", "0");
3362 checkConfig.addProperty("caseIndent", "4");
3363 checkConfig.addProperty("throwsIndent", "4");
3364 checkConfig.addProperty("arrayInitIndent", "4");
3365 checkConfig.addProperty("lineWrappingIndentation", "4");
3366 checkConfig.addProperty("forceStrictCondition", "false");
3367
3368 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3369
3370 verifyWarns(checkConfig,
3371 getNonCompilablePath("InputIndentationRecords.java"),
3372 expected);
3373 }
3374
3375 @Test
3376 public void testIndentationRecordsAndCompactCtors() throws Exception {
3377 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3378 checkConfig.addProperty("tabWidth", "4");
3379 final String[] expected = {
3380 "13:1: " + getCheckMessage(MSG_ERROR, "(", 0, 8),
3381 "25:1: " + getCheckMessage(MSG_ERROR, "String", 0, 12),
3382 "38:1: " + getCheckMessage(MSG_CHILD_ERROR, "compact ctor def", 0, 12),
3383 "48:8: " + getCheckMessage(MSG_ERROR, "record def ident", 0, 4),
3384 "53:1: " + getCheckMessage(MSG_ERROR, "compact ctor def rcurly", 0, 8),
3385 "61:1: " + getCheckMessage(MSG_ERROR, "ctor def rcurly", 0, 8),
3386 };
3387
3388 verifyWarns(checkConfig,
3389 getNonCompilablePath("InputIndentationRecordsAndCompactCtors.java"),
3390 expected);
3391 }
3392
3393 @Test
3394 public void testIndentationSwitchExpressionNewLine() throws Exception {
3395 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3396 checkConfig.addProperty("tabWidth", "4");
3397 final String[] expected = {
3398 "30:13: " + getCheckMessage(MSG_ERROR, "lambda", 12, 16),
3399 "32:13: " + getCheckMessage(MSG_ERROR, "lambda", 12, 16),
3400 };
3401
3402 verifyWarns(checkConfig,
3403 getNonCompilablePath("InputIndentationCheckSwitchExpressionNewLine.java"),
3404 expected);
3405 }
3406
3407 @Test
3408 public void testIndentationMethodParenthesisOnNewLine() throws Exception {
3409 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3410 checkConfig.addProperty("tabWidth", "4");
3411 final String[] expected = {
3412 "13:9: " + getCheckMessage(MSG_ERROR, "method def rparen", 8, 4),
3413 "18:9: " + getCheckMessage(MSG_ERROR, "method def rparen", 8, 4),
3414 };
3415
3416 verifyWarns(checkConfig,
3417 getPath("InputIndentationCheckMethodParenOnNewLine.java"),
3418 expected);
3419 }
3420
3421 @Test
3422 public void testIndentationMethodParenthesisOnNewLine1() throws Exception {
3423 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3424 checkConfig.addProperty("tabWidth", "4");
3425 final String[] expected = {
3426 "11:10: " + getCheckMessage(MSG_ERROR, "2", 9, 12),
3427 "17:8: " + getCheckMessage(MSG_ERROR, "int", 7, 8),
3428 "18:9: " + getCheckMessage(MSG_ERROR, "method def rparen", 8, 4),
3429 };
3430
3431 verifyWarns(checkConfig,
3432 getPath("InputIndentationCheckMethodParenOnNewLine1.java"),
3433 expected);
3434 }
3435
3436 @Test
3437 public void testIndentationLineWrappedRecordDeclaration() throws Exception {
3438 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3439 checkConfig.addProperty("tabWidth", "4");
3440 checkConfig.addProperty("basicOffset", "4");
3441 checkConfig.addProperty("braceAdjustment", "0");
3442 checkConfig.addProperty("caseIndent", "4");
3443 checkConfig.addProperty("throwsIndent", "4");
3444 checkConfig.addProperty("arrayInitIndent", "4");
3445 checkConfig.addProperty("lineWrappingIndentation", "4");
3446
3447 final String[] expected = {
3448 "33:1: " + getCheckMessage(MSG_ERROR, ")", 0, 4),
3449 "55:11: " + getCheckMessage(MSG_ERROR, "interface def ident", 0, 4),
3450 "56:1: " + getCheckMessage(MSG_ERROR, "method def modifier", 0, 8),
3451 "57:1: " + getCheckMessage(MSG_ERROR, "void", 0, 4),
3452 "58:1: " + getCheckMessage(MSG_ERROR, "method", 0, 4),
3453 "59:1: " + getCheckMessage(MSG_ERROR, "throws", 0, 4),
3454 "60:1: " + getCheckMessage(MSG_ERROR, "IOException", 0, 4),
3455 "61:1: " + getCheckMessage(MSG_ERROR, "method def rcurly", 0, 8),
3456 "62:1: " + getCheckMessage(MSG_ERROR, "interface def rcurly", 0, 4),
3457 "75:8: " + getCheckMessage(MSG_ERROR, "record def ident", 0, 4),
3458 "76:1: " + getCheckMessage(MSG_ERROR, "record def rparen", 0, 4),
3459 "77:1: " + getCheckMessage(MSG_ERROR, "implements", 0, 4),
3460 "78:1: " + getCheckMessage(MSG_ERROR, "SimpleInterface2", 0, 4),
3461 "79:8: " + getCheckMessage(MSG_ERROR, "record def ident", 0, 8),
3462 "80:1: " + getCheckMessage(MSG_ERROR, "(", 0, 4),
3463 "81:1: " + getCheckMessage(MSG_ERROR, "record def rparen", 0, 8),
3464 "82:1: " + getCheckMessage(MSG_ERROR, "record def lcurly", 0, 8),
3465 "83:1: " + getCheckMessage(MSG_ERROR, "record def rcurly", 0, 8),
3466 "84:1: " + getCheckMessage(MSG_ERROR, "record def rcurly", 0, 4),
3467 };
3468
3469 verifyWarns(checkConfig,
3470 getNonCompilablePath("InputIndentationLineWrappedRecordDeclaration.java"),
3471 expected);
3472 }
3473
3474 @Test
3475 public void testIndentationAnnotationFieldDefinition() throws Exception {
3476 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3477 checkConfig.addProperty("tabWidth", "4");
3478 checkConfig.addProperty("basicOffset", "4");
3479 checkConfig.addProperty("braceAdjustment", "0");
3480 checkConfig.addProperty("caseIndent", "4");
3481 checkConfig.addProperty("throwsIndent", "8");
3482 checkConfig.addProperty("forceStrictCondition", "true");
3483
3484 final String[] expected = {
3485 "17:5: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 4, 8),
3486 "18:13: " + getCheckMessage(MSG_ERROR, "annotation field def modifier", 12, 8),
3487 "25:5: " + getCheckMessage(MSG_ERROR, "member def type", 4, 8),
3488 "26:5: " + getCheckMessage(MSG_ERROR, "member def type", 4, 8),
3489 };
3490
3491 verifyWarns(checkConfig, getPath("InputIndentationAnnotationFieldDefinition.java"),
3492 expected);
3493 }
3494
3495 @Test
3496 public void testIndentationLongConcatenatedString() throws Exception {
3497 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3498 checkConfig.addProperty("tabWidth", "4");
3499
3500 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3501
3502 verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString.java"),
3503 expected);
3504 }
3505
3506 @Test
3507 public void testIndentationLongConcatenatedString1() throws Exception {
3508 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3509 checkConfig.addProperty("tabWidth", "4");
3510
3511 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3512
3513 verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString1.java"),
3514 expected);
3515 }
3516
3517 @Test
3518 public void testIndentationLongConcatenatedString2() throws Exception {
3519 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3520 checkConfig.addProperty("tabWidth", "4");
3521
3522 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3523
3524 verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString2.java"),
3525 expected);
3526 }
3527
3528 @Test
3529 public void testIndentationLongConcatenatedString3() throws Exception {
3530 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3531 checkConfig.addProperty("tabWidth", "4");
3532
3533 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3534
3535 verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString3.java"),
3536 expected);
3537 }
3538
3539 @Test
3540 public void testIndentationLongConcatenatedString4() throws Exception {
3541 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3542 checkConfig.addProperty("tabWidth", "4");
3543
3544 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3545
3546 verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString4.java"),
3547 expected);
3548 }
3549
3550 @Test
3551 public void testIndentationLongConcatenatedString5() throws Exception {
3552 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3553 checkConfig.addProperty("tabWidth", "4");
3554
3555 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3556
3557 verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString5.java"),
3558 expected);
3559 }
3560
3561 @Test
3562 public void testIndentationLongConcatenatedString6() throws Exception {
3563 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3564 checkConfig.addProperty("tabWidth", "4");
3565
3566 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3567
3568 verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString6.java"),
3569 expected);
3570 }
3571
3572 @Test
3573 public void testIndentationLongConcatenatedString7() throws Exception {
3574 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3575 checkConfig.addProperty("tabWidth", "4");
3576
3577 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3578
3579 verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString7.java"),
3580 expected);
3581 }
3582
3583 @Test
3584 public void testIndentationLongConcatenatedString8() throws Exception {
3585 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3586 checkConfig.addProperty("tabWidth", "4");
3587
3588 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3589
3590 verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString8.java"),
3591 expected);
3592 }
3593
3594 @Test
3595 public void testIndentationLongConcatenatedString9() throws Exception {
3596 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3597 checkConfig.addProperty("tabWidth", "4");
3598
3599 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3600
3601 verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString9.java"),
3602 expected);
3603 }
3604
3605 @Test
3606 public void testIndentationLongConcatenatedString10() throws Exception {
3607 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3608 checkConfig.addProperty("tabWidth", "4");
3609
3610 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3611
3612 verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString10.java"),
3613 expected);
3614 }
3615
3616 @Test
3617 public void testIndentationLongConcatenatedString11() throws Exception {
3618 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3619 checkConfig.addProperty("tabWidth", "4");
3620
3621 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3622
3623 verifyWarns(checkConfig, getPath("InputIndentationLongConcatenatedString11.java"),
3624 expected);
3625 }
3626
3627 @Test
3628 public void testIndentationLineBreakVariableDeclaration()
3629 throws Exception {
3630 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3631 checkConfig.addProperty("tabWidth", "4");
3632
3633 final String fileName = getPath("InputIndentationLineBreakVariableDeclaration.java");
3634 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
3635 verifyWarns(checkConfig, fileName, expected);
3636 }
3637
3638 @Test
3639 public void testIndentationSwitchExpressionOnStartOfTheLine() throws Exception {
3640 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3641 checkConfig.addProperty("tabWidth", "4");
3642 checkConfig.addProperty("basicOffset", "2");
3643 checkConfig.addProperty("braceAdjustment", "2");
3644 checkConfig.addProperty("caseIndent", "2");
3645 checkConfig.addProperty("throwsIndent", "4");
3646 checkConfig.addProperty("lineWrappingIndentation", "4");
3647
3648 final String[] expected = {
3649 "40:7: " + getCheckMessage(MSG_ERROR, "switch", 6, 8),
3650 "41:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 10),
3651 "42:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 10),
3652 "43:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 10),
3653 "44:7: " + getCheckMessage(MSG_ERROR, "switch rcurly", 6, 8),
3654 "49:11: " + getCheckMessage(MSG_ERROR, "switch", 10, 8),
3655 "50:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 10),
3656 "51:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 10),
3657 "52:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 10),
3658 };
3659
3660 verifyWarns(checkConfig,
3661 getNonCompilablePath("InputIndentationSwitchOnStartOfLine.java"), expected);
3662 }
3663
3664 @Test
3665 public void testIndentationPatternMatchingForSwitch()
3666 throws Exception {
3667 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3668 checkConfig.addProperty("forceStrictCondition", "true");
3669 checkConfig.addProperty("tabWidth", "4");
3670 checkConfig.addProperty("basicOffset", "4");
3671 checkConfig.addProperty("braceAdjustment", "0");
3672 checkConfig.addProperty("caseIndent", "4");
3673 checkConfig.addProperty("throwsIndent", "8");
3674
3675 final String fileName = getNonCompilablePath(
3676 "InputIndentationPatternMatchingForSwitch.java");
3677 final String[] expected = {
3678 "21:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 16),
3679 "54:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 16),
3680 "69:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 16),
3681 "70:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 16),
3682 "75:5: " + getCheckMessage(MSG_CHILD_ERROR, "case", 4, 16),
3683 "76:5: " + getCheckMessage(MSG_CHILD_ERROR, "case", 4, 16),
3684 "87:1: " + getCheckMessage(MSG_CHILD_ERROR, "case", 0, 16),
3685 "88:1: " + getCheckMessage(MSG_CHILD_ERROR, "case", 0, 16),
3686 "89:1: " + getCheckMessage(MSG_CHILD_ERROR, "case", 0, 16),
3687 "90:1: " + getCheckMessage(MSG_ERROR, "lambda", 0, 16),
3688 };
3689 verifyWarns(checkConfig, fileName, expected);
3690 }
3691
3692 @Test
3693 public void testIndentationRecordPattern()
3694 throws Exception {
3695 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3696 checkConfig.addProperty("forceStrictCondition", "true");
3697 checkConfig.addProperty("tabWidth", "4");
3698 checkConfig.addProperty("basicOffset", "4");
3699 checkConfig.addProperty("braceAdjustment", "0");
3700 checkConfig.addProperty("caseIndent", "4");
3701 checkConfig.addProperty("throwsIndent", "8");
3702
3703 final String fileName = getNonCompilablePath(
3704 "InputIndentationRecordPattern.java");
3705 final String[] expected = {
3706 "19:17: " + getCheckMessage(MSG_ERROR, "ColoredPoint", 16, 12),
3707 "24:9: " + getCheckMessage(MSG_ERROR, "ColoredPoint", 8, 12),
3708 "29:17: " + getCheckMessage(MSG_ERROR, "ColoredPoint", 16, 12),
3709 "34:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 12),
3710 "37:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3711 "39:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3712 "40:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3713 "41:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3714 "42:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3715 "56:17: " + getCheckMessage(MSG_ERROR, "Rectangle", 16, 12),
3716 "57:17: " + getCheckMessage(MSG_ERROR, "ColoredPoint", 16, 12),
3717 "58:25: " + getCheckMessage(MSG_ERROR, "boolean", 24, 12),
3718 "59:17: " + getCheckMessage(MSG_ERROR, "int", 16, 12),
3719 "60:25: " + getCheckMessage(MSG_ERROR, "_", 24, 12),
3720 "61:17: " + getCheckMessage(MSG_ERROR, "ColoredPoint", 16, 12),
3721 "62:17: " + getCheckMessage(MSG_ERROR, ")", 16, 8),
3722 "67:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3723 "66:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3724 "68:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 12),
3725 "69:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 12),
3726 "70:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 12),
3727 "71:1: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
3728 "72:9: " + getCheckMessage(MSG_CHILD_ERROR, "if", 8, 12),
3729 "81:13: " + getCheckMessage(MSG_ERROR, ")", 12, 8),
3730 "89:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 16),
3731 "90:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 16),
3732 };
3733 verifyWarns(checkConfig, fileName, expected);
3734 }
3735
3736 @Test
3737 public void testIndentationCodeBlocks1() throws Exception {
3738 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3739 checkConfig.addProperty("tabWidth", "4");
3740 checkConfig.addProperty("basicOffset", "2");
3741 checkConfig.addProperty("braceAdjustment", "2");
3742 checkConfig.addProperty("caseIndent", "2");
3743 checkConfig.addProperty("throwsIndent", "4");
3744 checkConfig.addProperty("lineWrappingIndentation", "4");
3745 final String[] expected = {
3746 "17:5: " + getCheckMessage(MSG_ERROR, "block lcurly", 4, 2),
3747 "18:7: " + getCheckMessage(MSG_CHILD_ERROR, "block", 6, 4),
3748 "19:5: " + getCheckMessage(MSG_ERROR, "block rcurly", 4, 2),
3749 "30:5: " + getCheckMessage(MSG_ERROR, "block lcurly", 4, 2),
3750 "31:7: " + getCheckMessage(MSG_CHILD_ERROR, "block", 6, 4),
3751 "32:5: " + getCheckMessage(MSG_ERROR, "block rcurly", 4, 2),
3752 };
3753 verifyWarns(checkConfig, getPath("InputIndentationCodeBlocks1.java"), expected);
3754 }
3755
3756 @Test
3757 public void testIndentationCodeBlocks2() throws Exception {
3758 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3759 checkConfig.addProperty("tabWidth", "4");
3760 checkConfig.addProperty("basicOffset", "2");
3761 checkConfig.addProperty("braceAdjustment", "2");
3762 checkConfig.addProperty("throwsIndent", "4");
3763 checkConfig.addProperty("caseIndent", "2");
3764 checkConfig.addProperty("lineWrappingIndentation", "4");
3765 final String[] expected = {
3766 "45:13: " + getCheckMessage(MSG_ERROR, "for lcurly", 12, 14),
3767 "47:13: " + getCheckMessage(MSG_ERROR, "for rcurly", 12, 14),
3768 };
3769 verifyWarns(checkConfig,
3770 getNonCompilablePath("InputIndentationCodeBlocks2.java"), expected);
3771 }
3772
3773 @Test
3774 public void testIndentationSealedClasses()
3775 throws Exception {
3776 final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
3777 checkConfig.addProperty("forceStrictCondition", "true");
3778 checkConfig.addProperty("tabWidth", "4");
3779 checkConfig.addProperty("basicOffset", "4");
3780 checkConfig.addProperty("braceAdjustment", "0");
3781 checkConfig.addProperty("caseIndent", "4");
3782 checkConfig.addProperty("throwsIndent", "8");
3783
3784 final String fileName = getNonCompilablePath(
3785 "InputIndentationSealedClasses.java");
3786 final String[] expected = {
3787 "14:1: " + getCheckMessage(MSG_ERROR, "class def modifier", 0, 4),
3788 "15:2: " + getCheckMessage(MSG_ERROR, "class", 1, 4),
3789 "16:6: " + getCheckMessage(MSG_ERROR, "permits", 5, 4),
3790 "19:5: " + getCheckMessage(MSG_ERROR, "class", 4, 8),
3791 "20:5: " + getCheckMessage(MSG_ERROR, "permits", 4, 8),
3792 "28:1: " + getCheckMessage(MSG_ERROR, "class def modifier", 0, 4),
3793 "29:9: " + getCheckMessage(MSG_ERROR, "extends", 8, 4),
3794 "32:5: " + getCheckMessage(MSG_ERROR, "extends", 4, 8),
3795 "38:5: " + getCheckMessage(MSG_ERROR, "class", 4, 8),
3796 "39:1: " + getCheckMessage(MSG_ERROR, "permits", 0, 8),
3797 "40:13: " + getCheckMessage(MSG_ERROR, "C", 12, 8),
3798 "48:5: " + getCheckMessage(MSG_ERROR, "class", 4, 8),
3799 "49:5: " + getCheckMessage(MSG_ERROR, "C", 4, 8),
3800 "55:1: " + getCheckMessage(MSG_ERROR, "class def modifier", 0, 4),
3801 "56:9: " + getCheckMessage(MSG_ERROR, "class", 8, 4),
3802 };
3803 verifyWarns(checkConfig, fileName, expected);
3804 }
3805
3806 private static final class IndentAudit implements AuditListener {
3807
3808 private final IndentComment[] comments;
3809 private int position;
3810
3811 private IndentAudit(IndentComment... comments) {
3812 this.comments = Arrays.copyOf(comments, comments.length);
3813 }
3814
3815 @Override
3816 public void auditStarted(AuditEvent event) {
3817
3818 }
3819
3820 @Override
3821 public void auditFinished(AuditEvent event) {
3822
3823 }
3824
3825 @Override
3826 public void fileStarted(AuditEvent event) {
3827
3828 }
3829
3830 @Override
3831 public void fileFinished(AuditEvent event) {
3832
3833 }
3834
3835 @Override
3836 public void addError(AuditEvent event) {
3837 final int line = event.getLine();
3838 final String message = event.getMessage();
3839
3840 assertWithMessage(
3841 "found a warning when none was expected for #%s at line %s with message %s",
3842 position, line, message)
3843 .that(position)
3844 .isLessThan(comments.length);
3845
3846 final IndentComment comment = comments[position];
3847 position++;
3848
3849 final String possibleExceptedMessages = Arrays.stream(comment.getExpectedMessages())
3850 .reduce("", (cur, next) -> cur + "\"" + next + "\", ");
3851 final String assertMessage = String.format(
3852 Locale.ROOT,
3853 "input expected warning #%d at line %d to report one of the following: %s"
3854 + "but got instead: %d: %s",
3855 position, comment.getLineNumber(), possibleExceptedMessages, line, message);
3856 assertWithMessage(assertMessage)
3857 .that(line == comment.getLineNumber() && Arrays
3858 .stream(comment.getExpectedMessages()).anyMatch(message::endsWith))
3859 .isTrue();
3860 }
3861
3862 @Override
3863 public void addException(AuditEvent event, Throwable throwable) {
3864
3865 }
3866
3867 }
3868
3869 private static final class IndentComment {
3870
3871
3872 private static final String FAKE_ARGUMENT_ZERO = "##0##";
3873 private final int lineNumber;
3874 private final int indent;
3875
3876 private final int indentOffset;
3877 private final boolean expectedNonStrict;
3878 private final String expectedWarning;
3879 private final boolean warning;
3880
3881 private IndentComment(Matcher match, int lineNumber) {
3882 this.lineNumber = lineNumber;
3883 indent = Integer.parseInt(match.group(1));
3884 if (match.group(2) == null) {
3885 indentOffset = 0;
3886 }
3887 else {
3888 indentOffset = Integer.parseInt(match.group(2));
3889 }
3890 expectedNonStrict = match.group(3) != null;
3891 expectedWarning = match.group(4).replace(",", ", ");
3892 warning = match.group(5) != null;
3893 }
3894
3895 public String[] getExpectedMessages() {
3896 final String[] expectedMessages;
3897 if (expectedWarning.contains(",")) {
3898 expectedMessages = new String[] {
3899 getExpectedMessagePostfix(MSG_ERROR_MULTI),
3900 getExpectedMessagePostfix(MSG_CHILD_ERROR_MULTI),
3901 };
3902 }
3903 else {
3904 expectedMessages = new String[] {
3905 getExpectedMessagePostfix(MSG_ERROR),
3906 getExpectedMessagePostfix(MSG_CHILD_ERROR),
3907 };
3908 }
3909 return expectedMessages;
3910 }
3911
3912 private String getExpectedMessagePostfix(final String messageKey) {
3913 final String msg = getCheckMessage(IndentationCheck.class, messageKey,
3914 FAKE_ARGUMENT_ZERO, indent + indentOffset, expectedWarning);
3915 final int indexOfMsgPostfix = msg.indexOf(FAKE_ARGUMENT_ZERO)
3916 + FAKE_ARGUMENT_ZERO.length();
3917 return msg.substring(indexOfMsgPostfix);
3918 }
3919
3920 public int getLineNumber() {
3921 return lineNumber;
3922 }
3923
3924 public int getIndent() {
3925 return indent;
3926 }
3927
3928 public int getIndentOffset() {
3929 return indentOffset;
3930 }
3931
3932 public boolean isExpectedNonStrict() {
3933 return expectedNonStrict;
3934 }
3935
3936 public String getExpectedWarning() {
3937 return expectedWarning;
3938 }
3939
3940 public boolean isWarning() {
3941 return warning;
3942 }
3943
3944 }
3945
3946 }