Skip to content

Commit

Permalink
Remove use of deprecated PlatformTokenizerCache
Browse files Browse the repository at this point in the history
It was deprecated in scalameta 4.3.0, used since 2.3.0-RC2.
  • Loading branch information
kitbellew committed Jul 24, 2023
1 parent 29e6900 commit bf26e01
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.scalafmt.{Formatted, Scalafmt, Versions}
import org.scalafmt.config.{ProjectFiles, ScalafmtConfig}
import org.scalafmt.CompatCollections.ParConverters._

import scala.meta.internal.tokenizers.PlatformTokenizerCache
import scala.meta.parsers.ParseException
import scala.meta.tokenizers.TokenizeException

Expand Down Expand Up @@ -36,7 +35,6 @@ object ScalafmtCoreRunner extends ScalafmtRunner {
val code = handleFile(inputMethod, options, scalafmtConf)
exitCode.getAndUpdate(ExitCode.merge(code, _))
if (options.check && !code.isOk) Breaks.break
PlatformTokenizerCache.megaCache.clear()
termDisplay.taskProgress(termDisplayMessage)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.scalafmt.interfaces.Scalafmt
import org.scalafmt.interfaces.ScalafmtSession
import org.scalafmt.sysops.FileOps

import scala.meta.internal.tokenizers.PlatformTokenizerCache
import util.control.Breaks._

object ScalafmtDynamicRunner extends ScalafmtRunner {
Expand Down Expand Up @@ -53,7 +52,6 @@ object ScalafmtDynamicRunner extends ScalafmtRunner {
reporter.error(e.file, e)
if (options.check) break
}
PlatformTokenizerCache.megaCache.clear()
termDisplay.taskProgress(termDisplayMessage)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ case class ScalafmtReflect(
case _ =>
formatMethod.invoke(null, code, config.target, emptyRange)
}
clearTokenizerCache()
if (version < ScalafmtVersion(2, 3, 0))
moduleInstance("scala.meta.internal.tokenizers.PlatformTokenizerCache$")
.invoke("megaCache")
.invoke("clear")
formattedGet.invoke(formatted).asInstanceOf[String]
}.recoverWith {
case ReflectionException(e)
Expand Down Expand Up @@ -168,13 +171,6 @@ case class ScalafmtReflect(
}
}

private def clearTokenizerCache(): Unit = {
val cache = moduleInstance(
"scala.meta.internal.tokenizers.PlatformTokenizerCache$"
)
cache.invoke("megaCache").invoke("clear")
}

private def moduleInstance(fqn: String): Object = {
val module = loadClass(fqn).getField("MODULE$")
module.setAccessible(true)
Expand Down

0 comments on commit bf26e01

Please sign in to comment.