Skip to content

Commit 0d693a4

Browse files
authored
Merge pull request #91 from sourcegraph/nsc/jdk9+
JDK 9+ Support
2 parents fb0a21a + 38c865e commit 0d693a4

24 files changed

+757
-465
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v2
1212
- uses: olafurpg/setup-scala@v10
13+
with:
14+
java-version: [email protected]
1315
- run: sbt test
1416
check:
1517
runs-on: ubuntu-latest
1618
steps:
1719
- uses: actions/checkout@v2
1820
- uses: olafurpg/setup-scala@v10
21+
with:
22+
java-version: [email protected]
1923
- run: sbt checkAll

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ These are the main components of the project.
105105
| `./sbt` | terminal | Start interactive sbt shell with Java 8. Takes a while to load on the first run. |
106106
| `unit/test` | sbt | Run fast unit tests. |
107107
| `~unit/test` | sbt | Start watch mode to run tests on file save, good for local edit-and-test workflows. |
108-
| `snapshot/testOnly tests.MinimizedSnapshotSuite` | sbt | Runs fast snapshot tests. Indexes a small set of files under `tests/minimized`. |
109-
| `snapshot/testOnly tests.MinimizedSnapshotSuite -- *InnerClasses*` | sbt | Runs only individual tests cases matching the name "InnerClasses". |
110-
| `snapshot/testOnly tests.LibrarySnapshotSuite` | sbt | Runs slow snapshot tests. Indexes a corpus of external Java libraries. |
111-
| `snapshot/test` | sbt | Runs all snapshot tests. |
112-
| `snapshot/run` | sbt | Update snapshot tests. Use this command after you have fixed a bug. |
108+
| `snapshots/testOnly tests.MinimizedSnapshotSuite` | sbt | Runs fast snapshot tests. Indexes a small set of files under `tests/minimized`. |
109+
| `snapshots/testOnly tests.MinimizedSnapshotSuite -- *InnerClasses*` | sbt | Runs only individual tests cases matching the name "InnerClasses". |
110+
| `snapshots/testOnly tests.LibrarySnapshotSuite` | sbt | Runs slow snapshot tests. Indexes a corpus of external Java libraries. |
111+
| `snapshots/test` | sbt | Runs all snapshot tests. |
112+
| `snapshots/run` | sbt | Update snapshot tests. Use this command after you have fixed a bug. |
113113
| `fixAll` | sbt | Run Scalafmt, Scalafix and Javafmt on all sources. Run this before opening a PR. |
114114

115115
### Import the project into IntelliJ

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/GlobalSymbolsCache.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.sourcegraph.semanticdb_javac;
22

3-
import com.sun.tools.javac.code.Kinds;
4-
import com.sun.tools.javac.code.Scope;
53
import com.sun.tools.javac.code.Symbol;
64

7-
import java.util.ArrayList;
8-
import java.util.Collections;
9-
import java.util.IdentityHashMap;
5+
import javax.lang.model.element.Element;
6+
import javax.lang.model.element.ExecutableElement;
7+
import java.util.*;
108

119
import static com.sourcegraph.semanticdb_javac.Debugging.pprint;
1210

@@ -33,7 +31,7 @@ public String semanticdbSymbol(Symbol sym, LocalSymbolsCache locals) {
3331
}
3432

3533
public boolean isNone(Symbol sym) {
36-
return sym == null || sym.kind == Kinds.NIL || (sym.kind & Kinds.ERRONEOUS) != 0;
34+
return sym == null;
3735
}
3836

3937
private String uncachedSemanticdbSymbol(Symbol sym, LocalSymbolsCache locals) {
@@ -97,18 +95,13 @@ private SemanticdbSymbols.Descriptor semanticdbDescriptor(Symbol sym) {
9795
* SemanticDB spec</a>.
9896
*/
9997
private String methodDisambiguator(Symbol.MethodSymbol sym) {
100-
Scope.Entry lookup =
101-
sym.owner.members().lookup(sym.name, s -> s instanceof Symbol.MethodSymbol);
102-
ArrayList<Symbol> peers = new ArrayList<>();
103-
while (lookup != null) {
104-
if (lookup.sym != null) {
105-
peers.add(lookup.sym);
98+
Iterable<? extends Element> elements = sym.owner.getEnclosedElements();
99+
ArrayList<ExecutableElement> methods = new ArrayList<>();
100+
for (Element e : elements) {
101+
if (e instanceof ExecutableElement && e.getSimpleName() == sym.name) {
102+
methods.add((ExecutableElement) e);
106103
}
107-
lookup = lookup.next();
108104
}
109-
// NOTE(olafur): reverse the iteration from `Scope.Entry` to get order in which the symbols are
110-
// defined in source.
111-
Collections.reverse(peers);
112105
// NOTE(olafur): sort static methods last, according to the spec. Historical note: this
113106
// requirement is
114107
// part of the SemanticDB spec because static methods and non-static methods have a different
@@ -117,8 +110,9 @@ private String methodDisambiguator(Symbol.MethodSymbol sym) {
117110
// definitions.
118111
// In practice, it's unusual to mix static and non-static methods so this shouldn't be a big
119112
// issue.
120-
peers.sort((a, b) -> Boolean.compare(a.isStatic(), b.isStatic()));
121-
int index = peers.indexOf(sym);
113+
methods.sort(
114+
(a, b) -> Boolean.compare(a.getReceiverType() == null, b.getReceiverType() == null));
115+
int index = methods.indexOf(sym);
122116
if (index == 0) return "()";
123117
return String.format("(+%d)", index);
124118
}

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import com.sun.source.util.JavacTask;
55
import com.sun.source.util.TaskEvent;
66
import com.sun.source.util.TreePathScanner;
7+
import com.sun.source.util.Trees;
78
import com.sun.tools.javac.code.Symbol;
89
import com.sun.tools.javac.tree.EndPosTable;
910
import com.sun.tools.javac.tree.JCTree;
1011
import com.sun.tools.javac.util.JCDiagnostic;
1112
import com.sun.tools.javac.util.Position;
12-
import com.sourcegraph.semanticdb_javac.Semanticdb;
1313
import com.sourcegraph.semanticdb_javac.Semanticdb.SymbolOccurrence.Role;
1414

1515
import javax.lang.model.util.Elements;

0 commit comments

Comments
 (0)