-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.java
More file actions
25 lines (20 loc) · 930 Bytes
/
Copy pathToken.java
File metadata and controls
25 lines (20 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package jtree.parser;
import org.apache.commons.text.StringEscapeUtils;
import lombok.NonNull;
import lombok.Value;
public @Value class Token<TokenType> {
TokenType type;
@NonNull String string;
@NonNull Position start, end;
@NonNull CharSequence line;
@Override
public String toString() {
var type = this.type.toString();
return String.format("%s(type=%s, string=%s, start=%s, end=%s, line=%s)",
getClass().getSimpleName(),
Character.isJavaIdentifierPart(type.charAt(0)) && Character.isJavaIdentifierPart(type.charAt(type.length()-1)) || type.charAt(0) == '\'' && type.charAt(type.length()-1) == '\'' && type.length() > 1? type : " " + type + " ",
'"' + StringEscapeUtils.escapeJava(string) + '"',
start, end,
'"' + StringEscapeUtils.escapeJava(line.toString()) + '"');
}
}