Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions rewrites/src/main/scala/fix/scala213/ExplicitNonNullaryApply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])

private def unsafeFix()(implicit doc: SemanticDocument) = {
lazy val power = new impl.Power(global.value)
val handled = mutable.Set.empty[Name]
val handled = mutable.Set.empty[Term.Name]

def isJavaDefined(name: Term.Name): Boolean = name.value match {
case "toString" => true // fast-track known, common cases
case "getClass" => true
case "hashCode" => true
case "asInstanceOf" => true
case "isInstanceOf" => true
case _ => power.isJavaDefined(name)
}

def fix(tree: Tree, meth: Term, noTypeArgs: Boolean, noArgs: Boolean) = {
for {
Expand All @@ -61,7 +70,7 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])
cond(decl.signature) { case MethodSignature(_, Nil :: _, _) => true }
}
}
if !power.isJavaDefined(name) // full check, using the presentation compiler :O
if !isJavaDefined(name) // full check, using the presentation compiler :O
} yield {
val optAddDot = name.parent.collect {
case PostfixSelect(qual, `name`) =>
Expand All @@ -84,7 +93,7 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])

// No PostfixSelect in Scalameta, so build one
private object PostfixSelect {
def unapply(t: Tree)(implicit doc: SemanticDocument): Option[(Term, Name)] = t match {
def unapply(t: Tree)(implicit doc: SemanticDocument): Option[(Term, Term.Name)] = t match {
case Term.Select(qual, name) =>
val tokenList = doc.tokenList
val inBetweenSlice = tokenList.slice(tokenList.next(qual.tokens.last), name.tokens.head)
Expand All @@ -94,10 +103,9 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])
}
}

private def termName(term: Term): Option[Name] = condOpt(term) {
private def termName(term: Term): Option[Term.Name] = condOpt(term) {
case name: Term.Name => name
case Term.Select(_, name: Term.Name) => name
case Type.Select(_, name: Type.Name) => name
}

override def withConfiguration(config: Configuration) = {
Expand Down