1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ch.qos.logback.core.joran.util.beans;
16
17 import java.lang.reflect.Method;
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import ch.qos.logback.core.Context;
22 import ch.qos.logback.core.spi.ContextAwareBase;
23
24
25
26
27
28
29
30
31
32
33
34
35 public class BeanDescriptionFactory extends ContextAwareBase {
36
37 BeanDescriptionFactory(Context context) {
38 setContext(context);
39 }
40
41
42
43
44
45
46 public BeanDescription create(Class<?> clazz) {
47 Map<String, Method> propertyNameToGetter = new HashMap<String, Method>();
48 Map<String, Method> propertyNameToSetter = new HashMap<String, Method>();
49 Map<String, Method> propertyNameToAdder = new HashMap<String, Method>();
50 Method[] methods = clazz.getMethods();
51 for (Method method : methods) {
52 if (method.isBridge()) {
53
54 continue;
55 }
56 if (BeanUtil.isGetter(method)) {
57 String propertyName = BeanUtil.getPropertyName(method);
58 Method oldGetter = propertyNameToGetter.put(propertyName, method);
59 if (oldGetter != null) {
60 if (oldGetter.getName().startsWith(BeanUtil.PREFIX_GETTER_IS)) {
61 propertyNameToGetter.put(propertyName, oldGetter);
62 }
63 String message = String.format("Class '%s' contains multiple getters for the same property '%s'.",
64 clazz.getCanonicalName(), propertyName);
65 addWarn(message);
66 }
67 } else if (BeanUtil.isSetter(method)) {
68 String propertyName = BeanUtil.getPropertyName(method);
69 Method oldSetter = propertyNameToSetter.put(propertyName, method);
70 if (oldSetter != null) {
71 String message = String.format("Class '%s' contains multiple setters for the same property '%s'.",
72 clazz.getCanonicalName(), propertyName);
73 addWarn(message);
74 }
75 } else if (BeanUtil.isAdder(method)) {
76 String propertyName = BeanUtil.getPropertyName(method);
77 Method oldAdder = propertyNameToAdder.put(propertyName, method);
78 if (oldAdder != null) {
79 String message = String.format("Class '%s' contains multiple adders for the same property '%s'.",
80 clazz.getCanonicalName(), propertyName);
81 addWarn(message);
82 }
83 }
84 }
85 return new BeanDescription(clazz, propertyNameToGetter, propertyNameToSetter, propertyNameToAdder);
86 }
87 }