761 return null; |
761 return null; |
762 } |
762 } |
763 } |
763 } |
764 |
764 |
765 public static Symbol symbolFor(JCTree node) { |
765 public static Symbol symbolFor(JCTree node) { |
|
766 Symbol sym = symbolForImpl(node); |
|
767 |
|
768 return sym != null ? sym.baseSymbol() : null; |
|
769 } |
|
770 |
|
771 private static Symbol symbolForImpl(JCTree node) { |
766 node = skipParens(node); |
772 node = skipParens(node); |
767 switch (node.getTag()) { |
773 switch (node.getTag()) { |
|
774 case TOPLEVEL: |
|
775 return ((JCCompilationUnit) node).packge; |
768 case CLASSDEF: |
776 case CLASSDEF: |
769 return ((JCClassDecl) node).sym; |
777 return ((JCClassDecl) node).sym; |
770 case METHODDEF: |
778 case METHODDEF: |
771 return ((JCMethodDecl) node).sym; |
779 return ((JCMethodDecl) node).sym; |
772 case VARDEF: |
780 case VARDEF: |
773 return ((JCVariableDecl) node).sym; |
781 return ((JCVariableDecl) node).sym; |
|
782 case IDENT: |
|
783 return ((JCIdent) node).sym; |
|
784 case SELECT: |
|
785 return ((JCFieldAccess) node).sym; |
|
786 case REFERENCE: |
|
787 return ((JCMemberReference) node).sym; |
|
788 case NEWCLASS: |
|
789 return ((JCNewClass) node).constructor; |
|
790 case APPLY: |
|
791 return symbolFor(((JCMethodInvocation) node).meth); |
|
792 case TYPEAPPLY: |
|
793 return symbolFor(((JCTypeApply) node).clazz); |
|
794 case ANNOTATION: |
|
795 case TYPE_ANNOTATION: |
|
796 case TYPEPARAMETER: |
|
797 if (node.type != null) |
|
798 return node.type.tsym; |
|
799 return null; |
774 default: |
800 default: |
775 return null; |
801 return null; |
776 } |
802 } |
777 } |
803 } |
778 |
804 |