Code formatting problem of AST (import statement) [message #244565] |
Fri, 15 June 2007 23:07  |
Eclipse User |
|
|
|
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 05:53  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.02804 seconds