01: package spoon.vsuite.common;
02:
03: import spoon.processing.AbstractProcessor;
04: import spoon.processing.Property;
05: import spoon.processing.Severity;
06: import spoon.reflect.declaration.CtExecutable;
07: import spoon.reflect.declaration.CtField;
08: import spoon.reflect.declaration.CtInterface;
09: import spoon.reflect.declaration.CtMethod;
10: import spoon.reflect.declaration.CtModifiable;
11: import spoon.reflect.declaration.CtNamedElement;
12: import spoon.reflect.declaration.CtSimpleType;
13: import spoon.reflect.declaration.ModifierKind;
14: import spoon.reflect.reference.CtExecutableReference;
15: import spoon.reflect.reference.CtTypeReference;
16:
17: /**
18: * Report warnings when undocumented elements are found.
19: */
20: public class DocProcessor extends AbstractProcessor<CtNamedElement> {
21:
22: @Property
23: Severity level = Severity.WARNING;
24:
25: public void process(CtNamedElement element) {
26: if (element instanceof CtSimpleType
27: || element instanceof CtField
28: || element instanceof CtExecutable) {
29: if (shouldBeDocumented(element)) {
30: if (element.getDocComment() == null
31: || element.getDocComment().equals("")) {
32: if ((element instanceof CtMethod)
33: && isInterfaceDocumented((CtExecutableReference<?>) element
34: .getReference())) {
35: return;
36: }
37: getEnvironment().report(
38: this ,
39: level,
40: element,
41: "Undocument element: "
42: + element.getSignature());
43: }
44: }
45: }
46: }
47:
48: private boolean shouldBeDocumented(CtNamedElement element) {
49: if (((CtModifiable) element).getModifiers().contains(
50: ModifierKind.PUBLIC)
51: || ((CtModifiable) element).getModifiers().contains(
52: ModifierKind.PROTECTED)) {
53: return true;
54: }
55: if (element instanceof CtMethod
56: && element.getParent() instanceof CtInterface) {
57: return true;
58: }
59: return false;
60: }
61:
62: private boolean isInterfaceDocumented(CtExecutableReference<?> m) {
63: for (CtTypeReference<?> r : m.getDeclaringType()
64: .getSuperInterfaces()) {
65: for (CtExecutableReference<?> im : r.getAllExecutables()) {
66: if (m.isOverriding(im)) {
67: CtExecutable<?> e = m.getDeclaration();
68: if (e != null && e.getDocComment() != null
69: && !e.getDocComment().equals("")) {
70: return true;
71: }
72: }
73: }
74: }
75: return false;
76: }
77:
78: }
|