Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 12bc5309bd828eafe9a42341a5d77c5173224b2d (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
/*******************************************************************************
 * Copyright (c) 2008, 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.internal.builder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.Stack;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.EnumDeclaration;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.PackageDeclaration;
import org.eclipse.jdt.core.dom.TagElement;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.pde.api.tools.internal.JavadocTagManager;
import org.eclipse.pde.api.tools.internal.problems.ApiProblemFactory;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
import org.eclipse.pde.api.tools.internal.provisional.IApiJavadocTag;
import org.eclipse.pde.api.tools.internal.provisional.IApiMarkerConstants;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem;
import org.eclipse.pde.api.tools.internal.util.Util;

/**
 * Visit Javadoc comments of types and member to find API javadoc tags that are being misused
 * <br><br>
 * The logic in this class must be kept in sync with how we determine what is visible in out
 * completion proposal code
 * 
 * @see org.eclipse.pde.api.tools.ui.internal.completion.APIToolsJavadocCompletionProposalComputer
 * 
 * @since 1.0.0
 */
public class TagValidator extends ASTVisitor {

	class Item {
		String typename;
		int flags;
		boolean visible = false;
		Item(String name, int flags, boolean vis) {
			typename = name;
			this.flags = flags;
			visible = vis;
		}
	}
	
	/**
	 * backing collection of tag problems, if any
	 */
	private ArrayList fTagProblems = null;
	
	private ICompilationUnit fCompilationUnit = null;
	boolean isvisible = true;
	Stack fStack/*<Item>*/ = new Stack();
	
	/**
	 * Constructor
	 * @param parent
	 */
	public TagValidator(ICompilationUnit parent) {
		fCompilationUnit = parent;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.Javadoc)
	 */
	public boolean visit(Javadoc node) {
		ASTNode parent = node.getParent();
		if(parent != null) {
			List tags = node.tags();
			validateTags(parent, tags);
		}
		return false;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration)
	 */
	public boolean visit(AnnotationTypeDeclaration node) {
		isvisible &= !Flags.isPrivate(node.getModifiers());
		fStack.push(new Item(getTypeName(node), node.getModifiers(), isvisible));
		return true;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration)
	 */
	public void endVisit(AnnotationTypeDeclaration node) {
		fStack.pop();
		if(!fStack.isEmpty()) {
			Item item = (Item) fStack.peek();
			isvisible = item.visible;
		}
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeDeclaration)
	 */
	public boolean visit(TypeDeclaration node) {
		int flags = node.getModifiers();
		if(Flags.isPrivate(flags)) {
			isvisible &= false;
		} else {
			if(node.isMemberTypeDeclaration()) {
				isvisible &= (Flags.isPublic(flags) && Flags.isStatic(flags)) || 
						Flags.isPublic(flags) ||
						Flags.isProtected(flags) ||
						node.isInterface();
			}
			else {
				isvisible &= (!Flags.isPrivate(flags) && !Flags.isPackageDefault(flags)) || node.isInterface();
			}
		}
		fStack.push(new Item(getTypeName(node), node.getModifiers(), isvisible));
		return true;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.TypeDeclaration)
	 */
	public void endVisit(TypeDeclaration node) {
		fStack.pop();
		if(!fStack.isEmpty()) {
			Item item = (Item) fStack.peek();
			isvisible = item.visible;
		}
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.EnumDeclaration)
	 */
	public boolean visit(EnumDeclaration node) {
		int flags = node.getModifiers();
		if(node.isMemberTypeDeclaration()) {
			isvisible &= Flags.isPublic(flags);
		}
		else {
			isvisible &= !Flags.isPrivate(flags) && !Flags.isPackageDefault(flags);
		}
		fStack.push(new Item(getTypeName(node), node.getModifiers(), isvisible));
		return true;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.EnumDeclaration)
	 */
	public void endVisit(EnumDeclaration node){
		fStack.pop();
		if(!fStack.isEmpty()) {
			Item item = (Item) fStack.peek();
			isvisible = item.visible;
		}
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.CompilationUnit)
	 */
	public void endVisit(CompilationUnit node) {
		fStack.clear();
	}
	
	/**
	 * Validates the set of tags for the given parent node and the given listing of {@link TagElement}s
	 * @param node
	 * @param tags
	 */
	private void validateTags(ASTNode node, List tags) {
		if(tags.size() == 0) {
			return;
		}
		switch(node.getNodeType()) {
			case ASTNode.TYPE_DECLARATION: {
				TypeDeclaration type = (TypeDeclaration) node;
				processTypeNode(type, tags);
				break;
			}
			case ASTNode.ENUM_DECLARATION: {
				Item item = (Item) fStack.peek();
				Set supported = getSupportedTagNames(IApiJavadocTag.TYPE_ENUM, IApiJavadocTag.MEMBER_NONE);
				for (Iterator i = tags.iterator(); i.hasNext();) {
					TagElement tag = (TagElement) i.next();
					String tagname = tag.getTagName();
					if(tagname == null || !JavadocTagManager.ALL_TAGS.contains(tagname)) {
						continue;
					}
					if(!supported.contains(tagname)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.TYPE, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_an_enum);
						continue;
					}
					if(!item.visible) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.TYPE, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_enum_not_visible);
					}
				}
				break;
			}
			case ASTNode.ENUM_CONSTANT_DECLARATION: {
				Item item = (Item) fStack.peek();
				for (Iterator i = tags.iterator(); i.hasNext();) {
					TagElement tag = (TagElement) i.next();
					String tagname = tag.getTagName();
					if(tagname == null || !JavadocTagManager.ALL_TAGS.contains(tagname)) {
						continue;
					}
					processTagProblem(item.typename, 
							tag, 
							IElementDescriptor.FIELD, 
							IApiProblem.UNSUPPORTED_TAG_USE, 
							IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
							BuilderMessages.TagValidator_an_enum_constant);
				}
				break;
			}
			case ASTNode.ANNOTATION_TYPE_DECLARATION: {
				Item item = (Item) fStack.peek();
				Set supported = getSupportedTagNames(IApiJavadocTag.TYPE_ANNOTATION, IApiJavadocTag.MEMBER_NONE);
				for (Iterator i = tags.iterator(); i.hasNext();) {
					TagElement tag = (TagElement) i.next();
					String tagname = tag.getTagName();
					if(tagname == null || !JavadocTagManager.ALL_TAGS.contains(tagname)) {
						continue;
					}
					if(!supported.contains(tagname)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.TYPE, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_an_annotation);
						continue;
					}
					if(!item.visible) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.TYPE, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_annotation_not_visible);
					}
				}
				break;
			}
			case ASTNode.METHOD_DECLARATION: {
				MethodDeclaration method = (MethodDeclaration) node;
				processMethodNode(method, tags);
				break;
			}
			case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: {
				Item item = (Item) fStack.peek();
				for (Iterator i = tags.iterator(); i.hasNext();) {
					TagElement tag = (TagElement) i.next();
					String tagname = tag.getTagName();
					if(tagname == null || !JavadocTagManager.ALL_TAGS.contains(tagname)) {
						continue;
					}
					processTagProblem(item.typename, 
							tag, 
							IElementDescriptor.METHOD, 
							IApiProblem.UNSUPPORTED_TAG_USE, 
							IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
							BuilderMessages.TagValidator_an_annotation_method);
				}
				break;
			}
			case ASTNode.FIELD_DECLARATION: {
				FieldDeclaration field = (FieldDeclaration) node;
				processFieldNode(field, tags);
				break;
			}
		default:
			break;
		}
	}
		
	/**
	 * Process the tags for the given {@link TypeDeclaration} node
	 * 
	 * @param type
	 * @param tags
	 * @since 1.0.400
	 */
	void processTypeNode(TypeDeclaration type, List tags) {
		HashSet processed = new HashSet();
		Item item = (Item) fStack.peek();
		for (Iterator i = tags.iterator(); i.hasNext();) {
			TagElement tag = (TagElement) i.next();
			String tagname = tag.getTagName();
			if(tagname == null || !JavadocTagManager.ALL_TAGS.contains(tagname)) {
				continue;
			}
			if(processed.contains(tagname)) {
				processTagProblem(item.typename, 
						tag, 
						IElementDescriptor.METHOD, 
						IApiProblem.DUPLICATE_TAG_USE, 
						IApiMarkerConstants.DUPLICATE_TAG_MARKER_ID, 
						null);
			}
			else {
				Set supportedtags = getSupportedTagNames(type.isInterface() ? IApiJavadocTag.TYPE_INTERFACE : IApiJavadocTag.TYPE_CLASS, IApiJavadocTag.MEMBER_NONE);
				if(!type.isInterface()) {
					int flags = type.getModifiers();
					if(!supportedtags.contains(tagname)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.TYPE, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_a_class);
					}
					else if(Flags.isPrivate(flags)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.TYPE, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_a_private_class);
					}
					else if(Flags.isPackageDefault(flags)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.TYPE, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_a_package_default_class);
					}
					else if(Flags.isAbstract(flags) && JavadocTagManager.TAG_NOINSTANTIATE.equals(tagname)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.TYPE, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_an_abstract_class);
					}
					else if(Flags.isFinal(flags) && JavadocTagManager.TAG_NOEXTEND.equals(tagname)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.TYPE, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_a_final_class);
					}
					else if(!item.visible) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.TYPE, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_a_class_that_is_not_visible);
					}
				} else {
					if(!supportedtags.contains(tagname)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.TYPE, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_an_interface);
					}
					else if(!item.visible) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.TYPE, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_an_interface_that_is_not_visible);
					}
				}
			}
			processed.add(tagname);
		}
	}
	
	/**
	 * Processes all of the tags for the given {@link FieldDeclaration}
	 * @param field
	 * @param tags
	 * @since 1.0.400
	 */
	void processFieldNode(FieldDeclaration field, List tags) {
		HashSet processed = new HashSet();
		Item item = (Item) fStack.peek();
		for (Iterator i = tags.iterator(); i.hasNext();) {
			TagElement tag = (TagElement) i.next();
			String tagname = tag.getTagName();
			if(tagname == null || !JavadocTagManager.ALL_TAGS.contains(tagname)) {
				continue;
			}
			if(processed.contains(tagname)) {
				processTagProblem(item.typename, 
						tag, 
						IElementDescriptor.METHOD, 
						IApiProblem.DUPLICATE_TAG_USE, 
						IApiMarkerConstants.DUPLICATE_TAG_MARKER_ID, 
						null);
			}
			else {
				int pkind = getParentKind(field);
				int flags = field.getModifiers();
				boolean isprivate = Flags.isPrivate(flags);
				boolean ispackage = Flags.isPackageDefault(flags);
				Set supportedtags = getSupportedTagNames(pkind, IApiJavadocTag.MEMBER_FIELD);
				switch(pkind) {
					case IApiJavadocTag.TYPE_ANNOTATION: {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.FIELD, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_annotation_field);
						break;
					}
					case IApiJavadocTag.TYPE_ENUM: {
						if(!supportedtags.contains(tagname)) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.FIELD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									BuilderMessages.TagValidator_enum_field);
						}
						else if(isprivate) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.FIELD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									BuilderMessages.TagValidator_private_enum_field);
						}
						else if(!item.visible) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.FIELD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									BuilderMessages.TagValidator_not_visible_enum_field);
						}
						break;
					}
					case IApiJavadocTag.TYPE_INTERFACE: {
						if(!supportedtags.contains(tagname)) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.FIELD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									BuilderMessages.TagValidator_an_interface_field);
						}
						else if(!item.visible) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.FIELD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									BuilderMessages.TagValidator_not_visible_interface_field);
						}
						break;
					}
					case IApiJavadocTag.TYPE_CLASS: {
						if(!supportedtags.contains(tagname)) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.FIELD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									BuilderMessages.TagValidator_a_field);
						}
						else if(isprivate) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.FIELD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									BuilderMessages.TagValidator_private_field);
						}
						else if(ispackage) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.FIELD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									BuilderMessages.TagValidator_a_package_default_field);
						}
						else if(!item.visible) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.FIELD, 
									IApiProblem.UNSUPPORTED_TAG_USE,
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									BuilderMessages.TagValidator_a_field_that_is_not_visible);
						}
						break;
					}
					default: {
						break;
					}
				}
			}
			processed.add(tagname);
		}
	}
	
	/**
	 * Processes all of the tags for the given {@link MethodDeclaration}
	 * @param method
	 * @param tags
	 * @since 1.0.400
	 */
	void processMethodNode(MethodDeclaration method, List tags) {
		int pkind = getParentKind(method);
		int mods = method.getModifiers();
		boolean isconstructor = method.isConstructor();
		boolean isstatic = Flags.isStatic(mods);
		Item item = (Item) fStack.peek();
		Set supportedtags = getSupportedTagNames(pkind, isconstructor ? IApiJavadocTag.MEMBER_CONSTRUCTOR : IApiJavadocTag.MEMBER_METHOD);
		HashSet processed = new HashSet();
		for (Iterator i = tags.iterator(); i.hasNext();) {
			TagElement tag = (TagElement) i.next();
			String tagname = tag.getTagName();
			if(tagname == null || !JavadocTagManager.ALL_TAGS.contains(tagname)) {
				continue;
			}
			if(processed.contains(tagname)) {
				processTagProblem(item.typename, 
						tag, 
						IElementDescriptor.METHOD, 
						IApiProblem.DUPLICATE_TAG_USE, 
						IApiMarkerConstants.DUPLICATE_TAG_MARKER_ID, 
						null);
			}
			else {
				switch(pkind) {
				case IApiJavadocTag.TYPE_ENUM: {
					if(!supportedtags.contains(tagname)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.METHOD, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_an_enum_method);
					}
					else if(Flags.isPrivate(mods)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.METHOD, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_private_enum_method);
					}
					else if(Flags.isPackageDefault(mods)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.METHOD, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_a_package_default_enum);
					}
					else if(!item.visible) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.METHOD, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_not_visible_enum_method);
					}
					break;
				}
				case IApiJavadocTag.TYPE_INTERFACE: {
					if(!supportedtags.contains(tagname)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.METHOD, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_an_interface_method);
					}
					else if(!item.visible) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.METHOD, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								BuilderMessages.TagValidator_not_visible_interface_method);
					}
					break;
				}
				case IApiJavadocTag.TYPE_CLASS: {
					if(!supportedtags.contains(tagname)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.METHOD, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								isconstructor ? BuilderMessages.TagValidator_a_constructor : BuilderMessages.TagValidator_a_method);
					}
					else if(Flags.isPrivate(mods)) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.METHOD, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								isconstructor ? BuilderMessages.TagValidator_private_constructor : BuilderMessages.TagValidator_private_method);
					}
					else if(Flags.isPackageDefault(mods)) {
						if(isstatic) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.METHOD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									isconstructor ? BuilderMessages.TagValidator_static_package_constructor : BuilderMessages.TagValidator_a_static_package_default_method);
						}
						else {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.METHOD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									isconstructor ? BuilderMessages.TagValidator_a_package_default_constructor : BuilderMessages.TagValidator_a_package_default_method);
						}
					}
					else if(JavadocTagManager.TAG_NOOVERRIDE.equals(tagname)) {
						if (Flags.isFinal(mods)) {
							if(isstatic) {
								processTagProblem(item.typename, 
										tag, 
										IElementDescriptor.METHOD, 
										IApiProblem.UNSUPPORTED_TAG_USE, 
										IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
										isconstructor ? BuilderMessages.TagValidator_static_final_constructor : BuilderMessages.TagValidator_a_static_final_method);
							}
							else {
								processTagProblem(item.typename, 
										tag, 
										IElementDescriptor.METHOD, 
										IApiProblem.UNSUPPORTED_TAG_USE, 
										IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
										isconstructor ? BuilderMessages.TagValidator_final_constructor : BuilderMessages.TagValidator_a_final_method);
							}
						}
						else if(isstatic) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.METHOD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									isconstructor ? BuilderMessages.TagValidator_a_static_constructor : BuilderMessages.TagValidator_a_static_method);
						}
						else if(Flags.isFinal(getParentModifiers(method))) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.METHOD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									isconstructor ? BuilderMessages.TagValidator_constructor_in_final_class : BuilderMessages.TagValidator_a_method_in_a_final_class);
						}
						else if(!item.visible) {
							processTagProblem(item.typename, 
									tag, 
									IElementDescriptor.METHOD, 
									IApiProblem.UNSUPPORTED_TAG_USE, 
									IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
									isconstructor ? BuilderMessages.TagValidator_not_visible_constructor : BuilderMessages.TagValidator_a_method_that_is_not_visible);
						}
					}
					else if(!item.visible) {
						processTagProblem(item.typename, 
								tag, 
								IElementDescriptor.METHOD, 
								IApiProblem.UNSUPPORTED_TAG_USE, 
								IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, 
								isconstructor ? BuilderMessages.TagValidator_not_visible_constructor : BuilderMessages.TagValidator_a_method_that_is_not_visible);
					}
					break;
				}
				default: {
					break;
				}
			}
			}
			processed.add(tagname);
		}
	}
	
	/**
	 * Returns the complete listing of supported tags for the given type and member
	 * @param type
	 * @param member
	 * @return the list of supported tag names or the {@link Collections#EMPTY_SET}, never <code>null</code>
	 * @since 1.0.400
	 */
	Set getSupportedTagNames(int type, int member) {
		IApiJavadocTag[] tags = ApiPlugin.getJavadocTagManager().getTagsForType(type, member);
		if(tags.length > 0) {
			HashSet valid = new HashSet(tags.length, 1);
			for (int i = 0; i < tags.length; i++) {
				valid.add(tags[i].getTagName());
			}
			return valid;
		}
		return Collections.EMPTY_SET;
	}
	
	/**
	 * Returns the modifiers from the smallest enclosing type containing the given node
	 * @param node
	 * @return the modifiers for the smallest enclosing type or 0
	 */
	private int getParentModifiers(ASTNode node) {
		if(node == null) {
			return 0;
		}
		if(node instanceof AbstractTypeDeclaration) {
			AbstractTypeDeclaration type = (AbstractTypeDeclaration) node;
			return type.getModifiers();
		}
		return getParentModifiers(node.getParent());
	}
	
	/**
	 * Returns the fully qualified name of the enclosing type for the given node
	 * @param node
	 * @return the fully qualified name of the enclosing type
	 */
	private String getTypeName(ASTNode node) {
		return getTypeName(node, new StringBuffer());
	}
	
	/**
	 * Constructs the qualified name of the enclosing parent type
	 * @param node the node to get the parent name for
	 * @param buffer the buffer to write the name into
	 * @return the fully qualified name of the parent 
	 */
	private String getTypeName(ASTNode node, StringBuffer buffer) {
		switch(node.getNodeType()) {
			case ASTNode.COMPILATION_UNIT : {
				CompilationUnit unit = (CompilationUnit) node;
				PackageDeclaration packageDeclaration = unit.getPackage();
				if (packageDeclaration != null) {
					buffer.insert(0, '.');
					buffer.insert(0, packageDeclaration.getName().getFullyQualifiedName());
				}
				return String.valueOf(buffer);
			}
			default : {
				if (node instanceof AbstractTypeDeclaration) {
					AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) node;
					if (typeDeclaration.isPackageMemberTypeDeclaration()) {
						buffer.insert(0, typeDeclaration.getName().getIdentifier());
					}
					else {
						buffer.insert(0, typeDeclaration.getName().getFullyQualifiedName());
						buffer.insert(0, '$');
					}
				}
			}
		}
		return getTypeName(node.getParent(), buffer);
	}

	/**
	 * Creates a new {@link IApiProblem} for the given tag and adds it to the cache
	 * @param tag
	 * @param element
	 * @param context
	 */
	private void processTagProblem(String typeName, TagElement tag, int element, int kind, int markerid, String context) {
		if(fTagProblems == null) {
			fTagProblems = new ArrayList(10);
		}
		int charstart = tag.getStartPosition();
		int charend = charstart + tag.getTagName().length();
		int linenumber = -1;
		try {
			// unit cannot be null
			IDocument document = Util.getDocument(fCompilationUnit);
			linenumber = document.getLineOfOffset(charstart);
		} 
		catch (BadLocationException e) {} 
		catch (CoreException e) {}
		try {
			IApiProblem problem = ApiProblemFactory.newApiProblem(fCompilationUnit.getCorrespondingResource().getProjectRelativePath().toPortableString(),
					typeName,
					new String[] {tag.getTagName(), context},
					new String[] {IApiMarkerConstants.API_MARKER_ATTR_ID, IApiMarkerConstants.MARKER_ATTR_HANDLE_ID}, 
					new Object[] {new Integer(markerid), fCompilationUnit.getHandleIdentifier()}, 
					linenumber,
					charstart,
					charend,
					IApiProblem.CATEGORY_USAGE,
					element,
					kind,
					IApiProblem.NO_FLAGS);
			
			fTagProblems.add(problem);
		} 
		catch (JavaModelException e) {}
	}
	
	/**
	 * Returns the {@link IApiJavadocTag} kind of the parent {@link ASTNode} for the given 
	 * node or -1 if the parent is not found or not a {@link TypeDeclaration}
	 * @param node
	 * @return the {@link IApiJavadocTag} kind of the parent or -1
	 */
	private int getParentKind(ASTNode node) {
		if(node == null) {
			return -1;
		}
		if(node instanceof TypeDeclaration) {
			return ((TypeDeclaration)node).isInterface() ? IApiJavadocTag.TYPE_INTERFACE : IApiJavadocTag.TYPE_CLASS;
		}
		else if(node instanceof AnnotationTypeDeclaration) {
			return IApiJavadocTag.TYPE_ANNOTATION;
		}
		else if(node instanceof EnumDeclaration) {
			return IApiJavadocTag.TYPE_ENUM;
		}
		return getParentKind(node.getParent());
	}
	
	/**
	 * Returns the complete listing of API tag problems found during the scan or 
	 * an empty array, never <code>null</code>
	 * @return the complete listing of API tag problems found
	 */
	public IApiProblem[] getTagProblems() {
		if(fTagProblems == null) {
			return new IApiProblem[0];
		}
		return (IApiProblem[]) fTagProblems.toArray(new IApiProblem[fTagProblems.size()]);
	}
}

Back to the top