Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java
38899 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.javadoc;2627import java.lang.reflect.Modifier;28import java.text.CollationKey;2930import com.sun.javadoc.*;3132import com.sun.source.util.TreePath;33import com.sun.tools.javac.code.Flags;34import com.sun.tools.javac.code.Symbol.*;35import com.sun.tools.javac.code.Type;36import com.sun.tools.javac.util.List;37import com.sun.tools.javac.util.ListBuffer;3839/**40* Represents a method or constructor of a java class.41*42* <p><b>This is NOT part of any supported API.43* If you write code that depends on this, you do so at your own risk.44* This code and its internal interfaces are subject to change or45* deletion without notice.</b>46*47* @since 1.248* @author Robert Field49* @author Neal Gafter (rewrite)50* @author Scott Seligman (generics, annotations)51*/5253public abstract class ExecutableMemberDocImpl54extends MemberDocImpl implements ExecutableMemberDoc {5556protected final MethodSymbol sym;5758/**59* Constructor.60*/61public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {62super(env, sym, treePath);63this.sym = sym;64}6566/**67* Constructor.68*/69public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym) {70this(env, sym, null);71}7273/**74* Returns the flags in terms of javac's flags75*/76protected long getFlags() {77return sym.flags();78}7980/**81* Identify the containing class82*/83protected ClassSymbol getContainingClass() {84return sym.enclClass();85}8687/**88* Return true if this method is native89*/90public boolean isNative() {91return Modifier.isNative(getModifiers());92}9394/**95* Return true if this method is synchronized96*/97public boolean isSynchronized() {98return Modifier.isSynchronized(getModifiers());99}100101/**102* Return true if this method was declared to take a variable number103* of arguments.104*/105public boolean isVarArgs() {106return ((sym.flags() & Flags.VARARGS) != 0107&& !env.legacyDoclet);108}109110/**111* Returns true if this field was synthesized by the compiler.112*/113public boolean isSynthetic() {114return ((sym.flags() & Flags.SYNTHETIC) != 0);115}116117public boolean isIncluded() {118return containingClass().isIncluded() && env.shouldDocument(sym);119}120121/**122* Return the throws tags in this method.123*124* @return an array of ThrowTagImpl containing all {@code @exception}125* and {@code @throws} tags.126*/127public ThrowsTag[] throwsTags() {128return comment().throwsTags();129}130131/**132* Return the param tags in this method, excluding the type133* parameter tags.134*135* @return an array of ParamTagImpl containing all {@code @param} tags.136*/137public ParamTag[] paramTags() {138return comment().paramTags();139}140141/**142* Return the type parameter tags in this method.143*/144public ParamTag[] typeParamTags() {145return env.legacyDoclet146? new ParamTag[0]147: comment().typeParamTags();148}149150/**151* Return exceptions this method or constructor throws.152*153* @return an array of ClassDoc[] representing the exceptions154* thrown by this method.155*/156public ClassDoc[] thrownExceptions() {157ListBuffer<ClassDocImpl> l = new ListBuffer<ClassDocImpl>();158for (Type ex : sym.type.getThrownTypes()) {159ex = env.types.erasure(ex);160//### Will these casts succeed in the face of static semantic161//### errors in the documented code?162ClassDocImpl cdi = env.getClassDoc((ClassSymbol)ex.tsym);163if (cdi != null) l.append(cdi);164}165return l.toArray(new ClassDocImpl[l.length()]);166}167168/**169* Return exceptions this method or constructor throws.170* Each array element is either a <code>ClassDoc</code> or a171* <code>TypeVariable</code>.172*/173public com.sun.javadoc.Type[] thrownExceptionTypes() {174return TypeMaker.getTypes(env, sym.type.getThrownTypes());175}176177/**178* Get argument information.179*180* @see ParameterImpl181*182* @return an array of ParameterImpl, one element per argument183* in the order the arguments are present.184*/185public Parameter[] parameters() {186// generate the parameters on the fly: they're not cached187List<VarSymbol> params = sym.params();188Parameter result[] = new Parameter[params.length()];189190int i = 0;191for (VarSymbol param : params) {192result[i++] = new ParameterImpl(env, param);193}194return result;195}196197/**198* Get the receiver type of this executable element.199*200* @return the receiver type of this executable element.201* @since 1.8202*/203public com.sun.javadoc.Type receiverType() {204Type recvtype = sym.type.asMethodType().recvtype;205return (recvtype != null) ? TypeMaker.getType(env, recvtype, false, true) : null;206}207208/**209* Return the formal type parameters of this method or constructor.210* Return an empty array if there are none.211*/212public TypeVariable[] typeParameters() {213if (env.legacyDoclet) {214return new TypeVariable[0];215}216TypeVariable res[] = new TypeVariable[sym.type.getTypeArguments().length()];217TypeMaker.getTypes(env, sym.type.getTypeArguments(), res);218return res;219}220221/**222* Get the signature. It is the parameter list, type is qualified.223* For instance, for a method <code>mymethod(String x, int y)</code>,224* it will return <code>(java.lang.String,int)</code>.225*/226public String signature() {227return makeSignature(true);228}229230/**231* Get flat signature. All types are not qualified.232* Return a String, which is the flat signiture of this member.233* It is the parameter list, type is not qualified.234* For instance, for a method <code>mymethod(String x, int y)</code>,235* it will return <code>(String, int)</code>.236*/237public String flatSignature() {238return makeSignature(false);239}240241private String makeSignature(boolean full) {242StringBuilder result = new StringBuilder();243result.append("(");244for (List<Type> types = sym.type.getParameterTypes(); types.nonEmpty(); ) {245Type t = types.head;246result.append(TypeMaker.getTypeString(env, t, full));247types = types.tail;248if (types.nonEmpty()) {249result.append(", ");250}251}252if (isVarArgs()) {253int len = result.length();254result.replace(len - 2, len, "...");255}256result.append(")");257return result.toString();258}259260protected String typeParametersString() {261return TypeMaker.typeParametersString(env, sym, true);262}263264/**265* Generate a key for sorting.266*/267@Override268CollationKey generateKey() {269String k = name() + flatSignature() + typeParametersString();270// ',' and '&' are between '$' and 'a': normalize to spaces.271k = k.replace(',', ' ').replace('&', ' ');272// System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");273return env.doclocale.collator.getCollationKey(k);274}275276/**277* Return the source position of the entity, or null if278* no position is available.279*/280@Override281public SourcePosition position() {282if (sym.enclClass().sourcefile == null) return null;283return SourcePositionImpl.make(sym.enclClass().sourcefile,284(tree==null) ? 0 : tree.pos,285lineMap);286}287}288289290