Skip to content

Commit

Permalink
Merge pull request #91 from sourcegraph/nsc/jdk9+
Browse files Browse the repository at this point in the history
JDK 9+ Support
  • Loading branch information
olafurpg committed Mar 1, 2021
2 parents fb0a21a + 38c865e commit 0d693a4
Show file tree
Hide file tree
Showing 24 changed files with 757 additions and 465 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v10
with:
java-version: adopt@1.11
- run: sbt test
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v10
with:
java-version: adopt@1.11
- run: sbt checkAll
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ These are the main components of the project.
| `./sbt` | terminal | Start interactive sbt shell with Java 8. Takes a while to load on the first run. |
| `unit/test` | sbt | Run fast unit tests. |
| `~unit/test` | sbt | Start watch mode to run tests on file save, good for local edit-and-test workflows. |
| `snapshot/testOnly tests.MinimizedSnapshotSuite` | sbt | Runs fast snapshot tests. Indexes a small set of files under `tests/minimized`. |
| `snapshot/testOnly tests.MinimizedSnapshotSuite -- *InnerClasses*` | sbt | Runs only individual tests cases matching the name "InnerClasses". |
| `snapshot/testOnly tests.LibrarySnapshotSuite` | sbt | Runs slow snapshot tests. Indexes a corpus of external Java libraries. |
| `snapshot/test` | sbt | Runs all snapshot tests. |
| `snapshot/run` | sbt | Update snapshot tests. Use this command after you have fixed a bug. |
| `snapshots/testOnly tests.MinimizedSnapshotSuite` | sbt | Runs fast snapshot tests. Indexes a small set of files under `tests/minimized`. |
| `snapshots/testOnly tests.MinimizedSnapshotSuite -- *InnerClasses*` | sbt | Runs only individual tests cases matching the name "InnerClasses". |
| `snapshots/testOnly tests.LibrarySnapshotSuite` | sbt | Runs slow snapshot tests. Indexes a corpus of external Java libraries. |
| `snapshots/test` | sbt | Runs all snapshot tests. |
| `snapshots/run` | sbt | Update snapshot tests. Use this command after you have fixed a bug. |
| `fixAll` | sbt | Run Scalafmt, Scalafix and Javafmt on all sources. Run this before opening a PR. |

### Import the project into IntelliJ
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.sourcegraph.semanticdb_javac;

import com.sun.tools.javac.code.Kinds;
import com.sun.tools.javac.code.Scope;
import com.sun.tools.javac.code.Symbol;

import java.util.ArrayList;
import java.util.Collections;
import java.util.IdentityHashMap;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import java.util.*;

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

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

public boolean isNone(Symbol sym) {
return sym == null || sym.kind == Kinds.NIL || (sym.kind & Kinds.ERRONEOUS) != 0;
return sym == null;
}

private String uncachedSemanticdbSymbol(Symbol sym, LocalSymbolsCache locals) {
Expand Down Expand Up @@ -97,18 +95,13 @@ private SemanticdbSymbols.Descriptor semanticdbDescriptor(Symbol sym) {
* SemanticDB spec</a>.
*/
private String methodDisambiguator(Symbol.MethodSymbol sym) {
Scope.Entry lookup =
sym.owner.members().lookup(sym.name, s -> s instanceof Symbol.MethodSymbol);
ArrayList<Symbol> peers = new ArrayList<>();
while (lookup != null) {
if (lookup.sym != null) {
peers.add(lookup.sym);
Iterable<? extends Element> elements = sym.owner.getEnclosedElements();
ArrayList<ExecutableElement> methods = new ArrayList<>();
for (Element e : elements) {
if (e instanceof ExecutableElement && e.getSimpleName() == sym.name) {
methods.add((ExecutableElement) e);
}
lookup = lookup.next();
}
// NOTE(olafur): reverse the iteration from `Scope.Entry` to get order in which the symbols are
// defined in source.
Collections.reverse(peers);
// NOTE(olafur): sort static methods last, according to the spec. Historical note: this
// requirement is
// part of the SemanticDB spec because static methods and non-static methods have a different
Expand All @@ -117,8 +110,9 @@ private String methodDisambiguator(Symbol.MethodSymbol sym) {
// definitions.
// In practice, it's unusual to mix static and non-static methods so this shouldn't be a big
// issue.
peers.sort((a, b) -> Boolean.compare(a.isStatic(), b.isStatic()));
int index = peers.indexOf(sym);
methods.sort(
(a, b) -> Boolean.compare(a.getReceiverType() == null, b.getReceiverType() == null));
int index = methods.indexOf(sym);
if (index == 0) return "()";
return String.format("(+%d)", index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import com.sun.source.util.JavacTask;
import com.sun.source.util.TaskEvent;
import com.sun.source.util.TreePathScanner;
import com.sun.source.util.Trees;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.tree.EndPosTable;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.util.JCDiagnostic;
import com.sun.tools.javac.util.Position;
import com.sourcegraph.semanticdb_javac.Semanticdb;
import com.sourcegraph.semanticdb_javac.Semanticdb.SymbolOccurrence.Role;

import javax.lang.model.util.Elements;
Expand Down
Loading

0 comments on commit 0d693a4

Please sign in to comment.