Skip to content

Commit 6b480bf

Browse files
committed
use set binding in ValidateComponent
1 parent 2adac2f commit 6b480bf

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

compiler/src/main/java/net/jbock/convert/match/MatchFinder.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import javax.lang.model.type.PrimitiveType;
1414
import javax.lang.model.type.TypeMirror;
1515
import java.util.Optional;
16-
import java.util.stream.Stream;
16+
import java.util.Set;
1717

1818
import static io.jbock.util.Either.right;
1919
import static javax.lang.model.type.TypeKind.BOOLEAN;
@@ -24,17 +24,14 @@
2424
@ValidateScope
2525
public class MatchFinder {
2626

27-
private final OptionalMatcher optionalMatcher;
28-
private final ListMatcher listMatcher;
27+
private final Set<Matcher> matchers;
2928
private final SafeTypes types;
3029

3130
@Inject
3231
MatchFinder(
33-
OptionalMatcher optionalMatcher,
34-
ListMatcher listMatcher,
32+
Set<Matcher> matchers,
3533
SafeTypes types) {
36-
this.optionalMatcher = optionalMatcher;
37-
this.listMatcher = listMatcher;
34+
this.matchers = matchers;
3835
this.types = types;
3936
}
4037

@@ -61,7 +58,7 @@ Either<ValidationFailure, Match<M>> findMatch(
6158
private <M extends AnnotatedMethod> Match<M>
6259
findMatchInternal(
6360
M sourceMethod) {
64-
return Stream.of(optionalMatcher, listMatcher)
61+
return matchers.stream()
6562
.map(matcher -> matcher.tryMatch(sourceMethod))
6663
.flatMap(Optional::stream)
6764
.findFirst()

compiler/src/main/java/net/jbock/validate/ValidateComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/* subcomponent of ProcessorComponent */
88
@ValidateScope
9-
@Subcomponent
9+
@Subcomponent(modules = ValidateModule.class)
1010
public interface ValidateComponent {
1111

1212
CommandProcessor processor();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package net.jbock.validate;
2+
3+
import dagger.Binds;
4+
import dagger.Module;
5+
import dagger.multibindings.IntoSet;
6+
import net.jbock.convert.match.ListMatcher;
7+
import net.jbock.convert.match.Matcher;
8+
import net.jbock.convert.match.OptionalMatcher;
9+
10+
@Module
11+
public interface ValidateModule {
12+
13+
@Binds
14+
@IntoSet
15+
Matcher optionalMatcher(OptionalMatcher validator);
16+
17+
@Binds
18+
@IntoSet
19+
Matcher listMatcher(ListMatcher validator);
20+
}

0 commit comments

Comments
 (0)