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
6   63   4   2
2   17   0.67   3
3     1.33  
1    
 
  StaticFieldType       Line # 38 6 0% 4 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Feb 5, 2006
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5    * 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 is distributed on
10    * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11    * specific language governing permissions and limitations under the License.
12    *
13    * Copyright @2006-2009 the original author or authors.
14    */
15    package org.fest.reflect.field;
16   
17    import static org.fest.reflect.field.Invoker.newInvoker;
18   
19    import org.fest.reflect.exception.ReflectionError;
20   
21    /**
22    * Understands the type of a static field to access using Java Reflection.
23    * <p>
24    * The following is an example of proper usage of this class:
25    * <pre>
26    * // Retrieves the value of the static field "count"
27    * int count = {@link org.fest.reflect.core.Reflection#staticField(String) staticField}("count").{@link StaticFieldName#ofType(Class) ofType}(int.class).{@link StaticFieldType#in(Class) in}(Person.class).{@link Invoker#get() get}();
28    *
29    * // Sets the value of the static field "count" to 3
30    * {@link org.fest.reflect.core.Reflection#staticField(String) staticField}("count").{@link StaticFieldName#ofType(Class) ofType}(int.class).{@link StaticFieldType#in(Class) in}(Person.class).{@link Invoker#set(Object) set}(3);
31    * </pre>
32    * </p>
33    *
34    * @param <T> the generic type of the field.
35    *
36    * @author Alex Ruiz
37    */
 
38    public class StaticFieldType<T> {
39   
 
40  8 toggle static <T> StaticFieldType<T> newFieldType(String name, Class<T> type) {
41  8 if (type == null) throw new NullPointerException("The type of the static field to access should not be null");
42  7 return new StaticFieldType<T>(name, type);
43    }
44   
45    private final String name;
46    private final Class<T> type;
47   
 
48  7 toggle StaticFieldType(String name, Class<T> type) {
49  7 this.name = name;
50  7 this.type = type;
51    }
52   
53    /**
54    * Returns a new field invoker. A field invoker is capable of accessing (read/write) the underlying field.
55    * @param target the type containing the static field of interest.
56    * @return the created field invoker.
57    * @throws NullPointerException if the given target is <code>null</code>.
58    * @throws ReflectionError if a static field with a matching name and type cannot be found.
59    */
 
60  7 toggle public Invoker<T> in(Class<?> target) {
61  7 return newInvoker(name, type, target);
62    }
63    }