22
33import com .sourcegraph .scip .LocalSymbolsCache ;
44import com .sourcegraph .scip .ScipDocumentBuilder ;
5+ import com .sourcegraph .scip .ScipRanges ;
6+ import com .sourcegraph .scip .ScipRanges .Range ;
57import com .sourcegraph .scip .ScipSymbols ;
68import com .sun .source .tree .AnnotatedTypeTree ;
79import com .sun .source .tree .ClassTree ;
@@ -182,7 +184,7 @@ private void resolveMethodTree(MethodTree node, TreePath treePath) {
182184 private void resolveVariableTree (VariableTree node , TreePath treePath ) {
183185 Element sym = trees .getElement (treePath );
184186 if (sym == null ) return ;
185- int [] range =
187+ Range range =
186188 emitDefinition (sym , node , sym .getSimpleName (), CompilerRange .FROM_POINT_WITH_TEXT_SEARCH );
187189 if (sym .getKind () == ElementKind .ENUM_CONSTANT ) {
188190 TreePath typeTreePath = nodes .get (node .getInitializer ());
@@ -246,8 +248,8 @@ private void resolveNewClassTree(NewClassTree node, TreePath treePath) {
246248 // =======================================
247249 // Occurrence + SymbolInformation emission
248250 // =======================================
249- private int [] emitDefinition (Element sym , Tree tree , Name name , CompilerRange kind ) {
250- int [] range = computeRange (tree , kind , sym , name == null ? null : name .toString ());
251+ private Range emitDefinition (Element sym , Tree tree , Name name , CompilerRange kind ) {
252+ Range range = computeRange (tree , kind , sym , name == null ? null : name .toString ());
251253 if (range == null ) return null ;
252254 emitOccurrence (sym , range , SymbolRole .Definition_VALUE , computeEnclosingRange (tree ));
253255 declTrees .put (sym , tree );
@@ -256,18 +258,18 @@ private int[] emitDefinition(Element sym, Tree tree, Name name, CompilerRange ki
256258 }
257259
258260 private void emitReference (Element sym , Tree tree , Name name , CompilerRange kind ) {
259- int [] range = computeRange (tree , kind , sym , name == null ? null : name .toString ());
261+ Range range = computeRange (tree , kind , sym , name == null ? null : name .toString ());
260262 if (range == null ) return ;
261263 emitOccurrence (sym , range , 0 /* reference */ , null );
262264 }
263265
264- private void emitOccurrence (Element sym , int [] range , int role , int [] enclosingRange ) {
266+ private void emitOccurrence (Element sym , Range range , int role , Range enclosingRange ) {
265267 String symbol = scipSymbol (sym );
266268 if (symbol .isEmpty ()) return ;
267269 Occurrence .Builder b = Occurrence .newBuilder ().setSymbol (symbol ).setSymbolRoles (role );
268- for ( int v : range ) b . addRange ( v );
270+ ScipRanges . setRange ( b , range );
269271 if (enclosingRange != null ) {
270- for ( int v : enclosingRange ) b . addEnclosingRange ( v );
272+ ScipRanges . setEnclosingRange ( b , enclosingRange );
271273 }
272274 documentBuilder .addOccurrence (b .build ());
273275 }
@@ -360,7 +362,7 @@ private SymbolInformation.Kind scipKind(Element sym) {
360362 // =======================================
361363 // Source position / range computation
362364 // =======================================
363- private int [] computeRange (Tree tree , CompilerRange kind , Element sym , String name ) {
365+ private Range computeRange (Tree tree , CompilerRange kind , Element sym , String name ) {
364366 if (sym == null ) return null ;
365367 SourcePositions sourcePositions = trees .getSourcePositions ();
366368 int start = (int ) sourcePositions .getStartPosition (compUnitTree , tree );
@@ -394,7 +396,7 @@ private int[] computeRange(Tree tree, CompilerRange kind, Element sym, String na
394396 return lineMapRange (start , end );
395397 }
396398
397- private int [] computeEnclosingRange (Tree tree ) {
399+ private Range computeEnclosingRange (Tree tree ) {
398400 if (tree == null ) return null ;
399401 TreePath path = nodes .get (tree );
400402 if (path == null ) return null ;
@@ -413,7 +415,7 @@ private int[] computeEnclosingRange(Tree tree) {
413415 return lineMapRange (start , end );
414416 }
415417
416- private int [] lineMapRange (int start , int end ) {
418+ private Range lineMapRange (int start , int end ) {
417419 if (start == Diagnostic .NOPOS || end == Diagnostic .NOPOS || end <= start ) return null ;
418420 LineMap lineMap = compUnitTree .getLineMap ();
419421 int startLine = (int ) lineMap .getLineNumber (start ) - 1 ;
@@ -431,8 +433,8 @@ private int[] lineMapRange(int start, int end) {
431433 endChar -= count * 7 ;
432434 }
433435
434- if (startLine == endLine ) return new int [] { startLine , startChar , endChar } ;
435- return new int [] { startLine , startChar , endLine , endChar } ;
436+ if (startLine == endLine ) return ScipRanges . singleLineRange ( startLine , startChar , endChar ) ;
437+ return ScipRanges . range ( startLine , startChar , endLine , endChar ) ;
436438 }
437439
438440 // =======================================
0 commit comments