1 /* 2 OneStatementPerLine 3 treatTryResourcesAsStatement = true 4 5 6 */ 7 8 package com.puppycrawl.tools.checkstyle.checks.coding.onestatementperline; 9 10 /* 11 This class provides test input for OneStatementPerLineCheck with different 12 types of multiline statements. 13 A Java statement is the smallest unit that is a complete instruction. 14 Statements must end with a semicolon. 15 Statements generally contain expressions (expressions have a value). 16 One of the simplest is the Assignment Statement. 17 */ 18 public class InputOneStatementPerLineMultilineForDeclarations { 19 20 /** 21 * One multiline assignment (declaration) statement 22 * is legal. 23 */ 24 int e = 1, f = 2, 25 g = 5; 26 27 /** 28 * One multiline assignment (declaration) statement 29 * is legal. 30 */ 31 int h = 1, 32 i = 2, 33 j = 5; 34 35 /** 36 * One multiline assignment (declaration) statement 37 * is legal. 38 */ 39 int k = 1, 40 l = 2, 41 m = 5 42 ; 43 44 /** 45 * Two multiline assignment (declaration) statements 46 * on the same line are illegal. 47 */ 48 int o = 1, p = 2, 49 r = 5; int t; // violation 'Only one statement per line allowed.' 50 51 /** 52 * Two assignment (declaration) statement 53 * which are not on the same line are legal. 54 */ 55 int one = 1, 56 three = 5; 57 int two = 2; 58 59 /** 60 * Two statements on the same line 61 * (they both are distributed over two lines) 62 * are illegal. 63 */ 64 int var1 = 5, 65 var4 = 5; int var2 = 6, 66 var3 = 5; // violation 'Only one statement per line allowed.' 67 68 /** 69 * Two statements on the same line 70 * (the second is distributed over two lines) 71 * are illegal. 72 */ 73 int var6 = 5; int var7 = 6, 74 var8 = 5; // violation 'Only one statement per line allowed.' 75 76 /** 77 * Two statements on the same line 78 * (they both are distributed over two lines) 79 * are illegal. 80 */ 81 private void foo() { 82 toString( 83 84 );toString( 85 86 ); // violation 'Only one statement per line allowed.' 87 } 88 89 /** 90 * While theoretically being distributed over three lines, this is a sample 91 * of 2 statements on one line. 92 */ 93 int var9 = 1, 94 var10 = 5 95 ; int var11 = 2; // violation 'Only one statement per line allowed.' 96 97 /** 98 * Multiline for loop statement is legal. 99 */ 100 private void foo2() { 101 for (int n = 0, 102 k = 1; 103 n < 5; n++, 104 k--) { 105 106 } 107 } 108 109 }