diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/delombok/lombok/delombok/CommentPreservingParser.java | 30 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/PrettyCommentsPrinter.java | 10 |
2 files changed, 25 insertions, 15 deletions
diff --git a/src/delombok/lombok/delombok/CommentPreservingParser.java b/src/delombok/lombok/delombok/CommentPreservingParser.java index c85124b5..19219d93 100644 --- a/src/delombok/lombok/delombok/CommentPreservingParser.java +++ b/src/delombok/lombok/delombok/CommentPreservingParser.java @@ -25,29 +25,43 @@ import java.io.IOException; import java.io.Writer; import com.sun.tools.javac.main.JavaCompiler; +import com.sun.tools.javac.main.OptionName; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.Options; public class CommentPreservingParser { - private final JavaCompiler compiler; - private final Context context; - public CommentPreservingParser(Context context) { - this.context = context; + private final String encoding; + + public CommentPreservingParser() { + this("utf-8"); + } + + public CommentPreservingParser(String encoding) { + this.encoding = encoding; + } + + public ParseResult parseFile(String fileName) throws IOException { + Context context = new Context(); + + Options.instance(context).put(OptionName.ENCODING, encoding); + CommentCollectingScanner.Factory.preRegister(context); - compiler = new JavaCompiler(context) { + + JavaCompiler compiler = new JavaCompiler(context) { @Override protected boolean keepComments() { return true; } }; compiler.genEndPos = true; - } - - public ParseResult parseFile(String fileName) throws IOException { + Comments comments = new Comments(); context.put(Comments.class, comments); + + comments.comments = List.nil(); @SuppressWarnings("deprecation") JCCompilationUnit cu = compiler.parse(fileName); return new ParseResult(comments.comments, cu); diff --git a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java index c6b58a31..2fb62e53 100644 --- a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java +++ b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java @@ -184,10 +184,6 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { */ Writer out; - /** Indentation width (can be reassigned from outside). - */ - public int width = 4; - /** The current left margin. */ int lmargin = 0; @@ -205,19 +201,19 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { */ void align() throws IOException { newLine = false; - for (int i = 0; i < lmargin; i++) out.write(" "); + for (int i = 0; i < lmargin; i++) out.write("\t"); } /** Increase left margin by indentation width. */ void indent() { - lmargin = lmargin + width; + lmargin++; } /** Decrease left margin by indentation width. */ void undent() { - lmargin = lmargin - width; + lmargin--; } /** Enter a new precedence level. Emit a `(' if new precedence level |