0N/A/*
553N/A * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
553N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
553N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.tools.javadoc;
0N/A
0N/Aimport com.sun.javadoc.*;
0N/A
0N/Aimport com.sun.tools.javac.code.Attribute;
0N/Aimport com.sun.tools.javac.code.Flags;
0N/Aimport com.sun.tools.javac.code.Symbol;
0N/Aimport com.sun.tools.javac.code.Symbol.ClassSymbol;
0N/A
0N/Aimport com.sun.tools.javac.tree.JCTree;
0N/A
0N/Aimport com.sun.tools.javac.util.Position;
0N/A
0N/Aimport java.lang.reflect.Modifier;
0N/Aimport java.text.CollationKey;
0N/A
0N/A/**
0N/A * Represents a java program element: class, interface, field,
0N/A * constructor, or method.
0N/A * This is an abstract class dealing with information common to
0N/A * these elements.
0N/A *
0N/A * @see MemberDocImpl
0N/A * @see ClassDocImpl
0N/A *
0N/A * @author Robert Field
0N/A * @author Neal Gafter (rewrite)
0N/A * @author Scott Seligman (generics, enums, annotations)
0N/A */
0N/Apublic abstract class ProgramElementDocImpl
0N/A extends DocImpl implements ProgramElementDoc {
0N/A
0N/A private final Symbol sym;
0N/A
0N/A // For source position information.
0N/A JCTree tree = null;
0N/A Position.LineMap lineMap = null;
0N/A
0N/A
0N/A // Cache for getModifiers().
0N/A private int modifiers = -1;
0N/A
0N/A protected ProgramElementDocImpl(DocEnv env, Symbol sym,
0N/A String doc, JCTree tree, Position.LineMap lineMap) {
0N/A super(env, doc);
0N/A this.sym = sym;
0N/A this.tree = tree;
0N/A this.lineMap = lineMap;
0N/A }
0N/A
0N/A void setTree(JCTree tree) {
0N/A this.tree = tree;
0N/A }
0N/A
0N/A /**
0N/A * Subclasses override to identify the containing class
0N/A */
0N/A protected abstract ClassSymbol getContainingClass();
0N/A
0N/A /**
0N/A * Returns the flags in terms of javac's flags
0N/A */
0N/A abstract protected long getFlags();
0N/A
0N/A /**
0N/A * Returns the modifier flags in terms of java.lang.reflect.Modifier.
0N/A */
0N/A protected int getModifiers() {
0N/A if (modifiers == -1) {
0N/A modifiers = DocEnv.translateModifiers(getFlags());
0N/A }
0N/A return modifiers;
0N/A }
0N/A
0N/A /**
0N/A * Get the containing class of this program element.
0N/A *
0N/A * @return a ClassDocImpl for this element's containing class.
0N/A * If this is a class with no outer class, return null.
0N/A */
0N/A public ClassDoc containingClass() {
0N/A if (getContainingClass() == null) {
0N/A return null;
0N/A }
0N/A return env.getClassDoc(getContainingClass());
0N/A }
0N/A
0N/A /**
0N/A * Return the package that this member is contained in.
0N/A * Return "" if in unnamed package.
0N/A */
0N/A public PackageDoc containingPackage() {
0N/A return env.getPackageDoc(getContainingClass().packge());
0N/A }
0N/A
0N/A /**
0N/A * Get the modifier specifier integer.
0N/A *
0N/A * @see java.lang.reflect.Modifier
0N/A */
0N/A public int modifierSpecifier() {
0N/A int modifiers = getModifiers();
0N/A if (isMethod() && containingClass().isInterface())
0N/A // Remove the implicit abstract modifier.
0N/A return modifiers & ~Modifier.ABSTRACT;
0N/A return modifiers;
0N/A }
0N/A
0N/A /**
0N/A * Get modifiers string.
0N/A * <pre>
0N/A * Example, for:
0N/A * public abstract int foo() { ... }
0N/A * modifiers() would return:
0N/A * 'public abstract'
0N/A * </pre>
0N/A * Annotations are not included.
0N/A */
0N/A public String modifiers() {
0N/A int modifiers = getModifiers();
0N/A if (isAnnotationTypeElement() ||
0N/A (isMethod() && containingClass().isInterface())) {
0N/A // Remove the implicit abstract modifier.
0N/A return Modifier.toString(modifiers & ~Modifier.ABSTRACT);
0N/A } else {
0N/A return Modifier.toString(modifiers);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Get the annotations of this program element.
0N/A * Return an empty array if there are none.
0N/A */
0N/A public AnnotationDesc[] annotations() {
0N/A AnnotationDesc res[] = new AnnotationDesc[sym.getAnnotationMirrors().length()];
0N/A int i = 0;
0N/A for (Attribute.Compound a : sym.getAnnotationMirrors()) {
0N/A res[i++] = new AnnotationDescImpl(env, a);
0N/A }
0N/A return res;
0N/A }
0N/A
0N/A /**
0N/A * Return true if this program element is public
0N/A */
0N/A public boolean isPublic() {
0N/A int modifiers = getModifiers();
0N/A return Modifier.isPublic(modifiers);
0N/A }
0N/A
0N/A /**
0N/A * Return true if this program element is protected
0N/A */
0N/A public boolean isProtected() {
0N/A int modifiers = getModifiers();
0N/A return Modifier.isProtected(modifiers);
0N/A }
0N/A
0N/A /**
0N/A * Return true if this program element is private
0N/A */
0N/A public boolean isPrivate() {
0N/A int modifiers = getModifiers();
0N/A return Modifier.isPrivate(modifiers);
0N/A }
0N/A
0N/A /**
0N/A * Return true if this program element is package private
0N/A */
0N/A public boolean isPackagePrivate() {
0N/A return !(isPublic() || isPrivate() || isProtected());
0N/A }
0N/A
0N/A /**
0N/A * Return true if this program element is static
0N/A */
0N/A public boolean isStatic() {
0N/A int modifiers = getModifiers();
0N/A return Modifier.isStatic(modifiers);
0N/A }
0N/A
0N/A /**
0N/A * Return true if this program element is final
0N/A */
0N/A public boolean isFinal() {
0N/A int modifiers = getModifiers();
0N/A return Modifier.isFinal(modifiers);
0N/A }
0N/A
0N/A /**
0N/A * Generate a key for sorting.
0N/A */
0N/A CollationKey generateKey() {
0N/A String k = name();
0N/A // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");
0N/A return env.doclocale.collator.getCollationKey(k);
0N/A }
0N/A
0N/A}