View Javadoc
1   /*
2   AnonInnerLength
3   max = 6
4   
5   
6   */
7   
8   package com.puppycrawl.tools.checkstyle.checks.sizes.anoninnerlength;
9   
10  import java.awt.event.MouseAdapter;
11  import java.awt.event.MouseEvent;
12  
13  import javax.swing.JButton;
14  
15  /**
16   * Tests for length of anonymous inner types
17   * @author Rob Worth
18   * @author Lars Kühne
19   **/
20  public class InputAnonInnerLength2
21  {
22      /**
23       * Check that instantiations of normal classes work OK.
24       */
25      private JButton mButton = new JButton();
26  
27      private class MyInner
28      {
29          private MyInner(int[] anArray)
30          {
31          }
32      }
33  
34      /**
35       * the AnonInnerLengthCheck works with 'new' and RCURLY - check that
36       * it will not confuse constructors calls with array params with
37       * anon inners.
38       */
39      private MyInner myInner = new MyInner(new int[]{
40              // make the array span multiple lines
41              1,
42              2,
43              3,
44              4,
45              5,
46              6,
47              7,
48              }
49      );
50  
51      /**
52         anon inner in member variable initialization which is 21 lines long
53      */
54      private Runnable mRunnable1 = new Runnable() { // violation
55          public void run() // should not have to be documented, class is anon.
56          {
57              System.identityHashCode("running");
58              System.identityHashCode("running");
59              System.identityHashCode("running");
60              System.identityHashCode("running");
61              System.identityHashCode("running");
62              System.identityHashCode("running");
63              System.identityHashCode("running");
64              System.identityHashCode("running");
65              System.identityHashCode("running");
66              System.identityHashCode("running");
67              System.identityHashCode("running");
68              System.identityHashCode("running");
69              System.identityHashCode("running");
70              System.identityHashCode("running");
71              System.identityHashCode("running");
72              System.identityHashCode("running");
73          }
74      };
75  
76      /**
77         anon inner in member variable initialization which is 20 lines long
78      */
79      private Runnable mRunnable2 = new Runnable() { // violation
80          public void run() // should not have to be documented, class is anon.
81          {
82              System.identityHashCode("running");
83              System.identityHashCode("running");
84              System.identityHashCode("running");
85              System.identityHashCode("running");
86              System.identityHashCode("running");
87              System.identityHashCode("running");
88              System.identityHashCode("running");
89              System.identityHashCode("running");
90              System.identityHashCode("running");
91              System.identityHashCode("running");
92              System.identityHashCode("running");
93              System.identityHashCode("running");
94              System.identityHashCode("running");
95              System.identityHashCode("running");
96              System.identityHashCode("running");
97          }
98      };
99  
100     /**
101        anon inner in constructor.
102     */
103     InputAnonInnerLength2()
104     {
105         mButton.addMouseListener( new MouseAdapter()
106             {
107                 public void mouseClicked( MouseEvent aEv )
108                 {
109                     System.identityHashCode("click");
110                 }
111             } );
112     }
113 
114     /**
115        anon inner in method
116     */
117     public void addInputAnonInner()
118     {
119         mButton.addMouseListener( new MouseAdapter()
120             {
121                 public void mouseClicked( MouseEvent aEv )
122                 {
123                     System.identityHashCode("click");
124                 }
125             } );
126     }
127 }