1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.builder.annotation;
17
18 import java.lang.reflect.Method;
19 import java.util.Arrays;
20 import java.util.List;
21 import java.util.stream.Collectors;
22
23 import org.apache.ibatis.builder.BuilderException;
24
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
52
53
54
55 default Method resolveMethod(ProviderContext context) {
56 List<Method> sameNameMethods = Arrays.stream(getClass().getMethods())
57 .filter(m -> m.getName().equals(context.getMapperMethod().getName())).collect(Collectors.toList());
58 if (sameNameMethods.isEmpty()) {
59 throw new BuilderException("Cannot resolve the provider method because '" + context.getMapperMethod().getName()
60 + "' not found in SqlProvider '" + getClass().getName() + "'.");
61 }
62 List<Method> targetMethods = sameNameMethods.stream()
63 .filter(m -> CharSequence.class.isAssignableFrom(m.getReturnType())).collect(Collectors.toList());
64 if (targetMethods.size() == 1) {
65 return targetMethods.get(0);
66 }
67 if (targetMethods.isEmpty()) {
68 throw new BuilderException("Cannot resolve the provider method because '" + context.getMapperMethod().getName()
69 + "' does not return the CharSequence or its subclass in SqlProvider '" + getClass().getName() + "'.");
70 }
71 throw new BuilderException("Cannot resolve the provider method because '" + context.getMapperMethod().getName()
72 + "' is found multiple in SqlProvider '" + getClass().getName() + "'.");
73 }
74
75 }