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