Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
povder committed Nov 4, 2023
1 parent 6d1de70 commit 4053e13
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
9 changes: 4 additions & 5 deletions compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -830,16 +830,15 @@ object JavaParsers {
val name = source.name.replaceAll("\\.java$", "").nn.toTypeName
val (statics, body) = typeBodyDecls(CLASS, name, parentTParams = Nil, firstMemberMods = Some(firstMemberMods))

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

val cls = atSpan(start, 0) {
TypeDef(name, makeTemplate(
parents = Nil,
stats = priorBody ::: body,
stats = body,
tparams = Nil,
needsDummyConstr = true)
).withMods(Modifiers(Flags.Private | Flags.Final))
Expand Down
53 changes: 51 additions & 2 deletions compiler/test/dotty/tools/dotc/parsing/JavaJep445ParserTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import dotty.tools.dotc.core.StdNames.tpnme
import dotty.tools.dotc.printing.{PlainPrinter, Printer}
import dotty.tools.dotc.util.SourceFile
import dotty.tools.io.PlainFile
import org.junit.Assert.fail
import org.junit.Assert.{assertTrue, fail}
import org.junit.Test

class JavaJep445ParserTest extends DottyTest {
Expand Down Expand Up @@ -62,7 +62,56 @@ class JavaJep445ParserTest extends DottyTest {
val tree = parser.parse()

println(tree.show)
}

fail("TODO")
@Test def `produces same trees for a class and equivalent unnamed class`
: Unit = {
val unnamedCode =
s"""
|import some.pkg.*;
|
|@interface InnerAnnotation {}
|
|interface InnerInterface {}
|
|static class InnerStaticClass {}
|
|void main() {}
|
|interface SecondInnerInterface {}
|
|""".stripMargin

val namedCode =
s"""
|import some.pkg.*;
|
|private final class MyUnnamed {
|
| @interface InnerAnnotation {}
|
| interface InnerInterface {}
|
| static class InnerStaticClass {}
|
| void main() {}
|
| interface SecondInnerInterface {}
|
|}
|
|""".stripMargin

val unnamedTree = JavaParsers
.JavaParser(SourceFile.virtual("MyUnnamed.java", unnamedCode))
.parse()
val namedTree = JavaParsers
.JavaParser(SourceFile.virtual("SomeFile.java", namedCode))
.parse()

assertTrue(
"expected same trees for named and unnamed classes",
unnamedTree == namedTree
)
}
}

0 comments on commit 4053e13

Please sign in to comment.