Skip to content

Commit b43ae58

Browse files
committed
introduces an exhaustive java-to-scala test
Originally composed to accommodate pull request feedback, this test has uncovered a handful of bugs in FromJavaClassCompleter, namely: * SI-7071 non-public ctors get lost * SI-7072 inner classes are read incorrectly I'm leaving the incorrect results of FromJavaClassCompleters in the check file, so that we get notified when something changes there.
1 parent 02ed5fb commit b43ae58

File tree

3 files changed

+262
-17
lines changed

3 files changed

+262
-17
lines changed

test/files/run/t6989.check

Lines changed: 196 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,216 @@
11
============
2-
class JavaClass_1
2+
sym = class PackagePrivateJavaClass, signature = ClassInfoType(...), owner = package foo
33
isPrivate = false
44
isProtected = false
55
isPublic = false
66
privateWithin = package foo
77
============
8-
variable x
8+
sym = constructor PackagePrivateJavaClass, signature = (x$1: Int, x$2: Int)foo.PackagePrivateJavaClass, owner = class PackagePrivateJavaClass
9+
isPrivate = false
10+
isProtected = false
11+
isPublic = true
12+
privateWithin = <none>
13+
============
14+
sym = variable privateField, signature = Int, owner = class PackagePrivateJavaClass
15+
isPrivate = true
16+
isProtected = false
17+
isPublic = false
18+
privateWithin = <none>
19+
============
20+
sym = method privateMethod, signature = ()Unit, owner = class PackagePrivateJavaClass
21+
isPrivate = true
22+
isProtected = false
23+
isPublic = false
24+
privateWithin = <none>
25+
============
26+
sym = variable protectedField, signature = Int, owner = class PackagePrivateJavaClass
27+
isPrivate = false
28+
isProtected = true
29+
isPublic = false
30+
privateWithin = package foo
31+
============
32+
sym = method protectedMethod, signature = ()Unit, owner = class PackagePrivateJavaClass
33+
isPrivate = false
34+
isProtected = true
35+
isPublic = false
36+
privateWithin = package foo
37+
============
38+
sym = variable publicField, signature = Int, owner = class PackagePrivateJavaClass
39+
isPrivate = false
40+
isProtected = false
41+
isPublic = true
42+
privateWithin = <none>
43+
============
44+
sym = method publicMethod, signature = ()Unit, owner = class PackagePrivateJavaClass
45+
isPrivate = false
46+
isProtected = false
47+
isPublic = true
48+
privateWithin = <none>
49+
============
50+
sym = object PackagePrivateJavaClass, signature = foo.PackagePrivateJavaClass.type, owner = package foo
51+
isPrivate = false
52+
isProtected = false
53+
isPublic = false
54+
privateWithin = package foo
55+
============
56+
sym = variable privateStaticField, signature = Int, owner = object PackagePrivateJavaClass
57+
isPrivate = true
58+
isProtected = false
59+
isPublic = false
60+
privateWithin = <none>
61+
============
62+
sym = method privateStaticMethod, signature = ()Unit, owner = object PackagePrivateJavaClass
63+
isPrivate = true
64+
isProtected = false
65+
isPublic = false
66+
privateWithin = <none>
67+
============
68+
sym = variable protectedStaticField, signature = Int, owner = object PackagePrivateJavaClass
69+
isPrivate = false
70+
isProtected = true
71+
isPublic = false
72+
privateWithin = package foo
73+
============
74+
sym = method protectedStaticMethod, signature = ()Unit, owner = object PackagePrivateJavaClass
75+
isPrivate = false
76+
isProtected = true
77+
isPublic = false
78+
privateWithin = package foo
79+
============
80+
sym = variable publicStaticField, signature = Int, owner = object PackagePrivateJavaClass
81+
isPrivate = false
82+
isProtected = false
83+
isPublic = true
84+
privateWithin = <none>
85+
============
86+
sym = method publicStaticMethod, signature = ()Unit, owner = object PackagePrivateJavaClass
87+
isPrivate = false
88+
isProtected = false
89+
isPublic = true
90+
privateWithin = <none>
91+
============
92+
sym = class JavaClass_1, signature = ClassInfoType(...), owner = package foo
93+
isPrivate = false
94+
isProtected = false
95+
isPublic = true
96+
privateWithin = <none>
97+
============
98+
sym = class $PrivateJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
99+
isPrivate = true
100+
isProtected = false
101+
isPublic = false
102+
privateWithin = <none>
103+
============
104+
sym = value this$0, signature = foo.JavaClass_1, owner = class $PrivateJavaClass
105+
isPrivate = false
106+
isProtected = false
107+
isPublic = false
108+
privateWithin = package foo
109+
============
110+
sym = object $PrivateJavaClass, signature = JavaClass_1.this.$PrivateJavaClass.type, owner = class JavaClass_1
9111
isPrivate = true
10112
isProtected = false
11113
isPublic = false
12114
privateWithin = <none>
13115
============
14-
variable y
116+
sym = class $ProtectedJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
15117
isPrivate = false
16118
isProtected = true
17119
isPublic = false
18120
privateWithin = package foo
19121
============
20-
variable z
122+
sym = value this$0, signature = foo.JavaClass_1, owner = class $ProtectedJavaClass
123+
isPrivate = false
124+
isProtected = false
125+
isPublic = false
126+
privateWithin = package foo
127+
============
128+
sym = object $ProtectedJavaClass, signature = JavaClass_1.this.$ProtectedJavaClass.type, owner = class JavaClass_1
129+
isPrivate = false
130+
isProtected = false
131+
isPublic = false
132+
privateWithin = package foo
133+
============
134+
sym = class $PublicJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
135+
isPrivate = false
136+
isProtected = false
137+
isPublic = true
138+
privateWithin = <none>
139+
============
140+
sym = constructor $PublicJavaClass, signature = (x$1: foo.JavaClass_1)JavaClass_1.this.$PublicJavaClass, owner = class $PublicJavaClass
141+
isPrivate = false
142+
isProtected = false
143+
isPublic = true
144+
privateWithin = <none>
145+
============
146+
sym = value this$0, signature = foo.JavaClass_1, owner = class $PublicJavaClass
147+
isPrivate = false
148+
isProtected = false
149+
isPublic = false
150+
privateWithin = package foo
151+
============
152+
sym = object $PublicJavaClass, signature = JavaClass_1.this.$PublicJavaClass.type, owner = class JavaClass_1
153+
isPrivate = false
154+
isProtected = false
155+
isPublic = true
156+
privateWithin = <none>
157+
============
158+
sym = constructor JavaClass_1, signature = ()foo.JavaClass_1, owner = class JavaClass_1
159+
isPrivate = false
160+
isProtected = false
161+
isPublic = true
162+
privateWithin = <none>
163+
============
164+
sym = object JavaClass_1, signature = foo.JavaClass_1.type, owner = package foo
21165
isPrivate = false
22166
isProtected = false
23167
isPublic = true
24168
privateWithin = <none>
169+
============
170+
sym = class PrivateStaticJavaClass, signature = ClassInfoType(...), owner = object JavaClass_1
171+
isPrivate = true
172+
isProtected = false
173+
isPublic = false
174+
privateWithin = <none>
175+
============
176+
sym = object PrivateStaticJavaClass, signature = foo.JavaClass_1.PrivateStaticJavaClass.type, owner = object JavaClass_1
177+
isPrivate = true
178+
isProtected = false
179+
isPublic = false
180+
privateWithin = <none>
181+
============
182+
sym = class ProtectedStaticJavaClass, signature = ClassInfoType(...), owner = object JavaClass_1
183+
isPrivate = true
184+
isProtected = false
185+
isPublic = false
186+
privateWithin = <none>
187+
============
188+
sym = object ProtectedStaticJavaClass, signature = foo.JavaClass_1.ProtectedStaticJavaClass.type, owner = object JavaClass_1
189+
isPrivate = true
190+
isProtected = false
191+
isPublic = false
192+
privateWithin = <none>
193+
============
194+
sym = class PublicStaticJavaClass, signature = ClassInfoType(...), owner = object JavaClass_1
195+
isPrivate = false
196+
isProtected = false
197+
isPublic = true
198+
privateWithin = <none>
199+
============
200+
sym = constructor PublicStaticJavaClass, signature = ()foo.JavaClass_1.PublicStaticJavaClass, owner = class PublicStaticJavaClass
201+
isPrivate = false
202+
isProtected = false
203+
isPublic = true
204+
privateWithin = <none>
205+
============
206+
sym = object PublicStaticJavaClass, signature = foo.JavaClass_1.PublicStaticJavaClass.type, owner = object JavaClass_1
207+
isPrivate = false
208+
isProtected = false
209+
isPublic = true
210+
privateWithin = <none>
211+
============
212+
sym = variable staticField, signature = Int, owner = object JavaClass_1
213+
isPrivate = true
214+
isProtected = false
215+
isPublic = false
216+
privateWithin = <none>

test/files/run/t6989/JavaClass_1.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
11
package foo;
22

3-
class JavaClass_1 {
4-
private int x = 0;
5-
protected String y = "";
6-
public float z = 0.0f;
3+
// Originally composed to accommodate pull request feedback, this test has
4+
// uncovered a handful of bugs in FromJavaClassCompleter, namely:
5+
// * SI-7071 non-public ctors get lost
6+
// * SI-7072 inner classes are read incorrectly
7+
8+
// I'm leaving the incorrect results of FromJavaClassCompleters in the check
9+
// file, so that we get notified when something changes there.
10+
11+
class PackagePrivateJavaClass {
12+
private int privateField = 0;
13+
protected int protectedField = 1;
14+
public int publicField = 2;
15+
16+
private static int privateStaticField = 3;
17+
protected static int protectedStaticField = 4;
18+
public static int publicStaticField = 5;
19+
20+
private void privateMethod() {}
21+
protected void protectedMethod() {}
22+
public void publicMethod() {}
23+
24+
private static void privateStaticMethod() {}
25+
protected static void protectedStaticMethod() {}
26+
public static void publicStaticMethod() {}
27+
28+
private PackagePrivateJavaClass() {}
29+
protected PackagePrivateJavaClass(int x) {}
30+
public PackagePrivateJavaClass(int x, int y) {}
31+
}
32+
33+
public class JavaClass_1 {
34+
private class PrivateJavaClass {}
35+
private static class PrivateStaticJavaClass {}
36+
protected class ProtectedJavaClass {}
37+
private static class ProtectedStaticJavaClass {}
38+
public class PublicJavaClass {}
39+
public static class PublicStaticJavaClass {}
40+
private static int staticField = 0;
741
}

test/files/run/t6989/Test_2.scala

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
import scala.reflect.runtime.universe._
22

3+
// Originally composed to accommodate pull request feedback, this test has
4+
// uncovered a handful of bugs in FromJavaClassCompleter, namely:
5+
// * SI-7071 non-public ctors get lost
6+
// * SI-7072 inner classes are read incorrectly
7+
8+
// I'm leaving the incorrect results of FromJavaClassCompleters in the check
9+
// file, so that we get notified when something changes there.
10+
311
package object foo {
4-
def test(sym: Symbol) = {
12+
def testAll(): Unit = {
13+
test(typeOf[foo.PackagePrivateJavaClass].typeSymbol)
14+
test(typeOf[foo.PackagePrivateJavaClass].typeSymbol.companionSymbol)
15+
test(typeOf[foo.JavaClass_1].typeSymbol)
16+
test(typeOf[foo.JavaClass_1].typeSymbol.companionSymbol)
17+
}
18+
19+
def test(sym: Symbol): Unit = {
20+
printSymbolDetails(sym)
21+
if (sym.isClass || sym.isModule) {
22+
sym.typeSignature.declarations.toList.sortBy(_.name.toString) foreach test
23+
}
24+
}
25+
26+
def printSymbolDetails(sym: Symbol): Unit = {
27+
def stableSignature(sym: Symbol) = sym.typeSignature match {
28+
case ClassInfoType(_, _, _) => "ClassInfoType(...)"
29+
case tpe => tpe.toString
30+
}
531
println("============")
6-
println(sym)
32+
println(s"sym = $sym, signature = ${stableSignature(sym)}, owner = ${sym.owner}")
733
println(s"isPrivate = ${sym.isPrivate}")
834
println(s"isProtected = ${sym.isProtected}")
935
println(s"isPublic = ${sym.isPublic}")
1036
println(s"privateWithin = ${sym.privateWithin}")
1137
}
12-
13-
def testAll() = {
14-
test(typeOf[foo.JavaClass_1].typeSymbol)
15-
test(typeOf[foo.JavaClass_1].declaration(newTermName("x")))
16-
test(typeOf[foo.JavaClass_1].declaration(newTermName("y")))
17-
test(typeOf[foo.JavaClass_1].declaration(newTermName("z")))
18-
}
1938
}
2039

2140
object Test extends App {

0 commit comments

Comments
 (0)