duke@1: /* ohair@798: * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: duke@1: import com.sun.javadoc.*; bpatel@766: import com.sun.tools.doclets.formats.html.markup.*; bpatel@766: import com.sun.tools.doclets.internal.toolkit.*; bpatel@766: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: /** duke@1: * Print method and constructor info. duke@1: * duke@1: * @author Robert Field duke@1: * @author Atul M Dambalkar bpatel@766: * @author Bhavesh Patel (Modified) duke@1: */ duke@1: public abstract class AbstractExecutableMemberWriter extends AbstractMemberWriter { duke@1: duke@1: public AbstractExecutableMemberWriter(SubWriterHolderWriter writer, duke@1: ClassDoc classdoc) { duke@1: super(writer, classdoc); duke@1: } duke@1: duke@1: public AbstractExecutableMemberWriter(SubWriterHolderWriter writer) { duke@1: super(writer); duke@1: } duke@1: duke@1: /** bpatel@766: * Add the type parameters for the executable member. duke@1: * duke@1: * @param member the member to write type parameters for. bpatel@766: * @param htmltree the content tree to which the parameters will be added. duke@1: * @return the display length required to write this information. duke@1: */ bpatel@766: protected int addTypeParameters(ExecutableMemberDoc member, Content htmltree) { duke@1: LinkInfoImpl linkInfo = new LinkInfoImpl( duke@1: LinkInfoImpl.CONTEXT_MEMBER_TYPE_PARAMS, member, false); duke@1: String typeParameters = writer.getTypeParameterLinks(linkInfo); duke@1: if (linkInfo.displayLength > 0) { bpatel@766: Content linkContent = new RawHtml(typeParameters); bpatel@766: htmltree.addContent(linkContent); bpatel@766: htmltree.addContent(writer.getSpace()); duke@1: writer.displayLength += linkInfo.displayLength + 1; duke@1: } duke@1: return linkInfo.displayLength; duke@1: } duke@1: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ bpatel@766: protected Content getDeprecatedLink(ProgramElementDoc member) { bpatel@766: ExecutableMemberDoc emd = (ExecutableMemberDoc)member; bpatel@766: return writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER, (MemberDoc) emd, bpatel@766: emd.qualifiedName() + emd.flatSignature()); duke@1: } duke@1: bpatel@766: /** bpatel@766: * Add the summary link for the member. bpatel@766: * bpatel@766: * @param context the id of the context where the link will be printed bpatel@766: * @param classDoc the classDoc that we should link to bpatel@766: * @param member the member being linked to bpatel@766: * @param tdSummary the content tree to which the link will be added bpatel@766: */ bpatel@766: protected void addSummaryLink(int context, ClassDoc cd, ProgramElementDoc member, bpatel@766: Content tdSummary) { duke@1: ExecutableMemberDoc emd = (ExecutableMemberDoc)member; bpatel@766: String name = emd.name(); bpatel@766: Content strong = HtmlTree.STRONG(new RawHtml( bpatel@766: writer.getDocLink(context, cd, (MemberDoc) emd, bpatel@766: name, false))); bpatel@766: Content code = HtmlTree.CODE(strong); bpatel@766: writer.displayLength = name.length(); bpatel@766: addParameters(emd, false, code); bpatel@766: tdSummary.addContent(code); duke@1: } duke@1: bpatel@766: /** bpatel@766: * Add the inherited summary link for the member. bpatel@766: * bpatel@766: * @param classDoc the classDoc that we should link to bpatel@766: * @param member the member being linked to bpatel@766: * @param linksTree the content tree to which the link will be added bpatel@766: */ bpatel@766: protected void addInheritedSummaryLink(ClassDoc cd, bpatel@766: ProgramElementDoc member, Content linksTree) { bpatel@766: linksTree.addContent(new RawHtml( bpatel@766: writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER, cd, (MemberDoc) member, bpatel@766: member.name(), false))); duke@1: } duke@1: bpatel@766: /** bpatel@766: * Add the parameter for the executable member. bpatel@766: * bpatel@766: * @param member the member to write parameter for. bpatel@766: * @param param the parameter that needs to be written. bpatel@766: * @param isVarArg true if this is a link to var arg. bpatel@766: * @param tree the content tree to which the parameter information will be added. bpatel@766: */ bpatel@766: protected void addParam(ExecutableMemberDoc member, Parameter param, bpatel@766: boolean isVarArg, Content tree) { duke@1: if (param.type() != null) { bpatel@766: Content link = new RawHtml(writer.getLink(new LinkInfoImpl( bpatel@766: LinkInfoImpl.CONTEXT_EXECUTABLE_MEMBER_PARAM, param.type(), bpatel@766: isVarArg))); bpatel@766: tree.addContent(link); duke@1: } duke@1: if(param.name().length() > 0) { bpatel@766: tree.addContent(writer.getSpace()); bpatel@766: tree.addContent(param.name()); duke@1: } duke@1: } duke@1: bpatel@766: /** bpatel@766: * Add all the parameters for the executable member. bpatel@766: * bpatel@766: * @param member the member to write parameters for. bpatel@766: * @param tree the content tree to which the parameters information will be added. bpatel@766: */ bpatel@766: protected void addParameters(ExecutableMemberDoc member, Content htmltree) { bpatel@766: addParameters(member, true, htmltree); duke@1: } duke@1: bpatel@766: /** bpatel@766: * Add all the parameters for the executable member. bpatel@766: * bpatel@766: * @param member the member to write parameters for. bpatel@766: * @param includeAnnotations true if annotation information needs to be added. bpatel@766: * @param tree the content tree to which the parameters information will be added. bpatel@766: */ bpatel@766: protected void addParameters(ExecutableMemberDoc member, bpatel@766: boolean includeAnnotations, Content htmltree) { bpatel@766: htmltree.addContent("("); duke@1: Parameter[] params = member.parameters(); duke@1: String indent = makeSpace(writer.displayLength); duke@1: if (configuration().linksource) { duke@1: //add spaces to offset indentation changes caused by link. duke@1: indent+= makeSpace(member.name().length()); duke@1: } duke@1: int paramstart; duke@1: for (paramstart = 0; paramstart < params.length; paramstart++) { duke@1: Parameter param = params[paramstart]; duke@1: if (!param.name().startsWith("this$")) { duke@1: if (includeAnnotations) { bpatel@766: boolean foundAnnotations = bpatel@766: writer.addAnnotationInfo(indent.length(), bpatel@766: member, param, htmltree); bpatel@766: if (foundAnnotations) { bpatel@766: htmltree.addContent(DocletConstants.NL); bpatel@766: htmltree.addContent(indent); duke@1: } duke@1: } bpatel@766: addParam(member, param, bpatel@766: (paramstart == params.length - 1) && member.isVarArgs(), htmltree); duke@1: break; duke@1: } duke@1: } duke@1: duke@1: for (int i = paramstart + 1; i < params.length; i++) { bpatel@766: htmltree.addContent(","); bpatel@766: htmltree.addContent(DocletConstants.NL); bpatel@766: htmltree.addContent(indent); duke@1: if (includeAnnotations) { duke@1: boolean foundAnnotations = bpatel@766: writer.addAnnotationInfo(indent.length(), member, params[i], bpatel@766: htmltree); duke@1: if (foundAnnotations) { bpatel@766: htmltree.addContent(DocletConstants.NL); bpatel@766: htmltree.addContent(indent); duke@1: } duke@1: } bpatel@766: addParam(member, params[i], (i == params.length - 1) && member.isVarArgs(), bpatel@766: htmltree); duke@1: } bpatel@766: htmltree.addContent(")"); duke@1: } duke@1: bpatel@766: /** bpatel@766: * Add exceptions for the executable member. bpatel@766: * bpatel@766: * @param member the member to write exceptions for. bpatel@766: * @param htmltree the content tree to which the exceptions information will be added. bpatel@766: */ bpatel@766: protected void addExceptions(ExecutableMemberDoc member, Content htmltree) { duke@1: Type[] exceptions = member.thrownExceptionTypes(); duke@1: if(exceptions.length > 0) { duke@1: LinkInfoImpl memberTypeParam = new LinkInfoImpl( bpatel@766: LinkInfoImpl.CONTEXT_MEMBER, member, false); duke@1: int retlen = getReturnTypeLength(member); duke@1: writer.getTypeParameterLinks(memberTypeParam); duke@1: retlen += memberTypeParam.displayLength == 0 ? duke@1: 0 : memberTypeParam.displayLength + 1; duke@1: String indent = makeSpace(modifierString(member).length() + bpatel@766: member.name().length() + retlen - 4); bpatel@766: htmltree.addContent(DocletConstants.NL); bpatel@766: htmltree.addContent(indent); bpatel@766: htmltree.addContent("throws "); duke@1: indent += " "; bpatel@766: Content link = new RawHtml(writer.getLink(new LinkInfoImpl( bpatel@766: LinkInfoImpl.CONTEXT_MEMBER, exceptions[0]))); bpatel@766: htmltree.addContent(link); duke@1: for(int i = 1; i < exceptions.length; i++) { bpatel@766: htmltree.addContent(","); bpatel@766: htmltree.addContent(DocletConstants.NL); bpatel@766: htmltree.addContent(indent); bpatel@766: Content exceptionLink = new RawHtml(writer.getLink(new LinkInfoImpl( bpatel@766: LinkInfoImpl.CONTEXT_MEMBER, exceptions[i]))); bpatel@766: htmltree.addContent(exceptionLink); duke@1: } duke@1: } duke@1: } duke@1: duke@1: protected int getReturnTypeLength(ExecutableMemberDoc member) { duke@1: if (member instanceof MethodDoc) { duke@1: MethodDoc method = (MethodDoc)member; duke@1: Type rettype = method.returnType(); duke@1: if (rettype.isPrimitive()) { duke@1: return rettype.typeName().length() + duke@1: rettype.dimension().length(); duke@1: } else { duke@1: LinkInfoImpl linkInfo = new LinkInfoImpl( duke@1: LinkInfoImpl.CONTEXT_MEMBER, rettype); duke@1: writer.getLink(linkInfo); duke@1: return linkInfo.displayLength; duke@1: } duke@1: } else { // it's a constructordoc duke@1: return -1; duke@1: } duke@1: } duke@1: duke@1: protected ClassDoc implementsMethodInIntfac(MethodDoc method, duke@1: ClassDoc[] intfacs) { duke@1: for (int i = 0; i < intfacs.length; i++) { duke@1: MethodDoc[] methods = intfacs[i].methods(); duke@1: if (methods.length > 0) { duke@1: for (int j = 0; j < methods.length; j++) { duke@1: if (methods[j].name().equals(method.name()) && duke@1: methods[j].signature().equals(method.signature())) { duke@1: return intfacs[i]; duke@1: } duke@1: } duke@1: } duke@1: } duke@1: return null; duke@1: } duke@1: duke@1: /** duke@1: * For backward compatibility, include an anchor using the erasures of the duke@1: * parameters. NOTE: We won't need this method anymore after we fix duke@1: * see tags so that they use the type instead of the erasure. duke@1: * duke@1: * @param emd the ExecutableMemberDoc to anchor to. duke@1: * @return the 1.4.x style anchor for the ExecutableMemberDoc. duke@1: */ duke@1: protected String getErasureAnchor(ExecutableMemberDoc emd) { duke@1: StringBuffer buf = new StringBuffer(emd.name() + "("); duke@1: Parameter[] params = emd.parameters(); duke@1: boolean foundTypeVariable = false; duke@1: for (int i = 0; i < params.length; i++) { duke@1: if (i > 0) { duke@1: buf.append(","); duke@1: } duke@1: Type t = params[i].type(); duke@1: foundTypeVariable = foundTypeVariable || t.asTypeVariable() != null; duke@1: buf.append(t.isPrimitive() ? duke@1: t.typeName() : t.asClassDoc().qualifiedName()); duke@1: buf.append(t.dimension()); duke@1: } duke@1: buf.append(")"); duke@1: return foundTypeVariable ? buf.toString() : null; duke@1: } duke@1: }