Class ClassSourceStaticAnalyzer

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

public class ClassSourceStaticAnalyzer extends Object
Static source file parser for the given component class. See findCreateLocationCandidateOrThrow(VaadinSession)
  • Constructor Details

    • ClassSourceStaticAnalyzer

      public ClassSourceStaticAnalyzer(ComponentSourceFinder sourceFinder, com.vaadin.flow.component.Component component, File file)
      Parameters:
      sourceFinder - to get children of the given component if necessary
      component - Component instance that is created with
      file - Source file of the component
  • Method Details

    • findCreateLocationCandidateOrThrow

      public com.vaadin.flow.component.internal.ComponentTracker.Location findCreateLocationCandidateOrThrow(com.vaadin.flow.server.VaadinSession vaadinSession) throws IOException
      Determines the candidate create location. There are three ways to find the candidate, it is done in the following order:

      1. Using the reference of children create locations to find candidate constructor
      2. Returning default constructor if present
      3. Returning class declaration as fallback

      Throws an exception if no candidate found from approaches above
      Returns:
      Create location of the given source file
      Throws:
      IOException - thrown if file operation fails
    • findRelevantClassDeclaration

      public static com.github.javaparser.ast.body.ClassOrInterfaceDeclaration findRelevantClassDeclaration(com.github.javaparser.ast.CompilationUnit compilationUnit, Class<?> clazz)
      Locates the ClassOrInterfaceDeclaration in a given CompilationUnit that corresponds to the provided Class object, including support for inner classes.

      This method first retrieves the top-level class declaration in the compilation unit. If the given class is a top-level class (i.e., its name does not contain a dollar sign indicating inner classes), that declaration is returned directly.

      If the class is an inner or nested class (denoted by dollar signs in the class name), it recursively searches the child nodes of each class declaration to find the exact inner class corresponding to the provided Class object.

      Parameters:
      compilationUnit - the CompilationUnit representing the parsed Java source file.
      clazz - the Class for which the corresponding class declaration should be found.
      Returns:
      the ClassOrInterfaceDeclaration matching the structure of the given class, including nested inner classes if applicable.
      Throws:
      CopilotException - if the relevant class or inner class declaration cannot be found.