netbeans-no-javac-patch / javac-trees-hack

# HG changeset patch
# Parent e345afa60aade83dcb372fe21cb43fc6871f72df

diff -r e345afa60aad lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavacTrees.java
--- a/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavacTrees.java	Sat Oct 06 11:52:35 2012 -0700
+++ b/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavacTrees.java	Sat Oct 06 12:07:07 2012 -0700
@@ -42,10 +42,16 @@
 package org.netbeans.lib.nbjavac.services;
 
 import com.sun.source.tree.ClassTree;
+import com.sun.source.tree.MethodInvocationTree;
+import com.sun.source.tree.ParameterizedTypeTree;
+import com.sun.source.tree.Tree;
+import com.sun.source.util.TreePath;
 import com.sun.tools.javac.api.JavacTrees;
 import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.*;
 import com.sun.tools.javac.tree.TreeMaker;
 import com.sun.tools.javac.util.Context;
+import javax.lang.model.element.Element;
 import org.netbeans.lib.nbjavac.services.NBTreeMaker.IndexedClassDecl;
 
 /**
@@ -80,4 +86,37 @@
         };
     }
 
+    private Element elementFor(Tree tree) {
+        switch (tree.getKind()) {
+            case COMPILATION_UNIT:
+                return ((JCCompilationUnit) tree).packge;
+            case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE:
+                return ((JCClassDecl) tree).sym;
+            case METHOD:
+                return ((JCMethodDecl) tree).sym;
+            case VARIABLE:
+                return ((JCVariableDecl) tree).sym;
+            case IDENTIFIER:
+                return ((JCIdent) tree).sym;
+            case MEMBER_SELECT:
+                return ((JCFieldAccess) tree).sym;
+            case NEW_CLASS:
+                return ((JCNewClass) tree).constructor;
+            case METHOD_INVOCATION:
+                return elementFor(((MethodInvocationTree) tree).getMethodSelect());
+            case PARAMETERIZED_TYPE:
+                return elementFor(((ParameterizedTypeTree) tree).getType());
+            case ANNOTATION:
+            case TYPE_PARAMETER:
+                if (((JCTree) tree).type != null)
+                    return ((JCTree) tree).type.tsym;
+        }
+
+        return null;
+    }
+
+    @Override
+    public Element getElement(TreePath tp) {
+        return elementFor(tp.getLeaf());
+    }
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.