Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3da69468a7fb09cd11c240b826ac7901288e2fee (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
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
/*******************************************************************************
 * Copyright (c) 2007, 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.pde.api.tools.model.tests;

import java.util.Map;

import junit.framework.TestCase;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.pde.api.tools.internal.ApiDescription;
import org.eclipse.pde.api.tools.internal.CompilationUnit;
import org.eclipse.pde.api.tools.internal.model.ArchiveApiTypeContainer;
import org.eclipse.pde.api.tools.internal.model.DirectoryApiTypeContainer;
import org.eclipse.pde.api.tools.internal.provisional.Factory;
import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations;
import org.eclipse.pde.api.tools.internal.provisional.IApiDescription;
import org.eclipse.pde.api.tools.internal.provisional.RestrictionModifiers;
import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers;
import org.eclipse.pde.api.tools.internal.provisional.model.ApiTypeContainerVisitor;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiElement;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;
import org.eclipse.pde.api.tools.internal.provisional.scanner.TagScanner;

import com.ibm.icu.text.MessageFormat;

/**
 * Class tests that the tag scanner for the API tools correctly scans source 
 * for API tags
 * 
 * @since 1.0.0
 */
@SuppressWarnings("unchecked")
public class TagScannerTests extends TestCase {

	private static final IPath SRC_LOC = TestSuiteHelper.getPluginDirectoryPath().append("test-source");
	private static final IPath BIN_LOC = TestSuiteHelper.getPluginDirectoryPath().append("test-classes");
	
	/**
	 * Creates a new empty API component description, not owned by any component.
	 * 
	 * @return
	 */
	protected IApiDescription newDescription() {
		return new ApiDescription(null);
	}
	
	/**
	 * Creates a new {@link ArchiveApiTypeContainer} on the given path
	 * @param path
	 * @return
	 */
	protected IApiTypeContainer newArchiveClassFileContainer(IPath path) {
		return new ArchiveApiTypeContainer(null, path.toOSString());
	}
	
	/**
	 * Returns a new compilation unit on the standard test source path with the
	 * specified name appended
	 * @param name
	 * @return a new compilation unit
	 */
	private CompilationUnit getCompilationUnit(String name) {
		Path path = (Path)SRC_LOC.append(name);
		return new CompilationUnit(path.toOSString());
	}
	
	/**
	 * Performs the scan to populate the manifest and traps exceptions thrown from the scanner
	 * @param name
	 * @param manifest
	 * @param cfc
	 */
	protected void doScan(String name, IApiDescription manifest, IApiTypeContainer cfc) {
		try {
			TagScanner.newScanner().scan(getCompilationUnit(name), manifest, cfc, null, null);
		}
		catch(CoreException e) {
			fail(MessageFormat.format("Error scanning: {0}", new Object[] {name}));
		}
	}
	
	/**
	 * Performs the scan to populate the manifest and traps exceptions thrown from the scanner
	 * @param name
	 * @param manifest
	 */
	protected void doScan(String name, IApiDescription manifest) {
		try {
			TagScanner.newScanner().scan(getCompilationUnit(name), manifest, null, null, null);
		}
		catch(CoreException e) {
			fail(MessageFormat.format("Error scanning: {0}", new Object[] {name}));
		}
	}
	
	/**
	 * Performs the scan to populate the manifest and traps exceptions thrown from the scanner
	 * @param name
	 * @param manifest
	 * @param cfc
	 */
	protected void doScan(String name, IApiDescription manifest, Map options) {
		try {
			TagScanner.newScanner().scan(getCompilationUnit(name), manifest, null, options, null);
		}
		catch(CoreException e) {
			fail(MessageFormat.format("Error scanning: {0}", new Object[] {name}));
		}
	}
	/**
	 * Tests that methods with non-simple type parameters have their signatures resolved if a backing class file 
	 * is provided (via an {@link IApiTypeContainer})
	 */
	public void testBug212276() {
		DirectoryApiTypeContainer container = new DirectoryApiTypeContainer(null, BIN_LOC.toOSString());
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod10.java", manifest, container);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod10", "one", "(Ljava/lang/String;Ljava/lang/Integer;)V"));
		assertTrue("There should exist a description for method 'void one(String, Integer)'", description != null);
		assertTrue("There should be API visibility for method 'void one(String, Integer)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one(String, Integer)'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod10", "two", "(Ljava/util/List;Ljava/lang/Runnable;)V"));
		assertTrue("There should exist a description for method 'void two(List, Runnable)'", description != null);
		assertTrue("There should be API visibility for method 'void two(List, Runnable)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'void two(List, Runnable)'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod10", "one", "(Ljava/lang/Object;Ljava/lang/Integer;)V"));
		assertTrue("There should exist a description for method 'void one(Object, Integer)'", description != null);
		assertTrue("There should be API visibility for method 'void one(Object, Integer)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction and no override restriction on method 'void one(Object, Integer)'", description.getRestrictions() == (RestrictionModifiers.NO_OVERRIDE | RestrictionModifiers.NO_REFERENCE));
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod10", "one", "([[Ljava/lang/String;Ljava/lang/Integer;)V"));
		assertTrue("There should exist a description for method 'void one(String[][], Integer)'", description != null);
		assertTrue("There should be API visibility for method 'void one(String[][], Integer)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'void one(String[][], Integer)'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
	}
	
	/**
	 * Tests that when given a class file container and the class file is not found
	 * and is required to resolve a method signature, an exception is thrown.
	 */
	public void testMissingClassfile() {
		IApiTypeContainer container = new IApiTypeContainer() {
			public String[] getPackageNames() throws CoreException {
				return new String[]{"there.are.none"};
			}
			public IApiTypeRoot findTypeRoot(String qualifiedName, String id) throws CoreException {
				return null;
			}
			public IApiTypeRoot findTypeRoot(String qualifiedName) throws CoreException {
				return null;
			}
			public void close() throws CoreException {
			}
		
			public void accept(ApiTypeContainerVisitor visitor) throws CoreException {
			}
			public IApiElement getAncestor(int ancestorType) {
				return null;
			}
			public String getName() {
				return "test container";
			}
			public IApiElement getParent() {
				return null;
			}
			public int getType() {
				return IApiElement.API_TYPE_CONTAINER;
			}
			public IApiComponent getApiComponent() {
				return null;
			}
			public int getContainerType() {
				return 0;
			}
		};
		IApiDescription manifest = newDescription();
		try { 
			TagScanner.newScanner().scan(getCompilationUnit("a/b/c/TestMethod10.java"), manifest, container, null, null);
		} catch (CoreException e) {
			fail("Should not be a core exception for missing class file");
		}
		return;
	}	
	
	/**
	 * Tests that a source file with one type which has javadoc tags
	 * is scanned correctly. Scans the file <code>TestClass1</code>
	 */
	public void testSingleTypeDefaultPackage() {	
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestClass1.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass1"));
		assertNotNull("the description for TestClass1 should exist", description);
		assertTrue("There should be no instantiate on TestClass1", description.getRestrictions() == RestrictionModifiers.NO_INSTANTIATE);
		assertTrue("TestClass1 should have API visibility", description.getVisibility() == VisibilityModifiers.API);
	}
	
	/**
	 * Tests that a source file with one type which has javadoc tags and contains 
	 * one inner static type with tags is scanned correctly. 
	 * Scans the file <code>TestClass2</code> 
	 */
	public void testSingleInnerStaticTypeDefaultPackage() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestClass2.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass2"));
		assertNotNull("the description for TestClass2 should exist", description);
		assertTrue("There should be no subclass on TestClass2", description.getRestrictions() == RestrictionModifiers.NO_EXTEND);
		assertTrue("TestClass2 should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass2$InnerTestClass2"));
		assertNotNull("the description for TestClass2$InnerTestClass2 should exist", description);
		assertTrue("There should be no subclass or instantiate on TestClass2$InnerTestClass2", description.getRestrictions() == (RestrictionModifiers.NO_EXTEND | RestrictionModifiers.NO_INSTANTIATE));
		assertTrue("TestClass2$InnerTestClass2 should have API visibility", description.getVisibility() == VisibilityModifiers.API);
	}
	
	/**
	 * Tests that a source file with one type which has javadoc tags and contains 
	 * one inner static type with tags is scanned correctly. 
	 * Scans the file <code>TestClass3</code> 
	 */
	public void testSingleInnerTypeDefaultPackage() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestClass3.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass3"));
		assertNull("the description for TestClass3 should not exist", description);
		
		// Prior to bug 402393 annotations were supported on package default restricted classes
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass3$InnerTestClass3"));
		assertNull("the description for TestClass3$InnerTestClass3 should not exist", description);
	}
	
	/**
	 * Tests that a source file with one type which has javadoc tags and contains 
	 * more than one nested inner static type with tags is scanned correctly. 
	 * Scans the file <code>TestClass4</code> 
	 */
	public void testMultiNestedInnerTypeDefaultPackage() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestClass4.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass4"));
		assertNull("the description for TestClass4 should not exist", description);
		
		// Prior to bug 402393 annotations were supported on package default restricted classes
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass4$InnerTestClass4"));
		assertNull("the description for TestClass4$InnerTestClass4 should not exist", description);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass4$InnerTestClass4$Inner2TestClass4"));
		assertNull("the description for TestClass4$InnerTestClass4$Inner2TestClass4 should not exist", description);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass4$InnerTestClass4$Inner2TestClass4$Inner3TestClass4"));
		assertNull("the description for TestClass4$InnerTestClass4$Inner2TestClass4$Inner3TestClass4 should not exist", description);
	}
	
	/**
	 * Tests that a source file with more than one type which has javadoc tags
	 * Scans the file <code>TestClass5</code> 
	 */
	public void testMultiTypeDefaultPackage() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestClass5.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass5"));
		assertNull("the description for TestClass5 should not exist", description);
		
		// Prior to bug 402393 annotations were supported on package default restricted classes
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass5a"));
		assertNull("the description for TestClass5a should not exist", description);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass5b"));
		assertNull("the description for TestClass5b should not exist", description);
	}
	
	/**
	 * Tests that a source file with one type which has javadoc tags and contains 
	 * more than one inner type with tags is scanned correctly. 
	 * Scans the file <code>TestClass6</code> 
	 */
	public void testMultiInnerTypeDefaultPackage() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestClass6.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass6"));
		assertNotNull("the description for TestClass6 should exist", description);
		assertTrue("There should be no restrictions on TestClass6", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		assertTrue("TestClass6 should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass6$InnerTestClass6a"));
		assertNotNull("the description for TestClass6$InnerTestClass6a should exist", description);
		assertTrue("There should be no subclass on TestClass6$InnerTestClass6a", description.getRestrictions() == RestrictionModifiers.NO_EXTEND);
		assertTrue("TestClass6$InnerTestClass6a should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass6$InnerTestClass6b"));
		assertNotNull("the description for TestClass6$InnerTestClass6b should exist", description);
		assertTrue("There should be no instantiate on TestClass6$InnerTestClass6b", description.getRestrictions() == RestrictionModifiers.NO_INSTANTIATE);
		assertTrue("TestClass6$InnerTestClass6b should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass6$InnerTestClass6c"));
		assertNotNull("the description for TestClass6$InnerTestClass6c should exist", description);
		assertTrue("There should be no restrictions on TestClass6$InnerTestClass6c", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		assertTrue("TestClass6$InnerTestClass6c should have API visibility", description.getVisibility() == VisibilityModifiers.API);
	}
	
	/**
	 * Tests that a source file with more than one type which has javadoc tags and contains 
	 * more than one inner type with tags is scanned correctly. 
	 * Scans the file <code>TestClass7</code> 
	 */
	public void testMultiTypeMultiInnerTypeDefatulPackage() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestClass7.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass7"));
		assertNotNull("the description for TestClass7 should exist", description);
		assertTrue("There should be no restrictions on TestClass7", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		assertTrue("TestClass7 should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass7$InnerTestClass7"));
		assertNotNull("the description for TestClass7$InnerTestClass7 should exist", description);
		assertTrue("There should be no restrictions on TestClass7$InnerTestClass7", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		assertTrue("TestClass7$InnerTestClass7 should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass7$InnerTestClass7$Inner2TestClass7"));
		assertNotNull("the description for TestClass7$InnerTestClass7$Inner2TestClass7 should exist", description);
		assertTrue("There should be no subclass on TestClass7$InnerTestClass7$Inner2TestClass7", description.getRestrictions() == RestrictionModifiers.NO_EXTEND);
		assertTrue("TestClass7$InnerTestClass7$Inner2TestClass7 should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass7a"));
		assertNotNull("the description for TestClass7a should exist", description);
		assertTrue("There should be no restrictions on TestClass7a", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		assertTrue("TestClass7a should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass7a$InnerTestClass7a"));
		//Bug 402393 - The description returned is for the parent element
		//and is expected because the parent has a restricted sub-type
		assertNotNull("the description for TestClass7a$InnerTestClass7a should exist", description);
		assertTrue("There should be no restrictions on TestClass7a$InnerTestClass7a", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		assertTrue("TestClass7a$InnerTestClass7a should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass7b"));
		assertNotNull("the description for TestClass7b should exist", description);
		assertTrue("There should be no restrictions on TestClass7b", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		assertTrue("TestClass7b should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass7b$InnerTestClass7b"));
		assertNotNull("the description for TestClass7b$InnerTestClass7b should exist", description);
		assertTrue("There should be no restrictions on TestClass7b$InnerTestClass7b", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		assertTrue("TestClass7b$InnerTestClass7b should have API visibility", description.getVisibility() == VisibilityModifiers.API);
	}
	
	/**
	 * Tests that a source file with one interface declaration is scanned correctly. 
	 * Scans the file <code>TestInterface1</code> 
	 */
	public void testInterfaceDefaultPackage() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestInterface1.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestInterface1"));
		assertNotNull("the description for TestInterface1 should exist", description);
		assertTrue("There should be no implement on TestInterface1", description.getRestrictions() == RestrictionModifiers.NO_IMPLEMENT);
		assertTrue("TestInterface1 should have API visibility", description.getVisibility() == VisibilityModifiers.API);
	}
	
	/**
	 * Tests that a source file with more than one interface declaration is scanned correctly. 
	 * Scans the file <code>TestInterface2</code> 
	 */
	public void testMultiInterfaceDefaultPackage() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestInterface2.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestInterface2"));
		assertNull("the description for TestInterface2 should not exist", description);
		
		// Prior to bug 402393 annotations were supported on package default restricted classes
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestInterface2a"));
		assertNull("the description for TestInterface2a should not exist", description);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestInterface2b"));
		assertNull("the description for TestInterface2b should not exist", description);
	}
	
	/**
	 * Tests that a source file with one interface declaration and a single nested interface is scanned correctly. 
	 * Scans the file <code>TestInterface3</code> 
	 */
	public void testSingleInnerInterfaceDefaultPackage() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestInterface3.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestInterface3"));
		assertNotNull("the description for TestInterface3 should exist", description);
		assertTrue("There should be no restrictions on TestInterface3", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		assertTrue("TestInterface3 should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestInterface3$Inner1"));
		assertNotNull("the description for TestInterface3$Inner1 should exist", description);
		assertTrue("There should be no implement on TestInterface3$Inner1", description.getRestrictions() == RestrictionModifiers.NO_IMPLEMENT);
		assertTrue("TestInterface3$Inner1 should have API visibility", description.getVisibility() == VisibilityModifiers.API);
	}
	
	/**
	 * Tests that a source file with one interface declaration and multi nested interfaces are scanned correctly. 
	 * Scans the file <code>TestInterface4</code> 
	 */
	public void testMultiInnerInterfaceDefaultPackage() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestInterface4.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestInterface4"));
		assertNotNull("the description for TestInterface4 should exist", description);
		assertTrue("There should be no restrictions on TestInterface4", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		assertTrue("TestInterface3 should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestInterface4$Inner1"));
		assertNotNull("the description for TestInterface4$Inner1 should exist", description);
		assertTrue("There should be no implement on TestInterface4$Inner1", description.getRestrictions() == RestrictionModifiers.NO_IMPLEMENT);
		assertTrue("TestInterface3$Inner1 should have API visibility", description.getVisibility() == VisibilityModifiers.API);
		description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestInterface4$Inner2"));
		
		//Bug 402393 - The description returned is for the parent element
		//and is expected because the root type has a restricted sub-type
		assertNotNull("the description for TestInterface4$Inner2 should exist", description);
		assertTrue("The root type should be unrestricted", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
	}
	
	/**
	 * Tests that source tags are added/collected properly for fields in a base public class.
	 * Scans the file <code>TestField1</code>
	 */
	public void testFieldBaseClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestField1.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField1", "field"));
		assertNotNull("the description for field 'field' in TestField1 should exist", description);
		assertTrue("there shouldbe API visibility on field 'field'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be no reference on field 'field'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
	}
	
	/**
	 * Tests that the source tags are added/collected properly for fields that have no restriction tags, but the parent class does.
	 * Scans the file <code>TestField7</code>
	 */
	public void testFieldBaseClassInheritedNotSupported() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestField7.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField7", "field1"));
		assertNotNull("the description for field 'field1' in TestField7 should exist", description);
		assertEquals("there shouldbe API visibility on field 'field1'", VisibilityModifiers.API, description.getVisibility());
		assertEquals("There should be no restrictions on field 'field1'", RestrictionModifiers.NO_RESTRICTIONS, description.getRestrictions());
	}
	
	/**
	 * Tests that the source tags are added/collected properly for fields that have no restriction tags, but the parent class does.
	 * Scans the file <code>TestField8</code>
	 */
	public void testFieldBaseClassInheritedSupported() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestField8.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField8", "field1"));
		assertNotNull("the description for field 'field1' in TestField8 should exist", description);
		assertTrue("there shouldbe API visibility on field 'field1'", description.getVisibility() == VisibilityModifiers.API);
	}
	
	/**
	 * Tests that source tags are added/collected properly for fields in an inner class.
	 * Scans the file <code>TestField2</code>
	 */
	public void testFieldInnerClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestField2.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField2$Inner", "field"));
		assertNull("the description for field 'field' in TestField2$Inner should not exist", description);
		
		// Prior to bug 402393 annotations were supported on package default restricted classes
		description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField2$Inner", "number"));
		assertNull("the description for field 'number' in TestField2$Inner should not exist", description);
	}
	
	/**
	 * Tests that source tags are added/collected properly for fields in a static inner class.
	 * Scans the file <code>TestField3</code>
	 */
	public void testFieldStaticInnerClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestField3.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField3$Inner", "field"));
		assertNotNull("the description for field 'field' in TestField3$Inner should exist", description);
		assertTrue("there shouldbe API visibility on field 'field'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be no reference on field 'field'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField3$Inner", "number"));
		assertNotNull("the description for field 'number' in TestField3$Inner should exist", description);
		assertTrue("there shouldbe API visibility on field 'number'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be no reference on field 'number'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for fields in multiple inner classes.
	 * Scans the file <code>TestField4</code>
	 */
	public void testFieldMultiInnerClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestField4.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField4$Inner1", "field"));
		assertNotNull("the description for field 'field' in TestField4$Inner1 should exist", description);
		assertTrue("there shouldbe API visibility on field 'field' in TestField4$Inner1", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be no reference on field 'field' in TestField4$Inner1", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField4$Inner1$Inner3", "field"));
		assertNotNull("the description for field 'field' in TestField4$Inner1$Inner3 should exist", description);
		assertTrue("there shouldbe API visibility on field 'field' in TestField4$Inner1$Inner3", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be no reference on field 'field' in TestField4$Inner1$Inner3", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField4$Inner1$Inner3$Inner", "number"));
		assertNotNull("the description for field 'number' in TestField4$Inner1$Inner3$Inner should exist", description);
		assertTrue("there shouldbe API visibility on field 'number' in TestField4$Inner1$Inner3$Inner", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be no reference on field 'number' in TestField4$Inner1$Inner3$Inner", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField4$Inner2", "field"));
		assertNotNull("the description for field 'field' in TestField4$Inner2 should exist", description);
		assertTrue("there should be API visibility on field 'field' in TestField4$Inner2", description.getVisibility() == VisibilityModifiers.API);
	}
	
	/**
	 * Tests that source tags are added/collected properly for fields in an outer class.
	 * Scans the file <code>TestField5</code>
	 */
	public void testFieldOuterClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestField5.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField5Outer", "field"));
		assertNull("the description for field 'field' in a.b.c.TestField5 should not exist", description);
	}
	
	/**
	 * Tests that source tags are added/collected properly for fields in an anonymous class.
	 * Scans the file <code>TestField6</code>
	 */
	public void testFieldAnonymousClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestField6.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField6", "number"));
		assertNotNull("the description for field 'number' in a.b.c.TestField6 should exist", description);
		assertTrue("there shouldbe API visibility on field 'number' in a.b.c.TestField6", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be no reference on field 'number' in a.b.c.TestField6", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a base public class.
	 * Scans the file <code>TestMethod1</code>
	 */
	public void testMethodBaseClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod1.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod1", "one", "()V"));
		assertTrue("There should exist a description for method 'void one()'", description != null);
		assertTrue("There should be API visibility for method 'void one()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one()'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod1", "two", "()V"));
		assertTrue("There should exist a description for method 'void two()'", description != null);
		assertTrue("There should be API visibility for method 'void two()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'void two()'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod1", "three", "()V"));
		assertTrue("There should exist a description for method 'void three()'", description != null);
		assertTrue("There should be API visibility for method 'void three()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void three()'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a base public class
	 * with a single Object parameter.
	 * Scans the file <code>TestMethod7</code>
	 */
	public void testMethodSingleParam() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod7.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod7", "one", "(QString;)V"));
		assertTrue("There should exist a description for method 'void one(String)'", description != null);
		assertTrue("There should be API visibility for method 'void one(String)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one(String)'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a base public class
	 * with a single primitive parameter.
	 * Scans the file <code>TestMethod8</code>
	 */
	public void testMethodSinglePrimitiveParam() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod8.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod8", "one", "(I)V"));
		assertTrue("There should exist a description for method 'void one(int)'", description != null);
		assertTrue("There should be API visibility for method 'void one(int)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'void one(int)'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a base public class
	 * with primitive parameters.
	 * Scans the file <code>TestMethod9</code>
	 */
	public void testMethodPrimitiveParams() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod9.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod9", "one", "(IDF)V"));
		assertTrue("There should exist a description for method 'void one(int, double , float)'", description != null);
		assertTrue("There should be API visibility for method 'void one(int, double , float)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one(int, double , float)'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod9", "two", "(DF)V"));
		assertTrue("There should exist a description for method 'void two(double, float)'", description != null);
		assertTrue("There should be API visibility for method 'void two(double, float)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'void two(double, float)'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
		
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a base public class
	 * with Object parameters.
	 * Scans the file <code>TestMethod10</code>
	 */
	public void testMethodObjectParams() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod10.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod10", "one", "(QString;QInteger;)V"));
		assertTrue("There should exist a description for method 'void one(String, Integer)'", description != null);
		assertTrue("There should be API visibility for method 'void one(String, Integer)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one(String, Integer)'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod10", "two", "(QList;QRunnable;)V"));
		assertTrue("There should exist a description for method 'void two(List, Runnable)'", description != null);
		assertTrue("There should be API visibility for method 'void two(List, Runnable)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'void two(List, Runnable)'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a base public class
	 * with primitive array parameters.
	 * Scans the file <code>TestMethod11</code>
	 */
	public void testMethodPrimitiveArrayParams() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod11.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod11", "one", "([I[[C)V"));
		assertTrue("There should exist a description for method 'void one(int[], char[][])'", description != null);
		assertTrue("There should be API visibility for method 'void one(int[], char[][])'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one(int[], char[][])'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod11", "two", "([[F[D)V"));
		assertTrue("There should exist a description for method 'void two(float[][], double[])'", description != null);
		assertTrue("There should be API visibility for method 'void two(float[][], double[])'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'void two(float[][], double[])'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a base public class
	 * with Object array parameters.
	 * Scans the file <code>TestMethod12</code>
	 */
	public void testMethodObjectArrayParams() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod12.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod12", "one", "([QString;[[QDouble;)V"));
		assertTrue("There should exist a description for method 'void one(String[], Double[][])'", description != null);
		assertTrue("There should be API visibility for method 'void one(String[], Double[][])'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one(String[], Double[][])'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod12", "two", "([[QList;[QRunnable;)V"));
		assertTrue("There should exist a description for method 'void two(List[][], Runnable[])'", description != null);
		assertTrue("There should be API visibility for method 'void two(List[][], Runnable[])'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'void two(List[][], Runnable[])'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a base public class
	 * with a mix of  parameters.
	 * Scans the file <code>TestMethod13</code>
	 */
	public void testMethodMixedParams() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod13.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod13", "one", "(I[[QDouble;[CQInteger;)V"));
		assertTrue("There should exist a description for method 'void one(int, Double[][], char[], Integer)'", description != null);
		assertTrue("There should be API visibility for method 'void one(int, Double[][], char[], Integer)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one(int, Double[][], char[], Integer)'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod13", "two", "([[QList;DC[I[QRunnable;)V"));
		assertTrue("There should exist a description for method 'void two(List[][], double, char, int[], Runnable[])'", description != null);
		assertTrue("There should be API visibility for method 'void two(List[][], double, char, int[], Runnable[])'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'void two(List[][], double, char, int[], Runnable[])'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a base public class
	 * with an Object return type.
	 * Scans the file <code>TestMethod14</code>
	 */
	public void testMethodObjectReturn() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod14.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod14", "one", "(I[[QDouble;[CQInteger;)QString;"));
		assertTrue("There should exist a description for method 'String one(int, Double[][], char[], Integer)'", description != null);
		assertTrue("There should be API visibility for method 'String one(int, Double[][], char[], Integer)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'String one(int, Double[][], char[], Integer)'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod14", "two", "([[QList;DC[I[QRunnable;)QDouble;"));
		assertTrue("There should exist a description for method 'Double two(List[][], double, char, int[], Runnable[])'", description != null);
		assertTrue("There should be API visibility for method 'Double two(List[][], double, char, int[], Runnable[])'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'Double two(List[][], double, char, int[], Runnable[])'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a base public class
	 * with a primitive return type.
	 * Scans the file <code>TestMethod15</code>
	 */
	public void testMethodPrimitiveReturn() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod15.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod15", "one", "(I[[QDouble;[CQInteger;)C"));
		assertTrue("There should exist a description for method 'char one(int, Double[][], char[], Integer)'", description != null);
		assertTrue("There should be API visibility for method 'char one(int, Double[][], char[], Integer)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'char one(int, Double[][], char[], Integer)'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod15", "two", "([[QList;DC[I[QRunnable;)D"));
		assertTrue("There should exist a description for method 'double two(List[][], double, char, int[], Runnable[])'", description != null);
		assertTrue("There should be API visibility for method 'double two(List[][], double, char, int[], Runnable[])'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'double two(List[][], double, char, int[], Runnable[])'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a base public class
	 * with a primitive array return type.
	 * Scans the file <code>TestMethod17</code>
	 */
	public void testMethodPrimitiveArrayReturn() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod17.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod17", "one", "(I[[QDouble;[CQInteger;)[[C"));
		assertTrue("There should exist a description for method 'char[][] one(int, Double[][], char[], Integer)'", description != null);
		assertTrue("There should be API visibility for method 'char[][] one(int, Double[][], char[], Integer)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'char[][] one(int, Double[][], char[], Integer)'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod17", "two", "([[QList;DC[I[QRunnable;)[D"));
		assertTrue("There should exist a description for method 'double[] two(List[][], double, char, int[], Runnable[])'", description != null);
		assertTrue("There should be API visibility for method 'double[] two(List[][], double, char, int[], Runnable[])'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'double[] two(List[][], double, char, int[], Runnable[])'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a base public class
	 * with an Object array return type.
	 * Scans the file <code>TestMethod16</code>
	 */
	public void testMethodObjectArrayReturn() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod16.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod16", "one", "(I[[QDouble;[CQInteger;)[[QString;"));
		assertTrue("There should exist a description for method 'String[][] one(int, Double[][], char[], Integer)'", description != null);
		assertTrue("There should be API visibility for method 'String[][] one(int, Double[][], char[], Integer)'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'String[][] one(int, Double[][], char[], Integer)'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod16", "two", "([[QList;DC[I[QRunnable;)[QDouble;"));
		assertTrue("There should exist a description for method 'Double[] two(List[][], double, char, int[], Runnable[])'", description != null);
		assertTrue("There should be API visibility for method 'Double[] two(List[][], double, char, int[], Runnable[])'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'Double[] two(List[][], double, char, int[], Runnable[])'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in an inner class.
	 * Scans the file <code>TestMethod2</code>
	 */
	public void testMethodInnerClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod2.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod2$Inner", "one", "()V"));
		assertNull("There should be no description for method 'void one()", description);
		
		// Prior to bug 402393 annotations were supported on package default restricted classes
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod2$Inner", "two", "()V"));
		assertNull("There should not exist a description for method 'void two()'", description);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in a static inner class.
	 * Scans the file <code>TestMethod3</code>
	 */
	public void testMethodStaticInnerClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod3.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod3$Inner", "one", "()V"));
		assertTrue("There should exist a description for method 'void one()'", description != null);
		assertTrue("There should be API visibility for method 'void one()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one()'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod3$Inner", "two", "()V"));
		assertTrue("There should exist a description for method 'void two()'", description != null);
		assertTrue("There should be API visibility for method 'void two()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'void two()'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod3$Inner", "three", "()V"));
		assertTrue("There should exist a description for method 'void three()'", description != null);
		assertTrue("There should be API visibility for method 'void three()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no extend restriction on method 'void three()'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in multiple inner classes.
	 * Scans the file <code>TestMethod4</code>
	 */
	public void testMethodMultiInnerClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod4.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod4$Inner1", "one", "()V"));
		assertTrue("There should exist a description for method 'void one()'", description != null);
		assertTrue("There should be API visibility for method 'void one()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one()'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod4$Inner1", "two", "()V"));
		assertTrue("There should exist a description for method 'void two()'", description != null);
		assertTrue("There should be API visibility for method 'void two()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'void two()'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod4$Inner1", "three", "()V"));
		assertTrue("There should exist a description for method 'void three()'", description != null);
		assertTrue("There should be API visibility for method 'void three()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no extend restriction on method 'void three()'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod4$Inner1$Inner3", "one", "()V"));
		assertTrue("There should exist a description for method 'void one()'", description != null);
		assertTrue("There should be API visibility for method 'void one()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one()'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod4$Inner1$Inner3", "two", "()V"));
		assertTrue("There should exist a description for method 'void two()'", description != null);
		assertTrue("There should be API visibility for method 'void two()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no override restriction on method 'void two()'", description.getRestrictions() == RestrictionModifiers.NO_OVERRIDE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod4$Inner1$Inner3", "three", "()V"));
		assertTrue("There should exist a description for method 'void three()'", description != null);
		assertTrue("There should be API visibility for method 'void three()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no extend restriction on method 'void three()'", description.getRestrictions() == RestrictionModifiers.NO_REFERENCE);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod4$Inner2", "one", "()V"));
		//Bug 402393 - The description returned is for the parent element
		//and is expected because the parent element has a restricted sub-element
		assertNotNull("There should not exist a description for method one() in class Inner2", description);
		assertTrue("Inner2#one() must be unrestricted", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod4$Inner2", "two", "()V"));
		assertNotNull("There should exist a description for method 'void two()'", description);
		assertTrue("Inner2#two() must be unrestricted", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod4$Inner2$Inner4", "one", "()V"));
		assertNotNull("There should exist a description for method 'void one()'", description);
		assertTrue("Inner2$Inner4#one() must be unrestricted", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod4$Inner2$Inner4", "two", "()V"));
		assertNotNull("There should exist a description for method 'void two()'", description);
		assertTrue("Inner2$Inner4#two() must be unrestricted", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in an outer class.
	 * Scans the file <code>TestMethod5</code>
	 */
	public void testMethodOuterClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod5.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod5Outer", "one", "()V"));
		assertNull("The description for method 'void one()' should not exist", description);
		
		// Prior to bug 402393 annotations were supported on package default restricted classes
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod5Outer", "two", "()V"));
		assertNull("There should not exist a description for method 'void two()'", description);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod5Outer", "three", "()V"));
		assertNull("There should not exist a description for method 'void three()'", description);
	}
	
	/**
	 * Tests that source tags are added/collected properly for methods in an anonymous class.
	 * Scans the file <code>TestMethod6</code>
	 */
	public void testMethodAnonymousClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod6.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod6", "run", "()V"));
		assertTrue("There should exist a description for method 'void run()'", description != null);
		assertTrue("There should be API visibility for method 'void run()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference and no override restriction on method 'void run()'", description.getRestrictions() == (RestrictionModifiers.NO_REFERENCE | RestrictionModifiers.NO_OVERRIDE));
	}
	
	/**
	 * Tests that a method properly inherits restrictions. Restrictions are not inherited.
	 * Scans the file <code>TestMethod18</code>
	 */
	public void testMethodInheritValidRestriction() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod18.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod18", "one", "()V"));
		assertTrue("There should exist a description for method 'void one()'", description != null);
		assertTrue("There should be API visibility for method 'void one()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be no restriction on method 'void one()'", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod18Outer", "two", "()V"));
		assertTrue("There should exist a description for method 'void two()'", description != null);
		assertTrue("There should be API visibility for method 'void two()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be no restriction on method 'void two()'", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
	}
	
	/**
	 * Tests that a method properly inherits restrictions from 
	 * source tags are added/collected properly for the enclosing type of the methods.
	 * In this case the parent tags cannot be inherited, expected result is 'no restriction'
	 * Scans the file <code>TestMethod19</code>
	 */
	public void testMethodInheritInvalidRestrictionClass() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod19.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod19", "one", "()V"));
		assertTrue("There should exist a description for method 'void one()'", description != null);
		assertTrue("There should be API visibility for method 'void one()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one()'", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod19Outer", "two", "()V"));
		assertTrue("There should exist a description for method 'void two()'", description != null);
		assertTrue("There should be API visibility for method 'void two()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no extend restriction on method 'void two()'", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
	}
	
	/**
	 * Tests that a method properly inherits restrictions from 
	 * source tags are added/collected properly for the enclosing type of the methods.
	 * In this case the parent tags cannot be inherited, expected result is 'no restriction'
	 * Scans the file <code>TestField20</code>
	 */
	public void testMethodInheritInvalidRestrictionInterface() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/TestMethod20.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod20", "one", "()V"));
		assertTrue("There should exist a description for method 'void one()'", description != null);
		assertTrue("There should be API visibility for method 'void one()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no reference restriction on method 'void one()'", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
		description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestMethod20Outer", "two", "()V"));
		assertTrue("There should exist a description for method 'void two()'", description != null);
		assertTrue("There should be API visibility for method 'void two()'", description.getVisibility() == VisibilityModifiers.API);
		assertTrue("There should be a no extend restriction on method 'void two()'", description.getRestrictions() == RestrictionModifiers.NO_RESTRICTIONS);
	}
	
	/**
	 * Tests that a restriction on a @noreference constructor inside an enum class.
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=253055
	 */
	public void testEnumMethodWithNoReference() {
		IApiDescription manifest = newDescription();
		Map options = JavaCore.getDefaultOptions();
		options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
		options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
		options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
		doScan("a/b/c/TestMethod21.java", manifest, options);
	}
	
	/**
	 * Tests that invalid Javadoc tags do not get leaked into the API description
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=255222
	 */
	public void testInterfaceWithBadTags() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/InvalidTagScanInterface.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.InvalidTagScanInterface"));
		assertNotNull("there should be noreference restrictions for interface InvalidTagScanInterface", description);
		assertTrue("The restrictions for InvalidTagScanInterface should be noreference", (description.getRestrictions() & RestrictionModifiers.NO_REFERENCE) > 0);
	}
	
	/**
	 * Tests that invalid Javadoc tags do not get leaked into the API description
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=255222
	 */
	public void testClassWithBadTags1() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/InvalidTagScanClass1.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.InvalidTagScanClass1"));
		assertNotNull("there should be noreference annotations for class InvalidTagScanClass1", description);
		assertTrue("The restrictions for InvalidTagScanClass1 should be noreference", (description.getRestrictions() & RestrictionModifiers.NO_REFERENCE) > 0);
	}
	
	/**
	 * Tests that invalid Javadoc tags do not get leaked into the API description
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=255222
	 */
	public void testClassWithBadTags2() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/InvalidTagScanClass2.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.InvalidTagScanClass2"));
		assertNotNull("there should be noreference annotations for class InvalidTagScanClass2", description);
		assertTrue("The restrictions for InvalidTagScanClass2 should be noreference", (description.getRestrictions() & RestrictionModifiers.NO_REFERENCE) > 0);
	}
	
	/**
	 * Tests that invalid Javadoc tags do not get leaked into the API description
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=255222
	 */
	public void testClassWithBadTags3() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/InvalidTagScanClass3.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.typeDescriptor("a.b.c.InvalidTagScanClass3"));
		assertNotNull("there should be noreference annotations for class InvalidTagScanClass3", description);
		assertTrue("The restrictions for InvalidTagScanClass3 should be noreference", (description.getRestrictions() & RestrictionModifiers.NO_REFERENCE) > 0);
	}
	
	/**
	 * Tests that invalid Javadoc tags do not get leaked into the API description
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=255222
	 */
	public void testMethodWithBadTags1() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/InvalidTagScanMethod1.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.InvalidTagScanMethod1", "one", "()V"));
		assertNull("there should be no annotations for method 'public void one()'", description);
	}
	
	/**
	 * Tests that invalid Javadoc tags do not get leaked into the API description
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=255222
	 */
	public void testMethodWithBadTags2() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/InvalidTagScanMethod2.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.InvalidTagScanMethod2", "one", "()V"));
		assertNull("there should be no annotations for method 'public void one()'", description);
	}
	
	/**
	 * Tests that invalid Javadoc tags do not get leaked into the API description
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=255222
	 */
	public void testMethodWithBadTags3() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/InvalidTagScanMethod3.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.methodDescriptor("a.b.c.InvalidTagScanMethod3", "one", "()V"));
		assertNull("there should be no annotations for method 'public void one()'", description);
	}
	
	/**
	 * Tests that invalid Javadoc tags do not get leaked into the API description
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=255222
	 */
	public void testFieldWithBadTags1() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/InvalidTagScanField1.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.InvalidTagScanField1", "field"));
		assertNull("there should be no annotations for field 'field'", description);
	}
	
	/**
	 * Tests that invalid Javadoc tags do not get leaked into the API description
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=255222
	 */
	public void testFieldWithBadTags2() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/InvalidTagScanField2.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.InvalidTagScanField2", "field"));
		assertNull("there should be no annotations for field 'field'", description);
	}
	
	/**
	 * Tests that invalid Javadoc tags do not get leaked into the API description
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=255222
	 */
	public void testFieldWithBadTags3() {
		IApiDescription manifest = newDescription();
		doScan("a/b/c/InvalidTagScanField3.java", manifest);
		IApiAnnotations description = manifest.resolveAnnotations(Factory.fieldDescriptor("a.b.c.InvalidTagScanField3", "field"));
		assertNull("there should be no annotations for field 'field'", description);
	}
}

Back to the top