Clover Coverage Report - FEST Reflection 1.2
Coverage timestamp: Tue Nov 24 2009 20:12:25 PST
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
11   60   6   2.75
4   25   0.55   4
4     1.5  
1    
 
  Invoker       Line # 29 11 0% 6 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Jan 25, 2009
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2009 the original author or authors.
15    */
16    package org.fest.reflect.innerclass;
17   
18    import static org.fest.util.Strings.concat;
19   
20    import org.fest.reflect.exception.ReflectionError;
21   
22    /**
23    * Understands how to obtain a reference to a static inner class.
24    *
25    * @author Alex Ruiz
26    *
27    * @since 1.1
28    */
 
29    public class Invoker {
30   
 
31  3 toggle static Invoker newInvoker(Class<?> declaringClass, String innerClassName) {
32  3 if (declaringClass == null) throw new NullPointerException("The declaring class should not be null");
33  2 return new Invoker(declaringClass, innerClassName);
34    }
35   
36    private final Class<?> declaringClass;
37    private final String innerClassName;
38   
 
39  2 toggle private Invoker(Class<?> declaringClass, String innerClassName) {
40  2 this.declaringClass = declaringClass;
41  2 this.innerClassName = innerClassName;
42    }
43   
44    /**
45    * Returns a reference to the static inner class with the specified name in the specified declaring class.
46    * @return a reference to the static inner class with the specified name in the specified declaring class.
47    * @throws ReflectionError if the static inner class does not exist (since 1.2).
48    */
 
49  2 toggle public Class<?> get() {
50  2 String namespace = declaringClass.getName();
51  2 for (Class<?> innerClass : declaringClass.getDeclaredClasses())
52  5 if (innerClass.getName().equals(expectedInnerClassName(namespace))) return innerClass;
53  1 throw new ReflectionError(concat(
54    "The static inner class <", innerClassName, "> cannot be found in ", declaringClass.getName()));
55    }
56   
 
57  5 toggle private String expectedInnerClassName(String namespace) {
58  5 return concat(namespace, "$", innerClassName);
59    }
60    }