You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2020/06/17 08:18:01 UTC
[openwebbeans] branch master updated: refactor stream into concrete
logic
This is an automated email from the ASF dual-hosted git repository.
struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 16b0d7e refactor stream into concrete logic
16b0d7e is described below
commit 16b0d7e1fb3db03401b3bd9a65077f9abb942983
Author: Mark Struberg <st...@apache.org>
AuthorDate: Wed Jun 17 09:30:04 2020 +0200
refactor stream into concrete logic
Stream fell back to CopyOnWriteArrayList operations which are expensive.
---
.../webbeans/portable/AbstractAnnotated.java | 51 ++++++++++++++--------
1 file changed, 32 insertions(+), 19 deletions(-)
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java b/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
index 7656168..9406c47 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
@@ -19,19 +19,22 @@
package org.apache.webbeans.portable;
import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
-import java.util.Objects;
import java.util.Optional;
import java.util.Set;
-import java.util.stream.Stream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.enterprise.inject.spi.Annotated;
import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
import org.apache.webbeans.util.Asserts;
import org.apache.webbeans.util.GenericsUtil;
@@ -45,6 +48,8 @@ import static java.util.stream.Collectors.toList;
*/
public abstract class AbstractAnnotated implements Annotated
{
+ private static final Logger logger = WebBeansLoggerFacade.getLogger(AbstractAnnotated.class);
+
/**Base type of an annotated element*/
private final Type baseType;
@@ -93,27 +98,35 @@ public abstract class AbstractAnnotated implements Annotated
{
return;
}
- List<Annotation> repeatables = annotations.stream()
- .map(a -> {
- Class<?> type = a.annotationType();
- try
+
+ List<Annotation> repeatables = null;
+ for (Annotation annotation : annotations)
+ {
+ Class<?> type = annotation.annotationType();
+ Optional<Method> repeatableMethod = webBeansContext.getAnnotationManager().getRepeatableMethod(type);
+ if (repeatableMethod.isPresent())
+ {
+ try
+ {
+ if (repeatables == null)
{
- Optional<Method> repeatableMethod =
- webBeansContext.getAnnotationManager().getRepeatableMethod(type);
- if (!repeatableMethod.isPresent())
- {
- return null;
- }
- return (Annotation[]) repeatableMethod.orElseThrow(IllegalStateException::new).invoke(a);
+ repeatables = new ArrayList<>();
}
- catch (Exception e)
+ Annotation[] repeatableAnns =
+ (Annotation[]) repeatableMethod.orElseThrow(IllegalStateException::new).invoke(annotation);
+ for (Annotation repeatableAnn : repeatableAnns)
{
- return null;
+ repeatables.add(repeatableAnn);
}
- }).filter(Objects::nonNull)
- .flatMap(Stream::of)
- .collect(toList());
- if (!repeatables.isEmpty())
+ }
+ catch (IllegalAccessException | InvocationTargetException e)
+ {
+ logger.log(Level.FINER, "Problem while handling repeatable Annotations "
+ + annotation.annotationType());
+ }
+ }
+ }
+ if (repeatables != null && !repeatables.isEmpty())
{
this.repeatables.addAll(repeatables.stream().map(Annotation::annotationType).collect(toList()));
this.annotations.addAll(repeatables);