public class SourceRoot extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
SourceRoot.Callback |
Constructor and Description |
---|
SourceRoot(Path root) |
SourceRoot(Path root,
ParserConfiguration parserConfiguration) |
Modifier and Type | Method and Description |
---|---|
SourceRoot |
add(CompilationUnit compilationUnit)
Add a newly created Java file to the cache of this source root.
|
SourceRoot |
add(String startPackage,
String filename,
CompilationUnit compilationUnit)
Add a newly created Java file to the cache of this source root.
|
List<ParseResult<CompilationUnit>> |
getCache()
The Java files that have been parsed by this source root object, or have been added manually.
|
List<CompilationUnit> |
getCompilationUnits()
The CompilationUnits of the Java files that have been parsed succesfully by this source root object, or have been
added manually.
|
ParserConfiguration |
getParserConfiguration() |
Function<CompilationUnit,String> |
getPrinter()
Get the printing function.
|
Path |
getRoot()
The path that was passed in the constructor.
|
SourceRoot |
parse(String startPackage,
ParserConfiguration configuration,
SourceRoot.Callback callback)
Tries to parse all .java files in a package recursively and passes them one by one to the callback.
|
SourceRoot |
parse(String startPackage,
SourceRoot.Callback callback) |
CompilationUnit |
parse(String startPackage,
String filename)
Parses a .java files under the source root and returns its CompilationUnit.
|
SourceRoot |
parse(String startPackage,
String filename,
ParserConfiguration configuration,
SourceRoot.Callback callback)
Locates the .java file with the provided package and file name, parses it and passes it to the
callback.
|
SourceRoot |
parse(String startPackage,
String filename,
SourceRoot.Callback callback)
Parses the provided .java file and passes it to the callback.
|
SourceRoot |
parseParallelized(SourceRoot.Callback callback)
Tries to parse all .java files recursively using multiple threads, and passes them one by one to the callback.
|
SourceRoot |
parseParallelized(String startPackage,
ParserConfiguration configuration,
SourceRoot.Callback callback)
Tries to parse all .java files in a package recursively using multiple threads, and passes them one by one to the
callback.
|
SourceRoot |
parseParallelized(String startPackage,
SourceRoot.Callback callback)
Tries to parse all .java files in a package recursively using multiple threads, and passes them one by one to the
callback.
|
SourceRoot |
saveAll()
Save all previously parsed files back to where they were found.
|
SourceRoot |
saveAll(Charset encoding)
Save all previously parsed files back to where they were found, with the given encoding.
|
SourceRoot |
saveAll(Path root)
Save all previously parsed files back to a new path.
|
SourceRoot |
saveAll(Path root,
Charset encoding)
Save all previously parsed files back to a new path.
|
SourceRoot |
setParserConfiguration(ParserConfiguration parserConfiguration)
Set the parser configuration that is used for parsing when no configuration is passed to a method.
|
SourceRoot |
setPrinter(Function<CompilationUnit,String> printer)
Set the printing function that transforms compilation units into a string to save.
|
String |
toString() |
List<ParseResult<CompilationUnit>> |
tryToParse()
Tries to parse all .java files under the source root recursively, and returns all files ever parsed with this
source root.
|
List<ParseResult<CompilationUnit>> |
tryToParse(String startPackage)
Tries to parse all .java files in a package recursively, and returns all files ever parsed with this source root.
|
ParseResult<CompilationUnit> |
tryToParse(String startPackage,
String filename)
Tries to parse a .java files under the source root and returns the ParseResult.
|
ParseResult<CompilationUnit> |
tryToParse(String startPackage,
String filename,
ParserConfiguration configuration)
Tries to parse a .java files under the source root and returns the ParseResult.
|
List<ParseResult<CompilationUnit>> |
tryToParseParallelized()
Tries to parse all .java files under the source root recursively using multiple threads, and returns all files
ever parsed with this source root.
|
List<ParseResult<CompilationUnit>> |
tryToParseParallelized(String startPackage)
Tries to parse all .java files in a package recursively using multiple threads, and returns all files ever parsed
with this source root.
|
public SourceRoot(Path root)
root
- the root directory of a set of source files. It corresponds to the root of the package structure of the
source files within, like "javaparser/javaparser-core/src/main/java"public SourceRoot(Path root, ParserConfiguration parserConfiguration)
root
- the root directory of a set of source files. It corresponds to the root of the package structure of the
source files within, like "javaparser/javaparser-core/src/main/java"public ParseResult<CompilationUnit> tryToParse(String startPackage, String filename, ParserConfiguration configuration) throws IOException
startPackage
- files in this package and deeper are parsed. Pass "" to parse all files.IOException
public ParseResult<CompilationUnit> tryToParse(String startPackage, String filename) throws IOException
startPackage
- files in this package and deeper are parsed. Pass "" to parse all files.IOException
public List<ParseResult<CompilationUnit>> tryToParse(String startPackage) throws IOException
startPackage
- files in this package and deeper are parsed. Pass "" to parse all files.IOException
public List<ParseResult<CompilationUnit>> tryToParse() throws IOException
IOException
public List<ParseResult<CompilationUnit>> tryToParseParallelized(String startPackage)
setParserConfiguration(ParserConfiguration)
) configuration.
It keeps track of all parsed files so you can write them out with a single saveAll() call.
Note that the cache grows with every file parsed,
so if you don't need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the cache is
useful) you might want to use the parse method with a callback.startPackage
- files in this package and deeper are parsed. Pass "" to parse all files.public List<ParseResult<CompilationUnit>> tryToParseParallelized()
setParserConfiguration(ParserConfiguration)
) configuration. It keeps track of
all parsed files so you can write them out with a single saveAll() call. Note that the cache grows with every
file parsed, so if you don't need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the
cache is useful) you might want to use the parse method with a callback.public CompilationUnit parse(String startPackage, String filename)
startPackage
- files in this package and deeper are parsed. Pass "" to parse all files.ParseProblemException
- when something went wrong.public SourceRoot parse(String startPackage, String filename, ParserConfiguration configuration, SourceRoot.Callback callback) throws IOException
startPackage
- The package containing the filefilename
- The name of the fileIOException
public SourceRoot parse(String startPackage, String filename, SourceRoot.Callback callback) throws IOException
IOException
public SourceRoot parse(String startPackage, ParserConfiguration configuration, SourceRoot.Callback callback) throws IOException
startPackage
- files in this package and deeper are parsed. Pass "" to parse all files.IOException
public SourceRoot parse(String startPackage, SourceRoot.Callback callback) throws IOException
IOException
public SourceRoot parseParallelized(String startPackage, ParserConfiguration configuration, SourceRoot.Callback callback)
SourceRoot.Callback
code must be made thread-safe. Note
that to ensure thread safety, a new parser instance is created for every file with the provided ParserConfiguration
. In comparison to the other parse methods, this is much more memory efficient, but saveAll()
won't work.startPackage
- files in this package and deeper are parsed. Pass "" to parse all files.public SourceRoot parseParallelized(String startPackage, SourceRoot.Callback callback) throws IOException
SourceRoot.Callback
code must be made thread-safe. Note
that to ensure thread safety, a new parser instance is created for every file. In comparison to the other
parse methods, this is much more memory efficient, but saveAll() won't work.startPackage
- files in this package and deeper are parsed. Pass "" to parse all files.IOException
public SourceRoot parseParallelized(SourceRoot.Callback callback) throws IOException
SourceRoot.Callback
code must be made thread-safe. Note that to
ensure thread safety, a new parser instance is created for every file. In comparison to the other parse methods,
this is much more memory efficient, but saveAll() won't work.IOException
public SourceRoot add(String startPackage, String filename, CompilationUnit compilationUnit)
startPackage
- files in this package and deeper are parsed. Pass "" to parse all files.public SourceRoot add(CompilationUnit compilationUnit)
public SourceRoot saveAll(Path root, Charset encoding)
root
- the root of the java packagesencoding
- the encoding to use while saving the filepublic SourceRoot saveAll(Path root)
root
- the root of the java packagespublic SourceRoot saveAll()
public SourceRoot saveAll(Charset encoding)
encoding
- the encoding to use.public List<ParseResult<CompilationUnit>> getCache()
public List<CompilationUnit> getCompilationUnits()
public Path getRoot()
public ParserConfiguration getParserConfiguration()
public SourceRoot setParserConfiguration(ParserConfiguration parserConfiguration)
public SourceRoot setPrinter(Function<CompilationUnit,String> printer)
public Function<CompilationUnit,String> getPrinter()
Copyright © 2007–2023. All rights reserved.