Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6f12b7dd0e6354235e732a58532ee5977bc78ecd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
/*******************************************************************************
 * Copyright (c) 2017, 2018 GK Software SE, and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Stephan Herrmann - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;

import junit.framework.Test;

public class Deprecated9Test extends AbstractRegressionTest9 {
	public Deprecated9Test(String name) {
		super(name);
	}
	public static Test suite() {
		return buildMinimalComplianceTestSuite(testClass(), F_9);
	}

	static {
//		TESTS_NAMES = new String[] { "test007" };
	}

	@Override
	protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) {
		if (this.javaClassLib != null) {
			String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding);
			if ("".equals(encoding))
				encoding = null;
			return new INameEnvironment[] {
					this.javaClassLib,
					new FileSystem(this.classpaths, new String[]{}, // ignore initial file names
							encoding // default encoding
					)};
		}
		return super.getClassLibs(useDefaultClasspaths);
	}

	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159709
	// guard variant for DeprecatedTest#test015 using an annotation
	public void test002() {
		Map<String, String> customOptions = new HashMap<>();
		customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING);
		customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR);
		customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE);
		this.runNegativeTest(
			true,
			new String[] {
				"p/M1.java",
				"package p;\n" +
				"public class M1 {\n" +
				"  void bar() {\n" +
				"    a.N1.N2.N3 m = null;\n" +
				"    m.foo();\n" +
				"  }\n" +
				"}\n",
				"a/N1.java",
				"package a;\n" +
				"public class N1 {\n" +
				"  @Deprecated(since=\"1.2\",forRemoval=true)\n" +
				"  public class N2 {" +
				"    public void foo() {}" +
				"    public class N3 {" +
				"      public void foo() {}" +
				"    }" +
				"  }" +
				"}\n",
			},
			null, customOptions,
			"----------\n" +
			"1. ERROR in p\\M1.java (at line 4)\n" +
			"	a.N1.N2.N3 m = null;\n" +
			"	     ^^\n" +
			"The type N1.N2 has been deprecated since version 1.2 and marked for removal\n" +
			"----------\n" +
			"2. ERROR in p\\M1.java (at line 4)\n" +
			"	a.N1.N2.N3 m = null;\n" +
			"	        ^^\n" +
			"The type N1.N2.N3 has been deprecated and marked for removal\n" +
			"----------\n" +
			"3. ERROR in p\\M1.java (at line 5)\n" +
			"	m.foo();\n" +
			"	  ^^^^^\n" +
			"The method foo() from the type N1.N2.N3 has been deprecated and marked for removal\n" +
			"----------\n",
			JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
	}
	public void test002binary() {
		Runner runner = new Runner();
		runner.customOptions = new HashMap<>();
		runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING);
		runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR);
		runner.customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE);
		runner.testFiles =
			new String[] {
				"a/N1.java",
				"package a;\n" +
				"public class N1 {\n" +
				"  @Deprecated(since=\"1.2\",forRemoval=true)\n" +
				"  public class N2 {" +
				"    public void foo() {}" +
				"    public class N3 {" +
				"      public void foo() {}" +
				"    }" +
				"  }" +
				"}\n"
			};
		runner.runConformTest();

		runner.shouldFlushOutputDirectory = false;
		runner.testFiles =
			new String[] {
				"p/M1.java",
				"package p;\n" +
				"public class M1 {\n" +
				"  void bar() {\n" +
				"    a.N1.N2.N3 m = null;\n" +
				"    m.foo();\n" +
				"  }\n" +
				"}\n"
			};
		runner.expectedCompilerLog =
			"----------\n" +
			"1. ERROR in p\\M1.java (at line 4)\n" +
			"	a.N1.N2.N3 m = null;\n" +
			"	     ^^\n" +
			"The type N1.N2 has been deprecated since version 1.2 and marked for removal\n" +
			"----------\n" +
			"2. ERROR in p\\M1.java (at line 4)\n" +
			"	a.N1.N2.N3 m = null;\n" +
			"	        ^^\n" +
			"The type N1.N2.N3 has been deprecated and marked for removal\n" +
			"----------\n" +
			"3. ERROR in p\\M1.java (at line 5)\n" +
			"	m.foo();\n" +
			"	  ^^^^^\n" +
			"The method foo() from the type N1.N2.N3 has been deprecated and marked for removal\n" +
			"----------\n";
		runner.javacTestOptions =
			JavacTestOptions.Excuse.EclipseWarningConfiguredAsError;
		runner.runNegativeTest();
	}
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191909
	public void test004() {
		Map<String, String> customOptions = new HashMap<>();
		customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING);
		customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR);
		this.runNegativeTest(
			true,
			new String[] {
				"test1/E01.java",
				"package test1;\n" +
				"public class E01 {\n" +
				"	@Deprecated(forRemoval=true,since=\"3\")\n" +
				"	public static int x = 5, y= 10;\n" +
				"}",
				"test1/E02.java",
				"package test1;\n" +
				"public class E02 {\n" +
				"	public void foo() {\n" +
				"		System.out.println(E01.x);\n" +
				"		System.out.println(E01.y);\n" +
				"	}\n" +
				"}"
			},
			null, customOptions,
			"----------\n" +
			"1. ERROR in test1\\E02.java (at line 4)\n" +
			"	System.out.println(E01.x);\n" +
			"	                       ^\n" +
			"The field E01.x has been deprecated since version 3 and marked for removal\n" +
			"----------\n" +
			"2. ERROR in test1\\E02.java (at line 5)\n" +
			"	System.out.println(E01.y);\n" +
			"	                       ^\n" +
			"The field E01.y has been deprecated since version 3 and marked for removal\n" +
			"----------\n",
			JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
	}
	// Bug 354536 - compiling package-info.java still depends on the order of compilation units
	public void test005a() {
		Map<String, String> customOptions = new HashMap<>();
		customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING);
		customOptions.put(CompilerOptions.OPTION_ReportTerminalDeprecation, CompilerOptions.ERROR);
		this.runNegativeTest(
			true,
			new String[] {
				"p1/X.java",
				"package p1;\n" +
				"public class X {\n" +
				"    public static class Inner {" +
				"        public void foo() {}\n" +
				"    }\n" +
				"}\n",
				"p1/package-info.java",
				"@java.lang.Deprecated(forRemoval=true)\n" +
				"package p1;\n",
				"p2/C.java",
				"package p2;\n" +
				"public class C {\n" +
				"    void bar(p1.X.Inner a) {\n" +
				"        a.foo();\n" +
				"    }\n" +
				"}\n",
			},
			null, customOptions,
			"----------\n" +
			"1. ERROR in p2\\C.java (at line 3)\n" + 
			"	void bar(p1.X.Inner a) {\n" + 
			"	            ^\n" + 
			"The type X has been deprecated and marked for removal\n" + 
			"----------\n" + 
			"2. ERROR in p2\\C.java (at line 3)\n" + 
			"	void bar(p1.X.Inner a) {\n" + 
			"	              ^^^^^\n" + 
			"The type X.Inner has been deprecated and marked for removal\n" + 
			"----------\n" + 
			"3. ERROR in p2\\C.java (at line 4)\n" + 
			"	a.foo();\n" + 
			"	  ^^^^^\n" + 
			"The method foo() from the type X.Inner has been deprecated and marked for removal\n" + 
			"----------\n",
			JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
	}
	public void test005b() {
		Map<String, String> customOptions = new HashMap<>();
		customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING);
		customOptions.put(CompilerOptions.OPTION_ReportTerminalDeprecation, CompilerOptions.IGNORE);
		this.runConformTest(
			new String[] {
				"p1/X.java",
				"package p1;\n" +
				"public class X {\n" +
				"    public static class Inner {" +
				"        public void foo() {}\n" +
				"    }\n" +
				"}\n",
				"p1/package-info.java",
				"@java.lang.Deprecated(forRemoval=true)\n" +
				"package p1;\n",
				"p2/C.java",
				"package p2;\n" +
				"public class C {\n" +
				"    void bar(p1.X.Inner a) {\n" +
				"        a.foo();\n" +
				"    }\n" +
				"}\n",
			},
			customOptions);
	}
	public void test005c() {
		Runner runner = new Runner();
		runner.customOptions = new HashMap<>();
		runner.customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING);
		runner.customOptions.put(CompilerOptions.OPTION_ReportTerminalDeprecation, CompilerOptions.WARNING);
		runner.testFiles =
			new String[] {
				"p1/X.java",
				"package p1;\n" +
				"public class X {\n" +
				"    public static class Inner {\n" +
				"		 @java.lang.Deprecated(forRemoval=true)\n" + 
				"        public void foo() {}\n" +
				"    }\n" +
				"}\n",
				"p1/package-info.java",
				"@java.lang.Deprecated(forRemoval=false)\n" +
				"package p1;\n",
				"p2/C.java",
				"package p2;\n" +
				"public class C {\n" +
				"	 @SuppressWarnings(\"deprecation\")\n" +
				"    void bar(p1.X.Inner a) {\n" +
				"        a.foo();\n" +
				"    }\n" +
				"}\n",
			};
		runner.expectedCompilerLog =
			"----------\n" +
			"1. WARNING in p2\\C.java (at line 5)\n" + 
			"	a.foo();\n" + 
			"	  ^^^^^\n" + 
			"The method foo() from the type X.Inner has been deprecated and marked for removal\n" + 
			"----------\n";
		runner.runWarningTest();
	}
	public void test006() {
		Runner runner = new Runner();
		runner.customOptions = new HashMap<>();
		runner.customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING);
		runner.customOptions.put(CompilerOptions.OPTION_ReportTerminalDeprecation, CompilerOptions.ERROR);
		runner.testFiles =
			new String[] {
				"test1/E02.java",
				"package test1;\n" +
				"public class E02 {\n" +
				"	public void foo(E01 arg) {\n" +
				"		// nop\n" +
				"	}\n" +
				"}",
				"test1/E01.java",
				"package test1;\n" +
				"@SuppressWarnings(\"all\") @Deprecated(since=\"4\")\n" +
				"public class E01 {\n" +
				"	public static int x = 5;\n" +
				"}"
			};
		runner.expectedCompilerLog =
			"----------\n" + 
			"1. WARNING in test1\\E02.java (at line 3)\n" + 
			"	public void foo(E01 arg) {\n" + 
			"	                ^^^\n" + 
			"The type E01 is deprecated since version 4\n" + 
			"----------\n";
		runner.runWarningTest();
	}
	// method overriding
	public void test007() {
		Map<String, String> customOptions = new HashMap<>();
		customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING);
		customOptions.put(CompilerOptions.OPTION_ReportTerminalDeprecation, CompilerOptions.ERROR);
		customOptions.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.ENABLED);
		this.runNegativeTest(
			true,
			new String[] {
				"p1/X.java",
				"package p1;\n" +
				"public class X {\n" +
				"	 @java.lang.Deprecated(forRemoval=false)\n" +
				"    public void foo() {}\n" +
				"	 @java.lang.Deprecated(forRemoval=true)\n" +
				"	 public void bar() {}\n" +
				"}\n",
				"p2/C.java",
				"package p2;\n" +
				"import p1.X;\n" +
				"public class C extends X {\n" +
				"    @Override public void foo() {}\n" +
				"    @Override public void bar() {}\n" +
				"}\n",
			},
			null, customOptions,
			"----------\n" + 
			"1. WARNING in p2\\C.java (at line 4)\n" + 
			"	@Override public void foo() {}\n" + 
			"	                      ^^^^^\n" + 
			"The method C.foo() overrides a deprecated method from X\n" + 
			"----------\n" + 
			"2. ERROR in p2\\C.java (at line 5)\n" + 
			"	@Override public void bar() {}\n" + 
			"	                      ^^^^^\n" + 
			"The method C.bar() overrides a method from X that has been deprecated and marked for removal\n" + 
			"----------\n",
			JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
	}
	public void testSinceSource() {
		Runner runner = new Runner();
		runner.customOptions = new HashMap<>();
		runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING);
		runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION_WHEN_OVERRIDING_DEPRECATED_METHOD, CompilerOptions.ENABLED);
		runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR);
		runner.testFiles =
			new String[] {
				"test1/E01.java",
				"package test1;\n" +
				"public class E01 {\n" +
				"	@Deprecated(since=\"1.0\") protected static class Old {}\n" +
				"	@Deprecated(since=\"2\") public static int x = 5, y= 10;\n" +
				"	@Deprecated(since=\"3.0.0\") public E01() {}\n" +
				"	@Deprecated(since=\"4-SNAPSHOT\") protected void old() {}\n" +
				"}",
				"test1/E02.java",
				"package test1;\n" +
				"public class E02 {\n" +
				"	public void foo() {\n" +
				"		System.out.println(new E01.Old());\n" +
				"		E01 e = new E01();\n" +
				"		e.old();\n" +
				"		System.out.println(E01.x);\n" +
				"		System.out.println(E01.y);\n" +
				"	}\n" +
				"	class E03 extends E01 {\n" +
				"		protected void old() {}\n" +
				"	}\n" +
				"}"
			};
		runner.expectedCompilerLog =
			"----------\n" + 
			"1. WARNING in test1\\E02.java (at line 4)\n" + 
			"	System.out.println(new E01.Old());\n" + 
			"	                       ^^^^^^^^^\n" + 
			"The constructor E01.Old() is deprecated since version 1.0\n" + 
			"----------\n" + 
			"2. WARNING in test1\\E02.java (at line 4)\n" + 
			"	System.out.println(new E01.Old());\n" + 
			"	                           ^^^\n" + 
			"The type E01.Old is deprecated since version 1.0\n" + 
			"----------\n" + 
			"3. WARNING in test1\\E02.java (at line 5)\n" + 
			"	E01 e = new E01();\n" + 
			"	            ^^^^^\n" + 
			"The constructor E01() is deprecated since version 3.0.0\n" + 
			"----------\n" + 
			"4. WARNING in test1\\E02.java (at line 6)\n" + 
			"	e.old();\n" + 
			"	  ^^^^^\n" + 
			"The method old() from the type E01 is deprecated since version 4-SNAPSHOT\n" + 
			"----------\n" + 
			"5. WARNING in test1\\E02.java (at line 7)\n" + 
			"	System.out.println(E01.x);\n" + 
			"	                       ^\n" + 
			"The field E01.x is deprecated since version 2\n" + 
			"----------\n" + 
			"6. WARNING in test1\\E02.java (at line 8)\n" + 
			"	System.out.println(E01.y);\n" + 
			"	                       ^\n" + 
			"The field E01.y is deprecated since version 2\n" + 
			"----------\n" + 
			"7. WARNING in test1\\E02.java (at line 10)\n" + 
			"	class E03 extends E01 {\n" + 
			"	      ^^^\n" + 
			"The constructor E01() is deprecated since version 3.0.0\n" + 
			"----------\n" + 
			"8. WARNING in test1\\E02.java (at line 11)\n" + 
			"	protected void old() {}\n" + 
			"	               ^^^^^\n" + 
			"The method E02.E03.old() overrides a method from E01 that is deprecated since version 4-SNAPSHOT\n" + 
			"----------\n";
		runner.runWarningTest();
	}
	public void testSinceBinary() {
		Runner runner = new Runner();
		runner.customOptions = new HashMap<>();
		runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING);
		runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION_WHEN_OVERRIDING_DEPRECATED_METHOD, CompilerOptions.ENABLED);
		runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR);
		runner.testFiles =
			new String[] {
				"test1/E01.java",
				"package test1;\n" +
				"public class E01 {\n" +
				"	@Deprecated(since=\"1.0\") protected static class Old {}\n" +
				"	@Deprecated(since=\"2\") public static int x = 5, y= 10;\n" +
				"	@Deprecated(since=\"3.0.0\") public E01() {}\n" +
				"	@Deprecated(since=\"4-SNAPSHOT\") protected void old() {}\n" +
				"}"
			};
		runner.runConformTest();

		runner.shouldFlushOutputDirectory = false;
		runner.testFiles =
			new String[] {
				"test1/E02.java",
				"package test1;\n" +
				"public class E02 {\n" +
				"	public void foo() {\n" +
				"		System.out.println(new E01.Old());\n" +
				"		E01 e = new E01();\n" +
				"		e.old();\n" +
				"		System.out.println(E01.x);\n" +
				"		System.out.println(E01.y);\n" +
				"	}\n" +
				"	class E03 extends E01 {\n" +
				"		protected void old() {}\n" +
				"	}\n" +
				"}"
			};
		runner.expectedCompilerLog =
			"----------\n" + 
			"1. WARNING in test1\\E02.java (at line 4)\n" + 
			"	System.out.println(new E01.Old());\n" + 
			"	                       ^^^^^^^^^\n" + 
			"The constructor E01.Old() is deprecated since version 1.0\n" + 
			"----------\n" + 
			"2. WARNING in test1\\E02.java (at line 4)\n" + 
			"	System.out.println(new E01.Old());\n" + 
			"	                           ^^^\n" + 
			"The type E01.Old is deprecated since version 1.0\n" + 
			"----------\n" + 
			"3. WARNING in test1\\E02.java (at line 5)\n" + 
			"	E01 e = new E01();\n" + 
			"	            ^^^^^\n" + 
			"The constructor E01() is deprecated since version 3.0.0\n" + 
			"----------\n" + 
			"4. WARNING in test1\\E02.java (at line 6)\n" + 
			"	e.old();\n" + 
			"	  ^^^^^\n" + 
			"The method old() from the type E01 is deprecated since version 4-SNAPSHOT\n" + 
			"----------\n" + 
			"5. WARNING in test1\\E02.java (at line 7)\n" + 
			"	System.out.println(E01.x);\n" + 
			"	                       ^\n" + 
			"The field E01.x is deprecated since version 2\n" + 
			"----------\n" + 
			"6. WARNING in test1\\E02.java (at line 8)\n" + 
			"	System.out.println(E01.y);\n" + 
			"	                       ^\n" + 
			"The field E01.y is deprecated since version 2\n" + 
			"----------\n" + 
			"7. WARNING in test1\\E02.java (at line 10)\n" + 
			"	class E03 extends E01 {\n" + 
			"	      ^^^\n" + 
			"The constructor E01() is deprecated since version 3.0.0\n" + 
			"----------\n" + 
			"8. WARNING in test1\\E02.java (at line 11)\n" + 
			"	protected void old() {}\n" + 
			"	               ^^^^^\n" + 
			"The method E02.E03.old() overrides a method from E01 that is deprecated since version 4-SNAPSHOT\n" + 
			"----------\n";
		runner.runWarningTest();
	}
	public void testSinceTerminally() {
		Runner runner = new Runner();
		runner.customOptions = new HashMap<>();
		runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING);
		runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION_WHEN_OVERRIDING_DEPRECATED_METHOD, CompilerOptions.ENABLED);
		runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR);
		runner.testFiles =
			new String[] {
				"test1/E01.java",
				"package test1;\n" +
				"public class E01 {\n" +
				"	@Deprecated(since=\"1.0\", forRemoval=true) protected static class Old {}\n" +
				"	@Deprecated(since=\"2\", forRemoval=true) public static int x = 5, y= 10;\n" +
				"	@Deprecated(since=\"3.0.0\", forRemoval=true) public E01() {}\n" +
				"	@Deprecated(since=\"4-SNAPSHOT\", forRemoval=true) protected void old() {}\n" +
				"}",
				"test1/E02.java",
				"package test1;\n" +
				"public class E02 {\n" +
				"	public void foo() {\n" +
				"		System.out.println(new E01.Old());\n" +
				"		E01 e = new E01();\n" +
				"		e.old();\n" +
				"		System.out.println(E01.x);\n" +
				"		System.out.println(E01.y);\n" +
				"	}\n" +
				"	class E03 extends E01 {\n" +
				"		protected void old() {}\n" +
				"	}\n" +
				"}"
			};
		runner.expectedCompilerLog =
			"----------\n" + 
			"1. ERROR in test1\\E02.java (at line 4)\n" + 
			"	System.out.println(new E01.Old());\n" + 
			"	                       ^^^^^^^^^\n" + 
			"The constructor E01.Old() has been deprecated since version 1.0 and marked for removal\n" + 
			"----------\n" + 
			"2. ERROR in test1\\E02.java (at line 4)\n" + 
			"	System.out.println(new E01.Old());\n" + 
			"	                           ^^^\n" + 
			"The type E01.Old has been deprecated since version 1.0 and marked for removal\n" + 
			"----------\n" + 
			"3. ERROR in test1\\E02.java (at line 5)\n" + 
			"	E01 e = new E01();\n" + 
			"	            ^^^^^\n" + 
			"The constructor E01() has been deprecated since version 3.0.0 and marked for removal\n" + 
			"----------\n" + 
			"4. ERROR in test1\\E02.java (at line 6)\n" + 
			"	e.old();\n" + 
			"	  ^^^^^\n" + 
			"The method old() from the type E01 has been deprecated since version 4-SNAPSHOT and marked for removal\n" + 
			"----------\n" + 
			"5. ERROR in test1\\E02.java (at line 7)\n" + 
			"	System.out.println(E01.x);\n" + 
			"	                       ^\n" + 
			"The field E01.x has been deprecated since version 2 and marked for removal\n" + 
			"----------\n" + 
			"6. ERROR in test1\\E02.java (at line 8)\n" + 
			"	System.out.println(E01.y);\n" + 
			"	                       ^\n" + 
			"The field E01.y has been deprecated since version 2 and marked for removal\n" + 
			"----------\n" + 
			"7. ERROR in test1\\E02.java (at line 10)\n" + 
			"	class E03 extends E01 {\n" + 
			"	      ^^^\n" + 
			"The constructor E01() has been deprecated since version 3.0.0 and marked for removal\n" + 
			"----------\n" + 
			"8. ERROR in test1\\E02.java (at line 11)\n" + 
			"	protected void old() {}\n" + 
			"	               ^^^^^\n" + 
			"The method E02.E03.old() overrides a method from E01 that has been deprecated since version 4-SNAPSHOT and marked for removal\n" + 
			"----------\n";
		runner.javacTestOptions =
			JavacTestOptions.Excuse.EclipseWarningConfiguredAsError;
		runner.runNegativeTest();
	}
	public void testDeprecatedPackageExport() {
		associateToModule("mod1",
				"p1/package-info.java", "p1/C1.java",
				"p2/package-info.java", "p2/C2.java",
				"p3/package-info.java", "p3/C3.java",
				"p4/package-info.java", "p4/C4.java");
		Runner runner = new Runner();
		runner.customOptions = new HashMap<>();
		runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.ERROR);
		runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR);
		runner.testFiles =
			new String[] {
				"p1/package-info.java",
				"@Deprecated package p1;\n",
				"p1/C1.java",
				"package p1; public class C1 {}\n",
				"p2/package-info.java",
				"@Deprecated(since=\"13\") package p2;\n",
				"p2/C2.java",
				"package p2; public class C2 {}\n",
				"p3/package-info.java",
				"@Deprecated(since=\"13\",forRemoval=true) package p3;\n",
				"p3/C3.java",
				"package p3; public class C3 {}\n",
				"p4/package-info.java",
				"@Deprecated(since=\"14\",forRemoval=true) package p4;\n",
				"p4/C4.java",
				"package p4; public class C4 {}\n",
				"module-info.java",
				"module mod1 {\n" +
				"	exports p1;\n" +
				"	exports p2;\n" +
				"	exports p3;\n" +
				"	opens p4;\n" +
				"}\n"
			};
		runner.runConformTest();
	}
	public void testDeprecatedModule() {
		Runner runner = new Runner();
		runner.customOptions = new HashMap<>();
		runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING);
		runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR);
		runner.testFiles =
			new String[] {
				"folder0/module-info.java",
				"@Deprecated module mod.dep {}\n",
				"folder1/module-info.java",
				"@Deprecated(since=\"42\") module mod.dep.since {}\n",
				"folder2/module-info.java",
				"@Deprecated(forRemoval=true) module mod.dep.terminally {}\n",
				"folder3/module-info.java",
				"@Deprecated(since=\"42\",forRemoval=true) module mod.dep.since.terminally {}\n",
				"module-info.java",
				"module mod1 {\n" +
				"	requires mod.dep;\n" +
				"	requires mod.dep.since;\n" +
				"	requires mod.dep.terminally;\n" +
				"	requires mod.dep.since.terminally;\n" +
				"}\n"
			};
		runner.expectedCompilerLog =
			"----------\n" + 
			"1. WARNING in module-info.java (at line 2)\n" + 
			"	requires mod.dep;\n" + 
			"	         ^^^^^^^\n" + 
			"The module mod.dep is deprecated\n" + 
			"----------\n" + 
			"2. WARNING in module-info.java (at line 3)\n" + 
			"	requires mod.dep.since;\n" + 
			"	         ^^^^^^^^^^^^^\n" + 
			"The module mod.dep.since is deprecated since version 42\n" + 
			"----------\n" + 
			"3. ERROR in module-info.java (at line 4)\n" + 
			"	requires mod.dep.terminally;\n" + 
			"	         ^^^^^^^^^^^^^^^^^^\n" + 
			"The module mod.dep.terminally has been deprecated and marked for removal\n" + 
			"----------\n" + 
			"4. ERROR in module-info.java (at line 5)\n" + 
			"	requires mod.dep.since.terminally;\n" + 
			"	         ^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
			"The module mod.dep.since.terminally has been deprecated since version 42 and marked for removal\n" + 
			"----------\n";
		runner.runNegativeTest();
	}
	public void testDeprecatedProvidedServices() {
		javacUsePathOption(" --module-source-path ");
		associateToModule("mod0", "module-info.java", "p1/IServiceDep.java", "p1/IServiceDepSince.java", "p1/IServiceTermDep.java", "p1/IServiceTermDepSince.java");
		associateToModule("mod1", "p1impl/ServiceDep.java", "p1impl/ServiceDepSince.java", "p1impl/ServiceTermDep.java", "p1impl/ServiceTermDepSince.java");
		Runner runner = new Runner();
		runner.customOptions = new HashMap<>();
		runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.INFO);
		runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.WARNING);
		runner.testFiles =
			new String[] {
				"p1/IServiceDep.java",
				"package p1;\n" +
				"@Deprecated\n" +
				"public interface IServiceDep {}\n",
				"p1/IServiceDepSince.java",
				"package p1;\n" +
				"@Deprecated(since=\"2\")\n" +
				"public interface IServiceDepSince {}\n",
				"p1/IServiceTermDep.java",
				"package p1;\n" +
				"@Deprecated(forRemoval=true)\n" +
				"public interface IServiceTermDep {}\n",
				"p1/IServiceTermDepSince.java",
				"package p1;\n" +
				"@Deprecated(since=\"3\",forRemoval=true)\n" +
				"public interface IServiceTermDepSince {}\n",
				"module-info.java",
				"module mod0 {\n" +
				"	exports p1;\n" +
				"}\n",
				"p1impl/ServiceDep.java",
				"package p1impl;\n" +
				"@Deprecated\n" +
				"public class ServiceDep implements p1.IServiceDep {}\n",
				"p1impl/ServiceDepSince.java",
				"package p1impl;\n" +
				"@Deprecated(since=\"2\")\n" +
				"public class ServiceDepSince implements p1.IServiceDepSince {}\n",
				"p1impl/ServiceTermDep.java",
				"package p1impl;\n" +
				"@Deprecated(forRemoval=true)\n" +
				"public class ServiceTermDep implements p1.IServiceTermDep {}\n",
				"p1impl/ServiceTermDepSince.java",
				"package p1impl;\n" +
				"@Deprecated(since=\"3\",forRemoval=true)\n" +
				"public class ServiceTermDepSince implements p1.IServiceTermDepSince {}\n",
				"mod1/module-info.java",
				"module mod1 {\n" +
				"	requires mod0;\n" +
				"	provides p1.IServiceDep with p1impl.ServiceDep;\n" +
				"	provides p1.IServiceDepSince with p1impl.ServiceDepSince;\n" +
				"	provides p1.IServiceTermDep with p1impl.ServiceTermDep;\n" +
				"	provides p1.IServiceTermDepSince with p1impl.ServiceTermDepSince;\n" +
				"}\n"
			};
		runner.expectedCompilerLog =
			"----------\n" + 
			"1. INFO in mod1\\module-info.java (at line 3)\n" + 
			"	provides p1.IServiceDep with p1impl.ServiceDep;\n" + 
			"	            ^^^^^^^^^^^\n" + 
			"The type IServiceDep is deprecated\n" + 
			"----------\n" + 
			"2. INFO in mod1\\module-info.java (at line 3)\n" + 
			"	provides p1.IServiceDep with p1impl.ServiceDep;\n" + 
			"	                                    ^^^^^^^^^^\n" + 
			"The type ServiceDep is deprecated\n" + 
			"----------\n" + 
			"3. INFO in mod1\\module-info.java (at line 4)\n" + 
			"	provides p1.IServiceDepSince with p1impl.ServiceDepSince;\n" + 
			"	            ^^^^^^^^^^^^^^^^\n" + 
			"The type IServiceDepSince is deprecated since version 2\n" + 
			"----------\n" + 
			"4. INFO in mod1\\module-info.java (at line 4)\n" + 
			"	provides p1.IServiceDepSince with p1impl.ServiceDepSince;\n" + 
			"	                                         ^^^^^^^^^^^^^^^\n" + 
			"The type ServiceDepSince is deprecated since version 2\n" + 
			"----------\n" + 
			"5. WARNING in mod1\\module-info.java (at line 5)\n" + 
			"	provides p1.IServiceTermDep with p1impl.ServiceTermDep;\n" + 
			"	            ^^^^^^^^^^^^^^^\n" + 
			"The type IServiceTermDep has been deprecated and marked for removal\n" + 
			"----------\n" + 
			"6. WARNING in mod1\\module-info.java (at line 5)\n" + 
			"	provides p1.IServiceTermDep with p1impl.ServiceTermDep;\n" + 
			"	                                        ^^^^^^^^^^^^^^\n" + 
			"The type ServiceTermDep has been deprecated and marked for removal\n" + 
			"----------\n" + 
			"7. WARNING in mod1\\module-info.java (at line 6)\n" + 
			"	provides p1.IServiceTermDepSince with p1impl.ServiceTermDepSince;\n" + 
			"	            ^^^^^^^^^^^^^^^^^^^^\n" + 
			"The type IServiceTermDepSince has been deprecated since version 3 and marked for removal\n" + 
			"----------\n" + 
			"8. WARNING in mod1\\module-info.java (at line 6)\n" + 
			"	provides p1.IServiceTermDepSince with p1impl.ServiceTermDepSince;\n" + 
			"	                                             ^^^^^^^^^^^^^^^^^^^\n" + 
			"The type ServiceTermDepSince has been deprecated since version 3 and marked for removal\n" + 
			"----------\n";
		runner.runWarningTest();
	}
	public void testDeprecatedUsedServices() {
		javacUsePathOption(" --module-path ");

		associateToModule("mod0", "p1/IServiceDep.java", "p1/IServiceDepSince.java", "p1/IServiceTermDep.java", "p1/IServiceTermDepSince.java");
		Runner runner = new Runner();
		runner.customOptions = new HashMap<>();
		runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.INFO);
		runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.WARNING);
		runner.testFiles =
			new String[] {
				"p1/IServiceDep.java",
				"package p1;\n" +
				"@Deprecated\n" +
				"public interface IServiceDep {}\n",
				"p1/IServiceDepSince.java",
				"package p1;\n" +
				"@Deprecated(since=\"2\")\n" +
				"public interface IServiceDepSince {}\n",
				"p1/IServiceTermDep.java",
				"package p1;\n" +
				"@Deprecated(forRemoval=true)\n" +
				"public interface IServiceTermDep {}\n",
				"p1/IServiceTermDepSince.java",
				"package p1;\n" +
				"@Deprecated(since=\"3\",forRemoval=true)\n" +
				"public interface IServiceTermDepSince {}\n",
				"module-info.java",
				"module mod0 {\n" +
				"	exports p1;\n" +
				"}\n",
			};
		runner.runConformTest();
		
		runner.shouldFlushOutputDirectory = false;
		runner.testFiles =
			new String[] {
				"module-info.java",
				"module mod2 {\n" +
				"	requires mod0;\n" +
				"	uses p1.IServiceDep;\n" +
				"	uses p1.IServiceDepSince;\n" +
				"	uses p1.IServiceTermDep;\n" +
				"	uses p1.IServiceTermDepSince;\n" +
				"}\n"
			};
		runner.expectedCompilerLog =
			"----------\n" + 
			"1. INFO in module-info.java (at line 3)\n" + 
			"	uses p1.IServiceDep;\n" + 
			"	        ^^^^^^^^^^^\n" + 
			"The type IServiceDep is deprecated\n" + 
			"----------\n" + 
			"2. INFO in module-info.java (at line 4)\n" + 
			"	uses p1.IServiceDepSince;\n" + 
			"	        ^^^^^^^^^^^^^^^^\n" + 
			"The type IServiceDepSince is deprecated since version 2\n" + 
			"----------\n" + 
			"3. WARNING in module-info.java (at line 5)\n" + 
			"	uses p1.IServiceTermDep;\n" + 
			"	        ^^^^^^^^^^^^^^^\n" + 
			"The type IServiceTermDep has been deprecated and marked for removal\n" + 
			"----------\n" + 
			"4. WARNING in module-info.java (at line 6)\n" + 
			"	uses p1.IServiceTermDepSince;\n" + 
			"	        ^^^^^^^^^^^^^^^^^^^^\n" + 
			"The type IServiceTermDepSince has been deprecated since version 3 and marked for removal\n" + 
			"----------\n";
		runner.runWarningTest();
	}
	public void testBug533063_1() throws Exception {
		INameEnvironment save = this.javaClassLib;
		try {
			List<String> limitModules = Arrays.asList("java.se", "jdk.xml.bind");
			this.javaClassLib = new CustomFileSystem(limitModules);
			Runner runner = new Runner();
			runner.testFiles = new String[] {
				"module-info.java",
				"module my.mod {\n" +
				"	requires jdk.xml.bind;\n" +
				"}\n"
			};
			if (isJRE11Plus) {
				runner.expectedCompilerLog =
					"----------\n" + 
					"1. ERROR in module-info.java (at line 2)\n" + 
					"	requires jdk.xml.bind;\n" + 
					"	         ^^^^^^^^^^^^\n" + 
					"jdk.xml.bind cannot be resolved to a module\n" + 
					"----------\n";
				runner.runNegativeTest();
			} else {
				runner.expectedCompilerLog =
					"----------\n" + 
					"1. WARNING in module-info.java (at line 2)\n" + 
					"	requires jdk.xml.bind;\n" + 
					"	         ^^^^^^^^^^^^\n" + 
					"The module jdk.xml.bind has been deprecated since version 9 and marked for removal\n" + 
					"----------\n";
				runner.runWarningTest();
			}
		} finally {
			this.javaClassLib = save;
		}
	}
	public void testBug533063_2() throws Exception {
		javacUsePathOption(" --module-path ");

		runConformTest(new String[] {
			"dont.use/module-info.java",
			"@Deprecated(forRemoval=true,since=\"9\") module dont.use {}\n"
		});
		this.moduleMap.clear(); // don't use the source module beyond this point
		Runner runner = new Runner();
		runner.shouldFlushOutputDirectory = false;
		runner.testFiles = new String[] {
			"my.mod/module-info.java",
			"module my.mod {\n" +
			"	requires dont.use;\n" +
			"}\n"
		};
		runner.expectedCompilerLog =
			"----------\n" + 
			"1. WARNING in my.mod\\module-info.java (at line 2)\n" + 
			"	requires dont.use;\n" + 
			"	         ^^^^^^^^\n" + 
			"The module dont.use has been deprecated since version 9 and marked for removal\n" + 
			"----------\n";
		runner.runWarningTest();
	}
	public void testBug534304() throws Exception {
		runNegativeTest(
			new String[] {
				"p1/C1.java",
				"package p1;\n" + 
				"\n" + 
				"import pdep.Dep1;\n" + 
				"\n" + 
				"public class C1 {\n" + 
				"	Dep1 f;\n" + 
				"}\n",
				"pdep/Dep1.java",
				"package pdep;\n" + 
				"\n" + 
				"import pmissing.CMissing;\n" + 
				"\n" + 
				"@Deprecated(since=\"13\")\n" + 
				"@CMissing\n" + 
				"public class Dep1 {\n" + 
				"\n" + 
				"}\n"
			}, 
			"----------\n" + 
			"1. WARNING in p1\\C1.java (at line 3)\n" + 
			"	import pdep.Dep1;\n" + 
			"	       ^^^^^^^^^\n" + 
			"The type Dep1 is deprecated since version 13\n" + 
			"----------\n" + 
			"2. WARNING in p1\\C1.java (at line 6)\n" + 
			"	Dep1 f;\n" + 
			"	^^^^\n" + 
			"The type Dep1 is deprecated since version 13\n" + 
			"----------\n" + 
			"----------\n" + 
			"1. ERROR in pdep\\Dep1.java (at line 3)\n" + 
			"	import pmissing.CMissing;\n" + 
			"	       ^^^^^^^^\n" + 
			"The import pmissing cannot be resolved\n" + 
			"----------\n" + 
			"2. ERROR in pdep\\Dep1.java (at line 6)\n" + 
			"	@CMissing\n" + 
			"	 ^^^^^^^^\n" + 
			"CMissing cannot be resolved to a type\n" + 
			"----------\n");
	}
	public static Class<?> testClass() {
		return Deprecated9Test.class;
	}
}

Back to the top