Package org.sonar.java.checks.regex
Class AbstractRegexCheck
- java.lang.Object
-
- org.sonar.java.ast.visitors.SubscriptionVisitor
-
- org.sonar.plugins.java.api.IssuableSubscriptionVisitor
-
- org.sonar.java.checks.methods.AbstractMethodDetection
-
- org.sonar.java.checks.regex.AbstractRegexCheck
-
- All Implemented Interfaces:
RegexCheck,JavaCheck,JavaFileScanner
- Direct Known Subclasses:
AnchorPrecedenceCheck,CanonEqFlagInRegexCheck,DuplicatesInCharacterClassCheck,EmptyLineRegexCheck,EmptyStringRepetitionCheck,GraphemeClustersInClassesCheck,ImpossibleRegexCheck,InvalidRegexCheck,RedosCheck,RegexComplexityCheck,ReluctantQuantifierCheck,StringReplaceCheck,UnicodeAwareCharClassesCheck,UnicodeCaseCheck,UnusedGroupNamesCheck
public abstract class AbstractRegexCheck extends AbstractMethodDetection implements RegexCheck
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.sonar.java.regex.RegexCheck
RegexCheck.RegexIssueLocation
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringJAVA_LANG_STRINGprotected static MethodMatchersREGEX_METHODS-
Fields inherited from class org.sonar.java.ast.visitors.SubscriptionVisitor
context
-
-
Constructor Summary
Constructors Constructor Description AbstractRegexCheck()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidcheckRegex(RegexParseResult regexForLiterals, MethodInvocationTree mit)protected static Optional<ExpressionTree>getFinalVariableInitializer(IdentifierTree identifier)protected static Optional<ExpressionTree>getFlagsTree(MethodInvocationTree mit)protected static Optional<LiteralTree[]>getLiterals(ExpressionTree expr)protected MethodMatchersgetMethodInvocationMatchers()List<Tree.Kind>nodesToVisit()protected voidonMethodInvocationFound(MethodInvocationTree mit)protected RegexParseResultregexForLiterals(FlagSet flags, LiteralTree... literals)voidreportIssue(RegexSyntaxElement regexTree, String message, Integer cost, List<RegexCheck.RegexIssueLocation> secondaries)voidreportIssue(Tree javaTree, String message, Integer cost, List<RegexCheck.RegexIssueLocation> secondaries)voidsetContext(JavaFileScannerContext context)-
Methods inherited from class org.sonar.java.checks.methods.AbstractMethodDetection
onConstructorFound, onMethodReferenceFound, visitNode
-
Methods inherited from class org.sonar.plugins.java.api.IssuableSubscriptionVisitor
addIssue, addIssueOnFile, reportIssue, reportIssue, reportIssue, scanTree
-
Methods inherited from class org.sonar.java.ast.visitors.SubscriptionVisitor
hasSemantic, leaveFile, leaveNode, scanFile, visitToken, visitTrivia
-
-
-
-
Field Detail
-
JAVA_LANG_STRING
protected static final String JAVA_LANG_STRING
- See Also:
- Constant Field Values
-
REGEX_METHODS
protected static final MethodMatchers REGEX_METHODS
-
-
Method Detail
-
setContext
public final void setContext(JavaFileScannerContext context)
- Overrides:
setContextin classSubscriptionVisitor
-
nodesToVisit
public List<Tree.Kind> nodesToVisit()
- Overrides:
nodesToVisitin classAbstractMethodDetection
-
getMethodInvocationMatchers
protected MethodMatchers getMethodInvocationMatchers()
- Specified by:
getMethodInvocationMatchersin classAbstractMethodDetection
-
onMethodInvocationFound
protected void onMethodInvocationFound(MethodInvocationTree mit)
- Overrides:
onMethodInvocationFoundin classAbstractMethodDetection
-
regexForLiterals
protected final RegexParseResult regexForLiterals(FlagSet flags, LiteralTree... literals)
-
getLiterals
protected static Optional<LiteralTree[]> getLiterals(ExpressionTree expr)
-
getFinalVariableInitializer
protected static Optional<ExpressionTree> getFinalVariableInitializer(IdentifierTree identifier)
-
checkRegex
public abstract void checkRegex(RegexParseResult regexForLiterals, MethodInvocationTree mit)
-
reportIssue
public final void reportIssue(RegexSyntaxElement regexTree, String message, @Nullable Integer cost, List<RegexCheck.RegexIssueLocation> secondaries)
-
reportIssue
public final void reportIssue(Tree javaTree, String message, @Nullable Integer cost, List<RegexCheck.RegexIssueLocation> secondaries)
-
getFlagsTree
protected static Optional<ExpressionTree> getFlagsTree(MethodInvocationTree mit)
- Parameters:
mit- A method call constructing a regex.- Returns:
- An optional containing the expression used to set the regex's flag if the regex is created using Pattern.compile with an argument to set the flags. An empty optional otherwise.
-
-