View Javadoc
1   /*
2   OverloadMethodsDeclarationOrder
3   
4   
5   */
6   
7   package com.puppycrawl.tools.checkstyle.checks.coding.overloadmethodsdeclarationorder;
8   
9   class InputOverloadMethodsDeclarationOrder
10  {
11      public void overloadMethod(int i)
12      {
13          //some foo code
14      }
15  
16      public void overloadMethod(String s)
17      {
18          //some foo code
19      }
20  
21      public void overloadMethod(boolean b)
22      {
23          //some foo code
24      }
25  
26      public void fooMethod()
27      {
28  
29      }
30  
31      //violation: because overloads never split
32      // violation below 'All overloaded methods should be placed next to each other.'
33      public void overloadMethod(String s, Boolean b, int i)
34      {
35          //some foo code
36      }
37  
38      InputOverloadMethodsDeclarationOrder anonymous = new InputOverloadMethodsDeclarationOrder()
39      {
40          public void overloadMethod(int i)
41          {
42              //some foo code
43          }
44  
45          public void overloadMethod(String s)
46          {
47              //some foo code
48          }
49  
50          public void overloadMethod(boolean b)
51          {
52              //some foo code
53          }
54  
55          public void fooMethod()
56          {
57  
58          }
59  
60          //violation: because overloads never split
61          // violation below 'All overloaded methods should be placed next to each other.'
62          public void overloadMethod(String s, Boolean b, int i)
63          {
64              //some foo code
65          };
66  
67          public void overloadMethod(double d)
68          {
69            // violation 2 lines above 'All overloaded methods should be placed next to each other.'
70            /*
71             * Explanation of violation:
72             * There is a semicolon at the end of the previous method
73             * which is separating these overloaded methods
74             * and causing the violation.
75             */
76          }
77      };
78  }
79  
80  interface Fooable
81  {
82      public abstract void foo(int i);
83      public abstract void foo(String s);
84      public abstract void noFoo();
85  
86      // violation below 'All overloaded methods should be placed next to each other.'
87      public abstract void foo(String s, Boolean b, int i);
88  }
89  
90  enum FooType {
91      Strategy(""),
92      Shooter(""),
93      RPG("");
94  
95      private String description;
96  
97      private FooType(String description) {
98          this.description = description;
99      }
100 
101     public String getDescription() {
102         return description;
103     }
104 
105     public void setDescription(String description) {
106         this.description = description;
107     }
108 
109     public void overloadMethod(int i)
110     {
111         //some foo code
112     }
113 
114     public void overloadMethod(String s)
115     {
116         //some foo code
117     }
118 
119     // comments between overloaded methods are allowed.
120     public void overloadMethod(boolean b)
121     {
122         //some foo code
123     }
124 
125     public void fooMethod()
126     {
127 
128     }
129 
130     //violation: because overloads never split
131     // violation below 'All overloaded methods should be placed next to each other.'
132     public void overloadMethod(String s, Boolean b, int i)
133     {
134         //some foo code
135     }
136 
137     void test() {}
138 
139     String str;
140 
141     private interface Testing {}
142 
143     // violation below 'All overloaded methods should be placed next to each other.'
144     void test(int x) {}
145 
146     private class Inner {
147         void test() {}
148 
149         void test(String str) {}
150 
151         void test2() {}
152 
153         String str;
154 
155         // violation below 'All overloaded methods should be placed next to each other.'
156         void test(int x) {}
157     }
158     // violation below 'All overloaded methods should be placed next to each other.'
159     void test(double d) {}
160 }
161 
162 enum Foo2 {
163     VALUE {
164         public void value() {
165             value("");
166         }
167 
168         public void middle() {
169         }
170 
171         public void value(String s) {
172         }
173     };
174 }
175 
176 @interface ClassPreamble {
177     String author();
178 }