Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.tools.javadoc; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.lang.reflect.Modifier; |
aoqi@0 | 29 | import java.text.CollationKey; |
aoqi@0 | 30 | |
aoqi@0 | 31 | import com.sun.javadoc.*; |
aoqi@0 | 32 | import com.sun.source.util.TreePath; |
aoqi@0 | 33 | import com.sun.tools.javac.code.Attribute; |
aoqi@0 | 34 | import com.sun.tools.javac.code.Symbol; |
aoqi@0 | 35 | import com.sun.tools.javac.code.Symbol.ClassSymbol; |
aoqi@0 | 36 | import com.sun.tools.javac.tree.JCTree; |
aoqi@0 | 37 | import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; |
aoqi@0 | 38 | import com.sun.tools.javac.util.Position; |
aoqi@0 | 39 | |
aoqi@0 | 40 | /** |
aoqi@0 | 41 | * Represents a java program element: class, interface, field, |
aoqi@0 | 42 | * constructor, or method. |
aoqi@0 | 43 | * This is an abstract class dealing with information common to |
aoqi@0 | 44 | * these elements. |
aoqi@0 | 45 | * |
aoqi@0 | 46 | * <p><b>This is NOT part of any supported API. |
aoqi@0 | 47 | * If you write code that depends on this, you do so at your own risk. |
aoqi@0 | 48 | * This code and its internal interfaces are subject to change or |
aoqi@0 | 49 | * deletion without notice.</b> |
aoqi@0 | 50 | * |
aoqi@0 | 51 | * @see MemberDocImpl |
aoqi@0 | 52 | * @see ClassDocImpl |
aoqi@0 | 53 | * |
aoqi@0 | 54 | * @author Robert Field |
aoqi@0 | 55 | * @author Neal Gafter (rewrite) |
aoqi@0 | 56 | * @author Scott Seligman (generics, enums, annotations) |
aoqi@0 | 57 | */ |
aoqi@0 | 58 | public abstract class ProgramElementDocImpl |
aoqi@0 | 59 | extends DocImpl implements ProgramElementDoc { |
aoqi@0 | 60 | |
aoqi@0 | 61 | private final Symbol sym; |
aoqi@0 | 62 | |
aoqi@0 | 63 | // For source position information. |
aoqi@0 | 64 | JCTree tree = null; |
aoqi@0 | 65 | Position.LineMap lineMap = null; |
aoqi@0 | 66 | |
aoqi@0 | 67 | |
aoqi@0 | 68 | // Cache for getModifiers(). |
aoqi@0 | 69 | private int modifiers = -1; |
aoqi@0 | 70 | |
aoqi@0 | 71 | protected ProgramElementDocImpl(DocEnv env, Symbol sym, TreePath treePath) { |
aoqi@0 | 72 | super(env, treePath); |
aoqi@0 | 73 | this.sym = sym; |
aoqi@0 | 74 | if (treePath != null) { |
aoqi@0 | 75 | tree = (JCTree) treePath.getLeaf(); |
aoqi@0 | 76 | lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap; |
aoqi@0 | 77 | } |
aoqi@0 | 78 | } |
aoqi@0 | 79 | |
aoqi@0 | 80 | @Override |
aoqi@0 | 81 | void setTreePath(TreePath treePath) { |
aoqi@0 | 82 | super.setTreePath(treePath); |
aoqi@0 | 83 | this.tree = (JCTree) treePath.getLeaf(); |
aoqi@0 | 84 | this.lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap; |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | /** |
aoqi@0 | 88 | * Subclasses override to identify the containing class |
aoqi@0 | 89 | */ |
aoqi@0 | 90 | protected abstract ClassSymbol getContainingClass(); |
aoqi@0 | 91 | |
aoqi@0 | 92 | /** |
aoqi@0 | 93 | * Returns the flags in terms of javac's flags |
aoqi@0 | 94 | */ |
aoqi@0 | 95 | abstract protected long getFlags(); |
aoqi@0 | 96 | |
aoqi@0 | 97 | /** |
aoqi@0 | 98 | * Returns the modifier flags in terms of java.lang.reflect.Modifier. |
aoqi@0 | 99 | */ |
aoqi@0 | 100 | protected int getModifiers() { |
aoqi@0 | 101 | if (modifiers == -1) { |
aoqi@0 | 102 | modifiers = DocEnv.translateModifiers(getFlags()); |
aoqi@0 | 103 | } |
aoqi@0 | 104 | return modifiers; |
aoqi@0 | 105 | } |
aoqi@0 | 106 | |
aoqi@0 | 107 | /** |
aoqi@0 | 108 | * Get the containing class of this program element. |
aoqi@0 | 109 | * |
aoqi@0 | 110 | * @return a ClassDocImpl for this element's containing class. |
aoqi@0 | 111 | * If this is a class with no outer class, return null. |
aoqi@0 | 112 | */ |
aoqi@0 | 113 | public ClassDoc containingClass() { |
aoqi@0 | 114 | if (getContainingClass() == null) { |
aoqi@0 | 115 | return null; |
aoqi@0 | 116 | } |
aoqi@0 | 117 | return env.getClassDoc(getContainingClass()); |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | /** |
aoqi@0 | 121 | * Return the package that this member is contained in. |
aoqi@0 | 122 | * Return "" if in unnamed package. |
aoqi@0 | 123 | */ |
aoqi@0 | 124 | public PackageDoc containingPackage() { |
aoqi@0 | 125 | return env.getPackageDoc(getContainingClass().packge()); |
aoqi@0 | 126 | } |
aoqi@0 | 127 | |
aoqi@0 | 128 | /** |
aoqi@0 | 129 | * Get the modifier specifier integer. |
aoqi@0 | 130 | * |
aoqi@0 | 131 | * @see java.lang.reflect.Modifier |
aoqi@0 | 132 | */ |
aoqi@0 | 133 | public int modifierSpecifier() { |
aoqi@0 | 134 | int modifiers = getModifiers(); |
aoqi@0 | 135 | if (isMethod() && containingClass().isInterface()) |
aoqi@0 | 136 | // Remove the implicit abstract modifier. |
aoqi@0 | 137 | return modifiers & ~Modifier.ABSTRACT; |
aoqi@0 | 138 | return modifiers; |
aoqi@0 | 139 | } |
aoqi@0 | 140 | |
aoqi@0 | 141 | /** |
aoqi@0 | 142 | * Get modifiers string. |
aoqi@0 | 143 | * <pre> |
aoqi@0 | 144 | * Example, for: |
aoqi@0 | 145 | * public abstract int foo() { ... } |
aoqi@0 | 146 | * modifiers() would return: |
aoqi@0 | 147 | * 'public abstract' |
aoqi@0 | 148 | * </pre> |
aoqi@0 | 149 | * Annotations are not included. |
aoqi@0 | 150 | */ |
aoqi@0 | 151 | public String modifiers() { |
aoqi@0 | 152 | int modifiers = getModifiers(); |
aoqi@0 | 153 | if (isAnnotationTypeElement() || |
aoqi@0 | 154 | (isMethod() && containingClass().isInterface())) { |
aoqi@0 | 155 | // Remove the implicit abstract modifier. |
aoqi@0 | 156 | return Modifier.toString(modifiers & ~Modifier.ABSTRACT); |
aoqi@0 | 157 | } else { |
aoqi@0 | 158 | return Modifier.toString(modifiers); |
aoqi@0 | 159 | } |
aoqi@0 | 160 | } |
aoqi@0 | 161 | |
aoqi@0 | 162 | /** |
aoqi@0 | 163 | * Get the annotations of this program element. |
aoqi@0 | 164 | * Return an empty array if there are none. |
aoqi@0 | 165 | */ |
aoqi@0 | 166 | public AnnotationDesc[] annotations() { |
aoqi@0 | 167 | AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()]; |
aoqi@0 | 168 | int i = 0; |
aoqi@0 | 169 | for (Attribute.Compound a : sym.getRawAttributes()) { |
aoqi@0 | 170 | res[i++] = new AnnotationDescImpl(env, a); |
aoqi@0 | 171 | } |
aoqi@0 | 172 | return res; |
aoqi@0 | 173 | } |
aoqi@0 | 174 | |
aoqi@0 | 175 | /** |
aoqi@0 | 176 | * Return true if this program element is public |
aoqi@0 | 177 | */ |
aoqi@0 | 178 | public boolean isPublic() { |
aoqi@0 | 179 | int modifiers = getModifiers(); |
aoqi@0 | 180 | return Modifier.isPublic(modifiers); |
aoqi@0 | 181 | } |
aoqi@0 | 182 | |
aoqi@0 | 183 | /** |
aoqi@0 | 184 | * Return true if this program element is protected |
aoqi@0 | 185 | */ |
aoqi@0 | 186 | public boolean isProtected() { |
aoqi@0 | 187 | int modifiers = getModifiers(); |
aoqi@0 | 188 | return Modifier.isProtected(modifiers); |
aoqi@0 | 189 | } |
aoqi@0 | 190 | |
aoqi@0 | 191 | /** |
aoqi@0 | 192 | * Return true if this program element is private |
aoqi@0 | 193 | */ |
aoqi@0 | 194 | public boolean isPrivate() { |
aoqi@0 | 195 | int modifiers = getModifiers(); |
aoqi@0 | 196 | return Modifier.isPrivate(modifiers); |
aoqi@0 | 197 | } |
aoqi@0 | 198 | |
aoqi@0 | 199 | /** |
aoqi@0 | 200 | * Return true if this program element is package private |
aoqi@0 | 201 | */ |
aoqi@0 | 202 | public boolean isPackagePrivate() { |
aoqi@0 | 203 | return !(isPublic() || isPrivate() || isProtected()); |
aoqi@0 | 204 | } |
aoqi@0 | 205 | |
aoqi@0 | 206 | /** |
aoqi@0 | 207 | * Return true if this program element is static |
aoqi@0 | 208 | */ |
aoqi@0 | 209 | public boolean isStatic() { |
aoqi@0 | 210 | int modifiers = getModifiers(); |
aoqi@0 | 211 | return Modifier.isStatic(modifiers); |
aoqi@0 | 212 | } |
aoqi@0 | 213 | |
aoqi@0 | 214 | /** |
aoqi@0 | 215 | * Return true if this program element is final |
aoqi@0 | 216 | */ |
aoqi@0 | 217 | public boolean isFinal() { |
aoqi@0 | 218 | int modifiers = getModifiers(); |
aoqi@0 | 219 | return Modifier.isFinal(modifiers); |
aoqi@0 | 220 | } |
aoqi@0 | 221 | |
aoqi@0 | 222 | /** |
aoqi@0 | 223 | * Generate a key for sorting. |
aoqi@0 | 224 | */ |
aoqi@0 | 225 | CollationKey generateKey() { |
aoqi@0 | 226 | String k = name(); |
aoqi@0 | 227 | // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\""); |
aoqi@0 | 228 | return env.doclocale.collator.getCollationKey(k); |
aoqi@0 | 229 | } |
aoqi@0 | 230 | |
aoqi@0 | 231 | } |