summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2009-12-18 10:43:36 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2009-12-18 10:43:36 +0000
commitbbc126660fd65c0aacee03b77f04de91df6959c7 (patch)
tree46e159a4eb87cb71b2387cf11cb79c89975ee617 /src/compiler
parent05363648a6f97f3a2175200484bb46df9f9548d5 (diff)
downloadscala-bbc126660fd65c0aacee03b77f04de91df6959c7.tar.gz
scala-bbc126660fd65c0aacee03b77f04de91df6959c7.tar.bz2
scala-bbc126660fd65c0aacee03b77f04de91df6959c7.zip
read the Exceptions attribute from java classfi...
read the Exceptions attribute from java classfiles. review by dragos
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala11
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Definitions.scala1
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala18
3 files changed, 24 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
index fef14e940b..50e16dc6b8 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
@@ -93,7 +93,6 @@ abstract class GenJVM extends SubComponent {
val TransientAtt = definitions.getClass("scala.transient")
val VolatileAttr = definitions.getClass("scala.volatile")
val RemoteAttr = definitions.getClass("scala.remote")
- val ThrowsAttr = definitions.getClass("scala.throws")
val BeanInfoAttr = definitions.getClass("scala.reflect.BeanInfo")
val BeanInfoSkipAttr = definitions.getClass("scala.reflect.BeanInfoSkip")
val BeanDisplayNameAttr = definitions.getClass("scala.reflect.BeanDisplayName")
@@ -333,7 +332,7 @@ abstract class GenJVM extends SubComponent {
// put some radom value; the actual number is determined at the end
buf.putShort(0xbaba.toShort)
- for (AnnotationInfo(tp, List(exc), _) <- excs.removeDuplicates if tp.typeSymbol == ThrowsAttr) {
+ for (AnnotationInfo(tp, List(exc), _) <- excs.removeDuplicates if tp.typeSymbol == definitions.ThrowsClass) {
val Literal(const) = exc
buf.putShort(
cpool.addClass(
@@ -626,7 +625,7 @@ abstract class GenJVM extends SubComponent {
}
addGenericSignature(jmethod, m.symbol, clasz.symbol)
- val (excs, others) = splitAnnotations(m.symbol.annotations, ThrowsAttr)
+ val (excs, others) = splitAnnotations(m.symbol.annotations, definitions.ThrowsClass)
addExceptionsAttribute(jmethod, excs)
addAnnotations(jmethod, others)
addParamAnnotations(jmethod, m.params.map(_.sym.annotations))
@@ -634,7 +633,7 @@ abstract class GenJVM extends SubComponent {
private def addRemoteException(jmethod: JMethod, meth: Symbol) {
def isRemoteThrows(ainfo: AnnotationInfo) = ainfo match {
- case AnnotationInfo(tp, List(arg), _) if tp.typeSymbol == ThrowsAttr =>
+ case AnnotationInfo(tp, List(arg), _) if tp.typeSymbol == definitions.ThrowsClass =>
arg match {
case Literal(Constant(tpe: Type)) if tpe.typeSymbol == RemoteException.typeSymbol => true
case _ => false
@@ -645,7 +644,7 @@ abstract class GenJVM extends SubComponent {
if (remoteClass ||
(meth.hasAnnotation(RemoteAttr) && jmethod.isPublic())) {
val c = Constant(RemoteException)
- val ainfo = AnnotationInfo(ThrowsAttr.tpe, List(Literal(c).setType(c.tpe)), List())
+ val ainfo = AnnotationInfo(definitions.ThrowsClass.tpe, List(Literal(c).setType(c.tpe)), List())
if (!meth.annotations.exists(isRemoteThrows)) {
meth.addAnnotation(ainfo)
}
@@ -810,7 +809,7 @@ abstract class GenJVM extends SubComponent {
if (!m.hasFlag(Flags.DEFERRED))
addGenericSignature(mirrorMethod, m, module)
- val (throws, others) = splitAnnotations(m.annotations, ThrowsAttr)
+ val (throws, others) = splitAnnotations(m.annotations, definitions.ThrowsClass)
addExceptionsAttribute(mirrorMethod, throws)
addAnnotations(mirrorMethod, others)
addParamAnnotations(mirrorMethod, m.info.params.map(_.annotations))
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
index 7e346090e0..e1cf7a5a7e 100644
--- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
@@ -118,6 +118,7 @@ trait Definitions {
lazy val uncheckedStableClass = getClass("scala.annotation.unchecked.uncheckedStable")
lazy val uncheckedVarianceClass = getClass("scala.annotation.unchecked.uncheckedVariance")
lazy val UncheckedClass = getClass("scala.unchecked")
+ lazy val ThrowsClass = getClass("scala.throws")
lazy val TailrecClass = getClass("scala.annotation.tailrec")
lazy val SwitchClass = getClass("scala.annotation.switch")
lazy val ElidableMethodClass = getClass("scala.annotation.elidable")
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
index 6f21e3fee9..da4e0aaa49 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
@@ -809,6 +809,10 @@ abstract class ClassfileParser {
// TODO 2: also parse RuntimeInvisibleAnnotation / RuntimeInvisibleParamAnnotation,
// i.e. java annotations with RetentionPolicy.CLASS?
+
+ case nme.ExceptionsATTR if (!isScala) =>
+ parseExceptions(attrLen)
+
case _ =>
in.skip(attrLen)
}
@@ -872,6 +876,20 @@ abstract class ClassfileParser {
None // ignore malformed annotations ==> t1135
}
+ /**
+ * Parse the "Exceptions" attribute which denotes the exceptions
+ * thrown by a method.
+ */
+ def parseExceptions(len: Int) {
+ val nClasses = in.nextChar
+ for (n <- 0 until nClasses) {
+ val cls = pool.getClassSymbol(in.nextChar.toInt)
+ sym.addAnnotation(AnnotationInfo(definitions.ThrowsClass.tpe,
+ Literal(Constant(cls.tpe)) :: Nil,
+ Nil))
+ }
+ }
+
/** Parse a sequence of annotations and attach them to the
* current symbol sym.
*/