Skip to content

Commit

Permalink
Print privates in Scalap renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
retronym committed Jul 31, 2019
1 parent c50806c commit 37d3bfa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/scala/tools/jardiff/JarDiff.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ object JarDiff {
}
def apply(files: List[List[Path]], config: JarDiff.Config): JarDiff = {
val renderers = Map(
"class" -> List(new AsmTextifyRenderer(config.code, config.raw, config.privates), new ScalapRenderer()),
"sig" -> List(new ScalapSigRenderer())
"class" -> List(new AsmTextifyRenderer(config.code, config.raw, config.privates), new ScalapRenderer(config.privates)),
"sig" -> List(new ScalapSigRenderer(config.privates))
).withDefault(_ => List(IdentityRenderer))
new JarDiff(files, config, renderers)
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/scala/scala/tools/jardiff/ScalapRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import java.nio.file.{Files, Path}

import scala.tools.scalap.scalax.rules.ScalaSigParserError

class ScalapRenderer() extends FileRenderer {
class ScalapRenderer(privates: Boolean) extends FileRenderer {
def outFileExtension: String = ".scalap"
override def render(in: Path, out: Path): Unit = {
val classBytes = Files.readAllBytes(in)
try {
val decompiled = scala.tools.scalap.Main.decompileScala(classBytes, in.getFileName.toString == "package.class")
val main = new scala.tools.scalap.Main
main.printPrivates = privates
val decompiled = main.decompileScala(classBytes, in.getFileName.toString == "package.class")
if (decompiled != "") {
Files.createDirectories(out.getParent)
Files.write(out, decompiled.getBytes("UTF-8"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import java.nio.file.{Files, Path}
import scala.tools.scalap.scalax.rules.ScalaSigParserError
import scala.tools.scalap.scalax.rules.scalasig.{ByteCode, ScalaSigAttributeParsers}

class ScalapSigRenderer() extends FileRenderer {
class ScalapSigRenderer(privates: Boolean) extends FileRenderer {
def outFileExtension: String = ".scalap"
override def render(in: Path, out: Path): Unit = {
val classBytes = Files.readAllBytes(in)
try {
val scalaSig = ScalaSigAttributeParsers.parse(ByteCode(classBytes))
val decompiled = scala.tools.scalap.Main.parseScalaSignature(scalaSig, in.getFileName.toString == "package.sig")
val main = new scala.tools.scalap.Main
main.printPrivates = privates
val decompiled = main.parseScalaSignature(scalaSig, in.getFileName.toString == "package.sig")
if (decompiled != "") {
Files.createDirectories(out.getParent)
Files.write(out, decompiled.getBytes("UTF-8"))
Expand Down

0 comments on commit 37d3bfa

Please sign in to comment.