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 2003-2008 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;
29 import com.sun.javadoc.*;
31 import com.sun.tools.javac.code.Kinds;
32 import com.sun.tools.javac.code.Symbol;
33 import com.sun.tools.javac.code.Symbol.ClassSymbol;
34 import com.sun.tools.javac.code.Symbol.MethodSymbol;
35 import com.sun.tools.javac.code.Type;
36 import com.sun.tools.javac.code.Type.TypeVar;
37 import com.sun.tools.javac.util.List;
38 import com.sun.tools.javac.util.Name;
39 import com.sun.tools.javac.util.Names;
41 /**
42 * Implementation of <code>TypeVariable</code>, which
43 * represents a type variable.
44 *
45 * @author Scott Seligman
46 * @since 1.5
47 */
48 public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
50 TypeVariableImpl(DocEnv env, TypeVar type) {
51 super(env, type);
52 }
54 /**
55 * Return the bounds of this type variable.
56 */
57 public com.sun.javadoc.Type[] bounds() {
58 return TypeMaker.getTypes(env, getBounds((TypeVar)type, env));
59 }
61 /**
62 * Return the class, interface, method, or constructor within
63 * which this type variable is declared.
64 */
65 public ProgramElementDoc owner() {
66 Symbol osym = type.tsym.owner;
67 if ((osym.kind & Kinds.TYP) != 0) {
68 return env.getClassDoc((ClassSymbol)osym);
69 }
70 Names names = osym.name.table.names;
71 if (osym.name == names.init) {
72 return env.getConstructorDoc((MethodSymbol)osym);
73 } else {
74 return env.getMethodDoc((MethodSymbol)osym);
75 }
76 }
78 /**
79 * Return the ClassDoc of the erasure of this type variable.
80 */
81 public ClassDoc asClassDoc() {
82 return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
83 }
85 public TypeVariable asTypeVariable() {
86 return this;
87 }
89 public String toString() {
90 return typeVarToString(env, (TypeVar)type, true);
91 }
94 /**
95 * Return the string form of a type variable along with any
96 * "extends" clause. Class names are qualified if "full" is true.
97 */
98 static String typeVarToString(DocEnv env, TypeVar v, boolean full) {
99 StringBuffer s = new StringBuffer(v.toString());
100 List<Type> bounds = getBounds(v, env);
101 if (bounds.nonEmpty()) {
102 boolean first = true;
103 for (Type b : bounds) {
104 s.append(first ? " extends " : " & ");
105 s.append(TypeMaker.getTypeString(env, b, full));
106 first = false;
107 }
108 }
109 return s.toString();
110 }
112 /**
113 * Get the bounds of a type variable as listed in the "extends" clause.
114 */
115 private static List<Type> getBounds(TypeVar v, DocEnv env) {
116 Name boundname = v.getUpperBound().tsym.getQualifiedName();
117 if (boundname == boundname.table.names.java_lang_Object) {
118 return List.nil();
119 } else {
120 return env.types.getBounds(v);
121 }
122 }
123 }