44import com .sun .source .util .JavacTask ;
55import com .sun .source .util .TaskEvent ;
66import com .sun .source .util .TreePathScanner ;
7- import com .sun .source .util .Trees ;
87import com .sun .tools .javac .code .Symbol ;
98import com .sun .tools .javac .tree .EndPosTable ;
109import com .sun .tools .javac .tree .JCTree ;
@@ -75,11 +74,13 @@ private void emitSymbolOccurrence(
7574 }
7675
7776 private void emitSymbolInformation (Symbol sym ) {
78- Semanticdb .SymbolInformation info =
79- Semanticdb .SymbolInformation .newBuilder ()
80- .setSymbol (semanticdbSymbol (sym ))
81- .setDocumentation (semanticdbDocumentation (sym ))
82- .build ();
77+ Semanticdb .SymbolInformation .Builder builder =
78+ Semanticdb .SymbolInformation .newBuilder ().setSymbol (semanticdbSymbol (sym ));
79+ Semanticdb .Documentation documentation = semanticdbDocumentation (sym );
80+ if (documentation != null ) builder .setDocumentation (documentation );
81+
82+ Semanticdb .SymbolInformation info = builder .build ();
83+
8384 if (SemanticdbSymbols .isGlobal (info .getSymbol ())) {
8485 symbolInfos .add (info );
8586 }
@@ -242,15 +243,18 @@ private String semanticdbUri() {
242243 return out .toString ();
243244 }
244245
245- private String semanticdbDocumentation (Symbol sym ) {
246+ private Semanticdb . Documentation semanticdbDocumentation (Symbol sym ) {
246247 try {
247248 Elements elements = task .getElements ();
248- if (elements == null ) return "" ;
249+ if (elements == null ) return null ;
249250
250251 String doc = elements .getDocComment (sym );
251- if (doc == null ) return "" ;
252+ if (doc == null ) return null ;
252253
253- return doc ;
254+ return Semanticdb .Documentation .newBuilder ()
255+ .setFormat (Semanticdb .Documentation .Format .JAVADOC )
256+ .setMessage (doc )
257+ .build ();
254258 } catch (NullPointerException e ) {
255259 // Can happen in `getDocComment()`
256260 // Caused by: java.lang.NullPointerException
@@ -259,7 +263,7 @@ private String semanticdbDocumentation(Symbol sym) {
259263 // at com.sun.tools.javac.model.JavacElements.getDocComment(JavacElements.java:321)
260264 // at
261265 // com.sourcegraph.semanticdb_javac.SemanticdbVisitor.semanticdbDocumentation(SemanticdbVisitor.java:233)
262- return "" ;
266+ return null ;
263267 }
264268 }
265269}
0 commit comments