1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ibatis.builder.annotation;
18
19 import java.lang.reflect.Method;
20 import java.util.Arrays;
21 import java.util.List;
22 import java.util.stream.Collectors;
23
24 import org.apache.ibatis.builder.BuilderException;
25
26
27
28
29
30
31
32
33
34
35 public interface ProviderMethodResolver {
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 default Method resolveMethod(ProviderContext context) {
52 List<Method> sameNameMethods = Arrays.stream(getClass().getMethods())
53 .filter(m -> m.getName().equals(context.getMapperMethod().getName()))
54 .collect(Collectors.toList());
55 if (sameNameMethods.isEmpty()) {
56 throw new BuilderException("Cannot resolve the provider method because '"
57 + context.getMapperMethod().getName() + "' not found in SqlProvider '" + getClass().getName() + "'.");
58 }
59 List<Method> targetMethods = sameNameMethods.stream()
60 .filter(m -> CharSequence.class.isAssignableFrom(m.getReturnType()))
61 .collect(Collectors.toList());
62 if (targetMethods.size() == 1) {
63 return targetMethods.get(0);
64 }
65 if (targetMethods.isEmpty()) {
66 throw new BuilderException("Cannot resolve the provider method because '"
67 + context.getMapperMethod().getName() + "' does not return the CharSequence or its subclass in SqlProvider '"
68 + getClass().getName() + "'.");
69 } else {
70 throw new BuilderException("Cannot resolve the provider method because '"
71 + context.getMapperMethod().getName() + "' is found multiple in SqlProvider '" + getClass().getName() + "'.");
72 }
73 }
74
75 }