Skip to content

Commit 4053e13

Browse files
committed
wip
1 parent 6d1de70 commit 4053e13

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -830,16 +830,15 @@ object JavaParsers {
830830
val name = source.name.replaceAll("\\.java$", "").nn.toTypeName
831831
val (statics, body) = typeBodyDecls(CLASS, name, parentTParams = Nil, firstMemberMods = Some(firstMemberMods))
832832

833-
val (priorStatics, priorBody) = priorTypes.partition {
834-
case t: TypeDef => t.mods.is(Flags.JavaStatic)
835-
case _: ModuleDef => true
836-
case _ => false
833+
val priorStatics = priorTypes.map {
834+
case t: (TypeDef | ModuleDef) => t.withMods(t.mods.withFlags(Flags.JavaStatic))
835+
case x => x //TODO bug
837836
}
838837

839838
val cls = atSpan(start, 0) {
840839
TypeDef(name, makeTemplate(
841840
parents = Nil,
842-
stats = priorBody ::: body,
841+
stats = body,
843842
tparams = Nil,
844843
needsDummyConstr = true)
845844
).withMods(Modifiers(Flags.Private | Flags.Final))

compiler/test/dotty/tools/dotc/parsing/JavaJep445ParserTest.scala

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dotty.tools.dotc.core.StdNames.tpnme
88
import dotty.tools.dotc.printing.{PlainPrinter, Printer}
99
import dotty.tools.dotc.util.SourceFile
1010
import dotty.tools.io.PlainFile
11-
import org.junit.Assert.fail
11+
import org.junit.Assert.{assertTrue, fail}
1212
import org.junit.Test
1313

1414
class JavaJep445ParserTest extends DottyTest {
@@ -62,7 +62,56 @@ class JavaJep445ParserTest extends DottyTest {
6262
val tree = parser.parse()
6363

6464
println(tree.show)
65+
}
6566

66-
fail("TODO")
67+
@Test def `produces same trees for a class and equivalent unnamed class`
68+
: Unit = {
69+
val unnamedCode =
70+
s"""
71+
|import some.pkg.*;
72+
|
73+
|@interface InnerAnnotation {}
74+
|
75+
|interface InnerInterface {}
76+
|
77+
|static class InnerStaticClass {}
78+
|
79+
|void main() {}
80+
|
81+
|interface SecondInnerInterface {}
82+
|
83+
|""".stripMargin
84+
85+
val namedCode =
86+
s"""
87+
|import some.pkg.*;
88+
|
89+
|private final class MyUnnamed {
90+
|
91+
| @interface InnerAnnotation {}
92+
|
93+
| interface InnerInterface {}
94+
|
95+
| static class InnerStaticClass {}
96+
|
97+
| void main() {}
98+
|
99+
| interface SecondInnerInterface {}
100+
|
101+
|}
102+
|
103+
|""".stripMargin
104+
105+
val unnamedTree = JavaParsers
106+
.JavaParser(SourceFile.virtual("MyUnnamed.java", unnamedCode))
107+
.parse()
108+
val namedTree = JavaParsers
109+
.JavaParser(SourceFile.virtual("SomeFile.java", namedCode))
110+
.parse()
111+
112+
assertTrue(
113+
"expected same trees for named and unnamed classes",
114+
unnamedTree == namedTree
115+
)
67116
}
68117
}

0 commit comments

Comments
 (0)