Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK 9+ Support #91

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: [email protected]
- run: sbt test
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v10
with:
java-version: [email protected]
- 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`. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

| `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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find 👍 This looks like a decent replacement for members().lookup()

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