Thu, 18 Sep 2008 18:39:44 -0700
6744408: Extra ouput is appearing in stderr
Reviewed-by: bpatel
duke@1 | 1 | /* |
duke@1 | 2 | * Copyright 1997-2006 Sun Microsystems, Inc. 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 |
duke@1 | 7 | * published by the Free Software Foundation. Sun designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
duke@1 | 9 | * by Sun 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 | * |
duke@1 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@1 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@1 | 23 | * have any 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.util.List; |
duke@1 | 31 | import com.sun.tools.javac.util.ListBuffer; |
duke@1 | 32 | import com.sun.tools.javac.util.Position; |
duke@1 | 33 | import com.sun.tools.javac.code.Flags; |
duke@1 | 34 | import com.sun.tools.javac.code.Type; |
duke@1 | 35 | import com.sun.tools.javac.code.Symbol; |
duke@1 | 36 | import com.sun.tools.javac.code.Symbol.*; |
duke@1 | 37 | import com.sun.tools.javac.tree.JCTree.JCMethodDecl; |
duke@1 | 38 | |
duke@1 | 39 | import java.text.CollationKey; |
duke@1 | 40 | |
duke@1 | 41 | import java.lang.reflect.Modifier; |
duke@1 | 42 | |
duke@1 | 43 | /** |
duke@1 | 44 | * Represents a method or constructor of a java class. |
duke@1 | 45 | * |
duke@1 | 46 | * @since 1.2 |
duke@1 | 47 | * @author Robert Field |
duke@1 | 48 | * @author Neal Gafter (rewrite) |
duke@1 | 49 | * @author Scott Seligman (generics, annotations) |
duke@1 | 50 | */ |
duke@1 | 51 | |
duke@1 | 52 | public abstract class ExecutableMemberDocImpl |
duke@1 | 53 | extends MemberDocImpl implements ExecutableMemberDoc { |
duke@1 | 54 | |
duke@1 | 55 | protected final MethodSymbol sym; |
duke@1 | 56 | |
duke@1 | 57 | /** |
duke@1 | 58 | * Constructor. |
duke@1 | 59 | */ |
duke@1 | 60 | public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym, |
duke@1 | 61 | String rawDocs, JCMethodDecl tree, Position.LineMap lineMap) { |
duke@1 | 62 | super(env, sym, rawDocs, tree, lineMap); |
duke@1 | 63 | this.sym = sym; |
duke@1 | 64 | } |
duke@1 | 65 | |
duke@1 | 66 | /** |
duke@1 | 67 | * Constructor. |
duke@1 | 68 | */ |
duke@1 | 69 | public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym) { |
duke@1 | 70 | this(env, sym, null, null, null); |
duke@1 | 71 | } |
duke@1 | 72 | |
duke@1 | 73 | /** |
duke@1 | 74 | * Returns the flags in terms of javac's flags |
duke@1 | 75 | */ |
duke@1 | 76 | protected long getFlags() { |
duke@1 | 77 | return sym.flags(); |
duke@1 | 78 | } |
duke@1 | 79 | |
duke@1 | 80 | /** |
duke@1 | 81 | * Identify the containing class |
duke@1 | 82 | */ |
duke@1 | 83 | protected ClassSymbol getContainingClass() { |
duke@1 | 84 | return sym.enclClass(); |
duke@1 | 85 | } |
duke@1 | 86 | |
duke@1 | 87 | /** |
duke@1 | 88 | * Return true if this method is native |
duke@1 | 89 | */ |
duke@1 | 90 | public boolean isNative() { |
duke@1 | 91 | return Modifier.isNative(getModifiers()); |
duke@1 | 92 | } |
duke@1 | 93 | |
duke@1 | 94 | /** |
duke@1 | 95 | * Return true if this method is synchronized |
duke@1 | 96 | */ |
duke@1 | 97 | public boolean isSynchronized() { |
duke@1 | 98 | return Modifier.isSynchronized(getModifiers()); |
duke@1 | 99 | } |
duke@1 | 100 | |
duke@1 | 101 | /** |
duke@1 | 102 | * Return true if this method was declared to take a variable number |
duke@1 | 103 | * of arguments. |
duke@1 | 104 | */ |
duke@1 | 105 | public boolean isVarArgs() { |
duke@1 | 106 | return ((sym.flags() & Flags.VARARGS) != 0 |
duke@1 | 107 | && !env.legacyDoclet); |
duke@1 | 108 | } |
duke@1 | 109 | |
duke@1 | 110 | /** |
duke@1 | 111 | * Returns true if this field was synthesized by the compiler. |
duke@1 | 112 | */ |
duke@1 | 113 | public boolean isSynthetic() { |
duke@1 | 114 | return ((sym.flags() & Flags.SYNTHETIC) != 0); |
duke@1 | 115 | } |
duke@1 | 116 | |
duke@1 | 117 | public boolean isIncluded() { |
duke@1 | 118 | return containingClass().isIncluded() && env.shouldDocument(sym); |
duke@1 | 119 | } |
duke@1 | 120 | |
duke@1 | 121 | /** |
duke@1 | 122 | * Return the throws tags in this method. |
duke@1 | 123 | * |
duke@1 | 124 | * @return an array of ThrowTagImpl containing all {@code @exception} |
duke@1 | 125 | * and {@code @throws} tags. |
duke@1 | 126 | */ |
duke@1 | 127 | public ThrowsTag[] throwsTags() { |
duke@1 | 128 | return comment().throwsTags(); |
duke@1 | 129 | } |
duke@1 | 130 | |
duke@1 | 131 | /** |
duke@1 | 132 | * Return the param tags in this method, excluding the type |
duke@1 | 133 | * parameter tags. |
duke@1 | 134 | * |
duke@1 | 135 | * @return an array of ParamTagImpl containing all {@code @param} tags. |
duke@1 | 136 | */ |
duke@1 | 137 | public ParamTag[] paramTags() { |
duke@1 | 138 | return comment().paramTags(); |
duke@1 | 139 | } |
duke@1 | 140 | |
duke@1 | 141 | /** |
duke@1 | 142 | * Return the type parameter tags in this method. |
duke@1 | 143 | */ |
duke@1 | 144 | public ParamTag[] typeParamTags() { |
duke@1 | 145 | return env.legacyDoclet |
duke@1 | 146 | ? new ParamTag[0] |
duke@1 | 147 | : comment().typeParamTags(); |
duke@1 | 148 | } |
duke@1 | 149 | |
duke@1 | 150 | /** |
duke@1 | 151 | * Return exceptions this method or constructor throws. |
duke@1 | 152 | * |
duke@1 | 153 | * @return an array of ClassDoc[] representing the exceptions |
duke@1 | 154 | * thrown by this method. |
duke@1 | 155 | */ |
duke@1 | 156 | public ClassDoc[] thrownExceptions() { |
duke@1 | 157 | ListBuffer<ClassDocImpl> l = new ListBuffer<ClassDocImpl>(); |
duke@1 | 158 | for (Type ex : sym.type.getThrownTypes()) { |
duke@1 | 159 | ex = env.types.erasure(ex); |
duke@1 | 160 | //### Will these casts succeed in the face of static semantic |
duke@1 | 161 | //### errors in the documented code? |
duke@1 | 162 | ClassDocImpl cdi = env.getClassDoc((ClassSymbol)ex.tsym); |
duke@1 | 163 | if (cdi != null) l.append(cdi); |
duke@1 | 164 | } |
duke@1 | 165 | return l.toArray(new ClassDocImpl[l.length()]); |
duke@1 | 166 | } |
duke@1 | 167 | |
duke@1 | 168 | /** |
duke@1 | 169 | * Return exceptions this method or constructor throws. |
duke@1 | 170 | * Each array element is either a <code>ClassDoc</code> or a |
duke@1 | 171 | * <code>TypeVariable</code>. |
duke@1 | 172 | */ |
duke@1 | 173 | public com.sun.javadoc.Type[] thrownExceptionTypes() { |
duke@1 | 174 | return TypeMaker.getTypes(env, sym.type.getThrownTypes()); |
duke@1 | 175 | } |
duke@1 | 176 | |
duke@1 | 177 | /** |
duke@1 | 178 | * Get argument information. |
duke@1 | 179 | * |
duke@1 | 180 | * @see ParameterImpl |
duke@1 | 181 | * |
duke@1 | 182 | * @return an array of ParameterImpl, one element per argument |
duke@1 | 183 | * in the order the arguments are present. |
duke@1 | 184 | */ |
duke@1 | 185 | public Parameter[] parameters() { |
duke@1 | 186 | // generate the parameters on the fly: they're not cached |
duke@1 | 187 | List<VarSymbol> params = sym.params(); |
duke@1 | 188 | Parameter result[] = new Parameter[params.length()]; |
duke@1 | 189 | |
duke@1 | 190 | int i = 0; |
duke@1 | 191 | for (VarSymbol param : params) { |
duke@1 | 192 | result[i++] = new ParameterImpl(env, param); |
duke@1 | 193 | } |
duke@1 | 194 | return result; |
duke@1 | 195 | } |
duke@1 | 196 | |
duke@1 | 197 | /** |
duke@1 | 198 | * Return the formal type parameters of this method or constructor. |
duke@1 | 199 | * Return an empty array if there are none. |
duke@1 | 200 | */ |
duke@1 | 201 | public TypeVariable[] typeParameters() { |
duke@1 | 202 | if (env.legacyDoclet) { |
duke@1 | 203 | return new TypeVariable[0]; |
duke@1 | 204 | } |
duke@1 | 205 | TypeVariable res[] = new TypeVariable[sym.type.getTypeArguments().length()]; |
duke@1 | 206 | TypeMaker.getTypes(env, sym.type.getTypeArguments(), res); |
duke@1 | 207 | return res; |
duke@1 | 208 | } |
duke@1 | 209 | |
duke@1 | 210 | /** |
duke@1 | 211 | * Get the signature. It is the parameter list, type is qualified. |
duke@1 | 212 | * For instance, for a method <code>mymethod(String x, int y)</code>, |
duke@1 | 213 | * it will return <code>(java.lang.String,int)</code>. |
duke@1 | 214 | */ |
duke@1 | 215 | public String signature() { |
duke@1 | 216 | return makeSignature(true); |
duke@1 | 217 | } |
duke@1 | 218 | |
duke@1 | 219 | /** |
duke@1 | 220 | * Get flat signature. All types are not qualified. |
duke@1 | 221 | * Return a String, which is the flat signiture of this member. |
duke@1 | 222 | * It is the parameter list, type is not qualified. |
duke@1 | 223 | * For instance, for a method <code>mymethod(String x, int y)</code>, |
duke@1 | 224 | * it will return <code>(String, int)</code>. |
duke@1 | 225 | */ |
duke@1 | 226 | public String flatSignature() { |
duke@1 | 227 | return makeSignature(false); |
duke@1 | 228 | } |
duke@1 | 229 | |
duke@1 | 230 | private String makeSignature(boolean full) { |
duke@1 | 231 | StringBuffer result = new StringBuffer(); |
duke@1 | 232 | result.append("("); |
duke@1 | 233 | for (List<Type> types = sym.type.getParameterTypes(); types.nonEmpty(); ) { |
jjg@74 | 234 | Type t = types.head; |
duke@1 | 235 | result.append(TypeMaker.getTypeString(env, t, full)); |
duke@1 | 236 | types = types.tail; |
duke@1 | 237 | if (types.nonEmpty()) { |
duke@1 | 238 | result.append(", "); |
duke@1 | 239 | } |
duke@1 | 240 | } |
duke@1 | 241 | if (isVarArgs()) { |
duke@1 | 242 | int len = result.length(); |
duke@1 | 243 | result.replace(len - 2, len, "..."); |
duke@1 | 244 | } |
duke@1 | 245 | result.append(")"); |
duke@1 | 246 | return result.toString(); |
duke@1 | 247 | } |
duke@1 | 248 | |
duke@1 | 249 | protected String typeParametersString() { |
duke@1 | 250 | return TypeMaker.typeParametersString(env, sym, true); |
duke@1 | 251 | } |
duke@1 | 252 | |
duke@1 | 253 | /** |
duke@1 | 254 | * Generate a key for sorting. |
duke@1 | 255 | */ |
duke@1 | 256 | CollationKey generateKey() { |
duke@1 | 257 | String k = name() + flatSignature() + typeParametersString(); |
duke@1 | 258 | // ',' and '&' are between '$' and 'a': normalize to spaces. |
duke@1 | 259 | k = k.replace(',', ' ').replace('&', ' '); |
duke@1 | 260 | // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\""); |
duke@1 | 261 | return env.doclocale.collator.getCollationKey(k); |
duke@1 | 262 | } |
duke@1 | 263 | |
duke@1 | 264 | /** |
duke@1 | 265 | * Return the source position of the entity, or null if |
duke@1 | 266 | * no position is available. |
duke@1 | 267 | */ |
duke@1 | 268 | public SourcePosition position() { |
duke@1 | 269 | if (sym.enclClass().sourcefile == null) return null; |
duke@1 | 270 | return SourcePositionImpl.make(sym.enclClass().sourcefile.toString(), |
duke@1 | 271 | (tree==null) ? 0 : tree.pos, |
duke@1 | 272 | lineMap); |
duke@1 | 273 | } |
duke@1 | 274 | } |