001: /*
002: * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.javadoc;
027:
028: import com.sun.javadoc.*;
029:
030: import static com.sun.javadoc.LanguageVersion.*;
031:
032: import com.sun.tools.javac.code.Symbol.ClassSymbol;
033: import com.sun.tools.javac.code.Type;
034: import com.sun.tools.javac.util.List;
035:
036: /**
037: * Implementation of <code>WildcardType</code>, which
038: * represents a wildcard type.
039: *
040: * @author Scott Seligman
041: * @version 1.17 07/05/05
042: * @since 1.5
043: */
044: public class WildcardTypeImpl extends AbstractTypeImpl implements
045: WildcardType {
046:
047: WildcardTypeImpl(DocEnv env, Type.WildcardType type) {
048: super (env, type);
049: }
050:
051: /**
052: * Return the upper bounds of this wildcard type argument
053: * as given by the <i>extends</i> clause.
054: * Return an empty array if no such bounds are explicitly given.
055: */
056: public com.sun.javadoc.Type[] extendsBounds() {
057: return TypeMaker.getTypes(env,
058: getExtendsBounds((Type.WildcardType) type));
059: }
060:
061: /**
062: * Return the lower bounds of this wildcard type argument
063: * as given by the <i>super</i> clause.
064: * Return an empty array if no such bounds are explicitly given.
065: */
066: public com.sun.javadoc.Type[] super Bounds() {
067: return TypeMaker.getTypes(env,
068: getSuperBounds((Type.WildcardType) type));
069: }
070:
071: /**
072: * Return the ClassDoc of the erasure of this wildcard type.
073: */
074: public ClassDoc asClassDoc() {
075: return env
076: .getClassDoc((ClassSymbol) env.types.erasure(type).tsym);
077: }
078:
079: public WildcardType asWildcardType() {
080: return this ;
081: }
082:
083: public String typeName() {
084: return "?";
085: }
086:
087: public String qualifiedTypeName() {
088: return "?";
089: }
090:
091: public String simpleTypeName() {
092: return "?";
093: }
094:
095: public String toString() {
096: return wildcardTypeToString(env, (Type.WildcardType) type, true);
097: }
098:
099: /**
100: * Return the string form of a wildcard type ("?") along with any
101: * "extends" or "super" clause. Delimiting brackets are not
102: * included. Class names are qualified if "full" is true.
103: */
104: static String wildcardTypeToString(DocEnv env,
105: Type.WildcardType wildThing, boolean full) {
106: if (env.legacyDoclet) {
107: return TypeMaker.getTypeName(env.types.erasure(wildThing),
108: full);
109: }
110: StringBuffer s = new StringBuffer("?");
111: List<Type> bounds = getExtendsBounds(wildThing);
112: if (bounds.nonEmpty()) {
113: s.append(" extends ");
114: } else {
115: bounds = getSuperBounds(wildThing);
116: if (bounds.nonEmpty()) {
117: s.append(" super ");
118: }
119: }
120: boolean first = true; // currently only one bound is allowed
121: for (Type b : bounds) {
122: if (!first) {
123: s.append(" & ");
124: }
125: s.append(TypeMaker.getTypeString(env, b, full));
126: first = false;
127: }
128: return s.toString();
129: }
130:
131: private static List<Type> getExtendsBounds(Type.WildcardType wild) {
132: return wild.isSuperBound() ? List.<Type> nil() : List
133: .of(wild.type);
134: }
135:
136: private static List<Type> getSuperBounds(Type.WildcardType wild) {
137: return wild.isExtendsBound() ? List.<Type> nil() : List
138: .of(wild.type);
139: }
140: }
|