aboutsummaryrefslogtreecommitdiff
path: root/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-09-25 01:19:55 +0200
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-09-25 01:19:55 +0200
commit69011b90d8e9d15dbf45479df2f4f08658970a16 (patch)
tree7fda0f5c5f70428740801cd4e18a71e1a6fd8324 /src/utils/lombok/javac/java8/CommentCollectingTokenizer.java
parent230cd667657ab5c1e07819b18294c698bf17f9a5 (diff)
downloadlombok-69011b90d8e9d15dbf45479df2f4f08658970a16.tar.gz
lombok-69011b90d8e9d15dbf45479df2f4f08658970a16.tar.bz2
lombok-69011b90d8e9d15dbf45479df2f4f08658970a16.zip
[jdk13] Added support for printing text blocks (triple quoted strings) in text block form
Diffstat (limited to 'src/utils/lombok/javac/java8/CommentCollectingTokenizer.java')
-rw-r--r--src/utils/lombok/javac/java8/CommentCollectingTokenizer.java25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java b/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java
index 1834fb00..08477e61 100644
--- a/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java
+++ b/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 The Project Lombok Authors.
+ * Copyright (C) 2013-2019 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,19 +39,30 @@ import com.sun.tools.javac.util.ListBuffer;
class CommentCollectingTokenizer extends JavaTokenizer {
private int prevEndPosition = 0;
private final ListBuffer<CommentInfo> comments = new ListBuffer<CommentInfo>();
+ private final ListBuffer<Integer> textBlockStarts;
private int endComment = 0;
-
- CommentCollectingTokenizer(ScannerFactory fac, char[] buf, int inputLength) {
+
+ CommentCollectingTokenizer(ScannerFactory fac, char[] buf, int inputLength, boolean findTextBlocks) {
super(fac, new PositionUnicodeReader(fac, buf, inputLength));
+ textBlockStarts = findTextBlocks ? new ListBuffer<Integer>() : null;
}
- CommentCollectingTokenizer(ScannerFactory fac, CharBuffer buf) {
+ CommentCollectingTokenizer(ScannerFactory fac, CharBuffer buf, boolean findTextBlocks) {
super(fac, new PositionUnicodeReader(fac, buf));
+ textBlockStarts = findTextBlocks ? new ListBuffer<Integer>() : null;
+ }
+
+ int pos() {
+ return ((PositionUnicodeReader) reader).pos();
}
@Override public Token readToken() {
Token token = super.readToken();
- prevEndPosition = ((PositionUnicodeReader)reader).pos();
+ prevEndPosition = pos();
+ if (textBlockStarts != null && (prevEndPosition - token.pos > 5) && token.getClass().getSimpleName().equals("StringToken")) {
+ char[] start = reader.getRawCharacters(token.pos, token.pos + 3);
+ if (start[0] == '"' && start[1] == '"' && start[2] == '"') textBlockStarts.add(token.pos);
+ }
return token;
}
@@ -113,6 +124,10 @@ class CommentCollectingTokenizer extends JavaTokenizer {
return comments.toList();
}
+ public List<Integer> getTextBlockStarts() {
+ return textBlockStarts == null ? List.<Integer>nil() : textBlockStarts.toList();
+ }
+
static class PositionUnicodeReader extends UnicodeReader {
protected PositionUnicodeReader(ScannerFactory sf, char[] input, int inputLength) {
super(sf, input, inputLength);