Thu, 12 Jan 2012 15:28:34 +0000
7123100: javac fails with java.lang.StackOverflowError
Summary: Inference of under-constrained type-variables creates erroneous recursive wildcard types
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.javadoc; |
duke@1 | 27 | |
duke@1 | 28 | import com.sun.javadoc.*; |
duke@1 | 29 | |
duke@1 | 30 | import com.sun.tools.javac.code.Attribute; |
duke@1 | 31 | import com.sun.tools.javac.code.Flags; |
duke@1 | 32 | import com.sun.tools.javac.code.Symbol; |
duke@1 | 33 | import com.sun.tools.javac.code.Symbol.ClassSymbol; |
duke@1 | 34 | |
duke@1 | 35 | import com.sun.tools.javac.tree.JCTree; |
duke@1 | 36 | |
duke@1 | 37 | import com.sun.tools.javac.util.Position; |
duke@1 | 38 | |
duke@1 | 39 | import java.lang.reflect.Modifier; |
duke@1 | 40 | import java.text.CollationKey; |
duke@1 | 41 | |
duke@1 | 42 | /** |
duke@1 | 43 | * Represents a java program element: class, interface, field, |
duke@1 | 44 | * constructor, or method. |
duke@1 | 45 | * This is an abstract class dealing with information common to |
duke@1 | 46 | * these elements. |
duke@1 | 47 | * |
duke@1 | 48 | * @see MemberDocImpl |
duke@1 | 49 | * @see ClassDocImpl |
duke@1 | 50 | * |
duke@1 | 51 | * @author Robert Field |
duke@1 | 52 | * @author Neal Gafter (rewrite) |
duke@1 | 53 | * @author Scott Seligman (generics, enums, annotations) |
duke@1 | 54 | */ |
duke@1 | 55 | public abstract class ProgramElementDocImpl |
duke@1 | 56 | extends DocImpl implements ProgramElementDoc { |
duke@1 | 57 | |
duke@1 | 58 | private final Symbol sym; |
duke@1 | 59 | |
duke@1 | 60 | // For source position information. |
duke@1 | 61 | JCTree tree = null; |
duke@1 | 62 | Position.LineMap lineMap = null; |
duke@1 | 63 | |
duke@1 | 64 | |
duke@1 | 65 | // Cache for getModifiers(). |
duke@1 | 66 | private int modifiers = -1; |
duke@1 | 67 | |
duke@1 | 68 | protected ProgramElementDocImpl(DocEnv env, Symbol sym, |
duke@1 | 69 | String doc, JCTree tree, Position.LineMap lineMap) { |
duke@1 | 70 | super(env, doc); |
duke@1 | 71 | this.sym = sym; |
duke@1 | 72 | this.tree = tree; |
duke@1 | 73 | this.lineMap = lineMap; |
duke@1 | 74 | } |
duke@1 | 75 | |
duke@1 | 76 | void setTree(JCTree tree) { |
duke@1 | 77 | this.tree = tree; |
duke@1 | 78 | } |
duke@1 | 79 | |
duke@1 | 80 | /** |
duke@1 | 81 | * Subclasses override to identify the containing class |
duke@1 | 82 | */ |
duke@1 | 83 | protected abstract ClassSymbol getContainingClass(); |
duke@1 | 84 | |
duke@1 | 85 | /** |
duke@1 | 86 | * Returns the flags in terms of javac's flags |
duke@1 | 87 | */ |
duke@1 | 88 | abstract protected long getFlags(); |
duke@1 | 89 | |
duke@1 | 90 | /** |
duke@1 | 91 | * Returns the modifier flags in terms of java.lang.reflect.Modifier. |
duke@1 | 92 | */ |
duke@1 | 93 | protected int getModifiers() { |
duke@1 | 94 | if (modifiers == -1) { |
duke@1 | 95 | modifiers = DocEnv.translateModifiers(getFlags()); |
duke@1 | 96 | } |
duke@1 | 97 | return modifiers; |
duke@1 | 98 | } |
duke@1 | 99 | |
duke@1 | 100 | /** |
duke@1 | 101 | * Get the containing class of this program element. |
duke@1 | 102 | * |
duke@1 | 103 | * @return a ClassDocImpl for this element's containing class. |
duke@1 | 104 | * If this is a class with no outer class, return null. |
duke@1 | 105 | */ |
duke@1 | 106 | public ClassDoc containingClass() { |
duke@1 | 107 | if (getContainingClass() == null) { |
duke@1 | 108 | return null; |
duke@1 | 109 | } |
duke@1 | 110 | return env.getClassDoc(getContainingClass()); |
duke@1 | 111 | } |
duke@1 | 112 | |
duke@1 | 113 | /** |
duke@1 | 114 | * Return the package that this member is contained in. |
duke@1 | 115 | * Return "" if in unnamed package. |
duke@1 | 116 | */ |
duke@1 | 117 | public PackageDoc containingPackage() { |
duke@1 | 118 | return env.getPackageDoc(getContainingClass().packge()); |
duke@1 | 119 | } |
duke@1 | 120 | |
duke@1 | 121 | /** |
duke@1 | 122 | * Get the modifier specifier integer. |
duke@1 | 123 | * |
duke@1 | 124 | * @see java.lang.reflect.Modifier |
duke@1 | 125 | */ |
duke@1 | 126 | public int modifierSpecifier() { |
duke@1 | 127 | int modifiers = getModifiers(); |
duke@1 | 128 | if (isMethod() && containingClass().isInterface()) |
duke@1 | 129 | // Remove the implicit abstract modifier. |
duke@1 | 130 | return modifiers & ~Modifier.ABSTRACT; |
duke@1 | 131 | return modifiers; |
duke@1 | 132 | } |
duke@1 | 133 | |
duke@1 | 134 | /** |
duke@1 | 135 | * Get modifiers string. |
duke@1 | 136 | * <pre> |
duke@1 | 137 | * Example, for: |
duke@1 | 138 | * public abstract int foo() { ... } |
duke@1 | 139 | * modifiers() would return: |
duke@1 | 140 | * 'public abstract' |
duke@1 | 141 | * </pre> |
duke@1 | 142 | * Annotations are not included. |
duke@1 | 143 | */ |
duke@1 | 144 | public String modifiers() { |
duke@1 | 145 | int modifiers = getModifiers(); |
duke@1 | 146 | if (isAnnotationTypeElement() || |
duke@1 | 147 | (isMethod() && containingClass().isInterface())) { |
duke@1 | 148 | // Remove the implicit abstract modifier. |
duke@1 | 149 | return Modifier.toString(modifiers & ~Modifier.ABSTRACT); |
duke@1 | 150 | } else { |
duke@1 | 151 | return Modifier.toString(modifiers); |
duke@1 | 152 | } |
duke@1 | 153 | } |
duke@1 | 154 | |
duke@1 | 155 | /** |
duke@1 | 156 | * Get the annotations of this program element. |
duke@1 | 157 | * Return an empty array if there are none. |
duke@1 | 158 | */ |
duke@1 | 159 | public AnnotationDesc[] annotations() { |
duke@1 | 160 | AnnotationDesc res[] = new AnnotationDesc[sym.getAnnotationMirrors().length()]; |
duke@1 | 161 | int i = 0; |
duke@1 | 162 | for (Attribute.Compound a : sym.getAnnotationMirrors()) { |
duke@1 | 163 | res[i++] = new AnnotationDescImpl(env, a); |
duke@1 | 164 | } |
duke@1 | 165 | return res; |
duke@1 | 166 | } |
duke@1 | 167 | |
duke@1 | 168 | /** |
duke@1 | 169 | * Return true if this program element is public |
duke@1 | 170 | */ |
duke@1 | 171 | public boolean isPublic() { |
duke@1 | 172 | int modifiers = getModifiers(); |
duke@1 | 173 | return Modifier.isPublic(modifiers); |
duke@1 | 174 | } |
duke@1 | 175 | |
duke@1 | 176 | /** |
duke@1 | 177 | * Return true if this program element is protected |
duke@1 | 178 | */ |
duke@1 | 179 | public boolean isProtected() { |
duke@1 | 180 | int modifiers = getModifiers(); |
duke@1 | 181 | return Modifier.isProtected(modifiers); |
duke@1 | 182 | } |
duke@1 | 183 | |
duke@1 | 184 | /** |
duke@1 | 185 | * Return true if this program element is private |
duke@1 | 186 | */ |
duke@1 | 187 | public boolean isPrivate() { |
duke@1 | 188 | int modifiers = getModifiers(); |
duke@1 | 189 | return Modifier.isPrivate(modifiers); |
duke@1 | 190 | } |
duke@1 | 191 | |
duke@1 | 192 | /** |
duke@1 | 193 | * Return true if this program element is package private |
duke@1 | 194 | */ |
duke@1 | 195 | public boolean isPackagePrivate() { |
duke@1 | 196 | return !(isPublic() || isPrivate() || isProtected()); |
duke@1 | 197 | } |
duke@1 | 198 | |
duke@1 | 199 | /** |
duke@1 | 200 | * Return true if this program element is static |
duke@1 | 201 | */ |
duke@1 | 202 | public boolean isStatic() { |
duke@1 | 203 | int modifiers = getModifiers(); |
duke@1 | 204 | return Modifier.isStatic(modifiers); |
duke@1 | 205 | } |
duke@1 | 206 | |
duke@1 | 207 | /** |
duke@1 | 208 | * Return true if this program element is final |
duke@1 | 209 | */ |
duke@1 | 210 | public boolean isFinal() { |
duke@1 | 211 | int modifiers = getModifiers(); |
duke@1 | 212 | return Modifier.isFinal(modifiers); |
duke@1 | 213 | } |
duke@1 | 214 | |
duke@1 | 215 | /** |
duke@1 | 216 | * Generate a key for sorting. |
duke@1 | 217 | */ |
duke@1 | 218 | CollationKey generateKey() { |
duke@1 | 219 | String k = name(); |
duke@1 | 220 | // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\""); |
duke@1 | 221 | return env.doclocale.collator.getCollationKey(k); |
duke@1 | 222 | } |
duke@1 | 223 | |
duke@1 | 224 | } |