Path: blob/master/src/java.compiler/share/classes/javax/lang/model/element/NestingKind.java
41161 views
/*1* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.lang.model.element;2627/**28* The <i>nesting kind</i> of a type element.29* Type elements come in four varieties:30* top-level, member, local, and anonymous.31* <i>Nesting kind</i> is a non-standard term used here to denote this32* classification.33*34* <p>Note that it is possible additional nesting kinds will be added35* in future versions of the platform.36*37* <p><b>Example:</b> The classes below are annotated with their nesting kind.38* <blockquote><pre>39*40* import java.lang.annotation.*;41* import static java.lang.annotation.RetentionPolicy.*;42* import javax.lang.model.element.*;43* import static javax.lang.model.element.NestingKind.*;44*45* @Nesting(TOP_LEVEL)46* public class NestingExamples {47* @Nesting(MEMBER)48* static class MemberClass1{}49*50* @Nesting(MEMBER)51* class MemberClass2{}52*53* public static void main(String... argv) {54* @Nesting(LOCAL)55* class LocalClass{};56*57* Class<?>[] classes = {58* NestingExamples.class,59* MemberClass1.class,60* MemberClass2.class,61* LocalClass.class62* };63*64* for(Class<?> clazz : classes) {65* System.out.format("%s is %s%n",66* clazz.getName(),67* clazz.getAnnotation(Nesting.class).value());68* }69* }70* }71*72* @Retention(RUNTIME)73* @interface Nesting {74* NestingKind value();75* }76* </pre></blockquote>77*78* @author Joseph D. Darcy79* @author Scott Seligman80* @author Peter von der Ahé81* @since 1.682*/83public enum NestingKind {84/**85* A top-level class or interface, not contained within another86* class or interface.87*/88TOP_LEVEL,8990/**91* A class or interface that is a named member of another class or92* interface.93* @jls 8.5 Member Class and Interface Declarations94*/95MEMBER,9697/**98* A named class or interface declared within a construct other99* than a class or interface.100* @jls 14.3 Local Class Declarations101*/102LOCAL,103104/**105* A class without a name.106* @jls 15.9.5 Anonymous Class Declarations107*/108ANONYMOUS;109110/**111* Does this constant correspond to a nested type element?112* A <i>nested</i> type element is any that is not top-level.113* More specifically, an <i>inner</i> type element is any nested type element that114* is not {@linkplain Modifier#STATIC static}.115* @return whether or not the constant is nested116* @jls 14.3 Local Class Declarations117*/118public boolean isNested() {119return this != TOP_LEVEL;120}121}122123124