diff options
author | Eugene Vigdorchik <eugene.vigdorchik@gmail.com> | 2013-03-18 16:34:15 +0400 |
---|---|---|
committer | Eugene Vigdorchik <eugene.vigdorchik@gmail.com> | 2013-03-19 14:04:43 +0400 |
commit | 50ee635e3c5914f75be57209f7a145fbb3e23d80 (patch) | |
tree | 595102d6ccc89304272afa2e1adb07dcd9b46dc8 | |
parent | b7b4f877326acd6a8a24ff60fa1638cc18143c45 (diff) | |
download | scala-50ee635e3c5914f75be57209f7a145fbb3e23d80.tar.gz scala-50ee635e3c5914f75be57209f7a145fbb3e23d80.tar.bz2 scala-50ee635e3c5914f75be57209f7a145fbb3e23d80.zip |
SI-5699 correct java parser for annotation defs.
Correct java source parser not to insert a constructor with the type
of its value method.
-rw-r--r-- | src/compiler/scala/tools/nsc/javac/JavaParsers.scala | 8 | ||||
-rwxr-xr-x | test/files/run/t5699.check | 11 | ||||
-rwxr-xr-x | test/files/run/t5699.scala | 24 |
3 files changed, 36 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index 43a8402fc7..8aa9b81a72 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -800,13 +800,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { val pos = in.currentPos val name = identForType() val (statics, body) = typeBody(AT, name) - def getValueMethodType(tree: Tree) = tree match { - case DefDef(_, nme.value, _, _, tpt, _) => Some(tpt.duplicate) - case _ => None - } - var templ = makeTemplate(annotationParents, body) - for (stat <- templ.body; tpt <- getValueMethodType(stat)) - templ = makeTemplate(annotationParents, makeConstructor(List(tpt)) :: templ.body) + val templ = makeTemplate(annotationParents, body) addCompanionObject(statics, atPos(pos) { ClassDef(mods, name, List(), templ) }) diff --git a/test/files/run/t5699.check b/test/files/run/t5699.check new file mode 100755 index 0000000000..df19644ae6 --- /dev/null +++ b/test/files/run/t5699.check @@ -0,0 +1,11 @@ +[[syntax trees at end of parser]] // annodef.java +package <empty> { + object MyAnnotation extends { + def <init>() = _ + }; + class MyAnnotation extends scala.annotation.Annotation with _root_.java.lang.annotation.Annotation with scala.annotation.ClassfileAnnotation { + def <init>() = _; + def value(): String + } +} + diff --git a/test/files/run/t5699.scala b/test/files/run/t5699.scala new file mode 100755 index 0000000000..5cef67e3b1 --- /dev/null +++ b/test/files/run/t5699.scala @@ -0,0 +1,24 @@ +import scala.tools.partest.DirectTest +import scala.tools.nsc.util.BatchSourceFile + +object Test extends DirectTest { + // Java code + override def code = """ + |public @interface MyAnnotation { String value(); } + """.stripMargin + + override def extraSettings: String = "-usejavacp -Ystop-after:typer -Xprint:parser" + + override def show(): Unit = { + // redirect err to out, for logging + val prevErr = System.err + System.setErr(System.out) + compile() + System.setErr(prevErr) + } + + override def newSources(sourceCodes: String*) = { + assert(sourceCodes.size == 1) + List(new BatchSourceFile("annodef.java", sourceCodes(0))) + } +} |