public static boolean isBenchmarkable ( final Method meth ) { boolean returnVal = true ; // Check if bench-anno is given. For testing purposes against // before/after annos final Bench benchAnno = meth . getAnnotation ( Bench . class ) ; // if method is annotated with SkipBench, the method is never // benchmarkable. final SkipBench skipBenchAnno = meth . getAnnotation ( SkipBench . class ) ; if ( skipBenchAnno != null ) { returnVal = false ; } // Check if method is defined as beforeClass, beforeFirstRun, // beforeEachRun, afterEachRun, afterLastRun, afterClass. A method can // either be a before/after class or afterwards be benchmarkable through // the BenchClass annotation. final BeforeBenchClass beforeClass = meth . getAnnotation ( BeforeBenchClass . class ) ; if ( beforeClass != null && benchAnno == null ) { returnVal = false ; } final BeforeFirstRun beforeFirstRun = meth . getAnnotation ( BeforeFirstRun . class ) ; if ( beforeFirstRun != null && benchAnno == null ) { returnVal = false ; } final BeforeEachRun beforeEachRun = meth . getAnnotation ( BeforeEachRun . class ) ; if ( beforeEachRun != null && benchAnno == null ) { returnVal = false ; } final AfterEachRun afterEachRun = meth . getAnnotation ( AfterEachRun . class ) ; if ( afterEachRun != null && benchAnno == null ) { returnVal = false ; } final AfterLastRun afterLastRun = meth . getAnnotation ( AfterLastRun . class ) ; if ( afterLastRun != null && benchAnno == null ) { returnVal = false ; } final AfterBenchClass afterClass = meth . getAnnotation ( AfterBenchClass . class ) ; if ( afterClass != null && benchAnno == null ) { returnVal = false ; } // if method is not annotated with Bench and class is not annotated with // BenchClass, the method is never benchmarkable. final BenchClass classBenchAnno = meth . getDeclaringClass ( ) . getAnnotation ( BenchClass . class ) ; if ( benchAnno == null && classBenchAnno == null ) { returnVal = false ; } // check if method is executable for perfidix purposes. if ( ! isReflectedExecutable ( meth , Bench . class ) ) { returnVal = false ; } return returnVal ; }
This method should act as a check to guarantee that only specific Benchmarkables are used for benching .