001 /*
002 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.lang.model.element;
027
028 /**
029 * The <i>nesting kind</i> of a type element.
030 * Type elements come in four varieties:
031 * top-level, member, local, and anonymous.
032 * <i>Nesting kind</i> is a non-standard term used here to denote this
033 * classification.
034 *
035 * <p>Note that it is possible additional nesting kinds will be added
036 * in future versions of the platform.
037 *
038 * <p><b>Example:</b> The classes below are annotated with their nesting kind.
039 * <blockquote><pre>
040 *
041 * import java.lang.annotation.*;
042 * import static java.lang.annotation.RetentionPolicy.*;
043 * import javax.lang.model.element.*;
044 * import static javax.lang.model.element.NestingKind.*;
045 *
046 * @Nesting(TOP_LEVEL)
047 * public class NestingExamples {
048 * @Nesting(MEMBER)
049 * static class MemberClass1{}
050 *
051 * @Nesting(MEMBER)
052 * class MemberClass2{}
053 *
054 * public static void main(String... argv) {
055 * @Nesting(LOCAL)
056 * class LocalClass{};
057 *
058 * Class<?>[] classes = {
059 * NestingExamples.class,
060 * MemberClass1.class,
061 * MemberClass2.class,
062 * LocalClass.class
063 * };
064 *
065 * for(Class<?> clazz : classes) {
066 * System.out.format("%s is %s%n",
067 * clazz.getName(),
068 * clazz.getAnnotation(Nesting.class).value());
069 * }
070 * }
071 * }
072 *
073 * @Retention(RUNTIME)
074 * @interface Nesting {
075 * NestingKind value();
076 * }
077 * </pre></blockquote>
078 *
079 * @author Joseph D. Darcy
080 * @author Scott Seligman
081 * @author Peter von der Ahé
082 * @since 1.6
083 */
084 public enum NestingKind {
085 TOP_LEVEL,
086 MEMBER,
087 LOCAL,
088 ANONYMOUS;
089
090 /**
091 * Does this constant correspond to a nested type element?
092 * A <i>nested</i> type element is any that is not top-level.
093 * An <i>inner</i> type element is any nested type element that
094 * is not {@linkplain Modifier#STATIC static}.
095 */
096 public boolean isNested() {
097 return this != TOP_LEVEL;
098 }
099 }