1 /* 2 ModifierOrder 3 4 5 */ 6 7 package com.puppycrawl.tools.checkstyle.checks.modifier.modifierorder; 8 9 /** 10 * Test case for Modifier checks: 11 * - order of modifiers 12 * - use of 'public' in interface definition 13 * @author lkuehne 14 */ 15 strictfp final class InputModifierOrderItOne // violation ''final'.*out of order.*JLS suggestions.' 16 { 17 18 /** Illegal order of modifiers for variables */ 19 static private boolean sModifierOrderVar = false; // violation ''private'.*JLS suggestions.' 20 21 /** 22 * Illegal order of modifiers for methods. Make sure that the 23 * first and last modifier from the JLS sequence is used. 24 */ 25 strictfp private void doStuff() // violation ''private' modifier.*order.*JLS suggestions.' 26 { 27 } 28 29 /** Single annotation without other modifiers */ 30 @MyAnnotation2 void someMethod() 31 { 32 } 33 34 /** Illegal order of annotation - must come first */ 35 private @MyAnnotation2 void someMethod2() 36 { // violation above ''@MyAnnotation2' annotation modifier.*precede non-annotation modifiers.' 37 } 38 39 /** Annotation in middle of other modifiers otherwise in correct order */ 40 private @MyAnnotation2 strictfp void someMethod3() 41 { // violation above ''@MyAnnotation2' annotation modifier.*precede non-annotation modifiers.' 42 } 43 44 /** Correct order */ 45 @MyAnnotation2 private strictfp void someMethod4() 46 { 47 } 48 49 /** Annotation in middle of other modifiers otherwise in correct order */ 50 @MyAnnotation2 private static @MyAnnotation4 strictfp void someMethod5() 51 { // violation above ''@MyAnnotation4' annotation modifier.*precede non-annotation modifiers.' 52 } 53 54 /** holder for redundant 'public' modifier check. */ 55 public static interface InputRedundantPublicModifier 56 { 57 /** redundant 'public' modifier */ 58 public void a(); 59 60 /** all OK */ 61 void b(); 62 63 /** redundant abstract modifier */ 64 abstract void c(); 65 66 /** redundant 'public' modifier */ 67 public float PI_PUBLIC = (float) 3.14; 68 69 /** redundant 'abstract' modifier (field can not be abstract) */ 70 // abstract float PI_ABSTRACT = (float) 3.14; 71 72 /** redundant 'final' modifier */ 73 final float PI_FINAL = (float) 3.14; 74 75 /** all OK */ 76 float PI_OK = (float) 3.14; 77 } 78 79 /** redundant 'final' modifier */ 80 private final void method() 81 { 82 } 83 } 84 85 86 87 /** Holder for redundant modifiers of inner implementation */ 88 abstract interface InnerImplementation 89 { 90 InnerImplementation inner = 91 new InnerImplementation() 92 { 93 /** compiler requires 'public' modifier */ 94 public void method() 95 { 96 } 97 }; 98 99 void method(); 100 } 101 102 /** Holder for redundant modifiers of annotation fields/variables */ 103 @interface Annotation 104 { 105 public String s1 = ""; 106 final String s2 = ""; 107 static String s3 = ""; 108 String s4 = ""; 109 public String blah(); 110 abstract String blah2(); 111 } 112 113 @interface MyAnnotation2 { 114 } 115 116 @interface MyAnnotation4 { 117 }