Class KotlinSource
java.lang.Object
com.vaadin.copilot.kotlinrewriter.KotlinSource
- All Implemented Interfaces:
ParsedSource
A Kotlin source file, parsed for reading and edited by splicing text at
offsets.
The Java implementation mutates a JavaParser tree and prints it back. This
one cannot: the Kotlin parser exists to read, and generating code through it
would mean building PSI by hand. So the tree stays untouched and every edit
is recorded in a TextEditBuffer as a character range plus
replacement, which is also why a Kotlin file that Copilot edits comes out
byte-identical except on the lines the edit actually touched.
The parsed tree is exposed only within this package. Callers outside it work
through ParsedSource and the rewriter interfaces, so the parser stays
replaceable — see KotlinPsi.
-
Constructor Summary
ConstructorsConstructorDescriptionKotlinSource(File file, String source) Parses the source, eagerly: aKotlinSourcethat exists always has a tree, so no caller has to handle a half-built one. -
Method Summary
Modifier and TypeMethodDescriptiongetFile()intThe first line that differs between the original source and the result, used to tell the IDE where to scroll.booleanbooleanvoidsetWritten(boolean written) Records that the result has been written to disk, so one operation touching a file twice does not write it twice.
-
Constructor Details
-
KotlinSource
Parses the source, eagerly: aKotlinSourcethat exists always has a tree, so no caller has to handle a half-built one.- Parameters:
file- the file this was read from, ornullfor source held only in memorysource- the source text
-
-
Method Details
-
getFile
- Specified by:
getFilein interfaceParsedSource- Returns:
- the file this source was read from, or
nullfor source that has no file, such as a template being prepared in memory
-
getSource
- Specified by:
getSourcein interfaceParsedSource- Returns:
- the original, unmodified source
-
getResult
- Specified by:
getResultin interfaceParsedSource- Returns:
- the source with all recorded changes applied
-
getLanguage
- Specified by:
getLanguagein interfaceParsedSource- Returns:
- the language of this source
-
isChanged
public boolean isChanged()- Specified by:
isChangedin interfaceParsedSource- Returns:
- true if anything has been changed
-
isWritten
public boolean isWritten()- Specified by:
isWrittenin interfaceParsedSource- Returns:
- true if the result has already been written to disk
-
setWritten
public void setWritten(boolean written) Description copied from interface:ParsedSourceRecords that the result has been written to disk, so one operation touching a file twice does not write it twice.- Specified by:
setWrittenin interfaceParsedSource- Parameters:
written- true once written
-
getFirstModifiedRow
public int getFirstModifiedRow()Description copied from interface:ParsedSourceThe first line that differs between the original source and the result, used to tell the IDE where to scroll.- Specified by:
getFirstModifiedRowin interfaceParsedSource- Returns:
- the 1-based line number, or -1 if nothing changed
-