Skip to content

Commit

Permalink
Merge pull request #2274 from vigdorchik/ticket/si-5699
Browse files Browse the repository at this point in the history
SI-5699 correct java parser for annotation defs.
  • Loading branch information
JamesIry committed Mar 22, 2013
2 parents e5a081c + 50ee635 commit 62dd51a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/compiler/scala/tools/nsc/javac/JavaParsers.scala
Expand Up @@ -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)
})
Expand Down
11 changes: 11 additions & 0 deletions 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
}
}

24 changes: 24 additions & 0 deletions 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)))
}
}

0 comments on commit 62dd51a

Please sign in to comment.