Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import mill.scalalib.publish.{Developer, License, PomSettings, VersionControl}
import mill.util.{Tasks, VcsVersion}

object Versions {
def scala = "3.3.8"
def scala = "3.9.0"
def graalVmVersion = "22.3.1"
def coursier = "2.1.25-M26"
def osLib = "0.11.8"
Expand Down Expand Up @@ -54,10 +54,8 @@ trait JavaMainClassNativeImage extends NativeImage {
}

trait JavaClassNameModule extends ScalaModule with ScalafixModule {
private val futureLazyValOpts = Seq("-Yfuture-lazy-vals", "-java-output-version:17")

override def scalacOptions: T[Seq[String]] =
super.scalacOptions() ++ Seq("-Wunused:all", "-deprecation", "-Werror") ++ futureLazyValOpts
super.scalacOptions() ++ Seq("-Wunused:all", "-deprecation", "-Werror")

override def scalaVersion: T[String] = Versions.scala
}
Expand Down
19 changes: 18 additions & 1 deletion java-class-name/src/scala/cli/javaclassname/JavaParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,35 @@ import dotty.tools.dotc.ast.untpd.ModuleDef
import dotty.tools.dotc.ast.{Trees, untpd}
import dotty.tools.dotc.core.Contexts.{Context, ContextBase}
import dotty.tools.dotc.core.Flags
import dotty.tools.dotc.core.StdNames.tpnme
import dotty.tools.dotc.parsing.JavaParsers.OutlineJavaParser
import dotty.tools.dotc.util.SourceFile
import dotty.tools.io.VirtualFile

import scala.io.Codec

object JavaParser {

/** The stock parser emits typed trees for `java.lang.Object` and `Unit`, which require the
* compiler definitions to be initialized (and thus the Scala library on the classpath). We only
* need names and modifiers, so we fall back to untyped trees and skip the dummy constructors.
*/
private class UntypedOutlineJavaParser(source: SourceFile)(using Context)
extends OutlineJavaParser(source) {
override def ObjectTpt(): untpd.Tree = javaLangDot(tpnme.Object)
override def makeTemplate(
parents: List[untpd.Tree],
stats: List[untpd.Tree],
tparams: List[untpd.TypeDef],
needsDummyConstr: Boolean
): untpd.Template = super.makeTemplate(parents, stats, tparams, needsDummyConstr = false)
}

private def parseOutline(byteContent: Array[Byte]): untpd.Tree = {
given Context = ContextBase().initialCtx.fresh
val virtualFile = VirtualFile("placeholder.java", byteContent)
val sourceFile = SourceFile(virtualFile, Codec.UTF8)
val outlineParser = OutlineJavaParser(sourceFile)
val outlineParser = UntypedOutlineJavaParser(sourceFile)
outlineParser.parse()
}

Expand Down
Loading