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 e404996  JUNEAU-197
e404996 is described below

commit e404996e565a51d8a75f6cd0a88278b13cae1429
Author: JamesBognar <[email protected]>
AuthorDate: Mon Mar 9 11:20:07 2020 -0400

    JUNEAU-197
    
    @BeanConfig(bpi) does not override @Bean(bpi)
---
 .../main/java/org/apache/juneau/BeanContext.java   | 22 +++++++--------
 .../java/org/apache/juneau/BeanPropertyMeta.java   | 32 ++++++++++------------
 .../main/java/org/apache/juneau/MetaProvider.java  |  9 ------
 .../apache/juneau/html/HtmlBeanPropertyMeta.java   |  6 ++--
 .../apache/juneau/internal/CollectionUtils.java    | 13 +++++++++
 .../java/org/apache/juneau/reflect/MethodInfo.java |  4 ++-
 6 files changed, 44 insertions(+), 42 deletions(-)

diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
index 53fb413..552b7e0 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
@@ -3251,12 +3251,10 @@ public class BeanContext extends Context implements 
MetaProvider {
                return (List<A>)aa;
        }
 
-//     @Override
-//     public <A extends Annotation> A getAnnotation(Class<A> a, Class<?> c) {
-//             List<A> aa = getAnnotations(a, c);
-//             return aa.isEmpty() ? null : aa.get(0);
-//     }
-//
+       public <A extends Annotation> A getLastAnnotation(Class<A> a, Class<?> 
c) {
+               return last(getAnnotations(a, c));
+       }
+
        /**
         * Finds the specified annotation on the specified class.
         *
@@ -3331,12 +3329,12 @@ public class BeanContext extends Context implements 
MetaProvider {
                return (List<A>)aa;
        }
 
-       @Override
-       public <A extends Annotation> A getAnnotation(Class<A> a, Method m) {
-               List<A> aa = getAnnotations(a, m);
-               return aa.isEmpty() ? null : aa.get(0);
-       }
-
+//     @Override
+//     public <A extends Annotation> A getAnnotation(Class<A> a, Method m) {
+//             List<A> aa = getAnnotations(a, m);
+//             return aa.isEmpty() ? null : aa.get(0);
+//     }
+//
        /**
         * Finds the specified annotation on the specified method.
         *
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
index ec778fd..aec81f2 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
@@ -205,16 +205,16 @@ public final class BeanPropertyMeta {
 
                        if (getter != null) {
                                BeanProperty px = 
MethodInfo.of(getter).getLastAnnotation(BeanProperty.class);
-                               Beanp p = bc.getAnnotation(Beanp.class, getter);
+                               List<Beanp> lp = bc.getAnnotations(Beanp.class, 
getter);
                                if (rawTypeMeta == null)
-                                       rawTypeMeta = bc.resolveClassMeta(px, 
p, getter.getGenericReturnType(), typeVarImpls);
+                                       rawTypeMeta = bc.resolveClassMeta(px, 
last(lp), getter.getGenericReturnType(), typeVarImpls);
                                isUri |= (rawTypeMeta.isUri() || 
bc.hasAnnotation(org.apache.juneau.annotation.URI.class, getter));
                                if (px != null) {
                                        if (properties != null && ! 
px.properties().isEmpty())
                                                properties = 
split(px.properties());
                                        
bdClasses.addAll(Arrays.asList(px.beanDictionary()));
                                }
-                               if (p != null) {
+                               for (Beanp p : lp) {
                                        if (properties != null && ! 
p.properties().isEmpty())
                                                properties = 
split(p.properties());
                                        
bdClasses.addAll(Arrays.asList(p.dictionary()));
@@ -223,17 +223,15 @@ public final class BeanPropertyMeta {
                                        if (! p.wo().isEmpty())
                                                writeOnly = 
Boolean.valueOf(p.wo());
                                }
-                               Swap s = bc.getAnnotation(Swap.class, getter);
-                               if (s != null && swap == null) {
+                               for (Swap s : bc.getAnnotations(Swap.class, 
getter))
                                        swap = getPropertyPojoSwap(s);
-                               }
                        }
 
                        if (setter != null) {
                                BeanProperty px = 
MethodInfo.of(setter).getLastAnnotation(BeanProperty.class);
-                               Beanp p = bc.getAnnotation(Beanp.class, setter);
+                               List<Beanp> lp = bc.getAnnotations(Beanp.class, 
setter);
                                if (rawTypeMeta == null)
-                                       rawTypeMeta = bc.resolveClassMeta(px, 
p, setter.getGenericParameterTypes()[0], typeVarImpls);
+                                       rawTypeMeta = bc.resolveClassMeta(px, 
last(lp), setter.getGenericParameterTypes()[0], typeVarImpls);
                                isUri |= (rawTypeMeta.isUri() || 
bc.hasAnnotation(org.apache.juneau.annotation.URI.class, setter));
                                if (px != null) {
                                        if (swap == null)
@@ -242,7 +240,7 @@ public final class BeanPropertyMeta {
                                                properties = 
split(px.properties());
                                        
bdClasses.addAll(Arrays.asList(px.beanDictionary()));
                                }
-                               if (p != null) {
+                               for (Beanp p : lp) {
                                        if (swap == null)
                                                swap = getPropertyPojoSwap(p);
                                        if (properties != null && ! 
p.properties().isEmpty())
@@ -253,10 +251,8 @@ public final class BeanPropertyMeta {
                                        if (! p.wo().isEmpty())
                                                writeOnly = 
Boolean.valueOf(p.wo());
                                }
-                               Swap s = bc.getAnnotation(Swap.class, setter);
-                               if (s != null && swap == null) {
+                               for (Swap s : bc.getAnnotations(Swap.class, 
setter))
                                        swap = getPropertyPojoSwap(s);
-                               }
                        }
 
                        if (rawTypeMeta == null)
@@ -1139,15 +1135,15 @@ public final class BeanPropertyMeta {
                        ClassInfo.of(field.getType()).appendAnnotations(l, a, 
bc);
                }
                if (getter != null) {
-                       addIfNotNull(l, bc.getAnnotation(a, getter));
+                       l.addAll(bc.getAnnotations(a, getter));
                        
ClassInfo.of(getter.getReturnType()).appendAnnotations(l, a, bc);
                }
                if (setter != null) {
-                       addIfNotNull(l, bc.getAnnotation(a, setter));
+                       l.addAll(bc.getAnnotations(a, setter));
                        
ClassInfo.of(setter.getReturnType()).appendAnnotations(l, a, bc);
                }
                if (extraKeys != null) {
-                       addIfNotNull(l, bc.getAnnotation(a, extraKeys));
+                       l.addAll(bc.getAnnotations(a, extraKeys));
                        
ClassInfo.of(extraKeys.getReturnType()).appendAnnotations(l, a, bc);
                }
 
@@ -1166,9 +1162,9 @@ public final class BeanPropertyMeta {
                BeanContext bc = beanContext;
                if (a == null)
                        return l;
-               addIfNotNull(l, bc.getAnnotation(a, field));
-               addIfNotNull(l, bc.getAnnotation(a, getter));
-               addIfNotNull(l, bc.getAnnotation(a, setter));
+               l.addAll(bc.getAnnotations(a, field));
+               l.addAll(bc.getAnnotations(a, getter));
+               l.addAll(bc.getAnnotations(a, setter));
                return l;
        }
 
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MetaProvider.java 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MetaProvider.java
index 65339f3..dd02af1 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MetaProvider.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MetaProvider.java
@@ -68,12 +68,6 @@ public interface MetaProvider {
                }
 
                @Override
-               public <A extends Annotation> A getAnnotation(Class<A> a, 
Method m) {
-                       List<A> l = getAnnotations(a, m);
-                       return l.isEmpty() ? null : l.get(0);
-               }
-
-               @Override
                public <A extends Annotation> A getAnnotation(Class<A> a, Field 
f) {
                        List<A> l = getAnnotations(a, f);
                        return l.isEmpty() ? null : l.get(0);
@@ -116,9 +110,6 @@ public interface MetaProvider {
         */
        <A extends Annotation> List<A> getAnnotations(Class<A> a, Method m);
 
-       // TEMPORARY
-       <A extends Annotation> A getAnnotation(Class<A> a, Method m);
-
        /**
         * Finds the specified annotation on the specified field.
         *
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlBeanPropertyMeta.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlBeanPropertyMeta.java
index b6f142c..e565d6f 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlBeanPropertyMeta.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlBeanPropertyMeta.java
@@ -47,9 +47,11 @@ public final class HtmlBeanPropertyMeta extends 
ExtendedBeanPropertyMeta {
                if (bpm.getInnerField() != null)
                        b.findHtmlInfo(mp.getAnnotation(Html.class, 
bpm.getInnerField()));
                if (bpm.getGetter() != null)
-                       b.findHtmlInfo(mp.getAnnotation(Html.class, 
bpm.getGetter()));
+                       for (Html html : mp.getAnnotations(Html.class, 
bpm.getGetter()))
+                               b.findHtmlInfo(html);
                if (bpm.getSetter() != null)
-                       b.findHtmlInfo(mp.getAnnotation(Html.class, 
bpm.getSetter()));
+                       for (Html html : mp.getAnnotations(Html.class, 
bpm.getSetter()))
+                               b.findHtmlInfo(html);
 
                this.format = b.format;
                this.noTables = b.noTables;
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/CollectionUtils.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/CollectionUtils.java
index d778f46..48720dc 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/CollectionUtils.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/CollectionUtils.java
@@ -536,4 +536,17 @@ public final class CollectionUtils {
        public static <K,V> Map<K,V> emptyMap() {
                return Collections.emptyMap();
        }
+
+       /**
+        * Returns the last entry in a list.
+        *
+        * @param <T> The element type.
+        * @param l The list.
+        * @return The last element, or <jk>null</jk> if the list is 
<jk>null</jk> or empty.
+        */
+       public static <T> T last(List<T> l) {
+               if (l == null || l.isEmpty())
+                       return null;
+               return l.get(l.size()-1);
+       }
 }
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 f9d0b39..96635cc 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
@@ -12,6 +12,8 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau.reflect;
 
+import static org.apache.juneau.internal.CollectionUtils.*;
+
 import java.beans.*;
 import java.lang.annotation.*;
 import java.lang.reflect.*;
@@ -189,7 +191,7 @@ public final class MethodInfo extends ExecutableInfo 
implements Comparable<Metho
                if (a == null)
                        return null;
                for (Method m2 : getMatching()) {
-                       T t = mp.getAnnotation(a, m2);
+                       T t = last(mp.getAnnotations(a, m2));
                        if (t != null)
                                return t;
                }

Reply via email to