View Javadoc
1   /*
2   OneStatementPerLine
3   treatTryResourcesAsStatement = true
4   
5   
6   */
7   
8   
9   package com.puppycrawl.tools.checkstyle.checks.coding.onestatementperline;
10  
11  import java.io.IOException;
12  import java.io.PipedOutputStream;
13  import java.io.OutputStream;
14  
15  /**
16   * Config treatTryResourcesAsStatement = true
17   */
18  public class InputOneStatementPerLineTryWithResources {
19  
20      void method() throws IOException {
21          OutputStream s1 = new PipedOutputStream();
22          OutputStream s2 = new PipedOutputStream();
23          try (s1; s2; OutputStream s3 = new PipedOutputStream();) {
24          }
25          try (s1; OutputStream s4 = new PipedOutputStream(); s2;) {
26          }
27          try (s1; s2; OutputStream s5 = new PipedOutputStream()) {
28          }
29          try (s1; OutputStream s6 = new PipedOutputStream(); s2) {
30          }
31          try (
32                  // violation below 'Only one statement per line allowed.'
33  OutputStream s7 = new PipedOutputStream();OutputStream s8 = new PipedOutputStream();
34             s2;
35          ) {}
36          try (
37                  // violation below 'Only one statement per line allowed.'
38  OutputStream s9=new PipedOutputStream();s2;OutputStream s10 = new PipedOutputStream())
39          {}
40          try (s1; OutputStream s11 = new PipedOutputStream();
41               s2;) {
42          }
43          try (OutputStream
44                  // violation below 'Only one statement per line allowed.'
45               s12 = new PipedOutputStream();s1;OutputStream s3 = new PipedOutputStream()
46               ;s2;) {
47          }
48          try (OutputStream
49                  // violation below 'Only one statement per line allowed.'
50               s12 = new PipedOutputStream();s1;OutputStream s3
51                  = new PipedOutputStream()) {}
52          try (s1; s2; OutputStream stream3 =
53               new PipedOutputStream()) {}
54          try (OutputStream s10 = new PipedOutputStream();
55               OutputStream s11 = new PipedOutputStream(); s2;) {
56          }
57      }
58  
59      void testNestedInLambda() {
60          Runnable r = () -> {
61              try (OutputStream s1 = new PipedOutputStream();
62                   OutputStream s2 = new PipedOutputStream();) {
63              }
64              catch (IOException e) {
65              }
66          };
67      }
68  }