01: package com.puppycrawl.tools.checkstyle.coding;
02:
03: public class InputInnerAssignment {
04: void innerAssignments() {
05: int a;
06: int b;
07: int c;
08:
09: a = b = c = 1; // flag two inner assignments
10:
11: String s = Integer.toString(b = 2); // flag inner assignment
12:
13: Integer i = new Integer(a += 5); // flag inner assigment
14:
15: c = b++; // common practice, don't flag
16: // even though technically an assigment to b
17:
18: for (int j = 0; j < 6; j += 2) { // common practice, don't flag
19: a += j;
20: }
21: }
22:
23: public void demoBug1195047Comment3() {
24: // inner assignment should flag all assignments to b or bb but none of those to i or j
25: int y = 1;
26: int b = 0;
27: boolean bb;
28: int i;
29:
30: if (bb = false) {
31: }
32: for (i = 0; bb = false; i = i + 1) {
33: }
34: while (bb = false) {
35: }
36: if ((bb = false)) {
37: }
38: for (int j = 0; (bb = false); j += 1) {
39: }
40: while ((bb = false)) {
41: }
42: i = (bb = false) ? (b = 2) : (b += 1);
43: i = (b += 1) + (b -= 1);
44: do {
45: i += 1;
46: } while (bb = false);
47: }
48:
49: public static void demoInputStreamIdiom(java.io.InputStream is)
50: throws java.io.IOException {
51: int b;
52: while ((b = is.read()) != -1) // common idiom to avoid clumsy loop control logic, don't flag (make configurable later)
53: {
54: // work with b
55: }
56: }
57:
58: public static void demoNoBrace() {
59: // code that doesn't contain braces around conditional code
60: // results in a parse tree without SLISTs
61: // no assignement should be flagged here
62: int sum = 0;
63:
64: for (int i = 0; i < 3; i++)
65: sum = sum + i;
66:
67: if (sum > 4)
68: sum += 2;
69: else if (sum < 2)
70: sum += 1;
71: else
72: sum += 100;
73:
74: while (sum > 4)
75: sum -= 1;
76:
77: do
78: sum = sum + 1;
79: while (sum < 6);
80: }
81:
82: @SuppressWarnings(value="unchecked")
83: public java.util.Collection<Object> allParams() {
84: java.util.ArrayList params = new java.util.ArrayList();
85: params.add("one");
86: params.add("two");
87: return params;
88: }
89: }
|