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