src/share/classes/com/sun/tools/javac/api/JavacTrees.java

Fri, 10 May 2013 15:15:50 +0200

author
jlahoda
date
Fri, 10 May 2013 15:15:50 +0200
changeset 1734
8dd528992c15
parent 1726
a7ff36d06fa2
child 1853
831467c4c6a7
permissions
-rw-r--r--

8012929: Trees.getElement should work not only for declaration trees, but also for use-trees
Reviewed-by: jjg
Contributed-by: Dusan Balek <dbalek@netbeans.org>, Jan Lahoda <jlahoda@netbeans.org>

duke@1 1 /*
jlahoda@1704 2 * Copyright (c) 2005, 2013, 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.javac.api;
duke@1 27
duke@1 28 import java.io.IOException;
jjg@1409 29 import java.util.HashSet;
jjg@1409 30 import java.util.Set;
jjg@1210 31
duke@1 32 import javax.annotation.processing.ProcessingEnvironment;
duke@1 33 import javax.lang.model.element.AnnotationMirror;
duke@1 34 import javax.lang.model.element.AnnotationValue;
duke@1 35 import javax.lang.model.element.Element;
jlahoda@1726 36 import javax.lang.model.element.ElementKind;
duke@1 37 import javax.lang.model.element.ExecutableElement;
duke@1 38 import javax.lang.model.element.TypeElement;
duke@1 39 import javax.lang.model.type.DeclaredType;
jjg@988 40 import javax.lang.model.type.TypeKind;
duke@1 41 import javax.lang.model.type.TypeMirror;
jjg@308 42 import javax.tools.Diagnostic;
duke@1 43 import javax.tools.JavaCompiler;
duke@1 44 import javax.tools.JavaFileObject;
duke@1 45
jjg@1409 46 import com.sun.source.doctree.DocCommentTree;
jlahoda@1704 47 import com.sun.source.doctree.DocTree;
jjg@988 48 import com.sun.source.tree.CatchTree;
duke@1 49 import com.sun.source.tree.CompilationUnitTree;
duke@1 50 import com.sun.source.tree.Scope;
duke@1 51 import com.sun.source.tree.Tree;
jlahoda@1704 52 import com.sun.source.util.DocSourcePositions;
jlahoda@1726 53 import com.sun.source.util.DocTreePath;
jlahoda@1704 54 import com.sun.source.util.DocTreeScanner;
jjg@1409 55 import com.sun.source.util.DocTrees;
jjg@1210 56 import com.sun.source.util.JavacTask;
duke@1 57 import com.sun.source.util.TreePath;
jjg@672 58 import com.sun.tools.javac.code.Flags;
jjg@1409 59 import com.sun.tools.javac.code.Kinds;
jjg@1210 60 import com.sun.tools.javac.code.Symbol;
duke@1 61 import com.sun.tools.javac.code.Symbol.ClassSymbol;
jjg@1409 62 import com.sun.tools.javac.code.Symbol.MethodSymbol;
jjg@1409 63 import com.sun.tools.javac.code.Symbol.PackageSymbol;
duke@1 64 import com.sun.tools.javac.code.Symbol.TypeSymbol;
jjg@1409 65 import com.sun.tools.javac.code.Symbol.VarSymbol;
jjg@1409 66 import com.sun.tools.javac.code.Type;
jjg@1409 67 import com.sun.tools.javac.code.Type.ArrayType;
jjg@1409 68 import com.sun.tools.javac.code.Type.ClassType;
jjg@1409 69 import com.sun.tools.javac.code.Type.ErrorType;
jjg@988 70 import com.sun.tools.javac.code.Type.UnionClassType;
jjg@1409 71 import com.sun.tools.javac.code.Types;
jjg@1409 72 import com.sun.tools.javac.code.Types.TypeRelation;
duke@1 73 import com.sun.tools.javac.comp.Attr;
duke@1 74 import com.sun.tools.javac.comp.AttrContext;
duke@1 75 import com.sun.tools.javac.comp.Enter;
duke@1 76 import com.sun.tools.javac.comp.Env;
duke@1 77 import com.sun.tools.javac.comp.MemberEnter;
duke@1 78 import com.sun.tools.javac.comp.Resolve;
duke@1 79 import com.sun.tools.javac.model.JavacElements;
jjg@1357 80 import com.sun.tools.javac.processing.JavacProcessingEnvironment;
jjg@1409 81 import com.sun.tools.javac.tree.DCTree;
jlahoda@1704 82 import com.sun.tools.javac.tree.DCTree.DCBlockTag;
jjg@1409 83 import com.sun.tools.javac.tree.DCTree.DCDocComment;
jlahoda@1704 84 import com.sun.tools.javac.tree.DCTree.DCEndPosTree;
jlahoda@1704 85 import com.sun.tools.javac.tree.DCTree.DCErroneous;
jlahoda@1704 86 import com.sun.tools.javac.tree.DCTree.DCIdentifier;
jlahoda@1704 87 import com.sun.tools.javac.tree.DCTree.DCParam;
jjg@1409 88 import com.sun.tools.javac.tree.DCTree.DCReference;
jlahoda@1704 89 import com.sun.tools.javac.tree.DCTree.DCText;
jjg@1280 90 import com.sun.tools.javac.tree.EndPosTable;
jjg@1210 91 import com.sun.tools.javac.tree.JCTree;
duke@1 92 import com.sun.tools.javac.tree.JCTree.*;
duke@1 93 import com.sun.tools.javac.tree.TreeCopier;
duke@1 94 import com.sun.tools.javac.tree.TreeInfo;
duke@1 95 import com.sun.tools.javac.tree.TreeMaker;
jjg@1455 96 import com.sun.tools.javac.util.Abort;
jjg@1090 97 import com.sun.tools.javac.util.Assert;
duke@1 98 import com.sun.tools.javac.util.Context;
jjg@308 99 import com.sun.tools.javac.util.JCDiagnostic;
duke@1 100 import com.sun.tools.javac.util.List;
jjg@1409 101 import com.sun.tools.javac.util.ListBuffer;
duke@1 102 import com.sun.tools.javac.util.Log;
jjg@1409 103 import com.sun.tools.javac.util.Name;
jjg@1409 104 import com.sun.tools.javac.util.Names;
duke@1 105 import com.sun.tools.javac.util.Pair;
jlahoda@1704 106 import com.sun.tools.javac.util.Position;
jjg@1409 107 import static com.sun.tools.javac.code.TypeTag.*;
duke@1 108
duke@1 109 /**
duke@1 110 * Provides an implementation of Trees.
duke@1 111 *
jjg@581 112 * <p><b>This is NOT part of any supported API.
duke@1 113 * If you write code that depends on this, you do so at your own
duke@1 114 * risk. This code and its internal interfaces are subject to change
duke@1 115 * or deletion without notice.</b></p>
duke@1 116 *
duke@1 117 * @author Peter von der Ah&eacute;
duke@1 118 */
jjg@1409 119 public class JavacTrees extends DocTrees {
duke@1 120
jjg@696 121 // in a world of a single context per compilation, these would all be final
jjg@696 122 private Resolve resolve;
jjg@696 123 private Enter enter;
jjg@696 124 private Log log;
jjg@696 125 private MemberEnter memberEnter;
jjg@696 126 private Attr attr;
jjg@696 127 private TreeMaker treeMaker;
jjg@696 128 private JavacElements elements;
jjg@696 129 private JavacTaskImpl javacTaskImpl;
jjg@1409 130 private Names names;
jjg@1409 131 private Types types;
duke@1 132
jjg@1210 133 // called reflectively from Trees.instance(CompilationTask task)
duke@1 134 public static JavacTrees instance(JavaCompiler.CompilationTask task) {
jjg@1416 135 if (!(task instanceof BasicJavacTask))
duke@1 136 throw new IllegalArgumentException();
jjg@1416 137 return instance(((BasicJavacTask)task).getContext());
duke@1 138 }
duke@1 139
jjg@1210 140 // called reflectively from Trees.instance(ProcessingEnvironment env)
duke@1 141 public static JavacTrees instance(ProcessingEnvironment env) {
duke@1 142 if (!(env instanceof JavacProcessingEnvironment))
duke@1 143 throw new IllegalArgumentException();
duke@1 144 return instance(((JavacProcessingEnvironment)env).getContext());
duke@1 145 }
duke@1 146
duke@1 147 public static JavacTrees instance(Context context) {
duke@1 148 JavacTrees instance = context.get(JavacTrees.class);
duke@1 149 if (instance == null)
duke@1 150 instance = new JavacTrees(context);
duke@1 151 return instance;
duke@1 152 }
duke@1 153
ksrini@1327 154 protected JavacTrees(Context context) {
duke@1 155 context.put(JavacTrees.class, this);
jjg@696 156 init(context);
jjg@696 157 }
jjg@696 158
jjg@696 159 public void updateContext(Context context) {
jjg@696 160 init(context);
jjg@696 161 }
jjg@696 162
jjg@696 163 private void init(Context context) {
duke@1 164 attr = Attr.instance(context);
duke@1 165 enter = Enter.instance(context);
duke@1 166 elements = JavacElements.instance(context);
duke@1 167 log = Log.instance(context);
duke@1 168 resolve = Resolve.instance(context);
duke@1 169 treeMaker = TreeMaker.instance(context);
duke@1 170 memberEnter = MemberEnter.instance(context);
jjg@1409 171 names = Names.instance(context);
jjg@1409 172 types = Types.instance(context);
jjg@1210 173
jjg@1210 174 JavacTask t = context.get(JavacTask.class);
jjg@1210 175 if (t instanceof JavacTaskImpl)
jjg@1210 176 javacTaskImpl = (JavacTaskImpl) t;
duke@1 177 }
duke@1 178
jlahoda@1704 179 public DocSourcePositions getSourcePositions() {
jlahoda@1704 180 return new DocSourcePositions() {
duke@1 181 public long getStartPosition(CompilationUnitTree file, Tree tree) {
duke@1 182 return TreeInfo.getStartPos((JCTree) tree);
duke@1 183 }
duke@1 184
duke@1 185 public long getEndPosition(CompilationUnitTree file, Tree tree) {
ksrini@1138 186 EndPosTable endPosTable = ((JCCompilationUnit) file).endPositions;
ksrini@1138 187 return TreeInfo.getEndPos((JCTree) tree, endPosTable);
duke@1 188 }
jlahoda@1704 189
jlahoda@1704 190 public long getStartPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) {
jlahoda@1704 191 return ((DCTree) tree).getSourcePosition((DCDocComment) comment);
jlahoda@1704 192 }
jlahoda@1704 193 @SuppressWarnings("fallthrough")
jlahoda@1704 194 public long getEndPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) {
jlahoda@1704 195 DCDocComment dcComment = (DCDocComment) comment;
jlahoda@1704 196 if (tree instanceof DCEndPosTree) {
jlahoda@1704 197 int endPos = ((DCEndPosTree) tree).getEndPos(dcComment);
jlahoda@1704 198
jlahoda@1704 199 if (endPos != Position.NOPOS) {
jlahoda@1704 200 return endPos;
jlahoda@1704 201 }
jlahoda@1704 202 }
jlahoda@1704 203 int correction = 0;
jlahoda@1704 204 switch (tree.getKind()) {
jlahoda@1704 205 case TEXT:
jlahoda@1704 206 DCText text = (DCText) tree;
jlahoda@1704 207
jlahoda@1704 208 return dcComment.comment.getSourcePos(text.pos + text.text.length());
jlahoda@1704 209 case ERRONEOUS:
jlahoda@1704 210 DCErroneous err = (DCErroneous) tree;
jlahoda@1704 211
jlahoda@1704 212 return dcComment.comment.getSourcePos(err.pos + err.body.length());
jlahoda@1704 213 case IDENTIFIER:
jlahoda@1704 214 DCIdentifier ident = (DCIdentifier) tree;
jlahoda@1704 215
jlahoda@1704 216 return dcComment.comment.getSourcePos(ident.pos + (ident.name != names.error ? ident.name.length() : 0));
jlahoda@1704 217 case PARAM:
jlahoda@1704 218 DCParam param = (DCParam) tree;
jlahoda@1704 219
jlahoda@1704 220 if (param.isTypeParameter && param.getDescription().isEmpty()) {
jlahoda@1704 221 correction = 1;
jlahoda@1704 222 }
jlahoda@1704 223 case AUTHOR: case DEPRECATED: case RETURN: case SEE:
jlahoda@1704 224 case SERIAL: case SERIAL_DATA: case SERIAL_FIELD: case SINCE:
jlahoda@1704 225 case THROWS: case UNKNOWN_BLOCK_TAG: case VERSION: {
jlahoda@1704 226 DocTree last = getLastChild(tree);
jlahoda@1704 227
jlahoda@1704 228 if (last != null) {
jlahoda@1704 229 return getEndPosition(file, comment, last) + correction;
jlahoda@1704 230 }
jlahoda@1704 231
jlahoda@1704 232 DCBlockTag block = (DCBlockTag) tree;
jlahoda@1704 233
jlahoda@1704 234 return dcComment.comment.getSourcePos(block.pos + block.getTagName().length() + 1);
jlahoda@1704 235 }
jlahoda@1704 236 default:
jlahoda@1704 237 DocTree last = getLastChild(tree);
jlahoda@1704 238
jlahoda@1704 239 if (last != null) {
jlahoda@1704 240 return getEndPosition(file, comment, last);
jlahoda@1704 241 }
jlahoda@1704 242 break;
jlahoda@1704 243 }
jlahoda@1704 244
jlahoda@1704 245 return Position.NOPOS;
jlahoda@1704 246 }
duke@1 247 };
duke@1 248 }
duke@1 249
jlahoda@1704 250 private DocTree getLastChild(DocTree tree) {
jlahoda@1704 251 final DocTree[] last = new DocTree[] {null};
jlahoda@1704 252
jlahoda@1704 253 tree.accept(new DocTreeScanner<Void, Void>() {
jlahoda@1704 254 @Override public Void scan(DocTree node, Void p) {
jlahoda@1704 255 if (node != null) last[0] = node;
jlahoda@1704 256 return null;
jlahoda@1704 257 }
jlahoda@1704 258 }, null);
jlahoda@1704 259
jlahoda@1704 260 return last[0];
jlahoda@1704 261 }
jlahoda@1704 262
duke@1 263 public JCClassDecl getTree(TypeElement element) {
duke@1 264 return (JCClassDecl) getTree((Element) element);
duke@1 265 }
duke@1 266
duke@1 267 public JCMethodDecl getTree(ExecutableElement method) {
duke@1 268 return (JCMethodDecl) getTree((Element) method);
duke@1 269 }
duke@1 270
duke@1 271 public JCTree getTree(Element element) {
duke@1 272 Symbol symbol = (Symbol) element;
duke@1 273 TypeSymbol enclosing = symbol.enclClass();
duke@1 274 Env<AttrContext> env = enter.getEnv(enclosing);
duke@1 275 if (env == null)
duke@1 276 return null;
duke@1 277 JCClassDecl classNode = env.enclClass;
duke@1 278 if (classNode != null) {
duke@1 279 if (TreeInfo.symbolFor(classNode) == element)
duke@1 280 return classNode;
duke@1 281 for (JCTree node : classNode.getMembers())
duke@1 282 if (TreeInfo.symbolFor(node) == element)
duke@1 283 return node;
duke@1 284 }
duke@1 285 return null;
duke@1 286 }
duke@1 287
duke@1 288 public JCTree getTree(Element e, AnnotationMirror a) {
duke@1 289 return getTree(e, a, null);
duke@1 290 }
duke@1 291
duke@1 292 public JCTree getTree(Element e, AnnotationMirror a, AnnotationValue v) {
duke@1 293 Pair<JCTree, JCCompilationUnit> treeTopLevel = elements.getTreeAndTopLevel(e, a, v);
duke@1 294 if (treeTopLevel == null)
duke@1 295 return null;
duke@1 296 return treeTopLevel.fst;
duke@1 297 }
duke@1 298
duke@1 299 public TreePath getPath(CompilationUnitTree unit, Tree node) {
duke@1 300 return TreePath.getPath(unit, node);
duke@1 301 }
duke@1 302
duke@1 303 public TreePath getPath(Element e) {
duke@1 304 return getPath(e, null, null);
duke@1 305 }
duke@1 306
duke@1 307 public TreePath getPath(Element e, AnnotationMirror a) {
duke@1 308 return getPath(e, a, null);
duke@1 309 }
duke@1 310
duke@1 311 public TreePath getPath(Element e, AnnotationMirror a, AnnotationValue v) {
duke@1 312 final Pair<JCTree, JCCompilationUnit> treeTopLevel = elements.getTreeAndTopLevel(e, a, v);
duke@1 313 if (treeTopLevel == null)
duke@1 314 return null;
duke@1 315 return TreePath.getPath(treeTopLevel.snd, treeTopLevel.fst);
duke@1 316 }
duke@1 317
jlahoda@1726 318 public Symbol getElement(TreePath path) {
jjg@672 319 JCTree tree = (JCTree) path.getLeaf();
jjg@672 320 Symbol sym = TreeInfo.symbolFor(tree);
jjg@1455 321 if (sym == null) {
jjg@1455 322 if (TreeInfo.isDeclaration(tree)) {
jjg@1455 323 for (TreePath p = path; p != null; p = p.getParentPath()) {
jjg@1455 324 JCTree t = (JCTree) p.getLeaf();
jjg@1455 325 if (t.hasTag(JCTree.Tag.CLASSDEF)) {
jjg@1455 326 JCClassDecl ct = (JCClassDecl) t;
jjg@1455 327 if (ct.sym != null) {
jjg@1455 328 if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
jjg@1455 329 attr.attribClass(ct.pos(), ct.sym);
jjg@1455 330 sym = TreeInfo.symbolFor(tree);
jjg@1455 331 }
jjg@1455 332 break;
jjg@672 333 }
jjg@672 334 }
jjg@672 335 }
jjg@672 336 }
jjg@672 337 }
jjg@672 338 return sym;
duke@1 339 }
duke@1 340
jjg@1409 341 @Override
jlahoda@1726 342 public Element getElement(DocTreePath path) {
jlahoda@1726 343 DocTree forTree = path.getLeaf();
jlahoda@1726 344 if (forTree instanceof DCReference)
jlahoda@1726 345 return attributeDocReference(path.getTreePath(), ((DCReference) forTree));
jlahoda@1726 346 if (forTree instanceof DCIdentifier) {
jlahoda@1726 347 if (path.getParentPath().getLeaf() instanceof DCParam) {
jlahoda@1726 348 return attributeParamIdentifier(path.getTreePath(), (DCParam) path.getParentPath().getLeaf());
jlahoda@1726 349 }
jlahoda@1726 350 }
jlahoda@1726 351 return null;
jlahoda@1726 352 }
jjg@1409 353
jlahoda@1726 354 private Symbol attributeDocReference(TreePath path, DCReference ref) {
jjg@1409 355 Env<AttrContext> env = getAttrContext(path);
jjg@1409 356
jjg@1409 357 Log.DeferredDiagnosticHandler deferredDiagnosticHandler =
jjg@1409 358 new Log.DeferredDiagnosticHandler(log);
jjg@1409 359 try {
jjg@1409 360 final ClassSymbol tsym;
jjg@1409 361 final Name memberName;
jjg@1409 362 if (ref.qualifierExpression == null) {
jjg@1409 363 tsym = env.enclClass.sym;
jjg@1409 364 memberName = ref.memberName;
jjg@1409 365 } else {
jjg@1409 366 // See if the qualifierExpression is a type or package name.
jjg@1409 367 // javac does not provide the exact method required, so
jjg@1409 368 // we first check if qualifierExpression identifies a type,
jjg@1409 369 // and if not, then we check to see if it identifies a package.
jjg@1409 370 Type t = attr.attribType(ref.qualifierExpression, env);
jjg@1409 371 if (t.isErroneous()) {
jjg@1409 372 if (ref.memberName == null) {
jjg@1409 373 // Attr/Resolve assume packages exist and create symbols as needed
jjg@1409 374 // so use getPackageElement to restrict search to existing packages
jjg@1409 375 PackageSymbol pck = elements.getPackageElement(ref.qualifierExpression.toString());
jjg@1409 376 if (pck != null) {
jjg@1409 377 return pck;
jjg@1409 378 } else if (ref.qualifierExpression.hasTag(JCTree.Tag.IDENT)) {
jjg@1409 379 // fixup: allow "identifier" instead of "#identifier"
jjg@1409 380 // for compatibility with javadoc
jjg@1409 381 tsym = env.enclClass.sym;
jjg@1409 382 memberName = ((JCIdent) ref.qualifierExpression).name;
jjg@1409 383 } else
jjg@1409 384 return null;
jjg@1409 385 } else {
jjg@1409 386 return null;
jjg@1409 387 }
jjg@1409 388 } else {
jjg@1409 389 tsym = (ClassSymbol) t.tsym;
jjg@1409 390 memberName = ref.memberName;
jjg@1409 391 }
jjg@1409 392 }
jjg@1409 393
jjg@1409 394 if (memberName == null)
jjg@1409 395 return tsym;
jjg@1409 396
jjg@1409 397 final List<Type> paramTypes;
jjg@1409 398 if (ref.paramTypes == null)
jjg@1409 399 paramTypes = null;
jjg@1409 400 else {
jjg@1409 401 ListBuffer<Type> lb = new ListBuffer<Type>();
jjg@1409 402 for (List<JCTree> l = ref.paramTypes; l.nonEmpty(); l = l.tail) {
jjg@1409 403 JCTree tree = l.head;
jjg@1409 404 Type t = attr.attribType(tree, env);
jjg@1409 405 lb.add(t);
jjg@1409 406 }
jjg@1409 407 paramTypes = lb.toList();
jjg@1409 408 }
jjg@1409 409
jjg@1409 410 Symbol msym = (memberName == tsym.name)
jjg@1409 411 ? findConstructor(tsym, paramTypes)
jjg@1409 412 : findMethod(tsym, memberName, paramTypes);
jjg@1409 413 if (paramTypes != null) {
jjg@1409 414 // explicit (possibly empty) arg list given, so cannot be a field
jjg@1409 415 return msym;
jjg@1409 416 }
jjg@1409 417
jjg@1409 418 VarSymbol vsym = (ref.paramTypes != null) ? null : findField(tsym, memberName);
jjg@1409 419 // prefer a field over a method with no parameters
jjg@1409 420 if (vsym != null &&
jjg@1409 421 (msym == null ||
jjg@1409 422 types.isSubtypeUnchecked(vsym.enclClass().asType(), msym.enclClass().asType()))) {
jjg@1409 423 return vsym;
jjg@1409 424 } else {
jjg@1409 425 return msym;
jjg@1409 426 }
jjg@1455 427 } catch (Abort e) { // may be thrown by Check.completionError in case of bad class file
jjg@1455 428 return null;
jjg@1409 429 } finally {
jjg@1409 430 log.popDiagnosticHandler(deferredDiagnosticHandler);
jjg@1409 431 }
jjg@1409 432 }
jjg@1409 433
jlahoda@1726 434 private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) {
jlahoda@1726 435 Symbol javadocSymbol = getElement(path);
jlahoda@1726 436 if (javadocSymbol == null)
jlahoda@1726 437 return null;
jlahoda@1726 438 ElementKind kind = javadocSymbol.getKind();
jlahoda@1726 439 List<? extends Symbol> params = List.nil();
jlahoda@1726 440 if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
jlahoda@1726 441 MethodSymbol ee = (MethodSymbol) javadocSymbol;
jlahoda@1726 442 params = ptag.isTypeParameter()
jlahoda@1726 443 ? ee.getTypeParameters()
jlahoda@1726 444 : ee.getParameters();
jlahoda@1726 445 } else if (kind.isClass() || kind.isInterface()) {
jlahoda@1726 446 ClassSymbol te = (ClassSymbol) javadocSymbol;
jlahoda@1726 447 params = te.getTypeParameters();
jlahoda@1726 448 }
jlahoda@1726 449
jlahoda@1726 450 for (Symbol param : params) {
jlahoda@1726 451 if (param.getSimpleName() == ptag.getName().getName()) {
jlahoda@1726 452 return param;
jlahoda@1726 453 }
jlahoda@1726 454 }
jlahoda@1726 455 return null;
jlahoda@1726 456 }
jlahoda@1726 457
jjg@1409 458 /** @see com.sun.tools.javadoc.ClassDocImpl#findField */
jjg@1409 459 private VarSymbol findField(ClassSymbol tsym, Name fieldName) {
jjg@1409 460 return searchField(tsym, fieldName, new HashSet<ClassSymbol>());
jjg@1409 461 }
jjg@1409 462
jjg@1409 463 /** @see com.sun.tools.javadoc.ClassDocImpl#searchField */
jjg@1409 464 private VarSymbol searchField(ClassSymbol tsym, Name fieldName, Set<ClassSymbol> searched) {
jjg@1409 465 if (searched.contains(tsym)) {
jjg@1409 466 return null;
jjg@1409 467 }
jjg@1409 468 searched.add(tsym);
jjg@1409 469
jjg@1409 470 for (com.sun.tools.javac.code.Scope.Entry e = tsym.members().lookup(fieldName);
jjg@1409 471 e.scope != null; e = e.next()) {
jjg@1409 472 if (e.sym.kind == Kinds.VAR) {
jjg@1409 473 return (VarSymbol)e.sym;
jjg@1409 474 }
jjg@1409 475 }
jjg@1409 476
jjg@1409 477 //### If we found a VarSymbol above, but which did not pass
jjg@1409 478 //### the modifier filter, we should return failure here!
jjg@1409 479
jjg@1409 480 ClassSymbol encl = tsym.owner.enclClass();
jjg@1409 481 if (encl != null) {
jjg@1409 482 VarSymbol vsym = searchField(encl, fieldName, searched);
jjg@1409 483 if (vsym != null) {
jjg@1409 484 return vsym;
jjg@1409 485 }
jjg@1409 486 }
jjg@1409 487
jjg@1409 488 // search superclass
jjg@1409 489 Type superclass = tsym.getSuperclass();
jjg@1409 490 if (superclass.tsym != null) {
jjg@1409 491 VarSymbol vsym = searchField((ClassSymbol) superclass.tsym, fieldName, searched);
jjg@1409 492 if (vsym != null) {
jjg@1409 493 return vsym;
jjg@1409 494 }
jjg@1409 495 }
jjg@1409 496
jjg@1409 497 // search interfaces
jjg@1409 498 List<Type> intfs = tsym.getInterfaces();
jjg@1409 499 for (List<Type> l = intfs; l.nonEmpty(); l = l.tail) {
jjg@1409 500 Type intf = l.head;
jjg@1409 501 if (intf.isErroneous()) continue;
jjg@1409 502 VarSymbol vsym = searchField((ClassSymbol) intf.tsym, fieldName, searched);
jjg@1409 503 if (vsym != null) {
jjg@1409 504 return vsym;
jjg@1409 505 }
jjg@1409 506 }
jjg@1409 507
jjg@1409 508 return null;
jjg@1409 509 }
jjg@1409 510
jjg@1409 511 /** @see com.sun.tools.javadoc.ClassDocImpl#findConstructor */
jjg@1409 512 MethodSymbol findConstructor(ClassSymbol tsym, List<Type> paramTypes) {
jjg@1409 513 for (com.sun.tools.javac.code.Scope.Entry e = tsym.members().lookup(names.init);
jjg@1409 514 e.scope != null; e = e.next()) {
jjg@1409 515 if (e.sym.kind == Kinds.MTH) {
jjg@1409 516 if (hasParameterTypes((MethodSymbol) e.sym, paramTypes)) {
jjg@1409 517 return (MethodSymbol) e.sym;
jjg@1409 518 }
jjg@1409 519 }
jjg@1409 520 }
jjg@1409 521 return null;
jjg@1409 522 }
jjg@1409 523
jjg@1409 524 /** @see com.sun.tools.javadoc.ClassDocImpl#findMethod */
jjg@1409 525 private MethodSymbol findMethod(ClassSymbol tsym, Name methodName, List<Type> paramTypes) {
jjg@1409 526 return searchMethod(tsym, methodName, paramTypes, new HashSet<ClassSymbol>());
jjg@1409 527 }
jjg@1409 528
jjg@1409 529 /** @see com.sun.tools.javadoc.ClassDocImpl#searchMethod */
jjg@1409 530 private MethodSymbol searchMethod(ClassSymbol tsym, Name methodName,
jjg@1409 531 List<Type> paramTypes, Set<ClassSymbol> searched) {
jjg@1409 532 //### Note that this search is not necessarily what the compiler would do!
jjg@1409 533
jjg@1409 534 // do not match constructors
jjg@1409 535 if (methodName == names.init)
jjg@1409 536 return null;
jjg@1409 537
jjg@1409 538 if (searched.contains(tsym))
jjg@1409 539 return null;
jjg@1409 540 searched.add(tsym);
jjg@1409 541
jjg@1409 542 // search current class
jjg@1409 543 com.sun.tools.javac.code.Scope.Entry e = tsym.members().lookup(methodName);
jjg@1409 544
jjg@1409 545 //### Using modifier filter here isn't really correct,
jjg@1409 546 //### but emulates the old behavior. Instead, we should
jjg@1409 547 //### apply the normal rules of visibility and inheritance.
jjg@1409 548
jjg@1409 549 if (paramTypes == null) {
jjg@1409 550 // If no parameters specified, we are allowed to return
jjg@1409 551 // any method with a matching name. In practice, the old
jjg@1409 552 // code returned the first method, which is now the last!
jjg@1409 553 // In order to provide textually identical results, we
jjg@1409 554 // attempt to emulate the old behavior.
jjg@1409 555 MethodSymbol lastFound = null;
jjg@1409 556 for (; e.scope != null; e = e.next()) {
jjg@1409 557 if (e.sym.kind == Kinds.MTH) {
jjg@1409 558 if (e.sym.name == methodName) {
jjg@1409 559 lastFound = (MethodSymbol)e.sym;
jjg@1409 560 }
jjg@1409 561 }
jjg@1409 562 }
jjg@1409 563 if (lastFound != null) {
jjg@1409 564 return lastFound;
jjg@1409 565 }
jjg@1409 566 } else {
jjg@1409 567 for (; e.scope != null; e = e.next()) {
jjg@1409 568 if (e.sym != null &&
jjg@1409 569 e.sym.kind == Kinds.MTH) {
jjg@1409 570 if (hasParameterTypes((MethodSymbol) e.sym, paramTypes)) {
jjg@1409 571 return (MethodSymbol) e.sym;
jjg@1409 572 }
jjg@1409 573 }
jjg@1409 574 }
jjg@1409 575 }
jjg@1409 576
jjg@1409 577 //### If we found a MethodSymbol above, but which did not pass
jjg@1409 578 //### the modifier filter, we should return failure here!
jjg@1409 579
jjg@1409 580 // search superclass
jjg@1409 581 Type superclass = tsym.getSuperclass();
jjg@1409 582 if (superclass.tsym != null) {
jjg@1409 583 MethodSymbol msym = searchMethod((ClassSymbol) superclass.tsym, methodName, paramTypes, searched);
jjg@1409 584 if (msym != null) {
jjg@1409 585 return msym;
jjg@1409 586 }
jjg@1409 587 }
jjg@1409 588
jjg@1409 589 // search interfaces
jjg@1409 590 List<Type> intfs = tsym.getInterfaces();
jjg@1409 591 for (List<Type> l = intfs; l.nonEmpty(); l = l.tail) {
jjg@1409 592 Type intf = l.head;
jjg@1409 593 if (intf.isErroneous()) continue;
jjg@1409 594 MethodSymbol msym = searchMethod((ClassSymbol) intf.tsym, methodName, paramTypes, searched);
jjg@1409 595 if (msym != null) {
jjg@1409 596 return msym;
jjg@1409 597 }
jjg@1409 598 }
jjg@1409 599
jjg@1409 600 // search enclosing class
jjg@1409 601 ClassSymbol encl = tsym.owner.enclClass();
jjg@1409 602 if (encl != null) {
jjg@1409 603 MethodSymbol msym = searchMethod(encl, methodName, paramTypes, searched);
jjg@1409 604 if (msym != null) {
jjg@1409 605 return msym;
jjg@1409 606 }
jjg@1409 607 }
jjg@1409 608
jjg@1409 609 return null;
jjg@1409 610 }
jjg@1409 611
jjg@1409 612 /** @see com.sun.tools.javadoc.ClassDocImpl */
jjg@1409 613 private boolean hasParameterTypes(MethodSymbol method, List<Type> paramTypes) {
jjg@1409 614 if (paramTypes == null)
jjg@1409 615 return true;
jjg@1409 616
jjg@1409 617 if (method.params().size() != paramTypes.size())
jjg@1409 618 return false;
jjg@1409 619
jjg@1409 620 List<Type> methodParamTypes = types.erasureRecursive(method.asType()).getParameterTypes();
jjg@1409 621
jjg@1409 622 return (Type.isErroneous(paramTypes))
jjg@1409 623 ? fuzzyMatch(paramTypes, methodParamTypes)
jjg@1409 624 : types.isSameTypes(paramTypes, methodParamTypes);
jjg@1409 625 }
jjg@1409 626
jjg@1409 627 boolean fuzzyMatch(List<Type> paramTypes, List<Type> methodParamTypes) {
jjg@1409 628 List<Type> l1 = paramTypes;
jjg@1409 629 List<Type> l2 = methodParamTypes;
jjg@1409 630 while (l1.nonEmpty()) {
jjg@1409 631 if (!fuzzyMatch(l1.head, l2.head))
jjg@1409 632 return false;
jjg@1409 633 l1 = l1.tail;
jjg@1409 634 l2 = l2.tail;
jjg@1409 635 }
jjg@1409 636 return true;
jjg@1409 637 }
jjg@1409 638
jjg@1409 639 boolean fuzzyMatch(Type paramType, Type methodParamType) {
jjg@1409 640 Boolean b = fuzzyMatcher.visit(paramType, methodParamType);
jjg@1409 641 return (b == Boolean.TRUE);
jjg@1409 642 }
jjg@1409 643
jjg@1409 644 TypeRelation fuzzyMatcher = new TypeRelation() {
jjg@1409 645 @Override
jjg@1409 646 public Boolean visitType(Type t, Type s) {
jjg@1409 647 if (t == s)
jjg@1409 648 return true;
jjg@1409 649
jjg@1409 650 if (s.isPartial())
jjg@1409 651 return visit(s, t);
jjg@1409 652
jjg@1409 653 switch (t.getTag()) {
jjg@1409 654 case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
jjg@1409 655 case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE:
jjg@1409 656 return t.getTag() == s.getTag();
jjg@1409 657
jjg@1409 658 default:
jjg@1409 659 throw new AssertionError("fuzzyMatcher " + t.getTag());
jjg@1409 660 }
jjg@1409 661 }
jjg@1409 662
jjg@1409 663 @Override
jjg@1409 664 public Boolean visitArrayType(ArrayType t, Type s) {
jjg@1409 665 if (t == s)
jjg@1409 666 return true;
jjg@1409 667
jjg@1409 668 if (s.isPartial())
jjg@1409 669 return visit(s, t);
jjg@1409 670
jjg@1409 671 return s.getTag() == ARRAY
jjg@1409 672 && visit(t.elemtype, types.elemtype(s));
jjg@1409 673 }
jjg@1409 674
jjg@1409 675 @Override
jjg@1409 676 public Boolean visitClassType(ClassType t, Type s) {
jjg@1409 677 if (t == s)
jjg@1409 678 return true;
jjg@1409 679
jjg@1409 680 if (s.isPartial())
jjg@1409 681 return visit(s, t);
jjg@1409 682
jjg@1409 683 return t.tsym == s.tsym;
jjg@1409 684 }
jjg@1409 685
jjg@1409 686 @Override
jjg@1409 687 public Boolean visitErrorType(ErrorType t, Type s) {
jjg@1409 688 return s.getTag() == CLASS
jjg@1409 689 && t.tsym.name == ((ClassType) s).tsym.name;
jjg@1409 690 }
jjg@1409 691 };
jjg@1409 692
duke@1 693 public TypeMirror getTypeMirror(TreePath path) {
duke@1 694 Tree t = path.getLeaf();
duke@1 695 return ((JCTree)t).type;
duke@1 696 }
duke@1 697
duke@1 698 public JavacScope getScope(TreePath path) {
duke@1 699 return new JavacScope(getAttrContext(path));
duke@1 700 }
duke@1 701
jjg@783 702 public String getDocComment(TreePath path) {
jjg@783 703 CompilationUnitTree t = path.getCompilationUnit();
jjg@1280 704 Tree leaf = path.getLeaf();
jjg@1280 705 if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) {
jjg@783 706 JCCompilationUnit cu = (JCCompilationUnit) t;
jjg@783 707 if (cu.docComments != null) {
jjg@1280 708 return cu.docComments.getCommentText((JCTree) leaf);
jjg@783 709 }
jjg@783 710 }
jjg@783 711 return null;
jjg@783 712 }
jjg@783 713
jjg@1409 714 public DocCommentTree getDocCommentTree(TreePath path) {
jjg@1409 715 CompilationUnitTree t = path.getCompilationUnit();
jjg@1409 716 Tree leaf = path.getLeaf();
jjg@1409 717 if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) {
jjg@1409 718 JCCompilationUnit cu = (JCCompilationUnit) t;
jjg@1409 719 if (cu.docComments != null) {
jjg@1409 720 return cu.docComments.getCommentTree((JCTree) leaf);
jjg@1409 721 }
jjg@1409 722 }
jjg@1409 723 return null;
jjg@1409 724 }
jjg@1409 725
duke@1 726 public boolean isAccessible(Scope scope, TypeElement type) {
duke@1 727 if (scope instanceof JavacScope && type instanceof ClassSymbol) {
duke@1 728 Env<AttrContext> env = ((JavacScope) scope).env;
mcimadamore@741 729 return resolve.isAccessible(env, (ClassSymbol)type, true);
duke@1 730 } else
duke@1 731 return false;
duke@1 732 }
duke@1 733
duke@1 734 public boolean isAccessible(Scope scope, Element member, DeclaredType type) {
duke@1 735 if (scope instanceof JavacScope
duke@1 736 && member instanceof Symbol
duke@1 737 && type instanceof com.sun.tools.javac.code.Type) {
duke@1 738 Env<AttrContext> env = ((JavacScope) scope).env;
mcimadamore@741 739 return resolve.isAccessible(env, (com.sun.tools.javac.code.Type)type, (Symbol)member, true);
duke@1 740 } else
duke@1 741 return false;
duke@1 742 }
duke@1 743
duke@1 744 private Env<AttrContext> getAttrContext(TreePath path) {
duke@1 745 if (!(path.getLeaf() instanceof JCTree)) // implicit null-check
duke@1 746 throw new IllegalArgumentException();
duke@1 747
jjg@1090 748 // if we're being invoked from a Tree API client via parse/enter/analyze,
jjg@1090 749 // we need to make sure all the classes have been entered;
jjg@1090 750 // if we're being invoked from JSR 199 or JSR 269, then the classes
jjg@1090 751 // will already have been entered.
duke@1 752 if (javacTaskImpl != null) {
duke@1 753 try {
duke@1 754 javacTaskImpl.enter(null);
duke@1 755 } catch (IOException e) {
duke@1 756 throw new Error("unexpected error while entering symbols: " + e);
duke@1 757 }
duke@1 758 }
duke@1 759
duke@1 760
duke@1 761 JCCompilationUnit unit = (JCCompilationUnit) path.getCompilationUnit();
ksrini@1327 762 Copier copier = createCopier(treeMaker.forToplevel(unit));
duke@1 763
duke@1 764 Env<AttrContext> env = null;
duke@1 765 JCMethodDecl method = null;
duke@1 766 JCVariableDecl field = null;
duke@1 767
duke@1 768 List<Tree> l = List.nil();
duke@1 769 TreePath p = path;
duke@1 770 while (p != null) {
duke@1 771 l = l.prepend(p.getLeaf());
duke@1 772 p = p.getParentPath();
duke@1 773 }
duke@1 774
duke@1 775 for ( ; l.nonEmpty(); l = l.tail) {
duke@1 776 Tree tree = l.head;
duke@1 777 switch (tree.getKind()) {
duke@1 778 case COMPILATION_UNIT:
duke@1 779 // System.err.println("COMP: " + ((JCCompilationUnit)tree).sourcefile);
duke@1 780 env = enter.getTopLevelEnv((JCCompilationUnit)tree);
duke@1 781 break;
jjg@727 782 case ANNOTATION_TYPE:
duke@1 783 case CLASS:
jjg@727 784 case ENUM:
jjg@682 785 case INTERFACE:
duke@1 786 // System.err.println("CLASS: " + ((JCClassDecl)tree).sym.getSimpleName());
duke@1 787 env = enter.getClassEnv(((JCClassDecl)tree).sym);
duke@1 788 break;
duke@1 789 case METHOD:
duke@1 790 // System.err.println("METHOD: " + ((JCMethodDecl)tree).sym.getSimpleName());
duke@1 791 method = (JCMethodDecl)tree;
duke@1 792 break;
duke@1 793 case VARIABLE:
duke@1 794 // System.err.println("FIELD: " + ((JCVariableDecl)tree).sym.getSimpleName());
duke@1 795 field = (JCVariableDecl)tree;
duke@1 796 break;
duke@1 797 case BLOCK: {
duke@1 798 // System.err.println("BLOCK: ");
jjg@1090 799 if (method != null) {
jjg@1090 800 try {
jjg@1090 801 Assert.check(method.body == tree);
jjg@1090 802 method.body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf());
jjg@1090 803 env = memberEnter.getMethodEnv(method, env);
jjg@1090 804 env = attribStatToTree(method.body, env, copier.leafCopy);
jjg@1090 805 } finally {
jjg@1090 806 method.body = (JCBlock) tree;
jjg@1090 807 }
jjg@1090 808 } else {
jjg@1090 809 JCBlock body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf());
jjg@1090 810 env = attribStatToTree(body, env, copier.leafCopy);
jjg@1090 811 }
duke@1 812 return env;
duke@1 813 }
duke@1 814 default:
duke@1 815 // System.err.println("DEFAULT: " + tree.getKind());
duke@1 816 if (field != null && field.getInitializer() == tree) {
duke@1 817 env = memberEnter.getInitEnv(field, env);
duke@1 818 JCExpression expr = copier.copy((JCExpression)tree, (JCTree) path.getLeaf());
duke@1 819 env = attribExprToTree(expr, env, copier.leafCopy);
duke@1 820 return env;
duke@1 821 }
duke@1 822 }
duke@1 823 }
jjg@1090 824 return (field != null) ? memberEnter.getInitEnv(field, env) : env;
duke@1 825 }
duke@1 826
duke@1 827 private Env<AttrContext> attribStatToTree(JCTree stat, Env<AttrContext>env, JCTree tree) {
duke@1 828 JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
duke@1 829 try {
duke@1 830 return attr.attribStatToTree(stat, env, tree);
duke@1 831 } finally {
duke@1 832 log.useSource(prev);
duke@1 833 }
duke@1 834 }
duke@1 835
duke@1 836 private Env<AttrContext> attribExprToTree(JCExpression expr, Env<AttrContext>env, JCTree tree) {
duke@1 837 JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
duke@1 838 try {
duke@1 839 return attr.attribExprToTree(expr, env, tree);
duke@1 840 } finally {
duke@1 841 log.useSource(prev);
duke@1 842 }
duke@1 843 }
duke@1 844
duke@1 845 /**
duke@1 846 * Makes a copy of a tree, noting the value resulting from copying a particular leaf.
duke@1 847 **/
ksrini@1327 848 protected static class Copier extends TreeCopier<JCTree> {
duke@1 849 JCTree leafCopy = null;
duke@1 850
ksrini@1327 851 protected Copier(TreeMaker M) {
duke@1 852 super(M);
duke@1 853 }
duke@1 854
jjg@696 855 @Override
duke@1 856 public <T extends JCTree> T copy(T t, JCTree leaf) {
duke@1 857 T t2 = super.copy(t, leaf);
duke@1 858 if (t == leaf)
duke@1 859 leafCopy = t2;
duke@1 860 return t2;
duke@1 861 }
duke@1 862 }
jjg@110 863
ksrini@1327 864 protected Copier createCopier(TreeMaker maker) {
ksrini@1327 865 return new Copier(maker);
ksrini@1327 866 }
ksrini@1327 867
jjg@110 868 /**
jjg@110 869 * Gets the original type from the ErrorType object.
jjg@110 870 * @param errorType The errorType for which we want to get the original type.
jjg@110 871 * @returns TypeMirror corresponding to the original type, replaced by the ErrorType.
jjg@110 872 * noType (type.tag == NONE) is returned if there is no original type.
jjg@110 873 */
jjg@110 874 public TypeMirror getOriginalType(javax.lang.model.type.ErrorType errorType) {
jjg@110 875 if (errorType instanceof com.sun.tools.javac.code.Type.ErrorType) {
jjg@110 876 return ((com.sun.tools.javac.code.Type.ErrorType)errorType).getOriginalType();
jjg@110 877 }
jjg@110 878
jjg@110 879 return com.sun.tools.javac.code.Type.noType;
jjg@110 880 }
jjg@308 881
jjg@308 882 /**
jjg@308 883 * Prints a message of the specified kind at the location of the
jjg@308 884 * tree within the provided compilation unit
jjg@308 885 *
jjg@308 886 * @param kind the kind of message
jjg@308 887 * @param msg the message, or an empty string if none
jjg@308 888 * @param t the tree to use as a position hint
jjg@308 889 * @param root the compilation unit that contains tree
jjg@308 890 */
jjg@308 891 public void printMessage(Diagnostic.Kind kind, CharSequence msg,
jjg@308 892 com.sun.source.tree.Tree t,
jjg@308 893 com.sun.source.tree.CompilationUnitTree root) {
jjg@1409 894 printMessage(kind, msg, ((JCTree) t).pos(), root);
jjg@1409 895 }
jjg@1409 896
jjg@1409 897 public void printMessage(Diagnostic.Kind kind, CharSequence msg,
jjg@1409 898 com.sun.source.doctree.DocTree t,
jjg@1409 899 com.sun.source.doctree.DocCommentTree c,
jjg@1409 900 com.sun.source.tree.CompilationUnitTree root) {
jjg@1409 901 printMessage(kind, msg, ((DCTree) t).pos((DCDocComment) c), root);
jjg@1409 902 }
jjg@1409 903
jjg@1409 904 private void printMessage(Diagnostic.Kind kind, CharSequence msg,
jjg@1409 905 JCDiagnostic.DiagnosticPosition pos,
jjg@1409 906 com.sun.source.tree.CompilationUnitTree root) {
jjg@308 907 JavaFileObject oldSource = null;
jjg@308 908 JavaFileObject newSource = null;
jjg@308 909
jjg@308 910 newSource = root.getSourceFile();
jjg@1409 911 if (newSource == null) {
jjg@1409 912 pos = null;
jjg@1409 913 } else {
jjg@308 914 oldSource = log.useSource(newSource);
jjg@308 915 }
jjg@308 916
jjg@308 917 try {
jjg@308 918 switch (kind) {
jjg@308 919 case ERROR:
jjg@308 920 boolean prev = log.multipleErrors;
jjg@308 921 try {
jjg@308 922 log.error(pos, "proc.messager", msg.toString());
jjg@308 923 } finally {
jjg@308 924 log.multipleErrors = prev;
jjg@308 925 }
jjg@308 926 break;
jjg@308 927
jjg@308 928 case WARNING:
jjg@308 929 log.warning(pos, "proc.messager", msg.toString());
jjg@308 930 break;
jjg@308 931
jjg@308 932 case MANDATORY_WARNING:
jjg@308 933 log.mandatoryWarning(pos, "proc.messager", msg.toString());
jjg@308 934 break;
jjg@308 935
jjg@308 936 default:
jjg@308 937 log.note(pos, "proc.messager", msg.toString());
jjg@308 938 }
jjg@308 939 } finally {
jjg@308 940 if (oldSource != null)
jjg@308 941 log.useSource(oldSource);
jjg@308 942 }
jjg@308 943 }
jjg@988 944
jjg@988 945 @Override
jjg@988 946 public TypeMirror getLub(CatchTree tree) {
jjg@988 947 JCCatch ct = (JCCatch) tree;
jjg@988 948 JCVariableDecl v = ct.param;
jjg@988 949 if (v.type != null && v.type.getKind() == TypeKind.UNION) {
jjg@988 950 UnionClassType ut = (UnionClassType) v.type;
jjg@988 951 return ut.getLub();
jjg@988 952 } else {
jjg@988 953 return v.type;
jjg@988 954 }
jjg@988 955 }
duke@1 956 }

mercurial