0N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.reflect.generics.scope;
0N/A
0N/Aimport java.lang.reflect.GenericDeclaration;
0N/Aimport java.lang.reflect.TypeVariable;
0N/A
0N/A
0N/A
0N/A/**
0N/A * Abstract superclass for lazy scope objects, used when building
0N/A * factories for generic information repositories.
0N/A * The type parameter <tt>D</tt> represents the type of reflective
0N/A * object whose scope this class is representing.
0N/A * <p> To subclass this, all one needs to do is implement
0N/A * <tt>computeEnclosingScope</tt> and the subclass' constructor.
0N/A */
0N/Apublic abstract class AbstractScope<D extends GenericDeclaration>
0N/A implements Scope {
0N/A
0N/A private D recvr; // the declaration whose scope this instance represents
0N/A private Scope enclosingScope; // the enclosing scope of this scope
0N/A
0N/A /**
0N/A * Constructor. Takes a reflective object whose scope the newly
0N/A * constructed instance will represent.
0N/A * @param D - A generic declaration whose scope the newly
0N/A * constructed instance will represent
0N/A */
0N/A protected AbstractScope(D decl){ recvr = decl;}
0N/A
0N/A /**
0N/A * Accessor for the receiver - the object whose scope this <tt>Scope</tt>
0N/A * object represents.
0N/A * @return The object whose scope this <tt>Scope</tt> object represents
0N/A */
0N/A protected D getRecvr() {return recvr;}
0N/A
0N/A /** This method must be implemented by any concrete subclass.
0N/A * It must return the enclosing scope of this scope. If this scope
0N/A * is a top-level scope, an instance of DummyScope must be returned.
0N/A * @return The enclosing scope of this scope
0N/A */
0N/A protected abstract Scope computeEnclosingScope();
0N/A
0N/A /**
0N/A * Accessor for the enclosing scope, which is computed lazily and cached.
0N/A * @return the enclosing scope
0N/A */
0N/A protected Scope getEnclosingScope(){
0N/A if (enclosingScope == null) {enclosingScope = computeEnclosingScope();}
0N/A return enclosingScope;
0N/A }
0N/A
0N/A /**
0N/A * Lookup a type variable in the scope, using its name. Returns null if
0N/A * no type variable with this name is declared in this scope or any of its
0N/A * surrounding scopes.
0N/A * @param name - the name of the type variable being looked up
0N/A * @return the requested type variable, if found
0N/A */
0N/A public TypeVariable<?> lookup(String name) {
0N/A TypeVariable[] tas = getRecvr().getTypeParameters();
0N/A for (TypeVariable/*<?>*/ tv : tas) {
0N/A if (tv.getName().equals(name)) {return tv;}
0N/A }
0N/A return getEnclosingScope().lookup(name);
0N/A }
0N/A}