Skip to content

Commit

Permalink
Remove unnecessary final, rename vals and narrow access (#1423)
Browse files Browse the repository at this point in the history
* Remove unnecessary final, rename vals and narrow access
  • Loading branch information
regadas authored and jto committed Oct 3, 2018
1 parent fac93db commit 3283fe6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Expand Up @@ -21,15 +21,14 @@ import scala.reflect.macros._

private[coders] object CoderMacros {

var verbose = true
val reported: scala.collection.mutable.Set[(String, String)] =
private[this] var verbose = true
private[this] val reported: scala.collection.mutable.Set[(String, String)] =
scala.collection.mutable.Set.empty

private[this] val SETTING_SHOW_WARN = "show-coder-fallback"
private[this] val DEFAULT_SHOW_WARN = true
private[this] val KVS = "show-coder-fallback=(true|false)".r
private[this] val ShowWarnDefault = true
private[this] val ShowWarnSettingRegex = "show-coder-fallback=(true|false)".r

val blacklistedTypes = List("org.apache.beam.sdk.values.Row")
private[this] val BlacklistedTypes = List("org.apache.beam.sdk.values.Row")

/**
* Makes it possible to configure fallback warnings by passing
Expand All @@ -38,10 +37,10 @@ private[coders] object CoderMacros {
private[this] def showWarn(c: whitebox.Context) =
c.settings
.collectFirst {
case KVS(value) =>
case ShowWarnSettingRegex(value) =>
value.toBoolean
}
.getOrElse(DEFAULT_SHOW_WARN)
.getOrElse(ShowWarnDefault)

// scalastyle:off method.length
def issueFallbackWarning[T: c.WeakTypeTag](c: whitebox.Context)(
Expand All @@ -61,7 +60,7 @@ private[coders] object CoderMacros {
.getOrElse("")
val fullType = typeName + params

val toReport = (c.enclosingPosition.toString -> wtt.toString)
val toReport = c.enclosingPosition.toString -> wtt.toString
val alreadyReported = reported.contains(toReport)
if (!alreadyReported) reported += toReport

Expand Down Expand Up @@ -101,7 +100,7 @@ private[coders] object CoderMacros {
val fallback = q"""_root_.com.spotify.scio.coders.Coder.kryo[$wtt]"""

(verbose, alreadyReported) match {
case _ if blacklistedTypes.contains(wtt.toString) =>
case _ if BlacklistedTypes.contains(wtt.toString) =>
val msg =
s"Can't use a Kryo coder for ${wtt}. You need to explicitly set the Coder for this type"
c.abort(c.enclosingPosition, msg)
Expand Down
Expand Up @@ -22,7 +22,7 @@ import org.apache.beam.sdk.coders.CoderRegistry
import org.apache.beam.sdk.options.PipelineOptions
import org.apache.beam.sdk.options.PipelineOptionsFactory

final object CoderMaterializer {
object CoderMaterializer {
import com.spotify.scio.ScioContext

final def beam[T](sc: ScioContext, c: Coder[T]): BCoder[T] =
Expand All @@ -33,8 +33,8 @@ final object CoderMaterializer {
o: PipelineOptions = PipelineOptionsFactory.create()): BCoder[T] =
beam(r, o, coder)

final def beam[T](r: CoderRegistry, o: PipelineOptions, c: Coder[T]): BCoder[T] = {
c match {
final def beam[T](r: CoderRegistry, o: PipelineOptions, coder: Coder[T]): BCoder[T] = {
coder match {
case Beam(c) => c
case Fallback(ct) =>
WrappedBCoder.create(
Expand Down

0 comments on commit 3283fe6

Please sign in to comment.