Tue, 11 Aug 2009 01:13:14 +0100
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
Summary: javac should warn/complain about identifiers with the same name as synthetic symbol
Reviewed-by: jjg
1 /*
2 * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
26 package com.sun.tools.javadoc;
28 import com.sun.javadoc.*;
30 import com.sun.tools.javac.code.Attribute;
31 import com.sun.tools.javac.code.Symbol.VarSymbol;
32 import com.sun.tools.javac.code.Type;
34 /**
35 * ParameterImpl information.
36 * This includes a parameter type and parameter name.
37 *
38 * @author Kaiyang Liu (original)
39 * @author Robert Field (rewrite)
40 * @author Scott Seligman (generics, annotations)
41 */
42 class ParameterImpl implements Parameter {
44 private final DocEnv env;
45 private final VarSymbol sym;
46 private final com.sun.javadoc.Type type;
48 /**
49 * Constructor of parameter info class.
50 */
51 ParameterImpl(DocEnv env, VarSymbol sym) {
52 this.env = env;
53 this.sym = sym;
54 this.type = TypeMaker.getType(env, sym.type, false);
55 }
57 /**
58 * Get the type of this parameter.
59 */
60 public com.sun.javadoc.Type type() {
61 return type;
62 }
64 /**
65 * Get local name of this parameter.
66 * For example if parameter is the short 'index', returns "index".
67 */
68 public String name() {
69 return sym.toString();
70 }
72 /**
73 * Get type name of this parameter.
74 * For example if parameter is the short 'index', returns "short".
75 */
76 public String typeName() {
77 return (type instanceof ClassDoc || type instanceof TypeVariable)
78 ? type.typeName() // omit formal type params or bounds
79 : type.toString();
80 }
82 /**
83 * Returns a string representation of the parameter.
84 * <p>
85 * For example if parameter is the short 'index', returns "short index".
86 *
87 * @return type name and parameter name of this parameter.
88 */
89 public String toString() {
90 return typeName() + " " + sym;
91 }
93 /**
94 * Get the annotations of this parameter.
95 * Return an empty array if there are none.
96 */
97 public AnnotationDesc[] annotations() {
98 AnnotationDesc res[] = new AnnotationDesc[sym.getAnnotationMirrors().length()];
99 int i = 0;
100 for (Attribute.Compound a : sym.getAnnotationMirrors()) {
101 res[i++] = new AnnotationDescImpl(env, a);
102 }
103 return res;
104 }
105 }