1 /* 2 MethodName 3 format = (default)^[a-z][a-zA-Z0-9]*$ 4 allowClassName = true 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 InputMethodNameEqualClassName2 { 22 23 //illegal name 24 // violation below 'Name 'InputMethodNameEqualClassName2' must match pattern.' 25 public int InputMethodNameEqualClassName2() { 26 return 0; 27 } 28 29 //illegal name 30 // violation below 'Name 'PRIVATEInputMethodNameEqualClassName' must match pattern.' 31 private int PRIVATEInputMethodNameEqualClassName() { 32 return 0; 33 } 34 35 class Inner { 36 //illegal name 37 // violation below 'Name 'Inner' must match pattern.' 38 public int Inner() { 39 return 0; 40 } 41 42 //OK name - name of the outter class's ctor 43 // violation below 'Name 'InputMethodNameEqualClassName2' must match pattern.' 44 public int InputMethodNameEqualClassName2() { 45 return 0; 46 } 47 } 48 49 public void anotherMethod() { 50 new InputMethodNameEqualClassName() { 51 52 //illegal name 53 // violation below 'Name 'InputMethodNameEqualClassName2' must match pattern.' 54 public int InputMethodNameEqualClassName2() { 55 return 1; 56 } 57 }; 58 } 59 } 60 61 interface SweetInterface2 { 62 63 //illegal name 64 int SweetInterface(); // violation 'Name 'SweetInterface' must match pattern' 65 } 66 67 class Outer2 { 68 69 //illegal name 70 public void Outer() { // violation 'Name 'Outer' must match pattern' 71 72 } 73 }