Clover coverage report - PLT Utilities Test Coverage (plt-20120304-r5436)
Coverage timestamp: Sat Mar 3 2012 22:01:56 CST
file stats: LOC: 132   Methods: 21
NCLOC: 66   Classes: 11
 
 Source file Conditionals Statements Methods TOTAL
ReflectException.java - 90.5% 90.5% 90.5%
coverage coverage
 1    /*BEGIN_COPYRIGHT_BLOCK*
 2   
 3    PLT Utilities BSD License
 4   
 5    Copyright (c) 2007-2010 JavaPLT group at Rice University
 6    All rights reserved.
 7   
 8    Developed by: Java Programming Languages Team
 9    Rice University
 10    http://www.cs.rice.edu/~javaplt/
 11   
 12    Redistribution and use in source and binary forms, with or without modification, are permitted
 13    provided that the following conditions are met:
 14   
 15    - Redistributions of source code must retain the above copyright notice, this list of conditions
 16    and the following disclaimer.
 17    - Redistributions in binary form must reproduce the above copyright notice, this list of
 18    conditions and the following disclaimer in the documentation and/or other materials provided
 19    with the distribution.
 20    - Neither the name of the JavaPLT group, Rice University, nor the names of the library's
 21    contributors may be used to endorse or promote products derived from this software without
 22    specific prior written permission.
 23   
 24    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 25    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 26    FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND
 27    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 28    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 29    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 30    IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 31    OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 32   
 33    *END_COPYRIGHT_BLOCK*/
 34   
 35    package edu.rice.cs.plt.reflect;
 36   
 37    import java.lang.reflect.InvocationTargetException;
 38   
 39    /**
 40    * <p>An exception wrapper to simplify interactions with reflection libraries. Most documented
 41    * exceptions (but not errors) thrown by reflection methods may be wrapped by a subclass of
 42    * {@code ReflectException}. The wrapped exception may be caught and handled directly,
 43    * or unwrapped with a {@link ReflectExceptionVisitor}.</p>
 44    *
 45    * <p>Like most of the exceptions it wraps, {@code ReflectException} is a checked exception.</p>
 46    */
 47    public abstract class ReflectException extends Exception {
 48   
 49  35 protected ReflectException(Throwable cause) { super(cause); }
 50    public abstract <T> T apply(ReflectExceptionVisitor<T> v);
 51   
 52    /** Wraps a {@link ClassNotFoundException} */
 53    public static class ClassNotFoundReflectException extends ReflectException {
 54  5 public ClassNotFoundReflectException(ClassNotFoundException e) { super(e); }
 55  10 public <T> T apply(ReflectExceptionVisitor<T> v) {
 56  10 return v.forClassNotFound((ClassNotFoundException) getCause());
 57    }
 58    }
 59   
 60    /** Wraps a {@link NoSuchFieldException} */
 61    public static class NoSuchFieldReflectException extends ReflectException {
 62  3 public NoSuchFieldReflectException(NoSuchFieldException e) { super(e); }
 63  6 public <T> T apply(ReflectExceptionVisitor<T> v) {
 64  6 return v.forNoSuchField((NoSuchFieldException) getCause());
 65    }
 66    }
 67   
 68    /** Wraps a {@link NoSuchMethodException} */
 69    public static class NoSuchMethodReflectException extends ReflectException {
 70  11 public NoSuchMethodReflectException(NoSuchMethodException e) { super(e); }
 71  22 public <T> T apply(ReflectExceptionVisitor<T> v) {
 72  22 return v.forNoSuchMethod((NoSuchMethodException) getCause());
 73    }
 74    }
 75   
 76    /** Wraps a {@link NullPointerException} */
 77    public static class NullPointerReflectException extends ReflectException {
 78  4 public NullPointerReflectException(NullPointerException e) { super(e); }
 79  8 public <T> T apply(ReflectExceptionVisitor<T> v) {
 80  8 return v.forNullPointer((NullPointerException) getCause());
 81    }
 82    }
 83   
 84    /** Wraps an {@link IllegalArgumentException} */
 85    public static class IllegalArgumentReflectException extends ReflectException {
 86  3 public IllegalArgumentReflectException(IllegalArgumentException e) { super(e); }
 87  6 public <T> T apply(ReflectExceptionVisitor<T> v) {
 88  6 return v.forIllegalArgument((IllegalArgumentException) getCause());
 89    }
 90    }
 91   
 92    /** Wraps a {@link ClassCastException} */
 93    public static class ClassCastReflectException extends ReflectException {
 94  4 public ClassCastReflectException(ClassCastException e) { super(e); }
 95  8 public <T> T apply(ReflectExceptionVisitor<T> v) {
 96  8 return v.forClassCast((ClassCastException) getCause());
 97    }
 98    }
 99   
 100    /** Wraps an {@link InvocationTargetException} */
 101    public static class InvocationTargetReflectException extends ReflectException {
 102  2 public InvocationTargetReflectException(InvocationTargetException e) { super(e); }
 103  4 public <T> T apply(ReflectExceptionVisitor<T> v) {
 104  4 return v.forInvocationTarget((InvocationTargetException) getCause());
 105    }
 106    }
 107   
 108    /** Wraps an {@link InstantiationException} */
 109    public static class InstantiationReflectException extends ReflectException {
 110  1 public InstantiationReflectException(InstantiationException e) { super(e); }
 111  2 public <T> T apply(ReflectExceptionVisitor<T> v) {
 112  2 return v.forInstantiation((InstantiationException) getCause());
 113    }
 114    }
 115   
 116    /** Wraps an {@link IllegalAccessException} */
 117    public static class IllegalAccessReflectException extends ReflectException {
 118  2 public IllegalAccessReflectException(IllegalAccessException e) { super(e); }
 119  4 public <T> T apply(ReflectExceptionVisitor<T> v) {
 120  4 return v.forIllegalAccess((IllegalAccessException) getCause());
 121    }
 122    }
 123   
 124    /** Wraps an {@link SecurityException} */
 125    public static class SecurityReflectException extends ReflectException {
 126  0 public SecurityReflectException(SecurityException e) { super(e); }
 127  0 public <T> T apply(ReflectExceptionVisitor<T> v) {
 128  0 return v.forSecurity((SecurityException) getCause());
 129    }
 130    }
 131   
 132    }