Empty lines remove when using ASTParser [message #1403445] |
Wed, 23 July 2014 17:21 |
Pedro Quintas Messages: 1 Registered: July 2014 |
Junior Member |
|
|
Hi guys,
I'm trying to use ASTParser to make a merge between two Java Files.
But when I parse the file, all empty line are deleted. I allready try to use the "DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE" option, but no matter I do all the empty line in the Source code are deleted.
For example:
Original Code
-------------
...
if ( x == 2 ) {
System.out.print("2 ...");
}
if ( x == 3 ) {
System.out.print("3 ---");
}
...
Final Code After apply ASTParser
--------------------------------
...
if ( x == 2 ) {
System.out.print("2 ...");
}
if ( x == 3 ) {
System.out.print("3 ---");
}
...
Diff: Empty line between the first "if" and de second "if", and between the last "}" and the last "..."
This is the code that I'm using (+/-):
ASTParser astParser = ASTParser.newParser(AST.JLS3);
astParser.setSource(newJavaSource.toCharArray());
CompilationUnit cu = (CompilationUnit) astParser.createAST(null);
NewJavaFileVisitor newVisitor = new NewJavaFileVisitor();
cu.accept(newVisitor);
...
The "NewJavaFileVisitor" class extends ASTVisitor and has implemented the following visit methods:
public boolean visit(FieldDeclaration node)
public boolean visit(MethodDeclaration node)
public boolean visit(TypeDeclaration node)
public boolean visit(CompilationUnit node)
This class store the methods found in a Array "List<ASTNode> newNodes". The ASTNode that are store in this array, don't have the empty lines.
Any ideias how to solve my problem?
Thanks,
Kintas
|
|
|
Powered by
FUDForum. Page generated in 0.03947 seconds