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 87aa54b JUNEAU-197
87aa54b is described below
commit 87aa54b56f45edc676d834c6881f1d0a6f2e909f
Author: JamesBognar <[email protected]>
AuthorDate: Mon Mar 9 11:45:43 2020 -0400
JUNEAU-197
@BeanConfig(bpi) does not override @Bean(bpi)
---
.../main/java/org/apache/juneau/BeanContext.java | 12 +++---
.../src/main/java/org/apache/juneau/BeanMeta.java | 44 ++++++++++++----------
.../java/org/apache/juneau/BeanPropertyMeta.java | 16 ++++----
.../main/java/org/apache/juneau/MetaProvider.java | 9 -----
.../apache/juneau/html/HtmlBeanPropertyMeta.java | 3 +-
.../java/org/apache/juneau/reflect/FieldInfo.java | 6 ++-
6 files changed, 44 insertions(+), 46 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 552b7e0..91c63d2 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
@@ -3369,12 +3369,12 @@ public class BeanContext extends Context implements
MetaProvider {
return (List<A>)aa;
}
- @Override
- public <A extends Annotation> A getAnnotation(Class<A> a, Field f) {
- List<A> aa = getAnnotations(a, f);
- return aa.isEmpty() ? null : aa.get(0);
- }
-
+// @Override
+// public <A extends Annotation> A getAnnotation(Class<A> a, Field f) {
+// List<A> aa = getAnnotations(a, f);
+// return aa.isEmpty() ? null : aa.get(0);
+// }
+//
/**
* Finds the specified annotation on the specified field.
*
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
index 37e137f..f56d34e 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
@@ -541,9 +541,9 @@ public class BeanMeta<T> {
private String findPropertyName(Field f, Set<String>
fixedBeanProps) {
@SuppressWarnings("deprecation")
BeanProperty px = f.getAnnotation(BeanProperty.class);
- Beanp p = ctx.getAnnotation(Beanp.class, f);
- Name n = ctx.getAnnotation(Name.class, f);
- String name = bpName(px, p, n);
+ List<Beanp> lp = ctx.getAnnotations(Beanp.class, f);
+ List<Name> ln = ctx.getAnnotations(Name.class, f);
+ String name = bpName(px, lp, ln);
if (isNotEmpty(name)) {
if (fixedBeanProps.isEmpty() ||
fixedBeanProps.contains(name))
return name;
@@ -682,9 +682,9 @@ public class BeanMeta<T> {
@SuppressWarnings("deprecation")
BeanProperty px =
m.getLastAnnotation(BeanProperty.class);
- Beanp p = ctx.getAnnotation(Beanp.class, m);
- Name n2 = ctx.getAnnotation(Name.class, m);
- if (! (m.isVisible(v) || px != null || p !=
null || n2 != null))
+ List<Beanp> lp =
ctx.getAnnotations(Beanp.class, m);
+ List<Name> ln = ctx.getAnnotations(Name.class,
m);
+ if (! (m.isVisible(v) || px != null ||
lp.size() > 0 || ln.size() > 0))
continue;
String n = m.getSimpleName();
@@ -692,7 +692,7 @@ public class BeanMeta<T> {
List<ClassInfo> pt = m.getParamTypes();
ClassInfo rt = m.getReturnType();
MethodType methodType = UNKNOWN;
- String bpName = bpName(px, p, n2);
+ String bpName = bpName(px, lp, ln);
if (! (isEmpty(bpName) || filterProps.isEmpty()
|| filterProps.contains(bpName)))
throw new BeanRuntimeException(c,
"Found @Beanp(\"{0}\") but name was not found in @Bean(properties)", bpName);
@@ -788,11 +788,11 @@ public class BeanMeta<T> {
@SuppressWarnings("deprecation")
BeanProperty px =
f.getAnnotation(BeanProperty.class);
- Beanp p = ctx.getAnnotation(Beanp.class, f);
- Name n = ctx.getAnnotation(Name.class, f);
- String bpName = bpName(px, p, n);
+ List<Beanp> lp =
ctx.getAnnotations(Beanp.class, f);
+ List<Name> ln = ctx.getAnnotations(Name.class,
f);
+ String bpName = bpName(px, lp, ln);
- if (! (v.isVisible(f.inner()) || px != null ||
p != null))
+ if (! (v.isVisible(f.inner()) || px != null ||
lp.size() > 0))
continue;
if (! (isEmpty(bpName) || filterProps.isEmpty()
|| filterProps.contains(bpName)))
@@ -957,16 +957,22 @@ public class BeanMeta<T> {
}
@SuppressWarnings("deprecation")
- static final String bpName(BeanProperty px, Beanp p, Name n) {
- if (px == null && p == null && n == null)
+ static final String bpName(BeanProperty px, List<Beanp> p, List<Name>
n) {
+ if (px == null && p.isEmpty() && n.isEmpty())
return null;
- if (n != null)
- return n.value();
- if (p != null) {
- if (! p.name().isEmpty())
- return p.name();
- return p.value();
+ if (! n.isEmpty())
+ return last(n).value();
+
+ String name = p.isEmpty() ? null : "";
+ for (Beanp pp : p) {
+ if (! pp.value().isEmpty())
+ name = pp.value();
+ if (! pp.name().isEmpty())
+ name = pp.name();
}
+ if (name != null)
+ return name;
+
if (px != null) {
if (! px.name().isEmpty())
return px.name();
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 aec81f2..cf396f1 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
@@ -175,11 +175,11 @@ public final class BeanPropertyMeta {
if (innerField != null) {
BeanProperty px =
innerField.getAnnotation(BeanProperty.class);
- Beanp p = bc.getAnnotation(Beanp.class,
innerField);
- if (field != null || px != null || p != null) {
+ List<Beanp> lp = bc.getAnnotations(Beanp.class,
innerField);
+ if (field != null || px != null || lp.size() >
0) {
// Only use field type if it's a bean
property or has @Beanp annotation.
// Otherwise, we want to infer the type
from the getter or setter.
- rawTypeMeta = bc.resolveClassMeta(px,
p, innerField.getGenericType(), typeVarImpls);
+ rawTypeMeta = bc.resolveClassMeta(px,
last(lp), innerField.getGenericType(), typeVarImpls);
isUri |= (rawTypeMeta.isUri());
}
if (px != null) {
@@ -187,7 +187,7 @@ public final class BeanPropertyMeta {
properties =
split(px.properties());
bdClasses.addAll(Arrays.asList(px.beanDictionary()));
}
- if (p != null) {
+ for (Beanp p : lp) {
if (! p.properties().isEmpty())
properties =
split(p.properties());
bdClasses.addAll(Arrays.asList(p.dictionary()));
@@ -196,11 +196,9 @@ public final class BeanPropertyMeta {
if (! p.wo().isEmpty())
writeOnly =
Boolean.valueOf(p.wo());
}
- Swap s = bc.getAnnotation(Swap.class,
innerField);
- if (s != null) {
+ for (Swap s : bc.getAnnotations(Swap.class,
innerField))
swap = getPropertyPojoSwap(s);
- }
- isUri |=
bc.getAnnotation(org.apache.juneau.annotation.URI.class, innerField) != null;
+ isUri |=
last(bc.getAnnotations(org.apache.juneau.annotation.URI.class, innerField)) !=
null;
}
if (getter != null) {
@@ -1131,7 +1129,7 @@ public final class BeanPropertyMeta {
getBeanMeta().getClassMeta().getInfo().appendAnnotations(l, a,
bc);
if (field != null) {
- addIfNotNull(l, bc.getAnnotation(a, field));
+ l.addAll(bc.getAnnotations(a, field));
ClassInfo.of(field.getType()).appendAnnotations(l, a,
bc);
}
if (getter != null) {
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 dd02af1..29768a9 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, Field
f) {
- List<A> l = getAnnotations(a, f);
- return l.isEmpty() ? null : l.get(0);
- }
-
- @Override
public <A extends Annotation> A getAnnotation(Class<A> a,
Constructor<?> c) {
List<A> l = getAnnotations(a, c);
return l.isEmpty() ? null : l.get(0);
@@ -120,9 +114,6 @@ public interface MetaProvider {
*/
<A extends Annotation> List<A> getAnnotations(Class<A> a, Field f);
- // TEMPORARY
- <A extends Annotation> A getAnnotation(Class<A> a, Field f);
-
/**
* Finds the specified annotation on the specified constructor.
*
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 e565d6f..408b9c2 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
@@ -45,7 +45,8 @@ public final class HtmlBeanPropertyMeta extends
ExtendedBeanPropertyMeta {
Builder b = new Builder();
if (bpm.getInnerField() != null)
- b.findHtmlInfo(mp.getAnnotation(Html.class,
bpm.getInnerField()));
+ for (Html html : mp.getAnnotations(Html.class,
bpm.getInnerField()))
+ b.findHtmlInfo(html);
if (bpm.getGetter() != null)
for (Html html : mp.getAnnotations(Html.class,
bpm.getGetter()))
b.findHtmlInfo(html);
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/FieldInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/FieldInfo.java
index 9cce182..4f9ad19 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/FieldInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/FieldInfo.java
@@ -12,6 +12,8 @@
//
***************************************************************************************************************************
package org.apache.juneau.reflect;
+import static org.apache.juneau.internal.CollectionUtils.*;
+
import java.lang.annotation.*;
import java.lang.reflect.*;
@@ -109,7 +111,7 @@ public final class FieldInfo implements
Comparable<FieldInfo> {
* @return The annotation, or <jk>null</jk> if not found.
*/
public <T extends Annotation> T getAnnotation(Class<T> a, MetaProvider
mp) {
- return mp.getAnnotation(a, f);
+ return last(mp.getAnnotations(a, f));
}
/**
@@ -130,7 +132,7 @@ public final class FieldInfo implements
Comparable<FieldInfo> {
* @return <jk>true</jk> if the specified annotation is present.
*/
public boolean hasAnnotation(Class<? extends Annotation> a,
MetaProvider mp) {
- return mp.getAnnotation(a, f) != null;
+ return ! mp.getAnnotations(a, f).isEmpty();
}
//-----------------------------------------------------------------------------------------------------------------