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

Wed, 10 Oct 2012 16:48:21 -0700

author
jjg
date
Wed, 10 Oct 2012 16:48:21 -0700
changeset 1359
25e14ad23cef
parent 1357
c75be5bc5283
child 1443
cfde9737131e
permissions
-rw-r--r--

8000665: fix "internal API" comments on javadoc files
Reviewed-by: darcy

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 import java.text.CollationKey;
jjg@1357 30
duke@1 31 import com.sun.javadoc.*;
duke@1 32 import com.sun.tools.javac.code.Attribute;
duke@1 33 import com.sun.tools.javac.code.Symbol;
duke@1 34 import com.sun.tools.javac.code.Symbol.ClassSymbol;
duke@1 35 import com.sun.tools.javac.tree.JCTree;
duke@1 36 import com.sun.tools.javac.util.Position;
duke@1 37
duke@1 38 /**
duke@1 39 * Represents a java program element: class, interface, field,
duke@1 40 * constructor, or method.
duke@1 41 * This is an abstract class dealing with information common to
duke@1 42 * these elements.
duke@1 43 *
jjg@1359 44 * <p><b>This is NOT part of any supported API.
jjg@1359 45 * If you write code that depends on this, you do so at your own risk.
jjg@1359 46 * This code and its internal interfaces are subject to change or
jjg@1359 47 * deletion without notice.</b>
jjg@1359 48 *
duke@1 49 * @see MemberDocImpl
duke@1 50 * @see ClassDocImpl
duke@1 51 *
duke@1 52 * @author Robert Field
duke@1 53 * @author Neal Gafter (rewrite)
duke@1 54 * @author Scott Seligman (generics, enums, annotations)
duke@1 55 */
duke@1 56 public abstract class ProgramElementDocImpl
duke@1 57 extends DocImpl implements ProgramElementDoc {
duke@1 58
duke@1 59 private final Symbol sym;
duke@1 60
duke@1 61 // For source position information.
duke@1 62 JCTree tree = null;
duke@1 63 Position.LineMap lineMap = null;
duke@1 64
duke@1 65
duke@1 66 // Cache for getModifiers().
duke@1 67 private int modifiers = -1;
duke@1 68
duke@1 69 protected ProgramElementDocImpl(DocEnv env, Symbol sym,
duke@1 70 String doc, JCTree tree, Position.LineMap lineMap) {
duke@1 71 super(env, doc);
duke@1 72 this.sym = sym;
duke@1 73 this.tree = tree;
duke@1 74 this.lineMap = lineMap;
duke@1 75 }
duke@1 76
duke@1 77 void setTree(JCTree tree) {
duke@1 78 this.tree = tree;
duke@1 79 }
duke@1 80
duke@1 81 /**
duke@1 82 * Subclasses override to identify the containing class
duke@1 83 */
duke@1 84 protected abstract ClassSymbol getContainingClass();
duke@1 85
duke@1 86 /**
duke@1 87 * Returns the flags in terms of javac's flags
duke@1 88 */
duke@1 89 abstract protected long getFlags();
duke@1 90
duke@1 91 /**
duke@1 92 * Returns the modifier flags in terms of java.lang.reflect.Modifier.
duke@1 93 */
duke@1 94 protected int getModifiers() {
duke@1 95 if (modifiers == -1) {
duke@1 96 modifiers = DocEnv.translateModifiers(getFlags());
duke@1 97 }
duke@1 98 return modifiers;
duke@1 99 }
duke@1 100
duke@1 101 /**
duke@1 102 * Get the containing class of this program element.
duke@1 103 *
duke@1 104 * @return a ClassDocImpl for this element's containing class.
duke@1 105 * If this is a class with no outer class, return null.
duke@1 106 */
duke@1 107 public ClassDoc containingClass() {
duke@1 108 if (getContainingClass() == null) {
duke@1 109 return null;
duke@1 110 }
duke@1 111 return env.getClassDoc(getContainingClass());
duke@1 112 }
duke@1 113
duke@1 114 /**
duke@1 115 * Return the package that this member is contained in.
duke@1 116 * Return "" if in unnamed package.
duke@1 117 */
duke@1 118 public PackageDoc containingPackage() {
duke@1 119 return env.getPackageDoc(getContainingClass().packge());
duke@1 120 }
duke@1 121
duke@1 122 /**
duke@1 123 * Get the modifier specifier integer.
duke@1 124 *
duke@1 125 * @see java.lang.reflect.Modifier
duke@1 126 */
duke@1 127 public int modifierSpecifier() {
duke@1 128 int modifiers = getModifiers();
duke@1 129 if (isMethod() && containingClass().isInterface())
duke@1 130 // Remove the implicit abstract modifier.
duke@1 131 return modifiers & ~Modifier.ABSTRACT;
duke@1 132 return modifiers;
duke@1 133 }
duke@1 134
duke@1 135 /**
duke@1 136 * Get modifiers string.
duke@1 137 * <pre>
duke@1 138 * Example, for:
duke@1 139 * public abstract int foo() { ... }
duke@1 140 * modifiers() would return:
duke@1 141 * 'public abstract'
duke@1 142 * </pre>
duke@1 143 * Annotations are not included.
duke@1 144 */
duke@1 145 public String modifiers() {
duke@1 146 int modifiers = getModifiers();
duke@1 147 if (isAnnotationTypeElement() ||
duke@1 148 (isMethod() && containingClass().isInterface())) {
duke@1 149 // Remove the implicit abstract modifier.
duke@1 150 return Modifier.toString(modifiers & ~Modifier.ABSTRACT);
duke@1 151 } else {
duke@1 152 return Modifier.toString(modifiers);
duke@1 153 }
duke@1 154 }
duke@1 155
duke@1 156 /**
duke@1 157 * Get the annotations of this program element.
duke@1 158 * Return an empty array if there are none.
duke@1 159 */
duke@1 160 public AnnotationDesc[] annotations() {
duke@1 161 AnnotationDesc res[] = new AnnotationDesc[sym.getAnnotationMirrors().length()];
duke@1 162 int i = 0;
duke@1 163 for (Attribute.Compound a : sym.getAnnotationMirrors()) {
duke@1 164 res[i++] = new AnnotationDescImpl(env, a);
duke@1 165 }
duke@1 166 return res;
duke@1 167 }
duke@1 168
duke@1 169 /**
duke@1 170 * Return true if this program element is public
duke@1 171 */
duke@1 172 public boolean isPublic() {
duke@1 173 int modifiers = getModifiers();
duke@1 174 return Modifier.isPublic(modifiers);
duke@1 175 }
duke@1 176
duke@1 177 /**
duke@1 178 * Return true if this program element is protected
duke@1 179 */
duke@1 180 public boolean isProtected() {
duke@1 181 int modifiers = getModifiers();
duke@1 182 return Modifier.isProtected(modifiers);
duke@1 183 }
duke@1 184
duke@1 185 /**
duke@1 186 * Return true if this program element is private
duke@1 187 */
duke@1 188 public boolean isPrivate() {
duke@1 189 int modifiers = getModifiers();
duke@1 190 return Modifier.isPrivate(modifiers);
duke@1 191 }
duke@1 192
duke@1 193 /**
duke@1 194 * Return true if this program element is package private
duke@1 195 */
duke@1 196 public boolean isPackagePrivate() {
duke@1 197 return !(isPublic() || isPrivate() || isProtected());
duke@1 198 }
duke@1 199
duke@1 200 /**
duke@1 201 * Return true if this program element is static
duke@1 202 */
duke@1 203 public boolean isStatic() {
duke@1 204 int modifiers = getModifiers();
duke@1 205 return Modifier.isStatic(modifiers);
duke@1 206 }
duke@1 207
duke@1 208 /**
duke@1 209 * Return true if this program element is final
duke@1 210 */
duke@1 211 public boolean isFinal() {
duke@1 212 int modifiers = getModifiers();
duke@1 213 return Modifier.isFinal(modifiers);
duke@1 214 }
duke@1 215
duke@1 216 /**
duke@1 217 * Generate a key for sorting.
duke@1 218 */
duke@1 219 CollationKey generateKey() {
duke@1 220 String k = name();
duke@1 221 // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");
duke@1 222 return env.doclocale.collator.getCollationKey(k);
duke@1 223 }
duke@1 224
duke@1 225 }

mercurial