Package com.vaadin.copilot.javarewriter
Class ClassSourceStaticAnalyzer
java.lang.Object
com.vaadin.copilot.javarewriter.ClassSourceStaticAnalyzer
Static source file parser for the given component class. See
findCreateLocationCandidateOrThrow(VaadinSession)-
Constructor Summary
ConstructorsConstructorDescriptionClassSourceStaticAnalyzer(ComponentSourceFinder sourceFinder, com.vaadin.flow.component.Component component, File file) Constructs aClassSourceStaticAnalyzer -
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.component.internal.ComponentTracker.LocationfindCreateLocationCandidateOrThrow(com.vaadin.flow.server.VaadinSession vaadinSession) Determines the candidate create location.static com.github.javaparser.ast.body.ClassOrInterfaceDeclarationfindRelevantClassDeclaration(com.github.javaparser.ast.CompilationUnit compilationUnit, Class<?> clazz) Locates theClassOrInterfaceDeclarationin a givenCompilationUnitthat corresponds to the providedClassobject, including support for inner classes.
-
Constructor Details
-
ClassSourceStaticAnalyzer
public ClassSourceStaticAnalyzer(ComponentSourceFinder sourceFinder, com.vaadin.flow.component.Component component, File file) Constructs aClassSourceStaticAnalyzer- Parameters:
sourceFinder- to get children of the given component if necessarycomponent- Component instance that is created withfile- 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:- Using the reference of children create locations to find candidate constructor
- Returning default constructor if present
- Returning class declaration as fallback
- 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 theClassOrInterfaceDeclarationin a givenCompilationUnitthat corresponds to the providedClassobject, 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
Classobject.- Parameters:
compilationUnit- theCompilationUnitrepresenting the parsed Java source file.clazz- theClassfor which the corresponding class declaration should be found.- Returns:
- the
ClassOrInterfaceDeclarationmatching 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.
-