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

changeset 1455
75ab654b5cd5
parent 1416
c0f0c41cafa0
child 1704
ed918a442b83
equal deleted inserted replaced
1454:02a18f209ab3 1455:75ab654b5cd5
82 import com.sun.tools.javac.tree.JCTree; 82 import com.sun.tools.javac.tree.JCTree;
83 import com.sun.tools.javac.tree.JCTree.*; 83 import com.sun.tools.javac.tree.JCTree.*;
84 import com.sun.tools.javac.tree.TreeCopier; 84 import com.sun.tools.javac.tree.TreeCopier;
85 import com.sun.tools.javac.tree.TreeInfo; 85 import com.sun.tools.javac.tree.TreeInfo;
86 import com.sun.tools.javac.tree.TreeMaker; 86 import com.sun.tools.javac.tree.TreeMaker;
87 import com.sun.tools.javac.util.Abort;
87 import com.sun.tools.javac.util.Assert; 88 import com.sun.tools.javac.util.Assert;
88 import com.sun.tools.javac.util.Context; 89 import com.sun.tools.javac.util.Context;
89 import com.sun.tools.javac.util.JCDiagnostic; 90 import com.sun.tools.javac.util.JCDiagnostic;
90 import com.sun.tools.javac.util.List; 91 import com.sun.tools.javac.util.List;
91 import com.sun.tools.javac.util.ListBuffer; 92 import com.sun.tools.javac.util.ListBuffer;
234 } 235 }
235 236
236 public Element getElement(TreePath path) { 237 public Element getElement(TreePath path) {
237 JCTree tree = (JCTree) path.getLeaf(); 238 JCTree tree = (JCTree) path.getLeaf();
238 Symbol sym = TreeInfo.symbolFor(tree); 239 Symbol sym = TreeInfo.symbolFor(tree);
239 if (sym == null && TreeInfo.isDeclaration(tree)) { 240 if (sym == null) {
240 for (TreePath p = path; p != null; p = p.getParentPath()) { 241 if (TreeInfo.isDeclaration(tree)) {
241 JCTree t = (JCTree) p.getLeaf(); 242 for (TreePath p = path; p != null; p = p.getParentPath()) {
242 if (t.hasTag(JCTree.Tag.CLASSDEF)) { 243 JCTree t = (JCTree) p.getLeaf();
243 JCClassDecl ct = (JCClassDecl) t; 244 if (t.hasTag(JCTree.Tag.CLASSDEF)) {
244 if (ct.sym != null) { 245 JCClassDecl ct = (JCClassDecl) t;
245 if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) { 246 if (ct.sym != null) {
246 attr.attribClass(ct.pos(), ct.sym); 247 if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
247 sym = TreeInfo.symbolFor(tree); 248 attr.attribClass(ct.pos(), ct.sym);
249 sym = TreeInfo.symbolFor(tree);
250 }
251 break;
248 } 252 }
249 break;
250 } 253 }
254 }
255 } else if (tree.hasTag(Tag.TOPLEVEL)) {
256 JCCompilationUnit cu = (JCCompilationUnit) tree;
257 if (cu.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) {
258 sym = cu.packge;
251 } 259 }
252 } 260 }
253 } 261 }
254 return sym; 262 return sym;
255 } 263 }
330 types.isSubtypeUnchecked(vsym.enclClass().asType(), msym.enclClass().asType()))) { 338 types.isSubtypeUnchecked(vsym.enclClass().asType(), msym.enclClass().asType()))) {
331 return vsym; 339 return vsym;
332 } else { 340 } else {
333 return msym; 341 return msym;
334 } 342 }
343 } catch (Abort e) { // may be thrown by Check.completionError in case of bad class file
344 return null;
335 } finally { 345 } finally {
336 log.popDiagnosticHandler(deferredDiagnosticHandler); 346 log.popDiagnosticHandler(deferredDiagnosticHandler);
337 } 347 }
338 } 348 }
339 349

mercurial