All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fest.reflect.innerclass.StaticInnerClassName Maven / Gradle / Ivy

The newest version!
/*
 * Created on Jan 25, 2009
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 * 
 * Copyright @2009 the original author or authors.
 */
package org.fest.reflect.innerclass;

import org.assertj.core.util.Strings;

import static org.fest.reflect.innerclass.Invoker.newInvoker;

/**
 * Understands the name of a static inner class.
 * 

* Let's assume we have the class Jedi, which contains two static inner classes: Master and * Padawan. * *

 * public class Jedi {
 *
 *   public static class Master {}
 *
 *   public static class Padawan {}
 * }
 * 
*

*

* The following example shows how to get a reference to the inner class Master: * *

 * Class<?> masterClass = {@link org.fest.reflect.core.Reflection#staticInnerClass(String) staticInnerClass}("Master").{@link StaticInnerClassName#in(Class) in}(Jedi.class).{@link Invoker#get() get}();
 * 
*

* * @author Alex Ruiz * * @since 1.1 */ public final class StaticInnerClassName { /** * Creates a new
{@link StaticInnerClassName}. * @param name the name of the static inner class to obtain. * @return the created StaticInnerClassName. * @throws NullPointerException if the given name is null. * @throws IllegalArgumentException if the given name is empty. */ public static StaticInnerClassName startStaticInnerClassAccess(String name) { validateIsNotNullOrEmpty(name); return new StaticInnerClassName(name); } private static void validateIsNotNullOrEmpty(String name) { if (name == null) throw new NullPointerException("The name of the static inner class to access should not be null"); if (Strings.isNullOrEmpty(name)) throw new IllegalArgumentException("The name of the static inner class to access should not be empty"); } private final String name; private StaticInnerClassName(String name) { this.name = name; } /** * Specifies the declaring class of the static inner class to obtain. * @param declaringClass the declaring class. * @return an object responsible for obtaining a reference to a static inner class. * @throws NullPointerException if the given declaring class is null. */ public Invoker in(Class declaringClass) { return newInvoker(declaringClass, name); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy