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

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

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

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

duke@1 1 /*
jjg@1357 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javadoc;
duke@1 27
jjg@1357 28 import java.lang.reflect.Modifier;
jjg@1357 29
duke@1 30 import com.sun.javadoc.*;
duke@1 31 import com.sun.tools.javac.code.*;
duke@1 32 import com.sun.tools.javac.code.Symbol.*;
duke@1 33 import com.sun.tools.javac.code.Type;
duke@1 34 import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
duke@1 35 import com.sun.tools.javac.util.Position;
duke@1 36
jjg@1374 37 import static com.sun.tools.javac.code.TypeTag.CLASS;
jjg@1374 38
duke@1 39 /**
duke@1 40 * Represents a method of a java class.
duke@1 41 *
jjg@1359 42 * <p><b>This is NOT part of any supported API.
jjg@1359 43 * If you write code that depends on this, you do so at your own risk.
jjg@1359 44 * This code and its internal interfaces are subject to change or
jjg@1359 45 * deletion without notice.</b>
jjg@1359 46 *
duke@1 47 * @since 1.2
duke@1 48 * @author Robert Field
duke@1 49 * @author Neal Gafter (rewrite)
duke@1 50 */
duke@1 51
duke@1 52 public class MethodDocImpl
duke@1 53 extends ExecutableMemberDocImpl implements MethodDoc {
duke@1 54
duke@1 55 /**
duke@1 56 * constructor.
duke@1 57 */
duke@1 58 public MethodDocImpl(DocEnv env, MethodSymbol sym) {
duke@1 59 super(env, sym);
duke@1 60 }
duke@1 61
duke@1 62 /**
duke@1 63 * constructor.
duke@1 64 */
duke@1 65 public MethodDocImpl(DocEnv env, MethodSymbol sym,
duke@1 66 String docComment, JCMethodDecl tree, Position.LineMap lineMap) {
duke@1 67 super(env, sym, docComment, tree, lineMap);
duke@1 68 }
duke@1 69
duke@1 70 /**
duke@1 71 * Return true if it is a method, which it is.
duke@1 72 * Note: constructors are not methods.
duke@1 73 * This method is overridden by AnnotationTypeElementDocImpl.
duke@1 74 *
duke@1 75 * @return true
duke@1 76 */
duke@1 77 public boolean isMethod() {
duke@1 78 return true;
duke@1 79 }
duke@1 80
duke@1 81 /**
duke@1 82 * Return true if this method is abstract
duke@1 83 */
duke@1 84 public boolean isAbstract() {
duke@1 85 //### This is dubious, but old 'javadoc' apparently does it.
duke@1 86 //### I regard this as a bug and an obstacle to treating the
duke@1 87 //### doclet API as a proper compile-time reflection facility.
duke@1 88 //### (maddox 09/26/2000)
duke@1 89 if (containingClass().isInterface()) {
duke@1 90 //### Don't force creation of ClassDocImpl for super here.
duke@1 91 // Abstract modifier is implicit. Strip/canonicalize it.
duke@1 92 return false;
duke@1 93 }
duke@1 94 return Modifier.isAbstract(getModifiers());
duke@1 95 }
duke@1 96
duke@1 97 /**
duke@1 98 * Get return type.
duke@1 99 *
duke@1 100 * @return the return type of this method, null if it
duke@1 101 * is a constructor.
duke@1 102 */
duke@1 103 public com.sun.javadoc.Type returnType() {
duke@1 104 return TypeMaker.getType(env, sym.type.getReturnType(), false);
duke@1 105 }
duke@1 106
duke@1 107 /**
duke@1 108 * Return the class that originally defined the method that
duke@1 109 * is overridden by the current definition, or null if no
duke@1 110 * such class exists.
duke@1 111 *
duke@1 112 * @return a ClassDocImpl representing the superclass that
duke@1 113 * originally defined this method, null if this method does
duke@1 114 * not override a definition in a superclass.
duke@1 115 */
duke@1 116 public ClassDoc overriddenClass() {
duke@1 117 com.sun.javadoc.Type t = overriddenType();
duke@1 118 return (t != null) ? t.asClassDoc() : null;
duke@1 119 }
duke@1 120
duke@1 121 /**
duke@1 122 * Return the type containing the method that this method overrides.
duke@1 123 * It may be a <code>ClassDoc</code> or a <code>ParameterizedType</code>.
duke@1 124 */
duke@1 125 public com.sun.javadoc.Type overriddenType() {
duke@1 126
duke@1 127 if ((sym.flags() & Flags.STATIC) != 0) {
duke@1 128 return null;
duke@1 129 }
duke@1 130
duke@1 131 ClassSymbol origin = (ClassSymbol)sym.owner;
duke@1 132 for (Type t = env.types.supertype(origin.type);
jjg@1374 133 t.hasTag(CLASS);
duke@1 134 t = env.types.supertype(t)) {
duke@1 135 ClassSymbol c = (ClassSymbol)t.tsym;
duke@1 136 for (Scope.Entry e = c.members().lookup(sym.name); e.scope != null; e = e.next()) {
duke@1 137 if (sym.overrides(e.sym, origin, env.types, true)) {
duke@1 138 return TypeMaker.getType(env, t);
duke@1 139 }
duke@1 140 }
duke@1 141 }
duke@1 142 return null;
duke@1 143 }
duke@1 144
duke@1 145 /**
duke@1 146 * Return the method that this method overrides.
duke@1 147 *
duke@1 148 * @return a MethodDoc representing a method definition
duke@1 149 * in a superclass this method overrides, null if
duke@1 150 * this method does not override.
duke@1 151 */
duke@1 152 public MethodDoc overriddenMethod() {
duke@1 153
duke@1 154 // Real overriding only. Static members are simply hidden.
duke@1 155 // Likewise for constructors, but the MethodSymbol.overrides
duke@1 156 // method takes this into account.
duke@1 157 if ((sym.flags() & Flags.STATIC) != 0) {
duke@1 158 return null;
duke@1 159 }
duke@1 160
duke@1 161 // Derived from com.sun.tools.javac.comp.Check.checkOverride .
duke@1 162
duke@1 163 ClassSymbol origin = (ClassSymbol)sym.owner;
duke@1 164 for (Type t = env.types.supertype(origin.type);
jjg@1374 165 t.hasTag(CLASS);
duke@1 166 t = env.types.supertype(t)) {
duke@1 167 ClassSymbol c = (ClassSymbol)t.tsym;
duke@1 168 for (Scope.Entry e = c.members().lookup(sym.name); e.scope != null; e = e.next()) {
duke@1 169 if (sym.overrides(e.sym, origin, env.types, true)) {
duke@1 170 return env.getMethodDoc((MethodSymbol)e.sym);
duke@1 171 }
duke@1 172 }
duke@1 173 }
duke@1 174 return null;
duke@1 175 }
duke@1 176
duke@1 177 /**
duke@1 178 * Tests whether this method overrides another.
duke@1 179 * The overridden method may be one declared in a superclass or
duke@1 180 * a superinterface (unlike {@link #overriddenMethod()}).
duke@1 181 *
duke@1 182 * <p> When a non-abstract method overrides an abstract one, it is
duke@1 183 * also said to <i>implement</i> the other.
duke@1 184 *
duke@1 185 * @param meth the other method to examine
duke@1 186 * @return <tt>true</tt> if this method overrides the other
duke@1 187 */
duke@1 188 public boolean overrides(MethodDoc meth) {
duke@1 189 MethodSymbol overridee = ((MethodDocImpl) meth).sym;
duke@1 190 ClassSymbol origin = (ClassSymbol) sym.owner;
duke@1 191
duke@1 192 return sym.name == overridee.name &&
duke@1 193
duke@1 194 // not reflexive as per JLS
duke@1 195 sym != overridee &&
duke@1 196
duke@1 197 // we don't care if overridee is static, though that wouldn't
duke@1 198 // compile
duke@1 199 !sym.isStatic() &&
duke@1 200
duke@1 201 // sym, whose declaring type is the origin, must be
duke@1 202 // in a subtype of overridee's type
duke@1 203 env.types.asSuper(origin.type, overridee.owner) != null &&
duke@1 204
duke@1 205 // check access and signatures; don't check return types
duke@1 206 sym.overrides(overridee, origin, env.types, false);
duke@1 207 }
duke@1 208
duke@1 209
duke@1 210 public String name() {
duke@1 211 return sym.name.toString();
duke@1 212 }
duke@1 213
duke@1 214 public String qualifiedName() {
duke@1 215 return sym.enclClass().getQualifiedName() + "." + sym.name;
duke@1 216 }
duke@1 217
duke@1 218 /**
duke@1 219 * Returns a string representation of this method. Includes the
duke@1 220 * qualified signature, the qualified method name, and any type
duke@1 221 * parameters. Type parameters follow the class name, as they do
duke@1 222 * in the syntax for invoking methods with explicit type parameters.
duke@1 223 */
duke@1 224 public String toString() {
duke@1 225 return sym.enclClass().getQualifiedName() +
duke@1 226 "." + typeParametersString() + name() + signature();
duke@1 227 }
duke@1 228 }

mercurial