Skip to content

Commit

Permalink
s/PcExplicitResultTypes/PresentationCompilerTypeInferrer/
Browse files Browse the repository at this point in the history
  • Loading branch information
bjaglin committed Sep 27, 2024
1 parent 91f876a commit b969ba3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import scalafix.patch.Patch
import scalafix.patch.Patch.empty
import scalafix.v1.*

final class PcExplicitResultTypes private (
final class PresentationCompilerTypeInferrer private (
pc: LazyValue[Option[PresentationCompiler]]
) {

Expand Down Expand Up @@ -84,7 +84,7 @@ final class PcExplicitResultTypes private (
* Prepare the static presentation compiler already in the classpath or download
* and classload one dynamically.
*/
object PcExplicitResultTypes {
object PresentationCompilerTypeInferrer {
private def configure(
config: Configuration,
pc: PresentationCompiler
Expand All @@ -106,7 +106,7 @@ object PcExplicitResultTypes {
)
}

def dynamic(config: Configuration): PcExplicitResultTypes = {
def dynamic(config: Configuration): PresentationCompilerTypeInferrer = {
val newPc: LazyValue[Option[PresentationCompiler]] =
LazyValue.from { () =>
Try(
Expand All @@ -116,18 +116,18 @@ object PcExplicitResultTypes {
)
)
}
new PcExplicitResultTypes(newPc)
new PresentationCompilerTypeInferrer(newPc)
}

def static(
config: Configuration,
pc: PresentationCompiler
): PcExplicitResultTypes = {
): PresentationCompilerTypeInferrer = {
val newPc: LazyValue[Option[PresentationCompiler]] =
LazyValue.from { () =>
Try(configure(config, pc))
}
new PcExplicitResultTypes(newPc)
new PresentationCompilerTypeInferrer(newPc)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import scala.meta.*

import dotty.tools.pc.ScalaPresentationCompiler
import metaconfig.Configured
import scalafix.internal.pc.PcExplicitResultTypes
import scalafix.internal.pc.PresentationCompilerTypeInferrer
import scalafix.patch.Patch
import scalafix.v1.*

final class ExplicitResultTypes(
val config: ExplicitResultTypesConfig,
fallback: Option[PcExplicitResultTypes]
pcTypeInferrer: Option[PresentationCompilerTypeInferrer]
) extends ExplicitResultTypesBase[Scala3Printer] {

def this() = this(ExplicitResultTypesConfig.default, None)
Expand All @@ -20,7 +20,7 @@ final class ExplicitResultTypes(
}

private def shutdownCompiler(): Unit = {
fallback.foreach(_.shutdownCompiler())
pcTypeInferrer.foreach(_.shutdownCompiler())
}

override def withConfiguration(config: Configuration): Configured[Rule] = {
Expand Down Expand Up @@ -52,10 +52,10 @@ final class ExplicitResultTypes(
stripPatchVersion(config.scalaVersion) ==
stripPatchVersion(compilerScalaVersion)
)
PcExplicitResultTypes
PresentationCompilerTypeInferrer
.static(config, new ScalaPresentationCompiler())
else
PcExplicitResultTypes.dynamic(config)
PresentationCompilerTypeInferrer.dynamic(config)
}
)
)
Expand All @@ -64,7 +64,7 @@ final class ExplicitResultTypes(

override def fix(implicit ctx: SemanticDocument): Patch =
try {
implicit val printer = new Scala3Printer(fallback)
implicit val printer = new Scala3Printer(pcTypeInferrer)
unsafeFix()
} catch {
case _: Throwable if !config.fatalWarnings =>
Expand All @@ -74,7 +74,7 @@ final class ExplicitResultTypes(
}

class Scala3Printer(
fallback: Option[PcExplicitResultTypes]
pcTypeInferrer: Option[PresentationCompilerTypeInferrer]
) extends Printer {

def defnType(
Expand All @@ -84,6 +84,6 @@ class Scala3Printer(
)(implicit
ctx: SemanticDocument
): Option[Patch] = {
fallback.flatMap(_.defnType(replace))
pcTypeInferrer.flatMap(_.defnType(replace))
}
}

0 comments on commit b969ba3

Please sign in to comment.