1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.guice.provision;
17
18 import com.google.inject.Binding;
19 import com.google.inject.Key;
20 import com.google.inject.matcher.AbstractMatcher;
21
22 public final class KeyMatcher<T> extends AbstractMatcher<Binding<?>> {
23 private final Key<T> key;
24
25 KeyMatcher(Key<T> key) {
26 this.key = key;
27 }
28
29 @Override
30 public boolean matches(Binding<?> t) {
31 return key.getTypeLiteral().getRawType().isAssignableFrom(t.getKey().getTypeLiteral().getRawType());
32 }
33
34 public static <T> KeyMatcher<T> create(Key<T> key) {
35 return new KeyMatcher<T>(key);
36 }
37 }