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 a1a7e7a REST refactoring. a1a7e7a is described below commit a1a7e7a9317883b1834178d9ef67cfdbacf4f8f3 Author: JamesBognar <james.bog...@salesforce.com> AuthorDate: Tue Jan 12 17:51:15 2021 -0500 REST refactoring. --- .../apache/juneau/reflection/ClassInfoTest.java | 22 +++- .../juneau/reflection/ConstructorInfoTest.java | 4 +- .../apache/juneau/reflection/MethodInfoTest.java | 4 +- .../src/main/java/org/apache/juneau/ClassMeta.java | 4 - .../java/org/apache/juneau/cp/BeanFactory.java | 14 +-- .../juneau/httppart/bean/ResponseBeanMeta.java | 8 +- .../java/org/apache/juneau/reflect/ClassInfo.java | 119 ++++++++------------- .../org/apache/juneau/reflect/ConstructorInfo.java | 12 +-- .../org/apache/juneau/reflect/ExecutableInfo.java | 10 +- .../java/org/apache/juneau/reflect/MethodInfo.java | 33 ++---- .../java/org/apache/juneau/reflect/ParamInfo.java | 9 +- .../rest/client/remote/RemoteMethodMeta.java | 2 +- .../rest/client/remote/RemoteMethodReturn.java | 3 +- .../apache/juneau/rest/BasicRestInfoProvider.java | 2 +- .../java/org/apache/juneau/rest/RestContext.java | 2 +- .../org/apache/juneau/rest/RestContextBuilder.java | 2 +- .../juneau/rest/RestMethodContextBuilder.java | 2 +- .../org/apache/juneau/rest/SwaggerGenerator.java | 6 +- 18 files changed, 109 insertions(+), 149 deletions(-) diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/reflection/ClassInfoTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/reflection/ClassInfoTest.java index 6ea45e4..4ac6204 100644 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/reflection/ClassInfoTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/reflection/ClassInfoTest.java @@ -174,10 +174,28 @@ public class ClassInfoTest { @Test public void resolved() { - check("A1", of(A1.class).resolved()); - check("A1", of(A2.class).resolved()); + check("A1", of(A1.class).unwrap(Value.class)); + check("A1", of(A2.class).unwrap(Value.class)); } + public static class A6 { + public Optional<A1> m1(Optional<A1> bar) { + return null; + } + public Value<A1> m2(Value<A1> bar) { + return null; + } + } + + @Test + public void resolvedParams() { + MethodInfo mi = ClassInfo.of(A6.class).getPublicMethod("m1", Optional.class); + check("A1", mi.getParamType(0).unwrap(Optional.class)); + check("A1", mi.getReturnType().unwrap(Optional.class)); + mi = ClassInfo.of(A6.class).getPublicMethod("m2", Value.class); + check("A1", mi.getParamType(0).unwrap(Value.class)); + check("A1", mi.getReturnType().unwrap(Value.class)); + } //----------------------------------------------------------------------------------------------------------------- // Parent classes and interfaces. diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/reflection/ConstructorInfoTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/reflection/ConstructorInfoTest.java index 7035dab..fa4b8bd 100644 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/reflection/ConstructorInfoTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/reflection/ConstructorInfoTest.java @@ -69,7 +69,7 @@ public class ConstructorInfoTest { @Test public void of_withDeclaringClass() throws Exception { - check("A()", ConstructorInfo.of(ClassInfo.of(A.class), a.inner(), null)); + check("A()", ConstructorInfo.of(ClassInfo.of(A.class), a.inner())); } @Test @@ -85,7 +85,7 @@ public class ConstructorInfoTest { @Test public void of_null() throws Exception { check(null, ConstructorInfo.of(null)); - check(null, ConstructorInfo.of(null, null, null)); + check(null, ConstructorInfo.of(null, null)); } //----------------------------------------------------------------------------------------------------------------- diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/reflection/MethodInfoTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/reflection/MethodInfoTest.java index 4b8d304..0a39904 100644 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/reflection/MethodInfoTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/reflection/MethodInfoTest.java @@ -122,7 +122,7 @@ public class MethodInfoTest { @Test public void of_withDeclaringClass() { check("A1.m()", a_m); - check("A1.m()", MethodInfo.of(ClassInfo.of(A1.class), a_m.inner(), null)); + check("A1.m()", MethodInfo.of(ClassInfo.of(A1.class), a_m.inner())); } @Test @@ -134,7 +134,7 @@ public class MethodInfoTest { @Test public void of_null() { check(null, MethodInfo.of(null)); - check(null, MethodInfo.of((ClassInfo)null, null, null)); + check(null, MethodInfo.of((ClassInfo)null, null)); } //----------------------------------------------------------------------------------------------------------------- diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java index e35aabb..b1fc084 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java @@ -358,10 +358,6 @@ public final class ClassMeta<T> implements Type { Class<T> c = innerClass; ci = ClassInfo.of(c); - if (ci.isProxy()) { - ci = ci.getProxyFor(); - innerClass = this.innerClass = ci.inner(); - } if (c.isPrimitive()) { if (c == Boolean.TYPE) diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanFactory.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanFactory.java index f8bc7f2..fc1964f 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanFactory.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanFactory.java @@ -228,10 +228,10 @@ public class BeanFactory { List<ClassInfo> l = AList.of(); for (int i = 0; i < paramTypes.size(); i++) { ClassInfo pt = paramTypes.get(i); - ClassInfo ptr = pt.resolved(); - if (i == 0 && ptr.isInstance(outer.orElse(null))) + ClassInfo ptu = pt.unwrap(Optional.class); + if (i == 0 && ptu.isInstance(outer.orElse(null))) continue; - if (! hasBean(ptr)) + if (! hasBean(ptu)) if (! pt.is(Optional.class)) l.add(pt); } @@ -248,14 +248,14 @@ public class BeanFactory { Object[] o = new Object[paramTypes.size()]; for (int i = 0; i < paramTypes.size(); i++) { ClassInfo pt = paramTypes.get(i); - ClassInfo ptr = pt.resolved(); - if (i == 0 && ptr.isInstance(outer.orElse(null))) + ClassInfo ptu = pt.unwrap(Optional.class); + if (i == 0 && ptu.isInstance(outer.orElse(null))) o[i] = outer.get(); else { if (pt.is(Optional.class)) { - o[i] = getBean(ptr); + o[i] = getBean(ptu); } else { - o[i] = getBean(ptr).get(); + o[i] = getBean(ptu).get(); } } } diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java index c2fd1c9..002d8ab 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java @@ -47,7 +47,7 @@ public class ResponseBeanMeta { * @return Metadata about the class, or <jk>null</jk> if class not annotated with {@link Response}. */ public static ResponseBeanMeta create(Type t, PropertyStore ps) { - ClassInfo ci = ClassInfo.of(t).resolved(); + ClassInfo ci = ClassInfo.of(t).unwrap(Value.class, Optional.class); if (! ci.hasAnnotation(Response.class)) return null; Builder b = new Builder(ps); @@ -67,10 +67,10 @@ public class ResponseBeanMeta { * @return Metadata about the class, or <jk>null</jk> if class not annotated with {@link Response}. */ public static ResponseBeanMeta create(MethodInfo m, PropertyStore ps) { - if (! (m.hasAnnotation(Response.class) || m.getResolvedReturnType().hasAnnotation(Response.class))) + if (! (m.hasAnnotation(Response.class) || m.getReturnType().unwrap(Value.class,Optional.class).hasAnnotation(Response.class))) return null; Builder b = new Builder(ps); - b.apply(m.getReturnType().resolved().innerType()); + b.apply(m.getReturnType().unwrap(Value.class, Optional.class).innerType()); for (Response r : m.getAnnotations(Response.class)) b.apply(r); return b.build(); @@ -89,7 +89,7 @@ public class ResponseBeanMeta { if (! mpi.hasAnnotation(Response.class)) return null; Builder b = new Builder(ps); - b.apply(mpi.getParameterType().resolved().innerType()); + b.apply(mpi.getParameterType().unwrap(Value.class, Optional.class).innerType()); for (Response r : mpi.getAnnotations(Response.class)) b.apply(r); return b.build(); diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java index e969439..ac5e52b 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java @@ -59,7 +59,6 @@ public final class ClassInfo { private final Type t; final Class<?> c; - private ClassInfo proxyFor; private final boolean isParameterizedType; private Boolean isRepeatedAnnotation; private ClassInfo[] interfaces, declaredInterfaces, parents, allParents; @@ -81,12 +80,10 @@ public final class ClassInfo { * * @param c The class type. * @param t The generic type (if parameterized type). - * @param proxyFor If the class is a CGLIB proxy, this is the underlying wrapped class. */ - protected ClassInfo(Class<?> c, Type t, Class<?> proxyFor) { + protected ClassInfo(Class<?> c, Type t) { this.t = t; this.c = c; - this.proxyFor = proxyFor == null ? null : ClassInfo.of(proxyFor); this.isParameterizedType = t == null ? false : (t instanceof ParameterizedType); } @@ -99,7 +96,7 @@ public final class ClassInfo { public static ClassInfo of(Type t) { if (t == null) return null; - return new ClassInfo(ClassUtils.toClass(t), t, null); + return new ClassInfo(ClassUtils.toClass(t), t); } /** @@ -111,7 +108,7 @@ public final class ClassInfo { public static ClassInfo of(Class<?> c) { if (c == null) return null; - return new ClassInfo(c, c, null); + return new ClassInfo(c, c); } /** @@ -139,7 +136,7 @@ public final class ClassInfo { * @return The constructed class info, or <jk>null</jk> if the type was <jk>null</jk>. */ public static ClassInfo of(Class<?> c, Type t) { - return new ClassInfo(c, t, null); + return new ClassInfo(c, t); } /** @@ -151,7 +148,20 @@ public final class ClassInfo { public static ClassInfo of(Object o) { if (o == null) return null; - return new ClassInfo(o.getClass(), o.getClass(), getProxyFor(o)); + return new ClassInfo(o.getClass(), o.getClass()); + } + + /** + * Same as {@link #of(Object)} but attempts to deproxify the object if it's wrapped in a CGLIB proxy. + * + * @param o The class instance. + * @return The constructed class info, or <jk>null</jk> if the object was <jk>null</jk>. + */ + public static ClassInfo ofProxy(Object o) { + if (o == null) + return null; + Class<?> c = getProxyFor(o); + return c == null ? ClassInfo.of(o) : ClassInfo.of(c); } /** @@ -213,20 +223,29 @@ public final class ClassInfo { } /** - * If this class is a parameterized {@link Value} type, returns the parameterized type. + * Unwrap this class if it's a parameterized type of the specified type such as {@link Value} or {@link Optional}. * - * @return The parameterized type, or this object if this class is not a parameterized {@link Value} type. + * @param wrapperTypes The parameterized types to unwrap if this class is one of those types. + * @return The class info on the unwrapped type, or just this type if this isn't one of the specified types. */ - public ClassInfo resolved() { - if (isValue(t) || isOptional(t)) { - Type t = getFirstParameterType(this.t); - if (t != null) - return of(t)._getProxiedClassInfo(); + public ClassInfo unwrap(Class<?>...wrapperTypes) { + for (Class<?> wt : wrapperTypes) { + if (isParameterizedTypeOf(wt)) { + Type t = getFirstParameterType(wt); + if (t != null) + return of(t).unwrap(wrapperTypes); // Recursively do it again. + } } - return _getProxiedClassInfo(); + return this; } - private static Type getFirstParameterType(Type t) { + private boolean isParameterizedTypeOf(Class<?> c) { + return + (t instanceof ParameterizedType && ((ParameterizedType)t).getRawType() == c) + || (t instanceof Class && c.isAssignableFrom((Class<?>)t)); + } + + private Type getFirstParameterType(Class<?> parameterizedType) { if (t instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType)t; Type[] ta = pt.getActualTypeArguments(); @@ -234,30 +253,12 @@ public final class ClassInfo { return ta[0]; } else if (t instanceof Class) /* Class that extends Optional<T> */ { Class<?> c = (Class<?>)t; - if (c != Value.class && Value.class.isAssignableFrom(c)) - return ClassInfo.of(c).getParameterType(0, Value.class); - if (c != Optional.class && Optional.class.isAssignableFrom(c)) - return ClassInfo.of(c).getParameterType(0, Optional.class); + if (c != parameterizedType && parameterizedType.isAssignableFrom(c)) + return ClassInfo.of(c).getParameterType(0, parameterizedType); } return null; } - private static boolean isOptional(Type t) { - return - (t instanceof ParameterizedType && ((ParameterizedType)t).getRawType() == Optional.class) - || (t instanceof Class && Optional.class.isAssignableFrom((Class<?>)t)); - } - - private static boolean isValue(Type t) { - return - (t instanceof ParameterizedType && ((ParameterizedType)t).getRawType() == Value.class) - || (t instanceof Class && Value.class.isAssignableFrom((Class<?>)t)); - } - - private ClassInfo _getProxiedClassInfo() { - return proxyFor == null ? this : proxyFor; - } - //----------------------------------------------------------------------------------------------------------------- // Parent classes and interfaces. //----------------------------------------------------------------------------------------------------------------- @@ -525,7 +526,7 @@ public final class ClassInfo { List<MethodInfo> l = new ArrayList<>(mm.length); for (Method m : mm) if (m.getDeclaringClass() != Object.class) - l.add(MethodInfo.of(this, m, _getProxyTarget(m))); + l.add(MethodInfo.of(this, m)); l.sort(null); publicMethods = l.toArray(new MethodInfo[l.size()]); } @@ -538,7 +539,7 @@ public final class ClassInfo { List<MethodInfo> l = new ArrayList<>(mm.length); for (Method m : mm) if (! "$jacocoInit".equals(m.getName())) // Jacoco adds its own simulated methods. - l.add(MethodInfo.of(this, m, _getProxyTarget(m))); + l.add(MethodInfo.of(this, m)); l.sort(null); declaredMethods = l.toArray(new MethodInfo[l.size()]); } @@ -570,24 +571,6 @@ public final class ClassInfo { return l; } - private Method _getProxyTarget(Method m) { - if (proxyFor != null) { - MethodInfo m2 = proxyFor.getMethod(m.getName(), m.getParameterTypes()); - if (m2 != null) - return m2.inner(); - } - return m; - } - - private Constructor<?> _getProxyTarget(Constructor<?> c) { - if (proxyFor != null) { - ConstructorInfo c2 = proxyFor.getConstructor(Visibility.PRIVATE, c.getParameterTypes()); - if (c2 != null) - return c2.inner(); - } - return c; - } - //----------------------------------------------------------------------------------------------------------------- // Special methods //----------------------------------------------------------------------------------------------------------------- @@ -863,7 +846,7 @@ public final class ClassInfo { Constructor<?>[] cc = c == null ? new Constructor[0] : c.getConstructors(); List<ConstructorInfo> l = new ArrayList<>(cc.length); for (Constructor<?> ccc : cc) - l.add(ConstructorInfo.of(this, ccc, _getProxyTarget(ccc))); + l.add(ConstructorInfo.of(this, ccc)); l.sort(null); publicConstructors = l.toArray(new ConstructorInfo[l.size()]); } @@ -875,7 +858,7 @@ public final class ClassInfo { Constructor<?>[] cc = c == null ? new Constructor[0] : c.getDeclaredConstructors(); List<ConstructorInfo> l = new ArrayList<>(cc.length); for (Constructor<?> ccc : cc) - l.add(ConstructorInfo.of(this, ccc, _getProxyTarget(ccc))); + l.add(ConstructorInfo.of(this, ccc)); l.sort(null); declaredConstructors = l.toArray(new ConstructorInfo[l.size()]); } @@ -2262,24 +2245,6 @@ public final class ClassInfo { } /** - * Returns <jk>true</jk> if this class is a proxy for another class. - * - * @return <jk>true</jk> if this class is a proxy for another class. - */ - public boolean isProxy() { - return proxyFor != null; - } - - /** - * Returns the class info of the proxied class. - * - * @return The class info of the proxied class, or <jk>null</jk> if this class is not proxied. - */ - public ClassInfo getProxyFor() { - return proxyFor; - } - - /** * Returns the number of dimensions if this is an array type. * * @return The number of dimensions if this is an array type, or <c>0</c> if it is not. diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ConstructorInfo.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ConstructorInfo.java index 367a18b..935fc2c 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ConstructorInfo.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ConstructorInfo.java @@ -37,10 +37,9 @@ public final class ConstructorInfo extends ExecutableInfo implements Comparable< * * @param declaringClass The class that declares this method. * @param c The constructor being wrapped. - * @param rc The "real" constructor if the constructor above is defined against a CGLIB proxy. */ - protected ConstructorInfo(ClassInfo declaringClass, Constructor<?> c, Constructor<?> rc) { - super(declaringClass, c, rc); + protected ConstructorInfo(ClassInfo declaringClass, Constructor<?> c) { + super(declaringClass, c); this.c = c; } @@ -49,13 +48,12 @@ public final class ConstructorInfo extends ExecutableInfo implements Comparable< * * @param declaringClass The class that declares this method. * @param c The constructor being wrapped. - * @param rc The "real" constructor if the constructor above is defined against a CGLIB proxy. * @return A new {@link ConstructorInfo} object, or <jk>null</jk> if the method was null; */ - public static ConstructorInfo of(ClassInfo declaringClass, Constructor<?> c, Constructor<?> rc) { + public static ConstructorInfo of(ClassInfo declaringClass, Constructor<?> c) { if (c == null) return null; - return new ConstructorInfo(declaringClass, c, rc); + return new ConstructorInfo(declaringClass, c); } /** @@ -67,7 +65,7 @@ public final class ConstructorInfo extends ExecutableInfo implements Comparable< public static ConstructorInfo of(Constructor<?> c) { if (c == null) return null; - return new ConstructorInfo(ClassInfo.of(c.getDeclaringClass()), c, c); + return new ConstructorInfo(ClassInfo.of(c.getDeclaringClass()), c); } /** diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java index 73d7c36..3d18321 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java @@ -27,7 +27,7 @@ import org.apache.juneau.internal.*; public abstract class ExecutableInfo { final ClassInfo declaringClass; - final Executable e, re; + final Executable e; final boolean isConstructor; private ParamInfo[] params; @@ -41,12 +41,10 @@ public abstract class ExecutableInfo { * * @param declaringClass The class that declares this method or constructor. * @param e The constructor or method that this info represents. - * @param re The "real" constructor if the constructor above is defined against a CGLIB proxy. */ - protected ExecutableInfo(ClassInfo declaringClass, Executable e, Executable re) { + protected ExecutableInfo(ClassInfo declaringClass, Executable e) { this.declaringClass = declaringClass; this.e = e; - this.re = re == null ? e : re; this.isConstructor = e instanceof Constructor; } @@ -263,13 +261,13 @@ public abstract class ExecutableInfo { private Type[] _getRawGenericParamTypes() { if (rawGenericParamTypes == null) - rawGenericParamTypes = re.getGenericParameterTypes(); + rawGenericParamTypes = e.getGenericParameterTypes(); return rawGenericParamTypes; } private Parameter[] _getRawParameters() { if (rawParameters == null) - rawParameters = re.getParameters(); + rawParameters = e.getParameters(); return rawParameters; } diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/MethodInfo.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/MethodInfo.java index 1822cbb..a8de582 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/MethodInfo.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/MethodInfo.java @@ -43,10 +43,9 @@ public final class MethodInfo extends ExecutableInfo implements Comparable<Metho * * @param declaringClass The class that declares this method. * @param m The method being wrapped. - * @param rm The "real" method if the method above is defined against a CGLIB proxy. */ - protected MethodInfo(ClassInfo declaringClass, Method m, Method rm) { - super(declaringClass, m, rm); + protected MethodInfo(ClassInfo declaringClass, Method m) { + super(declaringClass, m); this.m = m; } @@ -55,13 +54,12 @@ public final class MethodInfo extends ExecutableInfo implements Comparable<Metho * * @param declaringClass The class that declares this method. * @param m The method being wrapped. - * @param rm The "real" method if the method above is defined against a CGLIB proxy. * @return A new {@link MethodInfo} object, or <jk>null</jk> if the method was null; */ - public static MethodInfo of(ClassInfo declaringClass, Method m, Method rm) { + public static MethodInfo of(ClassInfo declaringClass, Method m) { if (m == null) return null; - return new MethodInfo(declaringClass, m, rm); + return new MethodInfo(declaringClass, m); } /** @@ -69,13 +67,12 @@ public final class MethodInfo extends ExecutableInfo implements Comparable<Metho * * @param declaringClass The class that declares this method. * @param m The method being wrapped. - * @param rm The "real" method if the method above is defined against a CGLIB proxy. * @return A new {@link MethodInfo} object, or <jk>null</jk> if the method was null; */ - public static MethodInfo of(Class<?> declaringClass, Method m, Method rm) { + public static MethodInfo of(Class<?> declaringClass, Method m) { if (m == null) return null; - return new MethodInfo(ClassInfo.of(declaringClass), m, rm); + return new MethodInfo(ClassInfo.of(declaringClass), m); } /** @@ -87,7 +84,7 @@ public final class MethodInfo extends ExecutableInfo implements Comparable<Metho public static MethodInfo of(Method m) { if (m == null) return null; - return new MethodInfo(ClassInfo.of(m.getDeclaringClass()), m, m); + return new MethodInfo(ClassInfo.of(m.getDeclaringClass()), m); } /** @@ -240,7 +237,7 @@ public final class MethodInfo extends ExecutableInfo implements Comparable<Metho for (Annotation a2 : m2.getDeclaredAnnotations()) if (a.isInstance(a2)) l.add((T)a2); - getReturnType().resolved().appendAnnotations(l, a); + getReturnType().unwrap(Value.class,Optional.class).appendAnnotations(l, a); return l; } @@ -384,20 +381,6 @@ public final class MethodInfo extends ExecutableInfo implements Comparable<Metho } /** - * Returns the generic return type of this method as a {@link ClassInfo} object. - * - * <p> - * Unwraps the type if it's a {@link Value}. - * - * @return The generic return type of this method. - */ - public ClassInfo getResolvedReturnType() { - if (returnType == null) - returnType = ClassInfo.of(m.getReturnType(), m.getGenericReturnType()); - return returnType.resolved(); - } - - /** * Returns <jk>true</jk> if this method has this return type. * * @param c The return type to test for. diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ParamInfo.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ParamInfo.java index 72c351a..3d95f76 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ParamInfo.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ParamInfo.java @@ -17,6 +17,7 @@ import java.lang.reflect.*; import java.util.*; import java.util.concurrent.*; +import org.apache.juneau.*; import org.apache.juneau.annotation.*; /** @@ -158,14 +159,14 @@ public final class ParamInfo { for (Annotation a2 : eInfo.getParameterAnnotations(index)) if (a.isInstance(a2)) return (T)a2; - return eInfo.getParamType(index).resolved().getLastAnnotation(a); + return eInfo.getParamType(index).unwrap(Value.class,Optional.class).getLastAnnotation(a); } MethodInfo mi = (MethodInfo)eInfo; for (Method m2 : mi.getMatching()) for (Annotation a2 : m2.getParameterAnnotations()[index]) if (a.isInstance(a2)) return (T)a2; - return eInfo.getParamType(index).resolved().getLastAnnotation(a); + return eInfo.getParamType(index).unwrap(Value.class,Optional.class).getLastAnnotation(a); } /** @@ -189,7 +190,7 @@ public final class ParamInfo { @SuppressWarnings("unchecked") private <T extends Annotation> List<T> appendAnnotations(List<T> l, Class<T> a, boolean parentFirst) { if (eInfo.isConstructor) { - ClassInfo ci = eInfo.getParamType(index).resolved(); + ClassInfo ci = eInfo.getParamType(index).unwrap(Value.class,Optional.class); Annotation[] annotations = eInfo.getParameterAnnotations(index); if (parentFirst) { ci.appendAnnotations(l, a); @@ -204,7 +205,7 @@ public final class ParamInfo { } } else { MethodInfo mi = (MethodInfo)eInfo; - ClassInfo ci = eInfo.getParamType(index).resolved(); + ClassInfo ci = eInfo.getParamType(index).unwrap(Value.class,Optional.class); if (parentFirst) { ci.appendAnnotations(l, a); for (Method m2 : mi.getMatchingParentFirst()) diff --git a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodMeta.java b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodMeta.java index 5aa45dd..868bc7e 100644 --- a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodMeta.java +++ b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodMeta.java @@ -85,7 +85,7 @@ public class RemoteMethodMeta { RemoteMethod rm = mi.getLastAnnotation(RemoteMethod.class); if (rm == null) - rm = mi.getResolvedReturnType().getLastAnnotation(RemoteMethod.class); + rm = mi.getReturnType().unwrap(Value.class,Optional.class).getLastAnnotation(RemoteMethod.class); httpMethod = rm == null ? "" : rm.method(); path = rm == null ? "" : rm.path(); diff --git a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodReturn.java b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodReturn.java index 9c3404a..65740b1 100644 --- a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodReturn.java +++ b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodReturn.java @@ -13,6 +13,7 @@ package org.apache.juneau.rest.client.remote; import java.lang.reflect.*; +import java.util.*; import java.util.concurrent.*; import org.apache.juneau.*; @@ -41,7 +42,7 @@ public final class RemoteMethodReturn { RemoteMethod rm = m.getLastAnnotation(RemoteMethod.class); if (rm == null) - rm = m.getResolvedReturnType().getLastAnnotation(RemoteMethod.class); + rm = m.getReturnType().unwrap(Value.class,Optional.class).getLastAnnotation(RemoteMethod.class); RemoteReturn rv = null; diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java index 8e9a384..0f1d1cd 100644 --- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java +++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/BasicRestInfoProvider.java @@ -66,7 +66,7 @@ public class BasicRestInfoProvider implements RestInfoProvider { description; Builder(RestContext context) { - ClassInfo ci = ClassInfo.of(context.getResource()).resolved(); + ClassInfo ci = ClassInfo.ofProxy(context.getResource()); for (Rest r : ci.getAnnotations(Rest.class)) { if (! r.siteName().isEmpty()) siteName = r.siteName(); 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 88c0ce2..8d46870 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 @@ -3285,7 +3285,7 @@ public class RestContext extends BeanContext { Object r = getResource(); parentContext = builder.parentContext; - ClassInfo rci = ClassInfo.of(r).resolved(); + ClassInfo rci = ClassInfo.ofProxy(r); rootBeanFactory = createRootBeanFactory(r); diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java index a11300d..8782cd1 100644 --- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java +++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java @@ -254,7 +254,7 @@ public class RestContextBuilder extends BeanContextBuilder implements ServletCon RestContextBuilder init(Object resource) throws ServletException { this.resource = resource; - ClassInfo rci = ClassInfo.of(resource).resolved(); + ClassInfo rci = ClassInfo.ofProxy(resource); Map<String,MethodInfo> map = new LinkedHashMap<>(); for (MethodInfo m : rci.getAllMethodsParentFirst()) { diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContextBuilder.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContextBuilder.java index 4db9a1b..1bee6bb 100644 --- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContextBuilder.java +++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContextBuilder.java @@ -37,7 +37,7 @@ public class RestMethodContextBuilder extends BeanContextBuilder { this.method = method; String sig = method.getDeclaringClass().getName() + '.' + method.getName(); - MethodInfo mi = MethodInfo.of(servlet.getClass(), method, method); + MethodInfo mi = MethodInfo.of(servlet.getClass(), method); try { diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/SwaggerGenerator.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/SwaggerGenerator.java index 2881496..69e9e3f 100644 --- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/SwaggerGenerator.java +++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/SwaggerGenerator.java @@ -97,7 +97,7 @@ final class SwaggerGenerator { */ public Swagger getSwagger() throws Exception { - ClassInfo rci = ClassInfo.of(resource).resolved(); + ClassInfo rci = ClassInfo.ofProxy(resource); rci.getSimpleName(); @@ -395,7 +395,7 @@ final class SwaggerGenerator { for (MethodInfo ecmi : eci.getAllMethodsParentFirst()) { ResponseHeader a = ecmi.getLastAnnotation(ResponseHeader.class); if (a == null) - a = ecmi.getResolvedReturnType().getLastAnnotation(ResponseHeader.class); + a = ecmi.getReturnType().unwrap(Value.class,Optional.class).getLastAnnotation(ResponseHeader.class); if (a != null && ! isMulti(a)) { String ha = a.name(); for (Integer code : codes) { @@ -408,7 +408,7 @@ final class SwaggerGenerator { } } - if (mi.hasAnnotation(Response.class) || mi.getResolvedReturnType().hasAnnotation(Response.class)) { + if (mi.hasAnnotation(Response.class) || mi.getReturnType().unwrap(Value.class,Optional.class).hasAnnotation(Response.class)) { List<Response> la = mi.getAnnotations(Response.class); Set<Integer> codes = getCodes(la, 200); for (Response a : la) {