summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2018-12-30 16:52:39 -0800
committerGeorge Fraser <george@fivetran.com>2018-12-30 16:52:39 -0800
commitf8f680f3636a132975381e8bb8ca55f7af8bd68a (patch)
tree3b8aaf9fa127ee449932e4bf46261dc76df110a2 /src
parentab0204a4fb369a1aa17d1e1f863477825d228fb8 (diff)
downloadjava-language-server-f8f680f3636a132975381e8bb8ca55f7af8bd68a.zip
Cleanup
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/javacs/CompileBatch.java45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/main/java/org/javacs/CompileBatch.java b/src/main/java/org/javacs/CompileBatch.java
index aeda6f3..f344c82 100644
--- a/src/main/java/org/javacs/CompileBatch.java
+++ b/src/main/java/org/javacs/CompileBatch.java
@@ -157,28 +157,6 @@ public class CompileBatch {
return field.getEnclosingElement() instanceof TypeElement;
}
- private Optional<TreePath> ref(TreePath from) {
- var root = from.getCompilationUnit();
- var lines = root.getLineMap();
- var to = trees.getElement(from);
- // Skip elements we can't find
- if (to == null) {
- // LOG.warning(String.format("No element for `%s`", from.getLeaf()));
- return Optional.empty();
- }
- // Skip non-methods
- if (!(to instanceof ExecutableElement || to instanceof TypeElement || isField(to))) {
- return Optional.empty();
- }
- // TODO skip anything not on source path
- var result = trees.getPath(to);
- if (result == null) {
- // LOG.warning(String.format("Element `%s` has no TreePath", to));
- return Optional.empty();
- }
- return Optional.of(result);
- }
-
private List<TreePath> referencesToElement(CompilationUnitTree root, Element to) {
var trees = Trees.instance(task);
var results = new ArrayList<TreePath>();
@@ -222,8 +200,31 @@ public class CompileBatch {
}
private List<Ptr> index(CompilationUnitTree root) {
+ // TODO remember if the file contains errors, and keep re-indexing it
var refs = new ArrayList<Ptr>();
class IndexFile extends TreePathScanner<Void, Void> {
+ Optional<TreePath> ref(TreePath from) {
+ var root = from.getCompilationUnit();
+ var lines = root.getLineMap();
+ var to = trees.getElement(from);
+ // Skip elements we can't find
+ if (to == null) {
+ // LOG.warning(String.format("No element for `%s`", from.getLeaf()));
+ return Optional.empty();
+ }
+ // Skip non-methods
+ if (!(to instanceof ExecutableElement || to instanceof TypeElement || isField(to))) {
+ return Optional.empty();
+ }
+ // TODO skip anything not on source path
+ var result = trees.getPath(to);
+ if (result == null) {
+ // LOG.warning(String.format("Element `%s` has no TreePath", to));
+ return Optional.empty();
+ }
+ return Optional.of(result);
+ }
+
void check(TreePath from) {
var r = ref(from);
if (r.isPresent()) {