From c14e0532fcd6d68c43a3c974efec9d15b6e4b217 Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Mon, 3 Feb 2014 21:44:59 +0100 Subject: SI-4788/SI-5948 Respect RetentionPolicy of Java annotations Note that I removed the check to ignore @deprecated: - @deprecated extends StaticAnnotation, so they aren't supposed to show up in the RuntimeInvisibleAnnotation attribute anyway, and the earlier check for "extends ClassfileAnnotationClass" makes this check superflous anyway. - Otherwise, if @deprecated was extending ClassfileAnnotationClass it would seem inconsistent that we don't emit @deprecated, but would do so for @deprecatedOverriding, @deprecatedInheritance, etc. Anyway, due to ClassfileAnnotation not working in Scala, and the additional check which only allows Java-defined annotations, this is pretty pointless from every perspective. --- test/files/run/t4788/C.scala | 2 ++ test/files/run/t4788/CAnnotation.java | 5 +++++ test/files/run/t4788/D.scala | 5 +++++ test/files/run/t4788/R.scala | 2 ++ test/files/run/t4788/RAnnotation.java | 5 +++++ test/files/run/t4788/S.scala | 2 ++ test/files/run/t4788/SAnnotation.java | 5 +++++ test/files/run/t4788/Test.scala | 35 +++++++++++++++++++++++++++++++++++ 8 files changed, 61 insertions(+) create mode 100644 test/files/run/t4788/C.scala create mode 100644 test/files/run/t4788/CAnnotation.java create mode 100644 test/files/run/t4788/D.scala create mode 100644 test/files/run/t4788/R.scala create mode 100644 test/files/run/t4788/RAnnotation.java create mode 100644 test/files/run/t4788/S.scala create mode 100644 test/files/run/t4788/SAnnotation.java create mode 100644 test/files/run/t4788/Test.scala (limited to 'test/files/run/t4788') diff --git a/test/files/run/t4788/C.scala b/test/files/run/t4788/C.scala new file mode 100644 index 0000000000..aba9b595e4 --- /dev/null +++ b/test/files/run/t4788/C.scala @@ -0,0 +1,2 @@ +@CAnnotation +class C diff --git a/test/files/run/t4788/CAnnotation.java b/test/files/run/t4788/CAnnotation.java new file mode 100644 index 0000000000..7120218d62 --- /dev/null +++ b/test/files/run/t4788/CAnnotation.java @@ -0,0 +1,5 @@ +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.CLASS; + +@Retention(value=CLASS) +@interface CAnnotation {} diff --git a/test/files/run/t4788/D.scala b/test/files/run/t4788/D.scala new file mode 100644 index 0000000000..c2479fba86 --- /dev/null +++ b/test/files/run/t4788/D.scala @@ -0,0 +1,5 @@ +@Deprecated +class DJava + +@deprecated("", "") +class DScala diff --git a/test/files/run/t4788/R.scala b/test/files/run/t4788/R.scala new file mode 100644 index 0000000000..ab0cd065d9 --- /dev/null +++ b/test/files/run/t4788/R.scala @@ -0,0 +1,2 @@ +@RAnnotation +class R diff --git a/test/files/run/t4788/RAnnotation.java b/test/files/run/t4788/RAnnotation.java new file mode 100644 index 0000000000..f24cf66f7b --- /dev/null +++ b/test/files/run/t4788/RAnnotation.java @@ -0,0 +1,5 @@ +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention(value=RUNTIME) +@interface RAnnotation {} diff --git a/test/files/run/t4788/S.scala b/test/files/run/t4788/S.scala new file mode 100644 index 0000000000..f8756d9bc8 --- /dev/null +++ b/test/files/run/t4788/S.scala @@ -0,0 +1,2 @@ +@SAnnotation +class S diff --git a/test/files/run/t4788/SAnnotation.java b/test/files/run/t4788/SAnnotation.java new file mode 100644 index 0000000000..471f27d82a --- /dev/null +++ b/test/files/run/t4788/SAnnotation.java @@ -0,0 +1,5 @@ +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.SOURCE; + +@Retention(value=SOURCE) +@interface SAnnotation {} diff --git a/test/files/run/t4788/Test.scala b/test/files/run/t4788/Test.scala new file mode 100644 index 0000000000..cbbb5ff386 --- /dev/null +++ b/test/files/run/t4788/Test.scala @@ -0,0 +1,35 @@ +import java.io.PrintWriter; + +import scala.tools.partest.BytecodeTest +import scala.tools.asm.util._ +import scala.tools.nsc.util.stringFromWriter + +object Test extends BytecodeTest { + def annotationsForClass(className: String): Option[String] = { + val classNode = loadClassNode(className, skipDebugInfo = false) + val textifier = new Textifier + classNode.accept(new TraceClassVisitor(null, textifier, null)) + + val classString = stringFromWriter(w => textifier.print(w)) + classString + .split('\n') + .filterNot(_.contains("@Lscala/reflect/ScalaSignature")) + .find(_.contains("@L")) + .map(_.trim) + } + + def show { + // It seems like @java.lang.Deprecated shows up in both the + // Deprecated attribute and RuntimeVisibleAnnotation attribute, + // while @scala.deprecated only shows up in the Deprecated attribute. + // The check file just documents status quo, not sure if Scala + // should brought in line with Java or not... + // See the commit message and SI-8883 for more info. + println(annotationsForClass("DJava")) + println(annotationsForClass("DScala")) + + println(annotationsForClass("S")) + println(annotationsForClass("C")) + println(annotationsForClass("R")) + } +} -- cgit v1.2.3