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

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 554
9d9f26857129
child 1725
e8987ce7fb4b
permissions
-rw-r--r--

8000663: clean up langtools imports
Reviewed-by: darcy

duke@1 1 /*
ohair@554 2 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package javax.lang.model.element;
duke@1 27
duke@1 28 /**
duke@1 29 * The <i>nesting kind</i> of a type element.
duke@1 30 * Type elements come in four varieties:
duke@1 31 * top-level, member, local, and anonymous.
duke@1 32 * <i>Nesting kind</i> is a non-standard term used here to denote this
duke@1 33 * classification.
duke@1 34 *
duke@1 35 * <p>Note that it is possible additional nesting kinds will be added
duke@1 36 * in future versions of the platform.
duke@1 37 *
duke@1 38 * <p><b>Example:</b> The classes below are annotated with their nesting kind.
duke@1 39 * <blockquote><pre>
duke@1 40 *
duke@1 41 * import java.lang.annotation.*;
duke@1 42 * import static java.lang.annotation.RetentionPolicy.*;
duke@1 43 * import javax.lang.model.element.*;
duke@1 44 * import static javax.lang.model.element.NestingKind.*;
duke@1 45 *
duke@1 46 * &#64;Nesting(TOP_LEVEL)
duke@1 47 * public class NestingExamples {
duke@1 48 * &#64;Nesting(MEMBER)
duke@1 49 * static class MemberClass1{}
duke@1 50 *
duke@1 51 * &#64;Nesting(MEMBER)
duke@1 52 * class MemberClass2{}
duke@1 53 *
duke@1 54 * public static void main(String... argv) {
duke@1 55 * &#64;Nesting(LOCAL)
duke@1 56 * class LocalClass{};
duke@1 57 *
duke@1 58 * Class&lt;?&gt;[] classes = {
duke@1 59 * NestingExamples.class,
duke@1 60 * MemberClass1.class,
duke@1 61 * MemberClass2.class,
duke@1 62 * LocalClass.class
duke@1 63 * };
duke@1 64 *
duke@1 65 * for(Class&lt;?&gt; clazz : classes) {
duke@1 66 * System.out.format("%s is %s%n",
duke@1 67 * clazz.getName(),
duke@1 68 * clazz.getAnnotation(Nesting.class).value());
duke@1 69 * }
duke@1 70 * }
duke@1 71 * }
duke@1 72 *
duke@1 73 * &#64;Retention(RUNTIME)
duke@1 74 * &#64;interface Nesting {
duke@1 75 * NestingKind value();
duke@1 76 * }
duke@1 77 * </pre></blockquote>
duke@1 78 *
duke@1 79 * @author Joseph D. Darcy
duke@1 80 * @author Scott Seligman
duke@1 81 * @author Peter von der Ah&eacute;
duke@1 82 * @since 1.6
duke@1 83 */
duke@1 84 public enum NestingKind {
duke@1 85 TOP_LEVEL,
duke@1 86 MEMBER,
duke@1 87 LOCAL,
duke@1 88 ANONYMOUS;
duke@1 89
duke@1 90 /**
duke@1 91 * Does this constant correspond to a nested type element?
duke@1 92 * A <i>nested</i> type element is any that is not top-level.
duke@1 93 * An <i>inner</i> type element is any nested type element that
duke@1 94 * is not {@linkplain Modifier#STATIC static}.
duke@1 95 */
duke@1 96 public boolean isNested() {
duke@1 97 return this != TOP_LEVEL;
duke@1 98 }
duke@1 99 }

mercurial