src/share/classes/javax/lang/model/element/NestingKind.java

changeset 1
9a66ca7c79fa
child 554
9d9f26857129
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/javax/lang/model/element/NestingKind.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,99 @@
     1.4 +/*
     1.5 + * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Sun designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Sun in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.26 + * have any questions.
    1.27 + */
    1.28 +
    1.29 +package javax.lang.model.element;
    1.30 +
    1.31 +/**
    1.32 + * The <i>nesting kind</i> of a type element.
    1.33 + * Type elements come in four varieties:
    1.34 + * top-level, member, local, and anonymous.
    1.35 + * <i>Nesting kind</i> is a non-standard term used here to denote this
    1.36 + * classification.
    1.37 + *
    1.38 + * <p>Note that it is possible additional nesting kinds will be added
    1.39 + * in future versions of the platform.
    1.40 + *
    1.41 + * <p><b>Example:</b> The classes below are annotated with their nesting kind.
    1.42 + * <blockquote><pre>
    1.43 + *
    1.44 + * import java.lang.annotation.*;
    1.45 + * import static java.lang.annotation.RetentionPolicy.*;
    1.46 + * import javax.lang.model.element.*;
    1.47 + * import static javax.lang.model.element.NestingKind.*;
    1.48 + *
    1.49 + * &#64;Nesting(TOP_LEVEL)
    1.50 + * public class NestingExamples {
    1.51 + *     &#64;Nesting(MEMBER)
    1.52 + *     static class MemberClass1{}
    1.53 + *
    1.54 + *     &#64;Nesting(MEMBER)
    1.55 + *     class MemberClass2{}
    1.56 + *
    1.57 + *     public static void main(String... argv) {
    1.58 + *         &#64;Nesting(LOCAL)
    1.59 + *         class LocalClass{};
    1.60 + *
    1.61 + *         Class&lt;?&gt;[] classes = {
    1.62 + *             NestingExamples.class,
    1.63 + *             MemberClass1.class,
    1.64 + *             MemberClass2.class,
    1.65 + *             LocalClass.class
    1.66 + *         };
    1.67 + *
    1.68 + *         for(Class&lt;?&gt; clazz : classes) {
    1.69 + *             System.out.format("%s is %s%n",
    1.70 + *                               clazz.getName(),
    1.71 + *                               clazz.getAnnotation(Nesting.class).value());
    1.72 + *         }
    1.73 + *     }
    1.74 + * }
    1.75 + *
    1.76 + * &#64;Retention(RUNTIME)
    1.77 + * &#64;interface Nesting {
    1.78 + *     NestingKind value();
    1.79 + * }
    1.80 + * </pre></blockquote>
    1.81 + *
    1.82 + * @author Joseph D. Darcy
    1.83 + * @author Scott Seligman
    1.84 + * @author Peter von der Ah&eacute;
    1.85 + * @since 1.6
    1.86 + */
    1.87 +public enum NestingKind {
    1.88 +    TOP_LEVEL,
    1.89 +    MEMBER,
    1.90 +    LOCAL,
    1.91 +    ANONYMOUS;
    1.92 +
    1.93 +    /**
    1.94 +     * Does this constant correspond to a nested type element?
    1.95 +     * A <i>nested</i> type element is any that is not top-level.
    1.96 +     * An <i>inner</i> type element is any nested type element that
    1.97 +     * is not {@linkplain Modifier#STATIC static}.
    1.98 +     */
    1.99 +    public boolean isNested() {
   1.100 +        return this != TOP_LEVEL;
   1.101 +    }
   1.102 +}

mercurial