@@ -8,12 +8,13 @@ import SymDenotations._, unpickleScala2.Scala2Unpickler._, Constants._, Annotati
8
8
import NameKinds .{ModuleClassName , DefaultGetterName }
9
9
import ast .tpd ._
10
10
import java .io .{ ByteArrayInputStream , DataInputStream , File , IOException }
11
+ import java .nio
11
12
import java .lang .Integer .toHexString
12
13
import scala .collection .{ mutable , immutable }
13
14
import scala .collection .mutable .{ ListBuffer , ArrayBuffer }
14
15
import scala .annotation .switch
15
16
import typer .Checking .checkNonCyclic
16
- import io .{AbstractFile , PlainFile }
17
+ import io .{AbstractFile , PlainFile , Path , ZipArchive , JarArchive }
17
18
import scala .util .control .NonFatal
18
19
19
20
object ClassfileParser {
@@ -781,11 +782,28 @@ class ClassfileParser(
781
782
782
783
if (scan(tpnme.TASTYATTR )) {
783
784
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)
789
807
}
790
808
else return unpickleTASTY(in.nextBytes(attrLen))
791
809
}
0 commit comments