diff options
author | michelou <michelou@epfl.ch> | 2006-06-20 12:42:03 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2006-06-20 12:42:03 +0000 |
commit | e10bdf2f822aa2c5a1faa9ccca5e7287809e3e33 (patch) | |
tree | 0045508263fb6fd7b03c2a470ee65c99b16e4c15 /test/files/run/attributes.scala | |
parent | 82492924248408873a734a200ae2b4b1bc71ec75 (diff) | |
download | scala-e10bdf2f822aa2c5a1faa9ccca5e7287809e3e33.tar.gz scala-e10bdf2f822aa2c5a1faa9ccca5e7287809e3e33.tar.bz2 scala-e10bdf2f822aa2c5a1faa9ccca5e7287809e3e33.zip |
initial version
Diffstat (limited to 'test/files/run/attributes.scala')
-rw-r--r-- | test/files/run/attributes.scala | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/test/files/run/attributes.scala b/test/files/run/attributes.scala new file mode 100644 index 0000000000..987f139f90 --- /dev/null +++ b/test/files/run/attributes.scala @@ -0,0 +1,85 @@ +object Test1 { + class Foo { + [remote] + def foo: Unit = () + } + def run: Unit = { + val method = classOf[Foo].getMethod("foo", Array()) + method.getExceptionTypes foreach Console.println + } +} + +object Test2 { + import java.io._ + class Reader(fname: String) { + private val in = new BufferedReader(new FileReader(fname)) + [throws(classOf[IOException])] + def read() = in.read() + } + def run: Unit = { + val method = classOf[Reader].getMethod("read", Array()) + method.getExceptionTypes foreach Console.println + } +} + +/* Java: +public class Main { + @Deprecated + public void foo() {} + public static void main(String[] args) throws Exception { + Method method = Class.forName("test.Main").getMethod("foo", new Class[]{}); + Annotation annotation = method.getAnnotation(Deprecated.class); + System.out.println(annotation); // @java.lang.Deprecated() + } +} +*/ +object Test3 { + class Foo { + [Deprecated] + def foo: Unit = () + } + def run: Unit = { + val method = classOf[Foo].getMethod("foo", Array()) + val annotation = method.getAnnotation(classOf[Deprecated]) + Console.println(annotation) + } +} + +/* Java: +@Retention(value=RetentionPolicy.RUNTIME) +@interface Source { + public String url(); + public String mail(); +} +@Source(url="http://scala.epfl.ch", mail="scala@lists.epfl.ch") +class Foo {} +public class Main { + public static void main(String[] args) throws Exception { + Class clazz = Class.forName("test.Foo"); + Annotation[] annotations = clazz.getAnnotations(); + for (int i = 0; i < annotations.length; i++) + System.out.println(annotations[i]); + // @test.Main$Source(url=http://scala.epfl.ch, mail=scala@lists.epfl.ch) + } +} +*/ +object Test4 { + import java.lang.annotation._ + [Retention(RetentionPolicy.RUNTIME)] + class Source(url: String, mail: String) extends Attribute + [Source("http://scala.epfl.ch", "scala@lists.epfl.ch")] + class Foo + def run: Unit = { + val clazz = classOf[Foo] + clazz.getAnnotations foreach Console.println + } +} + +object Test { + def main(args: Array[String]): Unit = { + Test1.run + Test2.run + Test3.run + Test4.run + } +} |