Permalink
Browse files

Added scala.throws(java.lang.Class) attribute t...

Added scala.throws(java.lang.Class) attribute to specify the checked
exceptions thrown by a method
  • Loading branch information...
1 parent 16b00da commit f746ce36d86a08c8456f5fae04459addcdd2c62d mihaylov committed May 19, 2006
@@ -68,6 +68,7 @@ abstract class GenJVM extends SubComponent {
val TransientAtt = definitions.getClass("scala.transient").tpe;
val VolatileAttr = definitions.getClass("scala.volatile").tpe;
val RemoteAttr = definitions.getClass("scala.remote").tpe;
+ val ThrowsAttr = definitions.getClass("scala.throws").tpe
val CloneableClass = if (forCLDC) null else definitions.getClass("java.lang.Cloneable");
val RemoteInterface = if (forCLDC) null else definitions.getClass("java.rmi.Remote");
@@ -175,6 +176,34 @@ abstract class GenJVM extends SubComponent {
emitClass(jclass, c.symbol)
}
+ def addExceptionsAttribute(jm: JMethod, throws: List[AttrInfo]): Unit = {
+ if (throws.forall(a => a match {
+ case Pair(ThrowsAttr, _) => false
+ case _ => true
+ })) return;
+
+ val cpool = jm.getConstantPool();
+ val buf: ByteBuffer = ByteBuffer.allocate(512);
+ var nattr = 0;
+
+ // put some radom value; the actual number is determined at the end
+ buf.putShort(0xbaba.toShort)
+
+ for (val Pair(ThrowsAttr, List(exc)) <- throws) {
+ buf.putShort(cpool.addClass(exc.typeValue.toString()).shortValue)
+ nattr = nattr + 1;
+ }
+
+ assert (nattr > 0);
+ val length = buf.position();
+ buf.putShort(0, nattr.toShort)
+ val arr = buf.array().subArray(0, length);
+
+ val attr = jm.getContext().JOtherAttribute(jm.getJClass(), jm,
+ nme.ExceptionsATTR.toString(),
+ arr, length)
+ jm.addAttribute(attr)
+ }
def addAttributes(jmember: JMember, attributes: List[AttrInfo]): Unit = {
if (attributes.isEmpty) return;
@@ -330,6 +359,7 @@ abstract class GenJVM extends SubComponent {
genLocalVariableTable;
}
+ addExceptionsAttribute(jmethod, m.symbol.attributes)
addAttributes(jmethod, m.symbol.attributes)
}
@@ -16,4 +16,4 @@ package scala;
* Attribute for specifying the static SerialVersionUID field
* of a serializable class
*/
-case class SerialVersionUID(uid: Long) extends Attribute {}
+class SerialVersionUID(uid: Long) extends Attribute {}
@@ -0,0 +1,17 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+*/
+
+// $Id$
+
+
+package scala;
+
+/**
+ * Attribute for specifying the exceptions thrown by a method.
+ */
+class throws(clazz: java.lang.Class) extends Attribute;

0 comments on commit f746ce3

Please sign in to comment.