src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java

Thu, 15 Nov 2012 09:18:36 -0800

author
jjg
date
Thu, 15 Nov 2012 09:18:36 -0800
changeset 1410
bfec2a1cc869
parent 1359
25e14ad23cef
child 1443
cfde9737131e
permissions
-rw-r--r--

8000800: javadoc uses static non-final fields
Reviewed-by: bpatel

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

mercurial