View Javadoc
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 InputModifierOrderIt // 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  /** Holder for redundant 'final' check. */
86  final class RedundantFinalClass
87  {
88      /** redundant 'final' modifier */
89      public final void finalMethod()
90      {
91      }
92  
93      /** OK */
94      public void method()
95      {
96      }
97  }
98  
99  /** Holder for redundant modifiers of inner implementation */
100 abstract interface InnerImplementation
101 {
102     InnerImplementation inner =
103             new InnerImplementation()
104             {
105                 /** compiler requires 'public' modifier */
106                 public void method()
107                 {
108                 }
109             };
110 
111     void method();
112 }
113 
114 /** Holder for redundant modifiers of annotation fields/variables */
115 @interface Annotation
116 {
117     public String s1 = "";
118     final String s2 = "";
119     static String s3 = "";
120     String s4 = "";
121     public String blah();
122     abstract String blah2();
123 }
124 
125 @interface MyAnnotation2 {
126 }
127 
128 @interface MyAnnotation4 {
129 }
130 
131 class SafeVarargsUsage {
132     @Deprecated
133     @SafeVarargs
134     private final void foo(int... k) {}
135 
136     @Deprecated
137     @SafeVarargs
138     @SuppressWarnings("")
139     private final void foo1(Object... obj) {}
140 }
141 
142 enum TestEnum {
143     ;
144 
145     public void method() {
146     }
147 }
148 
149 /** holder for interface specific modifier check. */
150 interface InputDefaultPublicModifier
151 {
152     /** correct order */
153     default strictfp void a()
154     {
155     }
156 
157     /** wrong order */
158     strictfp default void b() // violation ''default' modifier out of order .*JLS suggestions.'
159     {
160     }
161 }