0N/A/*
0N/A * Copyright (c) 2003, 2011, 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
0N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/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 *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.tools.javadoc;
0N/A
0N/A
0N/Aimport com.sun.javadoc.*;
0N/A
0N/Aimport com.sun.tools.javac.code.Symbol.ClassSymbol;
0N/Aimport com.sun.tools.javac.code.Type;
0N/Aimport com.sun.tools.javac.util.List;
0N/A
0N/A
0N/A/**
0N/A * Implementation of <code>WildcardType</code>, which
0N/A * represents a wildcard type.
0N/A *
0N/A * @author Scott Seligman
0N/A * @since 1.5
0N/A */
0N/Apublic class WildcardTypeImpl extends AbstractTypeImpl implements WildcardType {
0N/A
0N/A WildcardTypeImpl(DocEnv env, Type.WildcardType type) {
0N/A super(env, type);
0N/A }
0N/A
0N/A /**
0N/A * Return the upper bounds of this wildcard type argument
0N/A * as given by the <i>extends</i> clause.
0N/A * Return an empty array if no such bounds are explicitly given.
0N/A */
0N/A public com.sun.javadoc.Type[] extendsBounds() {
0N/A return TypeMaker.getTypes(env, getExtendsBounds((Type.WildcardType)type));
0N/A }
0N/A
0N/A /**
0N/A * Return the lower bounds of this wildcard type argument
0N/A * as given by the <i>super</i> clause.
0N/A * Return an empty array if no such bounds are explicitly given.
0N/A */
0N/A public com.sun.javadoc.Type[] superBounds() {
0N/A return TypeMaker.getTypes(env, getSuperBounds((Type.WildcardType)type));
0N/A }
0N/A
0N/A /**
0N/A * Return the ClassDoc of the erasure of this wildcard type.
0N/A */
0N/A @Override
0N/A public ClassDoc asClassDoc() {
0N/A return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
0N/A }
0N/A
0N/A @Override
0N/A public WildcardType asWildcardType() {
0N/A return this;
0N/A }
0N/A
0N/A @Override
0N/A public String typeName() { return "?"; }
0N/A @Override
0N/A public String qualifiedTypeName() { return "?"; }
0N/A @Override
0N/A public String simpleTypeName() { return "?"; }
0N/A
0N/A @Override
0N/A public String toString() {
0N/A return wildcardTypeToString(env, (Type.WildcardType)type, true);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Return the string form of a wildcard type ("?") along with any
0N/A * "extends" or "super" clause. Delimiting brackets are not
0N/A * included. Class names are qualified if "full" is true.
0N/A */
0N/A static String wildcardTypeToString(DocEnv env,
0N/A Type.WildcardType wildThing, boolean full) {
0N/A if (env.legacyDoclet) {
0N/A return TypeMaker.getTypeName(env.types.erasure(wildThing), full);
0N/A }
0N/A StringBuilder s = new StringBuilder("?");
0N/A List<Type> bounds = getExtendsBounds(wildThing);
0N/A if (bounds.nonEmpty()) {
0N/A s.append(" extends ");
0N/A } else {
0N/A bounds = getSuperBounds(wildThing);
0N/A if (bounds.nonEmpty()) {
0N/A s.append(" super ");
0N/A }
0N/A }
0N/A boolean first = true; // currently only one bound is allowed
0N/A for (Type b : bounds) {
0N/A if (!first) {
0N/A s.append(" & ");
0N/A }
0N/A s.append(TypeMaker.getTypeString(env, b, full));
0N/A first = false;
0N/A }
0N/A return s.toString();
0N/A }
0N/A
0N/A private static List<Type> getExtendsBounds(Type.WildcardType wild) {
0N/A return wild.isSuperBound()
0N/A ? List.<Type>nil()
0N/A : List.of(wild.type);
0N/A }
0N/A
0N/A private static List<Type> getSuperBounds(Type.WildcardType wild) {
0N/A return wild.isExtendsBound()
0N/A ? List.<Type>nil()
0N/A : List.of(wild.type);
0N/A }
0N/A}
0N/A