1 /*
2 OneStatementPerLine
3 treatTryResourcesAsStatement = (default)false
4
5
6 */
7
8 package com.puppycrawl.tools.checkstyle.checks.coding.onestatementperline;
9
10 /**
11 * Two import statements on the same line are illegal.
12 */
13 // violation below 'Only one statement per line allowed.'
14 import java.io.EOFException; import java.io.BufferedReader;
15
16 public class InputOneStatementPerLineSingleLineSmallTalkStyle {
17 /**
18 * Dummy innerclass to test the behaviour in the case of a smalltalk-style
19 * statements (<code>myObject.firstMethod().secondMethod().thirdMethod()</code>).
20 * For this programming style each method must return the object itself <code>this</code>.
21 */
22 class SmallTalkStyle {
23 SmallTalkStyle doSomething1() {
24 return this;
25 }
26
27 SmallTalkStyle doSomething2() {
28 return this;
29 }
30
31 SmallTalkStyle doSomething3() {
32 return this;
33 }
34 }
35
36 /**
37 * Dummy variable to work on.
38 */
39 private int one = 0;
40
41 /**
42 * Dummy variable to work on.
43 */
44 private int two = 0;
45
46 /**
47 * Simple legal method
48 */
49 public void doLegal() {
50 one = 1;
51 two = 2;
52 }
53
54 /**
55 * The illegal format is used in a comment. Therefor the whole method is legal.
56 */
57 public void doLegalComment() {
58 one = 1;
59 //one = 1; two = 2;
60 two = 2;
61 /*
62 * one = 1; two = 2;
63 */
64 }
65
66 /**
67 * The illegal format is used within a String. Therefor the whole method is legal.
68 */
69 public void doLegalString() {
70 one = 1;
71 two = 2;
72 System.identityHashCode("one = 1; two = 2");
73 }
74
75 /**
76 * Within the for-header there are 3 Statements, but this is legal.
77 */
78 public void doLegalForLoop() {
79 for (int i = 0; i < 20; i++) {
80 one = i;
81 }
82 }
83
84 /**
85 * Simplest form of an illegal layout.
86 */
87 public void doIllegal() {
88 one = 1; two = 2; // violation 'Only one statement per line allowed.'
89 }
90
91 /**
92 * Smalltalk-style is considered as one statement.
93 */
94 public void doIllegalSmallTalk() {
95 SmallTalkStyle smalltalker = new SmallTalkStyle();
96 smalltalker.doSomething1().doSomething2().doSomething3();
97 }
98
99 /**
100 * Smalltalk-style is considered as one statement.
101 */
102 public void doIllegalSmallTalk2() {
103 SmallTalkStyle smalltalker = new SmallTalkStyle();
104 smalltalker.doSomething1()
105 .doSomething2()
106 .doSomething3();
107 }
108
109 }