Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SI-5699 correct java parser for annotation defs.

Correct java source parser not to insert a constructor with the type
 of its value method.
  • Loading branch information...
commit 50ee635e3c5914f75be57209f7a145fbb3e23d80 1 parent b7b4f87
Eugene Vigdorchik vigdorchik authored
8 src/compiler/scala/tools/nsc/javac/JavaParsers.scala
View
@@ -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)
})
11 test/files/run/t5699.check
View
@@ -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 test/files/run/t5699.scala
View
@@ -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

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


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

scala-jenkins

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


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

Please sign in to comment.
Something went wrong with that request. Please try again.