File tree Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 1+ case class Scala3Class(a: Int)(using b: String)
Original file line number Diff line number Diff line change 11import scala .meta ._
2+ import scala .meta .Dialect
23
34case class ScalaFile (
45 imports : List [String ],
@@ -44,9 +45,8 @@ object FileParser {
4445 }
4546 }
4647
47- def parse (content : String ): ScalaFile = {
48+ def parse (content : String , dialect : Dialect = dialects. Scala213Source3 ): ScalaFile = {
4849 val input = Input .String (content)
49- val dialect = dialects.Scala213Source3
5050 val exampleTree : Source = dialect(input).parse[Source ].get
5151
5252 val tree =
@@ -78,6 +78,10 @@ object FileParser {
7878 val path = java.nio.file.Paths .get(filePath)
7979 val bytes = java.nio.file.Files .readAllBytes(path)
8080 val text = new String (bytes, " UTF-8" )
81- parse(text)
81+ val dialect =
82+ if (filePath.split(java.io.File .separator).contains(" scala-3" ))
83+ dialects.Scala3
84+ else dialects.Scala213Source3
85+ parse(text, dialect)
8286 }
8387}
Original file line number Diff line number Diff line change @@ -63,4 +63,13 @@ class FileParserTest extends munit.FunSuite {
6363 val parsedFile = FileParser .fromPathToClassDef(file)
6464 println(parsedFile)
6565 }
66+ test(" uses Scala3 dialect for sources in scala-3 directory" ) {
67+ val file = Thread
68+ .currentThread()
69+ .getContextClassLoader
70+ .getResource(" scala-3/Scala3Class.scala_test" )
71+ .getPath
72+ val parsedFile = FileParser .fromPathToClassDef(file)
73+ assert(parsedFile.classes.head.name == " Scala3Class" )
74+ }
6675}
You can’t perform that action at this time.
0 commit comments