Class Hints

All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class Hints extends AnahataToolkit
Surfaces IntelliJ's on-the-fly analysis (inspections + annotators) for a file.

This is the IntelliJ counterpart of the NetBeans Hints toolkit. Where NetBeans drives its hints SPI, IntelliJ runs the code-analysis daemon's main passes on demand via DaemonCodeAnalyzerImpl.runMainPasses(PsiFile, Document, ProgressIndicator) and reports the resulting HighlightInfos (errors, warnings, weak warnings) with line numbers and messages. Applying quick-fixes programmatically is deferred — it requires resolving each highlight's IntentionAction and running it in a write command.

Author:
anahata
  • Constructor Details

    • Hints

      public Hints()
      Constructs the Hints toolkit (instantiated reflectively via its public no-arg constructor).
  • Method Details

    • getFileHints

      public String getFileHints(String filePath, String minSeverity) throws AgiToolException
      Lists the inspection/annotator highlights for a file at or above a severity threshold.

      Runs the analysis daemon's main passes synchronously (on this background tool thread, under a progress indicator) so the result reflects the current file state without requiring the file to be open in an editor.

      Parameters:
      filePath - the absolute path of the file to analyze.
      minSeverity - the minimum severity to include: ERROR, WARNING (default), WEAK_WARNING, or INFO.
      Returns:
      a Markdown listing of highlights (severity, line, message).
      Throws:
      AgiToolException - if the file cannot be resolved.
    • applyHint

      public String applyHint(String filePath, int line, String fixName) throws AgiToolException
      Applies a quick-fix to a highlight on a given line of a file.

      Re-runs the analysis daemon, locates a highlight on the target line whose registered quick-fix matches (by name substring, or the first fix), opens the file at that offset, and invokes the fix's IntentionAction inside a write command.

      Parameters:
      filePath - the absolute path of the file.
      line - the 1-based line number of the highlight to fix.
      fixName - a case-insensitive substring of the fix name, or null for the first fix.
      Returns:
      a confirmation naming the applied fix.
      Throws:
      AgiToolException - if the file, highlight, or a matching fix cannot be resolved.
    • runMainPasses

      private List<com.intellij.codeInsight.daemon.impl.HighlightInfo> runMainPasses(com.intellij.openapi.project.Project project, com.intellij.psi.PsiFile psiFile, com.intellij.openapi.editor.Document document)
      Runs the analysis daemon's main passes for a file synchronously and returns its highlights. Must be called off the EDT (AI tool threads qualify).
      Parameters:
      project - the host project.
      psiFile - the file to analyze.
      document - the file's document.
      Returns:
      the highlights produced by the main passes.
    • parseSeverity

      private com.intellij.lang.annotation.HighlightSeverity parseSeverity(String name)
      Parses a severity name into a HighlightSeverity, defaulting to WARNING.
      Parameters:
      name - the severity name (case-insensitive), or null.
      Returns:
      the resolved severity threshold.