Class QuickFixHelper

java.lang.Object
org.sonar.java.checks.helpers.QuickFixHelper

@Beta public class QuickFixHelper extends Object
For internal use only. Can not be used outside SonarJava analyzer.
  • Method Details

    • newIssue

      public static InternalJavaIssueBuilder newIssue(JavaFileScannerContext context)
    • internalContext

      public static DefaultJavaFileScannerContext internalContext(JavaFileScannerContext context)
    • nextToken

      public static SyntaxToken nextToken(Tree tree)
    • previousToken

      public static SyntaxToken previousToken(Tree tree)
    • previousVariable

      public static Optional<VariableTree> previousVariable(VariableTree current)
      Returns the preceding variable in a mutli-variable declaration.
      Parameters:
      current - The target variable
      Returns:
      An Optional with the preceding variable, Optional.empty otherwise.
    • nextVariable

      public static Optional<VariableTree> nextVariable(VariableTree variable)
      Returns the following variable in a mutli-variable declaration.
      Parameters:
      variable - The target variable
      Returns:
      An Optional with the following variable, Optional.empty otherwise.
    • contentForTree

      public static String contentForTree(Tree tree, JavaFileScannerContext context)
    • contentForRange

      public static String contentForRange(SyntaxToken firstToken, SyntaxToken lastToken, JavaFileScannerContext context)
    • contentOfTreeTokens

      public static String contentOfTreeTokens(Tree tree, JavaFileScannerContext context)
    • addParenthesisIfRequired

      public static void addParenthesisIfRequired(JavaQuickFix.Builder quickFixBuilder, ExpressionTree expression)
    • newImportSupplier

      public static QuickFixHelper.ImportSupplier newImportSupplier(JavaFileScannerContext context)
      Check if a given type "requiredType" is available in the current "context". Imports are cached to not have to recompute order all the time. A new import is required if the given type:
      • is not in the same package of the current compilation unit
      • is not yet imported
      If the type is not yet known in the context, the supplier will provide an edit to be inserted with a quick-fix, which will add the type as import in the existing list of imports, at the best place it can. If the type is already available in the current context, then no changes are required. There is no need of an extra import.
      Parameters:
      context - The context of analysis