KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > lang > model > element > NestingKind


1 /*
2  * @(#)NestingKind.java 1.3 06/07/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.lang.model.element;
9
10 /**
11  * The <i>nesting kind</i> of a type element.
12  * Type elements come in four varieties:
13  * top-level, member, local, and anonymous.
14  * <i>Nesting kind</i> is a non-standard term used here to denote this
15  * classification.
16  *
17  * <p>Note that it is possible additional nesting kinds will be added
18  * in future versions of the platform.
19  *
20  * <p><b>Example:</b> The classes below are annotated with their nesting kind.
21  * <blockquote><pre>
22  *
23  * import java.lang.annotation.*;
24  * import static java.lang.annotation.RetentionPolicy.*;
25  * import javax.lang.model.element.*;
26  * import static javax.lang.model.element.NestingKind.*;
27  *
28  * &#64;Nesting(TOP_LEVEL)
29  * public class NestingExamples {
30  * &#64;Nesting(MEMBER)
31  * static class MemberClass1{}
32  *
33  * &#64;Nesting(MEMBER)
34  * class MemberClass2{}
35  *
36  * public static void main(String... argv) {
37  * &#64;Nesting(LOCAL)
38  * class LocalClass{};
39  *
40  * Class&lt;?&gt;[] classes = {
41  * NestingExamples.class,
42  * MemberClass1.class,
43  * MemberClass2.class,
44  * LocalClass.class
45  * };
46  *
47  * for(Class&lt;?&gt; clazz : classes) {
48  * System.out.format("%s is %s%n",
49  * clazz.getName(),
50  * clazz.getAnnotation(Nesting.class).value());
51  * }
52  * }
53  * }
54  *
55  * &#64;Retention(RUNTIME)
56  * &#64;interface Nesting {
57  * NestingKind value();
58  * }
59  * </pre></blockquote>
60  *
61  * @author Joseph D. Darcy
62  * @author Scott Seligman
63  * @author Peter von der Ah&eacute;
64  * @version 1.3 06/07/17
65  * @since 1.6
66  */

67 public enum NestingKind {
68     TOP_LEVEL,
69     MEMBER,
70     LOCAL,
71     ANONYMOUS;
72
73     /**
74      * Does this constant correspond to a nested type element?
75      * A <i>nested</i> type element is any that is not top-level.
76      * An <i>inner</i> type element is any nested type element that
77      * is not {@linkplain Modifier#STATIC static}.
78      */

79     public boolean isNested() {
80     return this != TOP_LEVEL;
81     }
82 }
83
Popular Tags