Class AnahataAnnotationLogic

java.lang.Object
uno.anahata.asi.nb.annotation.AnahataAnnotationLogic

public class AnahataAnnotationLogic extends Object
The decoupled logic engine for Anahata NetBeans annotations.

This class contains the 'Brain' of the annotation system, separating the business logic (calculating totals, building HTML, classifying nodes) from the NetBeans API plumbing. It is designed for high performance and includes instrumentation to monitor the impact on the IDE's repaint cycle.

V2 Migration: This class authoritatively uses the Universal Resource Pipeline (URP) via FilesContextActionLogic.

Author:
anahata
  • Field Details

    • LOG

      private static final Logger LOG
      Logger for performance tracking and classification diagnostics.
    • BADGE_ICON_URL

      private static final String BADGE_ICON_URL
      Pre-resolved URL string for the Anahata 16x16 badge icon to prevent synchronous ClassLoader lookups on the EDT.
  • Constructor Details

    • AnahataAnnotationLogic

      public AnahataAnnotationLogic()
  • Method Details

    • classify

      public static AnahataAnnotationLogic.NodeType classify(org.openide.filesystems.FileObject fo)
      Performs stack-trace forensics to classify the UI node identity.

      Scans the current call stack for specific NetBeans node implementation classes (PackageNode, BadgingNode) to distinguish between Projects view and Files view. This allows the system to apply different counting strategies (recursive vs. non-recursive) based on visual context.

      Parameters:
      fo - The FileObject to classify.
      Returns:
      The classified NodeType.
    • resolve

      public static org.openide.filesystems.FileObject resolve(org.openide.filesystems.FileObject fo)
      Resolves DataShadows (shortcuts) to their original physical files.

      Unwraps DataShadow instances using the DataObject API. This ensures that context checks are performed on the ground-truth resource rather than the IDE proxy.

      Parameters:
      fo - The potentially virtual FileObject.
      Returns:
      The resolved physical FileObject, or the original if not a shadow.
    • calculateSessionTotals

      public static List<Integer> calculateSessionTotals(org.openide.filesystems.FileObject fo, AnahataAnnotationLogic.NodeType nodeType, List<uno.anahata.asi.agi.Agi> activeAgis)
      Calculates the context presence totals for each active session with high-resolution timing.

      For projects, this method counts 'effectivelyProviding' context providers (e.g., Overview, Alerts). For packages, it performs a non-recursive resource count, while OS folders trigger a recursive search to propagate status badges.

      This method is instrumented with System.nanoTime(). If the calculation for a single node exceeds 2ms, a performance warning is logged at the INFO level.

      Parameters:
      fo - The file or container to count.
      nodeType - The classified type of the node.
      activeAgis - The list of active agi sessions.
      Returns:
      A list of integers representing resources in context per session.
    • buildNameAnnotation

      public static String buildNameAnnotation(AnahataAnnotationLogic.NodeType nodeType, List<uno.anahata.asi.agi.Agi> agis, List<Integer> totals)
      Builds the HTML name annotation suffix.

      Dispatches to specific bracketed or parenthesized formatting based on node type. Directories use square brackets [count], while individual files use parentheses (nickname).

      Parameters:
      nodeType - The node identity.
      agis - List of active agis.
      totals - Pre-calculated context counts.
      Returns:
      The HTML snippet to append to the node name.
    • buildTooltip

      public static String buildTooltip(org.openide.filesystems.FileObject fo, AnahataAnnotationLogic.NodeType nodeType, List<uno.anahata.asi.agi.Agi> activeAgis, List<Integer> totals)
      Builds the descriptive HTML tooltip for the Anahata badge.

      Injects the Anahata icon and builds a structured list of active sessions and their respective contributions (providers for projects, resource counts for folders).

      Parameters:
      fo - The target node's FileObject.
      nodeType - The classified identity.
      activeAgis - List of active sessions.
      totals - Pre-calculated context counts.
      Returns:
      The formatted HTML tooltip string.
    • buildBracketedTotal

      private static String buildBracketedTotal(List<Integer> totals)
      Formats context counts into greyed-out square brackets.

      Appends a series of bracketed totals (e.g., [3][1]) styled with a neutral grey color to minimize visual noise.

      Parameters:
      totals - The session-specific counts.
      Returns:
      The formatted bracketed HTML string.
    • buildFileAnnotation

      private static String buildFileAnnotation(List<uno.anahata.asi.agi.Agi> agis, List<Integer> totals)
      Formats file name annotations using parentheses.

      If the file is in a single session, it shows the session's display name. If in multiple sessions, it shows the total session count.

      Parameters:
      agis - Active agi list.
      totals - Session counts.
      Returns:
      The formatted parenthesized HTML string.
    • getProvidingProviders

      private static List<String> getProvidingProviders(uno.anahata.asi.agi.Agi agi, org.openide.filesystems.FileObject fo)
      Locates the names of all active providers for a project.

      Uses FileOwnerQuery to find the project root and queries the Projects toolkit for the flattened hierarchy of 'effectively providing' providers.

      Parameters:
      agi - The session to check.
      fo - Any FileObject belonging to the project.
      Returns:
      A list of names for all active providers.
    • flattenProvidingNames

      private static List<String> flattenProvidingNames(uno.anahata.asi.agi.context.ContextProvider root)
      Flattens a provider hierarchy and extracts names of active nodes.

      Performs a depth-first search of the children providers, checking the ContextProvider.isEffectivelyProviding() status for each node.

      Parameters:
      root - The starting context provider.
      Returns:
      List of matching provider names.