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;
28 import com.sun.javadoc.*;
31 import com.sun.tools.javac.code.Kinds;
32 import com.sun.tools.javac.code.Scope;
33 import com.sun.tools.javac.code.Symbol.*;
34 import com.sun.tools.javac.tree.JCTree.*;
35 import com.sun.tools.javac.util.List;
36 import com.sun.tools.javac.util.Names;
37 import com.sun.tools.javac.util.Position;
39 /**
40 * Represents an annotation type.
41 *
42 * @author Scott Seligman
43 * @since 1.5
44 */
46 public class AnnotationTypeDocImpl
47 extends ClassDocImpl implements AnnotationTypeDoc {
49 AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym) {
50 this(env, sym, null, null, null);
51 }
53 AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym,
54 String doc, JCClassDecl tree, Position.LineMap lineMap) {
55 super(env, sym, doc, tree, lineMap);
56 }
58 /**
59 * Returns true, as this is an annotation type.
60 * (For legacy doclets, return false.)
61 */
62 public boolean isAnnotationType() {
63 return !isInterface();
64 }
66 /**
67 * Returns false. Though technically an interface, an annotation
68 * type is not considered an interface for this purpose.
69 * (For legacy doclets, returns true.)
70 */
71 public boolean isInterface() {
72 return env.legacyDoclet;
73 }
75 /**
76 * Returns an empty array, as all methods are annotation type elements.
77 * (For legacy doclets, returns the elements.)
78 * @see #elements()
79 */
80 public MethodDoc[] methods(boolean filter) {
81 return env.legacyDoclet
82 ? (MethodDoc[])elements()
83 : new MethodDoc[0];
84 }
86 /**
87 * Returns the elements of this annotation type.
88 * Returns an empty array if there are none.
89 * Elements are always public, so no need to filter them.
90 */
91 public AnnotationTypeElementDoc[] elements() {
92 Names names = tsym.name.table.names;
93 List<AnnotationTypeElementDoc> elements = List.nil();
94 for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) {
95 if (e.sym != null && e.sym.kind == Kinds.MTH) {
96 MethodSymbol s = (MethodSymbol)e.sym;
97 elements = elements.prepend(env.getAnnotationTypeElementDoc(s));
98 }
99 }
100 return
101 elements.toArray(new AnnotationTypeElementDoc[elements.length()]);
102 }
103 }