Skip to content

Instantly share code, notes, and snippets.

@jbranchaud
Created February 7, 2012 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbranchaud/1761964 to your computer and use it in GitHub Desktop.
Save jbranchaud/1761964 to your computer and use it in GitHub Desktop.
Create an ASTParser (CompilationUnit) for the JDT using a char[]
public CompilationUnit createParser(char[] contents) {
// Create the ASTParser which will be a CompilationUnit
ASTParser parser = ASTParser.newParser(AST.JLS4);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(contents);
parser.setResolveBindings(true);
CompilationUnit parse = (CompilationUnit) parser.createAST(null);
return parse;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment