Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Code formatting problem of AST (import statement)
Code formatting problem of AST (import statement) [message #244565] Sat, 16 June 2007 03:07 Go to next message
Eddie Man is currently offline Eddie ManFriend
Messages: 102
Registered: July 2009
Senior Member
Hi all,

I found that the code formatting of AST Rewrite is not works for the
import statement. I had a AST model of the existing code, and I would
like to add a import declaration on it:

CompilationUnit unit;
unit.recordModifications();
AST ast = unit.getAST();
.....
ImportDeclaration newImport = ast.newImportDeclaration();
newImport.setOnDemand(true);
newImport.setName(ast.newSimpleName("abc.x"));
unit.imports().add(newImport);
....
unit.rewrite(document, JavaCore.getOptions());


After execute the above code, the code will like that:
import abc.x;public class MyClass {
}


When I press CTRL+SHIFT+F, then the code will formatted normally.

Did anyone know what is the problem? and how to solve it?

Many thanks,
Eddie
Re: Code formatting problem of AST (import statement) [message #244619 is a reply to message #244565] Mon, 18 June 2007 09:53 Go to previous message
Eddie Man is currently offline Eddie ManFriend
Messages: 102
Registered: July 2009
Senior Member
I found that the problem only exists in the default package.

Eddie Man wrote:
> Hi all,
>
> I found that the code formatting of AST Rewrite is not works for the
> import statement. I had a AST model of the existing code, and I would
> like to add a import declaration on it:
>
> CompilationUnit unit;
> unit.recordModifications();
> AST ast = unit.getAST();
> ....
> ImportDeclaration newImport = ast.newImportDeclaration();
> newImport.setOnDemand(true);
> newImport.setName(ast.newSimpleName("abc.x"));
> unit.imports().add(newImport);
> ...
> unit.rewrite(document, JavaCore.getOptions());
>
>
> After execute the above code, the code will like that:
> import abc.x;public class MyClass {
> }
>
>
> When I press CTRL+SHIFT+F, then the code will formatted normally.
>
> Did anyone know what is the problem? and how to solve it?
>
> Many thanks,
> Eddie
Previous Topic:How to set up a JAVA_HOME based JRE ?
Next Topic:Defect in flow analysis ?
Goto Forum:
  


Current Time: Sat Jul 13 16:58:02 GMT 2024

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

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

Back to the top