Package com.github.javaparser.ast
Class CompilationUnit.Storage
- java.lang.Object
-
- com.github.javaparser.ast.CompilationUnit.Storage
-
- Enclosing class:
- CompilationUnit
public static class CompilationUnit.Storage extends java.lang.Object
Information about where this compilation unit was loaded from. This class only stores the absolute location. For more flexibility use SourceRoot.
-
-
Field Summary
Fields Modifier and Type Field Description private CompilationUnit
compilationUnit
private java.nio.charset.Charset
encoding
private java.nio.file.Path
path
-
Constructor Summary
Constructors Modifier Constructor Description private
Storage(CompilationUnit compilationUnit, java.nio.file.Path path)
private
Storage(CompilationUnit compilationUnit, java.nio.file.Path path, java.nio.charset.Charset encoding)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompilationUnit
getCompilationUnit()
java.nio.file.Path
getDirectory()
java.nio.charset.Charset
getEncoding()
java.lang.String
getFileName()
java.nio.file.Path
getPath()
java.nio.file.Path
getSourceRoot()
ParseResult<CompilationUnit>
reparse(JavaParser javaParser)
void
save()
Saves the compilation unit to its original locationvoid
save(java.util.function.Function<CompilationUnit,java.lang.String> makeOutput)
Saves a compilation unit to its original location with formatting according to the function passed as a parameter.void
save(java.util.function.Function<CompilationUnit,java.lang.String> makeOutput, java.nio.charset.Charset encoding)
Saves a compilation unit to its original location with formatting and encoding according to the function and encoding passed as a parameter.
-
-
-
Field Detail
-
compilationUnit
private final CompilationUnit compilationUnit
-
path
private final java.nio.file.Path path
-
encoding
private final java.nio.charset.Charset encoding
-
-
Constructor Detail
-
Storage
private Storage(CompilationUnit compilationUnit, java.nio.file.Path path)
-
Storage
private Storage(CompilationUnit compilationUnit, java.nio.file.Path path, java.nio.charset.Charset encoding)
-
-
Method Detail
-
getPath
public java.nio.file.Path getPath()
- Returns:
- the path to the source for this CompilationUnit
-
getCompilationUnit
public CompilationUnit getCompilationUnit()
- Returns:
- the CompilationUnit this Storage is about.
-
getEncoding
public java.nio.charset.Charset getEncoding()
- Returns:
- the encoding used to read the file.
-
getSourceRoot
public java.nio.file.Path getSourceRoot()
- Returns:
- the source root directory, calculated from the path of this compiation unit, and the package declaration of this compilation unit. If the package declaration is invalid (when it does not match the end of the path) a RuntimeException is thrown.
-
getFileName
public java.lang.String getFileName()
-
getDirectory
public java.nio.file.Path getDirectory()
-
save
public void save()
Saves the compilation unit to its original location
-
save
public void save(java.util.function.Function<CompilationUnit,java.lang.String> makeOutput)
Saves a compilation unit to its original location with formatting according to the function passed as a parameter.- Parameters:
makeOutput
- a function that formats the compilation unit
-
save
public void save(java.util.function.Function<CompilationUnit,java.lang.String> makeOutput, java.nio.charset.Charset encoding)
Saves a compilation unit to its original location with formatting and encoding according to the function and encoding passed as a parameter.- Parameters:
makeOutput
- a function that formats the compilation unitencoding
- the encoding to use for the saved file
-
reparse
public ParseResult<CompilationUnit> reparse(JavaParser javaParser)
-
-