Coverage Report - net.mtu.eggplant.annotation.FindBugsAnnotationProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
FindBugsAnnotationProcessor
0%
0/24
0%
0/8
2.333
 
 1  
 /*
 2  
  * Copyright (c) 2008
 3  
  *      Jon Schewe.  All rights reserved
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met:
 8  
  * 1. Redistributions of source code must retain the above copyright
 9  
  *    notice, this list of conditions and the following disclaimer.
 10  
  * 2. Redistributions in binary form must reproduce the above copyright
 11  
  *    notice, this list of conditions and the following disclaimer in the
 12  
  *    documentation and/or other materials provided with the distribution.
 13  
  *
 14  
  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 15  
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 16  
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 17  
  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 18  
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 19  
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 20  
  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 21  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 22  
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 23  
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 24  
  * SUCH DAMAGE.
 25  
  *
 26  
  * I'd appreciate comments/suggestions on the code jpschewe@mtu.net
 27  
  */
 28  
 package net.mtu.eggplant.annotation;
 29  
 
 30  
 import java.util.Collection;
 31  
 import java.util.Map;
 32  
 
 33  
 import org.slf4j.Logger;
 34  
 import org.slf4j.LoggerFactory;
 35  
 
 36  
 import com.sun.mirror.apt.AnnotationProcessor;
 37  
 import com.sun.mirror.apt.AnnotationProcessorEnvironment;
 38  
 import com.sun.mirror.declaration.AnnotationMirror;
 39  
 import com.sun.mirror.declaration.AnnotationTypeDeclaration;
 40  
 import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
 41  
 import com.sun.mirror.declaration.AnnotationValue;
 42  
 import com.sun.mirror.declaration.Declaration;
 43  
 import com.sun.mirror.util.SourcePosition;
 44  
 
 45  
 /**
 46  
  * @author jpschewe
 47  
  */
 48  
 public class FindBugsAnnotationProcessor implements AnnotationProcessor {
 49  
 
 50  0
   private static final Logger LOGGER = LoggerFactory
 51  
   .getLogger(FindBugsAnnotationProcessor.class);
 52  
 
 53  
   private AnnotationProcessorEnvironment environment;
 54  
 
 55  
   private AnnotationTypeDeclaration suppressWarningsDeclaration;
 56  
 
 57  0
   public FindBugsAnnotationProcessor(final AnnotationProcessorEnvironment env) {
 58  0
     environment = env;
 59  0
     suppressWarningsDeclaration = (AnnotationTypeDeclaration) environment.getTypeDeclaration("edu.umd.cs.findbugs.annotations.SuppressWarnings");
 60  0
   }
 61  
 
 62  
   /**
 63  
    * @see com.sun.mirror.apt.AnnotationProcessor#process()
 64  
    */
 65  
   public void process() {
 66  0
     Collection<Declaration> declarations = environment.getDeclarationsAnnotatedWith(suppressWarningsDeclaration);
 67  0
     for (Declaration declaration : declarations) {
 68  0
       processAnnotations(declaration);
 69  
     }
 70  0
   }
 71  
 
 72  
   private void processAnnotations(final Declaration declaration) {
 73  
     // Get all of the annotation usage for this declaration.
 74  
     // the annotation mirror is a reflection of what is in the source.
 75  0
     final Collection<AnnotationMirror> annotations = declaration.getAnnotationMirrors();
 76  
     
 77  0
     for (final AnnotationMirror mirror : annotations) {
 78  0
       if (mirror.getAnnotationType().getDeclaration().equals(suppressWarningsDeclaration)) {
 79  0
         final SourcePosition position = mirror.getPosition();
 80  0
         final Map<AnnotationTypeElementDeclaration, AnnotationValue> values = mirror.getElementValues();
 81  
 
 82  0
         LOGGER.info("Declaration: "
 83  
             + declaration.toString());
 84  0
         LOGGER.info("Position: "
 85  
             + position);
 86  0
         LOGGER.info("Values:");
 87  0
         for (final Map.Entry<AnnotationTypeElementDeclaration, AnnotationValue> entry : values.entrySet()) {
 88  0
           final AnnotationTypeElementDeclaration elemDecl = entry.getKey();
 89  0
           final AnnotationValue value = entry.getValue();
 90  0
           LOGGER.info("    "
 91  
               + elemDecl + "=" + value);
 92  0
         }
 93  0
       }
 94  
     }
 95  0
   }
 96  
 
 97  
 }