1 package com.github.javaparser.utils; 2 3 import com.github.javaparser.ParserConfiguration; 4 5 import java.nio.file.Path; 6 import java.util.ArrayList; 7 import java.util.List; 8 import java.util.Map; 9 import java.util.Optional; 10 import java.util.concurrent.ConcurrentHashMap; 11 12 /** 13 * The structure of a Java project directory. 14 * It was originally created specifically to quickly configure the symbol solver. 15 * You can use it as a general container for project information. 16 * <p/>A project has a root directory, and it has zero or more directories that contain source code. 17 * <p/>To create a ProjectRoot use a CollectionStrategy, or instantiate ProjectRoot yourself. 18 */ 19 public class ProjectRoot { 20 21 private final Path root; 22 private final Map<Path, SourceRoot> cache = new ConcurrentHashMap<>(); 23 private final ParserConfiguration parserConfiguration; 24 ProjectRoot(Path root)25 public ProjectRoot(Path root) { 26 this(root, new ParserConfiguration()); 27 } 28 ProjectRoot(Path root, ParserConfiguration parserConfiguration)29 public ProjectRoot(Path root, ParserConfiguration parserConfiguration) { 30 this.root = root; 31 this.parserConfiguration = parserConfiguration; 32 } 33 getSourceRoot(Path sourceRoot)34 public Optional<SourceRoot> getSourceRoot(Path sourceRoot) { 35 return Optional.ofNullable(cache.get(sourceRoot)); 36 } 37 getSourceRoots()38 public List<SourceRoot> getSourceRoots() { 39 return new ArrayList<>(cache.values()); 40 } 41 addSourceRoot(Path path)42 public void addSourceRoot(Path path) { 43 cache.put(path, new SourceRoot(path).setParserConfiguration(parserConfiguration)); 44 } 45 getRoot()46 public Path getRoot() { 47 return root; 48 } 49 50 @Override toString()51 public String toString() { 52 return "ProjectRoot at " + root + " with " + cache.values().toString(); 53 } 54 } 55