From cab036f9f3afdbc131d3d43c35ea9684aeb23f62 Mon Sep 17 00:00:00 2001 From: Mirko Stocker Date: Thu, 29 Jul 2010 09:56:38 +0200 Subject: [PATCH] Clean up mark occurrences a bit. --- .../ScalaOccurrencesFinder.scala | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/org.scala-ide.sdt.core/src/scala/tools/eclipse/markoccurrences/ScalaOccurrencesFinder.scala b/org.scala-ide.sdt.core/src/scala/tools/eclipse/markoccurrences/ScalaOccurrencesFinder.scala index c881fe34f9..8d643c8c01 100644 --- a/org.scala-ide.sdt.core/src/scala/tools/eclipse/markoccurrences/ScalaOccurrencesFinder.scala +++ b/org.scala-ide.sdt.core/src/scala/tools/eclipse/markoccurrences/ScalaOccurrencesFinder.scala @@ -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]) @@ -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))