/* * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package sun.reflect.generics.reflectiveObjects; import java.lang.reflect.Type; import java.lang.reflect.WildcardType; import sun.reflect.generics.factory.GenericsFactory; import sun.reflect.generics.tree.FieldTypeSignature; import sun.reflect.generics.visitor.Reifier; import java.util.Arrays; /** * Implementation of WildcardType interface for core reflection. */ public class WildcardTypeImpl extends LazyReflectiveObjectGenerator implements WildcardType { // upper bounds - evaluated lazily private Type[] upperBounds; // lower bounds - evaluated lazily private Type[] lowerBounds; // The ASTs for the bounds. We are required to evaluate the bounds // lazily, so we store these at least until we are first asked // for the bounds. This also neatly solves the // problem with F-bounds - you can't reify them before the formal // is defined. private FieldTypeSignature[] upperBoundASTs; private FieldTypeSignature[] lowerBoundASTs; // constructor is private to enforce access through static factory private WildcardTypeImpl(FieldTypeSignature[] ubs, FieldTypeSignature[] lbs, GenericsFactory f) { super(f); upperBoundASTs = ubs; lowerBoundASTs = lbs; } /** * Factory method. * @param ubs - an array of ASTs representing the upper bounds for the type * variable to be created * @param lbs - an array of ASTs representing the lower bounds for the type * variable to be created * @param f - a factory that can be used to manufacture reflective * objects that represent the bounds of this wildcard type * @return a wild card type with the requested bounds and factory */ public static WildcardTypeImpl make(FieldTypeSignature[] ubs, FieldTypeSignature[] lbs, GenericsFactory f) { return new WildcardTypeImpl(ubs, lbs, f); } // Accessors // accessor for ASTs for upper bounds. Must not be called after upper // bounds have been evaluated, because we might throw the ASTs // away (but that is not thread-safe, is it?) private FieldTypeSignature[] getUpperBoundASTs() { // check that upper bounds were not evaluated yet assert(upperBounds == null); return upperBoundASTs; } // accessor for ASTs for lower bounds. Must not be called after lower // bounds have been evaluated, because we might throw the ASTs // away (but that is not thread-safe, is it?) private FieldTypeSignature[] getLowerBoundASTs() { // check that lower bounds were not evaluated yet assert(lowerBounds == null); return lowerBoundASTs; } /** * Returns an array of Type objects representing the upper * bound(s) of this type variable. Note that if no upper bound is * explicitly declared, the upper bound is Object. * *
For each upper bound B : *
For each lower bound B : *