/**
* Returns reference to ICompilationUnit object within the given project name and java file name.
*
* @param projectName
* Name of project created in Eclipse workspace.
* @param fileName
* packageName.JavaFileNameWithoutDotJava
*
* @return Instance of ICompilationUnit.
*/
public ICompilationUnit getCompilationUnit(final String projectName, final String fileName) throws Exception {
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IProject project = root.getProject(projectName);
IJavaProject javaProject = JavaCore.create(project);
IType lwType = javaProject.findType(fileName);
return lwType.getCompilationUnit();
}
public CompilationUnit parse(ICompilationUnit unit) {
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(unit); // set source
parser.setResolveBindings(true); // we need bindings later on
return (CompilationUnit) parser.createAST(null /* IProgressMonitor */); // parse
}