Skip to content

Commit 6e3adef

Browse files
committed
Drop semanticdb prefix from indexer-internal symbol APIs
Rename misleadingly-prefixed internal methods in semanticdb-javac and semanticdb-kotlinc (semanticdbSymbol -> scipSymbol, etc.) while keeping the public SemanticdbSymbols class name (still names the adopted grammar and is part of the published semanticdb-shared artifact).
1 parent 076c596 commit 6e3adef

11 files changed

Lines changed: 70 additions & 75 deletions

File tree

‎build.sbt‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,10 @@ lazy val semanticdbKotlinc = project
444444
// `semanticdbKotlincMinimized` mirrors the (still-present) Gradle build at
445445
// semanticdb-kotlinc/minimized/build.gradle.kts. It compiles a small set of
446446
// Kotlin and Java fixtures with the assembled `semanticdbKotlinc` plugin
447-
// attached to kotlinc/javac, producing *.semanticdb files under
448-
// target/semanticdb-targetroot/ which are then converted to SCIP and rendered
449-
// as the human-readable golden snapshots by the `snapshots` task.
447+
// attached to kotlinc/javac, producing *.scip shard files under
448+
// target/semanticdb-targetroot/ which are then aggregated into a single SCIP
449+
// index and rendered as the human-readable golden snapshots by the
450+
// `snapshots` task.
450451
lazy val semanticdbKotlincMinimized = project
451452
.in(file("semanticdb-kotlinc/minimized"))
452453
.enablePlugins(KotlinPlugin)
@@ -510,7 +511,7 @@ lazy val semanticdbKotlincMinimized = project
510511
// ----- snapshots regeneration task -----
511512
// Invokes `com.sourcegraph.scip_java.ScipJava.main` twice in the cli JVM
512513
// (forked — ScipJava.main calls System.exit on failure). First pass
513-
// converts the *.semanticdb files under target/semanticdb-targetroot/
514+
// aggregates the *.scip shard files under target/semanticdb-targetroot/
514515
// into an index.scip; second pass renders that index as the human-readable
515516
// golden snapshots.
516517
//

‎scip-java/src/main/scala/com/sourcegraph/scip_java/ScipSymbol.scala‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ object ScipSymbol {
4242
}
4343
}
4444

45-
private def parseDescriptors(
46-
semanticdbSymbol: String
47-
): List[SymbolDescriptor] = {
48-
val descriptor = SymbolDescriptor.parseFromSymbol(semanticdbSymbol)
45+
private def parseDescriptors(symbol: String): List[SymbolDescriptor] = {
46+
val descriptor = SymbolDescriptor.parseFromSymbol(symbol)
4947
if (descriptor.owner == SemanticdbSymbols.ROOT_PACKAGE)
5048
Nil
5149
else

‎scip-semanticdb/BUILD‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ java_library(
1919
srcs = glob(["src/main/java/**/*.java"]),
2020
deps = [
2121
":all_java_proto",
22-
"//semanticdb-shared",
22+
"//semanticdb-java",
2323
"@maven//:com_google_code_findbugs_jsr305",
2424
"@maven//:com_google_protobuf_protobuf_java",
2525
"@maven//:com_google_protobuf_protobuf_java_util",

‎semanticdb-javac/BUILD‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ java_library(
3131
srcs = glob(["src/main/java/**/*.java"]),
3232
resources = ["src/main/resources/META-INF/services/com.sun.source.util.Plugin"],
3333
deps = [
34-
"//semanticdb-shared",
34+
"//semanticdb-java",
3535
"@maven//:org_scip_code_scip_java_bindings",
3636
],
3737
)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

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

18-
/** Cache of SemanticDB symbols that can be referenced between files. */
18+
/** Cache of symbol strings shared across files. */
1919
public final class GlobalSymbolsCache {
2020

2121
private final IdentityHashMap<Element, String> globals = new IdentityHashMap<>();
@@ -25,19 +25,19 @@ public GlobalSymbolsCache(SemanticdbJavacOptions options) {
2525
this.options = options;
2626
}
2727

28-
public String semanticdbSymbol(Element sym, LocalSymbolsCache locals) {
28+
public String symbol(Element sym, LocalSymbolsCache locals) {
2929
String result = globals.get(sym);
3030
if (result != null) return result;
3131
String localResult = locals.get(sym);
3232
if (localResult != null) return localResult;
33-
result = uncachedSemanticdbSymbol(sym, locals);
33+
result = uncachedSymbol(sym, locals);
3434
if (SemanticdbSymbols.isGlobal(result)) {
3535
globals.put(sym, result);
3636
}
3737
return result;
3838
}
3939

40-
private String uncachedSemanticdbSymbol(Element sym, LocalSymbolsCache locals) {
40+
private String uncachedSymbol(Element sym, LocalSymbolsCache locals) {
4141
if (sym == null) return SemanticdbSymbols.ROOT_PACKAGE;
4242

4343
if (sym instanceof PackageElement) {
@@ -65,10 +65,10 @@ private String uncachedSemanticdbSymbol(Element sym, LocalSymbolsCache locals) {
6565

6666
if (isAnonymousClass(sym) || isLocalVariable(sym)) return locals.put(sym);
6767

68-
String owner = semanticdbSymbol(sym.getEnclosingElement(), locals);
68+
String owner = symbol(sym.getEnclosingElement(), locals);
6969
if (SemanticdbSymbols.isLocal(owner)) return locals.put(sym);
7070

71-
SemanticdbSymbols.Descriptor desc = semanticdbDescriptor(sym);
71+
SemanticdbSymbols.Descriptor desc = descriptor(sym);
7272
if (options.verboseEnabled && desc.kind == SemanticdbSymbols.Descriptor.Kind.None) {
7373
if (sym instanceof QualifiedNameable)
7474
pprint(((QualifiedNameable) sym).getQualifiedName().toString());
@@ -95,7 +95,7 @@ private boolean isAnonymousClass(Element sym) {
9595
return sym instanceof TypeElement && sym.getSimpleName().length() == 0;
9696
}
9797

98-
private SemanticdbSymbols.Descriptor semanticdbDescriptor(Element sym) {
98+
private SemanticdbSymbols.Descriptor descriptor(Element sym) {
9999
if (sym instanceof TypeElement) {
100100
return new SemanticdbSymbols.Descriptor(
101101
SemanticdbSymbols.Descriptor.Kind.Type, sym.getSimpleName().toString());

‎semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/ScipSymbols.java‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
import com.sourcegraph.semanticdb.SemanticdbSymbols;
44

55
/**
6-
* Converts SemanticDB-style symbol strings into the placeholder SCIP form expected by the
7-
* aggregator. The compiler plug-in doesn't know the final Maven coordinates, so globals are
8-
* prefixed with {@link #PLACEHOLDER_PREFIX} and the aggregator rewrites them into {@code "scip-java
9-
* maven <g> <a> <v> <descriptor>"}. Locals use the canonical {@code "local N"} form and pass
10-
* through unchanged.
6+
* Wraps descriptor strings into SCIP symbol strings. The compiler plug-in doesn't know the final
7+
* Maven coordinates, so globals are prefixed with {@link #PLACEHOLDER_PREFIX} and the aggregator
8+
* rewrites them into {@code "scip-java maven <g> <a> <v> <descriptor>"}. Locals use the canonical
9+
* {@code "local N"} form and pass through unchanged.
1110
*/
1211
public final class ScipSymbols {
1312

1413
public static final String PLACEHOLDER_PREFIX = ". . . . ";
1514

1615
private ScipSymbols() {}
1716

18-
public static String fromSemanticdbSymbol(String symbol) {
17+
public static String format(String symbol) {
1918
if (symbol == null || symbol.isEmpty()) return "";
2019
if (SemanticdbSymbols.isLocal(symbol)) {
2120
return "local " + symbol.substring("local".length());

‎semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/ScipVisitor.java‎

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656

5757
/**
5858
* Walks a typechecked compilation unit and builds a {@link Document}. Symbols come from {@link
59-
* GlobalSymbolsCache} via {@link ScipSymbols#fromSemanticdbSymbol(String)} and signatures from
60-
* {@link ScipSignatureFormatter}.
59+
* GlobalSymbolsCache} via {@link ScipSymbols#format(String)} and signatures from {@link
60+
* ScipSignatureFormatter}.
6161
*/
6262
public final class ScipVisitor extends TreePathScanner<Void, Void> {
6363

@@ -130,36 +130,36 @@ private Optional<ScipRange> emitSymbolOccurrence(
130130
private void emitOccurrence(
131131
Element sym, Optional<ScipRange> range, int roles, Optional<ScipRange> enclosingRange) {
132132
if (sym == null || !range.isPresent()) return;
133-
String semanticdbSymbol = semanticdbSymbol(sym);
134-
if (semanticdbSymbol.equals(SemanticdbSymbols.NONE)) return;
133+
String symbol = symbol(sym);
134+
if (symbol.equals(SemanticdbSymbols.NONE)) return;
135135

136136
Occurrence.Builder occ =
137137
Occurrence.newBuilder()
138138
.addAllRange(range.get().asScipRange())
139-
.setSymbol(ScipSymbols.fromSemanticdbSymbol(semanticdbSymbol))
139+
.setSymbol(ScipSymbols.format(symbol))
140140
.setSymbolRoles(roles);
141141
enclosingRange.ifPresent(r -> occ.addAllEnclosingRange(r.asScipRange()));
142142
occurrences.add(occ.build());
143143
}
144144

145145
private void emitSymbolInformation(Element sym, Tree tree) {
146-
String semanticdbSymbol = semanticdbSymbol(sym);
147-
if (semanticdbSymbol.equals(SemanticdbSymbols.NONE)) return;
146+
String symbol = symbol(sym);
147+
if (symbol.equals(SemanticdbSymbols.NONE)) return;
148148

149149
SymbolInformation.Builder builder =
150150
SymbolInformation.newBuilder()
151-
.setSymbol(ScipSymbols.fromSemanticdbSymbol(semanticdbSymbol))
151+
.setSymbol(ScipSymbols.format(symbol))
152152
.setDisplayName(sym.getSimpleName().toString())
153153
.setKind(scipKind(sym));
154154

155-
if (SemanticdbSymbols.isLocal(semanticdbSymbol)) {
156-
String enclosingSymbol = semanticdbSymbol(sym.getEnclosingElement());
155+
if (SemanticdbSymbols.isLocal(symbol)) {
156+
String enclosingSymbol = symbol(sym.getEnclosingElement());
157157
if (enclosingSymbol != null && !enclosingSymbol.equals(SemanticdbSymbols.NONE)) {
158-
builder.setEnclosingSymbol(ScipSymbols.fromSemanticdbSymbol(enclosingSymbol));
158+
builder.setEnclosingSymbol(ScipSymbols.format(enclosingSymbol));
159159
}
160160
}
161161

162-
String documentation = semanticdbDocumentation(tree);
162+
String documentation = documentation(tree);
163163
if (documentation != null && !documentation.isEmpty()) {
164164
builder.addDocumentation(documentation);
165165
}
@@ -181,12 +181,11 @@ private void emitSymbolInformation(Element sym, Tree tree) {
181181
break;
182182
case METHOD:
183183
for (String overridden :
184-
semanticdbOverrides(
185-
(ExecutableElement) sym, sym.getEnclosingElement(), new HashSet<>())) {
184+
overrides((ExecutableElement) sym, sym.getEnclosingElement(), new HashSet<>())) {
186185
if (isIgnoredOverriddenSymbol(overridden)) continue;
187186
builder.addRelationships(
188187
Relationship.newBuilder()
189-
.setSymbol(ScipSymbols.fromSemanticdbSymbol(overridden))
188+
.setSymbol(ScipSymbols.format(overridden))
190189
.setIsImplementation(true)
191190
.setIsReference(supportsReferenceRel));
192191
}
@@ -213,11 +212,11 @@ private void emitSymbolInformation(Element sym, Tree tree) {
213212

214213
private void addParentRelationships(
215214
SymbolInformation.Builder builder, TypeElement sym, boolean supportsReferenceRel) {
216-
for (String parent : semanticdbParentSymbols(sym)) {
215+
for (String parent : parentSymbols(sym)) {
217216
if (isIgnoredOverriddenSymbol(parent)) continue;
218217
builder.addRelationships(
219218
Relationship.newBuilder()
220-
.setSymbol(ScipSymbols.fromSemanticdbSymbol(parent))
219+
.setSymbol(ScipSymbols.format(parent))
221220
.setIsImplementation(true)
222221
.setIsReference(supportsReferenceRel));
223222
}
@@ -464,8 +463,8 @@ private void resolveNewClassTree(NewClassTree node, TreePath treePath) {
464463
}
465464
}
466465

467-
private String semanticdbSymbol(Element sym) {
468-
return globals.semanticdbSymbol(sym, locals);
466+
private String symbol(Element sym) {
467+
return globals.symbol(sym, locals);
469468
}
470469

471470
private Optional<ScipRange> scipRangeOf(Tree tree, CompilerRange kind, Element sym, String name) {
@@ -570,39 +569,38 @@ private static String sourceText(CompilationUnitTree tree) {
570569
}
571570
}
572571

573-
private List<String> semanticdbParentSymbols(TypeElement typeElement) {
572+
private List<String> parentSymbols(TypeElement typeElement) {
574573
ArrayList<String> parentSymbols = new ArrayList<>();
575-
Set<TypeElement> parentElements = semanticdbParentTypeElements(typeElement, new HashSet<>());
574+
Set<TypeElement> parentElements = parentTypeElements(typeElement, new HashSet<>());
576575
for (TypeElement parentElement : parentElements) {
577-
String ssym = semanticdbSymbol(parentElement);
576+
String ssym = symbol(parentElement);
578577
if (!Objects.equals(ssym, SemanticdbSymbols.NONE)) {
579578
parentSymbols.add(ssym);
580579
}
581580
}
582581
return parentSymbols;
583582
}
584583

585-
private Set<TypeElement> semanticdbParentTypeElements(
586-
TypeElement typeElement, Set<TypeElement> result) {
584+
private Set<TypeElement> parentTypeElements(TypeElement typeElement, Set<TypeElement> result) {
587585
TypeMirror superType = typeElement.getSuperclass();
588-
semanticdbParentSymbol(superType, result);
586+
parentSymbol(superType, result);
589587
for (TypeMirror interfaceType : typeElement.getInterfaces()) {
590-
semanticdbParentSymbol(interfaceType, result);
588+
parentSymbol(interfaceType, result);
591589
}
592590
return result;
593591
}
594592

595-
private void semanticdbParentSymbol(TypeMirror elementType, Set<TypeElement> result) {
593+
private void parentSymbol(TypeMirror elementType, Set<TypeElement> result) {
596594
if (!(elementType instanceof NoType)) {
597595
Element superElement = types.asElement(elementType);
598596
if (superElement instanceof TypeElement) {
599597
result.add((TypeElement) superElement);
600-
semanticdbParentTypeElements((TypeElement) superElement, result);
598+
parentTypeElements((TypeElement) superElement, result);
601599
}
602600
}
603601
}
604602

605-
private Set<String> semanticdbOverrides(
603+
private Set<String> overrides(
606604
ExecutableElement sym, Element enclosingElement, Set<String> overriddenSymbols) {
607605
if (enclosingElement instanceof TypeElement) {
608606
List<? extends TypeMirror> superTypes = types.directSupertypes(enclosingElement.asType());
@@ -618,15 +616,15 @@ private Set<String> semanticdbOverrides(
618616
ExecutableElement enclosedExecutableElement = (ExecutableElement) enclosedElement;
619617
if (elements.overrides(
620618
sym, enclosedExecutableElement, (TypeElement) sym.getEnclosingElement())) {
621-
String symbol = semanticdbSymbol(enclosedExecutableElement);
619+
String symbol = symbol(enclosedExecutableElement);
622620
overriddenSymbols.add(symbol);
623621
methodFound = true;
624-
semanticdbOverrides(enclosedExecutableElement, superElement, overriddenSymbols);
622+
overrides(enclosedExecutableElement, superElement, overriddenSymbols);
625623
}
626624
}
627625
}
628626
if (!methodFound) {
629-
semanticdbOverrides(sym, superElement, overriddenSymbols);
627+
overrides(sym, superElement, overriddenSymbols);
630628
}
631629
}
632630
}
@@ -653,7 +651,7 @@ private static String sourceRelativePath(
653651
return out.toString();
654652
}
655653

656-
private String semanticdbDocumentation(Tree tree) {
654+
private String documentation(Tree tree) {
657655
try {
658656
TreePath treePath = nodes.get(tree);
659657
String doc = trees.getDocComment(treePath);

‎semanticdb-kotlinc/src/main/kotlin/com/sourcegraph/semanticdb_kotlinc/ScipSymbols.kt‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package com.sourcegraph.semanticdb_kotlinc
22

33
/**
4-
* Converts SemanticDB-style symbol strings into the placeholder SCIP form expected by the
5-
* aggregator: globals are prefixed with [PLACEHOLDER_PREFIX] (rewritten to
6-
* `scip-java maven <g> <a> <v> <descriptor>` once coordinates are known), locals use the canonical
7-
* `local N` form and pass through unchanged. Mirrors the Java `ScipSymbols` helper.
4+
* Wraps descriptor strings into SCIP symbol strings: globals are prefixed with [PLACEHOLDER_PREFIX]
5+
* (rewritten to `scip-java maven <g> <a> <v> <descriptor>` once coordinates are known), locals use
6+
* the canonical `local N` form and pass through unchanged. Mirrors the Java `ScipSymbols` helper.
87
*/
98
object ScipSymbols {
109

1110
const val PLACEHOLDER_PREFIX: String = ". . . . "
1211

13-
fun fromSemanticdbSymbol(symbol: Symbol): String {
12+
fun format(symbol: Symbol): String {
1413
if (symbol == Symbol.NONE) return ""
1514
val raw = symbol.toString()
1615
if (symbol.isLocal()) {

‎semanticdb-kotlinc/src/main/kotlin/com/sourcegraph/semanticdb_kotlinc/ScipTextDocumentBuilder.kt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ScipTextDocumentBuilder(
7474
Occurrence
7575
.newBuilder()
7676
.addAllRange(scipRange(element))
77-
.setSymbol(ScipSymbols.fromSemanticdbSymbol(symbol))
77+
.setSymbol(ScipSymbols.format(symbol))
7878
.setSymbolRoles(roles)
7979
if (enclosingSource != null) {
8080
builder.addAllEnclosingRange(scipEnclosingRange(enclosingSource))
@@ -89,7 +89,7 @@ class ScipTextDocumentBuilder(
8989
element: KtSourceElement,
9090
context: CheckerContext,
9191
) {
92-
val scipSymbolStr = ScipSymbols.fromSemanticdbSymbol(symbol)
92+
val scipSymbolStr = ScipSymbols.format(symbol)
9393
val builder =
9494
SymbolInformation
9595
.newBuilder()
@@ -110,7 +110,7 @@ class ScipTextDocumentBuilder(
110110

111111
val supportsRefRel = supportsReferenceRelationship(firBasedSymbol)
112112
for (parent in parentOrOverriddenSymbols(firBasedSymbol, context)) {
113-
val parentSymbolStr = ScipSymbols.fromSemanticdbSymbol(parent)
113+
val parentSymbolStr = ScipSymbols.format(parent)
114114
if (parentSymbolStr.isEmpty()) continue
115115
builder.addRelationships(
116116
Relationship.newBuilder()

0 commit comments

Comments
 (0)