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 bd704f1 ClassInfo refactoring.
bd704f1 is described below
commit bd704f1993fb69c5aaac49d860c50be2cebc541c
Author: JamesBognar <[email protected]>
AuthorDate: Sun Jan 30 14:16:38 2022 -0500
ClassInfo refactoring.
---
.../main/java/org/apache/juneau/cp/BeanStore.java | 2 +-
.../org/apache/juneau/http/remote/RemoteOp.java | 1 -
.../org/apache/juneau/http/remote/RemoteUtils.java | 50 +++++-----------------
.../org/apache/juneau/reflect/AnnotationInfo.java | 33 ++++++++++++--
.../org/apache/juneau/reflect/AnnotationList.java | 16 +++----
.../java/org/apache/juneau/reflect/ClassInfo.java | 24 +++--------
.../java/org/apache/juneau/reflect/MethodInfo.java | 11 -----
.../rest/client/remote/RemoteOperationMeta.java | 14 +++---
.../rest/client/remote/RemoteOperationReturn.java | 18 ++++----
.../java/org/apache/juneau/rest/RestContext.java | 20 ++++-----
.../rest/annotation/OpSwaggerAnnotation.java | 10 +++++
.../juneau/rest/annotation/RestOpAnnotation.java | 6 +++
.../juneau/rest/matcher/ClientVersionMatcher.java | 8 ++--
.../rest/swagger/BasicSwaggerProviderSession.java | 17 ++++++--
.../juneau/reflection/AnnotationInfoTest.java | 2 +-
15 files changed, 117 insertions(+), 115 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanStore.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanStore.java
index 2c37c42..7c3c2b8 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanStore.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanStore.java
@@ -676,7 +676,7 @@ public class BeanStore {
private String findBeanName(ParamInfo pi) {
Annotation n = pi.getAnnotation(Annotation.class, x ->
x.annotationType().getSimpleName().equals("Named"));
if (n != null)
- return AnnotationInfo.of((ClassInfo)null,
n).getValue(String.class, "value").orElse(null);
+ return AnnotationInfo.of((ClassInfo)null,
n).getValue(String.class, "value", StringUtils::isNotEmpty).orElse(null);
return null;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RemoteOp.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RemoteOp.java
index 87c158b..c6d5790 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RemoteOp.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RemoteOp.java
@@ -17,7 +17,6 @@ import static java.lang.annotation.RetentionPolicy.*;
import java.io.*;
import java.lang.annotation.*;
-
import org.apache.juneau.annotation.*;
import org.apache.juneau.http.annotation.*;
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/reflection/AnnotationInfoTest.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RemoteUtils.java
similarity index 58%
copy from
juneau-utest/src/test/java/org/apache/juneau/reflection/AnnotationInfoTest.java
copy to
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RemoteUtils.java
index 4f99e98..e87a919 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/reflection/AnnotationInfoTest.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RemoteUtils.java
@@ -10,47 +10,19 @@
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
// * specific language governing permissions and limitations under the
License. *
//
***************************************************************************************************************************
-package org.apache.juneau.reflection;
+package org.apache.juneau.http.remote;
-import static java.lang.annotation.ElementType.*;
-import static java.lang.annotation.RetentionPolicy.*;
-import static org.junit.runners.MethodSorters.*;
-import static org.apache.juneau.assertions.Assertions.*;
-
-import org.apache.juneau.annotation.*;
-import java.lang.annotation.*;
+import java.util.function.*;
import org.apache.juneau.reflect.*;
-import org.junit.*;
-
-@FixMethodOrder(NAME_ASCENDING)
-public class AnnotationInfoTest {
-
-
//-----------------------------------------------------------------------------------------------------------------
- // Is in group.
-
//-----------------------------------------------------------------------------------------------------------------
-
- @Target(TYPE)
- @Retention(RUNTIME)
- @AnnotationGroup(D1.class)
- public static @interface D1 {}
-
- @Target(TYPE)
- @Retention(RUNTIME)
- @AnnotationGroup(D1.class)
- public static @interface D2 {}
-
- @Target(TYPE)
- @Retention(RUNTIME)
- public static @interface D3 {}
- @D1 @D2 @D3
- public static class D {}
+/**
+ * Utilities.
+ */
+public class RemoteUtils {
- @Test
- public void d01_isInGroup() {
- ClassInfo d = ClassInfo.of(D.class);
- AnnotationList l = d.getAnnotationGroupList(D1.class);
- assertList(l).isSize(2);
- }
-}
\ No newline at end of file
+ /**
+ * Predicate that can be used with the {@link
ClassInfo#getAnnotationList(Predicate)} and {@link
MethodInfo#getAnnotationList(Predicate)}
+ */
+ public static final Predicate<AnnotationInfo<?>> REMOTE_OP_GROUP = x ->
x.isInGroup(RemoteOp.class);
+}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationInfo.java
index 58ea913..2c7636b 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationInfo.java
@@ -275,18 +275,45 @@ public class AnnotationInfo<T extends Annotation> {
}
/**
+ * Consumes a value on this annotation.
+ *
+ * @param type The annotation field type.
+ * @param name The annotation field name.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
+ * @return This object.
+ */
+ @SuppressWarnings("unchecked")
+ public <V> AnnotationInfo<?> getValue(Class<V> type, String name,
Predicate<V> predicate, Consumer<V> consumer) {
+ for (Method m : a.annotationType().getMethods())
+ if (m.getName().equals(name) &&
m.getReturnType().equals(type)) {
+ try {
+ V v = (V)m.invoke(a);
+ if (predicate.test(v))
+ consumer.accept(v);
+ } catch (Exception e) {
+ e.printStackTrace(); // Shouldn't
happen.
+ }
+ }
+ return this;
+ }
+
+ /**
* Returns a value on this annotation.
*
* @param type The annotation field type.
* @param name The annotation field name.
- * @return The value on this annotation if the field exists and is the
specified type.
+ * @param predicate The predicate.
+ * @return This object.
*/
@SuppressWarnings("unchecked")
- public <V> Optional<V> getValue(Class<V> type, String name) {
+ public <V> Optional<V> getValue(Class<V> type, String name,
Predicate<V> predicate) {
for (Method m : a.annotationType().getMethods())
if (m.getName().equals(name) &&
m.getReturnType().equals(type)) {
try {
- return
Optional.ofNullable((V)m.invoke(a));
+ V v = (V)m.invoke(a);
+ if (predicate.test(v))
+ return Optional.of(v);
} catch (Exception e) {
e.printStackTrace(); // Shouldn't
happen.
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationList.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationList.java
index add1c28..5b6457a 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationList.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationList.java
@@ -50,16 +50,14 @@ public class AnnotationList extends
ArrayList<AnnotationInfo<?>> {
*
* @param type The annotation value type.
* @param name The annotation value name.
- * @return A list of all values found.
+ * @param predicate The predicate.
+ * @param consumer The consumer.
+ * @return This object.
*/
- public <T> List<T> getValues(Class<T> type, String name) {
- List<T> l = new ArrayList<>();
- for (AnnotationInfo<?> ai : this) {
- Optional<T> o = ai.getValue(type, name);
- if (o.isPresent())
- l.add(o.get());
- }
- return l;
+ public <T> AnnotationList getValues(Class<T> type, String name,
Predicate<T> predicate, Consumer<T> consumer) {
+ for (AnnotationInfo<?> ai : this)
+ ai.getValue(type, name, predicate, consumer);
+ return this;
}
/**
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 309c6b3..c56ee0e 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
@@ -23,7 +23,6 @@ import java.util.concurrent.*;
import java.util.function.*;
import org.apache.juneau.*;
-import org.apache.juneau.annotation.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.internal.*;
@@ -1085,18 +1084,7 @@ public final class ClassInfo {
}
/**
- * Constructs an {@link AnnotationList} of all annotations found on
this class that belong to the specified
- * annotation group.
- *
- * @param group The annotation group. See {@link AnnotationGroup}.
- * @return A new {@link AnnotationList} object on every call.
- */
- public AnnotationList getAnnotationGroupList(Class<? extends
Annotation> group) {
- return getAnnotationList(x -> x.isInGroup(group));
- }
-
- /**
- * Constructs an {@link AnnotationList} of all annotations found on
this class.
+ * Constructs an {@link AnnotationList} of all matching annotations
found on this class.
*
* <p>
* Annotations are appended in the following orders:
@@ -1107,14 +1095,12 @@ public final class ClassInfo {
* <li>On this class.
* </ol>
*
- * @param filter
- * Optional filter to apply to limit which annotations are added
to the list.
- * <br>Can be <jk>null</jk> for no filtering.
+ * @param predicate The predicate.
* @return A new {@link AnnotationList} object on every call.
*/
- public AnnotationList getAnnotationList(Predicate<AnnotationInfo<?>>
filter) {
+ public AnnotationList getAnnotationList(Predicate<AnnotationInfo<?>>
predicate) {
AnnotationList l = new AnnotationList();
- getAnnotationInfos(filter, x -> l.add(x));
+ getAnnotationInfos(predicate, x -> l.add(x));
return l;
}
@@ -1136,7 +1122,7 @@ public final class ClassInfo {
return new Annotation[]{a};
}
- <T extends Annotation> T findAnnotation(AnnotationProvider ap, Class<T>
a) {
+ private <T extends Annotation> T findAnnotation(AnnotationProvider ap,
Class<T> a) {
if (a == null)
return null;
T t = ap.getDeclaredAnnotation(a, c, x -> true);
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 73ae4cb..1a0fe56 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
@@ -396,17 +396,6 @@ public final class MethodInfo extends ExecutableInfo
implements Comparable<Metho
}
/**
- * Constructs an {@link AnnotationList} of all annotations found on
this class that belong to the specified
- * {@link AnnotationGroup annotation group}.
- *
- * @param group The annotation group.
- * @return A new {@link AnnotationList} object on every call.
- */
- public AnnotationList getAnnotationGroupList(Class<? extends
Annotation> group) {
- return getAnnotationList(x -> x.isInGroup(group));
- }
-
- /**
* Constructs an {@link AnnotationList} of all annotations found on
this method.
*
* <p>
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationMeta.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationMeta.java
index 6e20495..5813570 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationMeta.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationMeta.java
@@ -14,6 +14,7 @@ package org.apache.juneau.rest.client.remote;
import static org.apache.juneau.internal.StringUtils.*;
import static org.apache.juneau.httppart.HttpPartType.*;
+import static org.apache.juneau.http.remote.RemoteUtils.*;
import java.lang.reflect.*;
import java.util.*;
@@ -85,12 +86,15 @@ public class RemoteOperationMeta {
MethodInfo mi = MethodInfo.of(m);
- AnnotationList al =
mi.getAnnotationGroupList(RemoteOp.class);
+ AnnotationList al =
mi.getAnnotationList(REMOTE_OP_GROUP);
if (al.isEmpty())
- al =
mi.getReturnType().unwrap(Value.class,Optional.class).getAnnotationGroupList(RemoteOp.class);
+ al =
mi.getReturnType().unwrap(Value.class,Optional.class).getAnnotationList(REMOTE_OP_GROUP);
- httpMethod = al.getValues(String.class,
"method").stream().filter(x -> isNotEmpty(x)).findFirst().orElse("").trim();
- path = al.getValues(String.class,
"path").stream().filter(x -> isNotEmpty(x)).findFirst().orElse("").trim();
+ Value<String> _httpMethod = Value.empty(), _path =
Value.empty();
+ al.getValues(String.class, "method",
StringUtils::isNotEmpty, x -> _httpMethod.set(x.trim()));
+ al.getValues(String.class, "path",
StringUtils::isNotEmpty, x-> _path.set(x.trim()));
+ httpMethod = _httpMethod.orElse("").trim();
+ path = _path.orElse("").trim();
Value<String> value = Value.empty();
al.forEach(RemoteOp.class, x ->
isNotEmpty(x.inner().value().trim()), x -> value.set(x.inner().value().trim()));
@@ -105,7 +109,7 @@ public class RemoteOperationMeta {
path = v.substring(i).trim();
}
} else {
- al.forEach(x -> ! x.isType(RemoteOp.class) &&
isNotEmpty(x.getValue(String.class, "value").orElse("").trim()),x ->
value.set(x.getValue(String.class, "value").get().trim()));
+ al.forEach(x -> ! x.isType(RemoteOp.class) &&
isNotEmpty(x.getValue(String.class, "value",
StringUtils::isNotEmpty).orElse("").trim()),x ->
value.set(x.getValue(String.class, "value",
StringUtils::isNotEmpty).get().trim()));
if (value.isPresent())
path = value.get();
}
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationReturn.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationReturn.java
index d2f1e9a..5dd7714 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationReturn.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationReturn.java
@@ -12,12 +12,13 @@
//
***************************************************************************************************************************
package org.apache.juneau.rest.client.remote;
+import static org.apache.juneau.http.remote.RemoteUtils.*;
+
import java.lang.reflect.*;
import java.util.*;
import java.util.concurrent.*;
import org.apache.juneau.*;
-import org.apache.juneau.http.remote.RemoteOp;
import org.apache.juneau.http.remote.RemoteReturn;
import org.apache.juneau.http.annotation.*;
import org.apache.juneau.httppart.bean.*;
@@ -42,9 +43,9 @@ public final class RemoteOperationReturn {
RemoteOperationReturn(MethodInfo m) {
ClassInfo rt = m.getReturnType();
- AnnotationList al = m.getAnnotationGroupList(RemoteOp.class);
+ AnnotationList al = m.getAnnotationList(REMOTE_OP_GROUP);
if (al.isEmpty())
- al =
m.getReturnType().unwrap(Value.class,Optional.class).getAnnotationGroupList(RemoteOp.class);
+ al =
m.getReturnType().unwrap(Value.class,Optional.class).getAnnotationList(REMOTE_OP_GROUP);
RemoteReturn rv = null;
@@ -56,12 +57,13 @@ public final class RemoteOperationReturn {
rt =
ClassInfo.of(((ParameterizedType)rt.innerType()).getActualTypeArguments()[0]);
}
- if (rt.is(void.class) || rt.is(Void.class))
+ if (rt.is(void.class) || rt.is(Void.class)) {
rv = RemoteReturn.NONE;
- else if (! al.isEmpty())
- rv =
al.getValues(RemoteReturn.class,"returns").stream().findFirst().orElse(RemoteReturn.BODY);
- else
- rv = RemoteReturn.BODY;
+ } else {
+ Value<RemoteReturn> v = Value.of(RemoteReturn.BODY);
+ al.getValues(RemoteReturn.class, "returns", x -> true,
x -> v.set(x));
+ rv = v.get();
+ }
if (rt.hasAnnotation(Response.class) && rt.isInterface()) {
this.meta = ResponseBeanMeta.create(m,
AnnotationWorkList.create());
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 1ee45bd..fdb8704 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
@@ -27,6 +27,7 @@ import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.util.Optional.*;
import static java.util.logging.Level.*;
+import static org.apache.juneau.rest.annotation.RestOpAnnotation.*;
import java.io.*;
import java.lang.annotation.*;
@@ -3518,16 +3519,13 @@ public class RestContext extends Context {
v.get().defaultEnable(debugDefault);
// Gather @RestOp(debug) settings.
- ClassInfo.ofProxy(resource.get()).getPublicMethods(
- x -> true,
- x -> x
- .getAnnotationGroupList(RestOp.class)
- .getValues(String.class, "debug")
- .stream()
- .filter(y->!y.isEmpty())
- .findFirst()
- .ifPresent(x2 ->
v.get().enable(Enablement.fromString(x2), x.getFullName()))
- );
+ Consumer<MethodInfo> consumer = x -> {
+ Value<String> debug = Value.empty();
+
x.getAnnotationList(REST_OP_GROUP).getValues(String.class, "debug",
StringUtils::isNotEmpty, y -> debug.set(y));
+ if (debug.isPresent())
+
v.get().enable(Enablement.fromString(debug.get()), x.getFullName());
+ };
+ ClassInfo.ofProxy(resource.get()).getPublicMethods(x ->
true, consumer);
// Replace with bean from bean store.
rootBeanStore
@@ -4048,7 +4046,7 @@ public class RestContext extends Context {
ClassInfo rci = ClassInfo.of(resource.get());
for (MethodInfo mi : rci.getPublicMethods()) {
- AnnotationList al =
mi.getAnnotationGroupList(RestOp.class);
+ AnnotationList al =
mi.getAnnotationList(REST_OP_GROUP);
// Also include methods on @Rest-annotated
interfaces.
if (al.size() == 0) {
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/OpSwaggerAnnotation.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/OpSwaggerAnnotation.java
index 45fa5c8..34f5dac 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/OpSwaggerAnnotation.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/OpSwaggerAnnotation.java
@@ -55,6 +55,16 @@ public class OpSwaggerAnnotation {
return a == null || DEFAULT.equals(a);
}
+ /**
+ * Returns <jk>false</jk> if the specified annotation contains all
default values.
+ *
+ * @param a The annotation to check.
+ * @return <jk>false</jk> if the specified annotation contains all
default values.
+ */
+ public static boolean notEmpty(OpSwagger a) {
+ return ! empty(a);
+ }
+
//-----------------------------------------------------------------------------------------------------------------
// Builder
//-----------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestOpAnnotation.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestOpAnnotation.java
index 03484d6..0249f31 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestOpAnnotation.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestOpAnnotation.java
@@ -18,6 +18,7 @@ import static org.apache.juneau.http.HttpParts.*;
import java.lang.annotation.*;
import java.nio.charset.*;
+import java.util.function.*;
import org.apache.juneau.*;
import org.apache.juneau.annotation.*;
@@ -51,6 +52,11 @@ public class RestOpAnnotation {
public static final RestOp DEFAULT = create().build();
/**
+ * Predicate that can be used with the {@link
ClassInfo#getAnnotationList(Predicate)} and {@link
MethodInfo#getAnnotationList(Predicate)}
+ */
+ public static final Predicate<AnnotationInfo<?>> REST_OP_GROUP = x ->
x.isInGroup(RestOp.class);
+
+ /**
* Instantiates a new builder for this class.
*
* @return A new builder object.
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/matcher/ClientVersionMatcher.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/matcher/ClientVersionMatcher.java
index 3623095..511fae0 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/matcher/ClientVersionMatcher.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/matcher/ClientVersionMatcher.java
@@ -13,12 +13,13 @@
package org.apache.juneau.rest.matcher;
import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.annotation.RestOpAnnotation.*;
import javax.servlet.http.*;
+import org.apache.juneau.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.reflect.*;
-import org.apache.juneau.rest.annotation.*;
/**
* Specialized matcher for matching client versions.
@@ -43,8 +44,9 @@ public class ClientVersionMatcher extends RestMatcher {
*/
public ClientVersionMatcher(String clientVersionHeader, MethodInfo mi) {
this.clientVersionHeader = isEmpty(clientVersionHeader) ?
"Client-Version" : clientVersionHeader;
- String clientVersion =
mi.getAnnotationGroupList(RestOp.class).getValues(String.class,
"clientVersion").stream().filter(x->!x.isEmpty()).findFirst().orElse(null);
- range = new VersionRange(clientVersion);
+ Value<String> clientVersion = Value.empty();
+ mi.getAnnotationList(REST_OP_GROUP).getValues(String.class,
"clientVersion", StringUtils::isNotEmpty, x -> clientVersion.set(x));
+ range = new VersionRange(clientVersion.orElse(null));
}
@Override /* RestMatcher */
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
index 8f11259..680f944 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
@@ -16,6 +16,7 @@ import static org.apache.juneau.internal.ClassUtils.*;
import static org.apache.juneau.internal.ThrowableUtils.*;
import static org.apache.juneau.rest.httppart.RestPartType.*;
import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.rest.annotation.RestOpAnnotation.*;
import java.io.*;
import java.lang.reflect.*;
@@ -218,14 +219,16 @@ public class BasicSwaggerProviderSession {
Method m = sm.getJavaMethod();
MethodInfo mi = MethodInfo.of(m);
- AnnotationList al =
mi.getAnnotationGroupList(RestOp.class);
+ AnnotationList al = mi.getAnnotationList(REST_OP_GROUP);
String mn = m.getName();
// Get the operation from the existing swagger so far.
OMap op = getOperation(omSwagger, sm.getPathPattern(),
sm.getHttpMethod().toLowerCase());
// Add @RestOp(swagger)
- OpSwagger ms = al.getValues(OpSwagger.class,
"swagger").stream().filter(x -> !
OpSwaggerAnnotation.empty(x)).findFirst().orElse(OpSwaggerAnnotation.create().build());
+ Value<OpSwagger> _ms = Value.empty();
+ al.getValues(OpSwagger.class, "swagger",
OpSwaggerAnnotation::notEmpty, x -> _ms.set(x));
+ OpSwagger ms =
_ms.orElseGet(()->OpSwaggerAnnotation.create().build());
op.append(parseMap(ms.value(), "@OpSwagger(value) on
class {0} method {1}", c, m));
op.appendSkipEmpty("operationId",
@@ -235,20 +238,26 @@ public class BasicSwaggerProviderSession {
mn
)
);
+
+ Value<String> _summary = Value.empty();
+ al.getValues(String.class, "summary",
StringUtils::isNotEmpty, x -> _summary.set(x));
op.appendSkipEmpty("summary",
firstNonEmpty(
resolve(ms.summary()),
resolve(mb.findFirstString(mn +
".summary")),
op.getString("summary"),
- resolve(al.getValues(String.class,
"summary").stream().filter(x -> !x.isEmpty()).findFirst().orElse(null))
+ resolve(_summary.orElse(null))
)
);
+
+ Value<String[]> _description = Value.empty();
+ al.getValues(String[].class, "description",x ->
x.length > 0, x -> _description.set(x));
op.appendSkipEmpty("description",
firstNonEmpty(
resolve(ms.description()),
resolve(mb.findFirstString(mn +
".description")),
op.getString("description"),
- resolve(al.getValues(String[].class,
"description").stream().filter(x -> x.length > 0).findFirst().orElse(new
String[0]))
+ resolve(_description.orElse(new
String[0]))
)
);
op.appendSkipEmpty("deprecated",
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/reflection/AnnotationInfoTest.java
b/juneau-utest/src/test/java/org/apache/juneau/reflection/AnnotationInfoTest.java
index 4f99e98..cfacdc1 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/reflection/AnnotationInfoTest.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/reflection/AnnotationInfoTest.java
@@ -50,7 +50,7 @@ public class AnnotationInfoTest {
@Test
public void d01_isInGroup() {
ClassInfo d = ClassInfo.of(D.class);
- AnnotationList l = d.getAnnotationGroupList(D1.class);
+ AnnotationList l = d.getAnnotationList(x ->
x.isInGroup(D1.class));
assertList(l).isSize(2);
}
}
\ No newline at end of file