001: /*
002: * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.javadoc;
027:
028: import com.sun.javadoc.*;
029:
030: import com.sun.tools.javac.code.Attribute;
031: import com.sun.tools.javac.code.Symbol.VarSymbol;
032: import com.sun.tools.javac.code.Type;
033:
034: /**
035: * ParameterImpl information.
036: * This includes a parameter type and parameter name.
037: *
038: * @author Kaiyang Liu (original)
039: * @author Robert Field (rewrite)
040: * @author Scott Seligman (generics, annotations)
041: */
042: class ParameterImpl implements Parameter {
043:
044: private final DocEnv env;
045: private final VarSymbol sym;
046: private final com.sun.javadoc.Type type;
047:
048: /**
049: * Constructor of parameter info class.
050: */
051: ParameterImpl(DocEnv env, VarSymbol sym) {
052: this .env = env;
053: this .sym = sym;
054: this .type = TypeMaker.getType(env, sym.type, false);
055: }
056:
057: /**
058: * Get the type of this parameter.
059: */
060: public com.sun.javadoc.Type type() {
061: return type;
062: }
063:
064: /**
065: * Get local name of this parameter.
066: * For example if parameter is the short 'index', returns "index".
067: */
068: public String name() {
069: return sym.toString();
070: }
071:
072: /**
073: * Get type name of this parameter.
074: * For example if parameter is the short 'index', returns "short".
075: */
076: public String typeName() {
077: return (type instanceof ClassDoc || type instanceof TypeVariable) ? type
078: .typeName() // omit formal type params or bounds
079: : type.toString();
080: }
081:
082: /**
083: * Returns a string representation of the parameter.
084: * <p>
085: * For example if parameter is the short 'index', returns "short index".
086: *
087: * @return type name and parameter name of this parameter.
088: */
089: public String toString() {
090: return typeName() + " " + sym;
091: }
092:
093: /**
094: * Get the annotations of this parameter.
095: * Return an empty array if there are none.
096: */
097: public AnnotationDesc[] annotations() {
098: AnnotationDesc res[] = new AnnotationDesc[sym
099: .getAnnotationMirrors().length()];
100: int i = 0;
101: for (Attribute.Compound a : sym.getAnnotationMirrors()) {
102: res[i++] = new AnnotationDescImpl(env, a);
103: }
104: return res;
105: }
106: }
|