Package com.vaadin.copilot.javarewriter
Class JavaSource
java.lang.Object
com.vaadin.copilot.javarewriter.JavaSource
- All Implemented Interfaces:
ParsedSource
Represents a Java source file that can be parsed and rewritten using a custom
observer and parser configuration. Provides functionality to parse the given
Java source code.
-
Constructor Summary
ConstructorsConstructorDescriptionJavaSource(File file, String source) Constructs aJavaSourcewith the given Java source code.JavaSource(File file, String source, boolean solveJdkClassesBySimpleName) Constructs aJavaSourcewith the given Java source code.JavaSource(File file, String source, boolean solveJdkClassesBySimpleName, boolean javaParserLexicalPreservation) Constructs aJavaSourcewith the given Java source code. -
Method Summary
Modifier and TypeMethodDescriptioncom.github.javaparser.ast.CompilationUnitParsed compilation unit of the givensourcefrom constructor.getFile()Returns the file associated with this Java source.intFinds the first modified row in the given source by comparing result and initial sourceApplies changes to the given source and returns the result file contentReturns the source code.booleanChecks if there have been any changes based on added, modified, or removed nodes.booleanChecks if the file is written into disk.voidsetWritten(boolean written) Updates the flag with the given written value.
-
Constructor Details
-
JavaSource
Constructs aJavaSourcewith the given Java source code. The source is parsed without attempting to resolve JDK classes by their simple names.- Parameters:
file- the file containing the Java source codesource- the raw Java source code as a String
-
JavaSource
Constructs aJavaSourcewith the given Java source code. Allows specifying whether JDK classes should be resolved by their simple names.- Parameters:
file- the file containing the Java source codesource- the raw Java source code as a StringsolveJdkClassesBySimpleName-trueto resolve JDK classes by simple name,falseotherwise
-
JavaSource
public JavaSource(File file, String source, boolean solveJdkClassesBySimpleName, boolean javaParserLexicalPreservation) Constructs aJavaSourcewith the given Java source code. Allows specifying whether JDK classes should be resolved by their simple names.- Parameters:
file- the file containing the Java source codesource- the raw Java source code as a StringsolveJdkClassesBySimpleName-trueto resolve JDK classes by simple name,falseotherwisejavaParserLexicalPreservation- true to use the JavaParser feature to preserve indentation, false (default) to use the faster but sometimes broken version in Copilot
-
-
Method Details
-
getCompilationUnit
public com.github.javaparser.ast.CompilationUnit getCompilationUnit()Parsed compilation unit of the givensourcefrom constructor.- Returns:
- Compilation Unit
-
isChanged
public boolean isChanged()Checks if there have been any changes based on added, modified, or removed nodes. This method returns true if there are any added or modified nodes, or if there are any removed ranges.- Specified by:
isChangedin interfaceParsedSource- Returns:
- true if there are changes (i.e., added/modified nodes or removed ranges), false if there are no changes.
-
setWritten
public void setWritten(boolean written) Updates the flag with the given written value.- Specified by:
setWrittenin interfaceParsedSource- Parameters:
written-trueif it is saved,falseotherwise.
-
isWritten
public boolean isWritten()Checks if the file is written into disk.- Specified by:
isWrittenin interfaceParsedSource- Returns:
- true if it is written, false otherwise.
-
getResult
Applies changes to the given source and returns the result file content- Specified by:
getResultin interfaceParsedSource- Returns:
- Result file content after changes are applied
-
getFirstModifiedRow
public int getFirstModifiedRow()Finds the first modified row in the given source by comparing result and initial source- Specified by:
getFirstModifiedRowin interfaceParsedSource- Returns:
- row number, or -1 if no change is found.
-
getSource
Returns the source code.- Specified by:
getSourcein interfaceParsedSource- Returns:
- the source code
-
getLanguage
- Specified by:
getLanguagein interfaceParsedSource- Returns:
- the language of this source
-
getFile
Returns the file associated with this Java source.- Specified by:
getFilein interfaceParsedSource- Returns:
- the file containing the Java source code
-