1 /* 2 OneStatementPerLine 3 treatTryResourcesAsStatement = (default)false 4 5 6 */ 7 8 package com.puppycrawl.tools.checkstyle.checks.coding.onestatementperline; 9 10 public class InputOneStatementPerLineSingleLineInLoops { 11 /** 12 * Dummy variable to work on. 13 */ 14 private int one = 0; 15 16 /** 17 * Dummy variable to work on. 18 */ 19 private int two = 0; 20 21 /** 22 * While theoretically being distributed over two lines, this is a sample 23 * of 2 statements on one line. 24 */ 25 public void doIllegal2() { 26 one = 1 27 ; two = 2; // violation 'Only one statement per line allowed.' 28 } 29 30 /** 31 * The StringBuffer is a Java-API-class that permits smalltalk-style concatenation 32 * on the <code>append</code>-method. 33 */ 34 public void doStringBuffer() { 35 StringBuffer sb = new StringBuffer(); 36 sb.append("test "); 37 sb.append("test2 ").append("test3 "); 38 appendToSpringBuffer(sb, "test4"); 39 } 40 41 /** 42 * indirect stringbuffer-method. Used only internally. 43 * @param sb The stringbuffer we want to append something 44 * @param text The text to append 45 */ 46 private void appendToSpringBuffer(StringBuffer sb, String text) { 47 sb.append(text); 48 } 49 50 /** 51 * Two declaration statements on the same line are illegal. 52 */ 53 int a; int b; // violation 'Only one statement per line allowed.' 54 55 /** 56 * Two declaration statements which are not on the same line 57 * are legal. 58 */ 59 int c; 60 int d; 61 62 /** 63 * Two assignment (declaration) statements on the same line are illegal. 64 */ 65 int e = 1; int f = 2; // violation 'Only one statement per line allowed.' 66 67 /** 68 * Two assignment (declaration) statements on the different lines 69 * are legal. 70 */ 71 int g = 1; 72 int h = 2; 73 74 /** 75 * This method contains two increment statements 76 * and two object creation statements on the same line. 77 */ 78 private void foo() { 79 //This is two assignment (declaration) 80 //statements on different lines 81 int var1 = 1; 82 int var2 = 2; 83 84 //Two increment statements on the same line are illegal. 85 var1++; var2++; // violation 'Only one statement per line allowed.' 86 87 //Two object creation statements on the same line are illegal. 88 // violation below 'Only one statement per line allowed.' 89 Object obj1 = new Object(); Object obj2 = new Object(); 90 } 91 92 }