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   86   5   1.5
2   20   0.83   4
4     1.25  
1    
 
  StaticMethodReturnType       Line # 52 6 0% 5 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Aug 17, 2007
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 @2007-2009 the original author or authors.
15    */
16    package org.fest.reflect.method;
17   
18    import static org.fest.reflect.method.Invoker.newInvoker;
19    import static org.fest.reflect.method.StaticMethodParameterTypes.newParameterTypes;
20   
21    import org.fest.reflect.reference.TypeRef;
22   
23    /**
24    * Understands the return type of the static method to invoke.
25    * <p>
26    * The following is an example of proper usage of this class:
27    * <pre>
28    * // Equivalent to call 'Jedi.setCommonPower("Jump")'
29    * {@link org.fest.reflect.core.Reflection#staticMethod(String) staticMethod}("setCommonPower").{@link StaticMethodName#withParameterTypes(Class...) withParameterTypes}(String.class)
30    * .{@link StaticMethodParameterTypes#in(Class) in}(Jedi.class)
31    * .{@link Invoker#invoke(Object...) invoke}("Jump");
32    *
33    * // Equivalent to call 'Jedi.addPadawan()'
34    * {@link org.fest.reflect.core.Reflection#staticMethod(String) staticMethod}("addPadawan").{@link StaticMethodName#in(Class) in}(Jedi.class).{@link Invoker#invoke(Object...) invoke}();
35    *
36    * // Equivalent to call 'Jedi.commonPowerCount()'
37    * String name = {@link org.fest.reflect.core.Reflection#staticMethod(String) staticMethod}("commonPowerCount").{@link StaticMethodName#withReturnType(Class) withReturnType}(String.class)
38    * .{@link StaticMethodReturnType#in(Class) in}(Jedi.class)
39    * .{@link Invoker#invoke(Object...) invoke}();
40    *
41    * // Equivalent to call 'Jedi.getCommonPowers()'
42    * List&lt;String&gt; powers = {@link org.fest.reflect.core.Reflection#staticMethod(String) staticMethod}("getCommonPowers").{@link StaticMethodName#withReturnType(TypeRef) withReturnType}(new {@link TypeRef TypeRef}&lt;List&lt;String&gt;&gt;() {})
43    * .{@link StaticMethodReturnTypeRef#in(Class) in}(Jedi.class)
44    * .{@link Invoker#invoke(Object...) invoke}();
45    * </pre>
46    * </p>
47    *
48    * @param <T> the generic type of the static method's return type.
49    *
50    * @author Alex Ruiz
51    */
 
52    public class StaticMethodReturnType<T> {
53   
 
54  3 toggle static <T> StaticMethodReturnType<T> newReturnType(String name, Class<T> type) {
55  3 if (type == null)
56  1 throw new NullPointerException("The return type of the static method to access should not be null");
57  2 return new StaticMethodReturnType<T>(name);
58    }
59   
60    private final String name;
61   
 
62  2 toggle private StaticMethodReturnType(String name) {
63  2 this.name = name;
64    }
65   
66    /**
67    * Creates a new method invoker.
68    * @param target the object containing the method to invoke.
69    * @return the created method invoker.
70    * @throws NullPointerException if the given target is <code>null</code>.
71    */
 
72  1 toggle public Invoker<T> in(Class<?> target) {
73  1 return newInvoker(name, target);
74    }
75   
76    /**
77    * Specifies the parameter types of the static method to invoke. This method call is optional if the method to invoke
78    * does not take arguments.
79    * @param parameterTypes the parameter types of the method to invoke.
80    * @return the created parameter types holder.
81    * @throws NullPointerException if the array of parameter types is <code>null</code>.
82    */
 
83  1 toggle public StaticMethodParameterTypes<T> withParameterTypes(Class<?>... parameterTypes) {
84  1 return newParameterTypes(name, parameterTypes);
85    }
86    }