duke@1: /* ohair@554: * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package javax.lang.model.element; duke@1: duke@1: /** duke@1: * The nesting kind of a type element. duke@1: * Type elements come in four varieties: duke@1: * top-level, member, local, and anonymous. duke@1: * Nesting kind is a non-standard term used here to denote this duke@1: * classification. duke@1: * duke@1: *

Note that it is possible additional nesting kinds will be added duke@1: * in future versions of the platform. duke@1: * duke@1: *

Example: The classes below are annotated with their nesting kind. duke@1: *

duke@1:  *
duke@1:  * import java.lang.annotation.*;
duke@1:  * import static java.lang.annotation.RetentionPolicy.*;
duke@1:  * import javax.lang.model.element.*;
duke@1:  * import static javax.lang.model.element.NestingKind.*;
duke@1:  *
duke@1:  * @Nesting(TOP_LEVEL)
duke@1:  * public class NestingExamples {
duke@1:  *     @Nesting(MEMBER)
duke@1:  *     static class MemberClass1{}
duke@1:  *
duke@1:  *     @Nesting(MEMBER)
duke@1:  *     class MemberClass2{}
duke@1:  *
duke@1:  *     public static void main(String... argv) {
duke@1:  *         @Nesting(LOCAL)
duke@1:  *         class LocalClass{};
duke@1:  *
duke@1:  *         Class<?>[] classes = {
duke@1:  *             NestingExamples.class,
duke@1:  *             MemberClass1.class,
duke@1:  *             MemberClass2.class,
duke@1:  *             LocalClass.class
duke@1:  *         };
duke@1:  *
duke@1:  *         for(Class<?> clazz : classes) {
duke@1:  *             System.out.format("%s is %s%n",
duke@1:  *                               clazz.getName(),
duke@1:  *                               clazz.getAnnotation(Nesting.class).value());
duke@1:  *         }
duke@1:  *     }
duke@1:  * }
duke@1:  *
duke@1:  * @Retention(RUNTIME)
duke@1:  * @interface Nesting {
duke@1:  *     NestingKind value();
duke@1:  * }
duke@1:  * 
duke@1: * duke@1: * @author Joseph D. Darcy duke@1: * @author Scott Seligman duke@1: * @author Peter von der Ahé duke@1: * @since 1.6 duke@1: */ duke@1: public enum NestingKind { duke@1: TOP_LEVEL, duke@1: MEMBER, duke@1: LOCAL, duke@1: ANONYMOUS; duke@1: duke@1: /** duke@1: * Does this constant correspond to a nested type element? duke@1: * A nested type element is any that is not top-level. duke@1: * An inner type element is any nested type element that duke@1: * is not {@linkplain Modifier#STATIC static}. duke@1: */ duke@1: public boolean isNested() { duke@1: return this != TOP_LEVEL; duke@1: } duke@1: }