|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StaticMethodParameterTypes | Line # 51 | 6 | 0% | 4 | 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 | ||
| 20 | import org.fest.reflect.reference.TypeRef; | |
| 21 | ||
| 22 | /** | |
| 23 | * Understands the parameter types of the static method to invoke. | |
| 24 | * <p> | |
| 25 | * The following is an example of proper usage of this class: | |
| 26 | * <pre> | |
| 27 | * // Equivalent to call 'Jedi.setCommonPower("Jump")' | |
| 28 | * {@link org.fest.reflect.core.Reflection#staticMethod(String) staticMethod}("setCommonPower").{@link StaticMethodName#withParameterTypes(Class...) withParameterTypes}(String.class) | |
| 29 | * .{@link StaticMethodParameterTypes#in(Class) in}(Jedi.class) | |
| 30 | * .{@link Invoker#invoke(Object...) invoke}("Jump"); | |
| 31 | * | |
| 32 | * // Equivalent to call 'Jedi.addPadawan()' | |
| 33 | * {@link org.fest.reflect.core.Reflection#staticMethod(String) staticMethod}("addPadawan").{@link StaticMethodName#in(Class) in}(Jedi.class).{@link Invoker#invoke(Object...) invoke}(); | |
| 34 | * | |
| 35 | * // Equivalent to call 'Jedi.commonPowerCount()' | |
| 36 | * String name = {@link org.fest.reflect.core.Reflection#staticMethod(String) staticMethod}("commonPowerCount").{@link StaticMethodName#withReturnType(Class) withReturnType}(String.class) | |
| 37 | * .{@link StaticMethodReturnType#in(Class) in}(Jedi.class) | |
| 38 | * .{@link Invoker#invoke(Object...) invoke}(); | |
| 39 | * | |
| 40 | * // Equivalent to call 'Jedi.getCommonPowers()' | |
| 41 | * List<String> powers = {@link org.fest.reflect.core.Reflection#staticMethod(String) staticMethod}("getCommonPowers").{@link StaticMethodName#withReturnType(TypeRef) withReturnType}(new {@link TypeRef TypeRef}<List<String>>() {}) | |
| 42 | * .{@link StaticMethodReturnTypeRef#in(Class) in}(Jedi.class) | |
| 43 | * .{@link Invoker#invoke(Object...) invoke}(); | |
| 44 | * </pre> | |
| 45 | * </p> | |
| 46 | * | |
| 47 | * @param <T> the generic type of the static method's return type. | |
| 48 | * | |
| 49 | * @author Alex Ruiz | |
| 50 | */ | |
| 51 | public final class StaticMethodParameterTypes<T> { | |
| 52 | ||
| 53 | 5 |
static <T> StaticMethodParameterTypes<T> newParameterTypes(String name, Class<?>[] parameterTypes) { |
| 54 | 5 | if (parameterTypes == null) |
| 55 | 1 | throw new NullPointerException("The array of parameter types for the static method to access should not be null"); |
| 56 | 4 | return new StaticMethodParameterTypes<T>(name, parameterTypes); |
| 57 | } | |
| 58 | ||
| 59 | private final String name; | |
| 60 | private final Class<?>[] parameterTypes; | |
| 61 | ||
| 62 | 4 |
private StaticMethodParameterTypes(String name, Class<?>[] parameterTypes) { |
| 63 | 4 | this.name = name; |
| 64 | 4 | this.parameterTypes = parameterTypes; |
| 65 | } | |
| 66 | ||
| 67 | /** | |
| 68 | * Creates a new method invoker. | |
| 69 | * @param target the class containing the static method to invoke. | |
| 70 | * @return the created method invoker. | |
| 71 | * @throws NullPointerException if the given target is <code>null</code>. | |
| 72 | */ | |
| 73 | 4 |
public Invoker<T> in(Class<?> target) { |
| 74 | 4 | return newInvoker(name, target, parameterTypes); |
| 75 | } | |
| 76 | } | |
|
||||||||||||