@@ -68,7 +68,7 @@ public final class ScipVisitor extends TreePathScanner<Void, Void> {
6868 private final CompilationUnitTree compUnitTree ;
6969 private final Elements elements ;
7070 private final SemanticdbJavacOptions options ;
71- private final ArrayList < Occurrence > occurrences ;
71+ private final ScipOccurrences occurrences ;
7272 private final LinkedHashMap <String , SymbolInformation > symbols ;
7373 private final String source ;
7474 private final String relativePath ;
@@ -88,7 +88,7 @@ public ScipVisitor(
8888 this .elements = elements ;
8989 this .trees = trees ;
9090 this .compUnitTree = compUnitTree ;
91- this .occurrences = new ArrayList <> ();
91+ this .occurrences = new ScipOccurrences ();
9292 this .symbols = new LinkedHashMap <>();
9393 this .source = sourceText (compUnitTree );
9494 this .relativePath = sourceRelativePath (compUnitTree , options );
@@ -105,7 +105,7 @@ public Index buildShard(CompilationUnitTree tree) {
105105 if (options .includeText ) {
106106 document .setText (source );
107107 }
108- document .addAllOccurrences (ScipOccurrences . deduplicate ( occurrences ));
108+ document .addAllOccurrences (occurrences . values ( ));
109109 document .addAllSymbols (symbols .values ());
110110
111111 return Index .newBuilder ().addDocuments (document ).build ();
@@ -119,20 +119,20 @@ public Index buildShard(CompilationUnitTree tree) {
119119 // ==========================
120120
121121 private Optional <ScipRange > emitSymbolOccurrence (
122- Element sym , Tree tree , Name name , ScipRole role , CompilerRange kind ) {
122+ Element sym , Tree tree , Name name , int roles , CompilerRange kind ) {
123123 if (sym == null || name == null ) return Optional .empty ();
124124 Optional <ScipRange > range = scipRangeOf (tree , kind , sym , name .toString ());
125- if (role == ScipRole . DEFINITION ) {
126- emitOccurrence (sym , range , role , computeEnclosingRange (tree ));
125+ if (roles == SymbolRole . Definition_VALUE ) {
126+ emitOccurrence (sym , range , roles , computeEnclosingRange (tree ));
127127 emitSymbolInformation (sym , tree );
128128 return range ;
129129 }
130- emitOccurrence (sym , range , role , Optional .empty ());
130+ emitOccurrence (sym , range , roles , Optional .empty ());
131131 return range ;
132132 }
133133
134134 private void emitOccurrence (
135- Element sym , Optional <ScipRange > range , ScipRole role , Optional <ScipRange > enclosingRange ) {
135+ Element sym , Optional <ScipRange > range , int roles , Optional <ScipRange > enclosingRange ) {
136136 if (sym == null || !range .isPresent ()) return ;
137137 String semanticdbSymbol = semanticdbSymbol (sym );
138138 if (semanticdbSymbol .equals (SemanticdbSymbols .NONE )) return ;
@@ -141,7 +141,7 @@ private void emitOccurrence(
141141 Occurrence .newBuilder ()
142142 .addAllRange (range .get ().asScipRange ())
143143 .setSymbol (ScipSymbols .fromSemanticdbSymbol (semanticdbSymbol ))
144- .setSymbolRoles (scipRole ( role ) );
144+ .setSymbolRoles (roles );
145145 enclosingRange .ifPresent (r -> occ .addAllEnclosingRange (r .asScipRange ()));
146146 occurrences .add (occ .build ());
147147 }
@@ -244,16 +244,9 @@ private static boolean supportsReferenceRelationship(Element sym) {
244244 }
245245
246246 // =================================================
247- // Role / kind translation for SCIP emission.
247+ // Kind translation for SCIP emission.
248248 // =================================================
249249
250- private static int scipRole (ScipRole role ) {
251- if (role == ScipRole .DEFINITION || role == ScipRole .SYNTHETIC_DEFINITION ) {
252- return SymbolRole .Definition_VALUE ;
253- }
254- return 0 ;
255- }
256-
257250 private static SymbolInformation .Kind scipKind (Element sym ) {
258251 Set <Modifier > modifiers = sym .getModifiers ();
259252 boolean isStatic = modifiers .contains (Modifier .STATIC );
@@ -369,7 +362,7 @@ private void resolveClassTree(ClassTree node, TreePath treePath) {
369362 sym ,
370363 node ,
371364 sym .getSimpleName (),
372- ScipRole . DEFINITION ,
365+ SymbolRole . Definition_VALUE ,
373366 CompilerRange .FROM_POINT_WITH_TEXT_SEARCH );
374367 }
375368 }
@@ -381,7 +374,7 @@ private void resolveTypeParameterTree(TypeParameterTree node, TreePath treePath)
381374 sym ,
382375 node ,
383376 sym .getSimpleName (),
384- ScipRole . DEFINITION ,
377+ SymbolRole . Definition_VALUE ,
385378 CompilerRange .FROM_POINT_TO_SYMBOL_NAME );
386379 }
387380 }
@@ -396,7 +389,11 @@ private void resolveMethodTree(MethodTree node, TreePath treePath) {
396389 else name = sym .getSimpleName ();
397390
398391 emitSymbolOccurrence (
399- sym , node , name , ScipRole .DEFINITION , CompilerRange .FROM_POINT_WITH_TEXT_SEARCH );
392+ sym ,
393+ node ,
394+ name ,
395+ SymbolRole .Definition_VALUE ,
396+ CompilerRange .FROM_POINT_WITH_TEXT_SEARCH );
400397 }
401398 }
402399 }
@@ -409,12 +406,12 @@ private void resolveVariableTree(VariableTree node, TreePath treePath) {
409406 sym ,
410407 node ,
411408 sym .getSimpleName (),
412- ScipRole . DEFINITION ,
409+ SymbolRole . Definition_VALUE ,
413410 CompilerRange .FROM_POINT_WITH_TEXT_SEARCH );
414411 if (sym .getKind () == ElementKind .ENUM_CONSTANT ) {
415412 TreePath typeTreePath = nodes .get (node .getInitializer ());
416413 Element typeSym = trees .getElement (typeTreePath );
417- if (typeSym != null ) emitOccurrence (typeSym , range , ScipRole . REFERENCE , Optional .empty ());
414+ if (typeSym != null ) emitOccurrence (typeSym , range , 0 , Optional .empty ());
418415 }
419416 }
420417 }
@@ -431,11 +428,7 @@ private void resolveIdentifierTree(IdentifierTree node, TreePath treePath) {
431428 Element parentSym = trees .getElement (parentPath );
432429 if (parentSym == null || parentSym .getKind () != null ) {
433430 emitSymbolOccurrence (
434- sym ,
435- node ,
436- sym .getSimpleName (),
437- ScipRole .REFERENCE ,
438- CompilerRange .FROM_START_TO_END );
431+ sym , node , sym .getSimpleName (), 0 , CompilerRange .FROM_START_TO_END );
439432 }
440433 }
441434 }
@@ -446,23 +439,15 @@ private void resolveMemberReferenceTree(MemberReferenceTree node, TreePath treeP
446439 Element sym = trees .getElement (treePath );
447440 if (sym != null ) {
448441 emitSymbolOccurrence (
449- sym ,
450- node ,
451- sym .getSimpleName (),
452- ScipRole .REFERENCE ,
453- CompilerRange .FROM_END_TO_SYMBOL_NAME );
442+ sym , node , sym .getSimpleName (), 0 , CompilerRange .FROM_END_TO_SYMBOL_NAME );
454443 }
455444 }
456445
457446 private void resolveMemberSelectTree (MemberSelectTree node , TreePath treePath ) {
458447 Element sym = trees .getElement (treePath );
459448 if (sym != null ) {
460449 emitSymbolOccurrence (
461- sym ,
462- node ,
463- sym .getSimpleName (),
464- ScipRole .REFERENCE ,
465- CompilerRange .FROM_END_TO_SYMBOL_NAME );
450+ sym , node , sym .getSimpleName (), 0 , CompilerRange .FROM_END_TO_SYMBOL_NAME );
466451 }
467452 }
468453
@@ -477,18 +462,13 @@ private void resolveNewClassTree(NewClassTree node, TreePath treePath) {
477462 Element identifierSym = trees .getElement (identifierTreePath );
478463 if (identifierSym != null ) {
479464 emitSymbolOccurrence (
480- sym ,
481- node ,
482- identifierSym .getSimpleName (),
483- ScipRole .REFERENCE ,
484- CompilerRange .FROM_TEXT_SEARCH );
465+ sym , node , identifierSym .getSimpleName (), 0 , CompilerRange .FROM_TEXT_SEARCH );
485466 } else if (node .getIdentifier ().getKind () == Tree .Kind .ANNOTATED_TYPE ) {
486467 AnnotatedTypeTree annotatedTypeTree = (AnnotatedTypeTree ) node .getIdentifier ();
487468 if (annotatedTypeTree .getUnderlyingType () != null
488469 && annotatedTypeTree .getUnderlyingType ().getKind () == Tree .Kind .IDENTIFIER ) {
489470 IdentifierTree ident = (IdentifierTree ) annotatedTypeTree .getUnderlyingType ();
490- emitSymbolOccurrence (
491- sym , ident , ident .getName (), ScipRole .REFERENCE , CompilerRange .FROM_TEXT_SEARCH );
471+ emitSymbolOccurrence (sym , ident , ident .getName (), 0 , CompilerRange .FROM_TEXT_SEARCH );
492472 }
493473 }
494474 }
0 commit comments