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

changeset 1455
75ab654b5cd5
parent 1416
c0f0c41cafa0
child 1704
ed918a442b83
     1.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Mon Dec 17 14:54:42 2012 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Mon Dec 17 07:47:05 2012 -0800
     1.3 @@ -84,6 +84,7 @@
     1.4  import com.sun.tools.javac.tree.TreeCopier;
     1.5  import com.sun.tools.javac.tree.TreeInfo;
     1.6  import com.sun.tools.javac.tree.TreeMaker;
     1.7 +import com.sun.tools.javac.util.Abort;
     1.8  import com.sun.tools.javac.util.Assert;
     1.9  import com.sun.tools.javac.util.Context;
    1.10  import com.sun.tools.javac.util.JCDiagnostic;
    1.11 @@ -236,19 +237,26 @@
    1.12      public Element getElement(TreePath path) {
    1.13          JCTree tree = (JCTree) path.getLeaf();
    1.14          Symbol sym = TreeInfo.symbolFor(tree);
    1.15 -        if (sym == null && TreeInfo.isDeclaration(tree)) {
    1.16 -            for (TreePath p = path; p != null; p = p.getParentPath()) {
    1.17 -                JCTree t = (JCTree) p.getLeaf();
    1.18 -                if (t.hasTag(JCTree.Tag.CLASSDEF)) {
    1.19 -                    JCClassDecl ct = (JCClassDecl) t;
    1.20 -                    if (ct.sym != null) {
    1.21 -                        if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
    1.22 -                            attr.attribClass(ct.pos(), ct.sym);
    1.23 -                            sym = TreeInfo.symbolFor(tree);
    1.24 +        if (sym == null) {
    1.25 +            if (TreeInfo.isDeclaration(tree)) {
    1.26 +                for (TreePath p = path; p != null; p = p.getParentPath()) {
    1.27 +                    JCTree t = (JCTree) p.getLeaf();
    1.28 +                    if (t.hasTag(JCTree.Tag.CLASSDEF)) {
    1.29 +                        JCClassDecl ct = (JCClassDecl) t;
    1.30 +                        if (ct.sym != null) {
    1.31 +                            if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
    1.32 +                                attr.attribClass(ct.pos(), ct.sym);
    1.33 +                                sym = TreeInfo.symbolFor(tree);
    1.34 +                            }
    1.35 +                            break;
    1.36                          }
    1.37 -                        break;
    1.38                      }
    1.39                  }
    1.40 +            } else if (tree.hasTag(Tag.TOPLEVEL)) {
    1.41 +                JCCompilationUnit cu = (JCCompilationUnit) tree;
    1.42 +                if (cu.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) {
    1.43 +                    sym = cu.packge;
    1.44 +                }
    1.45              }
    1.46          }
    1.47          return sym;
    1.48 @@ -332,6 +340,8 @@
    1.49              } else {
    1.50                  return msym;
    1.51              }
    1.52 +        } catch (Abort e) { // may be thrown by Check.completionError in case of bad class file
    1.53 +            return null;
    1.54          } finally {
    1.55              log.popDiagnosticHandler(deferredDiagnosticHandler);
    1.56          }

mercurial