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,InvalidRegexCheck,PossessiveQuantifierContinuationCheck,RedundantRegexAlternativesCheck,RegexComplexityCheck,RegexStackOverflowCheck,ReluctantQuantifierCheck,SingleCharacterAlternationCheck,StringReplaceCheck,UnicodeAwareCharClassesCheck,UnicodeCaseCheck
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.sonar.java.regex.RegexCheck
RegexCheck.RegexIssueLocation -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static Stringprotected static Stringprotected static MethodMatchersprotected static MethodMatchersprotected static MethodMatchersFields inherited from class org.sonar.java.ast.visitors.SubscriptionVisitor
context -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidcheckRegex(org.sonarsource.analyzer.commons.regex.RegexParseResult regexForLiterals, ExpressionTree methodInvocationOrAnnotation)protected booleanfilterAnnotation(AnnotationTree annotation)protected static Optional<ExpressionTree>getFinalVariableInitializer(IdentifierTree identifier)protected static Optional<ExpressionTree>getFlagsTree(ExpressionTree methodInvocationOrAnnotation)protected static Optional<LiteralTree[]>getLiterals(ExpressionTree expr)protected MethodMatchersprotected ExpressionTreegetRegexLiteralExpression(ExpressionTree methodInvocationOrAnnotation)methodOrAnnotationName(ExpressionTree methodInvocationOrAnnotation)protected voidonAnnotationFound(AnnotationTree annotation)protected voidprotected org.sonarsource.analyzer.commons.regex.RegexParseResultregexForLiterals(org.sonarsource.analyzer.commons.regex.ast.FlagSet flags, LiteralTree... literals)voidreportIssue(Tree javaTree, String message, Integer cost, List<RegexCheck.RegexIssueLocation> secondaries)voidreportIssue(org.sonarsource.analyzer.commons.regex.ast.RegexSyntaxElement regexTree, String message, Integer cost, List<RegexCheck.RegexIssueLocation> secondaries)voidsetContext(JavaFileScannerContext context)voidMethods inherited from class org.sonar.plugins.java.api.IssuableSubscriptionVisitor
addIssue, addIssueOnFile, reportIssue, reportIssue, reportIssue, scanTreeMethods inherited from class org.sonar.java.ast.visitors.SubscriptionVisitor
leaveFile, leaveNode, scanFile, visitToken, visitTrivia
-
Field Details
-
JAVA_LANG_STRING
- See Also:
- Constant Field Values
-
LANG3_REGEX_UTILS
- See Also:
- Constant Field Values
-
REGEX_ON_THE_SECOND_ARGUMENT_METHODS
-
METHODS_IMPLYING_DOT_ALL_FLAG
-
REGEX_METHODS
-
-
Constructor Details
-
AbstractRegexCheck
public AbstractRegexCheck()
-
-
Method Details
-
setContext
- Overrides:
setContextin classSubscriptionVisitor
-
nodesToVisit
- Specified by:
nodesToVisitin classSubscriptionVisitor
-
getMethodInvocationMatchers
-
filterAnnotation
-
visitNode
- Overrides:
visitNodein classSubscriptionVisitor
-
onMethodInvocationFound
-
getRegexLiteralExpression
@Nullable protected ExpressionTree getRegexLiteralExpression(ExpressionTree methodInvocationOrAnnotation) -
onAnnotationFound
-
regexForLiterals
protected final org.sonarsource.analyzer.commons.regex.RegexParseResult regexForLiterals(org.sonarsource.analyzer.commons.regex.ast.FlagSet flags, LiteralTree... literals) -
getLiterals
-
getFinalVariableInitializer
-
checkRegex
public abstract void checkRegex(org.sonarsource.analyzer.commons.regex.RegexParseResult regexForLiterals, ExpressionTree methodInvocationOrAnnotation) -
reportIssue
public final void reportIssue(org.sonarsource.analyzer.commons.regex.ast.RegexSyntaxElement regexTree, String message, @Nullable Integer cost, List<RegexCheck.RegexIssueLocation> secondaries) -
methodOrAnnotationName
-
reportIssue
-
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.
-