-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java parser: add support for unnamed classes (JEP-445)
Fixes #18584
- Loading branch information
Showing
8 changed files
with
149 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
compiler/test/dotty/tools/dotc/parsing/JavaJep445ParserTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package dotty.tools.dotc.parsing | ||
|
||
import dotty.tools.DottyTest | ||
import dotty.tools.dotc.ast.Trees.{Ident, PackageDef, TypeDef} | ||
import dotty.tools.dotc.ast.untpd.ModuleDef | ||
import dotty.tools.dotc.core.Contexts.{Context, ContextBase} | ||
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.Test | ||
|
||
class JavaJep445ParserTest extends DottyTest { | ||
|
||
@Test def `parses unnamed class`: Unit = { | ||
val code = | ||
s""" | ||
|// hello | ||
| | ||
|import some.pkg.*; | ||
| | ||
|private volatile int x = 0; | ||
|@Magic | ||
|protected String s = "s"; | ||
| | ||
|void main() {} | ||
|""".stripMargin | ||
|
||
val parser = | ||
JavaParsers.JavaParser(SourceFile.virtual("MyUnnamed.java", code)) | ||
val tree = parser.parse() | ||
|
||
println(tree.show) | ||
|
||
fail("TODO") | ||
} | ||
|
||
@Test def `treats leading top-level types as nested types of unnamed class`: Unit = { | ||
val code = | ||
s""" | ||
|// hello | ||
| | ||
|import some.pkg.*; | ||
| | ||
|interface Inner {} | ||
| | ||
|static class InnerStatic {} | ||
| | ||
|void main() {} | ||
|""".stripMargin | ||
|
||
val parser = | ||
JavaParsers.JavaParser(SourceFile.virtual("MyUnnamed.java", code)) | ||
val tree = parser.parse() | ||
|
||
println(tree.show) | ||
|
||
fail("TODO") | ||
} | ||
|
||
@Test def `treats leading top-level annotated vars as members of unnamed class`: Unit = { | ||
val code = | ||
s""" | ||
| | ||
|import some.pkg.*; | ||
| | ||
|@MyAnnotation | ||
|int x = 0; | ||
| | ||
|void main() {} | ||
|""".stripMargin | ||
|
||
val parser = | ||
JavaParsers.JavaParser(SourceFile.virtual("MyUnnamed.java", code)) | ||
val tree = parser.parse() | ||
|
||
println(tree.show) | ||
|
||
fail("TODO") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class B |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
void main() {} |
5 changes: 5 additions & 0 deletions
5
tests/pos-java21+/jep445/UnnamedStartsWithAnnotatedField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
@MyAnnotation | ||
int myInt = 10; | ||
|
||
void main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
private volatile int myInt = 10; | ||
|
||
String hello() { | ||
return "hello"; | ||
} | ||
|
||
interface Inner {} | ||
|
||
void main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
class InnerOfUnnamed {} | ||
|
||
void main() {} |