Skip to content

Commit

Permalink
SI-5699 correct java parser for annotation defs.
Browse files Browse the repository at this point in the history
Correct java source parser not to insert a constructor with the type
 of its value method.
  • Loading branch information
vigdorchik committed Mar 19, 2013
1 parent b7b4f87 commit 50ee635
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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -800,13 +800,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
val pos = in.currentPos val pos = in.currentPos
val name = identForType() val name = identForType()
val (statics, body) = typeBody(AT, name) val (statics, body) = typeBody(AT, name)
def getValueMethodType(tree: Tree) = tree match { val templ = makeTemplate(annotationParents, body)
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)
addCompanionObject(statics, atPos(pos) { addCompanionObject(statics, atPos(pos) {
ClassDef(mods, name, List(), templ) ClassDef(mods, name, List(), templ)
}) })
Expand Down
11 changes: 11 additions & 0 deletions test/files/run/t5699.check
Original file line number Original file line Diff line number Diff line change
@@ -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
Original file line number Original file line Diff line number Diff line change
@@ -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)))
}
}

2 comments on commit 50ee635

@scala-jenkins
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Job pr-rangepos-per-commit failed for 50ee635 (results):


Took 8 s.
to rebuild, comment "PLS REBUILD/pr-rangepos-per-commit@50ee635e3c5914f75be57209f7a145fbb3e23d80" on PR 2274

@scala-jenkins
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Job pr-checkin-per-commit failed for 50ee635 (results):


Took 35 s.
to rebuild, comment "PLS REBUILD/pr-checkin-per-commit@50ee635e3c5914f75be57209f7a145fbb3e23d80" on PR 2274

Please sign in to comment.