001    /*
002     * Created on Aug 17, 2006
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
005     * the License. You may obtain a copy of the License at
006     *
007     * http://www.apache.org/licenses/LICENSE-2.0
008     *
009     * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
010     * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011     * specific language governing permissions and limitations under the License.
012     *
013     * Copyright @2006-2009 the original author or authors.
014     */
015    package org.fest.reflect.constructor;
016    
017    import static org.fest.reflect.constructor.Invoker.newInvoker;
018    
019    /**
020     * Understands the parameter types for the constructor to invoke.
021     * <p>
022     * The following is an example of proper usage of the classes in this package:
023     * <pre>
024     *   // Equivalent to call 'new Person()'
025     *   Person p = {@link org.fest.reflect.core.Reflection#constructor() constructor}().{@link TargetType#in in}(Person.class).{@link Invoker#newInstance newInstance}();
026     *
027     *   // Equivalent to call 'new Person("Yoda")'
028     *   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");
029     * </pre>
030     * </p>
031     *
032     * @author Alex Ruiz
033     * @author Yvonne Wang
034     */
035    public final class ParameterTypes {
036    
037      static ParameterTypes newParameterTypes(Class<?>[] parameterTypes) {
038        if (parameterTypes == null) throw new NullPointerException("The array of parameter types should not be null");
039        return new ParameterTypes(parameterTypes);
040      }
041    
042      private final Class<?>[] parameterTypes;
043    
044      private ParameterTypes(Class<?>[] parameterTypes) {
045        this.parameterTypes = parameterTypes;
046      }
047    
048      /**
049       * Creates a new constructor invoker.
050       * @param <T> the generic type of the class containing the constructor to invoke.
051       * @param target the the type of object that the constructor invoker will create.
052       * @return the created constructor invoker.
053       */
054      public <T> Invoker<T> in(Class<T> target) {
055        return newInvoker(target, parameterTypes);
056      }
057    }