Lines 12-17
Link Here
|
12 |
|
12 |
|
13 |
import java.io.File; |
13 |
import java.io.File; |
14 |
import java.io.IOException; |
14 |
import java.io.IOException; |
|
|
15 |
import java.util.Hashtable; |
15 |
import java.util.Map; |
16 |
import java.util.Map; |
16 |
|
17 |
|
17 |
import junit.framework.Test; |
18 |
import junit.framework.Test; |
Lines 4090-4094
Link Here
|
4090 |
" ^^^^\n" + |
4091 |
" ^^^^\n" + |
4091 |
"Zork cannot be resolved to a type\n" + |
4092 |
"Zork cannot be resolved to a type\n" + |
4092 |
"----------\n"); |
4093 |
"----------\n"); |
|
|
4094 |
} |
4095 |
// check @SuppressWarning support |
4096 |
public void test130() { |
4097 |
Map customOptions = new Hashtable(); |
4098 |
String[] warnings = CompilerOptions.warningOptionNames(); |
4099 |
for (int i = 0, ceil = warnings.length; i < ceil; i++) { |
4100 |
customOptions.put(warnings[i], CompilerOptions.WARNING); |
4101 |
} |
4102 |
this.runNegativeTest( |
4103 |
new String[] { |
4104 |
"X.java", |
4105 |
"public class X {\n" + |
4106 |
" public static void main(String[] args) {\n" + |
4107 |
" }\n" + |
4108 |
"}\n", |
4109 |
}, |
4110 |
"----------\n" + |
4111 |
"1. WARNING in X.java (at line 1)\n" + |
4112 |
" public class X {\n" + |
4113 |
" ^\n" + |
4114 |
"Javadoc: Missing comment for public declaration\n" + |
4115 |
"----------\n" + |
4116 |
"2. WARNING in X.java (at line 2)\n" + |
4117 |
" public static void main(String[] args) {\n" + |
4118 |
" ^^^^^^^^^^^^^^^^^^^\n" + |
4119 |
"Javadoc: Missing comment for public declaration\n" + |
4120 |
"----------\n" + |
4121 |
"3. WARNING in X.java (at line 2)\n" + |
4122 |
" public static void main(String[] args) {\n" + |
4123 |
" }\n" + |
4124 |
" ^^^^^\n" + |
4125 |
"Empty block should be documented\n" + |
4126 |
"----------\n", |
4127 |
null, true, customOptions); |
4093 |
} |
4128 |
} |
|
|
4129 |
// check @SuppressWarning support |
4130 |
public void test131() { |
4131 |
this.runNegativeTest( |
4132 |
new String[] { |
4133 |
"X.java", |
4134 |
"@SuppressWarnings(\"all\")\n" + |
4135 |
"public class X {\n" + |
4136 |
" public static void main(String[] args) {\n" + |
4137 |
" Zork z;\n" + |
4138 |
" }\n" + |
4139 |
"}\n", |
4140 |
}, |
4141 |
"----------\n" + |
4142 |
"1. ERROR in X.java (at line 4)\n" + |
4143 |
" Zork z;\n" + |
4144 |
" ^^^^\n" + |
4145 |
"Zork cannot be resolved to a type\n" + |
4146 |
"----------\n"); |
4147 |
} |
4148 |
// check @SuppressWarning support |
4149 |
public void test132() { |
4150 |
this.runNegativeTest( |
4151 |
new String[] { |
4152 |
"X.java", |
4153 |
"import java.io.Serializable;\n" + |
4154 |
"import java.util.List;\n" + |
4155 |
"import java.util.Vector;\n" + |
4156 |
"\n" + |
4157 |
"public class X {\n" + |
4158 |
" public static void main(String[] args) {\n" + |
4159 |
" W.deprecated();\n" + |
4160 |
" List<X> l = new Vector();\n" + |
4161 |
" l.size();\n" + |
4162 |
" try {\n" + |
4163 |
" // do nothing\n" + |
4164 |
" } finally {\n" + |
4165 |
" throw new Error();\n" + |
4166 |
" }\n" + |
4167 |
" // Zork z;\n" + |
4168 |
" }\n" + |
4169 |
"\n" + |
4170 |
" class S implements Serializable {\n" + |
4171 |
" String dummy;\n" + |
4172 |
" }\n" + |
4173 |
"}", |
4174 |
"W.java", |
4175 |
"public class W {\n" + |
4176 |
" // @deprecated\n" + |
4177 |
" @Deprecated\n" + |
4178 |
" static void deprecated() {\n" + |
4179 |
" // do nothing\n" + |
4180 |
" }\n" + |
4181 |
"}\n" |
4182 |
}, |
4183 |
"----------\n" + |
4184 |
"1. WARNING in X.java (at line 7)\n" + |
4185 |
" W.deprecated();\n" + |
4186 |
" ^^^^^^^^^^^^^^\n" + |
4187 |
"The method deprecated() from the type W is deprecated\n" + |
4188 |
"----------\n" + |
4189 |
"2. WARNING in X.java (at line 8)\n" + |
4190 |
" List<X> l = new Vector();\n" + |
4191 |
" ^^^^^^^^^^^^\n" + |
4192 |
"Type safety: The expression of type Vector needs unchecked conversion to conform to List<X>\n" + |
4193 |
"----------\n" + |
4194 |
"3. WARNING in X.java (at line 12)\n" + |
4195 |
" } finally {\n" + |
4196 |
" throw new Error();\n" + |
4197 |
" }\n" + |
4198 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
4199 |
"finally block does not complete normally\n" + |
4200 |
"----------\n" + |
4201 |
"4. WARNING in X.java (at line 18)\n" + |
4202 |
" class S implements Serializable {\n" + |
4203 |
" ^\n" + |
4204 |
"The serializable class S does not declare a static final serialVersionUID field of type long\n" + |
4205 |
"----------\n"); |
4206 |
} |
4207 |
// check @SuppressWarning support |
4208 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=89436 |
4209 |
public void test133() { |
4210 |
this.runNegativeTest( |
4211 |
new String[] { |
4212 |
"X.java", |
4213 |
"import java.io.Serializable;\n" + |
4214 |
"import java.util.List;\n" + |
4215 |
"import java.util.Vector;\n" + |
4216 |
"\n" + |
4217 |
"@SuppressWarnings( { \"deprecation\",//$NON-NLS-1$\n" + |
4218 |
" \"finally\",//$NON-NLS-1$\n" + |
4219 |
" \"serial\",//$NON-NLS-1$\n" + |
4220 |
" \"unchecked\"//$NON-NLS-1$\n" + |
4221 |
"})\n" + |
4222 |
"public class X {\n" + |
4223 |
" public static void main(String[] args) {\n" + |
4224 |
" W.deprecated();\n" + |
4225 |
" List<X> l = new Vector();\n" + |
4226 |
" l.size();\n" + |
4227 |
" try {\n" + |
4228 |
" // do nothing\n" + |
4229 |
" } finally {\n" + |
4230 |
" throw new Error();\n" + |
4231 |
" }\n" + |
4232 |
" Zork z;\n" + |
4233 |
" }\n" + |
4234 |
"\n" + |
4235 |
" class S implements Serializable {\n" + |
4236 |
" String dummy;\n" + |
4237 |
" }\n" + |
4238 |
"}", |
4239 |
"W.java", |
4240 |
"public class W {\n" + |
4241 |
" // @deprecated\n" + |
4242 |
" @Deprecated\n" + |
4243 |
" static void deprecated() {\n" + |
4244 |
" // do nothing\n" + |
4245 |
" }\n" + |
4246 |
"}\n" |
4247 |
}, |
4248 |
"----------\n" + |
4249 |
"1. ERROR in X.java (at line 20)\n" + |
4250 |
" Zork z;\n" + |
4251 |
" ^^^^\n" + |
4252 |
"Zork cannot be resolved to a type\n" + |
4253 |
"----------\n"); |
4254 |
} |
4255 |
// check @SuppressWarning support - NOT READY YET: field support |
4256 |
public void test134() { |
4257 |
this.runNegativeTest( |
4258 |
new String[] { |
4259 |
"X.java", |
4260 |
"import java.io.Serializable;\n" + |
4261 |
"import java.util.List;\n" + |
4262 |
"import java.util.Vector;\n" + |
4263 |
"\n" + |
4264 |
"public class X {\n" + |
4265 |
" @SuppressWarnings( { \"deprecation\",//$NON-NLS-1$\n" + |
4266 |
" \"finally\",//$NON-NLS-1$\n" + |
4267 |
" \"unchecked\"//$NON-NLS-1$\n" + |
4268 |
" })\n" + |
4269 |
" public static void main(String[] args) {\n" + |
4270 |
" W.deprecated();\n" + |
4271 |
" List<X> l = new Vector();\n" + |
4272 |
" l.size();\n" + |
4273 |
" try {\n" + |
4274 |
" // do nothing\n" + |
4275 |
" } finally {\n" + |
4276 |
" throw new Error();\n" + |
4277 |
" }\n" + |
4278 |
" Zork z;\n" + |
4279 |
" }\n" + |
4280 |
"\n" + |
4281 |
" // not ready yet: field support\n" + |
4282 |
" @SuppressWarnings(\"unchecked\"//$NON-NLS-1$\n" + |
4283 |
" )\n" + |
4284 |
" List<X> l = new Vector();\n" + |
4285 |
"\n" + |
4286 |
" @SuppressWarnings(\"serial\"//$NON-NLS-1$\n" + |
4287 |
" )\n" + |
4288 |
" class S implements Serializable {\n" + |
4289 |
" String dummy;\n" + |
4290 |
" }\n" + |
4291 |
"}", |
4292 |
"W.java", |
4293 |
"public class W {\n" + |
4294 |
" // @deprecated\n" + |
4295 |
" @Deprecated\n" + |
4296 |
" static void deprecated() {\n" + |
4297 |
" // do nothing\n" + |
4298 |
" }\n" + |
4299 |
"}\n" |
4300 |
}, |
4301 |
"----------\n" + |
4302 |
"1. ERROR in X.java (at line 19)\n" + |
4303 |
" Zork z;\n" + |
4304 |
" ^^^^\n" + |
4305 |
"Zork cannot be resolved to a type\n" + |
4306 |
"----------\n" + |
4307 |
"2. WARNING in X.java (at line 25)\n" + |
4308 |
" List<X> l = new Vector();\n" + |
4309 |
" ^^^^^^^^^^^^\n" + |
4310 |
"Type safety: The expression of type Vector needs unchecked conversion to conform to List<X>\n" + |
4311 |
"----------\n"); |
4312 |
} |
4313 |
// check @SuppressWarning support |
4314 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=69505 -- NOT READY YET: "all" only so far, no file support -- |
4315 |
// hence no import support |
4316 |
// MDL->PMT: should we check that the warnings are emitted when the annotation is not present (aka test132)? if yes, |
4317 |
// a single test or multiple ones? |
4318 |
public void test135() { |
4319 |
this.runNegativeTest( |
4320 |
new String[] { |
4321 |
"X.java", |
4322 |
"import java.util.List;\n" + |
4323 |
"\n" + |
4324 |
"@SuppressWarnings(\"all\"//$NON-NLS-1$\n" + |
4325 |
")\n" + |
4326 |
"public class X {\n" + |
4327 |
" public static void main(String[] args) {\n" + |
4328 |
" if (false) {\n" + |
4329 |
" ;\n" + |
4330 |
" } else {\n" + |
4331 |
" }\n" + |
4332 |
" Zork z;\n" + |
4333 |
" }\n" + |
4334 |
"}" |
4335 |
}, |
4336 |
"----------\n" + |
4337 |
"1. WARNING in X.java (at line 1)\n" + |
4338 |
" import java.util.List;\n" + |
4339 |
" ^^^^^^^^^^^^^^\n" + |
4340 |
"The import java.util.List is never used\n" + |
4341 |
"----------\n" + |
4342 |
"2. ERROR in X.java (at line 11)\n" + |
4343 |
" Zork z;\n" + |
4344 |
" ^^^^\n" + |
4345 |
"Zork cannot be resolved to a type\n" + |
4346 |
"----------\n"); |
4347 |
} |
4348 |
// check @SuppressWarning support |
4349 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=71968 -- NOT READY YET, preparing for it |
4350 |
public void test136() { |
4351 |
this.runNegativeTest( |
4352 |
new String[] { |
4353 |
"X.java", |
4354 |
"public class X {\n" + |
4355 |
" @SuppressWarnings(\"unusedPrivate\"//$NON-NLS-1$\n" + |
4356 |
" )\n" + |
4357 |
" private static final String marker = \"never used mark\"; //$NON-NLS-1$\n" + |
4358 |
"\n" + |
4359 |
" public static void main(String[] args) {\n" + |
4360 |
" Zork z;\n" + |
4361 |
" }\n" + |
4362 |
"}" |
4363 |
}, |
4364 |
"----------\n" + |
4365 |
"1. WARNING in X.java (at line 4)\n" + |
4366 |
" private static final String marker = \"never used mark\"; //$NON-NLS-1$\n" + |
4367 |
" ^^^^^^\n" + |
4368 |
"The private field X.marker is never read locally\n" + |
4369 |
"----------\n" + |
4370 |
"2. ERROR in X.java (at line 7)\n" + |
4371 |
" Zork z;\n" + |
4372 |
" ^^^^\n" + |
4373 |
"Zork cannot be resolved to a type\n" + |
4374 |
"----------\n"); |
4375 |
} |
4094 |
} |
4376 |
} |