Skip to content

Commit

Permalink
[test-import] Updated scalac-options.json for 3.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
SrTobi committed Jan 13, 2025
1 parent 221e183 commit 1d9ac62
Show file tree
Hide file tree
Showing 2 changed files with 1,551 additions and 456 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,12 @@ object UpdateScalacOptionsInfo {
case VersionTag =>
(Some(defaultScalaVersionStr(setting)), ArgType.OneAfterColon)
case StringTag =>
val prefix = prefixField.get(setting).asInstanceOf[String]
val prefix = prefixField.get(setting) match {
case s: String => s
case opt =>
// since 3.4 the prefix field is an Option[String]
toOption(opt).map(_.asInstanceOf[String]).getOrElse("")
}
val argType =
if (prefix.nonEmpty) ArgType.OneAfterPrefix(prefix)
else if (choices.nonEmpty) ArgType.OneAfterColon
Expand Down Expand Up @@ -364,17 +369,29 @@ object UpdateScalacOptionsInfo {
val additionalMapping =
Option.when(langLevel.isScala2 && langLevel > ScalaLanguageLevel.Scala_2_11)(getSecondElementOfTuple2(_))

def settingsInstanceByClass(settingsClass: Class[_]): Option[Any] =
settingsClass.getDeclaredConstructors
.sortBy(_.getParameterCount)
.headOption
.map(constructor => constructor.newInstance(Seq.fill(constructor.getParameterCount)(null): _*))

def settingsInstanceByObject(settingsClass: Class[_]): Option[Any] = {
val objectClass = loadClass(settingsClass.getName + "$")
Option(objectClass.getDeclaredField("MODULE$").get(null))
}

val settingsClassName =
if (langLevel.isScala3) "dotty.tools.dotc.config.ScalaSettings"
else "scala.tools.nsc.doc.Settings"

val settingsClass = loadClass(settingsClassName)

settingsClass.getDeclaredConstructors
.sortBy(_.getParameterCount)
.headOption
.map { constructor =>
val settingsInstance = constructor.newInstance(Seq.fill(constructor.getParameterCount)(null): _*)
val settingsInstance =
if (langLevel >= ScalaLanguageLevel.Scala_3_4) settingsInstanceByObject(settingsClass)
else settingsInstanceByClass(settingsClass)

settingsInstance
.map { settingsInstance =>
val allSettingsMethod = settingsClass.getMethod("allSettings")
val allSettings = allSettingsMethod.invoke(settingsInstance)

Expand Down
Loading

0 comments on commit 1d9ac62

Please sign in to comment.