KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > aval > annotations > jwsValImpl > ValidOnewayValidator


1 package spoon.aval.annotations.jwsValImpl;
2
3 import java.util.List JavaDoc;
4
5 import javax.jws.WebParam;
6
7 import spoon.aval.Validator;
8 import spoon.aval.annotations.jwsVal.ValidOneway;
9 import spoon.aval.processing.ValidationPoint;
10 import spoon.processing.Severity;
11 import spoon.reflect.declaration.CtMethod;
12 import spoon.reflect.declaration.CtParameter;
13
14 public class ValidOnewayValidator implements Validator<ValidOneway> {
15
16     public void check(ValidationPoint<ValidOneway> vp) {
17         if (vp.getProgramElement() instanceof CtMethod) {
18             CtMethod<?> oneway = (CtMethod<?>) vp.getProgramElement();
19
20             boolean isVoid = oneway.getType().equals(
21                     oneway.getFactory().Type().createReference(void.class));
22             boolean declaresExceptions = !oneway.getThrownTypes().isEmpty();
23             CtParameter<?> OUTorINOUTParams = hasINorINOUTParams(oneway);
24
25             if (!isVoid) {
26                 ValidationPoint.report(Severity.ERROR, oneway,
27                         "Oneway operations must have no return value");
28             }
29
30             if (declaresExceptions) {
31                 ValidationPoint.report(Severity.ERROR, oneway,
32                         "Oneway operations must not throw checked Exceptions");
33             }
34
35             if (OUTorINOUTParams != null) {
36                 ValidationPoint
37                         .report(Severity.ERROR, OUTorINOUTParams,
38                                 "Parameters in Oneway operations must not be OUT or INOUT");
39             }
40
41         }
42
43     }
44
45     private CtParameter<?> hasINorINOUTParams(CtMethod<?> oneway) {
46         List JavaDoc<CtParameter<?>> params = oneway.getParameters();
47
48         for (CtParameter<?> parameter : params) {
49             WebParam ann = parameter.getAnnotation(WebParam.class);
50             if (ann == null)
51                 continue;
52 //TODO: uncomment when bug Spoon is fixed
53
// if (ann.mode() == WebParam.Mode.OUT
54
// || ann.mode() == WebParam.Mode.INOUT) {
55
// return parameter;
56
// }
57

58         }
59
60         return null;
61     }
62
63 }
64
Popular Tags