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