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