Class OptimisticPreviewMarker

java.lang.Object
com.vaadin.copilot.javarewriter.OptimisticPreviewMarker

public final class OptimisticPreviewMarker extends Object
Maintains line-comment markers that associate optimistic preview components with their live source locations.

Structural preview rewrites replace AST nodes, making previously captured ComponentInfo instances stale. The markers written by this utility identify the current creation and attachment statements so callers can rebuild component information from the rewritten source tree.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Prefix of a line comment that identifies a component attachment statement.
    static final String
    Prefix of a line comment that identifies a component creation statement.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    add(ComponentInfo component, String optimisticComponentId)
    Adds creation and attachment markers for a component's current source locations.
    find(JavaSource source, String optimisticComponentId)
    Resolves live component locations identified by a creation marker in a source tree.
    Recreates every component that has a creation marker in a source tree.
    static void
    remove(JavaSource source, String componentId)
    Removes a component identity from all creation and attachment markers in the current source.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CREATE_ID

      public static final String CREATE_ID
      Prefix of a line comment that identifies a component creation statement.
      See Also:
    • ATTACH_ID

      public static final String ATTACH_ID
      Prefix of a line comment that identifies a component attachment statement.
      See Also:
  • Method Details

    • add

      public static void add(ComponentInfo component, String optimisticComponentId)
      Adds creation and attachment markers for a component's current source locations.
      Parameters:
      component - component information whose locations are marked
      optimisticComponentId - stable browser-to-preview identity to add to the markers
    • find

      public static ComponentInfo find(JavaSource source, String optimisticComponentId)
      Resolves live component locations identified by a creation marker in a source tree. This deliberately rebuilds the ComponentInfo; AST nodes from before a structural rewrite must not be reused.
      Parameters:
      source - source tree containing the marker
      optimisticComponentId - stable component identity
      Returns:
      a component backed by live AST nodes, or null when absent
    • findAll

      public static List<ComponentInfo> findAll(JavaSource source)
      Recreates every component that has a creation marker in a source tree. This is used when a structural operation needs the live hierarchy rather than a single component identified by a browser ID.
      Parameters:
      source - source tree containing preview markers
      Returns:
      component information rebuilt from the marked live AST nodes
    • remove

      public static void remove(JavaSource source, String componentId)
      Removes a component identity from all creation and attachment markers in the current source. Marker comments without remaining identities are removed.
      Parameters:
      source - source tree whose marker comments are updated
      componentId - identity to remove