summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
diff options
context:
space:
mode:
authorLex Spoon <lex@lexspoon.org>2007-10-10 01:07:30 +0000
committerLex Spoon <lex@lexspoon.org>2007-10-10 01:07:30 +0000
commitab093d847caf4d0d014628df1af5e9b611dd1fea (patch)
tree29bcfa974d0c852f3e407900464e8b7ac5c782a8 /src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
parent515ab49a70bd897a541acbe975a5fe25a24ff61f (diff)
downloadscala-ab093d847caf4d0d014628df1af5e9b611dd1fea.tar.gz
scala-ab093d847caf4d0d014628df1af5e9b611dd1fea.tar.bz2
scala-ab093d847caf4d0d014628df1af5e9b611dd1fea.zip
Annotations with embedded annotations are now
parsed but quietly discarded (trac issue #14)
Diffstat (limited to 'src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala53
1 files changed, 42 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
index 66ef759e79..fe448dcc76 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
@@ -680,21 +680,52 @@ abstract class ClassfileParser {
}
new ArrayConstant(arr.toArray,
appliedType(definitions.ArrayClass.typeConstructor, List(arr(0).tpe)))
+ case ANNOTATION_TAG =>
+ parseAnnotation(index) // skip it
+ new AnnotationConstant()
}
}
+
+ /** Parse and return a single annotation. If it is malformed,
+ * throw an exception. If it contains a nested annotation,
+ * return None.
+ */
+ def parseAnnotation(attrNameIndex: Char): Option[AnnotationInfo] = {
+ val attrType = pool.getType(attrNameIndex)
+ val nargs = in.nextChar
+ val nvpairs = new ListBuffer[(Name,AnnotationArgument)]
+ var nestedAnnot = false // if a nested annotation is seen,
+ // then skip this annotation
+ for (i <- 0 until nargs) {
+ val name = pool.getName(in.nextChar)
+ val argConst = parseTaggedConstant
+ if (argConst.tag == AnnotationTag)
+ nestedAnnot = true
+ else
+ nvpairs += ((name, new AnnotationArgument(argConst)))
+ }
+
+ if (nestedAnnot)
+ None
+ else
+ Some(AnnotationInfo(attrType, List(), nvpairs.toList))
+ }
+
+ /** Parse a sequence of annotations and attach them to the
+ * current symbol sym.
+ */
def parseAnnotations(len: Int) {
val nAttr = in.nextChar
- for (n <- 0 until nAttr) {
- val attrNameIndex = in.nextChar
- val attrType = pool.getType(attrNameIndex)
- val nargs = in.nextChar
- val nvpairs = new ListBuffer[(Name,AnnotationArgument)]
- for (i <- 0 until nargs) {
- val name = pool.getName(in.nextChar)
- nvpairs += ((name, new AnnotationArgument(parseTaggedConstant)))
- }
- sym.attributes = AnnotationInfo(attrType, List(), nvpairs.toList) :: sym.attributes
- }
+ for (n <- 0 until nAttr)
+ parseAnnotation(in.nextChar) match {
+ case None =>
+ if (settings.debug.value)
+ global.inform("dropping annotation on " +
+ sym +
+ " that has a nested annotation")
+ case Some(annot) =>
+ sym.attributes = annot :: sym.attributes
+ }
}
def parseInnerClasses() {