View Javadoc
1   /*
2   InnerAssignment
3   
4   
5   */
6   
7   package com.puppycrawl.tools.checkstyle.checks.coding.innerassignment;
8   
9   public class InputInnerAssignmentDemoBug1195047Comment3 {
10      public void demoBug1195047Comment3()
11      {
12          // inner assignment should flag all assignments to b or bb but none of those to i or j
13          int y = 1;
14          int b = 0;
15          boolean bb;
16          int i;
17  
18          if (bb = false) {} // violation, 'Inner assignments should be avoided'
19          for (i = 0; bb = false; i = i + 1) {} // violation, 'Inner assignments should be avoided'
20          while (bb = false) {} // violation, 'Inner assignments should be avoided'
21          if ((bb = false)) {} // violation, 'Inner assignments should be avoided'
22          for (int j = 0; (bb = false); j += 1) {} // violation, 'Inner assignments should be avoided'
23          while ((bb = false)) {} // violation, 'Inner assignments should be avoided'
24          i = (bb = false) ? (b = 2) : (b += 1);
25          // 3 violations above:
26          //    'Inner assignments should be avoided'
27          //    'Inner assignments should be avoided'
28          //    'Inner assignments should be avoided'
29          i = (b += 1) + (b -= 1);
30          // 2 violations above:
31          //    'Inner assignments should be avoided'
32          //    'Inner assignments should be avoided'
33          do {i += 1;} while (bb = false); // violation, 'Inner assignments should be avoided'
34      }
35  }