| Creating a class, displaying it in the editor [message #226207] |
Mon, 20 March 2006 17:54  |
Eclipse User |
|
|
|
Originally posted by: ara_vartanian.yahoo.com
I must be missing something conceptually. The code snippet below does
*nothing*. I am using 3.2 M5. The doc seems well-formatted after
TextEdit.apply() is called, but the resource does not appear in the
workspace (or in any editor window)
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource("".toCharArray());
CompilationUnit unit = (CompilationUnit) parser.createAST(null);
unit.recordModifications();
AST ast = unit.getAST();
PackageDeclaration packageDeclaration = ast.newPackageDeclaration();
unit.setPackage(packageDeclaration);
packageDeclaration.setName(ast.newSimpleName("someName"));
Document doc = new Document();
TextEdit edits = unit.rewrite(doc, null);
edits.apply(doc);
JavaUI.revealInEditor(getEditor(), unit.getJavaElement());
Any help would be appreciated. Obviously, I am missing something basic.
|
|
|
| Re: Creating a class, displaying it in the editor [message #226454 is a reply to message #226207] |
Fri, 24 March 2006 06:29  |
Eclipse User |
|
|
|
Ara Vartanian wrote:
> I must be missing something conceptually. The code snippet below does
> *nothing*. I am using 3.2 M5. The doc seems well-formatted after
> TextEdit.apply() is called, but the resource does not appear in the
> workspace (or in any editor window)
>
> ASTParser parser = ASTParser.newParser(AST.JLS3);
> parser.setSource("".toCharArray());
> CompilationUnit unit = (CompilationUnit) parser.createAST(null);
> unit.recordModifications();
> AST ast = unit.getAST();
> PackageDeclaration packageDeclaration = ast.newPackageDeclaration();
> unit.setPackage(packageDeclaration);
> packageDeclaration.setName(ast.newSimpleName("someName"));
> Document doc = new Document();
> TextEdit edits = unit.rewrite(doc, null);
> edits.apply(doc);
> JavaUI.revealInEditor(getEditor(), unit.getJavaElement());
>
> Any help would be appreciated. Obviously, I am missing something basic.
>
You forgot to write the document back to the filesystem. You have to
call unit.getBuffer().setcontents(...) first.
Cheers
Tobias
|
|
|
Powered by
FUDForum. Page generated in 0.04096 seconds