diff options
author | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2021-03-19 05:07:15 +0100 |
---|---|---|
committer | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2021-03-19 05:07:23 +0100 |
commit | c6076730de3b7b587ca0e1d6e31f5e7bd6ab6761 (patch) | |
tree | 4039fb8dfd85511483cab0bb25d4e1564c0e7a87 /src/utils/lombok/javac | |
parent | fccf57a2a531ae0fe9e7c0d1a1da54b8357131f5 (diff) | |
download | lombok-c6076730de3b7b587ca0e1d6e31f5e7bd6ab6761.tar.gz lombok-c6076730de3b7b587ca0e1d6e31f5e7bd6ab6761.tar.bz2 lombok-c6076730de3b7b587ca0e1d6e31f5e7bd6ab6761.zip |
[ecj] [bug-workarounds]
The last comment in a line is lost if the array handed to the scanner is exactly sized to the input to process.
Diffstat (limited to 'src/utils/lombok/javac')
-rw-r--r-- | src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java b/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java index 767cbf5b..f29f501b 100644 --- a/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java +++ b/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java @@ -75,8 +75,24 @@ public class CommentCollectingScannerFactory extends ScannerFactory { @SuppressWarnings("all") @Override public Scanner newScanner(CharSequence input, boolean keepDocComments) { - char[] array = input.toString().toCharArray(); - return newScanner(array, array.length, keepDocComments); + char[] array; + int limit; + if (input instanceof CharBuffer && ((CharBuffer) input).hasArray()) { + CharBuffer cb = (CharBuffer) input; + cb.compact().flip(); + array = cb.array(); + limit = cb.limit(); + } else { + array = input.toString().toCharArray(); + limit = array.length; + } + if (array.length == limit) { + // work around a bug where the last comment in a file falls away in this case. + char[] d = new char[limit + 1]; + System.arraycopy(array, 0, d, 0, limit); + array = d; + } + return newScanner(array, limit, keepDocComments); } @Override |