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

Mon, 25 Mar 2013 16:55:14 -0700

author
mfang
date
Mon, 25 Mar 2013 16:55:14 -0700
changeset 1658
fdf30b225e1c
parent 1476
0e17c3c23e3b
child 1706
95d29b99e5b3
permissions
-rw-r--r--

8010521: jdk8 l10n resource file translation update 2
Reviewed-by: naoto, yhuang

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.*;
jjg@1443 31 import com.sun.source.util.TreePath;
duke@1 32 import com.sun.tools.javac.code.*;
duke@1 33 import com.sun.tools.javac.code.Symbol.*;
duke@1 34 import com.sun.tools.javac.code.Type;
jjg@1374 35 import static com.sun.tools.javac.code.TypeTag.CLASS;
jjg@1374 36
duke@1 37 /**
duke@1 38 * Represents a method of a java class.
duke@1 39 *
jjg@1359 40 * <p><b>This is NOT part of any supported API.
jjg@1359 41 * If you write code that depends on this, you do so at your own risk.
jjg@1359 42 * This code and its internal interfaces are subject to change or
jjg@1359 43 * deletion without notice.</b>
jjg@1359 44 *
duke@1 45 * @since 1.2
duke@1 46 * @author Robert Field
duke@1 47 * @author Neal Gafter (rewrite)
duke@1 48 */
duke@1 49
duke@1 50 public class MethodDocImpl
duke@1 51 extends ExecutableMemberDocImpl implements MethodDoc {
duke@1 52
duke@1 53 /**
duke@1 54 * constructor.
duke@1 55 */
duke@1 56 public MethodDocImpl(DocEnv env, MethodSymbol sym) {
duke@1 57 super(env, sym);
duke@1 58 }
duke@1 59
duke@1 60 /**
duke@1 61 * constructor.
duke@1 62 */
jjg@1443 63 public MethodDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
jjg@1443 64 super(env, sym, treePath);
duke@1 65 }
duke@1 66
duke@1 67 /**
duke@1 68 * Return true if it is a method, which it is.
duke@1 69 * Note: constructors are not methods.
duke@1 70 * This method is overridden by AnnotationTypeElementDocImpl.
duke@1 71 *
duke@1 72 * @return true
duke@1 73 */
duke@1 74 public boolean isMethod() {
duke@1 75 return true;
duke@1 76 }
duke@1 77
duke@1 78 /**
vromero@1454 79 * Return true if this method is default
vromero@1454 80 */
vromero@1454 81 public boolean isDefault() {
vromero@1454 82 return (sym.flags() & Flags.DEFAULT) != 0;
vromero@1454 83 }
vromero@1454 84
vromero@1454 85 /**
duke@1 86 * Return true if this method is abstract
duke@1 87 */
duke@1 88 public boolean isAbstract() {
bpatel@1476 89 return (Modifier.isAbstract(getModifiers()) && !isDefault());
duke@1 90 }
duke@1 91
duke@1 92 /**
duke@1 93 * Get return type.
duke@1 94 *
duke@1 95 * @return the return type of this method, null if it
duke@1 96 * is a constructor.
duke@1 97 */
duke@1 98 public com.sun.javadoc.Type returnType() {
duke@1 99 return TypeMaker.getType(env, sym.type.getReturnType(), false);
duke@1 100 }
duke@1 101
duke@1 102 /**
duke@1 103 * Return the class that originally defined the method that
duke@1 104 * is overridden by the current definition, or null if no
duke@1 105 * such class exists.
duke@1 106 *
duke@1 107 * @return a ClassDocImpl representing the superclass that
duke@1 108 * originally defined this method, null if this method does
duke@1 109 * not override a definition in a superclass.
duke@1 110 */
duke@1 111 public ClassDoc overriddenClass() {
duke@1 112 com.sun.javadoc.Type t = overriddenType();
duke@1 113 return (t != null) ? t.asClassDoc() : null;
duke@1 114 }
duke@1 115
duke@1 116 /**
duke@1 117 * Return the type containing the method that this method overrides.
duke@1 118 * It may be a <code>ClassDoc</code> or a <code>ParameterizedType</code>.
duke@1 119 */
duke@1 120 public com.sun.javadoc.Type overriddenType() {
duke@1 121
duke@1 122 if ((sym.flags() & Flags.STATIC) != 0) {
duke@1 123 return null;
duke@1 124 }
duke@1 125
duke@1 126 ClassSymbol origin = (ClassSymbol)sym.owner;
duke@1 127 for (Type t = env.types.supertype(origin.type);
jjg@1374 128 t.hasTag(CLASS);
duke@1 129 t = env.types.supertype(t)) {
duke@1 130 ClassSymbol c = (ClassSymbol)t.tsym;
duke@1 131 for (Scope.Entry e = c.members().lookup(sym.name); e.scope != null; e = e.next()) {
duke@1 132 if (sym.overrides(e.sym, origin, env.types, true)) {
duke@1 133 return TypeMaker.getType(env, t);
duke@1 134 }
duke@1 135 }
duke@1 136 }
duke@1 137 return null;
duke@1 138 }
duke@1 139
duke@1 140 /**
duke@1 141 * Return the method that this method overrides.
duke@1 142 *
duke@1 143 * @return a MethodDoc representing a method definition
duke@1 144 * in a superclass this method overrides, null if
duke@1 145 * this method does not override.
duke@1 146 */
duke@1 147 public MethodDoc overriddenMethod() {
duke@1 148
duke@1 149 // Real overriding only. Static members are simply hidden.
duke@1 150 // Likewise for constructors, but the MethodSymbol.overrides
duke@1 151 // method takes this into account.
duke@1 152 if ((sym.flags() & Flags.STATIC) != 0) {
duke@1 153 return null;
duke@1 154 }
duke@1 155
duke@1 156 // Derived from com.sun.tools.javac.comp.Check.checkOverride .
duke@1 157
duke@1 158 ClassSymbol origin = (ClassSymbol)sym.owner;
duke@1 159 for (Type t = env.types.supertype(origin.type);
jjg@1374 160 t.hasTag(CLASS);
duke@1 161 t = env.types.supertype(t)) {
duke@1 162 ClassSymbol c = (ClassSymbol)t.tsym;
duke@1 163 for (Scope.Entry e = c.members().lookup(sym.name); e.scope != null; e = e.next()) {
duke@1 164 if (sym.overrides(e.sym, origin, env.types, true)) {
duke@1 165 return env.getMethodDoc((MethodSymbol)e.sym);
duke@1 166 }
duke@1 167 }
duke@1 168 }
duke@1 169 return null;
duke@1 170 }
duke@1 171
duke@1 172 /**
duke@1 173 * Tests whether this method overrides another.
duke@1 174 * The overridden method may be one declared in a superclass or
duke@1 175 * a superinterface (unlike {@link #overriddenMethod()}).
duke@1 176 *
duke@1 177 * <p> When a non-abstract method overrides an abstract one, it is
duke@1 178 * also said to <i>implement</i> the other.
duke@1 179 *
duke@1 180 * @param meth the other method to examine
duke@1 181 * @return <tt>true</tt> if this method overrides the other
duke@1 182 */
duke@1 183 public boolean overrides(MethodDoc meth) {
duke@1 184 MethodSymbol overridee = ((MethodDocImpl) meth).sym;
duke@1 185 ClassSymbol origin = (ClassSymbol) sym.owner;
duke@1 186
duke@1 187 return sym.name == overridee.name &&
duke@1 188
duke@1 189 // not reflexive as per JLS
duke@1 190 sym != overridee &&
duke@1 191
duke@1 192 // we don't care if overridee is static, though that wouldn't
duke@1 193 // compile
duke@1 194 !sym.isStatic() &&
duke@1 195
duke@1 196 // sym, whose declaring type is the origin, must be
duke@1 197 // in a subtype of overridee's type
duke@1 198 env.types.asSuper(origin.type, overridee.owner) != null &&
duke@1 199
duke@1 200 // check access and signatures; don't check return types
duke@1 201 sym.overrides(overridee, origin, env.types, false);
duke@1 202 }
duke@1 203
duke@1 204
duke@1 205 public String name() {
duke@1 206 return sym.name.toString();
duke@1 207 }
duke@1 208
duke@1 209 public String qualifiedName() {
duke@1 210 return sym.enclClass().getQualifiedName() + "." + sym.name;
duke@1 211 }
duke@1 212
duke@1 213 /**
duke@1 214 * Returns a string representation of this method. Includes the
duke@1 215 * qualified signature, the qualified method name, and any type
duke@1 216 * parameters. Type parameters follow the class name, as they do
duke@1 217 * in the syntax for invoking methods with explicit type parameters.
duke@1 218 */
duke@1 219 public String toString() {
duke@1 220 return sym.enclClass().getQualifiedName() +
duke@1 221 "." + typeParametersString() + name() + signature();
duke@1 222 }
duke@1 223 }

mercurial