Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Creating a class, displaying it in the editor
Creating a class, displaying it in the editor [message #226207] Mon, 20 March 2006 17:54 Go to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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
Previous Topic:rename() does nothing for IPackageFragment
Next Topic:Ant and XML namespace
Goto Forum:
  


Current Time: Fri Nov 07 05:23:24 EST 2025

Powered by FUDForum. Page generated in 0.04934 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top