Class AbstractRegexCheck

  • Field Details

    • JAVA_LANG_STRING

      protected static final String JAVA_LANG_STRING
      See Also:
    • LANG3_REGEX_UTILS

      protected static final String LANG3_REGEX_UTILS
      See Also:
    • 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
  • Constructor Details

    • AbstractRegexCheck

      public AbstractRegexCheck()
  • Method Details

    • setContext

      public final void setContext(JavaFileScannerContext context)
      Overrides:
      setContext in class IssuableSubscriptionVisitor
    • nodesToVisit

      public List<Tree.Kind> nodesToVisit()
      Specified by:
      nodesToVisit in class SubscriptionVisitor
    • getMethodInvocationMatchers

      protected MethodMatchers getMethodInvocationMatchers()
    • filterAnnotation

      protected boolean filterAnnotation(AnnotationTree annotation)
    • visitNode

      public void visitNode(Tree tree)
      Overrides:
      visitNode in class SubscriptionVisitor
    • onMethodInvocationFound

      protected void onMethodInvocationFound(MethodInvocationTree mit)
    • getRegexLiteralExpression

      @Nullable protected ExpressionTree getRegexLiteralExpression(ExpressionTree methodInvocationOrAnnotation)
    • onAnnotationFound

      protected void onAnnotationFound(AnnotationTree annotation)
    • regexForLiterals

      protected final org.sonarsource.analyzer.commons.regex.RegexParseResult regexForLiterals(org.sonarsource.analyzer.commons.regex.ast.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(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)
    • reportIssueFromCommons

      public final void reportIssueFromCommons(org.sonarsource.analyzer.commons.regex.ast.RegexSyntaxElement regexTree, String message, @Nullable Integer cost, List<org.sonarsource.analyzer.commons.regex.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.