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

changeset 672
ea54372637a5
parent 581
f2fdd52e4e87
child 682
6e2ccba61117
     1.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Fri Sep 03 12:00:21 2010 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Mon Sep 06 12:55:09 2010 -0700
     1.3 @@ -45,6 +45,7 @@
     1.4  import com.sun.source.util.SourcePositions;
     1.5  import com.sun.source.util.TreePath;
     1.6  import com.sun.source.util.Trees;
     1.7 +import com.sun.tools.javac.code.Flags;
     1.8  import com.sun.tools.javac.code.Symbol.ClassSymbol;
     1.9  import com.sun.tools.javac.code.Symbol.TypeSymbol;
    1.10  import com.sun.tools.javac.code.Symbol;
    1.11 @@ -189,8 +190,24 @@
    1.12      }
    1.13  
    1.14      public Element getElement(TreePath path) {
    1.15 -        Tree t = path.getLeaf();
    1.16 -        return TreeInfo.symbolFor((JCTree) t);
    1.17 +        JCTree tree = (JCTree) path.getLeaf();
    1.18 +        Symbol sym = TreeInfo.symbolFor(tree);
    1.19 +        if (sym == null && TreeInfo.isDeclaration(tree)) {
    1.20 +            for (TreePath p = path; p != null; p = p.getParentPath()) {
    1.21 +                JCTree t = (JCTree) p.getLeaf();
    1.22 +                if (t.getTag() == JCTree.CLASSDEF) {
    1.23 +                    JCClassDecl ct = (JCClassDecl) t;
    1.24 +                    if (ct.sym != null) {
    1.25 +                        if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
    1.26 +                            attr.attribClass(ct.pos(), ct.sym);
    1.27 +                            sym = TreeInfo.symbolFor(tree);
    1.28 +                        }
    1.29 +                        break;
    1.30 +                    }
    1.31 +                }
    1.32 +            }
    1.33 +        }
    1.34 +        return sym;
    1.35      }
    1.36  
    1.37      public TypeMirror getTypeMirror(TreePath path) {

mercurial