From f1701f704a2485fcc2eb6d5d8b5d0228beddd9b3 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Thu, 31 Jan 2013 20:40:16 +0100 Subject: SI-7008 @throws annotations are now populated in reflect Runtime reflection in JavaMirrors previously forgot to fill in @throws when importing Java reflection artifacts. Now this is fixed. Note that generic exception types used in `throws` specifications will be garbled (i.e. erased), because we don't use `getGenericExceptionTypes` in favor of just `getExceptionTypes` to stay compatible with the behavior of ClassfileParser. That's a bug, but a separate one and should be fixed separately. Also note that this commit updated javac-artifacts.jar, because we need to test how reflection works with javac-produced classfiles. The sources that were used to produce those classfiles can be found in the jar next to the classfiles. --- test/files/run/t7008.check | 9 +++++++++ test/files/run/t7008/Impls_Macros_1.scala | 12 ++++++++++++ test/files/run/t7008/Test_2.scala | 9 +++++++++ 3 files changed, 30 insertions(+) create mode 100644 test/files/run/t7008.check create mode 100644 test/files/run/t7008/Impls_Macros_1.scala create mode 100644 test/files/run/t7008/Test_2.scala (limited to 'test/files/run') diff --git a/test/files/run/t7008.check b/test/files/run/t7008.check new file mode 100644 index 0000000000..ee077f90ff --- /dev/null +++ b/test/files/run/t7008.check @@ -0,0 +1,9 @@ +: List(throws[NullPointerException](classOf[java.lang.NullPointerException])) +bar: List(throws[Exception](classOf[java.lang.Exception])) +baz: List(throws[IllegalStateException](classOf[java.lang.IllegalStateException])) +foo: List(throws[Exception](classOf[java.lang.Exception])) +============= +: List(throws[java.lang.NullPointerException](classOf[java.lang.NullPointerException])) +bar: List(throws[java.lang.Exception](classOf[java.lang.Exception])) +baz: List(throws[java.lang.IllegalStateException](classOf[java.lang.IllegalStateException])) +foo: List(throws[java.lang.Exception](classOf[java.lang.Exception])) diff --git a/test/files/run/t7008/Impls_Macros_1.scala b/test/files/run/t7008/Impls_Macros_1.scala new file mode 100644 index 0000000000..f2eb7425f5 --- /dev/null +++ b/test/files/run/t7008/Impls_Macros_1.scala @@ -0,0 +1,12 @@ +import language.experimental.macros +import scala.reflect.macros.Context + +object Macros { + def impl(c: Context) = { + val decls = c.typeOf[JavaClassWithCheckedExceptions[_]].declarations.toList + val s = decls.sortBy(_.name.toString).map(decl => (s"${decl.name}: ${decl.annotations}")).mkString(scala.compat.Platform.EOL) + c.universe.reify(println(c.literal(s).splice)) + } + + def foo = macro impl +} \ No newline at end of file diff --git a/test/files/run/t7008/Test_2.scala b/test/files/run/t7008/Test_2.scala new file mode 100644 index 0000000000..b67faa327f --- /dev/null +++ b/test/files/run/t7008/Test_2.scala @@ -0,0 +1,9 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + Macros.foo + println("=============") + + val decls = typeOf[JavaClassWithCheckedExceptions[_]].declarations.toList + decls sortBy (_.name.toString) foreach (decl => println(s"${decl.name}: ${decl.annotations}")) +} \ No newline at end of file -- cgit v1.2.3 From adf50a3ac0c6861a77a781abc0814c5d17927175 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Fri, 1 Feb 2013 19:23:00 +0100 Subject: evicts javac-artifacts.jar Apparently, the usual _1, _2, _3... naming scheme also works for java files, which need to be compiled together with partests. This allows us to get rid of javac-artifacts.jar. --- test/files/lib/javac-artifacts.jar.desired.sha1 | 1 - test/files/run/reflection-java-annotations.check | 2 +- test/files/run/reflection-java-annotations.scala | 7 ---- .../JavaAnnottee_1.java | 47 ++++++++++++++++++++++ .../JavaComplexAnnotation_1.java | 34 ++++++++++++++++ .../JavaSimpleAnnotation_1.java | 21 ++++++++++ .../JavaSimpleEnumeration_1.java | 4 ++ .../run/reflection-java-annotations/Test_2.scala | 7 ++++ test/files/run/reflection-java-crtp.scala | 8 ---- .../JavaSimpleEnumeration_1.java | 4 ++ test/files/run/reflection-java-crtp/Main_2.scala | 8 ++++ test/files/run/t6548.check | 2 +- test/files/run/t6548.scala | 12 ------ .../run/t6548/JavaAnnotationWithNestedEnum_1.java | 17 ++++++++ test/files/run/t6548/Test_2.scala | 12 ++++++ test/files/run/t7008/Impls_Macros_1.scala | 12 ------ test/files/run/t7008/Impls_Macros_2.scala | 12 ++++++ .../t7008/JavaClassWithCheckedExceptions_1.java | 7 ++++ test/files/run/t7008/Test_2.scala | 9 ----- test/files/run/t7008/Test_3.scala | 9 +++++ 20 files changed, 184 insertions(+), 51 deletions(-) delete mode 100644 test/files/lib/javac-artifacts.jar.desired.sha1 delete mode 100644 test/files/run/reflection-java-annotations.scala create mode 100644 test/files/run/reflection-java-annotations/JavaAnnottee_1.java create mode 100644 test/files/run/reflection-java-annotations/JavaComplexAnnotation_1.java create mode 100644 test/files/run/reflection-java-annotations/JavaSimpleAnnotation_1.java create mode 100644 test/files/run/reflection-java-annotations/JavaSimpleEnumeration_1.java create mode 100644 test/files/run/reflection-java-annotations/Test_2.scala delete mode 100644 test/files/run/reflection-java-crtp.scala create mode 100644 test/files/run/reflection-java-crtp/JavaSimpleEnumeration_1.java create mode 100644 test/files/run/reflection-java-crtp/Main_2.scala delete mode 100644 test/files/run/t6548.scala create mode 100644 test/files/run/t6548/JavaAnnotationWithNestedEnum_1.java create mode 100644 test/files/run/t6548/Test_2.scala delete mode 100644 test/files/run/t7008/Impls_Macros_1.scala create mode 100644 test/files/run/t7008/Impls_Macros_2.scala create mode 100644 test/files/run/t7008/JavaClassWithCheckedExceptions_1.java delete mode 100644 test/files/run/t7008/Test_2.scala create mode 100644 test/files/run/t7008/Test_3.scala (limited to 'test/files/run') diff --git a/test/files/lib/javac-artifacts.jar.desired.sha1 b/test/files/lib/javac-artifacts.jar.desired.sha1 deleted file mode 100644 index 508141b771..0000000000 --- a/test/files/lib/javac-artifacts.jar.desired.sha1 +++ /dev/null @@ -1 +0,0 @@ -a05ca69ac68fa7006b1b8ed98597046e105b4047 ?javac-artifacts.jar diff --git a/test/files/run/reflection-java-annotations.check b/test/files/run/reflection-java-annotations.check index 53c53cfbcc..2d37fff1f4 100644 --- a/test/files/run/reflection-java-annotations.check +++ b/test/files/run/reflection-java-annotations.check @@ -1 +1 @@ -List(JavaComplexAnnotation(v1 = 1, v10 = "hello", v101 = [101, 101], v102 = [102, 102], v103 = ['g', 'g'], v104 = [104, 104], v105 = [105L, 105L], v106 = [106.0, 106.0], v107 = [107.0, 107.0], v108 = [false, true], v11 = classOf[JavaAnnottee], v110 = ["hello", "world"], v111 = [classOf[JavaSimpleAnnotation], classOf[JavaComplexAnnotation]], v112 = [FOO, BAR], v113 = [JavaSimpleAnnotation(v1 = 21, v10 = "world2", v11 = classOf[JavaComplexAnnotation], v12 = BAR, v2 = 22, v3 = '\027', v4 = 24, v5 = 25L, v6 = 26.0, v7 = 27.0, v8 = false)], v12 = FOO, v13 = JavaSimpleAnnotation(v1 = 11, v10 = "world1", v11 = classOf[JavaSimpleAnnotation], v12 = FOO, v2 = 12, v3 = '\r', v4 = 14, v5 = 15L, v6 = 16.0, v7 = 17.0, v8 = false), v2 = 2, v3 = '\03', v4 = 4, v5 = 5L, v6 = 6.0, v7 = 7.0, v8 = false)) +List(JavaComplexAnnotation_1(v1 = 1, v10 = "hello", v101 = [101, 101], v102 = [102, 102], v103 = ['g', 'g'], v104 = [104, 104], v105 = [105L, 105L], v106 = [106.0, 106.0], v107 = [107.0, 107.0], v108 = [false, true], v11 = classOf[JavaAnnottee_1], v110 = ["hello", "world"], v111 = [classOf[JavaSimpleAnnotation_1], classOf[JavaComplexAnnotation_1]], v112 = [FOO, BAR], v113 = [JavaSimpleAnnotation_1(v1 = 21, v10 = "world2", v11 = classOf[JavaComplexAnnotation_1], v12 = BAR, v2 = 22, v3 = '\027', v4 = 24, v5 = 25L, v6 = 26.0, v7 = 27.0, v8 = false)], v12 = FOO, v13 = JavaSimpleAnnotation_1(v1 = 11, v10 = "world1", v11 = classOf[JavaSimpleAnnotation_1], v12 = FOO, v2 = 12, v3 = '\r', v4 = 14, v5 = 15L, v6 = 16.0, v7 = 17.0, v8 = false), v2 = 2, v3 = '\03', v4 = 4, v5 = 5L, v6 = 6.0, v7 = 7.0, v8 = false)) diff --git a/test/files/run/reflection-java-annotations.scala b/test/files/run/reflection-java-annotations.scala deleted file mode 100644 index 2e3fed48ce..0000000000 --- a/test/files/run/reflection-java-annotations.scala +++ /dev/null @@ -1,7 +0,0 @@ -object Test extends App { - import scala.reflect.runtime.universe._ - val sym = typeOf[JavaAnnottee].typeSymbol - sym.typeSignature - sym.annotations foreach (_.javaArgs) - println(sym.annotations) -} \ No newline at end of file diff --git a/test/files/run/reflection-java-annotations/JavaAnnottee_1.java b/test/files/run/reflection-java-annotations/JavaAnnottee_1.java new file mode 100644 index 0000000000..b241f5d25e --- /dev/null +++ b/test/files/run/reflection-java-annotations/JavaAnnottee_1.java @@ -0,0 +1,47 @@ +@JavaComplexAnnotation_1( + v1 = (byte)1, + v2 = (short)2, + v3 = (char)3, + v4 = (int)4, + v5 = (long)5, + v6 = (float)6, + v7 = (double)7, + v10 = "hello", + v11 = JavaAnnottee_1.class, + v12 = JavaSimpleEnumeration_1.FOO, + v13 = @JavaSimpleAnnotation_1( + v1 = (byte)11, + v2 = (short)12, + v3 = (char)13, + v4 = (int)14, + v5 = (long)15, + v6 = (float)16, + v7 = (double)17, + v10 = "world1", + v11 = JavaSimpleAnnotation_1.class, + v12 = JavaSimpleEnumeration_1.FOO + ), + v101 = {(byte)101, (byte)101}, + v102 = {(short)102, (short)102}, + v103 = {(char)103, (char)103}, + v104 = {(int)104, (int)104}, + v105 = {(long)105, (long)105}, + v106 = {(float)106, (float)106}, + v107 = {(double)107, (double)107}, + v108 = {false, true}, + v110 = {"hello", "world"}, + v111 = {JavaSimpleAnnotation_1.class, JavaComplexAnnotation_1.class}, + v112 = {JavaSimpleEnumeration_1.FOO, JavaSimpleEnumeration_1.BAR}, + v113 = {@JavaSimpleAnnotation_1( + v1 = (byte)21, + v2 = (short)22, + v3 = (char)23, + v4 = (int)24, + v5 = (long)25, + v6 = (float)26, + v7 = (double)27, + v10 = "world2", + v11 = JavaComplexAnnotation_1.class, + v12 = JavaSimpleEnumeration_1.BAR + )}) +public class JavaAnnottee_1 {} \ No newline at end of file diff --git a/test/files/run/reflection-java-annotations/JavaComplexAnnotation_1.java b/test/files/run/reflection-java-annotations/JavaComplexAnnotation_1.java new file mode 100644 index 0000000000..645eeb9399 --- /dev/null +++ b/test/files/run/reflection-java-annotations/JavaComplexAnnotation_1.java @@ -0,0 +1,34 @@ +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) +public @interface JavaComplexAnnotation_1 { + byte v1(); + short v2(); + char v3(); + int v4(); + long v5(); + float v6(); + double v7(); + boolean v8() default false; + // void v9(); + String v10(); + Class v11(); + JavaSimpleEnumeration_1 v12(); + JavaSimpleAnnotation_1 v13(); + byte[] v101(); + short[] v102(); + char[] v103(); + int[] v104(); + long[] v105(); + float[] v106(); + double[] v107(); + boolean[] v108(); + String[] v110(); + Class[] v111(); + JavaSimpleEnumeration_1[] v112(); + JavaSimpleAnnotation_1[] v113(); +} \ No newline at end of file diff --git a/test/files/run/reflection-java-annotations/JavaSimpleAnnotation_1.java b/test/files/run/reflection-java-annotations/JavaSimpleAnnotation_1.java new file mode 100644 index 0000000000..c0f92fad2c --- /dev/null +++ b/test/files/run/reflection-java-annotations/JavaSimpleAnnotation_1.java @@ -0,0 +1,21 @@ +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) +public @interface JavaSimpleAnnotation_1 { + byte v1(); + short v2(); + char v3(); + int v4(); + long v5(); + float v6(); + double v7(); + boolean v8() default false; + // void v9(); + String v10(); + Class v11(); + JavaSimpleEnumeration_1 v12(); +} \ No newline at end of file diff --git a/test/files/run/reflection-java-annotations/JavaSimpleEnumeration_1.java b/test/files/run/reflection-java-annotations/JavaSimpleEnumeration_1.java new file mode 100644 index 0000000000..39246141cc --- /dev/null +++ b/test/files/run/reflection-java-annotations/JavaSimpleEnumeration_1.java @@ -0,0 +1,4 @@ +enum JavaSimpleEnumeration_1 { + FOO, + BAR +} \ No newline at end of file diff --git a/test/files/run/reflection-java-annotations/Test_2.scala b/test/files/run/reflection-java-annotations/Test_2.scala new file mode 100644 index 0000000000..d2c3157071 --- /dev/null +++ b/test/files/run/reflection-java-annotations/Test_2.scala @@ -0,0 +1,7 @@ +object Test extends App { + import scala.reflect.runtime.universe._ + val sym = typeOf[JavaAnnottee_1].typeSymbol + sym.typeSignature + sym.annotations foreach (_.javaArgs) + println(sym.annotations) +} \ No newline at end of file diff --git a/test/files/run/reflection-java-crtp.scala b/test/files/run/reflection-java-crtp.scala deleted file mode 100644 index 260d3540dc..0000000000 --- a/test/files/run/reflection-java-crtp.scala +++ /dev/null @@ -1,8 +0,0 @@ -object Test extends App { - import scala.reflect.runtime.universe._ - val enum = typeOf[JavaSimpleEnumeration].baseClasses(1).asClass - // make sure that the E's in Enum> are represented by the same symbol - val e1 = enum.typeParams(0).asType - val TypeBounds(_, TypeRef(_, _, List(TypeRef(_, e2: TypeSymbol, _)))) = e1.typeSignature - println(e1, e2, e1 eq e2) -} \ No newline at end of file diff --git a/test/files/run/reflection-java-crtp/JavaSimpleEnumeration_1.java b/test/files/run/reflection-java-crtp/JavaSimpleEnumeration_1.java new file mode 100644 index 0000000000..39246141cc --- /dev/null +++ b/test/files/run/reflection-java-crtp/JavaSimpleEnumeration_1.java @@ -0,0 +1,4 @@ +enum JavaSimpleEnumeration_1 { + FOO, + BAR +} \ No newline at end of file diff --git a/test/files/run/reflection-java-crtp/Main_2.scala b/test/files/run/reflection-java-crtp/Main_2.scala new file mode 100644 index 0000000000..fb5668f323 --- /dev/null +++ b/test/files/run/reflection-java-crtp/Main_2.scala @@ -0,0 +1,8 @@ +object Test extends App { + import scala.reflect.runtime.universe._ + val enum = typeOf[JavaSimpleEnumeration_1].baseClasses(1).asClass + // make sure that the E's in Enum> are represented by the same symbol + val e1 = enum.typeParams(0).asType + val TypeBounds(_, TypeRef(_, _, List(TypeRef(_, e2: TypeSymbol, _)))) = e1.typeSignature + println(e1, e2, e1 eq e2) +} \ No newline at end of file diff --git a/test/files/run/t6548.check b/test/files/run/t6548.check index e82cae110a..5dfcb12e02 100644 --- a/test/files/run/t6548.check +++ b/test/files/run/t6548.check @@ -1,2 +1,2 @@ false -List(JavaAnnotationWithNestedEnum(value = VALUE)) +List(JavaAnnotationWithNestedEnum_1(value = VALUE)) diff --git a/test/files/run/t6548.scala b/test/files/run/t6548.scala deleted file mode 100644 index be3eb5b932..0000000000 --- a/test/files/run/t6548.scala +++ /dev/null @@ -1,12 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.reflect.runtime.{currentMirror => cm} - -class Bean { - @JavaAnnotationWithNestedEnum(JavaAnnotationWithNestedEnum.Value.VALUE) - def value = 1 -} - -object Test extends App { - println(cm.staticClass("Bean").isCaseClass) - println(typeOf[Bean].declaration(newTermName("value")).annotations) -} diff --git a/test/files/run/t6548/JavaAnnotationWithNestedEnum_1.java b/test/files/run/t6548/JavaAnnotationWithNestedEnum_1.java new file mode 100644 index 0000000000..32004de537 --- /dev/null +++ b/test/files/run/t6548/JavaAnnotationWithNestedEnum_1.java @@ -0,0 +1,17 @@ +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, + ElementType.TYPE, ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface JavaAnnotationWithNestedEnum_1 +{ + public Value value() default Value.VALUE; + + public enum Value + { + VALUE; + } +} \ No newline at end of file diff --git a/test/files/run/t6548/Test_2.scala b/test/files/run/t6548/Test_2.scala new file mode 100644 index 0000000000..6e4f6ba92a --- /dev/null +++ b/test/files/run/t6548/Test_2.scala @@ -0,0 +1,12 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} + +class Bean { + @JavaAnnotationWithNestedEnum_1(JavaAnnotationWithNestedEnum_1.Value.VALUE) + def value = 1 +} + +object Test extends App { + println(cm.staticClass("Bean").isCaseClass) + println(typeOf[Bean].declaration(newTermName("value")).annotations) +} diff --git a/test/files/run/t7008/Impls_Macros_1.scala b/test/files/run/t7008/Impls_Macros_1.scala deleted file mode 100644 index f2eb7425f5..0000000000 --- a/test/files/run/t7008/Impls_Macros_1.scala +++ /dev/null @@ -1,12 +0,0 @@ -import language.experimental.macros -import scala.reflect.macros.Context - -object Macros { - def impl(c: Context) = { - val decls = c.typeOf[JavaClassWithCheckedExceptions[_]].declarations.toList - val s = decls.sortBy(_.name.toString).map(decl => (s"${decl.name}: ${decl.annotations}")).mkString(scala.compat.Platform.EOL) - c.universe.reify(println(c.literal(s).splice)) - } - - def foo = macro impl -} \ No newline at end of file diff --git a/test/files/run/t7008/Impls_Macros_2.scala b/test/files/run/t7008/Impls_Macros_2.scala new file mode 100644 index 0000000000..7a17314085 --- /dev/null +++ b/test/files/run/t7008/Impls_Macros_2.scala @@ -0,0 +1,12 @@ +import language.experimental.macros +import scala.reflect.macros.Context + +object Macros { + def impl(c: Context) = { + val decls = c.typeOf[JavaClassWithCheckedExceptions_1[_]].declarations.toList + val s = decls.sortBy(_.name.toString).map(decl => (s"${decl.name}: ${decl.annotations}")).mkString(scala.compat.Platform.EOL) + c.universe.reify(println(c.literal(s).splice)) + } + + def foo = macro impl +} \ No newline at end of file diff --git a/test/files/run/t7008/JavaClassWithCheckedExceptions_1.java b/test/files/run/t7008/JavaClassWithCheckedExceptions_1.java new file mode 100644 index 0000000000..dda2128302 --- /dev/null +++ b/test/files/run/t7008/JavaClassWithCheckedExceptions_1.java @@ -0,0 +1,7 @@ +class JavaClassWithCheckedExceptions_1 { + public JavaClassWithCheckedExceptions_1() throws NullPointerException {} + + public void bar() throws E1 {} + public void baz(int x) throws IllegalStateException {} + public void foo() throws E2 {} +} \ No newline at end of file diff --git a/test/files/run/t7008/Test_2.scala b/test/files/run/t7008/Test_2.scala deleted file mode 100644 index b67faa327f..0000000000 --- a/test/files/run/t7008/Test_2.scala +++ /dev/null @@ -1,9 +0,0 @@ -import scala.reflect.runtime.universe._ - -object Test extends App { - Macros.foo - println("=============") - - val decls = typeOf[JavaClassWithCheckedExceptions[_]].declarations.toList - decls sortBy (_.name.toString) foreach (decl => println(s"${decl.name}: ${decl.annotations}")) -} \ No newline at end of file diff --git a/test/files/run/t7008/Test_3.scala b/test/files/run/t7008/Test_3.scala new file mode 100644 index 0000000000..b2961a829e --- /dev/null +++ b/test/files/run/t7008/Test_3.scala @@ -0,0 +1,9 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + Macros.foo + println("=============") + + val decls = typeOf[JavaClassWithCheckedExceptions_1[_]].declarations.toList + decls sortBy (_.name.toString) foreach (decl => println(s"${decl.name}: ${decl.annotations}")) +} \ No newline at end of file -- cgit v1.2.3 From 02dd4c974f33d137ea353a72e27efb70928fb378 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 4 Feb 2013 22:23:54 +0100 Subject: reflecting @throws defined in Scala code As per Jason's comment: How are Scala classes containing @throws annots treated? I can't figure out whether we pickle the annotation in addition to adding the exception to the signature. If we do, might we end up with duplicate annotations in runtime reflection? This warrants a test. See the context of the discussion here: https://github.com/scala/scala/pull/2040/files#r2874769. No, we won't end up with duplicates, because classes defined in Scala are loaded in a different completer. But I'll add a test - you can never have too many of those. --- test/files/run/t7008-scala-defined.check | 7 +++++++ test/files/run/t7008-scala-defined/Impls_Macros_2.scala | 12 ++++++++++++ .../ScalaClassWithCheckedExceptions_1.scala | 6 ++++++ test/files/run/t7008-scala-defined/Test_3.scala | 9 +++++++++ 4 files changed, 34 insertions(+) create mode 100644 test/files/run/t7008-scala-defined.check create mode 100644 test/files/run/t7008-scala-defined/Impls_Macros_2.scala create mode 100644 test/files/run/t7008-scala-defined/ScalaClassWithCheckedExceptions_1.scala create mode 100644 test/files/run/t7008-scala-defined/Test_3.scala (limited to 'test/files/run') diff --git a/test/files/run/t7008-scala-defined.check b/test/files/run/t7008-scala-defined.check new file mode 100644 index 0000000000..84ed62619e --- /dev/null +++ b/test/files/run/t7008-scala-defined.check @@ -0,0 +1,7 @@ +: List(throws[NullPointerException]("")) +bar: List(throws[E1]("")) +baz: List(throws[IllegalStateException]("")) +============= +: List(throws[NullPointerException]("")) +bar: List(throws[E1]("")) +baz: List(throws[IllegalStateException]("")) diff --git a/test/files/run/t7008-scala-defined/Impls_Macros_2.scala b/test/files/run/t7008-scala-defined/Impls_Macros_2.scala new file mode 100644 index 0000000000..94fd99018e --- /dev/null +++ b/test/files/run/t7008-scala-defined/Impls_Macros_2.scala @@ -0,0 +1,12 @@ +import language.experimental.macros +import scala.reflect.macros.Context + +object Macros { + def impl(c: Context) = { + val decls = c.typeOf[ScalaClassWithCheckedExceptions_1[_]].declarations.toList + val s = decls.sortBy(_.name.toString).map(decl => (s"${decl.name}: ${decl.annotations}")).mkString(scala.compat.Platform.EOL) + c.universe.reify(println(c.literal(s).splice)) + } + + def foo = macro impl +} \ No newline at end of file diff --git a/test/files/run/t7008-scala-defined/ScalaClassWithCheckedExceptions_1.scala b/test/files/run/t7008-scala-defined/ScalaClassWithCheckedExceptions_1.scala new file mode 100644 index 0000000000..7783c873ec --- /dev/null +++ b/test/files/run/t7008-scala-defined/ScalaClassWithCheckedExceptions_1.scala @@ -0,0 +1,6 @@ +class ScalaClassWithCheckedExceptions_1[E1 <: Exception] @throws[NullPointerException]("") () { + @throws[E1]("") def bar() {} + @throws[IllegalStateException]("") def baz(x: Int) {} + // FIXME: SI-7066 + // @throws[E2]("") def foo[E2 <: Exception] {} +} \ No newline at end of file diff --git a/test/files/run/t7008-scala-defined/Test_3.scala b/test/files/run/t7008-scala-defined/Test_3.scala new file mode 100644 index 0000000000..03bb79d311 --- /dev/null +++ b/test/files/run/t7008-scala-defined/Test_3.scala @@ -0,0 +1,9 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + Macros.foo + println("=============") + + val decls = typeOf[ScalaClassWithCheckedExceptions_1[_]].declarations.toList + decls sortBy (_.name.toString) foreach (decl => println(s"${decl.name}: ${decl.annotations}")) +} \ No newline at end of file -- cgit v1.2.3