Class ComponentSourceFinder

java.lang.Object
com.vaadin.copilot.ComponentSourceFinder

public class ComponentSourceFinder extends Object
Finds the source location of a component in the project.
  • Constructor Details

    • ComponentSourceFinder

      public ComponentSourceFinder(com.vaadin.flow.server.VaadinSession vaadinSession)
      Creates a new component source finder for the given session.
      Parameters:
      vaadinSession - the session to use
  • Method Details

    • findTypeAndSourceLocation

      public ComponentTypeAndSourceLocation findTypeAndSourceLocation(tools.jackson.databind.JsonNode component)
      Finds the source location of a component.
      Parameters:
      component - the component to find, defined by uiId and nodeId in the given JSON object
      Returns:
      the source location of the component
    • findTypeAndSourceLocation

      public ComponentTypeAndSourceLocation findTypeAndSourceLocation(tools.jackson.databind.JsonNode component, boolean includeChildren)
      Finds the source location of a component.
      Parameters:
      component - the component to find, defined by uiId and nodeId in the given JSON object
      Returns:
      the source location of the component
    • findTypeAndSourceLocation

      public ComponentTypeAndSourceLocation findTypeAndSourceLocation(int uiId, int nodeId)
      Finds the source location of a component.
      Parameters:
      uiId - the uiId of the component
      nodeId - the nodeId of the component
      Returns:
      the source location of the component
    • findTypeAndSourceLocation

      public ComponentTypeAndSourceLocation findTypeAndSourceLocation(int uiId, int nodeId, boolean includeChildren)
      Finds the source location of a component.
      Parameters:
      uiId - the uiId of the component
      nodeId - the nodeId of the component
      includeChildren - whether to include children in the search
      Returns:
      the source location of the component
    • findTypeAndSourceLocation

      public ComponentTypeAndSourceLocation findTypeAndSourceLocation(com.vaadin.flow.component.Component component, boolean includeChildren)
      Finds the source location of a component.
      Parameters:
      component - the component to find
      includeChildren - whether to include children in the search
      Returns:
      the source location of the component
    • analyzeSourceFileAndGetComponentTypeAndSourceLocation

      public Optional<ComponentTypeAndSourceLocation> analyzeSourceFileAndGetComponentTypeAndSourceLocation(int nodeId, int uiId) throws IOException
      Finds the ComponentTypeAndSourceLocation for given component with nodeId in ui with id uiId by analyzing the source code without using the createLocation provided by Flow.

      Note: This method should be used if an operation requires source file instead of creation location for the component

      Parameters:
      nodeId - Flow component node id
      uiId - Flow UI id
      Returns:
      ComponentTypeAndSourceLocation if component class analyzed successfully, empty when file or component is not accessible.
      Throws:
      IOException - thrown when file operation fails
    • analyzeSourceFileAndGetComponentTypeAndSourceLocation

      public Optional<ComponentTypeAndSourceLocation> analyzeSourceFileAndGetComponentTypeAndSourceLocation(com.vaadin.flow.component.Component component) throws IOException
      Finds the ComponentTypeAndSourceLocation for given component with by analyzing the source code without using the createLocation provided by Flow.

      Note: This method should be used if an operation requires source file instead of creation location for the component.

      Note: This method does not include children and parent info.

      Parameters:
      component - Component instance
      Returns:
      ComponentTypeAndSourceLocation if component class analyzed successfully, empty when file or component is not accessible.
      Throws:
      IOException - thrown when file operation fails
    • _getSourceLocation

      public ComponentTypeAndSourceLocation _getSourceLocation(com.vaadin.flow.component.Component component)
      Gets the source location for the given component.

      NOTE that the session must be locked when calling this method.

      Returns:
      the source location of the component
    • findInheritanceChain

      public static List<Class<?>> findInheritanceChain(com.vaadin.flow.component.Component component)
      Finds inheritance chain of a component by going up for each superclass
      Parameters:
      component - Flow component
      Returns:
      list of classes