Skip to content

Commit ec6df52

Browse files
authored
Merge pull request #48 from dwijnand/try-to-improve-ExplicitNonNullaryApply
Try to improve ExplicitNonNullaryApply
2 parents c5d5f5c + 74fcbfc commit ec6df52

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])
2525
override def fix(implicit doc: SemanticDocument): Patch = {
2626
try unsafeFix() catch {
2727
case _: CompilerException =>
28-
shutdownCompiler()
29-
global.restart()
28+
// Give it another shot (good old "retry.retry")
29+
// as the presentation compiler sometimes just dies and succeeds the next time...
30+
shutdownAndResetCompiler()
3031
try unsafeFix() catch {
31-
case _: CompilerException => Patch.empty /* ignore compiler crashes */
32+
case _: CompilerException =>
33+
// Give up on fixing this file as compiling it crashed the (presentation) compiler twice
34+
// but first reset the state of the compiler for the next file
35+
shutdownAndResetCompiler()
36+
Patch.empty
3237
}
3338
}
3439
}
@@ -47,7 +52,7 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])
4752
if !cond(name.parent) { case Some(Term.ApplyInfix(_, `name`, _, _)) => true }
4853
if !tree.parent.exists(_.is[Term.Eta]) // else rewrites `meth _` to `meth() _`, or requires running ExplicitNullaryEtaExpansion first
4954
info <- name.symbol.info
50-
if !power.isJavaDefined(name)
55+
if !info.isJava // shallow, isJavaDefined (below) checks overrides
5156
if cond(info.signature) {
5257
case MethodSignature(_, Nil :: _, _) => true
5358
case ClassSignature(_, _, _, decls) if tree.isInstanceOf[Term.ApplyType] =>
@@ -56,6 +61,7 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])
5661
cond(decl.signature) { case MethodSignature(_, Nil :: _, _) => true }
5762
}
5863
}
64+
if !power.isJavaDefined(name) // full check, using the presentation compiler :O
5965
} yield {
6066
val optAddDot = name.parent.collect {
6167
case PostfixSelect(qual, `name`) =>
@@ -112,6 +118,15 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])
112118
}
113119
}
114120

115-
override def afterComplete() = shutdownCompiler()
116-
def shutdownCompiler() = for (g <- global) nonFatalCatch { g.askShutdown(); g.close() }
121+
override def afterComplete() = shutdownAndResetCompiler()
122+
123+
def shutdownAndResetCompiler() = {
124+
for (g <- global) {
125+
nonFatalCatch {
126+
g.askShutdown()
127+
g.close()
128+
}
129+
}
130+
global.restart() // more of a "reset", as nothing's eagerly started
131+
}
117132
}

0 commit comments

Comments
 (0)