public class SourceRoot
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
SourceRoot.Callback |
private static class |
SourceRoot.ParallelParse
Executes a recursive file tree walk using threads.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.nio.file.Path,ParseResult<CompilationUnit>> |
cache |
private JavaParser |
javaParser |
private java.util.function.Function<CompilationUnit,java.lang.String> |
printer |
private java.nio.file.Path |
root |
Constructor and Description |
---|
SourceRoot(java.nio.file.Path root) |
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(java.lang.String pkg,
java.lang.String filename,
CompilationUnit compilationUnit)
Add a newly created Java file to the cache of this source root.
|
java.util.List<ParseResult<CompilationUnit>> |
getCache()
The Java files that have been parsed by this source root object,
or have been added manually.
|
java.util.List<CompilationUnit> |
getCompilationUnits()
The CompilationUnits of the Java files that have been parsed succesfully by this source root object,
or have been added manually.
|
JavaParser |
getJavaParser() |
java.util.function.Function<CompilationUnit,java.lang.String> |
getPrinter()
Get the printing function.
|
java.nio.file.Path |
getRoot()
The path that was passed in the constructor.
|
private void |
logPackage(java.lang.String startPackage) |
SourceRoot |
parse(java.lang.String startPackage,
JavaParser javaParser,
SourceRoot.Callback callback)
Tries to parse all .java files in a package recursively and passes them one by one to the callback.
|
CompilationUnit |
parse(java.lang.String pkg,
java.lang.String filename)
Parses a .java files under the source root and returns its CompilationUnit.
|
SourceRoot |
parseParallelized(java.lang.String startPackage,
JavaParser javaParser,
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.
|
private SourceRoot |
save(CompilationUnit cu,
java.nio.file.Path path)
Save the given compilation unit to the given path.
|
SourceRoot |
saveAll()
Save all previously parsed files back to where they were found.
|
SourceRoot |
saveAll(java.nio.file.Path root)
Save all previously parsed files back to a new path.
|
SourceRoot |
setJavaParser(JavaParser javaParser)
Set the parser that is used for parsing by default.
|
SourceRoot |
setPrinter(java.util.function.Function<CompilationUnit,java.lang.String> printer)
Set the printing function that transforms compilation units into a string to save.
|
java.util.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.
|
java.util.List<ParseResult<CompilationUnit>> |
tryToParse(java.lang.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(java.lang.String pkg,
java.lang.String filename)
Tries to parse a .java files under the source root and returns the ParseResult.
|
ParseResult<CompilationUnit> |
tryToParse(java.lang.String pkg,
java.lang.String filename,
JavaParser javaParser)
Tries to parse a .java files under the source root and returns the ParseResult.
|
java.util.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.
|
java.util.List<ParseResult<CompilationUnit>> |
tryToParseParallelized(java.lang.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.
|
private final java.nio.file.Path root
private final java.util.Map<java.nio.file.Path,ParseResult<CompilationUnit>> cache
private JavaParser javaParser
private java.util.function.Function<CompilationUnit,java.lang.String> printer
public ParseResult<CompilationUnit> tryToParse(java.lang.String pkg, java.lang.String filename, JavaParser javaParser) throws java.io.IOException
java.io.IOException
public ParseResult<CompilationUnit> tryToParse(java.lang.String pkg, java.lang.String filename) throws java.io.IOException
java.io.IOException
public java.util.List<ParseResult<CompilationUnit>> tryToParse(java.lang.String startPackage) throws java.io.IOException
java.io.IOException
public java.util.List<ParseResult<CompilationUnit>> tryToParse() throws java.io.IOException
java.io.IOException
public java.util.List<ParseResult<CompilationUnit>> tryToParseParallelized(java.lang.String startPackage) throws java.io.IOException
setJavaParser
) 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.java.io.IOException
public java.util.List<ParseResult<CompilationUnit>> tryToParseParallelized() throws java.io.IOException
setJavaParser
) 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.java.io.IOException
public CompilationUnit parse(java.lang.String pkg, java.lang.String filename)
ParseProblemException
- when something went wrong.public SourceRoot parse(java.lang.String startPackage, JavaParser javaParser, SourceRoot.Callback callback) throws java.io.IOException
java.io.IOException
private void logPackage(java.lang.String startPackage)
public SourceRoot parseParallelized(java.lang.String startPackage, JavaParser javaParser, SourceRoot.Callback callback) throws java.io.IOException
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
JavaParser
's configuration.
In comparison to the other parse methods, this is much more memory efficient,
but saveAll() won't work.java.io.IOException
public SourceRoot add(java.lang.String pkg, java.lang.String filename, CompilationUnit compilationUnit)
public SourceRoot add(CompilationUnit compilationUnit)
private SourceRoot save(CompilationUnit cu, java.nio.file.Path path)
public SourceRoot saveAll(java.nio.file.Path root)
public SourceRoot saveAll()
public java.util.List<ParseResult<CompilationUnit>> getCache()
public java.util.List<CompilationUnit> getCompilationUnits()
public java.nio.file.Path getRoot()
public JavaParser getJavaParser()
public SourceRoot setJavaParser(JavaParser javaParser)
public SourceRoot setPrinter(java.util.function.Function<CompilationUnit,java.lang.String> printer)
public java.util.function.Function<CompilationUnit,java.lang.String> getPrinter()