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    import static org.fest.reflect.constructor.ParameterTypes.newParameterTypes;
019    
020    /**
021     * Understands the type of object that the constructor will create.
022     * <p>
023     * The following is an example of proper usage of the classes in this package:
024     * <pre>
025     *   // Equivalent to call 'new Person()'
026     *   Person p = {@link org.fest.reflect.core.Reflection#constructor() constructor}().{@link TargetType#in in}(Person.class).{@link Invoker#newInstance newInstance}();
027     *
028     *   // Equivalent to call 'new Person("Yoda")'
029     *   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");
030     * </pre>
031     * </p>
032     *
033     * @author Alex Ruiz
034     * @author Yvonne Wang
035     */
036    public final class TargetType {
037    
038      /**
039       * Creates a new </code>{@link TargetType}</code>.
040       * @return the created <code>TargetType</code>.
041       */
042      public static TargetType startConstructorAccess() {
043        return new TargetType();
044      }
045    
046      private TargetType() {}
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);
056      }
057    
058      /**
059       * Specifies the parameter types for the constructor to invoke. This method call is optional if the constructor to
060       * call does not accept arguments.
061       * @param parameterTypes the types of the parameters to pass to the constructor.
062       * @return the created parameter type holder.
063       * @throws NullPointerException if the given array is <code>null</code>.
064       */
065      public ParameterTypes withParameterTypes(Class<?>... parameterTypes) {
066        return newParameterTypes(parameterTypes);
067      }
068    }