Path: blob/master/src/java.base/share/classes/sun/reflect/generics/scope/ClassScope.java
41161 views
/*1* Copyright (c) 2003, 2004, 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 sun.reflect.generics.scope;2627import java.lang.reflect.Constructor;28import java.lang.reflect.Method;293031/**32* This class represents the scope containing the type variables of33* a class.34*/35public class ClassScope extends AbstractScope<Class<?>> implements Scope {3637// constructor is private to enforce use of factory method38private ClassScope(Class<?> c){39super(c);40}4142/**43* Overrides the abstract method in the superclass.44* @return the enclosing scope45*/46protected Scope computeEnclosingScope() {47Class<?> receiver = getRecvr();4849Method m = receiver.getEnclosingMethod();50if (m != null)51// Receiver is a local or anonymous class enclosed in a52// method.53return MethodScope.make(m);5455Constructor<?> cnstr = receiver.getEnclosingConstructor();56if (cnstr != null)57// Receiver is a local or anonymous class enclosed in a58// constructor.59return ConstructorScope.make(cnstr);6061Class<?> c = receiver.getEnclosingClass();62// if there is a declaring class, recvr is a member class63// and its enclosing scope is that of the declaring class64if (c != null)65// Receiver is a local class, an anonymous class, or a66// member class (static or not).67return ClassScope.make(c);6869// otherwise, recvr is a top level class, and it has no real70// enclosing scope.71return DummyScope.make();72}7374/**75* Factory method. Takes a {@code Class} object and creates a76* scope for it.77* @param c - a Class whose scope we want to obtain78* @return The type-variable scope for the class c79*/80public static ClassScope make(Class<?> c) { return new ClassScope(c);}8182}838485