This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new d298a5a  Refactor RestMethodParam to include method parameter index.
d298a5a is described below

commit d298a5af8c0ff892fd2b811124de9c69b4b0cc8d
Author: JamesBognar <jamesbog...@apache.org>
AuthorDate: Wed Aug 1 15:51:29 2018 -0400

    Refactor RestMethodParam to include method parameter index.
---
 .../java/org/apache/juneau/rest/RestContext.java   | 14 ++++-----
 .../org/apache/juneau/rest/RestMethodParam.java    | 14 ++++++---
 .../org/apache/juneau/rest/RestParamDefaults.java  | 36 +++++++++++-----------
 3 files changed, 34 insertions(+), 30 deletions(-)

diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index ddf7748..aee7dd2 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -4316,23 +4316,23 @@ public final class RestContext extends BeanContext {
 
                        if (hasAnnotation(Header.class, method, i)) {
                                s = HttpPartSchema.create(Header.class, method, 
i);
-                               rp[i] = new 
RestParamDefaults.HeaderObject(method, s, t, ps);
+                               rp[i] = new 
RestParamDefaults.HeaderObject(method, i, s, t, ps);
                        } else if (hasAnnotation(Query.class, method, i)) {
                                s = HttpPartSchema.create(Query.class, method, 
i);
-                               rp[i] = new 
RestParamDefaults.QueryObject(method, s, t, ps);
+                               rp[i] = new 
RestParamDefaults.QueryObject(method, i, s, t, ps);
                        } else if (hasAnnotation(FormData.class, method, i)) {
                                s = HttpPartSchema.create(FormData.class, 
method, i);
-                               rp[i] = new 
RestParamDefaults.FormDataObject(method, s, t, ps);
+                               rp[i] = new 
RestParamDefaults.FormDataObject(method, i, s, t, ps);
                        } else if (hasAnnotation(Path.class, method, i)) {
                                s = HttpPartSchema.create(Path.class, method, 
i);
                                rp[i] = new 
RestParamDefaults.PathObject(method, i, s, t, ps);
                        } else if (hasAnnotation(Body.class, method, i)) {
                                s = HttpPartSchema.create(Body.class, method, 
i);
-                               rp[i] = new 
RestParamDefaults.BodyObject(method, s, t, ps);
+                               rp[i] = new 
RestParamDefaults.BodyObject(method, i, s, t, ps);
 
                        } else if (hasAnnotation(RequestBean.class, method, i)) 
{
                                RequestBeanMeta rbm = 
RequestBeanMeta.create(method, i, ps);
-                               rp[i] = new 
RestParamDefaults.RequestBeanObject(method, rbm, t);
+                               rp[i] = new 
RestParamDefaults.RequestBeanObject(method, i, rbm, t);
 
                        } else if (hasAnnotation(Response.class, method, i) || 
hasAnnotation(Response.class, Value.getValueType(method, i))) {
                                s = HttpPartSchema.create(Response.class, 
method, i);
@@ -4349,10 +4349,10 @@ public final class RestContext extends BeanContext {
 
                        } else if (hasAnnotation(HasFormData.class, method, i)) 
{
                                s = HttpPartSchema.create(HasFormData.class, 
method, i);
-                               rp[i] = new 
RestParamDefaults.HasFormDataObject(method, s, t);
+                               rp[i] = new 
RestParamDefaults.HasFormDataObject(method, i, s, t);
                        } else if (hasAnnotation(HasQuery.class, method, i)) {
                                s = HttpPartSchema.create(HasQuery.class, 
method, i);
-                               rp[i] = new 
RestParamDefaults.HasQueryObject(method, s, t);
+                               rp[i] = new 
RestParamDefaults.HasQueryObject(method, i, s, t);
 
                        } else if 
(hasAnnotation(org.apache.juneau.rest.annotation.Method.class, method, i)) {
                                rp[i] = new 
RestParamDefaults.MethodObject(method, t);
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodParam.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodParam.java
index b4b07c8..2942e53 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodParam.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodParam.java
@@ -115,6 +115,7 @@ public abstract class RestMethodParam {
 
        final RestParamType paramType;
        final Method method;
+       final int index;
        final String name;
        final Type type;
        final Class<?> c;
@@ -125,15 +126,17 @@ public abstract class RestMethodParam {
         *
         * @param paramType The Swagger parameter type.
         * @param method The method on which the parameter resides.
+        * @param index The method parameter index.
         * @param name
         *      The parameter name.
         *      Can be <jk>null</jk> if parameter doesn't have a name (e.g. the 
request body).
         * @param type The object type to convert the parameter to.
         * @param api Swagger metadata.
         */
-       protected RestMethodParam(RestParamType paramType, Method method, 
String name, Type type, ObjectMap api) {
+       protected RestMethodParam(RestParamType paramType, Method method, int 
index, String name, Type type, ObjectMap api) {
                this.paramType = paramType;
                this.method = method;
+               this.index = index;
                this.name = name;
                this.type = type;
                this.c = type instanceof Class ? (Class<?>)type : type 
instanceof ParameterizedType ? (Class<?>)((ParameterizedType)type).getRawType() 
: null;
@@ -147,7 +150,7 @@ public abstract class RestMethodParam {
         * @param type The object type to convert the parameter to.
         */
        protected RestMethodParam(RestParamType paramType, Type type) {
-               this(paramType, null, null, type, ObjectMap.EMPTY_MAP);
+               this(paramType, null, -1, null, type, ObjectMap.EMPTY_MAP);
        }
 
        /**
@@ -160,7 +163,7 @@ public abstract class RestMethodParam {
         * @param type The object type to convert the parameter to.
         */
        protected RestMethodParam(RestParamType paramType, String name, Type 
type) {
-               this(paramType, null, name, type, ObjectMap.EMPTY_MAP);
+               this(paramType, null, -1, name, type, ObjectMap.EMPTY_MAP);
        }
 
        /**
@@ -168,13 +171,14 @@ public abstract class RestMethodParam {
         *
         * @param paramType The Swagger parameter type.
         * @param method The method on which the parameter resides.
+        * @param index The method parameter index.
         * @param name
         *      The parameter name.
         *      Can be <jk>null</jk> if parameter doesn't have a name (e.g. the 
request body).
         * @param type The object type to convert the parameter to.
         */
-       protected RestMethodParam(RestParamType paramType, Method method, 
String name, Type type) {
-               this(paramType, method, name, type, ObjectMap.EMPTY_MAP);
+       protected RestMethodParam(RestParamType paramType, Method method, int 
index, String name, Type type) {
+               this(paramType, method, index, name, type, ObjectMap.EMPTY_MAP);
        }
 
        /**
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
index a14060f..52618b7 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
@@ -553,7 +553,7 @@ class RestParamDefaults {
                private final HttpPartSchema schema;
 
                protected PathObject(Method m, int i, HttpPartSchema s, Type t, 
PropertyStore ps) {
-                       super(PATH, m, s.getName(), t, s.getApi());
+                       super(PATH, m, i, s.getName(), t, s.getApi());
                        this.schema = HttpPartSchema.create(Path.class, m, i);
                        this.partParser = createPartParser(schema.getParser(), 
ps);
 
@@ -571,8 +571,8 @@ class RestParamDefaults {
                private final HttpPartParser partParser;
                private final HttpPartSchema schema;
 
-               protected BodyObject(Method m, HttpPartSchema s, Type t, 
PropertyStore ps) {
-                       super(BODY, m, null, t, s.getApi());
+               protected BodyObject(Method m, int i, HttpPartSchema s, Type t, 
PropertyStore ps) {
+                       super(BODY, m, i, null, t, s.getApi());
                        this.partParser = s.isUsePartParser() ? 
createPartParser(s.getParser(), ps) : null;
                        this.schema = s;
                }
@@ -587,8 +587,8 @@ class RestParamDefaults {
                private final HttpPartParser partParser;
                private final HttpPartSchema schema;
 
-               protected HeaderObject(Method m, HttpPartSchema s, Type t, 
PropertyStore ps) {
-                       super(HEADER, m, s.getName(), t, s.getApi());
+               protected HeaderObject(Method m, int i, HttpPartSchema s, Type 
t, PropertyStore ps) {
+                       super(HEADER, m, i, s.getName(), t, s.getApi());
                        this.partParser = createPartParser(s.getParser(), ps);
                        this.schema = s;
 
@@ -605,8 +605,8 @@ class RestParamDefaults {
        static final class RequestBeanObject extends RestMethodParam {
                private final RequestBeanMeta requestBeanMeta;
 
-               protected RequestBeanObject(Method m, RequestBeanMeta rbm, Type 
t) {
-                       super(RESPONSE_BODY, m, null, t, null);
+               protected RequestBeanObject(Method m, int i, RequestBeanMeta 
rbm, Type t) {
+                       super(RESPONSE_BODY, m, i, null, t, null);
                        this.requestBeanMeta = rbm;
                }
 
@@ -620,7 +620,7 @@ class RestParamDefaults {
                final ResponsePartMeta rpm;
 
                protected ResponseHeaderObject(Method m, int i, HttpPartSchema 
s, Type t, PropertyStore ps) {
-                       super(RESPONSE_HEADER, m, s.getName(), t, 
HttpPartSchema.getApiCodeMap(s, 200));
+                       super(RESPONSE_HEADER, m, i, s.getName(), t, 
HttpPartSchema.getApiCodeMap(s, 200));
                        this.rpm = new ResponsePartMeta(HttpPartType.HEADER, s, 
createPartSerializer(s.getSerializer(), ps));
 
                        if (isEmpty(rpm.getSchema().getName()))
@@ -654,7 +654,7 @@ class RestParamDefaults {
                final ResponsePartMeta rpm;
 
                protected ResponseBodyObject(Method m, int i, HttpPartSchema s, 
Type t, PropertyStore ps) {
-                       super(RESPONSE_BODY, m, s.getName(), t, 
HttpPartSchema.getApiCodeMap(s, 200));
+                       super(RESPONSE_BODY, m, i, s.getName(), t, 
HttpPartSchema.getApiCodeMap(s, 200));
                        this.rpm = new ResponsePartMeta(HttpPartType.BODY, s, 
createPartSerializer(s.getSerializer(), ps));
 
                        if (getTypeClass() != Value.class)
@@ -683,7 +683,7 @@ class RestParamDefaults {
                final ResponseBeanMeta rbm;
 
                protected ResponseBeanObject(Method m, int i, HttpPartSchema s, 
Type t, PropertyStore ps) {
-                       super(RESPONSE, m, s.getName(), t, 
HttpPartSchema.getApiCodeMap(s, 200));
+                       super(RESPONSE, m, i, s.getName(), t, 
HttpPartSchema.getApiCodeMap(s, 200));
                        this.rbm = 
ResponseBeanMeta.create(m.getParameterTypes()[i], ps);
                        if (getTypeClass() != Value.class)
                                throw new InternalServerError("Invalid type {0} 
specified with @Response annotation.  It must be Value.", type);
@@ -748,8 +748,8 @@ class RestParamDefaults {
                private final HttpPartParser partParser;
                private final HttpPartSchema schema;
 
-               protected FormDataObject(Method m, HttpPartSchema s, Type t, 
PropertyStore ps) {
-                       super(FORM_DATA, m, s.getName(), t, s.getApi());
+               protected FormDataObject(Method m, int i, HttpPartSchema s, 
Type t, PropertyStore ps) {
+                       super(FORM_DATA, m, i, s.getName(), t, s.getApi());
                        this.partParser = createPartParser(s.getParser(), ps);
                        this.schema = s;
                        this.multiPart = s.getCollectionFormat() == 
HttpPartSchema.CollectionFormat.MULTI;
@@ -773,8 +773,8 @@ class RestParamDefaults {
                private final HttpPartParser partParser;
                private final HttpPartSchema schema;
 
-               protected QueryObject(Method m, HttpPartSchema s, Type t, 
PropertyStore ps) {
-                       super(QUERY, m, s.getName(), t, s.getApi());
+               protected QueryObject(Method m, int i, HttpPartSchema s, Type 
t, PropertyStore ps) {
+                       super(QUERY, m, i, s.getName(), t, s.getApi());
                        this.partParser = createPartParser(s.getParser(), ps);
                        this.schema = s;
                        this.multiPart = s.getCollectionFormat() == 
HttpPartSchema.CollectionFormat.MULTI;
@@ -795,8 +795,8 @@ class RestParamDefaults {
 
        static final class HasFormDataObject extends RestMethodParam {
 
-               protected HasFormDataObject(Method m, HttpPartSchema s, Type t) 
throws ServletException {
-                       super(FORM_DATA, m, s.getName(), t);
+               protected HasFormDataObject(Method m, int i, HttpPartSchema s, 
Type t) throws ServletException {
+                       super(FORM_DATA, m, i, s.getName(), t);
                        if (t != Boolean.class && t != boolean.class)
                                throw new RestServletException("Use of @HasForm 
annotation on parameter that is not a boolean on method ''{0}''", m);
                }
@@ -810,8 +810,8 @@ class RestParamDefaults {
 
        static final class HasQueryObject extends RestMethodParam {
 
-               protected HasQueryObject(Method m, HttpPartSchema s, Type t) 
throws ServletException {
-                       super(QUERY, m, s.getName(), t);
+               protected HasQueryObject(Method m, int i, HttpPartSchema s, 
Type t) throws ServletException {
+                       super(QUERY, m, i, s.getName(), t);
                        if (t != Boolean.class && t != boolean.class)
                                throw new RestServletException("Use of 
@HasQuery annotation on parameter that is not a boolean on method ''{0}''", m);
                }

Reply via email to