|
5 | 5 | */ |
6 | 6 | package io.jooby.compiler; |
7 | 7 |
|
| 8 | +import io.jooby.Router; |
| 9 | +import io.jooby.annotations.CONNECT; |
| 10 | +import io.jooby.annotations.Consumes; |
| 11 | +import io.jooby.annotations.CookieParam; |
| 12 | +import io.jooby.annotations.DELETE; |
| 13 | +import io.jooby.annotations.FlashParam; |
| 14 | +import io.jooby.annotations.FormParam; |
| 15 | +import io.jooby.annotations.GET; |
| 16 | +import io.jooby.annotations.HEAD; |
| 17 | +import io.jooby.annotations.HeaderParam; |
| 18 | +import io.jooby.annotations.OPTIONS; |
| 19 | +import io.jooby.annotations.PATCH; |
| 20 | +import io.jooby.annotations.POST; |
| 21 | +import io.jooby.annotations.PUT; |
| 22 | +import io.jooby.annotations.Path; |
| 23 | +import io.jooby.annotations.PathParam; |
| 24 | +import io.jooby.annotations.Produces; |
| 25 | +import io.jooby.annotations.QueryParam; |
| 26 | +import io.jooby.annotations.TRACE; |
| 27 | + |
8 | 28 | import javax.lang.model.element.AnnotationMirror; |
9 | 29 | import javax.lang.model.element.AnnotationValue; |
10 | 30 | import javax.lang.model.element.ExecutableElement; |
| 31 | +import java.util.Arrays; |
11 | 32 | import java.util.Collections; |
12 | 33 | import java.util.LinkedHashSet; |
13 | 34 | import java.util.List; |
|
21 | 42 | import static java.util.Collections.unmodifiableSet; |
22 | 43 |
|
23 | 44 | public interface Annotations { |
24 | | - String PATH = "io.jooby.annotations.Path"; |
25 | | - |
26 | | - String GET = "io.jooby.annotations.GET"; |
| 45 | + Set<String> HTTP_METHODS = unmodifiableSet(new LinkedHashSet<>(Arrays.asList( |
| 46 | + GET.class.getName(), |
| 47 | + javax.ws.rs.GET.class.getName(), |
27 | 48 |
|
28 | | - String POST = "io.jooby.annotations.POST"; |
| 49 | + POST.class.getName(), |
| 50 | + javax.ws.rs.POST.class.getName(), |
29 | 51 |
|
30 | | - Set<String> HTTP_METHODS = unmodifiableSet(new LinkedHashSet<>(asList(GET, POST))); |
| 52 | + PUT.class.getName(), |
| 53 | + javax.ws.rs.PUT.class.getName(), |
31 | 54 |
|
32 | | - String PATH_PARAM = "io.jooby.annotations.PathParam"; |
| 55 | + DELETE.class.getName(), |
| 56 | + javax.ws.rs.DELETE.class.getName(), |
33 | 57 |
|
34 | | - String QUERY_PARAM = "io.jooby.annotations.QueryParam"; |
| 58 | + PATCH.class.getName(), |
| 59 | + javax.ws.rs.PATCH.class.getName(), |
35 | 60 |
|
36 | | - String COOKIE_PARAM = "io.jooby.annotations.CookieParam"; |
| 61 | + HEAD.class.getName(), |
| 62 | + javax.ws.rs.HEAD.class.getName(), |
37 | 63 |
|
38 | | - String HEADER_PARAM = "io.jooby.annotations.HeaderParam"; |
| 64 | + OPTIONS.class.getName(), |
| 65 | + javax.ws.rs.OPTIONS.class.getName(), |
39 | 66 |
|
40 | | - String FLASH_PARAM = "io.jooby.annotations.FlashParam"; |
| 67 | + CONNECT.class.getName(), |
41 | 68 |
|
42 | | - String FORM_PARAM = "io.jooby.annotations.FormParam"; |
| 69 | + TRACE.class.getName() |
| 70 | + ))); |
43 | 71 |
|
44 | | - String PRODUCES_PARAM = "io.jooby.annotations.Produces"; |
| 72 | + Set<String> PATH_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(PathParam.class.getName()))); |
45 | 73 |
|
46 | | - String CONSUMES_PARAM = "io.jooby.annotations.Consumes"; |
| 74 | + Set<String> QUERY_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList( |
| 75 | + QueryParam.class.getName(), |
| 76 | + javax.ws.rs.QueryParam.class.getName() |
| 77 | + ))); |
47 | 78 |
|
48 | | - Set<String> PATH_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(PATH_PARAM))); |
| 79 | + Set<String> COOKIE_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList( |
| 80 | + CookieParam.class.getName(), |
| 81 | + javax.ws.rs.CookieParam.class.getName() |
| 82 | + ))); |
49 | 83 |
|
50 | | - Set<String> QUERY_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(QUERY_PARAM))); |
| 84 | + Set<String> HEADER_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList( |
| 85 | + HeaderParam.class.getName(), |
| 86 | + javax.ws.rs.HeaderParam.class.getName() |
| 87 | + ))); |
51 | 88 |
|
52 | | - Set<String> COOKIE_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(COOKIE_PARAM))); |
| 89 | + Set<String> FLASH_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(FlashParam.class.getName()))); |
53 | 90 |
|
54 | | - Set<String> HEADER_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(HEADER_PARAM))); |
| 91 | + Set<String> FORM_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList( |
| 92 | + FormParam.class.getName(), |
| 93 | + javax.ws.rs.FormParam.class.getName() |
| 94 | + ))); |
55 | 95 |
|
56 | | - Set<String> FLASH_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(FLASH_PARAM))); |
| 96 | + Set<String> PRODUCES_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList( |
| 97 | + Produces.class.getName(), |
| 98 | + javax.ws.rs.Produces.class.getName() |
| 99 | + ))); |
57 | 100 |
|
58 | | - Set<String> FORM_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(FORM_PARAM))); |
| 101 | + Set<String> CONSUMES_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList( |
| 102 | + Consumes.class.getName(), |
| 103 | + javax.ws.rs.Consumes.class.getName() |
| 104 | + ))); |
59 | 105 |
|
60 | | - Set<String> PRODUCES_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(PRODUCES_PARAM))); |
61 | | - |
62 | | - Set<String> CONSUMES_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(CONSUMES_PARAM))); |
| 106 | + Set<String> PATH = unmodifiableSet(new LinkedHashSet<>(asList( |
| 107 | + Path.class.getName(), |
| 108 | + javax.ws.rs.Path.class.getName() |
| 109 | + ))); |
63 | 110 |
|
64 | 111 | static List<String> attribute(AnnotationMirror mirror, String name) { |
65 | | - Function<Object, String> cleanValue = arg -> ((AnnotationValue) arg).getValue().toString(); |
| 112 | + Function<Object, String> cleanValue = arg -> { |
| 113 | + if (arg instanceof AnnotationValue) { |
| 114 | + return ((AnnotationValue) arg).getValue().toString(); |
| 115 | + } |
| 116 | + return arg.toString(); |
| 117 | + }; |
66 | 118 |
|
67 | 119 | for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : mirror |
68 | 120 | .getElementValues().entrySet()) { |
|
0 commit comments