|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ParameterTypes | Line # 35 | 5 | 0% | 4 | 0 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| No Tests | |||
| 1 | /* | |
| 2 | * Created on Aug 17, 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.constructor; | |
| 16 | ||
| 17 | import static org.fest.reflect.constructor.Invoker.newInvoker; | |
| 18 | ||
| 19 | /** | |
| 20 | * Understands the parameter types for the constructor to invoke. | |
| 21 | * <p> | |
| 22 | * The following is an example of proper usage of the classes in this package: | |
| 23 | * <pre> | |
| 24 | * // Equivalent to call 'new Person()' | |
| 25 | * Person p = {@link org.fest.reflect.core.Reflection#constructor() constructor}().{@link TargetType#in in}(Person.class).{@link Invoker#newInstance newInstance}(); | |
| 26 | * | |
| 27 | * // Equivalent to call 'new Person("Yoda")' | |
| 28 | * Person p = {@link org.fest.reflect.core.Reflection#constructor() constructor}().{@link TargetType#withParameterTypes(Class...) withParameterTypes}(String.class).{@link ParameterTypes#in(Class) in}(Person.class).{@link Invoker#newInstance newInstance}("Yoda"); | |
| 29 | * </pre> | |
| 30 | * </p> | |
| 31 | * | |
| 32 | * @author Alex Ruiz | |
| 33 | * @author Yvonne Wang | |
| 34 | */ | |
| 35 | public final class ParameterTypes { | |
| 36 | ||
| 37 | 9 |
static ParameterTypes newParameterTypes(Class<?>[] parameterTypes) { |
| 38 | 9 | if (parameterTypes == null) throw new NullPointerException("The array of parameter types should not be null"); |
| 39 | 8 | return new ParameterTypes(parameterTypes); |
| 40 | } | |
| 41 | ||
| 42 | private final Class<?>[] parameterTypes; | |
| 43 | ||
| 44 | 8 |
private ParameterTypes(Class<?>[] parameterTypes) { |
| 45 | 8 | this.parameterTypes = parameterTypes; |
| 46 | } | |
| 47 | ||
| 48 | /** | |
| 49 | * Creates a new constructor invoker. | |
| 50 | * @param <T> the generic type of the class containing the constructor to invoke. | |
| 51 | * @param target the the type of object that the constructor invoker will create. | |
| 52 | * @return the created constructor invoker. | |
| 53 | */ | |
| 54 | 8 |
public <T> Invoker<T> in(Class<T> target) { |
| 55 | 8 | return newInvoker(target, parameterTypes); |
| 56 | } | |
| 57 | } | |
|
||||||||||||