diff options
Diffstat (limited to 'src')
4 files changed, 20 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index a59b9d3f48..0374e1e2e6 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -923,6 +923,7 @@ abstract class ClassfileParser { Some(ScalaSigBytes(pool.getBytes(entries.toList))) } + // TODO SI-9296 duplicated code, refactor /* Parse and return a single annotation. If it is malformed, * return None. */ diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index 237efd004f..ce60ade9f5 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -591,6 +591,7 @@ private[scala] trait JavaMirrors extends internal.SymbolTable with api.JavaUnive // don't use classOf[scala.reflect.ScalaSignature] here, because it will use getClass.getClassLoader, not mirror's classLoader // don't use asInstanceOf either because of the same reason (lol, I cannot believe I fell for it) // don't use structural types to simplify reflective invocations because of the same reason + // TODO SI-9296 duplicated code, refactor def loadAnnotation(name: String): Option[java.lang.annotation.Annotation] = tryJavaClass(name) flatMap { annotClass => val anns = jclazz.getAnnotations diff --git a/src/scalap/scala/tools/scalap/Main.scala b/src/scalap/scala/tools/scalap/Main.scala index 7c554d196c..3d2bfd7251 100644 --- a/src/scalap/scala/tools/scalap/Main.scala +++ b/src/scalap/scala/tools/scalap/Main.scala @@ -28,6 +28,7 @@ import scalax.rules.scalasig._ class Main { val SCALA_SIG = "ScalaSig" val SCALA_SIG_ANNOTATION = "Lscala/reflect/ScalaSignature;" + val SCALA_LONG_SIG_ANNOTATION = "Lscala/reflect/ScalaLongSignature;" val BYTES_VALUE = "bytes" val versionMsg = "Scala classfile decoder %s -- %s\n".format(Properties.versionString, Properties.copyrightString) diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala index e3076322dd..c36fdd02cd 100644 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala +++ b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala @@ -14,20 +14,32 @@ package scalasig import scala.language.postfixOps import scala.language.implicitConversions -import ClassFileParser.{ ConstValueIndex, Annotation } +import ClassFileParser._ import scala.reflect.internal.pickling.ByteCodecs object ScalaSigParser { - import Main.{ SCALA_SIG, SCALA_SIG_ANNOTATION, BYTES_VALUE } + import Main.{ BYTES_VALUE, SCALA_LONG_SIG_ANNOTATION, SCALA_SIG, SCALA_SIG_ANNOTATION } + // TODO SI-9296 duplicated code, refactor def scalaSigFromAnnotation(classFile: ClassFile): Option[ScalaSig] = { import classFile._ - classFile.annotation(SCALA_SIG_ANNOTATION) map { + def getBytes(bytesElem: AnnotationElement): Array[Byte] = bytesElem.elementValue match { + case ConstValueIndex(index) => bytesForIndex(index) + case ArrayValue(signatureParts) => mergedLongSignatureBytes(signatureParts) + } + + def mergedLongSignatureBytes(signatureParts: Seq[ElementValue]): Array[Byte] = signatureParts.flatMap { + case ConstValueIndex(index) => bytesForIndex(index) + }(collection.breakOut) + + def bytesForIndex(index: Int) = constantWrapped(index).asInstanceOf[StringBytesPair].bytes + + classFile.annotation(SCALA_SIG_ANNOTATION) + .orElse(classFile.annotation(SCALA_LONG_SIG_ANNOTATION)).map { case Annotation(_, elements) => val bytesElem = elements.find(elem => constant(elem.elementNameIndex) == BYTES_VALUE).get - val bytes = ((bytesElem.elementValue match {case ConstValueIndex(index) => constantWrapped(index)}) - .asInstanceOf[StringBytesPair].bytes) + val bytes = getBytes(bytesElem) val length = ByteCodecs.decode(bytes) ScalaSigAttributeParsers.parse(ByteCode(bytes.take(length))) |