15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.reflect.generics.scope; 27 28 import java.lang.reflect.GenericDeclaration; 29 import java.lang.reflect.TypeVariable; 30 31 32 /** 33 * Abstract superclass for lazy scope objects, used when building 34 * factories for generic information repositories. 35 * The type parameter <tt>D</tt> represents the type of reflective 36 * object whose scope this class is representing. 37 * <p> To subclass this, all one needs to do is implement 38 * <tt>computeEnclosingScope</tt> and the subclass' constructor. 39 */ 40 public abstract class AbstractScope<D extends GenericDeclaration> 41 implements Scope { 42 43 private final D recvr; // the declaration whose scope this instance represents 44 45 /** The enclosing scope of this scope. Lazily initialized. */ 46 private volatile Scope enclosingScope; 47 48 /** 49 * Constructor. Takes a reflective object whose scope the newly 50 * constructed instance will represent. 51 * @param decl - A generic declaration whose scope the newly 52 * constructed instance will represent 53 */ 54 protected AbstractScope(D decl){ recvr = decl;} 55 56 /** 57 * Accessor for the receiver - the object whose scope this <tt>Scope</tt> 58 * object represents. 59 * @return The object whose scope this <tt>Scope</tt> object represents 60 */ 61 protected D getRecvr() {return recvr;} 62 63 /** This method must be implemented by any concrete subclass. 64 * It must return the enclosing scope of this scope. If this scope 65 * is a top-level scope, an instance of DummyScope must be returned. 66 * @return The enclosing scope of this scope 67 */ 68 protected abstract Scope computeEnclosingScope(); 69 70 /** 71 * Accessor for the enclosing scope, which is computed lazily and cached. 72 * @return the enclosing scope 73 */ 74 protected Scope getEnclosingScope() { 75 Scope value = enclosingScope; 76 if (value == null) { 77 value = computeEnclosingScope(); 78 enclosingScope = value; 79 } | 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.reflect.generics.scope; 27 28 import java.lang.reflect.GenericDeclaration; 29 import java.lang.reflect.TypeVariable; 30 31 32 /** 33 * Abstract superclass for lazy scope objects, used when building 34 * factories for generic information repositories. 35 * The type parameter {@code D} represents the type of reflective 36 * object whose scope this class is representing. 37 * <p> To subclass this, all one needs to do is implement 38 * {@code computeEnclosingScope} and the subclass' constructor. 39 */ 40 public abstract class AbstractScope<D extends GenericDeclaration> 41 implements Scope { 42 43 private final D recvr; // the declaration whose scope this instance represents 44 45 /** The enclosing scope of this scope. Lazily initialized. */ 46 private volatile Scope enclosingScope; 47 48 /** 49 * Constructor. Takes a reflective object whose scope the newly 50 * constructed instance will represent. 51 * @param decl - A generic declaration whose scope the newly 52 * constructed instance will represent 53 */ 54 protected AbstractScope(D decl){ recvr = decl;} 55 56 /** 57 * Accessor for the receiver - the object whose scope this {@code Scope} 58 * object represents. 59 * @return The object whose scope this {@code Scope} object represents 60 */ 61 protected D getRecvr() {return recvr;} 62 63 /** This method must be implemented by any concrete subclass. 64 * It must return the enclosing scope of this scope. If this scope 65 * is a top-level scope, an instance of DummyScope must be returned. 66 * @return The enclosing scope of this scope 67 */ 68 protected abstract Scope computeEnclosingScope(); 69 70 /** 71 * Accessor for the enclosing scope, which is computed lazily and cached. 72 * @return the enclosing scope 73 */ 74 protected Scope getEnclosingScope() { 75 Scope value = enclosingScope; 76 if (value == null) { 77 value = computeEnclosingScope(); 78 enclosingScope = value; 79 } |