View Javadoc
1   /*xml
2   <module name="Checker">
3     <module name="TreeWalker">
4       <module name="AnonInnerLength">
5         <property name="max" value="7"/>
6       </module>
7     </module>
8   </module>
9   */
10  package com.puppycrawl.tools.checkstyle.checks.sizes.anoninnerlength;
11  
12  // xdoc section -- start
13  class Example2 {
14    void testMethod() {
15      Runnable shortAnonClass = new Runnable() {
16        @Override
17        public void run() {
18          System.out.println("Short anonymous class.");
19        }
20      };
21      shortAnonClass.run();
22      // violation below, 'Anonymous inner class length is 9 lines (max allowed is 7)'
23      Runnable longAnonClass = new Runnable() {
24        @Override
25        public void run() {
26          System.out.println("This is a lengthy anonymous class.");
27          System.out.println("It has too many lines of code.");
28          System.out.println("Exceeding the length limit.");
29          System.out.println("This would trigger the AnonInnerLength rule.");
30        }
31      };
32      longAnonClass.run();
33    }
34  }
35  // xdoc section -- end