Coverage Report - org.apache.onami.test.handler.GuiceInjectableClassHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
GuiceInjectableClassHandler
100%
12/12
75%
6/8
3
 
 1  
 package org.apache.onami.test.handler;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.lang.annotation.Annotation;
 23  
 import java.lang.reflect.AccessibleObject;
 24  
 import java.lang.reflect.Member;
 25  
 import java.util.HashSet;
 26  
 import java.util.Set;
 27  
 import java.util.logging.Level;
 28  
 import java.util.logging.Logger;
 29  
 
 30  
 import org.apache.onami.test.reflection.AnnotationHandler;
 31  
 import org.apache.onami.test.reflection.HandleException;
 32  
 
 33  
 /**
 34  
  * Handler class to handle all {@link com.google.inject.Inject} annotations.
 35  
  *
 36  
  * @param <A> whatever annotation type
 37  
  * @see org.apache.onami.test.reflection.ClassVisitor
 38  
  */
 39  39
 public final class GuiceInjectableClassHandler<A extends Annotation>
 40  
     implements AnnotationHandler<A, AccessibleObject>
 41  
 {
 42  
 
 43  1
     private static final Logger LOGGER = Logger.getLogger( GuiceInjectableClassHandler.class.getName() );
 44  
 
 45  
     /**
 46  
      * Contains the guice injectable classes founded, after inspection.
 47  
      */
 48  24
     protected final Set<Class<?>> classes = new HashSet<Class<?>>();
 49  
 
 50  
     /**
 51  
      * Return all {@link Class} that contains at last one {@link com.google.inject.Inject} annotation.
 52  
      *
 53  
      * @return {@link Class} array.
 54  
      */
 55  
     public Class<?>[] getClasses()
 56  
     {
 57  24
         return classes.toArray( new Class<?>[classes.size()] );
 58  
     }
 59  
 
 60  
     /**
 61  
      * {@inheritDoc}
 62  
      */
 63  
     public void handle( A annotation, AccessibleObject element )
 64  
         throws HandleException
 65  
     {
 66  15
         Class<?> type = null;
 67  
 
 68  15
         if ( element instanceof Member )
 69  
         {
 70  15
             type = ( (Member) element ).getDeclaringClass();
 71  
         }
 72  
 
 73  15
         if ( type != null && !classes.contains( type ) )
 74  
         {
 75  10
             if ( LOGGER.isLoggable( Level.FINER ) )
 76  
             {
 77  6
                 LOGGER.finer( "   Found injectable type: " + type );
 78  
             }
 79  10
             classes.add( type );
 80  
         }
 81  15
     }
 82  
 
 83  
 }