Coverage Report - com.lexicalscope.fluentreflection.FluentAnnotatedImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
FluentAnnotatedImpl
100%
11/11
N/A
1
 
 1  
 package com.lexicalscope.fluentreflection;
 2  
 
 3  
 import static ch.lambdaj.Lambda.*;
 4  
 import static com.lexicalscope.fluentreflection.ReflectionMatchers.reflectingOn;
 5  
 import static org.hamcrest.Matchers.hasItem;
 6  
 
 7  
 import java.lang.annotation.Annotation;
 8  
 import java.lang.reflect.AnnotatedElement;
 9  
 import java.util.List;
 10  
 
 11  
 import org.hamcrest.Matcher;
 12  
 
 13  
 /*
 14  
  * Copyright 2011 Tim Wood
 15  
  *
 16  
  * Licensed under the Apache License, Version 2.0 (the "License");
 17  
  * you may not use this file except in compliance with the License.
 18  
  * You may obtain a copy of the License at
 19  
  *
 20  
  * http://www.apache.org/licenses/LICENSE-2.0
 21  
  *
 22  
  * Unless required by applicable law or agreed to in writing, software
 23  
  * distributed under the License is distributed on an "AS IS" BASIS,
 24  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 25  
  * See the License for the specific language governing permissions and
 26  
  * limitations under the License.
 27  
  */
 28  
 final class FluentAnnotatedImpl implements FluentAnnotated {
 29  
     private final ReflectedTypeFactory reflectedTypeFactory;
 30  
     private final AnnotatedElement annotatedElement;
 31  
 
 32  24378
     public FluentAnnotatedImpl(
 33  
             final ReflectedTypeFactory reflectedTypeFactory,
 34  
             final AnnotatedElement annotatedElement) {
 35  24378
         this.reflectedTypeFactory = reflectedTypeFactory;
 36  24378
         this.annotatedElement = annotatedElement;
 37  24378
     }
 38  
 
 39  
     @Override public FluentClass<?> annotation(final Matcher<? super FluentClass<?>> annotationMatcher) {
 40  176
         return selectFirst(annotations(), annotationMatcher);
 41  
     }
 42  
 
 43  
     @Override public <A extends Annotation> A annotation(final Class<A> annotationClass) {
 44  16
         return annotatedElement.getAnnotation(annotationClass);
 45  
     }
 46  
 
 47  
     @Override public boolean annotatedWith(final Matcher<? super FluentClass<?>> annotationMatcher) {
 48  32
         return hasItem(annotationMatcher).matches(annotations());
 49  
     }
 50  
 
 51  
     @Override public boolean annotatedWith(final Class<? extends Annotation> annotationClass) {
 52  32
         return annotatedWith(reflectingOn(annotationClass));
 53  
     }
 54  
 
 55  
     private List<FluentClass<?>> annotations() {
 56  208
         return convert(
 57  208
                 convert(annotatedElement.getAnnotations(), new ConvertAnnotationToClass()),
 58  208
                 new ConvertClassToReflectedType(reflectedTypeFactory));
 59  
     }
 60  
 }