Skip to content

Instantly share code, notes, and snippets.

@rylan
Created October 13, 2011 19:37
Show Gist options
  • Save rylan/1285281 to your computer and use it in GitHub Desktop.
Save rylan/1285281 to your computer and use it in GitHub Desktop.
Get an ASTNode from an ICompilationUnit (Eclipse JDT)
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.AST;
public ASTUtil {
public static ASTNode getASTNode(ICompilationUnit unit) {
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(unit);
parser.setResolveBindings(true);
return parser.createAST(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment