Skip to content

Commit

Permalink
Clean up mark occurrences a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
misto committed Jul 29, 2010
1 parent d61069e commit cab036f
Showing 1 changed file with 4 additions and 13 deletions.
@@ -1,18 +1,12 @@
package scala.tools.eclipse.markoccurrences

import scala.tools.refactoring.transformation.TreeFactory
import scala.tools.refactoring.analysis.TreeAnalysis
import scala.tools.refactoring.common.Selections
import org.eclipse.jface.text.Region
import org.eclipse.jface.text.ITextSelection
import scala.tools.eclipse.javaelements.ScalaSourceFile
import scala.tools.eclipse.refactoring.ScalaIdeRefactoring
import scala.tools.nsc._
import scala.tools.nsc.interactive.Global
import scala.tools.refactoring.Refactoring
import scala.tools.refactoring.analysis.{ NameValidation, GlobalIndexes, CompilationUnitIndexes }
import scala.tools.refactoring.common.ConsoleTracing
import scala.tools.refactoring.implementations.Rename
import scala.tools.refactoring.analysis.GlobalIndexes

case class Occurrences(name: String, locations: List[Region])

Expand All @@ -35,15 +29,12 @@ class ScalaOccurrencesFinder(file: ScalaSourceFile, offset: Int, length: Int) {
if (position == global.NoPosition)
None
else {
val index = GlobalIndex(global.unitOf(position.source).body)
val symbol = selection.selectedSymbolTree.get.symbol
val symbol = selectedLocal.symbol
if (symbol.name.isOperatorName)
None
else {
val positions = index.occurences(symbol) map {
case t: global.DefTree => (t.pos.point, t.name.length)
case t: global.RefTree => (t.pos.start, t.pos.end - t.pos.start)
}
val index = GlobalIndex(global.unitOf(position.source).body)
val positions = index occurences symbol map (_.namePosition) map (p => (p.start, p.end - p.start))
val symbolName = symbol.nameString
val locations = positions collect { case (offset, length) if length == symbolName.length => new Region(offset, length) }
Some(Occurrences(symbolName, locations.toList))
Expand Down

0 comments on commit cab036f

Please sign in to comment.