Skip to content

Commit b3c5c8c

Browse files
authored
Merge pull request #49 from dwijnand/even-faster
2 parents ec6df52 + 294dd35 commit b3c5c8c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])
4040

4141
private def unsafeFix()(implicit doc: SemanticDocument) = {
4242
lazy val power = new impl.Power(global.value)
43-
val handled = mutable.Set.empty[Name]
43+
val handled = mutable.Set.empty[Term.Name]
44+
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+
}
4453

4554
def fix(tree: Tree, meth: Term, noTypeArgs: Boolean, noArgs: Boolean) = {
4655
for {
@@ -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`) =>
@@ -84,7 +93,7 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])
8493

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

97-
private def termName(term: Term): Option[Name] = condOpt(term) {
106+
private def termName(term: Term): Option[Term.Name] = condOpt(term) {
98107
case name: Term.Name => name
99108
case Term.Select(_, name: Term.Name) => name
100-
case Type.Select(_, name: Type.Name) => name
101109
}
102110

103111
override def withConfiguration(config: Configuration) = {

0 commit comments

Comments
 (0)