AST: public static CompilationUnit parseCompilationUnit(char[] source, String unitName, IJavaProject javaProject, boolean resolveBindings) { CompilationUnitDeclaration compilationUnitDeclaration = null; if (resolveBindings) { // If resolveBindings is true, we need to record the mod count // once newAST has been constructed. If the mod count goes above // this level, someone is modifying the AST and all bets are off // regarding resolved bindings. All existing binding info should be // discarded, and the various public resolveBinding methods should // thereafter return null. try { compilationUnitDeclaration = CompilationUnitResolver.resolve( source, unitName, javaProject, new AbstractSyntaxTreeVisitorAdapter()); if (compilationUnitDeclaration != null && source != null) { ASTConverter converter = new ASTConverter(true); AST ast = new AST(); ast.setBindingResolver(new DefaultBindingResolver(compilationUnitDeclaration.scope)); converter.setAST(ast); CompilationUnit cu = converter.convert(compilationUnitDeclaration, source); // line end table should be extracted from scanner cu.setLineEndTable(compilationUnitDeclaration.compilationResult.lineSeparatorPositions); // line end table should be extracted from scanner //cu.setLineEndTable(parser.scanner.lineEnds); return cu; } else { return null; } } catch(JavaModelException e) { } } else { return parseCompilationUnit(source); } return null; } CompilationUnitResolver: protected static INameEnvironment getNameEnvironment(IJavaProject javaProject) throws JavaModelException { return (SearchableEnvironment) ((JavaProject)javaProject).getSearchableNameEnvironment(); } public static CompilationUnitDeclaration resolve( char[] source, String unitName, IJavaProject javaProject, IAbstractSyntaxTreeVisitor visitor) throws JavaModelException { CompilationUnitResolver compilationUnitVisitor = new CompilationUnitResolver( getNameEnvironment(javaProject), getHandlingPolicy(), JavaCore.getOptions(), getRequestor(), getProblemFactory(visitor)); CompilationUnitDeclaration unit = null; try { String encoding = (String) JavaCore.getOptions().get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; //$NON-NLS-1$ unit = compilationUnitVisitor.resolve( new BasicCompilationUnit( source, unitName, encoding)); return unit; } finally { if (unit != null) { unit.cleanUp(); } } }