Skip to content

Commit 9c9a706

Browse files
committed
add sentinel unresolved type reference
1 parent 66f9691 commit 9c9a706

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
import java.util.ArrayList;
1212
import java.util.List;
1313

14-
import static com.sourcegraph.semanticdb_javac.Debugging.pprint;
15-
1614
public final class SemanticdbSignatures {
1715
private final GlobalSymbolsCache cache;
1816
private final LocalSymbolsCache locals;
1917

18+
private static final Semanticdb.Type UNRESOLVED_TYPE_REF =
19+
Semanticdb.Type.newBuilder()
20+
.setTypeRef(TypeRef.newBuilder().setSymbol("unresolved_type#"))
21+
.build();
22+
2023
public SemanticdbSignatures(GlobalSymbolsCache cache, LocalSymbolsCache locals) {
2124
this.cache = cache;
2225
this.locals = locals;
@@ -43,17 +46,14 @@ private Signature generateClassSignature(Symbol.ClassSymbol sym) {
4346
if (sym.getSuperclass() != Type.noType) {
4447
Semanticdb.Type superType = generateType(sym.getSuperclass());
4548
if (superType == null) {
46-
pprint("CLASS GAVE NULL " + sym.getSuperclass() + " " + sym);
47-
} else {
48-
builder.addParents(superType);
49+
superType = UNRESOLVED_TYPE_REF;
4950
}
51+
builder.addParents(superType);
5052
}
5153
for (Type iType : sym.getInterfaces()) {
5254
Semanticdb.Type type = generateType(iType);
53-
// this can happen if an interface type isnt properly resolved. Shows as _root_ in snapshots
5455
if (type == null) {
55-
pprint("INTERFACE GAVE NULL " + iType + " " + sym);
56-
continue;
56+
type = UNRESOLVED_TYPE_REF;
5757
}
5858
builder.addParents(type);
5959
}
@@ -85,8 +85,7 @@ private Signature generateMethodSignature(Symbol.MethodSymbol sym) {
8585
private Signature generateFieldSignature(Symbol.VarSymbol sym) {
8686
Semanticdb.Type generateType = generateType(sym.type);
8787
if (generateType == null) {
88-
pprint("FIELD TYPE GAVE NULL " + sym.type + " " + cache.semanticdbSymbol(sym, locals));
89-
return null;
88+
generateType = UNRESOLVED_TYPE_REF;
9089
}
9190
return Signature.newBuilder()
9291
.setValueSignature(ValueSignature.newBuilder().setTpe(generateType))
@@ -100,7 +99,7 @@ private Signature generateTypeSignature(Symbol.TypeVariableSymbol sym) {
10099

101100
Semanticdb.Type upperBound = generateType(sym.type.getUpperBound());
102101
if (upperBound != null) builder.setUpperBound(upperBound);
103-
if (upperBound == null) pprint("UPPER BOUND GAVE NULL " + sym + " " + sym.type.getUpperBound());
102+
else builder.setUpperBound(UNRESOLVED_TYPE_REF);
104103

105104
return Signature.newBuilder().setTypeSignature(builder).build();
106105
}
@@ -138,8 +137,7 @@ public Semanticdb.Type visitDeclared(DeclaredType t, Void unused) {
138137
for (TypeMirror type : t.getTypeArguments()) {
139138
Semanticdb.Type visited = super.visit(type);
140139
if (visited == null) {
141-
pprint("NULL TYPE PARAM " + type + " " + type.getClass());
142-
continue;
140+
visited = UNRESOLVED_TYPE_REF;
143141
}
144142
typeParams.add(visited);
145143

@@ -191,8 +189,7 @@ public Semanticdb.Type visitDeclared(DeclaredType t, Void unused) {
191189
public Semanticdb.Type visitArray(ArrayType t, Void unused) {
192190
Semanticdb.Type arrayComponentType = super.visit(t.getComponentType());
193191
if (arrayComponentType == null) {
194-
pprint("ARRAY GAVE NULL " + t.getComponentType() + " " + t);
195-
return null;
192+
arrayComponentType = UNRESOLVED_TYPE_REF;
196193
}
197194
return Semanticdb.Type.newBuilder()
198195
.setTypeRef(

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.util.Iterator;
2222
import java.util.Optional;
2323

24-
import static com.sourcegraph.semanticdb_javac.Debugging.pprint;
25-
2624
/** Walks the AST of a typechecked compilation unit and generates a SemanticDB TextDocument. */
2725
public class SemanticdbVisitor extends TreePathScanner<Void, Void> {
2826

@@ -56,7 +54,6 @@ public SemanticdbVisitor(
5654
}
5755

5856
public Semanticdb.TextDocument buildTextDocument(CompilationUnitTree tree) {
59-
pprint(semanticdbUri());
6057
this.scan(tree, null); // Trigger recursive AST traversal to collect SemanticDB information.
6158

6259
return Semanticdb.TextDocument.newBuilder()

0 commit comments

Comments
 (0)