aboutsummaryrefslogtreecommitdiff
path: root/src/delombok
diff options
context:
space:
mode:
Diffstat (limited to 'src/delombok')
-rw-r--r--src/delombok/lombok/delombok/Comment.java59
-rw-r--r--src/delombok/lombok/delombok/Delombok.java26
-rw-r--r--src/delombok/lombok/delombok/DelombokResult.java2
-rw-r--r--src/delombok/lombok/delombok/PrettyCommentsPrinter.java5
-rw-r--r--src/delombok/lombok/delombok/java6/CommentCollectingScanner.java97
-rw-r--r--src/delombok/lombok/delombok/java6/CommentCollectingScannerFactory.java65
-rw-r--r--src/delombok/lombok/delombok/java7/CommentCollectingScanner.java95
-rw-r--r--src/delombok/lombok/delombok/java7/CommentCollectingScannerFactory.java66
8 files changed, 8 insertions, 407 deletions
diff --git a/src/delombok/lombok/delombok/Comment.java b/src/delombok/lombok/delombok/Comment.java
deleted file mode 100644
index 5a129788..00000000
--- a/src/delombok/lombok/delombok/Comment.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package lombok.delombok;
-
-public final class Comment {
-
- public enum StartConnection {
- START_OF_LINE,
- ON_NEXT_LINE,
- DIRECT_AFTER_PREVIOUS,
- AFTER_PREVIOUS
- }
-
- public enum EndConnection {
- DIRECT_AFTER_COMMENT,
- AFTER_COMMENT,
- ON_NEXT_LINE
- }
-
- final int pos;
- final int prevEndPos;
- final String content;
- final int endPos;
- final StartConnection start;
- final EndConnection end;
-
- public Comment(int prevEndPos, int pos, int endPos, String content, StartConnection start, EndConnection end) {
- this.pos = pos;
- this.prevEndPos = prevEndPos;
- this.endPos = endPos;
- this.content = content;
- this.start = start;
- this.end = end;
- }
-
- @Override
- public String toString() {
- return String.format("%d: %s (%s,%s)", pos, content, start, end);
- }
-}
diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java
index c5973dac..e069fa5f 100644
--- a/src/delombok/lombok/delombok/Delombok.java
+++ b/src/delombok/lombok/delombok/Delombok.java
@@ -44,7 +44,7 @@ import java.util.Map;
import javax.tools.DiagnosticListener;
import javax.tools.JavaFileObject;
-import lombok.Lombok;
+import lombok.javac.Comments;
import lombok.javac.LombokOptions;
import com.sun.tools.javac.main.JavaCompiler;
@@ -357,17 +357,6 @@ public class Delombok {
if (sourcepath != null) options.put(OptionName.SOURCEPATH, sourcepath);
options.put("compilePolicy", "attr");
- try {
- if (JavaCompiler.version().startsWith("1.6")) {
- Class.forName("lombok.delombok.java6.CommentCollectingScannerFactory").getMethod("preRegister", Context.class).invoke(null, context);
- } else {
- Class.forName("lombok.delombok.java7.CommentCollectingScannerFactory").getMethod("preRegister", Context.class).invoke(null, context);
- }
-
- } catch (Throwable t) {
- throw Lombok.sneakyThrow(t);
- }
-
JavaCompiler compiler = new JavaCompiler(context);
compiler.keepComments = true;
compiler.genEndPos = true;
@@ -380,8 +369,7 @@ public class Delombok {
for (File fileToParse : filesToParse) {
Comments comments = new Comments();
- context.put(Comments.class, (Comments) null);
- context.put(Comments.class, comments);
+ comments.register(context);
@SuppressWarnings("deprecation")
JCCompilationUnit unit = compiler.parse(fileToParse.getAbsolutePath());
@@ -398,7 +386,7 @@ public class Delombok {
JavaCompiler delegate = compiler.processAnnotations(compiler.enterTrees(toJavacList(roots)));
for (JCCompilationUnit unit : roots) {
- DelombokResult result = new DelombokResult(commentsMap.get(unit).comments.toList(), unit, force || options.changed.contains(unit));
+ DelombokResult result = new DelombokResult(commentsMap.get(unit).getComments().toList(), unit, force || options.changed.contains(unit));
if (verbose) feedback.printf("File: %s [%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged");
Writer rawWriter;
if (presetWriter != null) rawWriter = presetWriter;
@@ -416,14 +404,6 @@ public class Delombok {
return true;
}
- public static class Comments {
- public com.sun.tools.javac.util.ListBuffer<Comment> comments = com.sun.tools.javac.util.ListBuffer.lb();
-
- public void add(Comment comment) {
- comments.append(comment);
- }
- }
-
private static String canonical(File dir) {
try {
return dir.getCanonicalPath();
diff --git a/src/delombok/lombok/delombok/DelombokResult.java b/src/delombok/lombok/delombok/DelombokResult.java
index 717a3bf1..739dd873 100644
--- a/src/delombok/lombok/delombok/DelombokResult.java
+++ b/src/delombok/lombok/delombok/DelombokResult.java
@@ -26,6 +26,8 @@ import java.util.Date;
import javax.tools.JavaFileObject;
+import lombok.javac.Comment;
+
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.List;
diff --git a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java
index ae65719f..387938c6 100644
--- a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java
@@ -39,9 +39,10 @@ import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
-import lombok.delombok.Comment.EndConnection;
-import lombok.delombok.Comment.StartConnection;
+import lombok.javac.Comment;
import lombok.javac.Javac;
+import lombok.javac.Comment.EndConnection;
+import lombok.javac.Comment.StartConnection;
import com.sun.source.tree.Tree;
import com.sun.tools.javac.code.BoundKind;
diff --git a/src/delombok/lombok/delombok/java6/CommentCollectingScanner.java b/src/delombok/lombok/delombok/java6/CommentCollectingScanner.java
deleted file mode 100644
index c05fd158..00000000
--- a/src/delombok/lombok/delombok/java6/CommentCollectingScanner.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright © 2011 Reinier Zwitserloot and Roel Spilker.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package lombok.delombok.java6;
-
-import java.nio.CharBuffer;
-
-import lombok.delombok.Comment;
-import lombok.delombok.Comment.EndConnection;
-import lombok.delombok.Comment.StartConnection;
-import lombok.delombok.Delombok.Comments;
-
-
-import com.sun.tools.javac.parser.Scanner;
-
-public class CommentCollectingScanner extends Scanner {
- private final Comments comments;
- private int endComment = 0;
-
-
- public CommentCollectingScanner(CommentCollectingScannerFactory factory, CharBuffer charBuffer, Comments comments) {
- super(factory, charBuffer);
- this.comments = comments;
- }
-
- public CommentCollectingScanner(CommentCollectingScannerFactory factory, char[] input, int inputLength, Comments comments) {
- super(factory, input, inputLength);
- this.comments = comments;
- }
-
- @Override
- protected void processComment(CommentStyle style) {
- int prevEndPos = Math.max(prevEndPos(), endComment);
- int pos = pos();
- int endPos = endPos();
- endComment = endPos;
- String content = new String(getRawCharacters(pos, endPos));
- StartConnection start = determineStartConnection(prevEndPos, pos);
- EndConnection end = determineEndConnection(endPos);
-
- Comment comment = new Comment(prevEndPos, pos, endPos, content, start, end);
- comments.add(comment);
- }
-
- private EndConnection determineEndConnection(int pos) {
- boolean first = true;
- for (int i = pos;; i++) {
- char c = getRawCharacters(i, i + 1)[0];
- if (isNewLine(c)) {
- return EndConnection.ON_NEXT_LINE;
- }
- if (Character.isWhitespace(c)) {
- first = false;
- continue;
- }
- return first ? EndConnection.DIRECT_AFTER_COMMENT : EndConnection.AFTER_COMMENT;
- }
- }
-
- private StartConnection determineStartConnection(int from, int to) {
- if (from == to) {
- return StartConnection.DIRECT_AFTER_PREVIOUS;
- }
- char[] between = getRawCharacters(from, to);
- if (isNewLine(between[between.length - 1])) {
- return StartConnection.START_OF_LINE;
- }
- for (char c : between) {
- if (isNewLine(c)) {
- return StartConnection.ON_NEXT_LINE;
- }
- }
- return StartConnection.AFTER_PREVIOUS;
- }
-
- private boolean isNewLine(char c) {
- return c == '\n' || c == '\r';
- }
-}
diff --git a/src/delombok/lombok/delombok/java6/CommentCollectingScannerFactory.java b/src/delombok/lombok/delombok/java6/CommentCollectingScannerFactory.java
deleted file mode 100644
index 46d00551..00000000
--- a/src/delombok/lombok/delombok/java6/CommentCollectingScannerFactory.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright © 2011 Reinier Zwitserloot and Roel Spilker.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package lombok.delombok.java6;
-
-import java.nio.CharBuffer;
-
-import lombok.delombok.Delombok.Comments;
-
-import com.sun.tools.javac.parser.Scanner;
-import com.sun.tools.javac.util.Context;
-
-public class CommentCollectingScannerFactory extends Scanner.Factory {
- private final Context context;
-
- public static void preRegister(final Context context) {
- context.put(scannerFactoryKey, new Context.Factory<Scanner.Factory>() {
- public CommentCollectingScanner.Factory make() {
- return new CommentCollectingScannerFactory(context);
- }
-
- public CommentCollectingScanner.Factory make(Context c) {
- return new CommentCollectingScannerFactory(c);
- }
- });
- }
-
- /** Create a new scanner factory. */
- protected CommentCollectingScannerFactory(Context 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(char[] input, int inputLength) {
- return new CommentCollectingScanner(this, input, inputLength, context.get(Comments.class));
- }
-} \ No newline at end of file
diff --git a/src/delombok/lombok/delombok/java7/CommentCollectingScanner.java b/src/delombok/lombok/delombok/java7/CommentCollectingScanner.java
deleted file mode 100644
index a6301143..00000000
--- a/src/delombok/lombok/delombok/java7/CommentCollectingScanner.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright © 2011 Reinier Zwitserloot and Roel Spilker.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package lombok.delombok.java7;
-
-import java.nio.CharBuffer;
-
-import lombok.delombok.Comment;
-import lombok.delombok.Comment.EndConnection;
-import lombok.delombok.Comment.StartConnection;
-import lombok.delombok.Delombok.Comments;
-
-import com.sun.tools.javac.parser.Scanner;
-
-public class CommentCollectingScanner extends Scanner {
- private final Comments comments;
- private int endComment = 0;
-
- public CommentCollectingScanner(CommentCollectingScannerFactory factory, CharBuffer charBuffer, Comments comments) {
- super(factory, charBuffer);
- this.comments = comments;
- }
-
- public CommentCollectingScanner(CommentCollectingScannerFactory factory, char[] input, int inputLength, Comments comments) {
- super(factory, input, inputLength);
- this.comments = comments;
- }
-
- @Override
- protected void processComment(CommentStyle style) {
- int prevEndPos = Math.max(prevEndPos(), endComment);
- int pos = pos();
- int endPos = endPos();
- endComment = endPos;
- String content = new String(getRawCharacters(pos, endPos));
- StartConnection start = determineStartConnection(prevEndPos, pos);
- EndConnection end = determineEndConnection(endPos);
-
- Comment comment = new Comment(prevEndPos, pos, endPos, content, start, end);
- comments.add(comment);
- }
-
- private EndConnection determineEndConnection(int pos) {
- boolean first = true;
- for (int i = pos;; i++) {
- char c = getRawCharacters(i, i + 1)[0];
- if (isNewLine(c)) {
- return EndConnection.ON_NEXT_LINE;
- }
- if (Character.isWhitespace(c)) {
- first = false;
- continue;
- }
- return first ? EndConnection.DIRECT_AFTER_COMMENT : EndConnection.AFTER_COMMENT;
- }
- }
-
- private StartConnection determineStartConnection(int from, int to) {
- if (from == to) {
- return StartConnection.DIRECT_AFTER_PREVIOUS;
- }
- char[] between = getRawCharacters(from, to);
- if (isNewLine(between[between.length - 1])) {
- return StartConnection.START_OF_LINE;
- }
- for (char c : between) {
- if (isNewLine(c)) {
- return StartConnection.ON_NEXT_LINE;
- }
- }
- return StartConnection.AFTER_PREVIOUS;
- }
-
- private boolean isNewLine(char c) {
- return c == '\n' || c == '\r';
- }
-}
diff --git a/src/delombok/lombok/delombok/java7/CommentCollectingScannerFactory.java b/src/delombok/lombok/delombok/java7/CommentCollectingScannerFactory.java
deleted file mode 100644
index ce6ee71c..00000000
--- a/src/delombok/lombok/delombok/java7/CommentCollectingScannerFactory.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright © 2011 Reinier Zwitserloot and Roel Spilker.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package lombok.delombok.java7;
-
-import java.nio.CharBuffer;
-
-import lombok.delombok.Delombok.Comments;
-
-import com.sun.tools.javac.parser.Scanner;
-import com.sun.tools.javac.parser.ScannerFactory;
-import com.sun.tools.javac.util.Context;
-
-public class CommentCollectingScannerFactory extends ScannerFactory {
- private final Context context;
-
- public static void preRegister(final Context context) {
- context.put(scannerFactoryKey, new Context.Factory<ScannerFactory>() {
- public ScannerFactory make() {
- return new CommentCollectingScannerFactory(context);
- }
-
- @Override public ScannerFactory make(Context c) {
- return new CommentCollectingScannerFactory(c);
- }
- });
- }
-
- /** Create a new scanner factory. */
- protected CommentCollectingScannerFactory(Context context) {
- super(context);
- this.context = context;
- }
-
- @Override
- public Scanner newScanner(CharSequence input, boolean keepDocComments) {
- if (input instanceof CharBuffer) {
- return new CommentCollectingScanner(this, (CharBuffer)input, context.get(Comments.class));
- }
- char[] array = input.toString().toCharArray();
- return newScanner(array, array.length, keepDocComments);
- }
-
- @Override
- public Scanner newScanner(char[] input, int inputLength, boolean keepDocComments) {
- return new CommentCollectingScanner(this, input, inputLength, context.get(Comments.class));
- }
-}