From 4609fc3f00a924dc9f6a367aec4031a80d471af6 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 28 Feb 2017 12:51:11 -0800 Subject: [PATCH] Moving Pattern to static constant --- .../pmd/lang/apex/rule/security/ApexCRUDViolationRule.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java index 5c655fb3d6..16458a3db4 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java @@ -57,6 +57,8 @@ import com.google.common.collect.ListMultimap; */ public class ApexCRUDViolationRule extends AbstractApexRule { private static final Pattern VOID_OR_STRING_PATTERN = Pattern.compile("^(string|void)$", Pattern.CASE_INSENSITIVE); + private static final Pattern SELECT_FROM_PATTERN = Pattern.compile("^[\\S|\\s]+?FROM[\\s]+?(\\S+)", + Pattern.CASE_INSENSITIVE); private final HashMap varToTypeMapping = new HashMap<>(); private final ListMultimap typeToDMLOperationMapping = ArrayListMultimap.create(); @@ -543,7 +545,7 @@ public class ApexCRUDViolationRule extends AbstractApexRule { private String getTypeFromSOQLQuery(final ASTSoqlExpression node) { final String canonQuery = node.getNode().getCanonicalQuery(); - Matcher m = Pattern.compile("^[\\S|\\s]+?FROM[\\s]+?(\\S+)", Pattern.CASE_INSENSITIVE).matcher(canonQuery); + Matcher m = SELECT_FROM_PATTERN.matcher(canonQuery); while (m.find()) { return new StringBuffer().append(node.getNode().getDefiningType().getApexName()).append(":") .append(m.group(1)).toString();