Skip to content

Commit 4ec31f0

Browse files
committed
Drop semanticdb prefix from indexer-internal symbol APIs
ScipSymbols.fromSemanticdbSymbol becomes ScipSymbols.format. Helpers named semanticdbXxx in GlobalSymbolsCache/SymbolsCache/ScipVisitor drop the misleading prefix; the SemanticdbSymbols utility class is kept since it encapsulates the symbol grammar SCIP adopted from SemanticDB.
1 parent 6e8e91f commit 4ec31f0

8 files changed

Lines changed: 63 additions & 69 deletions

File tree

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

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
@@ -13,7 +13,7 @@
1313

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

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

1919
private final IdentityHashMap<Element, String> globals = new IdentityHashMap<>();
@@ -23,19 +23,19 @@ public GlobalSymbolsCache(SemanticdbJavacOptions options) {
2323
this.options = options;
2424
}
2525

26-
public String semanticdbSymbol(Element sym, LocalSymbolsCache locals) {
26+
public String symbol(Element sym, LocalSymbolsCache locals) {
2727
String result = globals.get(sym);
2828
if (result != null) return result;
2929
String localResult = locals.get(sym);
3030
if (localResult != null) return localResult;
31-
result = uncachedSemanticdbSymbol(sym, locals);
31+
result = uncachedSymbol(sym, locals);
3232
if (SemanticdbSymbols.isGlobal(result)) {
3333
globals.put(sym, result);
3434
}
3535
return result;
3636
}
3737

38-
private String uncachedSemanticdbSymbol(Element sym, LocalSymbolsCache locals) {
38+
private String uncachedSymbol(Element sym, LocalSymbolsCache locals) {
3939
if (sym == null) return SemanticdbSymbols.ROOT_PACKAGE;
4040

4141
if (sym instanceof PackageElement) {
@@ -63,10 +63,10 @@ private String uncachedSemanticdbSymbol(Element sym, LocalSymbolsCache locals) {
6363

6464
if (isAnonymousClass(sym) || isLocalVariable(sym)) return locals.put(sym);
6565

66-
String owner = semanticdbSymbol(sym.getEnclosingElement(), locals);
66+
String owner = symbol(sym.getEnclosingElement(), locals);
6767
if (SemanticdbSymbols.isLocal(owner)) return locals.put(sym);
6868

69-
SemanticdbSymbols.Descriptor desc = semanticdbDescriptor(sym);
69+
SemanticdbSymbols.Descriptor desc = descriptor(sym);
7070
if (options.verboseEnabled && desc.kind == SemanticdbSymbols.Descriptor.Kind.None) {
7171
if (sym instanceof QualifiedNameable)
7272
pprint(((QualifiedNameable) sym).getQualifiedName().toString());
@@ -93,7 +93,7 @@ private boolean isAnonymousClass(Element sym) {
9393
return sym instanceof TypeElement && sym.getSimpleName().length() == 0;
9494
}
9595

96-
private SemanticdbSymbols.Descriptor semanticdbDescriptor(Element sym) {
96+
private SemanticdbSymbols.Descriptor descriptor(Element sym) {
9797
if (sym instanceof TypeElement) {
9898
return new SemanticdbSymbols.Descriptor(
9999
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
@@ -1,19 +1,18 @@
11
package com.sourcegraph.semanticdb_javac;
22

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

1211
public static final String PLACEHOLDER_PREFIX = ". . . . ";
1312

1413
private ScipSymbols() {}
1514

16-
public static String fromSemanticdbSymbol(String symbol) {
15+
public static String format(String symbol) {
1716
if (symbol == null || symbol.isEmpty()) return "";
1817
if (SemanticdbSymbols.isLocal(symbol)) {
1918
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
@@ -54,8 +54,8 @@
5454

5555
/**
5656
* Walks a typechecked compilation unit and builds a {@link Document}. Symbols come from {@link
57-
* GlobalSymbolsCache} via {@link ScipSymbols#fromSemanticdbSymbol(String)} and signatures from
58-
* {@link ScipSignatureFormatter}.
57+
* GlobalSymbolsCache} via {@link ScipSymbols#format(String)} and signatures from {@link
58+
* ScipSignatureFormatter}.
5959
*/
6060
public final class ScipVisitor extends TreePathScanner<Void, Void> {
6161

@@ -128,36 +128,36 @@ private Optional<ScipRange> emitSymbolOccurrence(
128128
private void emitOccurrence(
129129
Element sym, Optional<ScipRange> range, int roles, Optional<ScipRange> enclosingRange) {
130130
if (sym == null || !range.isPresent()) return;
131-
String semanticdbSymbol = semanticdbSymbol(sym);
132-
if (semanticdbSymbol.equals(SemanticdbSymbols.NONE)) return;
131+
String symbol = symbol(sym);
132+
if (symbol.equals(SemanticdbSymbols.NONE)) return;
133133

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

143143
private void emitSymbolInformation(Element sym, Tree tree) {
144-
String semanticdbSymbol = semanticdbSymbol(sym);
145-
if (semanticdbSymbol.equals(SemanticdbSymbols.NONE)) return;
144+
String symbol = symbol(sym);
145+
if (symbol.equals(SemanticdbSymbols.NONE)) return;
146146

147147
SymbolInformation.Builder builder =
148148
SymbolInformation.newBuilder()
149-
.setSymbol(ScipSymbols.fromSemanticdbSymbol(semanticdbSymbol))
149+
.setSymbol(ScipSymbols.format(symbol))
150150
.setDisplayName(sym.getSimpleName().toString())
151151
.setKind(scipKind(sym));
152152

153-
if (SemanticdbSymbols.isLocal(semanticdbSymbol)) {
154-
String enclosingSymbol = semanticdbSymbol(sym.getEnclosingElement());
153+
if (SemanticdbSymbols.isLocal(symbol)) {
154+
String enclosingSymbol = symbol(sym.getEnclosingElement());
155155
if (enclosingSymbol != null && !enclosingSymbol.equals(SemanticdbSymbols.NONE)) {
156-
builder.setEnclosingSymbol(ScipSymbols.fromSemanticdbSymbol(enclosingSymbol));
156+
builder.setEnclosingSymbol(ScipSymbols.format(enclosingSymbol));
157157
}
158158
}
159159

160-
String documentation = semanticdbDocumentation(tree);
160+
String documentation = documentation(tree);
161161
if (documentation != null && !documentation.isEmpty()) {
162162
builder.addDocumentation(documentation);
163163
}
@@ -179,12 +179,11 @@ private void emitSymbolInformation(Element sym, Tree tree) {
179179
break;
180180
case METHOD:
181181
for (String overridden :
182-
semanticdbOverrides(
183-
(ExecutableElement) sym, sym.getEnclosingElement(), new HashSet<>())) {
182+
overrides((ExecutableElement) sym, sym.getEnclosingElement(), new HashSet<>())) {
184183
if (isIgnoredOverriddenSymbol(overridden)) continue;
185184
builder.addRelationships(
186185
Relationship.newBuilder()
187-
.setSymbol(ScipSymbols.fromSemanticdbSymbol(overridden))
186+
.setSymbol(ScipSymbols.format(overridden))
188187
.setIsImplementation(true)
189188
.setIsReference(supportsReferenceRel));
190189
}
@@ -211,11 +210,11 @@ private void emitSymbolInformation(Element sym, Tree tree) {
211210

212211
private void addParentRelationships(
213212
SymbolInformation.Builder builder, TypeElement sym, boolean supportsReferenceRel) {
214-
for (String parent : semanticdbParentSymbols(sym)) {
213+
for (String parent : parentSymbols(sym)) {
215214
if (isIgnoredOverriddenSymbol(parent)) continue;
216215
builder.addRelationships(
217216
Relationship.newBuilder()
218-
.setSymbol(ScipSymbols.fromSemanticdbSymbol(parent))
217+
.setSymbol(ScipSymbols.format(parent))
219218
.setIsImplementation(true)
220219
.setIsReference(supportsReferenceRel));
221220
}
@@ -462,8 +461,8 @@ private void resolveNewClassTree(NewClassTree node, TreePath treePath) {
462461
}
463462
}
464463

465-
private String semanticdbSymbol(Element sym) {
466-
return globals.semanticdbSymbol(sym, locals);
464+
private String symbol(Element sym) {
465+
return globals.symbol(sym, locals);
467466
}
468467

469468
private Optional<ScipRange> scipRangeOf(Tree tree, CompilerRange kind, Element sym, String name) {
@@ -568,39 +567,38 @@ private static String sourceText(CompilationUnitTree tree) {
568567
}
569568
}
570569

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

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

593-
private void semanticdbParentSymbol(TypeMirror elementType, Set<TypeElement> result) {
591+
private void parentSymbol(TypeMirror elementType, Set<TypeElement> result) {
594592
if (!(elementType instanceof NoType)) {
595593
Element superElement = types.asElement(elementType);
596594
if (superElement instanceof TypeElement) {
597595
result.add((TypeElement) superElement);
598-
semanticdbParentTypeElements((TypeElement) superElement, result);
596+
parentTypeElements((TypeElement) superElement, result);
599597
}
600598
}
601599
}
602600

603-
private Set<String> semanticdbOverrides(
601+
private Set<String> overrides(
604602
ExecutableElement sym, Element enclosingElement, Set<String> overriddenSymbols) {
605603
if (enclosingElement instanceof TypeElement) {
606604
List<? extends TypeMirror> superTypes = types.directSupertypes(enclosingElement.asType());
@@ -616,15 +614,15 @@ private Set<String> semanticdbOverrides(
616614
ExecutableElement enclosedExecutableElement = (ExecutableElement) enclosedElement;
617615
if (elements.overrides(
618616
sym, enclosedExecutableElement, (TypeElement) sym.getEnclosingElement())) {
619-
String symbol = semanticdbSymbol(enclosedExecutableElement);
617+
String symbol = symbol(enclosedExecutableElement);
620618
overriddenSymbols.add(symbol);
621619
methodFound = true;
622-
semanticdbOverrides(enclosedExecutableElement, superElement, overriddenSymbols);
620+
overrides(enclosedExecutableElement, superElement, overriddenSymbols);
623621
}
624622
}
625623
}
626624
if (!methodFound) {
627-
semanticdbOverrides(sym, superElement, overriddenSymbols);
625+
overrides(sym, superElement, overriddenSymbols);
628626
}
629627
}
630628
}
@@ -651,7 +649,7 @@ private static String sourceRelativePath(
651649
return out.toString();
652650
}
653651

654-
private String semanticdbDocumentation(Tree tree) {
652+
private String documentation(Tree tree) {
655653
try {
656654
TreePath treePath = nodes.get(tree);
657655
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
@@ -73,7 +73,7 @@ class ScipTextDocumentBuilder(
7373
Occurrence
7474
.newBuilder()
7575
.addAllRange(scipRange(element))
76-
.setSymbol(ScipSymbols.fromSemanticdbSymbol(symbol))
76+
.setSymbol(ScipSymbols.format(symbol))
7777
.setSymbolRoles(roles)
7878
if (enclosingSource != null) {
7979
builder.addAllEnclosingRange(scipEnclosingRange(enclosingSource))
@@ -88,7 +88,7 @@ class ScipTextDocumentBuilder(
8888
element: KtSourceElement,
8989
context: CheckerContext,
9090
) {
91-
val scipSymbolStr = ScipSymbols.fromSemanticdbSymbol(symbol)
91+
val scipSymbolStr = ScipSymbols.format(symbol)
9292
val builder =
9393
SymbolInformation
9494
.newBuilder()
@@ -109,7 +109,7 @@ class ScipTextDocumentBuilder(
109109

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

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ class GlobalSymbolsCache {
6565
locals[symbol]?.let {
6666
return it
6767
}
68-
return uncachedSemanticdbSymbol(symbol, locals).also {
68+
return uncachedSymbol(symbol, locals).also {
6969
if (it.isGlobal()) globals[symbol] = it
7070
}
7171
}
7272
private fun getSymbol(symbol: FqName): Symbol {
7373
packages[symbol]?.let {
7474
return it
7575
}
76-
return uncachedSemanticdbSymbol(symbol).also { if (it.isGlobal()) packages[symbol] = it }
76+
return uncachedSymbol(symbol).also { if (it.isGlobal()) packages[symbol] = it }
7777
}
7878

7979
private fun skip(symbol: FirBasedSymbol<*>?): Boolean {
@@ -82,7 +82,7 @@ class GlobalSymbolsCache {
8282
}
8383

8484
@OptIn(SymbolInternals::class)
85-
private fun uncachedSemanticdbSymbol(
85+
private fun uncachedSymbol(
8686
symbol: FirBasedSymbol<*>?,
8787
locals: LocalSymbolsCache
8888
): Symbol {
@@ -94,12 +94,12 @@ class GlobalSymbolsCache {
9494

9595
if (owner.isLocal() || owner == Symbol.NONE) return locals + symbol
9696

97-
val semanticdbDescriptor = semanticdbDescriptor(symbol)
97+
val descriptor = descriptor(symbol)
9898

99-
return Symbol.createGlobal(owner, semanticdbDescriptor)
99+
return Symbol.createGlobal(owner, descriptor)
100100
}
101101

102-
private fun uncachedSemanticdbSymbol(symbol: FqName): Symbol {
102+
private fun uncachedSymbol(symbol: FqName): Symbol {
103103
if (symbol.isRoot) return Symbol.ROOT_PACKAGE
104104

105105
val owner = this.getSymbol(symbol.parent())
@@ -138,7 +138,7 @@ class GlobalSymbolsCache {
138138
}
139139

140140
@OptIn(SymbolInternals::class)
141-
private fun semanticdbDescriptor(symbol: FirBasedSymbol<*>): SemanticdbSymbolDescriptor {
141+
private fun descriptor(symbol: FirBasedSymbol<*>): SemanticdbSymbolDescriptor {
142142
return when {
143143
symbol is FirAnonymousObjectSymbol ->
144144
symbol.source?.let { source ->

tests/unit/src/test/scala/tests/ScipSymbolsSuite.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ class ScipSymbolsSuite extends FunSuite {
1717

1818
test("global symbol gets placeholder prefix") {
1919
assertEquals(
20-
ScipSymbols.fromSemanticdbSymbol("com/example/Foo#bar()."),
20+
ScipSymbols.format("com/example/Foo#bar()."),
2121
". . . . com/example/Foo#bar()."
2222
)
2323
}
2424

2525
test("local symbol gets canonical SCIP form") {
26-
assertEquals(ScipSymbols.fromSemanticdbSymbol("local42"), "local 42")
26+
assertEquals(ScipSymbols.format("local42"), "local 42")
2727
}
2828

2929
test("empty / null symbol stays empty") {
30-
assertEquals(ScipSymbols.fromSemanticdbSymbol(""), "")
31-
assertEquals(ScipSymbols.fromSemanticdbSymbol(null), "")
30+
assertEquals(ScipSymbols.format(""), "")
31+
assertEquals(ScipSymbols.format(null), "")
3232
}
3333

3434
// PackageTable that always returns no package; isolates SymbolRewriter from classpath.

0 commit comments

Comments
 (0)