Class IssuableSubscriptionVisitor

java.lang.Object
org.sonar.java.ast.visitors.SubscriptionVisitor
org.sonar.plugins.java.api.IssuableSubscriptionVisitor
All Implemented Interfaces:
JavaCheck, JavaFileScanner

public abstract class IssuableSubscriptionVisitor extends SubscriptionVisitor
Subscription visitor providing an API to report issues.
  • Constructor Details

    • IssuableSubscriptionVisitor

      public IssuableSubscriptionVisitor()
  • Method Details

    • setContext

      public void setContext(JavaFileScannerContext context)
      Override this method only if you need to execute some instructions prior to start the analysis of a file. Don't forget to call super.setContext()`.
      Overrides:
      setContext in class SubscriptionVisitor
      Parameters:
      context - the analysis context.
    • scanTree

      @Deprecated(since="7.31", forRemoval=false) protected final void scanTree(Tree tree)
      This method is never called and should not be called. It is inherited from the SubscriptionVisitor. Implementations of IssuableSubscriptionVisitor are not able to pilot the exploration of the AST.
      Overrides:
      scanTree in class SubscriptionVisitor
    • scanFile

      @Deprecated(since="7.31", forRemoval=false) public final void scanFile(JavaFileScannerContext context)
      This method is never called and should not be called. It is inherited from the SubscriptionVisitor. Implementations of IssuableSubscriptionVisitor are not able to impact visit of a file.
      Specified by:
      scanFile in interface JavaFileScanner
      Overrides:
      scanFile in class SubscriptionVisitor
      Parameters:
      context - Context of analysis containing the parsed tree.
    • leaveFile

      public void leaveFile(JavaFileScannerContext context)
      Override this method only if you need to execute some instructions after the end of the analysis of a file.
      Overrides:
      leaveFile in class SubscriptionVisitor
      Parameters:
      context - the analysis context.
    • addIssue

      public void addIssue(int line, String message)
      Report an issue on a specific line.
      Parameters:
      line - line on which to report the issue
      message - Message to display to the user
    • addIssueOnFile

      public void addIssueOnFile(String message)
      Report an issue at file level.
      Parameters:
      message - Message to display to the user
    • reportIssue

      public void reportIssue(Tree tree, String message)
      Report an issue.
      Parameters:
      tree - syntax node on which to raise the issue.
      message - Message to display to the user.
    • reportIssue

      public void reportIssue(Tree tree, String message, List<JavaFileScannerContext.Location> flow, @Nullable Integer cost)
      Report an issue.
      Parameters:
      tree - syntax node on which to raise the issue.
      message - Message to display to the user.
      flow - List of JavaFileScannerContext.Location to display secondary locations describing the flow leading to the issue. Empty list if the issue does not requires secondary location.
      cost - computed remediation cost if applicable, null if not.
    • reportIssue

      public void reportIssue(Tree startTree, Tree endTree, String message)
      Report an issue.
      Parameters:
      startTree - syntax node on which to start the highlighting of the issue.
      endTree - syntax node on which to end the highlighting of the issue.
      message - Message to display to the user.
    • reportIssue

      public void reportIssue(Tree startTree, Tree endTree, String message, List<JavaFileScannerContext.Location> flow, @Nullable Integer cost)
      Report an issue.
      Parameters:
      startTree - syntax node on which to start the highlighting of the issue.
      endTree - syntax node on which to end the highlighting of the issue.
      message - Message to display to the user.
      flow - List of JavaFileScannerContext.Location to display secondary locations describing the flow leading to the issue. Empty list if the issue does not requires secondary location.
      cost - computed remediation cost if applicable, null if not.