View | Details | Raw Unified | Return to bug 127533 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java (-4 / +6 lines)
Lines 217-228 Link Here
217
				"        case 1:\n" + 
217
				"        case 1:\n" + 
218
				"            System.out.println(1); // silent because of SuppressWarnings\n" + 
218
				"            System.out.println(1); // silent because of SuppressWarnings\n" + 
219
				"        }\n" + 
219
				"        }\n" + 
220
				"    }\n" +
220
				"    }\n" + 
221
				"	Zork z;\n" + // complain on Zork (unknown type)
221
				"    void foo() {\n" + 
222
				"}"
222
				"		Zork z;\n" + 
223
				"    }\n" + 
224
				"}\n"
223
			},
225
			},
224
			"----------\n" + 
226
			"----------\n" + 
225
			"1. ERROR in X.java (at line 11)\n" + 
227
			"1. ERROR in X.java (at line 12)\n" + 
226
			"	Zork z;\n" + 
228
			"	Zork z;\n" + 
227
			"	^^^^\n" + 
229
			"	^^^^\n" + 
228
			"Zork cannot be resolved to a type\n" + 
230
			"Zork cannot be resolved to a type\n" + 
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java (-41 / +250 lines)
Lines 4226-4236 Link Here
4226
    			"		} finally {\n" + 
4226
    			"		} finally {\n" + 
4227
    			"			throw new Error();\n" + 
4227
    			"			throw new Error();\n" + 
4228
    			"		}\n" + 
4228
    			"		}\n" + 
4229
    			"		Zork z;\n" + 
4230
    			"	}\n" + 
4229
    			"	}\n" + 
4231
    			"\n" + 
4230
    			"\n" + 
4232
    			"	class S implements Serializable {\n" + 
4231
    			"	class S implements Serializable {\n" + 
4233
    			"		String dummy;\n" + 
4232
    			"		Zork dummy;\n" + 
4234
    			"	}\n" + 
4233
    			"	}\n" + 
4235
    			"}",
4234
    			"}",
4236
    			"W.java",
4235
    			"W.java",
Lines 4243-4250 Link Here
4243
    			"}\n"
4242
    			"}\n"
4244
            },
4243
            },
4245
    		"----------\n" + 
4244
    		"----------\n" + 
4246
    		"1. ERROR in X.java (at line 20)\n" + 
4245
    		"1. ERROR in X.java (at line 23)\n" + 
4247
    		"	Zork z;\n" + 
4246
    		"	Zork dummy;\n" + 
4248
    		"	^^^^\n" + 
4247
    		"	^^^^\n" + 
4249
    		"Zork cannot be resolved to a type\n" + 
4248
    		"Zork cannot be resolved to a type\n" + 
4250
    		"----------\n");
4249
    		"----------\n");
Lines 4272-4278 Link Here
4272
    			"		} finally {\n" + 
4271
    			"		} finally {\n" + 
4273
    			"			throw new Error();\n" + 
4272
    			"			throw new Error();\n" + 
4274
    			"		}\n" + 
4273
    			"		}\n" + 
4275
    			"		Zork z;\n" + 
4276
    			"	}\n" + 
4274
    			"	}\n" + 
4277
    			"\n" + 
4275
    			"\n" + 
4278
    			"	@SuppressWarnings(\"unchecked\"//$NON-NLS-1$\n" + 
4276
    			"	@SuppressWarnings(\"unchecked\"//$NON-NLS-1$\n" + 
Lines 4282-4288 Link Here
4282
    			"	@SuppressWarnings(\"serial\"//$NON-NLS-1$\n" + 
4280
    			"	@SuppressWarnings(\"serial\"//$NON-NLS-1$\n" + 
4283
    			"	)\n" + 
4281
    			"	)\n" + 
4284
    			"	class S implements Serializable {\n" + 
4282
    			"	class S implements Serializable {\n" + 
4285
    			"		String dummy;\n" + 
4283
    			"		Zork dummy;\n" + 
4286
    			"	}\n" + 
4284
    			"	}\n" + 
4287
    			"}",
4285
    			"}",
4288
    			"W.java",
4286
    			"W.java",
Lines 4295-4302 Link Here
4295
    			"}\n"
4293
    			"}\n"
4296
            },
4294
            },
4297
    		"----------\n" + 
4295
    		"----------\n" + 
4298
    		"1. ERROR in X.java (at line 19)\n" + 
4296
    		"1. ERROR in X.java (at line 28)\n" + 
4299
    		"	Zork z;\n" + 
4297
    		"	Zork dummy;\n" + 
4300
    		"	^^^^\n" + 
4298
    		"	^^^^\n" + 
4301
    		"Zork cannot be resolved to a type\n" + 
4299
    		"Zork cannot be resolved to a type\n" + 
4302
    		"----------\n");
4300
    		"----------\n");
Lines 4450-4466 Link Here
4450
    			"	Zork z;\n" + 
4448
    			"	Zork z;\n" + 
4451
    			"}\n"
4449
    			"}\n"
4452
            },
4450
            },
4453
			"----------\n" + 
4451
    		"----------\n" + 
4454
			"1. WARNING in X.java (at line 1)\n" + 
4452
    		"1. WARNING in X.java (at line 1)\n" + 
4455
			"	@SuppressWarnings(\"zork\")//$NON-NLS-1$\n" + 
4453
    		"	@SuppressWarnings(\"zork\")//$NON-NLS-1$\n" + 
4456
			"	                  ^^^^^^\n" + 
4454
    		"	                  ^^^^^^\n" + 
4457
			"Unhandled warning token zork\n" + 
4455
    		"Unsupported @SuppressWarnings(\"zork\")\n" + 
4458
			"----------\n" + 
4456
    		"----------\n" + 
4459
			"2. ERROR in X.java (at line 3)\n" + 
4457
    		"2. ERROR in X.java (at line 3)\n" + 
4460
			"	Zork z;\n" + 
4458
    		"	Zork z;\n" + 
4461
			"	^^^^\n" + 
4459
    		"	^^^^\n" + 
4462
			"Zork cannot be resolved to a type\n" + 
4460
    		"Zork cannot be resolved to a type\n" + 
4463
			"----------\n",
4461
    		"----------\n",
4464
			null, true, customOptions);
4462
			null, true, customOptions);
4465
    }      
4463
    }      
4466
    // check @SuppressWarning support
4464
    // check @SuppressWarning support
Lines 4476-4491 Link Here
4476
    			"	Zork z;\n" + 
4474
    			"	Zork z;\n" + 
4477
    			"}\n"
4475
    			"}\n"
4478
            },
4476
            },
4479
            "----------\n" + 
4477
    		"----------\n" + 
4480
    		"1. WARNING in X.java (at line 1)\n" + 
4478
    		"1. WARNING in X.java (at line 1)\n" + 
4481
    		"	@SuppressWarnings({\"zork\", \"warningToken\"})//$NON-NLS-1$//$NON-NLS-2$\n" + 
4479
    		"	@SuppressWarnings({\"zork\", \"warningToken\"})//$NON-NLS-1$//$NON-NLS-2$\n" + 
4482
    		"	                   ^^^^^^\n" + 
4480
    		"	                   ^^^^^^\n" + 
4483
    		"Unhandled warning token zork\n" + 
4481
    		"Unsupported @SuppressWarnings(\"zork\")\n" + 
4484
    		"----------\n" + 
4482
    		"----------\n" + 
4485
    		"2. WARNING in X.java (at line 1)\n" + 
4483
    		"2. WARNING in X.java (at line 1)\n" + 
4486
    		"	@SuppressWarnings({\"zork\", \"warningToken\"})//$NON-NLS-1$//$NON-NLS-2$\n" + 
4484
    		"	@SuppressWarnings({\"zork\", \"warningToken\"})//$NON-NLS-1$//$NON-NLS-2$\n" + 
4487
    		"	                           ^^^^^^^^^^^^^^\n" + 
4485
    		"	                           ^^^^^^^^^^^^^^\n" + 
4488
    		"Unhandled warning token warningToken\n" + 
4486
    		"Unsupported @SuppressWarnings(\"warningToken\")\n" + 
4489
    		"----------\n" + 
4487
    		"----------\n" + 
4490
    		"3. ERROR in X.java (at line 3)\n" + 
4488
    		"3. ERROR in X.java (at line 3)\n" + 
4491
    		"	Zork z;\n" + 
4489
    		"	Zork z;\n" + 
Lines 4913-4923 Link Here
4913
				"@SuppressWarnings(\"assertIdentifier\")\n" + 
4911
				"@SuppressWarnings(\"assertIdentifier\")\n" + 
4914
				"class X {}",
4912
				"class X {}",
4915
            },
4913
            },
4916
            "----------\n" + 
4914
    		"----------\n" + 
4917
    		"1. WARNING in X.java (at line 1)\n" + 
4915
    		"1. WARNING in X.java (at line 1)\n" + 
4918
    		"	@SuppressWarnings(\"assertIdentifier\")\n" + 
4916
    		"	@SuppressWarnings(\"assertIdentifier\")\n" + 
4919
    		"	                  ^^^^^^^^^^^^^^^^^^\n" + 
4917
    		"	                  ^^^^^^^^^^^^^^^^^^\n" + 
4920
    		"Unhandled warning token assertIdentifier\n" + 
4918
    		"Unsupported @SuppressWarnings(\"assertIdentifier\")\n" + 
4921
    		"----------\n");
4919
    		"----------\n");
4922
    }
4920
    }
4923
    //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009
4921
    //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009
Lines 5680-5686 Link Here
5680
			null, true, customOptions);
5678
			null, true, customOptions);
5681
    }
5679
    }
5682
    
5680
    
5683
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220
5681
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation
5684
    public void test170() {
5682
    public void test170() {
5685
    	Map customOptions = getCompilerOptions();
5683
    	Map customOptions = getCompilerOptions();
5686
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
5684
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
Lines 5695-5701 Link Here
5695
    		"",
5693
    		"",
5696
			null, true, null, customOptions, null);
5694
			null, true, null, customOptions, null);
5697
    }
5695
    }
5698
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220
5696
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation
5699
    public void test171() {
5697
    public void test171() {
5700
    	Map customOptions = getCompilerOptions();
5698
    	Map customOptions = getCompilerOptions();
5701
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
5699
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
Lines 5709-5728 Link Here
5709
    			"	String s2 = \"Hello2\"; \n" +
5707
    			"	String s2 = \"Hello2\"; \n" +
5710
    			"}"
5708
    			"}"
5711
            },
5709
            },
5712
            "----------\n" + 
5710
    		"----------\n" + 
5713
    		"1. WARNING in X.java (at line 1)\n" + 
5711
    		"1. WARNING in X.java (at line 1)\n" + 
5714
    		"	public class X extends Exception {\n" + 
5712
    		"	public class X extends Exception {\n" + 
5715
    		"	             ^\n" + 
5713
    		"	             ^\n" + 
5716
    		"The serializable class X does not declare a static final serialVersionUID field of type long\n" + 
5714
    		"The serializable class X does not declare a static final serialVersionUID field of type long\n" + 
5717
    		"----------\n" + 
5715
    		"----------\n" + 
5718
    		"2. WARNING in X.java (at line 5)\n" + 
5716
    		"2. WARNING in X.java (at line 4)\n" + 
5717
    		"	@SuppressWarnings(\"serial\")\n" + 
5718
    		"	                  ^^^^^^^^\n" + 
5719
    		"Unnecessary @SuppressWarnings(\"serial\")\n" + 
5720
    		"----------\n" + 
5721
    		"3. WARNING in X.java (at line 5)\n" + 
5719
    		"	String s2 = \"Hello2\"; \n" + 
5722
    		"	String s2 = \"Hello2\"; \n" + 
5720
    		"	            ^^^^^^^^\n" + 
5723
    		"	            ^^^^^^^^\n" + 
5721
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5724
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5722
    		"----------\n",
5725
    		"----------\n",
5723
			null, true, customOptions);
5726
			null, true, customOptions);
5724
    }
5727
    }
5725
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220
5728
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation
5726
    public void test172() {
5729
    public void test172() {
5727
    	Map customOptions = getCompilerOptions();
5730
    	Map customOptions = getCompilerOptions();
5728
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
5731
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
Lines 5738-5751 Link Here
5738
    			"}"
5741
    			"}"
5739
            },
5742
            },
5740
    		"----------\n" + 
5743
    		"----------\n" + 
5741
    		"1. WARNING in X.java (at line 6)\n" + 
5744
    		"1. WARNING in X.java (at line 5)\n" + 
5745
    		"	@SuppressWarnings(\"serial\")\n" + 
5746
    		"	                  ^^^^^^^^\n" + 
5747
    		"Unnecessary @SuppressWarnings(\"serial\")\n" + 
5748
    		"----------\n" + 
5749
    		"2. WARNING in X.java (at line 6)\n" + 
5742
    		"	String s2 = \"Hello2\"; \n" + 
5750
    		"	String s2 = \"Hello2\"; \n" + 
5743
    		"	            ^^^^^^^^\n" + 
5751
    		"	            ^^^^^^^^\n" + 
5744
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5752
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5745
    		"----------\n",
5753
    		"----------\n",
5746
			null, true, customOptions);
5754
			null, true, customOptions);
5747
    }
5755
    }
5748
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220
5756
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation
5749
    public void test173() {
5757
    public void test173() {
5750
    	Map customOptions = getCompilerOptions();
5758
    	Map customOptions = getCompilerOptions();
5751
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
5759
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
Lines 5763-5782 Link Here
5763
    			"	String s2 = \"Hello2\"; \n" +
5771
    			"	String s2 = \"Hello2\"; \n" +
5764
    			"}"
5772
    			"}"
5765
            },
5773
            },
5766
            "----------\n" + 
5774
    		"----------\n" + 
5767
    		"1. WARNING in X.java (at line 5)\n" + 
5775
    		"1. WARNING in X.java (at line 5)\n" + 
5768
    		"	public class X extends Exception {\n" + 
5776
    		"	public class X extends Exception {\n" + 
5769
    		"	             ^\n" + 
5777
    		"	             ^\n" + 
5770
    		"The serializable class X does not declare a static final serialVersionUID field of type long\n" + 
5778
    		"The serializable class X does not declare a static final serialVersionUID field of type long\n" + 
5771
    		"----------\n" + 
5779
    		"----------\n" + 
5772
    		"2. WARNING in X.java (at line 9)\n" + 
5780
    		"2. WARNING in X.java (at line 8)\n" + 
5781
    		"	@SuppressWarnings(\"serial\")\n" + 
5782
    		"	                  ^^^^^^^^\n" + 
5783
    		"Unnecessary @SuppressWarnings(\"serial\")\n" + 
5784
    		"----------\n" + 
5785
    		"3. WARNING in X.java (at line 9)\n" + 
5773
    		"	String s2 = \"Hello2\"; \n" + 
5786
    		"	String s2 = \"Hello2\"; \n" + 
5774
    		"	            ^^^^^^^^\n" + 
5787
    		"	            ^^^^^^^^\n" + 
5775
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5788
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5776
    		"----------\n",
5789
    		"----------\n",
5777
			null, true, customOptions);
5790
			null, true, customOptions);
5778
    }
5791
    }
5779
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220
5792
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation
5780
    public void test174() {
5793
    public void test174() {
5781
    	Map customOptions = getCompilerOptions();
5794
    	Map customOptions = getCompilerOptions();
5782
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
5795
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
Lines 5798-5812 Link Here
5798
                "X.java",
5811
                "X.java",
5799
    			source
5812
    			source
5800
            },
5813
            },
5801
            "----------\n" + 
5814
    		"----------\n" + 
5802
    		"1. WARNING in X.java (at line 12)\n" + 
5815
    		"1. WARNING in X.java (at line 11)\n" + 
5816
    		"	@SuppressWarnings(\"serial\")\n" + 
5817
    		"	                  ^^^^^^^^\n" + 
5818
    		"Unnecessary @SuppressWarnings(\"serial\")\n" + 
5819
    		"----------\n" + 
5820
    		"2. WARNING in X.java (at line 12)\n" + 
5803
    		"	String s2 = \"Hello2\"; \n" + 
5821
    		"	String s2 = \"Hello2\"; \n" + 
5804
    		"	            ^^^^^^^^\n" + 
5822
    		"	            ^^^^^^^^\n" + 
5805
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5823
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5806
    		"----------\n",
5824
    		"----------\n",
5807
			null, true, customOptions);
5825
			null, true, customOptions);
5808
    }
5826
    }
5809
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220
5827
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation
5810
    public void test175() {
5828
    public void test175() {
5811
    	Map customOptions = getCompilerOptions();
5829
    	Map customOptions = getCompilerOptions();
5812
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
5830
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
Lines 5827-5846 Link Here
5827
                "X.java",
5845
                "X.java",
5828
    			source
5846
    			source
5829
            },
5847
            },
5830
            "----------\n" + 
5848
    		"----------\n" + 
5831
    		"1. WARNING in X.java (at line 9)\n" + 
5849
    		"1. WARNING in X.java (at line 9)\n" + 
5832
    		"	@Annot2(value=\"nls\") String s = \"value\"; \n" + 
5850
    		"	@Annot2(value=\"nls\") String s = \"value\"; \n" + 
5833
    		"	                                ^^^^^^^\n" + 
5851
    		"	                                ^^^^^^^\n" + 
5834
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5852
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5835
    		"----------\n" + 
5853
    		"----------\n" + 
5836
    		"2. WARNING in X.java (at line 11)\n" + 
5854
    		"2. WARNING in X.java (at line 10)\n" + 
5855
    		"	@SuppressWarnings(\"serial\")\n" + 
5856
    		"	                  ^^^^^^^^\n" + 
5857
    		"Unnecessary @SuppressWarnings(\"serial\")\n" + 
5858
    		"----------\n" + 
5859
    		"3. WARNING in X.java (at line 11)\n" + 
5837
    		"	String s2 = \"Hello2\"; \n" + 
5860
    		"	String s2 = \"Hello2\"; \n" + 
5838
    		"	            ^^^^^^^^\n" + 
5861
    		"	            ^^^^^^^^\n" + 
5839
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5862
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5840
    		"----------\n",
5863
    		"----------\n",
5841
			null, true, customOptions);
5864
			null, true, customOptions);
5842
    }
5865
    }
5843
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220
5866
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation
5844
    public void test176() {
5867
    public void test176() {
5845
    	Map customOptions = getCompilerOptions();
5868
    	Map customOptions = getCompilerOptions();
5846
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
5869
    	customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING);
Lines 5862-5872 Link Here
5862
                "X.java",
5885
                "X.java",
5863
    			source
5886
    			source
5864
            },
5887
            },
5865
            "----------\n" + 
5888
    		"----------\n" + 
5866
    		"1. WARNING in X.java (at line 9)\n" + 
5889
    		"1. WARNING in X.java (at line 9)\n" + 
5867
    		"	@Annot2(value=\"nls\") String s = \"value\"; \n" + 
5890
    		"	@Annot2(value=\"nls\") String s = \"value\"; \n" + 
5868
    		"	                                ^^^^^^^\n" + 
5891
    		"	                                ^^^^^^^\n" + 
5869
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5892
    		"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" + 
5893
    		"----------\n" + 
5894
    		"2. WARNING in X.java (at line 10)\n" + 
5895
    		"	@SuppressWarnings({\"serial\", \"nls\"})\n" + 
5896
    		"	                   ^^^^^^^^\n" + 
5897
    		"Unnecessary @SuppressWarnings(\"serial\")\n" + 
5870
    		"----------\n",
5898
    		"----------\n",
5871
			null, true, customOptions);
5899
			null, true, customOptions);
5872
    }
5900
    }
Lines 7590-7593 Link Here
7590
		"Syntax error, annotation declaration cannot have type parameters\n" + 
7618
		"Syntax error, annotation declaration cannot have type parameters\n" + 
7591
		"----------\n");
7619
		"----------\n");
7592
}
7620
}
7621
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533
7622
public void test228() {
7623
	this.runNegativeTest(
7624
		new String[] {
7625
				"X.java",
7626
				"public class X {\n" + 
7627
				"	@SuppressWarnings(\"unchecked\") //unused\n" + 
7628
				"	void doNoEvil(){\n" + 
7629
				"	}\n" + 
7630
				"	Zork z;\n" + 
7631
				"}\n",
7632
		},
7633
		"----------\n" + 
7634
		"1. WARNING in X.java (at line 2)\n" + 
7635
		"	@SuppressWarnings(\"unchecked\") //unused\n" + 
7636
		"	                  ^^^^^^^^^^^\n" + 
7637
		"Unnecessary @SuppressWarnings(\"unchecked\")\n" + 
7638
		"----------\n" + 
7639
		"2. ERROR in X.java (at line 5)\n" + 
7640
		"	Zork z;\n" + 
7641
		"	^^^^\n" + 
7642
		"Zork cannot be resolved to a type\n" + 
7643
		"----------\n");
7644
}
7645
7646
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533
7647
public void test229() {
7648
	this.runNegativeTest(
7649
		new String[] {
7650
				"X.java",
7651
				"public class X {\n" + 
7652
				"	@SuppressWarnings({\"unchecked\",\"all\"})\n" + 
7653
				"	void doNoEvil(){\n" + 
7654
				"	}\n" + 
7655
				"	Zork z;\n" + 
7656
				"}\n",
7657
		},
7658
		"----------\n" + 
7659
		"1. ERROR in X.java (at line 5)\n" + 
7660
		"	Zork z;\n" + 
7661
		"	^^^^\n" + 
7662
		"Zork cannot be resolved to a type\n" + 
7663
		"----------\n");
7664
}
7665
7666
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation
7667
public void test230() {
7668
	this.runNegativeTest(
7669
		new String[] {
7670
				"X.java",
7671
				"public class X {\n" + 
7672
				"	@SuppressWarnings({\"zork\", \"unused\" })\n" + 
7673
				"	void foo() {}\n" + 
7674
				"}\n" + 
7675
				"@SuppressWarnings({\"all\"})\n" + 
7676
				"class X2 {\n" + 
7677
				"	@SuppressWarnings({\"zork\", \"unused\" })\n" + 
7678
				"	Zork foo() {}\n" + 
7679
				"}\n",
7680
		},
7681
		"----------\n" + 
7682
		"1. WARNING in X.java (at line 2)\n" + 
7683
		"	@SuppressWarnings({\"zork\", \"unused\" })\n" + 
7684
		"	                   ^^^^^^\n" + 
7685
		"Unsupported @SuppressWarnings(\"zork\")\n" + 
7686
		"----------\n" + 
7687
		"2. WARNING in X.java (at line 2)\n" + 
7688
		"	@SuppressWarnings({\"zork\", \"unused\" })\n" + 
7689
		"	                           ^^^^^^^^\n" + 
7690
		"Unnecessary @SuppressWarnings(\"unused\")\n" + 
7691
		"----------\n" + 
7692
		"3. ERROR in X.java (at line 8)\n" + 
7693
		"	Zork foo() {}\n" + 
7694
		"	^^^^\n" + 
7695
		"Zork cannot be resolved to a type\n" + 
7696
		"----------\n");
7697
}
7698
7699
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation
7700
public void test231() {
7701
	this.runNegativeTest(
7702
		new String[] {
7703
				"X.java",
7704
				"public class X {\n" + 
7705
				"	@SuppressWarnings({\"zork\", \"unused\",\"all\"})\n" + 
7706
				"	void foo() {}\n" + 
7707
				"}\n" + 
7708
				"\n" + 
7709
				"@SuppressWarnings({\"all\"})\n" + 
7710
				"class X2 {\n" + 
7711
				"	@SuppressWarnings(\"unused\")\n" + 
7712
				"	void foo() {}\n" + 
7713
				"	Zork z;\n" + 
7714
				"}\n",
7715
		},
7716
		"----------\n" + 
7717
		"1. ERROR in X.java (at line 10)\n" + 
7718
		"	Zork z;\n" + 
7719
		"	^^^^\n" + 
7720
		"Zork cannot be resolved to a type\n" + 
7721
		"----------\n");
7722
}
7723
7724
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation
7725
public void test232() {
7726
	this.runNegativeTest(
7727
		new String[] {
7728
				"X.java",
7729
				"public class X {\n" + 
7730
				"    @SuppressWarnings({\"finally\",\"finally\"})\n" + 
7731
				"    public int test(int p) {\n" + 
7732
				"    	try {\n" +
7733
				"		return 1;\n" +
7734
				"	} finally {\n" +
7735
				"		return 2;\n" +
7736
				"	}\n" + 
7737
				"    }\n" + 
7738
				"}\n" +
7739
				"class Y extends Zork{}",
7740
		},
7741
		"----------\n" + 
7742
		"1. WARNING in X.java (at line 2)\n" + 
7743
		"	@SuppressWarnings({\"finally\",\"finally\"})\n" + 
7744
		"	                             ^^^^^^^^^\n" + 
7745
		"Unnecessary @SuppressWarnings(\"finally\")\n" + 
7746
		"----------\n" + 
7747
		"2. ERROR in X.java (at line 11)\n" + 
7748
		"	class Y extends Zork{}\n" + 
7749
		"	                ^^^^\n" + 
7750
		"Zork cannot be resolved to a type\n" + 
7751
		"----------\n");
7752
}
7753
7754
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation
7755
public void test233() {
7756
	this.runNegativeTest(
7757
		new String[] {
7758
				"X.java",
7759
				"public class X {\n" + 
7760
				"    @SuppressWarnings({\"finally\",\"finally\"})\n" + 
7761
				"    public int test(int p) {\n" + 
7762
				"    	try {\n" +
7763
				"		return Zork;\n" +
7764
				"	} finally {\n" +
7765
				"		return 2;\n" +
7766
				"	}\n" + 
7767
				"    }\n" + 
7768
				"}\n",
7769
		},
7770
		"----------\n" + 
7771
		"1. WARNING in X.java (at line 2)\n" + 
7772
		"	@SuppressWarnings({\"finally\",\"finally\"})\n" + 
7773
		"	                             ^^^^^^^^^\n" + 
7774
		"Unnecessary @SuppressWarnings(\"finally\")\n" + 
7775
		"----------\n" + 
7776
		"2. ERROR in X.java (at line 5)\n" + 
7777
		"	return Zork;\n" + 
7778
		"	       ^^^^\n" + 
7779
		"Zork cannot be resolved\n" + 
7780
		"----------\n");
7781
}
7782
7783
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation
7784
public void test234() {
7785
	this.runNegativeTest(
7786
		new String[] {
7787
				"X.java",
7788
				"public class X {\n" + 
7789
				"    @SuppressWarnings(\"finally\")\n" + // unused but no complaint since an error is nested (can't tell for sure)
7790
				"    public int test(int p) {\n" + 
7791
				"		return Zork;\n" +
7792
				"    }\n" + 
7793
				"}\n",
7794
		},
7795
		"----------\n" + 
7796
		"1. ERROR in X.java (at line 4)\n" + 
7797
		"	return Zork;\n" + 
7798
		"	       ^^^^\n" + 
7799
		"Zork cannot be resolved\n" + 
7800
		"----------\n");
7801
}
7593
}
7802
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (-11 / +9 lines)
Lines 19821-19827 Link Here
19821
                "X.java",
19821
                "X.java",
19822
				"public class X {\n" + 
19822
				"public class X {\n" + 
19823
				"	void foo() {\n" + 
19823
				"	void foo() {\n" + 
19824
				"		@SuppressWarnings(\"unused\")\n" + 
19825
				"		Outer.Inner inner = new Sub().get();\n" + 
19824
				"		Outer.Inner inner = new Sub().get();\n" + 
19826
				"	}\n" + 
19825
				"	}\n" + 
19827
				"	Zork z;\n" + 
19826
				"	Zork z;\n" + 
Lines 19835-19856 Link Here
19835
				"}\n",
19834
				"}\n",
19836
	        },
19835
	        },
19837
	        "----------\n" + 
19836
	        "----------\n" + 
19838
			"1. WARNING in X.java (at line 4)\n" + 
19837
			"1. WARNING in X.java (at line 3)\n" + 
19839
			"	Outer.Inner inner = new Sub().get();\n" + 
19838
			"	Outer.Inner inner = new Sub().get();\n" + 
19840
			"	^^^^^^^^^^^\n" + 
19839
			"	^^^^^^^^^^^\n" + 
19841
			"Outer.Inner is a raw type. References to generic type Outer<T>.Inner<U> should be parameterized\n" + 
19840
			"Outer.Inner is a raw type. References to generic type Outer<T>.Inner<U> should be parameterized\n" + 
19842
			"----------\n" + 
19841
			"----------\n" + 
19843
			"2. ERROR in X.java (at line 6)\n" + 
19842
			"2. ERROR in X.java (at line 5)\n" + 
19844
			"	Zork z;\n" + 
19843
			"	Zork z;\n" + 
19845
			"	^^^^\n" + 
19844
			"	^^^^\n" + 
19846
			"Zork cannot be resolved to a type\n" + 
19845
			"Zork cannot be resolved to a type\n" + 
19847
			"----------\n" + 
19846
			"----------\n" + 
19848
			"3. WARNING in X.java (at line 12)\n" + 
19847
			"3. WARNING in X.java (at line 11)\n" + 
19849
			"	class Sub extends Outer {\n" + 
19848
			"	class Sub extends Outer {\n" + 
19850
			"	                  ^^^^^\n" + 
19849
			"	                  ^^^^^\n" + 
19851
			"Outer is a raw type. References to generic type Outer<T> should be parameterized\n" + 
19850
			"Outer is a raw type. References to generic type Outer<T> should be parameterized\n" + 
19852
			"----------\n" + 
19851
			"----------\n" + 
19853
			"4. WARNING in X.java (at line 13)\n" + 
19852
			"4. WARNING in X.java (at line 12)\n" + 
19854
			"	Inner get() { return null; }\n" + 
19853
			"	Inner get() { return null; }\n" + 
19855
			"	^^^^^\n" + 
19854
			"	^^^^^\n" + 
19856
			"Outer.Inner is a raw type. References to generic type Outer<T>.Inner<U> should be parameterized\n" + 
19855
			"Outer.Inner is a raw type. References to generic type Outer<T>.Inner<U> should be parameterized\n" + 
Lines 19863-19869 Link Here
19863
                "X.java",
19862
                "X.java",
19864
				"public class X {\n" + 
19863
				"public class X {\n" + 
19865
				"	void foo() {\n" + 
19864
				"	void foo() {\n" + 
19866
				"		@SuppressWarnings(\"unused\")\n" + 
19867
				"		Outer<String>.Inner inner = new Sub().get();\n" + 
19865
				"		Outer<String>.Inner inner = new Sub().get();\n" + 
19868
				"	}\n" + 
19866
				"	}\n" + 
19869
				"	Zork z;\n" + 
19867
				"	Zork z;\n" + 
Lines 19877-19898 Link Here
19877
				"}\n",
19875
				"}\n",
19878
	        },
19876
	        },
19879
	        "----------\n" + 
19877
	        "----------\n" + 
19880
			"1. WARNING in X.java (at line 4)\n" + 
19878
			"1. WARNING in X.java (at line 3)\n" + 
19881
			"	Outer<String>.Inner inner = new Sub().get();\n" + 
19879
			"	Outer<String>.Inner inner = new Sub().get();\n" + 
19882
			"	                            ^^^^^^^^^^^^^^^\n" + 
19880
			"	                            ^^^^^^^^^^^^^^^\n" + 
19883
			"Type safety: The expression of type Outer.Inner needs unchecked conversion to conform to Outer<String>.Inner\n" + 
19881
			"Type safety: The expression of type Outer.Inner needs unchecked conversion to conform to Outer<String>.Inner\n" + 
19884
			"----------\n" + 
19882
			"----------\n" + 
19885
			"2. ERROR in X.java (at line 6)\n" + 
19883
			"2. ERROR in X.java (at line 5)\n" + 
19886
			"	Zork z;\n" + 
19884
			"	Zork z;\n" + 
19887
			"	^^^^\n" + 
19885
			"	^^^^\n" + 
19888
			"Zork cannot be resolved to a type\n" + 
19886
			"Zork cannot be resolved to a type\n" + 
19889
			"----------\n" + 
19887
			"----------\n" + 
19890
			"3. WARNING in X.java (at line 12)\n" + 
19888
			"3. WARNING in X.java (at line 11)\n" + 
19891
			"	class Sub extends Outer {\n" + 
19889
			"	class Sub extends Outer {\n" + 
19892
			"	                  ^^^^^\n" + 
19890
			"	                  ^^^^^\n" + 
19893
			"Outer is a raw type. References to generic type Outer<T> should be parameterized\n" + 
19891
			"Outer is a raw type. References to generic type Outer<T> should be parameterized\n" + 
19894
			"----------\n" + 
19892
			"----------\n" + 
19895
			"4. WARNING in X.java (at line 13)\n" + 
19893
			"4. WARNING in X.java (at line 12)\n" + 
19896
			"	Inner get() { return null; }\n" + 
19894
			"	Inner get() { return null; }\n" + 
19897
			"	^^^^^\n" + 
19895
			"	^^^^^\n" + 
19898
			"Outer.Inner is a raw type. References to generic type Outer<T>.Inner should be parameterized\n" + 
19896
			"Outer.Inner is a raw type. References to generic type Outer<T>.Inner should be parameterized\n" + 
Lines 23141-23147 Link Here
23141
			"			super(0, null, null, null);\n" + 
23139
			"			super(0, null, null, null);\n" + 
23142
			"		}\n" + 
23140
			"		}\n" + 
23143
			"\n" + 
23141
			"\n" + 
23144
			"		void ab(@SuppressWarnings(\"unused\") Entry<K2, V2> e) {\n" + 
23142
			"		void ab(Entry<K2, V2> e) {\n" + 
23145
			"		}\n" + 
23143
			"		}\n" + 
23146
			"\n" + 
23144
			"\n" + 
23147
			"		@Override void recordAccess(Super<K2, V2> m) {\n" + 
23145
			"		@Override void recordAccess(Super<K2, V2> m) {\n" + 
(-)src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java (-2 / +7 lines)
Lines 1918-1929 Link Here
1918
				"	^^^^\n" + 
1918
				"	^^^^\n" + 
1919
				"Zork cannot be resolved to a type\n" + 
1919
				"Zork cannot be resolved to a type\n" + 
1920
				"----------\n" + 
1920
				"----------\n" + 
1921
				"2. WARNING in X.java (at line 19)\n" + 
1921
				"2. WARNING in X.java (at line 17)\n" + 
1922
				"	@SuppressWarnings(\"boxing\")\n" + 
1923
				"	                  ^^^^^^^^\n" + 
1924
				"Unnecessary @SuppressWarnings(\"boxing\")\n" + 
1925
				"----------\n" + 
1926
				"3. WARNING in X.java (at line 19)\n" + 
1922
				"	varargs(i);\n" + 
1927
				"	varargs(i);\n" + 
1923
				"	^^^^^^^^^^\n" + 
1928
				"	^^^^^^^^^^\n" + 
1924
				"The argument of type Integer[] should explicitly be cast to Object[] for the invocation of the varargs method varargs(Object...) from type X. It could alternatively be cast to Object for a varargs invocation\n" + 
1929
				"The argument of type Integer[] should explicitly be cast to Object[] for the invocation of the varargs method varargs(Object...) from type X. It could alternatively be cast to Object for a varargs invocation\n" + 
1925
				"----------\n" + 
1930
				"----------\n" + 
1926
				"3. WARNING in X.java (at line 22)\n" + 
1931
				"4. WARNING in X.java (at line 22)\n" + 
1927
				"	varargs(i.clone());\n" + 
1932
				"	varargs(i.clone());\n" + 
1928
				"	^^^^^^^^^^^^^^^^^^\n" + 
1933
				"	^^^^^^^^^^^^^^^^^^\n" + 
1929
				"The argument of type Integer[] should explicitly be cast to Object[] for the invocation of the varargs method varargs(Object...) from type X. It could alternatively be cast to Object for a varargs invocation\n" + 
1934
				"The argument of type Integer[] should explicitly be cast to Object[] for the invocation of the varargs method varargs(Object...) from type X. It could alternatively be cast to Object for a varargs invocation\n" + 
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (-9 / +14 lines)
Lines 1153-1159 Link Here
1153
        "      unusedTypeArgs     + unused type arguments for method\n" +
1153
        "      unusedTypeArgs     + unused type arguments for method\n" +
1154
        "      uselessTypeCheck     unnecessary cast/instanceof operation\n" +
1154
        "      uselessTypeCheck     unnecessary cast/instanceof operation\n" +
1155
        "      varargsCast        + varargs argument need explicit cast\n" +
1155
        "      varargsCast        + varargs argument need explicit cast\n" +
1156
        "      warningToken       + unhandled warning token in @SuppressWarnings\n" +
1156
        "      warningToken       + unsupported or unnecessary @SuppressWarnings\n" +
1157
        " \n" +
1157
        " \n" +
1158
        " Advanced options:\n" +
1158
        " Advanced options:\n" +
1159
        "    -? -help           print the help message\n" +
1159
        "    -? -help           print the help message\n" +
Lines 1296-1302 Link Here
1296
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete\" value=\"disabled\"/>\n" + 
1296
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete\" value=\"disabled\"/>\n" + 
1297
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedPrivateMember\" value=\"warning\"/>\n" + 
1297
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedPrivateMember\" value=\"warning\"/>\n" + 
1298
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedTypeArgumentsForMethodInvocation\" value=\"warning\"/>\n" + 
1298
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedTypeArgumentsForMethodInvocation\" value=\"warning\"/>\n" + 
1299
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast\" value=\"warning\"/>\n" + 
1299
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.unusedWarningToken\" value=\"warning\"/>\n" +			"		<option key=\"org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast\" value=\"warning\"/>\n" + 
1300
			"		<option key=\"org.eclipse.jdt.core.compiler.processAnnotations\" value=\"disabled\"/>\n" + 
1300
			"		<option key=\"org.eclipse.jdt.core.compiler.processAnnotations\" value=\"disabled\"/>\n" + 
1301
			"		<option key=\"org.eclipse.jdt.core.compiler.source\" value=\"1.5\"/>\n" + 
1301
			"		<option key=\"org.eclipse.jdt.core.compiler.source\" value=\"1.5\"/>\n" + 
1302
			"		<option key=\"org.eclipse.jdt.core.compiler.taskCaseSensitive\" value=\"enabled\"/>\n" + 
1302
			"		<option key=\"org.eclipse.jdt.core.compiler.taskCaseSensitive\" value=\"enabled\"/>\n" + 
Lines 2950-2962 Link Here
2950
        + " -warn:+discouraged,forbidden,deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal"
2950
        + " -warn:+discouraged,forbidden,deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal"
2951
        + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"",
2951
        + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"",
2952
        "",
2952
        "",
2953
        "----------\n" +
2953
        "----------\n" + 
2954
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/Y.java (at line 4)\n" +
2954
        "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/Y.java (at line 2)\n" + 
2955
		"	p.X x;\n" +
2955
        "	@SuppressWarnings(\"deprecation\")\n" + 
2956
		"	^^^\n" +
2956
        "	                  ^^^^^^^^^^^^^\n" + 
2957
		"Discouraged access: The type X is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---\n" +
2957
        "Unnecessary @SuppressWarnings(\"deprecation\")\n" + 
2958
		"----------\n" +
2958
        "----------\n" + 
2959
		"1 problem (1 warning)",
2959
        "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/Y.java (at line 4)\n" + 
2960
        "	p.X x;\n" + 
2961
        "	^^^\n" + 
2962
        "Discouraged access: The type X is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---\n" + 
2963
        "----------\n" + 
2964
        "2 problems (2 warnings)",
2960
        false);
2965
        false);
2961
}
2966
}
2962
2967
(-)buildnotes_jdt-core.html (+17 lines)
Lines 47-52 Link Here
47
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_821">cvs</a>).
47
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_821">cvs</a>).
48
<h2>What's new in this drop</h2>
48
<h2>What's new in this drop</h2>
49
<ul>
49
<ul>
50
<li>Added new compiler optional warning for diagnosing unnecessary @SuppressWarnings annotation. This is mostly helpful
51
to get rid of <code>@SupressWarnings(...)</code> annotations which were necessary a while ago, but are no longer useful.
52
Note that <code>@SuppressWarnings("all")</code> is still silencing the warning for unnecessary <code>@SuppressWarnings</code>,
53
as it is the master switch to silence ALL warnings.
54
Also added option: <code>JavaCore.COMPILER_PB_UNUSED_WARNING_TOKEN</code> and problem ID
55
<code>IProblem.UnusedWarningToken</code>.
56
<pre>
57
* COMPILER / Reporting Unnecessary @SuppressWarnings
58
*    When enabled, the compiler will issue an error or a warning when encountering @SuppressWarnings annotation 
59
*    for which no corresponding warning got detected in the code. This diagnostic is provided to help developers to get
60
*    rid of transient @SuppressWarnings no longer needed. Note that <code>@SuppressWarnings("all")</code> is still 
61
*    silencing the warning for unnecessary <code>@SuppressWarnings</code>, as it is the master switch to silence ALL warnings.
62
*     - option id:         "org.eclipse.jdt.core.compiler.problem.unusedWarningToken"
63
*     - possible values:   { "error", "warning", "ignore" }
64
*     - default:           "warning"
65
</pre>
66
</li>
50
<li>Added the following APIs to support annotation in the Java model (see <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=79112">bug 79112</a>
67
<li>Added the following APIs to support annotation in the Java model (see <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=79112">bug 79112</a>
51
     for more details):
68
     for more details):
52
     <ul>
69
     <ul>
(-)dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java (+3 lines)
Lines 860-865 Link Here
860
860
861
				// code generation
861
				// code generation
862
				if (generateCode) unit.generateCode();
862
				if (generateCode) unit.generateCode();
863
				
864
				// finalize problems (suppressWarnings)
865
				unit.finalizeProblems();				
863
			}
866
			}
864
			if (this.unitsToProcess != null) this.unitsToProcess[0] = null; // release reference to processed unit declaration
867
			if (this.unitsToProcess != null) this.unitsToProcess[0] = null; // release reference to processed unit declaration
865
			this.requestor.acceptResult(unit.compilationResult.tagAsAccepted());
868
			this.requestor.acceptResult(unit.compilationResult.tagAsAccepted());
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+12 lines)
Lines 219-224 Link Here
219
			
219
			
220
		case IProblem.UnhandledWarningToken :
220
		case IProblem.UnhandledWarningToken :
221
			return CompilerOptions.UnhandledWarningToken;
221
			return CompilerOptions.UnhandledWarningToken;
222
223
		case IProblem.UnusedWarningToken :
224
			return CompilerOptions.UnusedWarningToken;
222
			
225
			
223
		case IProblem.UnusedLabel :
226
		case IProblem.UnusedLabel :
224
			return CompilerOptions.UnusedLabel;
227
			return CompilerOptions.UnusedLabel;
Lines 6299-6304 Link Here
6299
		location.sourceStart,
6302
		location.sourceStart,
6300
		location.sourceEnd);
6303
		location.sourceEnd);
6301
}
6304
}
6305
public void unusedWarningToken(Expression token) {
6306
	String[] arguments = new String[] { token.constant.stringValue() };
6307
	this.handle(
6308
		IProblem.UnusedWarningToken,
6309
		arguments,
6310
		arguments,
6311
		token.sourceStart,
6312
		token.sourceEnd);
6313
}
6302
public void unhandledWarningToken(Expression token) {
6314
public void unhandledWarningToken(Expression token) {
6303
	String[] arguments = new String[] { token.constant.stringValue() };
6315
	String[] arguments = new String[] { token.constant.stringValue() };
6304
	this.handle(
6316
	this.handle(
(-)compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (-1 / +2 lines)
Lines 542-551 Link Here
542
628 = The deprecated field {0}.{1} should be annotated with @Deprecated
542
628 = The deprecated field {0}.{1} should be annotated with @Deprecated
543
629 = The deprecated method {0}({1}) of type {2} should be annotated with @Deprecated
543
629 = The deprecated method {0}({1}) of type {2} should be annotated with @Deprecated
544
630 = The deprecated type {0} should be annotated with @Deprecated
544
630 = The deprecated type {0} should be annotated with @Deprecated
545
631 = Unhandled warning token {0}
545
631 = Unsupported @SuppressWarnings("{0}")
546
632 = The value for annotation attribute {0}.{1} must be an array initializer
546
632 = The value for annotation attribute {0}.{1} must be an array initializer
547
633 = The value for annotation attribute {0}.{1} must be an enum constant expression
547
633 = The value for annotation attribute {0}.{1} must be an enum constant expression
548
634 = The method {0}({1}) of type {2} must override or implement a supertype method
548
634 = The method {0}({1}) of type {2} must override or implement a supertype method
549
635 = Unnecessary @SuppressWarnings("{0}")
549
550
550
### CORRUPTED BINARIES
551
### CORRUPTED BINARIES
551
700 = The class file {0} contains a signature ''{1}'' ill-formed at position {2}
552
700 = The class file {0} contains a signature ''{1}'' ill-formed at position {2}
(-)model/org/eclipse/jdt/core/JavaCore.java (+15 lines)
Lines 730-735 Link Here
730
	/**
730
	/**
731
	 * Possible  configurable option ID.
731
	 * Possible  configurable option ID.
732
	 * @see #getDefaultOptions()
732
	 * @see #getDefaultOptions()
733
	 * @since 3.4
734
	 */
735
	public static final String COMPILER_PB_UNUSED_WARNING_TOKEN = PLUGIN_ID + ".compiler.problem.unusedWarningToken"; //$NON-NLS-1$
736
	/**
737
	 * Possible  configurable option ID.
738
	 * @see #getDefaultOptions()
733
	 * @since 3.2
739
	 * @since 3.2
734
	 */
740
	 */
735
	public static final String COMPILER_PB_NULL_REFERENCE = PLUGIN_ID + ".compiler.problem.nullReference"; //$NON-NLS-1$
741
	public static final String COMPILER_PB_NULL_REFERENCE = PLUGIN_ID + ".compiler.problem.nullReference"; //$NON-NLS-1$
Lines 2558-2563 Link Here
2558
	 *     - possible values:   { "error", "warning", "ignore" }
2564
	 *     - possible values:   { "error", "warning", "ignore" }
2559
	 *     - default:           "warning"
2565
	 *     - default:           "warning"
2560
	 *
2566
	 *
2567
	 * COMPILER / Reporting Unnecessary @SuppressWarnings
2568
	 *    When enabled, the compiler will issue an error or a warning when encountering @SuppressWarnings annotation 
2569
	 *    for which no corresponding warning got detected in the code. This diagnostic is provided to help developers to get
2570
	 *    rid of transient @SuppressWarnings no longer needed. Note that <code>@SuppressWarnings("all")</code> is still 
2571
	 *    silencing the warning for unnecessary <code>@SuppressWarnings</code>, as it is the master switch to silence ALL warnings.
2572
	 *     - option id:         "org.eclipse.jdt.core.compiler.problem.unusedWarningToken"
2573
	 *     - possible values:   { "error", "warning", "ignore" }
2574
	 *     - default:           "warning"
2575
	 *
2561
	 * COMPILER / Reporting Unreferenced Label
2576
	 * COMPILER / Reporting Unreferenced Label
2562
	 *    When enabled, the compiler will issue an error or a warning when encountering a labeled statement which label
2577
	 *    When enabled, the compiler will issue an error or a warning when encountering a labeled statement which label
2563
	 *    is never explicitly referenced. A label is considered to be referenced if its name explicitly appears behind a break
2578
	 *    is never explicitly referenced. A label is considered to be referenced if its name explicitly appears behind a break
(-)compiler/org/eclipse/jdt/internal/compiler/Compiler.java (+6 lines)
Lines 632-637 Link Here
632
		if (options.produceReferenceInfo && unit.scope != null)
632
		if (options.produceReferenceInfo && unit.scope != null)
633
			unit.scope.storeDependencyInfo();
633
			unit.scope.storeDependencyInfo();
634
634
635
		// finalize problems (suppressWarnings)
636
		unit.finalizeProblems();
637
		
635
		// refresh the total number of units known at this stage
638
		// refresh the total number of units known at this stage
636
		unit.compilationResult.totalUnitsKnown = totalUnits;
639
		unit.compilationResult.totalUnitsKnown = totalUnits;
637
640
Lines 732-737 Link Here
732
		
735
		
733
				// code generation
736
				// code generation
734
				if (generateCode) unit.generateCode();
737
				if (generateCode) unit.generateCode();
738
				
739
				// finalize problems (suppressWarnings)
740
				unit.finalizeProblems();
735
			}
741
			}
736
			if (unitsToProcess != null) unitsToProcess[0] = null; // release reference to processed unit declaration
742
			if (unitsToProcess != null) unitsToProcess[0] = null; // release reference to processed unit declaration
737
			requestor.acceptResult(unit.compilationResult.tagAsAccepted());
743
			requestor.acceptResult(unit.compilationResult.tagAsAccepted());
(-)compiler/org/eclipse/jdt/internal/compiler/CompilationResult.java (-62 / +2 lines)
Lines 46-52 Link Here
46
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
46
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
47
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
47
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
48
import org.eclipse.jdt.internal.compiler.parser.RecoveryScannerData;
48
import org.eclipse.jdt.internal.compiler.parser.RecoveryScannerData;
49
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
50
import org.eclipse.jdt.internal.compiler.util.Util;
49
import org.eclipse.jdt.internal.compiler.util.Util;
51
50
52
public class CompilationResult {
51
public class CompilationResult {
Lines 56-63 Link Here
56
	public int problemCount;
55
	public int problemCount;
57
	public int taskCount;
56
	public int taskCount;
58
	public ICompilationUnit compilationUnit;
57
	public ICompilationUnit compilationUnit;
59
	private Map problemsMap;
58
	public Map problemsMap;
60
	private Set firstErrors;
59
	public Set firstErrors;
61
	private int maxProblemPerUnit;
60
	private int maxProblemPerUnit;
62
	public char[][][] qualifiedReferences;
61
	public char[][][] qualifiedReferences;
63
	public char[][] simpleNameReferences;
62
	public char[][] simpleNameReferences;
Lines 70-78 Link Here
70
	public char[] fileName;
69
	public char[] fileName;
71
	public boolean hasInconsistentToplevelHierarchies = false; // record the fact some toplevel types have inconsistent hierarchies
70
	public boolean hasInconsistentToplevelHierarchies = false; // record the fact some toplevel types have inconsistent hierarchies
72
	public boolean hasSyntaxError = false;
71
	public boolean hasSyntaxError = false;
73
	long[] suppressWarningIrritants;  // irritant for suppressed warnings
74
	long[] suppressWarningScopePositions; // (start << 32) + end 
75
	int suppressWarningsCount;
76
	public char[][] packageName;
72
	public char[][] packageName;
77
	
73
	
78
private static final int[] EMPTY_LINE_ENDS = Util.EMPTY_INT_ARRAY;
74
private static final int[] EMPTY_LINE_ENDS = Util.EMPTY_INT_ARRAY;
Lines 137-184 Link Here
137
	return priority;
133
	return priority;
138
}
134
}
139
135
140
public void discardSuppressedWarnings() {
141
	if (this.suppressWarningsCount == 0) return;
142
	int removed = 0;
143
	nextProblem: for (int i = 0, length = this.problemCount; i < length; i++) {
144
		CategorizedProblem problem = this.problems[i];
145
		int problemID = problem.getID();
146
		if (!problem.isWarning()) {
147
			continue nextProblem;
148
		}
149
		int start = problem.getSourceStart();
150
		int end = problem.getSourceEnd();
151
		nextSuppress: for (int j = 0, max = this.suppressWarningsCount; j < max; j++) {
152
			long position = this.suppressWarningScopePositions[j];
153
			int startSuppress = (int) (position >>> 32);
154
			int endSuppress = (int) position;
155
			if (start < startSuppress) continue nextSuppress;
156
			if (end > endSuppress) continue nextSuppress;
157
			if ((ProblemReporter.getIrritant(problemID) & this.suppressWarningIrritants[j]) == 0)
158
				continue nextSuppress;
159
			// discard suppressed warning
160
			removed++;
161
			this.problems[i] = null;
162
			if (this.problemsMap != null) this.problemsMap.remove(problem);
163
			if (this.firstErrors != null) this.firstErrors.remove(problem);
164
			continue nextProblem;
165
		}
166
	}
167
	if (removed > 0) {
168
		for (int i = 0, index = 0; i < this.problemCount; i++) {
169
			CategorizedProblem problem;
170
			if ((problem = this.problems[i]) != null) {
171
				if (i > index) {
172
					this.problems[index++] = problem;
173
				} else {
174
					index++;
175
				}
176
			}
177
		}
178
		this.problemCount -= removed;
179
	}
180
}
181
182
public CategorizedProblem[] getAllProblems() {
136
public CategorizedProblem[] getAllProblems() {
183
	CategorizedProblem[] onlyProblems = this.getProblems();
137
	CategorizedProblem[] onlyProblems = this.getProblems();
184
	int onlyProblemCount = onlyProblems != null ? onlyProblems.length : 0;
138
	int onlyProblemCount = onlyProblems != null ? onlyProblems.length : 0;
Lines 285-292 Link Here
285
public CategorizedProblem[] getProblems() {
239
public CategorizedProblem[] getProblems() {
286
	// Re-adjust the size of the problems if necessary.
240
	// Re-adjust the size of the problems if necessary.
287
	if (this.problems != null) {
241
	if (this.problems != null) {
288
		discardSuppressedWarnings();
289
290
		if (this.problemCount != this.problems.length) {
242
		if (this.problemCount != this.problems.length) {
291
			System.arraycopy(this.problems, 0, (this.problems = new CategorizedProblem[this.problemCount]), 0, this.problemCount);
243
			System.arraycopy(this.problems, 0, (this.problems = new CategorizedProblem[this.problemCount]), 0, this.problemCount);
292
		}
244
		}
Lines 416-433 Link Here
416
	this.compiledTypes.put(typeName, classFile);
368
	this.compiledTypes.put(typeName, classFile);
417
}
369
}
418
370
419
public void recordSuppressWarnings(long irritant, int scopeStart, int scopeEnd) {
420
	if (this.suppressWarningIrritants == null) {
421
		this.suppressWarningIrritants = new long[3];
422
		this.suppressWarningScopePositions = new long[3];
423
	} else if (this.suppressWarningIrritants.length == this.suppressWarningsCount) {
424
		System.arraycopy(this.suppressWarningIrritants, 0,this.suppressWarningIrritants = new long[2*this.suppressWarningsCount], 0, this.suppressWarningsCount);
425
		System.arraycopy(this.suppressWarningScopePositions, 0,this.suppressWarningScopePositions = new long[2*this.suppressWarningsCount], 0, this.suppressWarningsCount);
426
	}
427
	this.suppressWarningIrritants[this.suppressWarningsCount] = irritant;
428
	this.suppressWarningScopePositions[this.suppressWarningsCount++] = ((long)scopeStart<<32) + scopeEnd;
429
}
430
431
private void recordTask(CategorizedProblem newProblem) {
371
private void recordTask(CategorizedProblem newProblem) {
432
	if (this.taskCount == 0) {
372
	if (this.taskCount == 0) {
433
		this.tasks = new CategorizedProblem[5];
373
		this.tasks = new CategorizedProblem[5];
(-)compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java (-5 / +7 lines)
Lines 192-199 Link Here
192
							if (cst != Constant.NotAConstant && cst.typeID() == T_JavaLangString) {
192
							if (cst != Constant.NotAConstant && cst.typeID() == T_JavaLangString) {
193
								long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue());
193
								long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue());
194
								if (irritant != 0) {
194
								if (irritant != 0) {
195
									suppressWarningIrritants |= irritant;
195
									if ((suppressWarningIrritants & irritant) == irritant) {
196
									if (~suppressWarningIrritants == 0) break pairLoop;
196
										scope.problemReporter().unusedWarningToken(inits[j]);
197
									} else {
198
										suppressWarningIrritants |= irritant;
199
									}
197
								} else {
200
								} else {
198
									scope.problemReporter().unhandledWarningToken(inits[j]);
201
									scope.problemReporter().unhandledWarningToken(inits[j]);
199
								}
202
								}
Lines 206-212 Link Here
206
						long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue());
209
						long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue());
207
						if (irritant != 0) {
210
						if (irritant != 0) {
208
							suppressWarningIrritants |= irritant;
211
							suppressWarningIrritants |= irritant;
209
							if (~suppressWarningIrritants == 0) break pairLoop;
210
						} else {
212
						} else {
211
							scope.problemReporter().unhandledWarningToken(value);
213
							scope.problemReporter().unhandledWarningToken(value);
212
						}
214
						}
Lines 216-222 Link Here
216
			}
218
			}
217
		}
219
		}
218
		if (isSuppressingWarnings && suppressWarningIrritants != 0) {
220
		if (isSuppressingWarnings && suppressWarningIrritants != 0) {
219
			scope.referenceCompilationUnit().compilationResult.recordSuppressWarnings(suppressWarningIrritants, startSuppresss, endSuppress);
221
			scope.referenceCompilationUnit().recordSuppressWarnings(suppressWarningIrritants, this, startSuppresss, endSuppress);
220
		}
222
		}
221
	}
223
	}
222
	
224
	
Lines 303-309 Link Here
303
		long tagBits = detectStandardAnnotation(scope, annotationType, valueAttribute);
305
		long tagBits = detectStandardAnnotation(scope, annotationType, valueAttribute);
304
306
305
		// record annotation positions in the compilation result
307
		// record annotation positions in the compilation result
306
		scope.referenceCompilationUnit().compilationResult.recordSuppressWarnings(CompilerOptions.NonExternalizedString, this.sourceStart, this.declarationSourceEnd);
308
		scope.referenceCompilationUnit().recordSuppressWarnings(CompilerOptions.NonExternalizedString, null, this.sourceStart, this.declarationSourceEnd);
307
		if (this.recipient != null) {
309
		if (this.recipient != null) {
308
			if (tagBits != 0) {
310
			if (tagBits != 0) {
309
				// tag bits onto recipient
311
				// tag bits onto recipient
(-)compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java (+138 lines)
Lines 15-29 Link Here
15
15
16
import org.eclipse.jdt.core.compiler.CategorizedProblem;
16
import org.eclipse.jdt.core.compiler.CategorizedProblem;
17
import org.eclipse.jdt.core.compiler.CharOperation;
17
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.core.compiler.IProblem;
18
import org.eclipse.jdt.internal.compiler.ASTVisitor;
19
import org.eclipse.jdt.internal.compiler.ASTVisitor;
19
import org.eclipse.jdt.internal.compiler.ClassFile;
20
import org.eclipse.jdt.internal.compiler.ClassFile;
20
import org.eclipse.jdt.internal.compiler.CompilationResult;
21
import org.eclipse.jdt.internal.compiler.CompilationResult;
22
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
23
import org.eclipse.jdt.internal.compiler.impl.Constant;
21
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
24
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
22
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
25
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
23
import org.eclipse.jdt.internal.compiler.lookup.ImportBinding;
26
import org.eclipse.jdt.internal.compiler.lookup.ImportBinding;
24
import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding;
27
import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding;
25
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
28
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
26
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
29
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
30
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
27
import org.eclipse.jdt.internal.compiler.parser.NLSTag;
31
import org.eclipse.jdt.internal.compiler.parser.NLSTag;
28
import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit;
32
import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit;
29
import org.eclipse.jdt.internal.compiler.problem.AbortMethod;
33
import org.eclipse.jdt.internal.compiler.problem.AbortMethod;
Lines 66-71 Link Here
66
	private StringLiteral[] stringLiterals;
70
	private StringLiteral[] stringLiterals;
67
	private int stringLiteralsPtr;
71
	private int stringLiteralsPtr;
68
72
73
	long[] suppressWarningIrritants;  // irritant for suppressed warnings
74
	Annotation[] suppressWarningAnnotations;
75
	long[] suppressWarningScopePositions; // (start << 32) + end 
76
	int suppressWarningsCount;
77
	
69
	public CompilationUnitDeclaration(
78
	public CompilationUnitDeclaration(
70
		ProblemReporter problemReporter,
79
		ProblemReporter problemReporter,
71
		CompilationResult compilationResult,
80
		CompilationResult compilationResult,
Lines 142-147 Link Here
142
			classFile.referenceBinding = null;
151
			classFile.referenceBinding = null;
143
			classFile.innerClassesBindings = null;
152
			classFile.innerClassesBindings = null;
144
		}
153
		}
154
		
155
		this.suppressWarningAnnotations = null;
145
	}
156
	}
146
	private void cleanUp(TypeDeclaration type) {
157
	private void cleanUp(TypeDeclaration type) {
147
		if (type.memberTypes != null) {
158
		if (type.memberTypes != null) {
Lines 191-196 Link Here
191
		return null;
202
		return null;
192
	}
203
	}
193
204
205
	public void finalizeProblems() {
206
		if (this.suppressWarningsCount == 0) return;
207
		int removed = 0;
208
		CategorizedProblem[] problems = this.compilationResult.problems;
209
		int problemCount = this.compilationResult.problemCount;
210
		long[] foundIrritants = new long[this.suppressWarningsCount];
211
		nextProblem: for (int iProblem = 0, length = problemCount; iProblem < length; iProblem++) {
212
			CategorizedProblem problem = problems[iProblem];
213
			int problemID = problem.getID();
214
			long problemIrritant = ProblemReporter.getIrritant(problemID);
215
			boolean isWarning = problem.isWarning();
216
			int start = problem.getSourceStart();
217
			int end = problem.getSourceEnd();
218
			nextSuppress: for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) {
219
				long position = this.suppressWarningScopePositions[iSuppress];
220
				int startSuppress = (int) (position >>> 32);
221
				int endSuppress = (int) position;
222
				if (start < startSuppress) continue nextSuppress;
223
				if (end > endSuppress) continue nextSuppress;
224
				if (isWarning) {
225
					if ((problemIrritant & this.suppressWarningIrritants[iSuppress]) == 0)
226
						continue nextSuppress;
227
					// discard suppressed warning
228
					removed++;
229
					problems[iProblem] = null;
230
					if (compilationResult.problemsMap != null) compilationResult.problemsMap.remove(problem);
231
					if (compilationResult.firstErrors != null) compilationResult.firstErrors.remove(problem);
232
					foundIrritants[iSuppress] |= problemIrritant;
233
					continue nextProblem;
234
				} else {
235
					// any error may prevent further warnings to be emitted, hence shouldn't report unused warning tokens if in same scope
236
					foundIrritants[iSuppress] = this.suppressWarningIrritants[iSuppress]; // treat as used
237
					continue nextSuppress;					
238
				}
239
			}
240
		}
241
		// compact remaining problems
242
		if (removed > 0) {
243
			for (int i = 0, index = 0; i < problemCount; i++) {
244
				CategorizedProblem problem;
245
				if ((problem = problems[i]) != null) {
246
					if (i > index) {
247
						problems[index++] = problem;
248
					} else {
249
						index++;
250
					}
251
				}
252
			}
253
			this.compilationResult.problemCount -= removed;
254
		}
255
		// flag SuppressWarnings which had no effect
256
		if (scope.compilerOptions().getSeverity(CompilerOptions.UnusedWarningToken) != ProblemSeverities.Ignore) {
257
			for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) {
258
				Annotation annotation = this.suppressWarningAnnotations[iSuppress];
259
				if (annotation == null) continue; // implicit annotation
260
				long irritants = this.suppressWarningIrritants[iSuppress];
261
				if (~irritants == 0) continue; // @SuppressWarnings("all") also suppresses unused warning token
262
				if (irritants != foundIrritants[iSuppress]) { // mismatch, some warning tokens were unused
263
					MemberValuePair[] pairs = annotation.memberValuePairs();
264
					pairLoop: for (int iPair = 0, pairCount = pairs.length; iPair < pairCount; iPair++) {
265
						MemberValuePair pair = pairs[iPair];
266
						if (CharOperation.equals(pair.name, TypeConstants.VALUE)) {
267
							Expression value = pair.value;
268
							if (value instanceof ArrayInitializer) {
269
								ArrayInitializer initializer = (ArrayInitializer) value;
270
								Expression[] inits = initializer.expressions;
271
								if (inits != null) {
272
									for (int iToken = 0, tokenCount = inits.length; iToken < tokenCount; iToken++) {
273
										Constant cst = inits[iToken].constant;
274
										if (cst != Constant.NotAConstant && cst.typeID() == TypeIds.T_JavaLangString) {
275
											long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue());
276
											if (irritant != 0 && (foundIrritants[iSuppress] & irritant) == 0) {
277
												int start = value.sourceStart, end = value.sourceEnd;
278
												nextSuppress: for (int jSuppress = iSuppress - 1; jSuppress >= 0; jSuppress--) {
279
													long position = this.suppressWarningScopePositions[jSuppress];
280
													int startSuppress = (int) (position >>> 32);
281
													int endSuppress = (int) position;
282
													if (start < startSuppress) continue nextSuppress;
283
													if (end > endSuppress) continue nextSuppress;
284
													if (~this.suppressWarningIrritants[jSuppress] == 0) break pairLoop; // suppress all?
285
												}
286
												scope.problemReporter().unusedWarningToken(inits[iToken]);
287
											}
288
										}
289
									}
290
								}
291
							} else {
292
								Constant cst = value.constant;
293
								if (cst != Constant.NotAConstant && cst.typeID() == T_JavaLangString) {
294
									long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue());
295
									if (irritant != 0 && (foundIrritants[iSuppress] & irritant) == 0) {
296
										int start = value.sourceStart, end = value.sourceEnd;
297
										nextSuppress: for (int jSuppress = iSuppress - 1; jSuppress >= 0; jSuppress--) {
298
											long position = this.suppressWarningScopePositions[jSuppress];
299
											int startSuppress = (int) (position >>> 32);
300
											int endSuppress = (int) position;
301
											if (start < startSuppress) continue nextSuppress;
302
											if (end > endSuppress) continue nextSuppress;
303
											if (~this.suppressWarningIrritants[jSuppress] == 0) break pairLoop; // suppress all?
304
										}
305
										scope.problemReporter().unusedWarningToken(value);
306
									}
307
								}	
308
							}
309
							break pairLoop;
310
						}
311
					}
312
				}
313
			}
314
		}
315
	}
316
	
194
	/**
317
	/**
195
	 * Bytecode generation
318
	 * Bytecode generation
196
	 */
319
	 */
Lines 313-318 Link Here
313
		this.stringLiterals[this.stringLiteralsPtr++] = literal;
436
		this.stringLiterals[this.stringLiteralsPtr++] = literal;
314
	}
437
	}
315
438
439
	public void recordSuppressWarnings(long irritant, Annotation annotation, int scopeStart, int scopeEnd) {
440
		if (this.suppressWarningIrritants == null) {
441
			this.suppressWarningIrritants = new long[3];
442
			this.suppressWarningAnnotations = new Annotation[3];
443
			this.suppressWarningScopePositions = new long[3];
444
		} else if (this.suppressWarningIrritants.length == this.suppressWarningsCount) {
445
			System.arraycopy(this.suppressWarningIrritants, 0,this.suppressWarningIrritants = new long[2*this.suppressWarningsCount], 0, this.suppressWarningsCount);
446
			System.arraycopy(this.suppressWarningAnnotations, 0,this.suppressWarningAnnotations = new Annotation[2*this.suppressWarningsCount], 0, this.suppressWarningsCount);
447
			System.arraycopy(this.suppressWarningScopePositions, 0,this.suppressWarningScopePositions = new long[2*this.suppressWarningsCount], 0, this.suppressWarningsCount);
448
		}
449
		this.suppressWarningIrritants[this.suppressWarningsCount] = irritant;
450
		this.suppressWarningAnnotations[this.suppressWarningsCount] = annotation;
451
		this.suppressWarningScopePositions[this.suppressWarningsCount++] = ((long)scopeStart<<32) + scopeEnd;
452
	}
453
	
316
	/*
454
	/*
317
	 * Keep track of all local types, so as to update their innerclass
455
	 * Keep track of all local types, so as to update their innerclass
318
	 * emulation later on.
456
	 * emulation later on.
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (-1 / +1 lines)
Lines 288-294 Link Here
288
\      unusedTypeArgs     + unused type arguments for method\n\
288
\      unusedTypeArgs     + unused type arguments for method\n\
289
\      uselessTypeCheck     unnecessary cast/instanceof operation\n\
289
\      uselessTypeCheck     unnecessary cast/instanceof operation\n\
290
\      varargsCast        + varargs argument need explicit cast\n\
290
\      varargsCast        + varargs argument need explicit cast\n\
291
\      warningToken       + unhandled warning token in @SuppressWarnings\n\
291
\      warningToken       + unsupported or unnecessary @SuppressWarnings\n\
292
\ \n\
292
\ \n\
293
\ Advanced options:\n\
293
\ Advanced options:\n\
294
\    -? -help           print the help message\n
294
\    -? -help           print the help message\n
(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (+3 lines)
Lines 1768-1773 Link Here
1768
		this.options.put(
1768
		this.options.put(
1769
			CompilerOptions.OPTION_ReportUnhandledWarningToken,
1769
			CompilerOptions.OPTION_ReportUnhandledWarningToken,
1770
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1770
			isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1771
		this.options.put(
1772
				CompilerOptions.OPTION_ReportUnusedWarningToken,
1773
				isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
1771
	} else if (token.equals("unnecessaryElse")) {//$NON-NLS-1$
1774
	} else if (token.equals("unnecessaryElse")) {//$NON-NLS-1$
1772
		this.options.put(
1775
		this.options.put(
1773
			CompilerOptions.OPTION_ReportUnnecessaryElse,
1776
			CompilerOptions.OPTION_ReportUnnecessaryElse,
(-)compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (-1 / +16 lines)
Lines 109-114 Link Here
109
	public static final String OPTION_ReportDiscouragedReference =  "org.eclipse.jdt.core.compiler.problem.discouragedReference"; //$NON-NLS-1$
109
	public static final String OPTION_ReportDiscouragedReference =  "org.eclipse.jdt.core.compiler.problem.discouragedReference"; //$NON-NLS-1$
110
	public static final String OPTION_SuppressWarnings =  "org.eclipse.jdt.core.compiler.problem.suppressWarnings"; //$NON-NLS-1$
110
	public static final String OPTION_SuppressWarnings =  "org.eclipse.jdt.core.compiler.problem.suppressWarnings"; //$NON-NLS-1$
111
	public static final String OPTION_ReportUnhandledWarningToken =  "org.eclipse.jdt.core.compiler.problem.unhandledWarningToken"; //$NON-NLS-1$
111
	public static final String OPTION_ReportUnhandledWarningToken =  "org.eclipse.jdt.core.compiler.problem.unhandledWarningToken"; //$NON-NLS-1$
112
	public static final String OPTION_ReportUnusedWarningToken =  "org.eclipse.jdt.core.compiler.problem.unusedWarningToken"; //$NON-NLS-1$
112
	public static final String OPTION_ReportUnusedLabel =  "org.eclipse.jdt.core.compiler.problem.unusedLabel"; //$NON-NLS-1$
113
	public static final String OPTION_ReportUnusedLabel =  "org.eclipse.jdt.core.compiler.problem.unusedLabel"; //$NON-NLS-1$
113
	public static final String OPTION_FatalOptionalError =  "org.eclipse.jdt.core.compiler.problem.fatalOptionalError"; //$NON-NLS-1$
114
	public static final String OPTION_FatalOptionalError =  "org.eclipse.jdt.core.compiler.problem.fatalOptionalError"; //$NON-NLS-1$
114
	public static final String OPTION_ReportParameterAssignment =  "org.eclipse.jdt.core.compiler.problem.parameterAssignment"; //$NON-NLS-1$
115
	public static final String OPTION_ReportParameterAssignment =  "org.eclipse.jdt.core.compiler.problem.parameterAssignment"; //$NON-NLS-1$
Lines 208-213 Link Here
208
	public static final long RedundantNullCheck = ASTNode.Bit52L;
209
	public static final long RedundantNullCheck = ASTNode.Bit52L;
209
	public static final long MissingJavadocTagDescription = ASTNode.Bit53L;
210
	public static final long MissingJavadocTagDescription = ASTNode.Bit53L;
210
	public static final long UnusedTypeArgumentsForMethodInvocation = ASTNode.Bit54L;
211
	public static final long UnusedTypeArgumentsForMethodInvocation = ASTNode.Bit54L;
212
	public static final long UnusedWarningToken = ASTNode.Bit55L;
211
213
212
	// Map: String optionKey --> Long irritant>
214
	// Map: String optionKey --> Long irritant>
213
	private static Map OptionToIrritants;
215
	private static Map OptionToIrritants;
Lines 242-248 Link Here
242
		| UnusedPrivateMember
244
		| UnusedPrivateMember
243
		| UnusedLabel
245
		| UnusedLabel
244
		| UnusedTypeArgumentsForMethodInvocation
246
		| UnusedTypeArgumentsForMethodInvocation
245
		| NullReference;
247
		| NullReference
248
		| UnusedWarningToken;
246
249
247
	// By default only lines and source attributes are generated.
250
	// By default only lines and source attributes are generated.
248
	public int produceDebugAttributes = ClassFileConstants.ATTR_SOURCE | ClassFileConstants.ATTR_LINES;
251
	public int produceDebugAttributes = ClassFileConstants.ATTR_SOURCE | ClassFileConstants.ATTR_LINES;
Lines 444-449 Link Here
444
		optionsMap.put(OPTION_ReportRedundantNullCheck, getSeverityString(RedundantNullCheck));
447
		optionsMap.put(OPTION_ReportRedundantNullCheck, getSeverityString(RedundantNullCheck));
445
		optionsMap.put(OPTION_SuppressWarnings, this.suppressWarnings ? ENABLED : DISABLED);
448
		optionsMap.put(OPTION_SuppressWarnings, this.suppressWarnings ? ENABLED : DISABLED);
446
		optionsMap.put(OPTION_ReportUnhandledWarningToken, getSeverityString(UnhandledWarningToken));
449
		optionsMap.put(OPTION_ReportUnhandledWarningToken, getSeverityString(UnhandledWarningToken));
450
		optionsMap.put(OPTION_ReportUnusedWarningToken, getSeverityString(UnusedWarningToken));
447
		optionsMap.put(OPTION_ReportParameterAssignment, getSeverityString(ParameterAssignment));
451
		optionsMap.put(OPTION_ReportParameterAssignment, getSeverityString(ParameterAssignment));
448
		optionsMap.put(OPTION_ReportFallthroughCase, getSeverityString(FallthroughCase));
452
		optionsMap.put(OPTION_ReportFallthroughCase, getSeverityString(FallthroughCase));
449
		optionsMap.put(OPTION_ReportOverridingMethodWithoutSuperInvocation, getSeverityString(OverridingMethodWithoutSuperInvocation));
453
		optionsMap.put(OPTION_ReportOverridingMethodWithoutSuperInvocation, getSeverityString(OverridingMethodWithoutSuperInvocation));
Lines 575-580 Link Here
575
					return OPTION_ReportMissingJavadocTagDescription;
579
					return OPTION_ReportMissingJavadocTagDescription;
576
				case (int)(UnusedTypeArgumentsForMethodInvocation >>> 32):
580
				case (int)(UnusedTypeArgumentsForMethodInvocation >>> 32):
577
					return OPTION_ReportUnusedTypeArgumentsForMethodInvocation;
581
					return OPTION_ReportUnusedTypeArgumentsForMethodInvocation;
582
				case (int)(UnusedWarningToken >>> 32) :
583
					return OPTION_ReportUnusedWarningToken;
578
			}
584
			}
579
		}
585
		}
580
		return null;
586
		return null;
Lines 596-601 Link Here
596
602
597
	public int getSeverity(long irritant) {
603
	public int getSeverity(long irritant) {
598
		if((this.errorThreshold & irritant) != 0) {
604
		if((this.errorThreshold & irritant) != 0) {
605
			if (irritant == UnusedWarningToken) {
606
				return ProblemSeverities.Error | ProblemSeverities.Optional; // cannot be treated as fatal - codegen already occurred
607
			}
599
			return this.treatOptionalErrorAsFatal
608
			return this.treatOptionalErrorAsFatal
600
				? ProblemSeverities.Error | ProblemSeverities.Optional | ProblemSeverities.Fatal
609
				? ProblemSeverities.Error | ProblemSeverities.Optional | ProblemSeverities.Fatal
601
				: ProblemSeverities.Error | ProblemSeverities.Optional;
610
				: ProblemSeverities.Error | ProblemSeverities.Optional;
Lines 847-852 Link Here
847
		if ((optionValue = optionsMap.get(OPTION_ReportMissingDeprecatedAnnotation)) != null) updateSeverity(MissingDeprecatedAnnotation, optionValue);
856
		if ((optionValue = optionsMap.get(OPTION_ReportMissingDeprecatedAnnotation)) != null) updateSeverity(MissingDeprecatedAnnotation, optionValue);
848
		if ((optionValue = optionsMap.get(OPTION_ReportIncompleteEnumSwitch)) != null) updateSeverity(IncompleteEnumSwitch, optionValue);
857
		if ((optionValue = optionsMap.get(OPTION_ReportIncompleteEnumSwitch)) != null) updateSeverity(IncompleteEnumSwitch, optionValue);
849
		if ((optionValue = optionsMap.get(OPTION_ReportUnhandledWarningToken)) != null) updateSeverity(UnhandledWarningToken, optionValue);
858
		if ((optionValue = optionsMap.get(OPTION_ReportUnhandledWarningToken)) != null) updateSeverity(UnhandledWarningToken, optionValue);
859
		if ((optionValue = optionsMap.get(OPTION_ReportUnusedWarningToken)) != null) updateSeverity(UnusedWarningToken, optionValue);
850
		if ((optionValue = optionsMap.get(OPTION_ReportUnusedLabel)) != null) updateSeverity(UnusedLabel, optionValue);
860
		if ((optionValue = optionsMap.get(OPTION_ReportUnusedLabel)) != null) updateSeverity(UnusedLabel, optionValue);
851
		if ((optionValue = optionsMap.get(OPTION_ReportParameterAssignment)) != null) updateSeverity(ParameterAssignment, optionValue);
861
		if ((optionValue = optionsMap.get(OPTION_ReportParameterAssignment)) != null) updateSeverity(ParameterAssignment, optionValue);
852
		if ((optionValue = optionsMap.get(OPTION_ReportFallthroughCase)) != null) updateSeverity(FallthroughCase, optionValue);
862
		if ((optionValue = optionsMap.get(OPTION_ReportFallthroughCase)) != null) updateSeverity(FallthroughCase, optionValue);
Lines 1039-1044 Link Here
1039
		buf.append("\n\t- incomplete enum switch: ").append(getSeverityString(IncompleteEnumSwitch)); //$NON-NLS-1$
1049
		buf.append("\n\t- incomplete enum switch: ").append(getSeverityString(IncompleteEnumSwitch)); //$NON-NLS-1$
1040
		buf.append("\n\t- suppress warnings: ").append(this.suppressWarnings ? ENABLED : DISABLED); //$NON-NLS-1$
1050
		buf.append("\n\t- suppress warnings: ").append(this.suppressWarnings ? ENABLED : DISABLED); //$NON-NLS-1$
1041
		buf.append("\n\t- unhandled warning token: ").append(getSeverityString(UnhandledWarningToken)); //$NON-NLS-1$
1051
		buf.append("\n\t- unhandled warning token: ").append(getSeverityString(UnhandledWarningToken)); //$NON-NLS-1$
1052
		buf.append("\n\t- unused warning token: ").append(getSeverityString(UnusedWarningToken)); //$NON-NLS-1$
1042
		buf.append("\n\t- unused label: ").append(getSeverityString(UnusedLabel)); //$NON-NLS-1$
1053
		buf.append("\n\t- unused label: ").append(getSeverityString(UnusedLabel)); //$NON-NLS-1$
1043
		buf.append("\n\t- treat optional error as fatal: ").append(this.treatOptionalErrorAsFatal ? ENABLED : DISABLED); //$NON-NLS-1$
1054
		buf.append("\n\t- treat optional error as fatal: ").append(this.treatOptionalErrorAsFatal ? ENABLED : DISABLED); //$NON-NLS-1$
1044
		buf.append("\n\t- parameter assignment: ").append(getSeverityString(ParameterAssignment)); //$NON-NLS-1$
1055
		buf.append("\n\t- parameter assignment: ").append(getSeverityString(ParameterAssignment)); //$NON-NLS-1$
Lines 1184-1195 Link Here
1184
			OPTION_ReportUnusedPrivateMember,
1195
			OPTION_ReportUnusedPrivateMember,
1185
			OPTION_ReportVarargsArgumentNeedCast,
1196
			OPTION_ReportVarargsArgumentNeedCast,
1186
			OPTION_ReportUnhandledWarningToken,
1197
			OPTION_ReportUnhandledWarningToken,
1198
			OPTION_ReportUnusedWarningToken,
1187
			OPTION_ReportOverridingMethodWithoutSuperInvocation,
1199
			OPTION_ReportOverridingMethodWithoutSuperInvocation,
1188
			OPTION_ReportUnusedTypeArgumentsForMethodInvocation,
1200
			OPTION_ReportUnusedTypeArgumentsForMethodInvocation,
1189
		};
1201
		};
1190
		return result;
1202
		return result;
1191
	}
1203
	}
1192
1204
1205
	/**
1206
	 * For suppressable warnings
1207
	 */
1193
	public static String warningTokenFromIrritant(long irritant) {
1208
	public static String warningTokenFromIrritant(long irritant) {
1194
		// keep in sync with warningTokens and warningTokenToIrritant
1209
		// keep in sync with warningTokens and warningTokenToIrritant
1195
		int irritantInt = (int) irritant;
1210
		int irritantInt = (int) irritant;
(-)compiler/org/eclipse/jdt/core/compiler/IProblem.java (+2 lines)
Lines 1193-1198 Link Here
1193
	int AnnotationValueMustBeAnEnumConstant = Internal + 633;
1193
	int AnnotationValueMustBeAnEnumConstant = Internal + 633;
1194
	/** @since 3.3 */
1194
	/** @since 3.3 */
1195
	int MethodMustOverrideOrImplement = MethodRelated + 634;
1195
	int MethodMustOverrideOrImplement = MethodRelated + 634;
1196
	/** @since 3.4 */
1197
	int UnusedWarningToken = Internal + 635;
1196
	
1198
	
1197
	/**
1199
	/**
1198
	 * Corrupted binaries
1200
	 * Corrupted binaries

Return to bug 127533