duke@1: /* jjg@1521: * Copyright (c) 1997, 2013, 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.javadoc; duke@1: jjg@197: import java.lang.reflect.Modifier; jjg@197: import java.text.CollationKey; jjg@197: jjg@1521: import javax.lang.model.type.TypeKind; jjg@1521: duke@1: import com.sun.javadoc.*; duke@1: jjg@1443: import com.sun.source.util.TreePath; jjg@1521: import com.sun.tools.javac.code.Attribute; jjg@197: import com.sun.tools.javac.code.Flags; jjg@1521: import com.sun.tools.javac.code.Attribute.Compound; jjg@197: import com.sun.tools.javac.code.Symbol.*; jjg@197: import com.sun.tools.javac.code.Type; duke@1: import com.sun.tools.javac.util.List; duke@1: import com.sun.tools.javac.util.ListBuffer; duke@1: duke@1: /** duke@1: * Represents a method or constructor of a java class. duke@1: * jjg@1359: *
This is NOT part of any supported API.
jjg@1359: * If you write code that depends on this, you do so at your own risk.
jjg@1359: * This code and its internal interfaces are subject to change or
jjg@1359: * deletion without notice.
jjg@1359: *
duke@1: * @since 1.2
duke@1: * @author Robert Field
duke@1: * @author Neal Gafter (rewrite)
duke@1: * @author Scott Seligman (generics, annotations)
duke@1: */
duke@1:
duke@1: public abstract class ExecutableMemberDocImpl
duke@1: extends MemberDocImpl implements ExecutableMemberDoc {
duke@1:
duke@1: protected final MethodSymbol sym;
duke@1:
duke@1: /**
duke@1: * Constructor.
duke@1: */
jjg@1443: public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
jjg@1443: super(env, sym, treePath);
duke@1: this.sym = sym;
duke@1: }
duke@1:
duke@1: /**
duke@1: * Constructor.
duke@1: */
duke@1: public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym) {
jjg@1443: this(env, sym, null);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Returns the flags in terms of javac's flags
duke@1: */
duke@1: protected long getFlags() {
duke@1: return sym.flags();
duke@1: }
duke@1:
duke@1: /**
duke@1: * Identify the containing class
duke@1: */
duke@1: protected ClassSymbol getContainingClass() {
duke@1: return sym.enclClass();
duke@1: }
duke@1:
duke@1: /**
duke@1: * Return true if this method is native
duke@1: */
duke@1: public boolean isNative() {
duke@1: return Modifier.isNative(getModifiers());
duke@1: }
duke@1:
duke@1: /**
duke@1: * Return true if this method is synchronized
duke@1: */
duke@1: public boolean isSynchronized() {
duke@1: return Modifier.isSynchronized(getModifiers());
duke@1: }
duke@1:
duke@1: /**
duke@1: * Return true if this method was declared to take a variable number
duke@1: * of arguments.
duke@1: */
duke@1: public boolean isVarArgs() {
duke@1: return ((sym.flags() & Flags.VARARGS) != 0
duke@1: && !env.legacyDoclet);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Returns true if this field was synthesized by the compiler.
duke@1: */
duke@1: public boolean isSynthetic() {
duke@1: return ((sym.flags() & Flags.SYNTHETIC) != 0);
duke@1: }
duke@1:
duke@1: public boolean isIncluded() {
duke@1: return containingClass().isIncluded() && env.shouldDocument(sym);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Return the throws tags in this method.
duke@1: *
duke@1: * @return an array of ThrowTagImpl containing all {@code @exception}
duke@1: * and {@code @throws} tags.
duke@1: */
duke@1: public ThrowsTag[] throwsTags() {
duke@1: return comment().throwsTags();
duke@1: }
duke@1:
duke@1: /**
duke@1: * Return the param tags in this method, excluding the type
duke@1: * parameter tags.
duke@1: *
duke@1: * @return an array of ParamTagImpl containing all {@code @param} tags.
duke@1: */
duke@1: public ParamTag[] paramTags() {
duke@1: return comment().paramTags();
duke@1: }
duke@1:
duke@1: /**
duke@1: * Return the type parameter tags in this method.
duke@1: */
duke@1: public ParamTag[] typeParamTags() {
duke@1: return env.legacyDoclet
duke@1: ? new ParamTag[0]
duke@1: : comment().typeParamTags();
duke@1: }
duke@1:
duke@1: /**
duke@1: * Return exceptions this method or constructor throws.
duke@1: *
duke@1: * @return an array of ClassDoc[] representing the exceptions
duke@1: * thrown by this method.
duke@1: */
duke@1: public ClassDoc[] thrownExceptions() {
duke@1: ListBufferClassDoc
or a
duke@1: * TypeVariable
.
duke@1: */
duke@1: public com.sun.javadoc.Type[] thrownExceptionTypes() {
duke@1: return TypeMaker.getTypes(env, sym.type.getThrownTypes());
duke@1: }
duke@1:
duke@1: /**
duke@1: * Get argument information.
duke@1: *
duke@1: * @see ParameterImpl
duke@1: *
duke@1: * @return an array of ParameterImpl, one element per argument
duke@1: * in the order the arguments are present.
duke@1: */
duke@1: public Parameter[] parameters() {
duke@1: // generate the parameters on the fly: they're not cached
duke@1: Listmymethod(String x, int y)
,
duke@1: * it will return (java.lang.String,int)
.
duke@1: */
duke@1: public String signature() {
duke@1: return makeSignature(true);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Get flat signature. All types are not qualified.
duke@1: * Return a String, which is the flat signiture of this member.
duke@1: * It is the parameter list, type is not qualified.
duke@1: * For instance, for a method mymethod(String x, int y)
,
duke@1: * it will return (String, int)
.
duke@1: */
duke@1: public String flatSignature() {
duke@1: return makeSignature(false);
duke@1: }
duke@1:
duke@1: private String makeSignature(boolean full) {
jjg@910: StringBuilder result = new StringBuilder();
duke@1: result.append("(");
duke@1: for (List