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