• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.caliper.runner;
18 
19 import com.google.caliper.runner.Running.AfterExperimentMethods;
20 import com.google.caliper.runner.Running.BeforeExperimentMethods;
21 import com.google.common.collect.ImmutableSet;
22 import dagger.Module;
23 import dagger.Provides;
24 
25 import java.lang.reflect.Method;
26 import javax.inject.Singleton;
27 
28 /**
29  * Binds objects related to a benchmark class.
30  */
31 // TODO(gak): move more of benchmark class into this module
32 @Module
33 public final class BenchmarkClassModule {
34 
35   @Provides
36   @Singleton
provideBenchmarkClass(@unning.BenchmarkClass Class<?> benchmarkClassObject)37   static BenchmarkClass provideBenchmarkClass(@Running.BenchmarkClass Class<?> benchmarkClassObject)
38       throws InvalidBenchmarkException {
39     return BenchmarkClass.forClass(benchmarkClassObject);
40   }
41 
42   @Provides
43   @BeforeExperimentMethods
provideBeforeExperimentMethods( BenchmarkClass benchmarkClass)44   static ImmutableSet<Method> provideBeforeExperimentMethods(
45       BenchmarkClass benchmarkClass) {
46     return benchmarkClass.beforeExperimentMethods();
47   }
48 
49   @Provides
50   @AfterExperimentMethods
provideAfterExperimentMethods( BenchmarkClass benchmarkClass)51   static ImmutableSet<Method> provideAfterExperimentMethods(
52       BenchmarkClass benchmarkClass) {
53     return benchmarkClass.afterExperimentMethods();
54   }
55 }
56