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