Skip to content

Commit

Permalink
rename of class, added some comments and added one final check for sk…
Browse files Browse the repository at this point in the history
…ipping a directory only when the root is succesfully added to known roots
  • Loading branch information
daanschipper committed Feb 27, 2018
1 parent 9b6720e commit 354773c
Showing 1 changed file with 10 additions and 5 deletions.
Expand Up @@ -46,14 +46,18 @@
import static java.nio.file.FileVisitResult.CONTINUE;
import static java.nio.file.FileVisitResult.SKIP_SIBLINGS;

public class SymbolSourceRoot {
/**
* Utility class to add all jars and roots of java files of the provided path to a TypeSolver instance.
* It traverses the file directory tree and adds all files ending in either .java or .jar.
*/
public class SymbolSolverQuickSetup {

private static Logger logger = Logger.getLogger(JavaParserFacade.class.getCanonicalName());

private final Path root;
private CombinedTypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(false));

public SymbolSourceRoot(Path root) {
public SymbolSolverQuickSetup(Path root) {
assertNotNull(root);
if (!Files.isDirectory(root)) {
throw new IllegalArgumentException("Only directories are allowed as root path!");
Expand Down Expand Up @@ -105,9 +109,10 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attr) throws Fil
.map(CompilationUnit.Storage::getSourceRoot);
if (root.isPresent()) {
typeSolver.add(new JavaParserTypeSolver(root.get().toFile()));
roots.add(root.get());
logger.log(Level.FINE, "Added dir " + root.get() + " to the TypeSolver");
return SKIP_SIBLINGS;
if (roots.add(root.get())) {
logger.log(Level.FINE, "Added dir " + root.get() + " to the TypeSolver");
return SKIP_SIBLINGS;
}
}
} catch (ParseProblemException e) {
logger.log(Level.WARNING, "Unable to parse file " + file, e);
Expand Down

0 comments on commit 354773c

Please sign in to comment.