src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java

Tue, 06 Nov 2012 14:32:49 -0800

author
jjg
date
Tue, 06 Nov 2012 14:32:49 -0800
changeset 1397
8abc56be3131
parent 1359
25e14ad23cef
child 1521
71f35e4b93a5
permissions
-rw-r--r--

8000612: Discrepancy between resources provided in javadoc resource files and resources required by code
Reviewed-by: bpatel

duke@1 1 /*
jjg@1357 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javadoc;
duke@1 27
duke@1 28 import com.sun.javadoc.*;
duke@1 29
duke@1 30 import com.sun.tools.javac.code.Kinds;
duke@1 31 import com.sun.tools.javac.code.Symbol;
duke@1 32 import com.sun.tools.javac.code.Symbol.ClassSymbol;
duke@1 33 import com.sun.tools.javac.code.Symbol.MethodSymbol;
duke@1 34 import com.sun.tools.javac.code.Type;
duke@1 35 import com.sun.tools.javac.code.Type.TypeVar;
duke@1 36 import com.sun.tools.javac.util.List;
duke@1 37 import com.sun.tools.javac.util.Name;
jjg@113 38 import com.sun.tools.javac.util.Names;
duke@1 39
duke@1 40 /**
duke@1 41 * Implementation of <code>TypeVariable</code>, which
duke@1 42 * represents a type variable.
duke@1 43 *
jjg@1359 44 * <p><b>This is NOT part of any supported API.
jjg@1359 45 * If you write code that depends on this, you do so at your own risk.
jjg@1359 46 * This code and its internal interfaces are subject to change or
jjg@1359 47 * deletion without notice.</b>
jjg@1359 48 *
duke@1 49 * @author Scott Seligman
duke@1 50 * @since 1.5
duke@1 51 */
duke@1 52 public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
duke@1 53
duke@1 54 TypeVariableImpl(DocEnv env, TypeVar type) {
duke@1 55 super(env, type);
duke@1 56 }
duke@1 57
duke@1 58 /**
duke@1 59 * Return the bounds of this type variable.
duke@1 60 */
duke@1 61 public com.sun.javadoc.Type[] bounds() {
duke@1 62 return TypeMaker.getTypes(env, getBounds((TypeVar)type, env));
duke@1 63 }
duke@1 64
duke@1 65 /**
duke@1 66 * Return the class, interface, method, or constructor within
duke@1 67 * which this type variable is declared.
duke@1 68 */
duke@1 69 public ProgramElementDoc owner() {
duke@1 70 Symbol osym = type.tsym.owner;
duke@1 71 if ((osym.kind & Kinds.TYP) != 0) {
duke@1 72 return env.getClassDoc((ClassSymbol)osym);
duke@1 73 }
jjg@113 74 Names names = osym.name.table.names;
duke@1 75 if (osym.name == names.init) {
duke@1 76 return env.getConstructorDoc((MethodSymbol)osym);
duke@1 77 } else {
duke@1 78 return env.getMethodDoc((MethodSymbol)osym);
duke@1 79 }
duke@1 80 }
duke@1 81
duke@1 82 /**
duke@1 83 * Return the ClassDoc of the erasure of this type variable.
duke@1 84 */
jjg@910 85 @Override
duke@1 86 public ClassDoc asClassDoc() {
duke@1 87 return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
duke@1 88 }
duke@1 89
jjg@910 90 @Override
duke@1 91 public TypeVariable asTypeVariable() {
duke@1 92 return this;
duke@1 93 }
duke@1 94
jjg@910 95 @Override
duke@1 96 public String toString() {
duke@1 97 return typeVarToString(env, (TypeVar)type, true);
duke@1 98 }
duke@1 99
duke@1 100
duke@1 101 /**
duke@1 102 * Return the string form of a type variable along with any
duke@1 103 * "extends" clause. Class names are qualified if "full" is true.
duke@1 104 */
duke@1 105 static String typeVarToString(DocEnv env, TypeVar v, boolean full) {
jjg@910 106 StringBuilder s = new StringBuilder(v.toString());
duke@1 107 List<Type> bounds = getBounds(v, env);
duke@1 108 if (bounds.nonEmpty()) {
duke@1 109 boolean first = true;
duke@1 110 for (Type b : bounds) {
duke@1 111 s.append(first ? " extends " : " & ");
duke@1 112 s.append(TypeMaker.getTypeString(env, b, full));
duke@1 113 first = false;
duke@1 114 }
duke@1 115 }
duke@1 116 return s.toString();
duke@1 117 }
duke@1 118
duke@1 119 /**
duke@1 120 * Get the bounds of a type variable as listed in the "extends" clause.
duke@1 121 */
duke@1 122 private static List<Type> getBounds(TypeVar v, DocEnv env) {
duke@1 123 Name boundname = v.getUpperBound().tsym.getQualifiedName();
jjg@113 124 if (boundname == boundname.table.names.java_lang_Object) {
duke@1 125 return List.nil();
duke@1 126 } else {
duke@1 127 return env.types.getBounds(v);
duke@1 128 }
duke@1 129 }
duke@1 130 }

mercurial