summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
authorSimon Ochsenreither <simon@ochsenreither.de>2014-02-03 21:44:59 +0100
committerSimon Ochsenreither <simon@ochsenreither.de>2014-10-07 20:25:01 +0200
commitc14e0532fcd6d68c43a3c974efec9d15b6e4b217 (patch)
tree39d214f792687f708fa390cf6e6432b70a6625da /test/files/run
parent0940f19dc6809ee7622dda1b76121af628d5b435 (diff)
downloadscala-c14e0532fcd6d68c43a3c974efec9d15b6e4b217.tar.gz
scala-c14e0532fcd6d68c43a3c974efec9d15b6e4b217.tar.bz2
scala-c14e0532fcd6d68c43a3c974efec9d15b6e4b217.zip
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.
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/t4788-separate-compilation.check5
-rw-r--r--test/files/run/t4788-separate-compilation/CAnnotation_1.java5
-rw-r--r--test/files/run/t4788-separate-compilation/C_1.scala2
-rw-r--r--test/files/run/t4788-separate-compilation/D_1.scala5
-rw-r--r--test/files/run/t4788-separate-compilation/RAnnotation_1.java5
-rw-r--r--test/files/run/t4788-separate-compilation/R_1.scala2
-rw-r--r--test/files/run/t4788-separate-compilation/SAnnotation_1.java5
-rw-r--r--test/files/run/t4788-separate-compilation/S_1.scala2
-rw-r--r--test/files/run/t4788-separate-compilation/Test_2.scala35
-rw-r--r--test/files/run/t4788.check5
-rw-r--r--test/files/run/t4788/C.scala2
-rw-r--r--test/files/run/t4788/CAnnotation.java5
-rw-r--r--test/files/run/t4788/D.scala5
-rw-r--r--test/files/run/t4788/R.scala2
-rw-r--r--test/files/run/t4788/RAnnotation.java5
-rw-r--r--test/files/run/t4788/S.scala2
-rw-r--r--test/files/run/t4788/SAnnotation.java5
-rw-r--r--test/files/run/t4788/Test.scala35
18 files changed, 132 insertions, 0 deletions
diff --git a/test/files/run/t4788-separate-compilation.check b/test/files/run/t4788-separate-compilation.check
new file mode 100644
index 0000000000..172ad90102
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation.check
@@ -0,0 +1,5 @@
+Some(@Ljava/lang/Deprecated;())
+None
+None
+Some(@LCAnnotation;() // invisible)
+Some(@LRAnnotation;())
diff --git a/test/files/run/t4788-separate-compilation/CAnnotation_1.java b/test/files/run/t4788-separate-compilation/CAnnotation_1.java
new file mode 100644
index 0000000000..7120218d62
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/CAnnotation_1.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-separate-compilation/C_1.scala b/test/files/run/t4788-separate-compilation/C_1.scala
new file mode 100644
index 0000000000..aba9b595e4
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/C_1.scala
@@ -0,0 +1,2 @@
+@CAnnotation
+class C
diff --git a/test/files/run/t4788-separate-compilation/D_1.scala b/test/files/run/t4788-separate-compilation/D_1.scala
new file mode 100644
index 0000000000..c2479fba86
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/D_1.scala
@@ -0,0 +1,5 @@
+@Deprecated
+class DJava
+
+@deprecated("", "")
+class DScala
diff --git a/test/files/run/t4788-separate-compilation/RAnnotation_1.java b/test/files/run/t4788-separate-compilation/RAnnotation_1.java
new file mode 100644
index 0000000000..f24cf66f7b
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/RAnnotation_1.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-separate-compilation/R_1.scala b/test/files/run/t4788-separate-compilation/R_1.scala
new file mode 100644
index 0000000000..ab0cd065d9
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/R_1.scala
@@ -0,0 +1,2 @@
+@RAnnotation
+class R
diff --git a/test/files/run/t4788-separate-compilation/SAnnotation_1.java b/test/files/run/t4788-separate-compilation/SAnnotation_1.java
new file mode 100644
index 0000000000..471f27d82a
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/SAnnotation_1.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-separate-compilation/S_1.scala b/test/files/run/t4788-separate-compilation/S_1.scala
new file mode 100644
index 0000000000..f8756d9bc8
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/S_1.scala
@@ -0,0 +1,2 @@
+@SAnnotation
+class S
diff --git a/test/files/run/t4788-separate-compilation/Test_2.scala b/test/files/run/t4788-separate-compilation/Test_2.scala
new file mode 100644
index 0000000000..cbbb5ff386
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/Test_2.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"))
+ }
+}
diff --git a/test/files/run/t4788.check b/test/files/run/t4788.check
new file mode 100644
index 0000000000..172ad90102
--- /dev/null
+++ b/test/files/run/t4788.check
@@ -0,0 +1,5 @@
+Some(@Ljava/lang/Deprecated;())
+None
+None
+Some(@LCAnnotation;() // invisible)
+Some(@LRAnnotation;())
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"))
+ }
+}