Mon, 25 Mar 2013 16:55:14 -0700
8010521: jdk8 l10n resource file translation update 2
Reviewed-by: naoto, yhuang
1 /*
2 * Copyright (c) 1997, 2013, 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.doclets.formats.html;
28 import com.sun.javadoc.*;
29 import com.sun.tools.doclets.formats.html.markup.*;
30 import com.sun.tools.doclets.internal.toolkit.*;
31 import com.sun.tools.doclets.internal.toolkit.util.*;
33 /**
34 * Print method and constructor info.
35 *
36 * <p><b>This is NOT part of any supported API.
37 * If you write code that depends on this, you do so at your own risk.
38 * This code and its internal interfaces are subject to change or
39 * deletion without notice.</b>
40 *
41 * @author Robert Field
42 * @author Atul M Dambalkar
43 * @author Bhavesh Patel (Modified)
44 */
45 public abstract class AbstractExecutableMemberWriter extends AbstractMemberWriter {
47 public AbstractExecutableMemberWriter(SubWriterHolderWriter writer,
48 ClassDoc classdoc) {
49 super(writer, classdoc);
50 }
52 public AbstractExecutableMemberWriter(SubWriterHolderWriter writer) {
53 super(writer);
54 }
56 /**
57 * Add the type parameters for the executable member.
58 *
59 * @param member the member to write type parameters for.
60 * @param htmltree the content tree to which the parameters will be added.
61 * @return the display length required to write this information.
62 */
63 protected int addTypeParameters(ExecutableMemberDoc member, Content htmltree) {
64 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
65 LinkInfoImpl.CONTEXT_MEMBER_TYPE_PARAMS, member, false);
66 String typeParameters = writer.getTypeParameterLinks(linkInfo);
67 if (linkInfo.displayLength > 0) {
68 Content linkContent = new RawHtml(typeParameters);
69 htmltree.addContent(linkContent);
70 htmltree.addContent(writer.getSpace());
71 writer.displayLength += linkInfo.displayLength + 1;
72 }
73 return linkInfo.displayLength;
74 }
76 /**
77 * {@inheritDoc}
78 */
79 protected Content getDeprecatedLink(ProgramElementDoc member) {
80 ExecutableMemberDoc emd = (ExecutableMemberDoc)member;
81 return writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER, (MemberDoc) emd,
82 emd.qualifiedName() + emd.flatSignature());
83 }
85 /**
86 * Add the summary link for the member.
87 *
88 * @param context the id of the context where the link will be printed
89 * @param cd the classDoc that we should link to
90 * @param member the member being linked to
91 * @param tdSummary the content tree to which the link will be added
92 */
93 protected void addSummaryLink(int context, ClassDoc cd, ProgramElementDoc member,
94 Content tdSummary) {
95 ExecutableMemberDoc emd = (ExecutableMemberDoc)member;
96 String name = emd.name();
97 Content strong = HtmlTree.STRONG(new RawHtml(
98 writer.getDocLink(context, cd, (MemberDoc) emd,
99 name, false)));
100 Content code = HtmlTree.CODE(strong);
101 writer.displayLength = name.length();
102 addParameters(emd, false, code);
103 tdSummary.addContent(code);
104 }
106 /**
107 * Add the inherited summary link for the member.
108 *
109 * @param cd the classDoc that we should link to
110 * @param member the member being linked to
111 * @param linksTree the content tree to which the link will be added
112 */
113 protected void addInheritedSummaryLink(ClassDoc cd,
114 ProgramElementDoc member, Content linksTree) {
115 linksTree.addContent(new RawHtml(
116 writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER, cd, (MemberDoc) member,
117 member.name(), false)));
118 }
120 /**
121 * Add the parameter for the executable member.
122 *
123 * @param member the member to write parameter for.
124 * @param param the parameter that needs to be written.
125 * @param isVarArg true if this is a link to var arg.
126 * @param tree the content tree to which the parameter information will be added.
127 */
128 protected void addParam(ExecutableMemberDoc member, Parameter param,
129 boolean isVarArg, Content tree) {
130 if (param.type() != null) {
131 Content link = new RawHtml(writer.getLink(new LinkInfoImpl(
132 configuration, LinkInfoImpl.CONTEXT_EXECUTABLE_MEMBER_PARAM,
133 param.type(), isVarArg)));
134 tree.addContent(link);
135 }
136 if(param.name().length() > 0) {
137 tree.addContent(writer.getSpace());
138 tree.addContent(param.name());
139 }
140 }
142 protected void addReceiverAnnotations(ExecutableMemberDoc member,
143 Content tree) {
144 if (member.receiverAnnotations().length > 0) {
145 tree.addContent(writer.getSpace());
146 writer.addReceiverAnnotationInfo(member, tree);
147 }
148 }
151 /**
152 * Add all the parameters for the executable member.
153 *
154 * @param member the member to write parameters for.
155 * @param htmltree the content tree to which the parameters information will be added.
156 */
157 protected void addParameters(ExecutableMemberDoc member, Content htmltree) {
158 addParameters(member, true, htmltree);
159 }
161 /**
162 * Add all the parameters for the executable member.
163 *
164 * @param member the member to write parameters for.
165 * @param includeAnnotations true if annotation information needs to be added.
166 * @param htmltree the content tree to which the parameters information will be added.
167 */
168 protected void addParameters(ExecutableMemberDoc member,
169 boolean includeAnnotations, Content htmltree) {
170 htmltree.addContent("(");
171 Parameter[] params = member.parameters();
172 String indent = makeSpace(writer.displayLength);
173 if (configuration.linksource) {
174 //add spaces to offset indentation changes caused by link.
175 indent+= makeSpace(member.name().length());
176 }
177 int paramstart;
178 for (paramstart = 0; paramstart < params.length; paramstart++) {
179 Parameter param = params[paramstart];
180 if (!param.name().startsWith("this$")) {
181 if (includeAnnotations) {
182 boolean foundAnnotations =
183 writer.addAnnotationInfo(indent.length(),
184 member, param, htmltree);
185 if (foundAnnotations) {
186 htmltree.addContent(DocletConstants.NL);
187 htmltree.addContent(indent);
188 }
189 }
190 addParam(member, param,
191 (paramstart == params.length - 1) && member.isVarArgs(), htmltree);
192 break;
193 }
194 }
196 for (int i = paramstart + 1; i < params.length; i++) {
197 htmltree.addContent(",");
198 htmltree.addContent(DocletConstants.NL);
199 htmltree.addContent(indent);
200 if (includeAnnotations) {
201 boolean foundAnnotations =
202 writer.addAnnotationInfo(indent.length(), member, params[i],
203 htmltree);
204 if (foundAnnotations) {
205 htmltree.addContent(DocletConstants.NL);
206 htmltree.addContent(indent);
207 }
208 }
209 addParam(member, params[i], (i == params.length - 1) && member.isVarArgs(),
210 htmltree);
211 }
212 htmltree.addContent(")");
213 }
215 /**
216 * Add exceptions for the executable member.
217 *
218 * @param member the member to write exceptions for.
219 * @param htmltree the content tree to which the exceptions information will be added.
220 */
221 protected void addExceptions(ExecutableMemberDoc member, Content htmltree) {
222 Type[] exceptions = member.thrownExceptionTypes();
223 if(exceptions.length > 0) {
224 LinkInfoImpl memberTypeParam = new LinkInfoImpl(configuration,
225 LinkInfoImpl.CONTEXT_MEMBER, member, false);
226 int retlen = getReturnTypeLength(member);
227 writer.getTypeParameterLinks(memberTypeParam);
228 retlen += memberTypeParam.displayLength == 0 ?
229 0 : memberTypeParam.displayLength + 1;
230 String indent = makeSpace(modifierString(member).length() +
231 member.name().length() + retlen - 4);
232 htmltree.addContent(DocletConstants.NL);
233 htmltree.addContent(indent);
234 htmltree.addContent("throws ");
235 indent += " ";
236 Content link = new RawHtml(writer.getLink(new LinkInfoImpl(configuration,
237 LinkInfoImpl.CONTEXT_MEMBER, exceptions[0])));
238 htmltree.addContent(link);
239 for(int i = 1; i < exceptions.length; i++) {
240 htmltree.addContent(",");
241 htmltree.addContent(DocletConstants.NL);
242 htmltree.addContent(indent);
243 Content exceptionLink = new RawHtml(writer.getLink(new LinkInfoImpl(
244 configuration, LinkInfoImpl.CONTEXT_MEMBER, exceptions[i])));
245 htmltree.addContent(exceptionLink);
246 }
247 }
248 }
250 protected int getReturnTypeLength(ExecutableMemberDoc member) {
251 if (member instanceof MethodDoc) {
252 MethodDoc method = (MethodDoc)member;
253 Type rettype = method.returnType();
254 if (rettype.isPrimitive()) {
255 return rettype.typeName().length() +
256 rettype.dimension().length();
257 } else {
258 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
259 LinkInfoImpl.CONTEXT_MEMBER, rettype);
260 writer.getLink(linkInfo);
261 return linkInfo.displayLength;
262 }
263 } else { // it's a constructordoc
264 return -1;
265 }
266 }
268 protected ClassDoc implementsMethodInIntfac(MethodDoc method,
269 ClassDoc[] intfacs) {
270 for (int i = 0; i < intfacs.length; i++) {
271 MethodDoc[] methods = intfacs[i].methods();
272 if (methods.length > 0) {
273 for (int j = 0; j < methods.length; j++) {
274 if (methods[j].name().equals(method.name()) &&
275 methods[j].signature().equals(method.signature())) {
276 return intfacs[i];
277 }
278 }
279 }
280 }
281 return null;
282 }
284 /**
285 * For backward compatibility, include an anchor using the erasures of the
286 * parameters. NOTE: We won't need this method anymore after we fix
287 * see tags so that they use the type instead of the erasure.
288 *
289 * @param emd the ExecutableMemberDoc to anchor to.
290 * @return the 1.4.x style anchor for the ExecutableMemberDoc.
291 */
292 protected String getErasureAnchor(ExecutableMemberDoc emd) {
293 StringBuilder buf = new StringBuilder(emd.name() + "(");
294 Parameter[] params = emd.parameters();
295 boolean foundTypeVariable = false;
296 for (int i = 0; i < params.length; i++) {
297 if (i > 0) {
298 buf.append(",");
299 }
300 Type t = params[i].type();
301 foundTypeVariable = foundTypeVariable || t.asTypeVariable() != null;
302 buf.append(t.isPrimitive() ?
303 t.typeName() : t.asClassDoc().qualifiedName());
304 buf.append(t.dimension());
305 }
306 buf.append(")");
307 return foundTypeVariable ? buf.toString() : null;
308 }
309 }