1
2
3
4
5
6
7 package com.puppycrawl.tools.checkstyle.checks.coding.innerassignment;
8
9 import java.io.FileInputStream;
10 import java.io.IOException;
11 import java.util.jar.JarInputStream;
12 import java.util.jar.Manifest;
13
14 public class InputInnerAssignment
15 {
16 void innerAssignments()
17 {
18 int a;
19 int b;
20 int c;
21
22 a = b = c = 1;
23
24
25
26
27 String s = Integer.toString(b = 2);
28
29 Integer i = new Integer(a += 5);
30
31 c = b++;
32
33
34 for (int j = 0; j < 6; j += 2) {
35 a += j;
36 }
37 }
38
39 public static void demoInputStreamIdiom(java.io.InputStream is) throws java.io.IOException
40 {
41 int b;
42 while ((b = is.read()) != -1)
43 {
44
45 }
46 }
47
48 public static void demoNoBrace()
49 {
50
51
52
53 int sum = 0;
54
55 for (int i = 0; i < 3; i++)
56 sum = sum + i;
57
58 if (sum > 4)
59 sum += 2;
60 else if (sum < 2)
61 sum += 1;
62 else
63 sum += 100;
64
65 while (sum > 4)
66 sum -= 1;
67
68 do
69 sum = sum + 1;
70 while (sum < 6);
71
72 ChildParent o = new ChildParent();
73 Object t = null;
74
75 while (o != null)
76 t = o = o.getParent();
77 }
78
79 @SuppressWarnings(value = "unchecked")
80 public java.util.Collection<Object> allParams() {
81 java.util.ArrayList params = new java.util.ArrayList();
82 params.add("one");
83 params.add("two");
84 return params;
85 }
86
87
88 private static Manifest loadManifest(String fn) {
89 try (FileInputStream fis = new FileInputStream(fn);
90 JarInputStream jis = new JarInputStream(fis, false))
91 {
92 return jis.getManifest();
93 } catch (IOException e)
94 {
95 return null;
96 }
97 }
98
99 private static class ChildParent {
100 public ChildParent getParent() {
101 return this;
102 }
103 }
104 }