Skip to content

Commit 294dd35

Browse files
committed
Fast-track known, common cases of Java-defined methods
1 parent 31792e1 commit 294dd35

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

rewrites/src/main/scala/fix/scala213/ExplicitNonNullaryApply.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])
4242
lazy val power = new impl.Power(global.value)
4343
val handled = mutable.Set.empty[Term.Name]
4444

45+
def isJavaDefined(name: Term.Name): Boolean = name.value match {
46+
case "toString" => true // fast-track known, common cases
47+
case "getClass" => true
48+
case "hashCode" => true
49+
case "asInstanceOf" => true
50+
case "isInstanceOf" => true
51+
case _ => power.isJavaDefined(name)
52+
}
53+
4554
def fix(tree: Tree, meth: Term, noTypeArgs: Boolean, noArgs: Boolean) = {
4655
for {
4756
name <- termName(meth)
@@ -61,7 +70,7 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])
6170
cond(decl.signature) { case MethodSignature(_, Nil :: _, _) => true }
6271
}
6372
}
64-
if !power.isJavaDefined(name) // full check, using the presentation compiler :O
73+
if !isJavaDefined(name) // full check, using the presentation compiler :O
6574
} yield {
6675
val optAddDot = name.parent.collect {
6776
case PostfixSelect(qual, `name`) =>

0 commit comments

Comments
 (0)