diff options
-rw-r--r-- | src/delombok/lombok/delombok/CommentCollectingScanner.java | 60 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/CommentPreservingParser.java | 10 |
2 files changed, 35 insertions, 35 deletions
diff --git a/src/delombok/lombok/delombok/CommentCollectingScanner.java b/src/delombok/lombok/delombok/CommentCollectingScanner.java index c38aef24..361d975c 100644 --- a/src/delombok/lombok/delombok/CommentCollectingScanner.java +++ b/src/delombok/lombok/delombok/CommentCollectingScanner.java @@ -29,55 +29,52 @@ import com.sun.tools.javac.parser.Scanner; import com.sun.tools.javac.util.Context; public class CommentCollectingScanner extends Scanner { - - private final Comments comments; + private final Comments comments; /** A factory for creating scanners. */ - public static class Factory extends Scanner.Factory { - - private final Context context; - + public static class Factory extends Scanner.Factory { + private final Context context; + public static void preRegister(final Context context) { - context.put(scannerFactoryKey, new Context.Factory<Scanner.Factory>() { + context.put(scannerFactoryKey, new Context.Factory<Scanner.Factory>() { public CommentCollectingScanner.Factory make() { - return new Factory(context); + return new Factory(context); } - }); + }); } - + /** Create a new scanner factory. */ protected Factory(Context context) { - super(context); + super(context); this.context = context; } - - @Override - public Scanner newScanner(CharSequence input) { - if (input instanceof CharBuffer) { - return new CommentCollectingScanner(this, (CharBuffer)input, context.get(Comments.class)); - } - char[] array = input.toString().toCharArray(); - return newScanner(array, array.length); - } + + @Override + public Scanner newScanner(CharSequence input) { + if (input instanceof CharBuffer) { + return new CommentCollectingScanner(this, (CharBuffer)input, context.get(Comments.class)); + } + char[] array = input.toString().toCharArray(); + return newScanner(array, array.length); + } + + @Override + public Scanner newScanner(char[] input, int inputLength) { + return new CommentCollectingScanner(this, input, inputLength, context.get(Comments.class)); + } + } - @Override - public Scanner newScanner(char[] input, int inputLength) { - return new CommentCollectingScanner(this, input, inputLength, context.get(Comments.class)); - } - } - public CommentCollectingScanner(CommentCollectingScanner.Factory factory, CharBuffer charBuffer, Comments comments) { super(factory, charBuffer); this.comments = comments; } - - + public CommentCollectingScanner(CommentCollectingScanner.Factory factory, char[] input, int inputLength, Comments comments) { super(factory, input, inputLength); this.comments = comments; } - + @Override protected void processComment(CommentStyle style) { int prevEndPos = prevEndPos(); @@ -86,8 +83,7 @@ public class CommentCollectingScanner extends Scanner { String content = new String(getRawCharacters(pos, endPos())); comments.add(prevEndPos, pos, endPos(), content, newLine); } - - + private boolean containsNewLine(int from, int to) { for (char c : getRawCharacters(from, to)) { if (c == '\n' || c == '\r') { @@ -96,4 +92,4 @@ public class CommentCollectingScanner extends Scanner { } return false; } -}
\ No newline at end of file +} diff --git a/src/delombok/lombok/delombok/CommentPreservingParser.java b/src/delombok/lombok/delombok/CommentPreservingParser.java index 9fd8778c..d353a9a6 100644 --- a/src/delombok/lombok/delombok/CommentPreservingParser.java +++ b/src/delombok/lombok/delombok/CommentPreservingParser.java @@ -43,9 +43,8 @@ import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Options; public class CommentPreservingParser { - private final String encoding; - + public CommentPreservingParser() { this("utf-8"); } @@ -73,6 +72,7 @@ public class CommentPreservingParser { context.put(Comments.class, comments); comments.comments = List.nil(); + @SuppressWarnings("deprecation") JCCompilationUnit cu = compiler.parse(fileName); @@ -130,5 +130,9 @@ public class CommentPreservingParser { out.write("// Generated by delombok at " + new Date() + "\n"); compilationUnit.accept(new PrettyCommentsPrinter(out, compilationUnit, comments)); } + + public boolean isChanged() { + return changed; + } } -}
\ No newline at end of file +} |