Package com.vaadin.copilot.javarewriter
Class JavaFileSourceProvider
java.lang.Object
com.vaadin.copilot.javarewriter.JavaFileSourceProvider
Provider that makes sure same JavaRewriter is served for the same file so
same file should not be overwritten in the same operation.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new Java file source provider that does not use the built in lexical preservation parser.JavaFileSourceProvider(boolean javaParserLexicalPreservation) Creates a new Java file source provider.JavaFileSourceProvider(Path workspace, Path projectRoot) Creates a provider that mirrors source files into a workspace instead of reading or writing the project files.JavaFileSourceProvider(Path workspace, Path projectRoot, boolean resetWorkspaceSources) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all cachedJavaSourceobjects from memory.getJavaSource(File sourceFile) Retrieves aJavaSourcerepresentation of the specified Java source file.Returns the Java sources loaded for the current rewrite operation.voidWrites every changed source currently held by this provider.voidsaveComponentInfoSourceFiles(ComponentInfo componentInfo) voidsetWriteMode(boolean writeMode) voidthrowExceptionIfNoChanges(ComponentInfo componentInfo) Validates whether any changes have been made to the Java source files associated with the givenComponentInfo.
-
Field Details
-
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
Creates a provider that mirrors source files into a workspace instead of reading or writing the project files.- Parameters:
workspace- workspace root for preview sourcesprojectRoot- root used to retain project-relative source paths
-
JavaFileSourceProvider
-
-
Method Details
-
getJavaSource
Retrieves aJavaSourcerepresentation of the specified Java source file.If the source has already been loaded previously, the cached
JavaSourceis returned. Otherwise, the file is read from disk, validated to ensure it is not a Kotlin file, and then parsed into a newJavaSourceinstance which is cached for future use.- Parameters:
sourceFile- the Java source file to load- Returns:
- the
JavaSourcerepresentation of the given file - Throws:
IOException- if an I/O error occurs while reading the fileKotlinNotSupportedException- if the file is determined to be a Kotlin file
-
saveComponentInfoSourceFiles
-
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
Validates whether any changes have been made to the Java source files associated with the givenComponentInfo. 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
CopilotExceptionis thrown. -
clear
public void clear()Clears all cachedJavaSourceobjects from memory.Note: This method should be called anytime a new Java related operation begins.
-
getLoadedSources
Returns the Java sources loaded for the current rewrite operation. -
setWriteMode
public void setWriteMode(boolean writeMode)
-