Class JavaFileSourceProvider

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

public class JavaFileSourceProvider extends Object
Provider that makes sure same JavaRewriter is served for the same file so same file should not be overwritten in the same operation.
  • Field Details

    • UNDO_LABEL

      public static final String UNDO_LABEL
  • Constructor Details

    • JavaFileSourceProvider

      public JavaFileSourceProvider()
      Creates a new Java file source provider that does not use the built in lexical preservation parser.
    • JavaFileSourceProvider

      public JavaFileSourceProvider(boolean javaParserLexicalPreservation)
      Creates a new Java file source provider.
      Parameters:
      javaParserLexicalPreservation - true to use the built in lexical preservation parser, false to use the custom, faster implementation which sometimes produces incorrect results.
    • JavaFileSourceProvider

      public JavaFileSourceProvider(Path workspace, Path projectRoot)
      Creates a provider that mirrors source files into a workspace instead of reading or writing the project files.
      Parameters:
      workspace - workspace root for preview sources
      projectRoot - root used to retain project-relative source paths
    • JavaFileSourceProvider

      public JavaFileSourceProvider(Path workspace, Path projectRoot, boolean resetWorkspaceSources)
  • Method Details

    • getJavaSource

      public JavaSource getJavaSource(File sourceFile) throws IOException
      Retrieves a JavaSource representation of the specified Java source file.

      If the source has already been loaded previously, the cached JavaSource is returned. Otherwise, the file is read from disk, validated to ensure it is not a Kotlin file, and then parsed into a new JavaSource instance which is cached for future use.

      Parameters:
      sourceFile - the Java source file to load
      Returns:
      the JavaSource representation of the given file
      Throws:
      IOException - if an I/O error occurs while reading the file
      KotlinNotSupportedException - if the file is determined to be a Kotlin file
    • saveComponentInfoSourceFiles

      public void saveComponentInfoSourceFiles(ComponentInfo componentInfo)
    • saveChangedSources

      public void saveChangedSources()
      Writes every changed source currently held by this provider.

      Used by compound operations that first validate all rewrites with write mode disabled and only then commit the accumulated result.

    • throwExceptionIfNoChanges

      public void throwExceptionIfNoChanges(ComponentInfo componentInfo)
      Validates whether any changes have been made to the Java source files associated with the given ComponentInfo. This method inspects both the component's creation and attachment information, checking if the underlying Java source has been modified.

      If no changes are detected in either the creation or attachment source information, a CopilotException is thrown.

    • clear

      public void clear()
      Clears all cached JavaSource objects from memory.

      Note: This method should be called anytime a new Java related operation begins.

    • getLoadedSources

      public Collection<JavaSource> getLoadedSources()
      Returns the Java sources loaded for the current rewrite operation.
    • setWriteMode

      public void setWriteMode(boolean writeMode)