Lines 30-36
Link Here
|
30 |
// Static initializer to specify tests subset using TESTS_* static variables |
30 |
// Static initializer to specify tests subset using TESTS_* static variables |
31 |
// All specified tests which does not belong to the class are skipped... |
31 |
// All specified tests which does not belong to the class are skipped... |
32 |
static { |
32 |
static { |
33 |
// TESTS_NAMES = new String[] { "test127" }; |
33 |
// TESTS_NAMES = new String[] { "test118" }; |
34 |
// TESTS_NUMBERS = new int[] { 113 }; |
34 |
// TESTS_NUMBERS = new int[] { 113 }; |
35 |
// TESTS_RANGE = new int[] { 108, -1 }; |
35 |
// TESTS_RANGE = new int[] { 108, -1 }; |
36 |
} |
36 |
} |
Lines 5887-5890
Link Here
|
5887 |
false, |
5887 |
false, |
5888 |
null); |
5888 |
null); |
5889 |
} |
5889 |
} |
|
|
5890 |
|
5891 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 |
5892 |
// QualifiedNameReference, SingleNameReference and MessageSend |
5893 |
// Can be static warning shown |
5894 |
public void test114() { |
5895 |
Map compilerOptions = getCompilerOptions(); |
5896 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
5897 |
this.runNegativeTest( |
5898 |
new String[] { |
5899 |
"X.java", |
5900 |
"public class X {\n" + |
5901 |
" public static int field1;\n" + |
5902 |
" public static int field2;\n" + |
5903 |
" public void bar(int i) {\n" + |
5904 |
" System.out.println(foo());\n" + |
5905 |
" foo();" + |
5906 |
" System.out.println(X.field1);\n" + |
5907 |
" System.out.println(field2);\n" + |
5908 |
" field2 = 1;\n" + |
5909 |
" }\n" + |
5910 |
" private static String foo() {\n" + |
5911 |
" return null;\n" + |
5912 |
" }\n" + |
5913 |
"}" |
5914 |
}, |
5915 |
"----------\n" + |
5916 |
"1. ERROR in X.java (at line 4)\n" + |
5917 |
" public void bar(int i) {\n" + |
5918 |
" ^^^^^^^^^^\n" + |
5919 |
"The method bar(int) from the type X can be declared as static\n" + |
5920 |
"----------\n", |
5921 |
null /* no extra class libraries */, |
5922 |
true /* flush output directory */, |
5923 |
compilerOptions /* custom options */ |
5924 |
); |
5925 |
} |
5926 |
|
5927 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 |
5928 |
// FieldReference and MessageSend |
5929 |
// Can be static warning shown |
5930 |
public void test115() { |
5931 |
Map compilerOptions = getCompilerOptions(); |
5932 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
5933 |
this.runNegativeTest( |
5934 |
new String[] { |
5935 |
"X.java", |
5936 |
"public class X extends B{\n" + |
5937 |
" public static int field1;\n" + |
5938 |
" public static int field2;\n" + |
5939 |
" public void bar(int i) {\n" + |
5940 |
" System.out.println(foo());\n" + |
5941 |
" X.field2 = 2;\n" + |
5942 |
" System.out.println(field1);\n" + |
5943 |
" A a = new A();\n" + |
5944 |
" a.a1();\n" + |
5945 |
" }\n" + |
5946 |
" private static String foo() {\n" + |
5947 |
" return null;\n" + |
5948 |
" }\n" + |
5949 |
"}\n" + |
5950 |
"class A{\n" + |
5951 |
" public void a1() {\n" + |
5952 |
" }\n" + |
5953 |
"}\n" + |
5954 |
"class B{\n" + |
5955 |
" public void b1(){\n" + |
5956 |
" }\n" + |
5957 |
"}" |
5958 |
}, |
5959 |
"----------\n" + |
5960 |
"1. ERROR in X.java (at line 4)\n" + |
5961 |
" public void bar(int i) {\n" + |
5962 |
" ^^^^^^^^^^\n" + |
5963 |
"The method bar(int) from the type X can be declared as static\n" + |
5964 |
"----------\n" + |
5965 |
"2. ERROR in X.java (at line 16)\n" + |
5966 |
" public void a1() {\n" + |
5967 |
" ^^^^\n" + |
5968 |
"The method a1() from the type A can be declared as static\n" + |
5969 |
"----------\n" + |
5970 |
"3. ERROR in X.java (at line 20)\n" + |
5971 |
" public void b1(){\n" + |
5972 |
" ^^^^\n" + |
5973 |
"The method b1() from the type B can be declared as static\n" + |
5974 |
"----------\n", |
5975 |
null /* no extra class libraries */, |
5976 |
true /* flush output directory */, |
5977 |
compilerOptions /* custom options */ |
5978 |
); |
5979 |
} |
5980 |
|
5981 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 |
5982 |
// MessageSend in different ways |
5983 |
public void test116a() { |
5984 |
Map compilerOptions = getCompilerOptions(); |
5985 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
5986 |
compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); |
5987 |
this.runNegativeTest( |
5988 |
new String[] { |
5989 |
"X.java", |
5990 |
"public class X extends B{\n" + |
5991 |
" public static int field1;\n" + |
5992 |
" public X xfield;\n" + |
5993 |
" public void bar1(int i) {\n" + |
5994 |
" baz();\n" + |
5995 |
" }\n" + |
5996 |
" public void bar2(int i) {\n" + |
5997 |
" this.baz();\n" + |
5998 |
" }\n" + |
5999 |
" public void bar3(int i) {\n" + |
6000 |
" this.xfield.baz();\n" + |
6001 |
" }\n" + |
6002 |
" public void bar4(int i) {\n" + |
6003 |
" xfield.baz();\n" + |
6004 |
" }\n" + |
6005 |
" public void bar5(int i) {\n" + |
6006 |
" X x = new X();\n" + |
6007 |
" x.baz();\n" + |
6008 |
" }\n" + |
6009 |
" public void bar6(int i) {\n" + |
6010 |
" A.xA.baz();\n" + |
6011 |
" }\n" + |
6012 |
" public void bar7(int i) {\n" + |
6013 |
" b1();\n" + |
6014 |
" }\n" + |
6015 |
" public void bar8(int i) {\n" + |
6016 |
" this.b1();\n" + |
6017 |
" }\n" + |
6018 |
" public void bar9(int i) {\n" + |
6019 |
" new X().b1();\n" + |
6020 |
" }\n" + |
6021 |
" public void baz() {\n" + |
6022 |
" }\n" + |
6023 |
"}\n" + |
6024 |
"class A{\n" + |
6025 |
" public static X xA;\n" + |
6026 |
"}\n" + |
6027 |
"class B{\n" + |
6028 |
" public void b1(){\n" + |
6029 |
" }\n" + |
6030 |
"}", |
6031 |
}, |
6032 |
"----------\n" + |
6033 |
"1. ERROR in X.java (at line 16)\n" + |
6034 |
" public void bar5(int i) {\n" + |
6035 |
" ^^^^^^^^^^^\n" + |
6036 |
"The method bar5(int) from the type X can be declared as static\n" + |
6037 |
"----------\n" + |
6038 |
"2. ERROR in X.java (at line 20)\n" + |
6039 |
" public void bar6(int i) {\n" + |
6040 |
" ^^^^^^^^^^^\n" + |
6041 |
"The method bar6(int) from the type X can be declared as static\n" + |
6042 |
"----------\n" + |
6043 |
"3. ERROR in X.java (at line 29)\n" + |
6044 |
" public void bar9(int i) {\n" + |
6045 |
" ^^^^^^^^^^^\n" + |
6046 |
"The method bar9(int) from the type X can be declared as static\n" + |
6047 |
"----------\n" + |
6048 |
"4. ERROR in X.java (at line 32)\n" + |
6049 |
" public void baz() {\n" + |
6050 |
" ^^^^^\n" + |
6051 |
"The method baz() from the type X can be declared as static\n" + |
6052 |
"----------\n" + |
6053 |
"5. ERROR in X.java (at line 39)\n" + |
6054 |
" public void b1(){\n" + |
6055 |
" ^^^^\n" + |
6056 |
"The method b1() from the type B can be declared as static\n" + |
6057 |
"----------\n", |
6058 |
null /* no extra class libraries */, |
6059 |
true /* flush output directory */, |
6060 |
compilerOptions /* custom options */ |
6061 |
); |
6062 |
} |
6063 |
|
6064 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 |
6065 |
// MessageSend in different ways, referencing a static method. |
6066 |
public void test116b() { |
6067 |
Map compilerOptions = getCompilerOptions(); |
6068 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
6069 |
compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); |
6070 |
this.runNegativeTest( |
6071 |
new String[] { |
6072 |
"X.java", |
6073 |
"public class X extends B{\n" + |
6074 |
" public static int field1;\n" + |
6075 |
" public static X xfield;\n" + |
6076 |
" public void bar1(int i) {\n" + |
6077 |
" baz();\n" + |
6078 |
" }\n" + |
6079 |
" public void bar2(int i) {\n" + |
6080 |
" this.baz();\n" + |
6081 |
" }\n" + |
6082 |
" public void bar3(int i) {\n" + |
6083 |
" this.xfield.baz();\n" + |
6084 |
" }\n" + |
6085 |
" public void bar4(int i) {\n" + |
6086 |
" xfield.baz();\n" + |
6087 |
" }\n" + |
6088 |
" public void bar5(int i) {\n" + |
6089 |
" X x = new X();\n" + |
6090 |
" x.baz();\n" + |
6091 |
" }\n" + |
6092 |
" public void bar6(int i) {\n" + |
6093 |
" A.xA.baz();\n" + |
6094 |
" }\n" + |
6095 |
" public void bar7(int i) {\n" + |
6096 |
" b1();\n" + |
6097 |
" }\n" + |
6098 |
" public void bar8(int i) {\n" + |
6099 |
" this.b1();\n" + |
6100 |
" }\n" + |
6101 |
" public void bar9(int i) {\n" + |
6102 |
" new X().b1();\n" + |
6103 |
" }\n" + |
6104 |
" public static void baz() {\n" + |
6105 |
" }\n" + |
6106 |
"}\n" + |
6107 |
"class A{\n" + |
6108 |
" public static X xA;\n" + |
6109 |
"}\n" + |
6110 |
"class B{\n" + |
6111 |
" public static void b1(){\n" + |
6112 |
" }\n" + |
6113 |
"}", |
6114 |
}, |
6115 |
"----------\n" + |
6116 |
"1. ERROR in X.java (at line 4)\n" + |
6117 |
" public void bar1(int i) {\n" + |
6118 |
" ^^^^^^^^^^^\n" + |
6119 |
"The method bar1(int) from the type X can be declared as static\n" + |
6120 |
"----------\n" + |
6121 |
"2. ERROR in X.java (at line 13)\n" + |
6122 |
" public void bar4(int i) {\n" + |
6123 |
" ^^^^^^^^^^^\n" + |
6124 |
"The method bar4(int) from the type X can be declared as static\n" + |
6125 |
"----------\n" + |
6126 |
"3. ERROR in X.java (at line 16)\n" + |
6127 |
" public void bar5(int i) {\n" + |
6128 |
" ^^^^^^^^^^^\n" + |
6129 |
"The method bar5(int) from the type X can be declared as static\n" + |
6130 |
"----------\n" + |
6131 |
"4. ERROR in X.java (at line 20)\n" + |
6132 |
" public void bar6(int i) {\n" + |
6133 |
" ^^^^^^^^^^^\n" + |
6134 |
"The method bar6(int) from the type X can be declared as static\n" + |
6135 |
"----------\n" + |
6136 |
"5. ERROR in X.java (at line 23)\n" + |
6137 |
" public void bar7(int i) {\n" + |
6138 |
" ^^^^^^^^^^^\n" + |
6139 |
"The method bar7(int) from the type X can be declared as static\n" + |
6140 |
"----------\n" + |
6141 |
"6. ERROR in X.java (at line 29)\n" + |
6142 |
" public void bar9(int i) {\n" + |
6143 |
" ^^^^^^^^^^^\n" + |
6144 |
"The method bar9(int) from the type X can be declared as static\n" + |
6145 |
"----------\n", |
6146 |
null /* no extra class libraries */, |
6147 |
true /* flush output directory */, |
6148 |
compilerOptions /* custom options */ |
6149 |
); |
6150 |
} |
6151 |
|
6152 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 |
6153 |
// Referring a field in different ways, accessing non-static field. |
6154 |
public void test117a() { |
6155 |
Map compilerOptions = getCompilerOptions(); |
6156 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
6157 |
compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); |
6158 |
this.runNegativeTest( |
6159 |
new String[] { |
6160 |
"X.java", |
6161 |
"public class X extends B{\n" + |
6162 |
" public int field1;\n" + |
6163 |
" public X xfield;\n" + |
6164 |
" public void bar1(int i) {\n" + |
6165 |
" field1 = 1;\n" + |
6166 |
" }\n" + |
6167 |
" public void bar2(int i) {\n" + |
6168 |
" this.field1 = 1;\n" + |
6169 |
" }\n" + |
6170 |
" public void bar3(int i) {\n" + |
6171 |
" System.out.println(field1);\n" + |
6172 |
" }\n" + |
6173 |
" public void bar4(int i) {\n" + |
6174 |
" System.out.println(this.field1);\n" + |
6175 |
" }\n" + |
6176 |
" public void bar5(int i) {\n" + |
6177 |
" X x = new X();\n" + |
6178 |
" x.field1 = 1;\n" + |
6179 |
" }\n" + |
6180 |
" public void bar6(int i) {\n" + |
6181 |
" A.xA.field1 = 1;\n" + |
6182 |
" }\n" + |
6183 |
" public void bar7(int i) {\n" + |
6184 |
" b1 = 1;\n" + |
6185 |
" }\n" + |
6186 |
" public void bar8(int i) {\n" + |
6187 |
" this.b1 = 1;\n" + |
6188 |
" }\n" + |
6189 |
" public void bar9(int i) {\n" + |
6190 |
" new X().b1 = 1;\n" + |
6191 |
" }\n" + |
6192 |
" public void bar10(int i) {\n" + |
6193 |
" this.xfield.field1 = 1;\n" + |
6194 |
" }\n" + |
6195 |
" public void bar11(int i) {\n" + |
6196 |
" System.out.println(this.xfield.field1);\n" + |
6197 |
" }\n" + |
6198 |
" public void bar12(int i) {\n" + |
6199 |
" System.out.println(new X().b1);\n" + |
6200 |
" }\n" + |
6201 |
" public void bar13(int i) {\n" + |
6202 |
" System.out.println(b1);\n" + |
6203 |
" }\n" + |
6204 |
" public void bar14(int i) {\n" + |
6205 |
" System.out.println(this.b1);\n" + |
6206 |
" }\n" + |
6207 |
" public void bar15(int i) {\n" + |
6208 |
" xfield.field1 = 1;\n" + |
6209 |
" }\n" + |
6210 |
" public void bar16(int i) {\n" + |
6211 |
" System.out.println(xfield.field1);\n" + |
6212 |
" }\n" + |
6213 |
" public void baz() {\n" + |
6214 |
" }\n" + |
6215 |
"}\n" + |
6216 |
"class A{\n" + |
6217 |
" public static X xA;\n" + |
6218 |
"}\n" + |
6219 |
"class B{\n" + |
6220 |
" public int b1;\n" + |
6221 |
"}", |
6222 |
}, |
6223 |
"----------\n" + |
6224 |
"1. ERROR in X.java (at line 16)\n" + |
6225 |
" public void bar5(int i) {\n" + |
6226 |
" ^^^^^^^^^^^\n" + |
6227 |
"The method bar5(int) from the type X can be declared as static\n" + |
6228 |
"----------\n" + |
6229 |
"2. ERROR in X.java (at line 20)\n" + |
6230 |
" public void bar6(int i) {\n" + |
6231 |
" ^^^^^^^^^^^\n" + |
6232 |
"The method bar6(int) from the type X can be declared as static\n" + |
6233 |
"----------\n" + |
6234 |
"3. ERROR in X.java (at line 29)\n" + |
6235 |
" public void bar9(int i) {\n" + |
6236 |
" ^^^^^^^^^^^\n" + |
6237 |
"The method bar9(int) from the type X can be declared as static\n" + |
6238 |
"----------\n" + |
6239 |
"4. ERROR in X.java (at line 38)\n" + |
6240 |
" public void bar12(int i) {\n" + |
6241 |
" ^^^^^^^^^^^^\n" + |
6242 |
"The method bar12(int) from the type X can be declared as static\n" + |
6243 |
"----------\n" + |
6244 |
"5. ERROR in X.java (at line 53)\n" + |
6245 |
" public void baz() {\n" + |
6246 |
" ^^^^^\n" + |
6247 |
"The method baz() from the type X can be declared as static\n" + |
6248 |
"----------\n", |
6249 |
null /* no extra class libraries */, |
6250 |
true /* flush output directory */, |
6251 |
compilerOptions /* custom options */ |
6252 |
); |
6253 |
} |
6254 |
|
6255 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 |
6256 |
// Referring a field in different ways, accessing non-static field. |
6257 |
public void test117b() { |
6258 |
Map compilerOptions = getCompilerOptions(); |
6259 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
6260 |
compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); |
6261 |
this.runNegativeTest( |
6262 |
new String[] { |
6263 |
"X.java", |
6264 |
"public class X extends B{\n" + |
6265 |
" public static int field1;\n" + |
6266 |
" public static X xfield;\n" + |
6267 |
" public void bar1(int i) {\n" + |
6268 |
" field1 = 1;\n" + |
6269 |
" }\n" + |
6270 |
" public void bar2(int i) {\n" + |
6271 |
" this.field1 = 1;\n" + |
6272 |
" }\n" + |
6273 |
" public void bar3(int i) {\n" + |
6274 |
" System.out.println(field1);\n" + |
6275 |
" }\n" + |
6276 |
" public void bar4(int i) {\n" + |
6277 |
" System.out.println(this.field1);\n" + |
6278 |
" }\n" + |
6279 |
" public void bar5(int i) {\n" + |
6280 |
" X x = new X();\n" + |
6281 |
" x.field1 = 1;\n" + |
6282 |
" }\n" + |
6283 |
" public void bar6(int i) {\n" + |
6284 |
" A.xA.field1 = 1;\n" + |
6285 |
" }\n" + |
6286 |
" public void bar7(int i) {\n" + |
6287 |
" b1 = 1;\n" + |
6288 |
" }\n" + |
6289 |
" public void bar8(int i) {\n" + |
6290 |
" this.b1 = 1;\n" + |
6291 |
" }\n" + |
6292 |
" public void bar9(int i) {\n" + |
6293 |
" new X().b1 = 1;\n" + |
6294 |
" }\n" + |
6295 |
" public void bar10(int i) {\n" + |
6296 |
" this.xfield.field1 = 1;\n" + |
6297 |
" }\n" + |
6298 |
" public void bar11(int i) {\n" + |
6299 |
" System.out.println(this.xfield.field1);\n" + |
6300 |
" }\n" + |
6301 |
" public void bar12(int i) {\n" + |
6302 |
" System.out.println(new X().b1);\n" + |
6303 |
" }\n" + |
6304 |
" public void bar13(int i) {\n" + |
6305 |
" System.out.println(b1);\n" + |
6306 |
" }\n" + |
6307 |
" public void bar14(int i) {\n" + |
6308 |
" System.out.println(this.b1);\n" + |
6309 |
" }\n" + |
6310 |
" public void bar15(int i) {\n" + |
6311 |
" xfield.field1 = 1;\n" + |
6312 |
" }\n" + |
6313 |
" public void bar16(int i) {\n" + |
6314 |
" System.out.println(xfield.field1);\n" + |
6315 |
" }\n" + |
6316 |
" public void baz() {\n" + |
6317 |
" }\n" + |
6318 |
"}\n" + |
6319 |
"class A{\n" + |
6320 |
" public static X xA;\n" + |
6321 |
"}\n" + |
6322 |
"class B{\n" + |
6323 |
" public static int b1;\n" + |
6324 |
"}", |
6325 |
}, |
6326 |
"----------\n" + |
6327 |
"1. ERROR in X.java (at line 4)\n" + |
6328 |
" public void bar1(int i) {\n" + |
6329 |
" ^^^^^^^^^^^\n" + |
6330 |
"The method bar1(int) from the type X can be declared as static\n" + |
6331 |
"----------\n" + |
6332 |
"2. ERROR in X.java (at line 10)\n" + |
6333 |
" public void bar3(int i) {\n" + |
6334 |
" ^^^^^^^^^^^\n" + |
6335 |
"The method bar3(int) from the type X can be declared as static\n" + |
6336 |
"----------\n" + |
6337 |
"3. ERROR in X.java (at line 16)\n" + |
6338 |
" public void bar5(int i) {\n" + |
6339 |
" ^^^^^^^^^^^\n" + |
6340 |
"The method bar5(int) from the type X can be declared as static\n" + |
6341 |
"----------\n" + |
6342 |
"4. ERROR in X.java (at line 20)\n" + |
6343 |
" public void bar6(int i) {\n" + |
6344 |
" ^^^^^^^^^^^\n" + |
6345 |
"The method bar6(int) from the type X can be declared as static\n" + |
6346 |
"----------\n" + |
6347 |
"5. ERROR in X.java (at line 23)\n" + |
6348 |
" public void bar7(int i) {\n" + |
6349 |
" ^^^^^^^^^^^\n" + |
6350 |
"The method bar7(int) from the type X can be declared as static\n" + |
6351 |
"----------\n" + |
6352 |
"6. ERROR in X.java (at line 29)\n" + |
6353 |
" public void bar9(int i) {\n" + |
6354 |
" ^^^^^^^^^^^\n" + |
6355 |
"The method bar9(int) from the type X can be declared as static\n" + |
6356 |
"----------\n" + |
6357 |
"7. ERROR in X.java (at line 38)\n" + |
6358 |
" public void bar12(int i) {\n" + |
6359 |
" ^^^^^^^^^^^^\n" + |
6360 |
"The method bar12(int) from the type X can be declared as static\n" + |
6361 |
"----------\n" + |
6362 |
"8. ERROR in X.java (at line 41)\n" + |
6363 |
" public void bar13(int i) {\n" + |
6364 |
" ^^^^^^^^^^^^\n" + |
6365 |
"The method bar13(int) from the type X can be declared as static\n" + |
6366 |
"----------\n" + |
6367 |
"9. ERROR in X.java (at line 47)\n" + |
6368 |
" public void bar15(int i) {\n" + |
6369 |
" ^^^^^^^^^^^^\n" + |
6370 |
"The method bar15(int) from the type X can be declared as static\n" + |
6371 |
"----------\n" + |
6372 |
"10. ERROR in X.java (at line 50)\n" + |
6373 |
" public void bar16(int i) {\n" + |
6374 |
" ^^^^^^^^^^^^\n" + |
6375 |
"The method bar16(int) from the type X can be declared as static\n" + |
6376 |
"----------\n" + |
6377 |
"11. ERROR in X.java (at line 53)\n" + |
6378 |
" public void baz() {\n" + |
6379 |
" ^^^^^\n" + |
6380 |
"The method baz() from the type X can be declared as static\n" + |
6381 |
"----------\n", |
6382 |
null /* no extra class libraries */, |
6383 |
true /* flush output directory */, |
6384 |
compilerOptions /* custom options */ |
6385 |
); |
6386 |
} |
6387 |
|
6388 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 |
6389 |
// Verify that can be static is not raised on overriden or static methods. |
6390 |
public void test118() { |
6391 |
Map compilerOptions = getCompilerOptions(); |
6392 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
6393 |
compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); |
6394 |
this.runNegativeTest( |
6395 |
new String[] { |
6396 |
"X.java", |
6397 |
"public class X extends B implements A{\n" + |
6398 |
" public static int field1 = 1;\n" + |
6399 |
" public static void methodX(){\n" + |
6400 |
" }\n" + |
6401 |
" public void methodB() {\n" + // overriding method, dont warn |
6402 |
" System.out.println(X.field1);\n" + |
6403 |
" X.methodX();\n" + |
6404 |
" }\n" + |
6405 |
" public void methodA() {\n" + // implementing method, dont warn |
6406 |
" System.out.println();\n" + |
6407 |
" }\n" + |
6408 |
"}\n" + |
6409 |
"interface A{\n" + |
6410 |
" public abstract void methodA();\n" + |
6411 |
"}\n" + |
6412 |
"class B{\n" + |
6413 |
" public void methodB() {\n" + |
6414 |
" System.out.println();\n" + |
6415 |
" }\n" + |
6416 |
"}", |
6417 |
}, |
6418 |
"----------\n" + |
6419 |
"1. ERROR in X.java (at line 17)\n" + |
6420 |
" public void methodB() {\n" + |
6421 |
" ^^^^^^^^^\n" + |
6422 |
"The method methodB() from the type B can be declared as static\n" + |
6423 |
"----------\n", |
6424 |
null /* no extra class libraries */, |
6425 |
true /* flush output directory */, |
6426 |
compilerOptions /* custom options */ |
6427 |
); |
6428 |
} |
5890 |
} |
6429 |
} |