@@ -8,12 +8,13 @@ import SymDenotations._, unpickleScala2.Scala2Unpickler._, Constants._, Annotati
88import NameKinds .{ModuleClassName , DefaultGetterName }
99import ast .tpd ._
1010import java .io .{ ByteArrayInputStream , DataInputStream , File , IOException }
11+ import java .nio
1112import java .lang .Integer .toHexString
1213import scala .collection .{ mutable , immutable }
1314import scala .collection .mutable .{ ListBuffer , ArrayBuffer }
1415import scala .annotation .switch
1516import typer .Checking .checkNonCyclic
16- import io .{AbstractFile , PlainFile }
17+ import io .{AbstractFile , PlainFile , Path , ZipArchive , JarArchive }
1718import scala .util .control .NonFatal
1819
1920object ClassfileParser {
@@ -781,11 +782,28 @@ class ClassfileParser(
781782
782783 if (scan(tpnme.TASTYATTR )) {
783784 val attrLen = in.nextInt
784- if (attrLen == 0 ) {
785- // A tasty attribute implies the existence of the .tasty file
786- val file = new PlainFile (io.File (classfile.jpath).changeExtension(" tasty" ))
787- if (file.exists) return unpickleTASTY(new AbstractFileReader (file).nextBytes(file.sizeOption.get))
788- else ctx.error(" Could not find " + file)
785+ if (attrLen == 0 ) { // A tasty attribute implies the existence of the .tasty file
786+ def readTastyForClass (jpath : nio.file.Path ): Array [Byte ] = {
787+ val plainFile = new PlainFile (io.File (jpath).changeExtension(" tasty" ))
788+ if (plainFile.exists) plainFile.toByteArray
789+ else {
790+ ctx.error(" Could not find " + plainFile)
791+ Array .empty
792+ }
793+ }
794+ val tastyBytes = classfile.underlyingSource match { // TODO: simplify when #3552 is fixed
795+ case None =>
796+ ctx.error(" Could not load TASTY from .tasty for virtual file " + classfile)
797+ Array .empty[Byte ]
798+ case Some (jar : ZipArchive ) => // We are in a jar
799+ val jarFile = JarArchive .open(io.File (jar.jpath))
800+ try readTastyForClass(jarFile.jpath.resolve(classfile.path))
801+ finally jarFile.close()
802+ case _ =>
803+ readTastyForClass(classfile.jpath)
804+ }
805+ if (tastyBytes.nonEmpty)
806+ return unpickleTASTY(tastyBytes)
789807 }
790808 else return unpickleTASTY(in.nextBytes(attrLen))
791809 }
0 commit comments