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   69   4   2
2   18   0.67   3
3     1.33  
1    
 
  PropertyTypeRef       Line # 44 6 0% 4 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Nov 23, 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.beanproperty;
17   
18    import static org.fest.reflect.beanproperty.Invoker.newInvoker;
19   
20    import org.fest.reflect.exception.ReflectionError;
21    import org.fest.reflect.reference.TypeRef;
22   
23    /**
24    * Understands the type of a property to access using Bean Instrospection. This implementation supports Java generics.
25    * <p>
26    * The following is an example of proper usage of this class:
27    * <pre>
28    * // Retrieves the value of the property "powers"
29    * List&lt;String&gt; powers = {@link org.fest.reflect.core.Reflection#property(String) property}("powers").{@link PropertyName#ofType(TypeRef) ofType}(new {@link TypeRef TypeRef}&lt;List&lt;String&gt;&gt;() {}).{@link #in(Object) in}(jedi).{@link Invoker#get() get}();
30    *
31    * // Sets the value of the property "powers"
32    * List&lt;String&gt; powers = new ArrayList&lt;String&gt;();
33    * powers.add("heal");
34    * {@link org.fest.reflect.core.Reflection#property(String) property}("powers").{@link PropertyName#ofType(TypeRef) ofType}(new {@link TypeRef TypeRef}&lt;List&lt;String&gt;&gt;() {}).{@link #in(Object) in}(jedi).{@link Invoker#set(Object) set}(powers);
35    * </pre>
36    * </p>
37    *
38    * @param <T> the generic type of the property.
39    *
40    * @author Alex Ruiz
41    *
42    * @since 1.2
43    */
 
44    public class PropertyTypeRef<T> {
45   
 
46  3 toggle static <T> PropertyTypeRef<T> newPropertyTypeRef(String name, TypeRef<T> type) {
47  3 if (type == null) throw new NullPointerException("The type reference of the property to access should not be null");
48  2 return new PropertyTypeRef<T>(name, type);
49    }
50   
51    private final TypeRef<T> type;
52    private final String name;
53   
 
54  2 toggle private PropertyTypeRef(String name, TypeRef<T> type) {
55  2 this.name = name;
56  2 this.type = type;
57    }
58   
59    /**
60    * Returns a new property invoker. A property invoker is capable of accessing (read/write) the underlying property.
61    * @param target the object containing the property of interest.
62    * @return the created property invoker.
63    * @throws NullPointerException if the given target is <code>null</code>.
64    * @throws ReflectionError if a property with a matching name and type cannot be found.
65    */
 
66  2 toggle public Invoker<T> in(Object target) {
67  2 return newInvoker(name, type, target);
68    }
69    }