1   ////////////////////////////////////////////////////////////////////////////////
2   // Test case file for checkstyle.
3   // Created: 2001
4   ////////////////////////////////////////////////////////////////////////////////
5   
6   package com.puppycrawl.tools.checkstyle.checks.modifier.redundantmodifier;
7   
8   /**
9    * Test case for Modifier checks:
10   * - order of modifiers
11   * - use of 'public' in interface definition
12   * @author lkuehne
13   */
14  strictfp final class InputRedundantModifierIt // illegal order of modifiers for class
15  {
16  
17      /** Illegal order of modifiers for variables */
18      static private boolean sModifierOrderVar = false;
19  
20      /**
21       * Illegal order of modifiers for methods. Make sure that the
22       * first and last modifier from the JLS sequence is used.
23       */
24      strictfp private void doStuff()
25      {
26      }
27  
28      /** Single annotation without other modifiers */
29      @MyAnnotation2 void someMethod()
30      {
31      }
32  
33      /** Illegal order of annotation - must come first */
34      private @MyAnnotation2 void someMethod2()
35      {
36      }
37  
38      /** Annotation in middle of other modifiers otherwise in correct order */
39      private @MyAnnotation2 strictfp void someMethod3()
40      {
41      }
42  
43      /** Correct order */
44      @MyAnnotation2 private strictfp void someMethod4()
45      {
46      }
47  
48      /** Annotation in middle of other modifiers otherwise in correct order */
49      @MyAnnotation2 private static @MyAnnotation4 strictfp void someMethod5()
50      {
51      }
52  
53      /** holder for redundant 'public' modifier check. */
54      public static interface InputRedundantPublicModifier // violation
55      {
56          /** redundant 'public' modifier */
57          public void a(); // violation
58  
59          /** all OK */
60          void b();
61  
62          /** redundant abstract modifier */
63          abstract void c(); // violation
64  
65          /** redundant 'public' modifier */
66          public float PI_PUBLIC = (float) 3.14; // violation
67  
68          /** redundant 'abstract' modifier (field can not be abstract) */
69  //        abstract float PI_ABSTRACT = (float) 3.14;
70  
71          /** redundant 'final' modifier */
72          final float PI_FINAL = (float) 3.14; // violation
73  
74          /** all OK */
75          float PI_OK = (float) 3.14;
76      }
77  
78      /** redundant 'final' modifier */
79      private final void method() // violation
80      {
81      }
82  }
83  
84  /** Holder for redundant 'final' check. */
85  final class RedundantFinalClass
86  {
87      /** redundant 'final' modifier */
88      public final void finalMethod() // violation
89      {
90      }
91  
92      /** OK */
93      public void method()
94      {
95      }
96  }
97  
98  /** Holder for redundant modifiers of inner implementation */
99  abstract interface InnerImplementation // violation
100 {
101     InnerImplementation inner =
102             new InnerImplementation()
103             {
104                 /** compiler requires 'public' modifier */
105                 public void method()
106                 {
107                 }
108             };
109 
110     void method();
111 }
112 
113 /** Holder for redundant modifiers of annotation fields/variables */
114 @interface Annotation
115 {
116     public String s1 = ""; // violation
117     final String s2 = ""; // violation
118     static String s3 = ""; // violation
119     String s4 = "";
120     public String blah(); // violation
121     abstract String blah2(); // violation
122 }
123 
124 @interface MyAnnotation2 {
125 }
126 
127 @interface MyAnnotation4 {
128 }
129 
130 class SafeVarargsUsage {
131     @Deprecated
132     @SafeVarargs
133     private final void foo(int... k) {}
134 
135     @Deprecated
136     @SafeVarargs
137     @SuppressWarnings("")
138     private final void foo1(Object... obj) {}
139 }
140 
141 enum TestEnum {
142     ;
143 
144     public void method() {
145     }
146 }
147 
148 /** holder for interface specific modifier check. */
149 interface InputDefaultPublicModifier
150 {
151     /** correct order */
152     default strictfp void a()
153     {
154     }
155 
156     /** wrong order */
157     strictfp default void b() // violation
158     {
159     }
160 }