src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractExecutableMemberWriter.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 21,37 **** * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package com.sun.tools.doclets.formats.html; ! import com.sun.javadoc.*; ! import com.sun.tools.doclets.formats.html.markup.*; ! import com.sun.tools.doclets.internal.toolkit.*; ! import com.sun.tools.doclets.internal.toolkit.util.*; /** * Print method and constructor info. * * <p><b>This is NOT part of any supported API. * If you write code that depends on this, you do so at your own risk. --- 21,55 ---- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package jdk.javadoc.internal.doclets.formats.html; ! import java.util.List; + import javax.lang.model.element.AnnotationMirror; + import javax.lang.model.element.Element; + import javax.lang.model.element.ElementKind; + import javax.lang.model.element.ExecutableElement; + import javax.lang.model.element.TypeElement; + import javax.lang.model.element.VariableElement; + import javax.lang.model.type.ArrayType; + import javax.lang.model.type.DeclaredType; + import javax.lang.model.type.TypeMirror; + import javax.lang.model.type.TypeVariable; + import javax.lang.model.util.SimpleTypeVisitor9; + + import com.sun.tools.javac.util.DefinedBy; + import com.sun.tools.javac.util.DefinedBy.Api; + import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; + import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; + import jdk.javadoc.internal.doclets.toolkit.Content; + import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants; + + import static jdk.javadoc.internal.doclets.formats.html.LinkInfoImpl.Kind.*; + /** * Print method and constructor info. * * <p><b>This is NOT part of any supported API. * If you write code that depends on this, you do so at your own risk.
*** 42,54 **** * @author Atul M Dambalkar * @author Bhavesh Patel (Modified) */ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWriter { ! public AbstractExecutableMemberWriter(SubWriterHolderWriter writer, ! ClassDoc classdoc) { ! super(writer, classdoc); } public AbstractExecutableMemberWriter(SubWriterHolderWriter writer) { super(writer); } --- 60,71 ---- * @author Atul M Dambalkar * @author Bhavesh Patel (Modified) */ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWriter { ! public AbstractExecutableMemberWriter(SubWriterHolderWriter writer, TypeElement typeElement) { ! super(writer, typeElement); } public AbstractExecutableMemberWriter(SubWriterHolderWriter writer) { super(writer); }
*** 57,67 **** * Add the type parameters for the executable member. * * @param member the member to write type parameters for. * @param htmltree the content tree to which the parameters will be added. */ ! protected void addTypeParameters(ExecutableMemberDoc member, Content htmltree) { Content typeParameters = getTypeParameters(member); if (!typeParameters.isEmpty()) { htmltree.addContent(typeParameters); htmltree.addContent(writer.getSpace()); } --- 74,84 ---- * Add the type parameters for the executable member. * * @param member the member to write type parameters for. * @param htmltree the content tree to which the parameters will be added. */ ! protected void addTypeParameters(ExecutableElement member, Content htmltree) { Content typeParameters = getTypeParameters(member); if (!typeParameters.isEmpty()) { htmltree.addContent(typeParameters); htmltree.addContent(writer.getSpace()); }
*** 71,127 **** * Get the type parameters for the executable member. * * @param member the member for which to get the type parameters. * @return the type parameters. */ ! protected Content getTypeParameters(ExecutableMemberDoc member) { ! LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, ! LinkInfoImpl.Kind.MEMBER_TYPE_PARAMS, member); return writer.getTypeParameterLinks(linkInfo); } /** * {@inheritDoc} */ ! protected Content getDeprecatedLink(ProgramElementDoc member) { ! ExecutableMemberDoc emd = (ExecutableMemberDoc)member; ! return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, (MemberDoc) emd, ! emd.qualifiedName() + emd.flatSignature()); } /** * Add the summary link for the member. * * @param context the id of the context where the link will be printed ! * @param cd the classDoc that we should link to * @param member the member being linked to * @param tdSummary the content tree to which the link will be added */ ! protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member, Content tdSummary) { ! ExecutableMemberDoc emd = (ExecutableMemberDoc)member; ! String name = emd.name(); Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink, ! writer.getDocLink(context, cd, (MemberDoc) emd, ! name, false)); Content code = HtmlTree.CODE(memberLink); ! addParameters(emd, false, code, name.length() - 1); tdSummary.addContent(code); } /** * Add the inherited summary link for the member. * ! * @param cd the classDoc that we should link to * @param member the member being linked to * @param linksTree the content tree to which the link will be added */ ! protected void addInheritedSummaryLink(ClassDoc cd, ! ProgramElementDoc member, Content linksTree) { ! linksTree.addContent( ! writer.getDocLink(LinkInfoImpl.Kind.MEMBER, cd, (MemberDoc) member, ! member.name(), false)); } /** * Add the parameter for the executable member. * --- 88,148 ---- * Get the type parameters for the executable member. * * @param member the member for which to get the type parameters. * @return the type parameters. */ ! protected Content getTypeParameters(ExecutableElement member) { ! LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, MEMBER_TYPE_PARAMS, member); return writer.getTypeParameterLinks(linkInfo); } /** * {@inheritDoc} */ ! @Override ! protected Content getDeprecatedLink(Element member) { ! StringBuilder sb = new StringBuilder(); ! sb.append(utils.getFullyQualifiedName(member)); ! if (!utils.isConstructor(member)) { ! sb.append("."); ! sb.append(member.getSimpleName().toString()); } + sb.append(utils.flatSignature((ExecutableElement) member)); + return writer.getDocLink(MEMBER, member, sb.toString()); + } + /** * Add the summary link for the member. * * @param context the id of the context where the link will be printed ! * @param te the classDoc that we should link to * @param member the member being linked to * @param tdSummary the content tree to which the link will be added */ ! @Override ! protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement te, Element member, Content tdSummary) { ! ExecutableElement ee = (ExecutableElement)member; Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink, ! writer.getDocLink(context, te, ee, ! name(ee), false)); Content code = HtmlTree.CODE(memberLink); ! addParameters(ee, false, code, name(ee).length() - 1); tdSummary.addContent(code); } /** * Add the inherited summary link for the member. * ! * @param te the type element that we should link to * @param member the member being linked to * @param linksTree the content tree to which the link will be added */ ! @Override ! protected void addInheritedSummaryLink(TypeElement te, Element member, Content linksTree) { ! linksTree.addContent(writer.getDocLink(MEMBER, te, member, name(member), false)); } /** * Add the parameter for the executable member. *
*** 128,148 **** * @param member the member to write parameter for. * @param param the parameter that needs to be written. * @param isVarArg true if this is a link to var arg. * @param tree the content tree to which the parameter information will be added. */ ! protected void addParam(ExecutableMemberDoc member, Parameter param, boolean isVarArg, Content tree) { ! if (param.type() != null) { ! Content link = writer.getLink(new LinkInfoImpl( ! configuration, LinkInfoImpl.Kind.EXECUTABLE_MEMBER_PARAM, ! param.type()).varargs(isVarArg)); tree.addContent(link); ! } ! if(param.name().length() > 0) { tree.addContent(writer.getSpace()); ! tree.addContent(param.name()); } } /** * Add the receiver annotations information. --- 149,166 ---- * @param member the member to write parameter for. * @param param the parameter that needs to be written. * @param isVarArg true if this is a link to var arg. * @param tree the content tree to which the parameter information will be added. */ ! protected void addParam(ExecutableElement member, VariableElement param, boolean isVarArg, Content tree) { ! Content link = writer.getLink(new LinkInfoImpl(configuration, EXECUTABLE_MEMBER_PARAM, ! param.asType()).varargs(isVarArg)); tree.addContent(link); ! if(name(param).length() > 0) { tree.addContent(writer.getSpace()); ! tree.addContent(name(param)); } } /** * Add the receiver annotations information.
*** 150,166 **** * @param member the member to write receiver annotations for. * @param rcvrType the receiver type. * @param descList list of annotation description. * @param tree the content tree to which the information will be added. */ ! protected void addReceiverAnnotations(ExecutableMemberDoc member, Type rcvrType, ! AnnotationDesc[] descList, Content tree) { ! writer.addReceiverAnnotationInfo(member, descList, tree); tree.addContent(writer.getSpace()); ! tree.addContent(rcvrType.typeName()); ! LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, ! LinkInfoImpl.Kind.CLASS_SIGNATURE, rcvrType); tree.addContent(writer.getTypeParameterLinks(linkInfo)); tree.addContent(writer.getSpace()); tree.addContent("this"); } --- 168,183 ---- * @param member the member to write receiver annotations for. * @param rcvrType the receiver type. * @param descList list of annotation description. * @param tree the content tree to which the information will be added. */ ! protected void addReceiverAnnotations(ExecutableElement member, TypeMirror rcvrType, ! List<? extends AnnotationMirror> annotationMirrors, Content tree) { ! writer.addReceiverAnnotationInfo(member, rcvrType, annotationMirrors, tree); tree.addContent(writer.getSpace()); ! tree.addContent(utils.getTypeName(rcvrType, false)); ! LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, RECEIVER_TYPE, rcvrType); tree.addContent(writer.getTypeParameterLinks(linkInfo)); tree.addContent(writer.getSpace()); tree.addContent("this"); }
*** 169,179 **** * Add all the parameters for the executable member. * * @param member the member to write parameters for. * @param htmltree the content tree to which the parameters information will be added. */ ! protected void addParameters(ExecutableMemberDoc member, Content htmltree, int indentSize) { addParameters(member, true, htmltree, indentSize); } /** * Add all the parameters for the executable member. --- 186,196 ---- * Add all the parameters for the executable member. * * @param member the member to write parameters for. * @param htmltree the content tree to which the parameters information will be added. */ ! protected void addParameters(ExecutableElement member, Content htmltree, int indentSize) { addParameters(member, true, htmltree, indentSize); } /** * Add all the parameters for the executable member.
*** 180,208 **** * * @param member the member to write parameters for. * @param includeAnnotations true if annotation information needs to be added. * @param htmltree the content tree to which the parameters information will be added. */ ! protected void addParameters(ExecutableMemberDoc member, boolean includeAnnotations, Content htmltree, int indentSize) { htmltree.addContent("("); String sep = ""; ! Parameter[] params = member.parameters(); String indent = makeSpace(indentSize + 1); ! Type rcvrType = member.receiverType(); ! if (includeAnnotations && rcvrType instanceof AnnotatedType) { ! AnnotationDesc[] descList = rcvrType.asAnnotatedType().annotations(); ! if (descList.length > 0) { ! addReceiverAnnotations(member, rcvrType, descList, htmltree); sep = "," + DocletConstants.NL + indent; } - } int paramstart; ! for (paramstart = 0; paramstart < params.length; paramstart++) { htmltree.addContent(sep); ! Parameter param = params[paramstart]; ! if (!param.name().startsWith("this$")) { if (includeAnnotations) { boolean foundAnnotations = writer.addAnnotationInfo(indent.length(), member, param, htmltree); if (foundAnnotations) { --- 197,224 ---- * * @param member the member to write parameters for. * @param includeAnnotations true if annotation information needs to be added. * @param htmltree the content tree to which the parameters information will be added. */ ! protected void addParameters(ExecutableElement member, boolean includeAnnotations, Content htmltree, int indentSize) { htmltree.addContent("("); String sep = ""; ! List<? extends VariableElement> parameters = member.getParameters(); String indent = makeSpace(indentSize + 1); ! TypeMirror rcvrType = member.getReceiverType(); ! if (includeAnnotations && rcvrType != null && utils.isAnnotated(rcvrType)) { ! List<? extends AnnotationMirror> annotationMirrors = rcvrType.getAnnotationMirrors(); ! addReceiverAnnotations(member, rcvrType, annotationMirrors, htmltree); sep = "," + DocletConstants.NL + indent; } int paramstart; ! for (paramstart = 0; paramstart < parameters.size(); paramstart++) { htmltree.addContent(sep); ! VariableElement param = parameters.get(paramstart); ! ! if (param.getKind() != ElementKind.INSTANCE_INIT) { if (includeAnnotations) { boolean foundAnnotations = writer.addAnnotationInfo(indent.length(), member, param, htmltree); if (foundAnnotations) {
*** 209,237 **** htmltree.addContent(DocletConstants.NL); htmltree.addContent(indent); } } addParam(member, param, ! (paramstart == params.length - 1) && member.isVarArgs(), htmltree); break; } } ! for (int i = paramstart + 1; i < params.length; i++) { htmltree.addContent(","); htmltree.addContent(DocletConstants.NL); htmltree.addContent(indent); if (includeAnnotations) { boolean foundAnnotations = ! writer.addAnnotationInfo(indent.length(), member, params[i], htmltree); if (foundAnnotations) { htmltree.addContent(DocletConstants.NL); htmltree.addContent(indent); } } ! addParam(member, params[i], (i == params.length - 1) && member.isVarArgs(), htmltree); } htmltree.addContent(")"); } --- 225,253 ---- htmltree.addContent(DocletConstants.NL); htmltree.addContent(indent); } } addParam(member, param, ! (paramstart == parameters.size() - 1) && member.isVarArgs(), htmltree); break; } } ! for (int i = paramstart + 1; i < parameters.size(); i++) { htmltree.addContent(","); htmltree.addContent(DocletConstants.NL); htmltree.addContent(indent); if (includeAnnotations) { boolean foundAnnotations = ! writer.addAnnotationInfo(indent.length(), member, parameters.get(i), htmltree); if (foundAnnotations) { htmltree.addContent(DocletConstants.NL); htmltree.addContent(indent); } } ! addParam(member, parameters.get(i), (i == parameters.size() - 1) && member.isVarArgs(), htmltree); } htmltree.addContent(")"); }
*** 239,280 **** * Add exceptions for the executable member. * * @param member the member to write exceptions for. * @param htmltree the content tree to which the exceptions information will be added. */ ! protected void addExceptions(ExecutableMemberDoc member, Content htmltree, int indentSize) { ! Type[] exceptions = member.thrownExceptionTypes(); ! if (exceptions.length > 0) { ! LinkInfoImpl memberTypeParam = new LinkInfoImpl(configuration, ! LinkInfoImpl.Kind.MEMBER, member); String indent = makeSpace(indentSize + 1 - 7); htmltree.addContent(DocletConstants.NL); htmltree.addContent(indent); htmltree.addContent("throws "); indent = makeSpace(indentSize + 1); ! Content link = writer.getLink(new LinkInfoImpl(configuration, ! LinkInfoImpl.Kind.MEMBER, exceptions[0])); htmltree.addContent(link); ! for(int i = 1; i < exceptions.length; i++) { htmltree.addContent(","); htmltree.addContent(DocletConstants.NL); htmltree.addContent(indent); ! Content exceptionLink = writer.getLink(new LinkInfoImpl( ! configuration, LinkInfoImpl.Kind.MEMBER, exceptions[i])); htmltree.addContent(exceptionLink); } } } ! protected ClassDoc implementsMethodInIntfac(MethodDoc method, ! ClassDoc[] intfacs) { ! for (ClassDoc intf : intfacs) { ! MethodDoc[] methods = intf.methods(); ! if (methods.length > 0) { ! for (MethodDoc md : methods) { ! if (md.name().equals(method.name()) && ! md.signature().equals(method.signature())) { return intf; } } } } --- 255,293 ---- * Add exceptions for the executable member. * * @param member the member to write exceptions for. * @param htmltree the content tree to which the exceptions information will be added. */ ! protected void addExceptions(ExecutableElement member, Content htmltree, int indentSize) { ! List<? extends TypeMirror> exceptions = member.getThrownTypes(); ! if (!exceptions.isEmpty()) { String indent = makeSpace(indentSize + 1 - 7); htmltree.addContent(DocletConstants.NL); htmltree.addContent(indent); htmltree.addContent("throws "); indent = makeSpace(indentSize + 1); ! Content link = writer.getLink(new LinkInfoImpl(configuration, MEMBER, exceptions.get(0))); htmltree.addContent(link); ! for(int i = 1; i < exceptions.size(); i++) { htmltree.addContent(","); htmltree.addContent(DocletConstants.NL); htmltree.addContent(indent); ! Content exceptionLink = writer.getLink(new LinkInfoImpl(configuration, MEMBER, ! exceptions.get(i))); htmltree.addContent(exceptionLink); } } } ! protected TypeElement implementsMethodInIntfac(ExecutableElement method, ! List<TypeElement> intfacs) { ! for (TypeElement intf : intfacs) { ! List<ExecutableElement> methods = utils.getMethods(intf); ! if (!methods.isEmpty()) { ! for (ExecutableElement md : methods) { ! if (name(md).equals(name(method)) && ! md.toString().equals(method.toString())) { return intf; } } } }
*** 284,309 **** /** * For backward compatibility, include an anchor using the erasures of the * parameters. NOTE: We won't need this method anymore after we fix * see tags so that they use the type instead of the erasure. * ! * @param emd the ExecutableMemberDoc to anchor to. ! * @return the 1.4.x style anchor for the ExecutableMemberDoc. */ ! protected String getErasureAnchor(ExecutableMemberDoc emd) { ! StringBuilder buf = new StringBuilder(emd.name() + "("); ! Parameter[] params = emd.parameters(); boolean foundTypeVariable = false; ! for (int i = 0; i < params.length; i++) { if (i > 0) { buf.append(","); } ! Type t = params[i].type(); ! foundTypeVariable = foundTypeVariable || t.asTypeVariable() != null; ! buf.append(t.isPrimitive() ? ! t.typeName() : t.asClassDoc().qualifiedName()); ! buf.append(t.dimension()); } buf.append(")"); return foundTypeVariable ? writer.getName(buf.toString()) : null; } } --- 297,352 ---- /** * For backward compatibility, include an anchor using the erasures of the * parameters. NOTE: We won't need this method anymore after we fix * see tags so that they use the type instead of the erasure. * ! * @param executableElement the ExecutableElement to anchor to. ! * @return the 1.4.x style anchor for the executable element. */ ! protected String getErasureAnchor(ExecutableElement executableElement) { ! final StringBuilder buf = new StringBuilder(name(executableElement) + "("); ! List<? extends VariableElement> parameters = executableElement.getParameters(); boolean foundTypeVariable = false; ! for (int i = 0; i < parameters.size(); i++) { if (i > 0) { buf.append(","); } ! TypeMirror t = parameters.get(i).asType(); ! SimpleTypeVisitor9<Boolean, Void> stv = new SimpleTypeVisitor9<Boolean, Void>() { ! boolean foundTypeVariable = false; ! ! @Override @DefinedBy(Api.LANGUAGE_MODEL) ! public Boolean visitArray(ArrayType t, Void p) { ! visit(t.getComponentType()); ! buf.append(utils.getDimension(t)); ! return foundTypeVariable; } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public Boolean visitTypeVariable(TypeVariable t, Void p) { + buf.append(utils.asTypeElement(t).getQualifiedName()); + foundTypeVariable = true; + return foundTypeVariable; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public Boolean visitDeclared(DeclaredType t, Void p) { + buf.append(utils.getQualifiedTypeName(t)); + return foundTypeVariable; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + protected Boolean defaultAction(TypeMirror e, Void p) { + buf.append(e.toString()); + return foundTypeVariable; + } + }; + + boolean isTypeVariable = stv.visit(t); + if (!foundTypeVariable) { + foundTypeVariable = isTypeVariable; + } + } buf.append(")"); return foundTypeVariable ? writer.getName(buf.toString()) : null; } }