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