Skip to content

Commit b2df038

Browse files
committed
ExplicitNonNullaryApply sad story for Java methods
What we'd like is to leave any call to a method that was defined in Java (or any "universal" method, like ##, eq, isInstanceOf) to be exempt. It appears Scalameta/Semanticdb/Scalafix doesn't capture that information, and thus basically all of them get parens... :( Apparently in Metals they use the presentation compiler to recover all the missing info and I know in ScalaClean they have their own nsc Traverser, I'm guessing for the same reason.
1 parent 947fe8d commit b2df038

File tree

6 files changed

+206
-0
lines changed

6 files changed

+206
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package fix.scala213;
2+
3+
interface ExplicitNonNullaryApplyI {
4+
String foo();
5+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
rule = fix.scala213.ExplicitNonNullaryApply
3+
*/
4+
package fix.scala213
5+
6+
import ExplicitNonNullaryApplyJavaDefs._
7+
8+
class ExplicitNonNullaryApplyJava {
9+
any.##
10+
any.getClass()
11+
any.getClass
12+
any.hashCode()
13+
any.hashCode
14+
any.toString()
15+
any.toString
16+
17+
ref.##
18+
ref.getClass()
19+
ref.getClass
20+
ref.hashCode()
21+
ref.hashCode
22+
ref.toString()
23+
ref.toString
24+
25+
obj.##
26+
obj.getClass()
27+
obj.getClass
28+
obj.hashCode()
29+
obj.hashCode
30+
obj.toString()
31+
obj.toString
32+
33+
str.##
34+
str.getClass()
35+
str.getClass
36+
str.hashCode()
37+
str.hashCode
38+
str.toString()
39+
str.toString
40+
41+
cm.toString()
42+
cm.toString
43+
cp.toString()
44+
cp.toString
45+
46+
cm.run()
47+
cm.run
48+
cp.run()
49+
cp.run
50+
51+
cm.foo()
52+
cm.foo
53+
cp.foo()
54+
cp.foo
55+
56+
vcm.toString()
57+
vcm.toString
58+
vcp.toString()
59+
vcp.toString
60+
61+
ccm.toString()
62+
ccm.toString
63+
ccp.toString()
64+
ccp.toString
65+
66+
vccm.toString()
67+
vccm.toString
68+
vccp.toString()
69+
vccp.toString
70+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**/
2+
package fix.scala213
3+
4+
object ExplicitNonNullaryApplyJavaDefs {
5+
class CM extends Runnable with ExplicitNonNullaryApplyI { override def toString() = ""; def run() = (); def foo() = "" }
6+
class CP extends Runnable with ExplicitNonNullaryApplyI { override def toString = ""; def run = (); def foo = "" }
7+
8+
case class CCM() extends Runnable with ExplicitNonNullaryApplyI { override def toString() = ""; def run() = (); def foo() = "" }
9+
case class CCP() extends Runnable with ExplicitNonNullaryApplyI { override def toString = ""; def run = (); def foo = "" }
10+
11+
class VCM(val x: String) extends AnyVal { override def toString() = "" }
12+
class VCP(val x: String) extends AnyVal { override def toString = "" }
13+
14+
case class VCCM(x: String) extends AnyVal { override def toString() = "" }
15+
case class VCCP(x: String) extends AnyVal { override def toString = "" }
16+
17+
val any: Any = ""
18+
val ref: AnyRef = ""
19+
val obj: Object = ""
20+
val str: String = ""
21+
22+
val cm: CM = new CM()
23+
val cp: CP = new CP()
24+
val vcm: VCM = new VCM("")
25+
val vcp: VCP = new VCP("")
26+
val ccm: CCM = CCM()
27+
val ccp: CCP = CCP()
28+
val vccm: VCCM = VCCM("")
29+
val vccp: VCCP = VCCP("")
30+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package fix.scala213;
2+
3+
interface ExplicitNonNullaryApplyI {
4+
String foo();
5+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package fix.scala213
2+
3+
import ExplicitNonNullaryApplyJavaDefs._
4+
5+
class ExplicitNonNullaryApplyJava {
6+
any.##()
7+
any.getClass()
8+
any.getClass()
9+
any.hashCode()
10+
any.hashCode()
11+
any.toString()
12+
any.toString()
13+
14+
ref.##
15+
ref.getClass()
16+
ref.getClass
17+
ref.hashCode()
18+
ref.hashCode
19+
ref.toString()
20+
ref.toString
21+
22+
obj.##
23+
obj.getClass()
24+
obj.getClass
25+
obj.hashCode()
26+
obj.hashCode
27+
obj.toString()
28+
obj.toString
29+
30+
str.##
31+
str.getClass()
32+
str.getClass
33+
str.hashCode()
34+
str.hashCode
35+
str.toString()
36+
str.toString
37+
38+
cm.toString()
39+
cm.toString()
40+
cp.toString()
41+
cp.toString()
42+
43+
cm.run()
44+
cm.run()
45+
cp.run()
46+
cp.run()
47+
48+
cm.foo()
49+
cm.foo()
50+
cp.foo()
51+
cp.foo()
52+
53+
vcm.toString()
54+
vcm.toString()
55+
vcp.toString()
56+
vcp.toString()
57+
58+
ccm.toString()
59+
ccm.toString()
60+
ccp.toString()
61+
ccp.toString()
62+
63+
vccm.toString()
64+
vccm.toString()
65+
vccp.toString()
66+
vccp.toString()
67+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package fix.scala213
2+
3+
object ExplicitNonNullaryApplyJavaDefs {
4+
class CM extends Runnable with ExplicitNonNullaryApplyI { override def toString() = ""; def run() = (); def foo() = "" }
5+
class CP extends Runnable with ExplicitNonNullaryApplyI { override def toString = ""; def run = (); def foo = "" }
6+
7+
case class CCM() extends Runnable with ExplicitNonNullaryApplyI { override def toString() = ""; def run() = (); def foo() = "" }
8+
case class CCP() extends Runnable with ExplicitNonNullaryApplyI { override def toString = ""; def run = (); def foo = "" }
9+
10+
class VCM(val x: String) extends AnyVal { override def toString() = "" }
11+
class VCP(val x: String) extends AnyVal { override def toString = "" }
12+
13+
case class VCCM(x: String) extends AnyVal { override def toString() = "" }
14+
case class VCCP(x: String) extends AnyVal { override def toString = "" }
15+
16+
val any: Any = ""
17+
val ref: AnyRef = ""
18+
val obj: Object = ""
19+
val str: String = ""
20+
21+
val cm: CM = new CM()
22+
val cp: CP = new CP()
23+
val vcm: VCM = new VCM("")
24+
val vcp: VCP = new VCP("")
25+
val ccm: CCM = CCM()
26+
val ccp: CCP = CCP()
27+
val vccm: VCCM = VCCM("")
28+
val vccp: VCCP = VCCP("")
29+
}

0 commit comments

Comments
 (0)