View Javadoc
1   /*
2   MethodName
3   format = (default)^[a-z][a-zA-Z0-9]*$
4   allowClassName = (default)false
5   applyToPublic = (default)true
6   applyToProtected = (default)true
7   applyToPackage = (default)true
8   applyToPrivate = (default)true
9   
10  
11  */
12  
13  package com.puppycrawl.tools.checkstyle.checks.naming.methodname;
14  
15  /**
16   * Test input for MethodNameCheck specifically
17   * whether the method name equals the class name.
18   *
19   * @author Travis Schneeberger
20   */
21  public class InputMethodNameEqualClassName {
22  
23      //illegal name
24      // 2 violations 3 lines below:
25      //        'Method Name 'InputMethodNameEqualClassName' must not equal the enclosing class name.'
26      //        'Name 'InputMethodNameEqualClassName' must match pattern.'
27      public int InputMethodNameEqualClassName() {
28          return 0;
29      }
30  
31      //illegal name
32      // violation below 'Name 'PRIVATEInputMethodNameEqualClassName' must match pattern.'
33      private int PRIVATEInputMethodNameEqualClassName() {
34          return 0;
35      }
36  
37      class Inner {
38          //illegal name
39          // 2 violations 3 lines below:
40          //        'Method Name 'Inner' must not equal the enclosing class name.'
41          //        'Name 'Inner' must match pattern.'
42          public int Inner() {
43                          return 0;
44          }
45  
46          //OK name - name of the outter class's ctor
47          // violation below 'Name 'InputMethodNameEqualClassName' must match pattern.'
48          public int InputMethodNameEqualClassName() {
49                          return 0;
50                  }
51          }
52  
53          public void anotherMethod() {
54                  new InputMethodNameEqualClassName() {
55  
56          //illegal name
57          // 2 violations 3 lines below:
58          //  'Method Name 'InputMethodNameEqualClassName' must not equal the enclosing class name.'
59          //  'Name 'InputMethodNameEqualClassName' must match pattern.'
60              public int InputMethodNameEqualClassName() {
61                                  return 1;
62                          }
63                  };
64          }
65  }
66  
67  interface SweetInterface {
68  
69      //illegal name
70      // 2 violations 3 lines below:
71      //       'Method Name 'SweetInterface' must not equal the enclosing class name.'
72      //       'Name 'SweetInterface' must match pattern.'
73      int SweetInterface();
74  }
75  
76  class Outer {
77  
78      //illegal name
79      // 2 violations 3 lines below:
80      //       'Method Name 'Outer' must not equal the enclosing class name.'
81      //       'Name 'Outer' must match pattern.'
82      public void Outer() {
83  
84      }
85  }