Use Matcher from pre-compiled Pattern rather than String for replaceAll

Closes gh-14483
This commit is contained in:
durigon
2018-09-16 11:42:49 +09:00
committed by Andy Wilkinson
parent 11016bc7f4
commit 7aaeefbc0e
8 changed files with 44 additions and 10 deletions

View File

@@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.annotation.processing.ProcessingEnvironment;
@@ -61,6 +62,8 @@ class TypeUtils {
private static final Map<String, TypeKind> WRAPPER_TO_PRIMITIVE;
private static final Pattern NEW_LINE_PATTERN = Pattern.compile("[\r\n]+");
static {
Map<String, TypeKind> primitives = new HashMap<>();
PRIMITIVE_WRAPPERS.forEach(
@@ -131,7 +134,7 @@ class TypeUtils {
String javadoc = (element != null)
? this.env.getElementUtils().getDocComment(element) : null;
if (javadoc != null) {
javadoc = javadoc.replaceAll("[\r\n]+", "").trim();
javadoc = NEW_LINE_PATTERN.matcher(javadoc).replaceAll("").trim();
}
return "".equals(javadoc) ? null : javadoc;
}