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.regex.AbstractRegexCheck
-
- All Implemented Interfaces:
RegexCheck,JavaCheck,JavaFileScanner
- Direct Known Subclasses:
AbstractRegexCheckTrackingMatchers,AnchorPrecedenceCheck,CanonEqFlagInRegexCheck,DuplicatesInCharacterClassCheck,EmptyLineRegexCheck,EmptyStringRepetitionCheck,EscapeSequenceControlCharacterCheck,GraphemeClustersInClassesCheck,ImpossibleBackReferenceCheck,ImpossibleBoundariesCheck,ImpossibleRegexCheck,InvalidRegexCheck,PossessiveQuantifierContinuationCheck,RedosCheck,RedundantRegexAlternativesCheck,RegexComplexityCheck,RegexStackOverflowCheck,ReluctantQuantifierCheck,SingleCharacterAlternationCheck,StringReplaceCheck,UnicodeAwareCharClassesCheck,UnicodeCaseCheck
public abstract class AbstractRegexCheck extends IssuableSubscriptionVisitor 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 StringLANG3_REGEX_UTILSprotected static MethodMatchersMETHODS_IMPLYING_DOT_ALL_FLAGprotected static MethodMatchersREGEX_METHODSprotected static MethodMatchersREGEX_ON_THE_SECOND_ARGUMENT_METHODS-
Fields inherited from class org.sonar.java.ast.visitors.SubscriptionVisitor
context
-
-
Constructor Summary
Constructors Constructor Description AbstractRegexCheck()
-
Method Summary
-
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
-
LANG3_REGEX_UTILS
protected static final String LANG3_REGEX_UTILS
- See Also:
- Constant Field Values
-
REGEX_ON_THE_SECOND_ARGUMENT_METHODS
protected static final MethodMatchers REGEX_ON_THE_SECOND_ARGUMENT_METHODS
-
METHODS_IMPLYING_DOT_ALL_FLAG
protected static final MethodMatchers METHODS_IMPLYING_DOT_ALL_FLAG
-
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()
- Specified by:
nodesToVisitin classSubscriptionVisitor
-
getMethodInvocationMatchers
protected MethodMatchers getMethodInvocationMatchers()
-
filterAnnotation
protected boolean filterAnnotation(AnnotationTree annotation)
-
visitNode
public void visitNode(Tree tree)
- Overrides:
visitNodein classSubscriptionVisitor
-
onMethodInvocationFound
protected void onMethodInvocationFound(MethodInvocationTree mit)
-
getRegexLiteralExpression
@Nullable protected ExpressionTree getRegexLiteralExpression(ExpressionTree methodInvocationOrAnnotation)
-
onAnnotationFound
protected void onAnnotationFound(AnnotationTree annotation)
-
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, ExpressionTree methodInvocationOrAnnotation)
-
reportIssue
public final void reportIssue(RegexSyntaxElement regexTree, String message, @Nullable Integer cost, List<RegexCheck.RegexIssueLocation> secondaries)
-
methodOrAnnotationName
public Tree methodOrAnnotationName(ExpressionTree methodInvocationOrAnnotation)
-
reportIssue
public final void reportIssue(Tree javaTree, String message, @Nullable Integer cost, List<RegexCheck.RegexIssueLocation> secondaries)
-
getFlagsTree
protected static Optional<ExpressionTree> getFlagsTree(ExpressionTree methodInvocationOrAnnotation)
- Parameters:
methodInvocationOrAnnotation- A method call or annotation constructing a regex.- Returns:
- An optional containing the expression used to set the regex's flag if the regex is created using Pattern.compile or "flags" annotation parameter with an argument to set the flags. An empty optional otherwise.
-
-