diff options
Diffstat (limited to 'src')
4 files changed, 27 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 49237b1af7..e743cff7f6 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -189,6 +189,8 @@ trait Definitions requires SymbolTable { // special attributes var SerializableAttr: Symbol = _ var BeanPropertyAttr: Symbol = _ + def AnnotationDefaultAttr: Symbol = + getClass("scala.tools.nsc.symtab.classfile.AnnotationDefault") def getModule(fullname: Name): Symbol = getModuleOrClass(fullname, true) diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala index deecaeb63c..3f823c5f37 100644 --- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala +++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala @@ -331,6 +331,7 @@ trait StdNames requires SymbolTable { val SignatureATTR = newTermName("Signature"); val ScalaSignatureATTR = newTermName("ScalaSig"); val JavaInterfaceATTR = newTermName("JacoInterface"); + val AnnotationDefaultATTR = newTermName("AnnotationDefault"); val RuntimeAnnotationATTR = newTermName("RuntimeVisibleAnnotations"); val ClassfileAnnotationATTR = newTermName("RuntimeInvisibleAnnotations"); diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 28b620cbc7..6f95151693 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -24,6 +24,8 @@ import scala.collection.immutable.{Map, ListMap} import java.io.IOException +class AnnotationDefault extends Attribute; + abstract class ClassfileParser { def sourcePath : AbstractFile = null @@ -522,6 +524,10 @@ abstract class ClassfileParser { } staticModule.moduleClass.sourceFile = clazz.sourceFile } + case nme.AnnotationDefaultATTR => + sym.attributes = + Triple(definitions.AnnotationDefaultAttr.tpe, List(), List()) :: sym.attributes + in.skip(attrLen) case nme.RuntimeAnnotationATTR => //parseAnnotations(attrLen) in.skip(attrLen) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 3991798aa1..9d488261b4 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1374,9 +1374,14 @@ trait Typers requires Analyzer { null } typed(constr, mode | CONSTmode, AttributeClass.tpe) match { - case Apply(Select(New(tpt), nme.CONSTRUCTOR), args) => + case t @ Apply(Select(New(tpt), nme.CONSTRUCTOR), args) => val constrArgs = args map getConstant - val attrScope = tpt.tpe.decls; + val attrScope = tpt.tpe.decls.filter(s => (s.isMethod && !s.isConstructor)) + val names = new collection.mutable.HashSet[Symbol] + names ++= attrScope.elements + if (args.length == 1) { + names.filter(sym => sym.name != nme.value) + } val nvPairs = elements map { case Assign(ntree @ Ident(name), rhs) => { val sym = attrScope.lookup(name); @@ -1384,12 +1389,23 @@ trait Typers requires Analyzer { error(ntree.pos, "unknown attribute element name: " + name) attrError = true; null + } else if (!names.contains(sym)) { + error(ntree.pos, "duplicate value for element " + name) + attrError = true; + null } else { + names -= sym Pair(sym, getConstant(typed(rhs, mode | CONSTmode, sym.tpe.resultType))) } } } + for (val name <- names) { + if (!name.attributes.contains(Triple(AnnotationDefaultAttr.tpe, List(), List()))) { + error(t.pos, "attribute " + tpt.tpe.symbol.fullNameString + " is missing element " + name.name) + attrError = true; + } + } if (!attrError) { val attrInfo = Triple(tpt.tpe, constrArgs, nvPairs) val attributed = |