diff options
author | Paul Phillips <paulp@improving.org> | 2013-02-01 17:38:56 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-02-01 17:38:56 -0800 |
commit | a45a78a1d4111709acdc0bca9a1ac869a8e53ea5 (patch) | |
tree | 5c909c41db2470c460cbb3c33672294c9342b914 /test/files/jvm | |
parent | 26de4394b19d6614b7d414b33f66ebf7adcb8833 (diff) | |
parent | 644eb7078a11613a06dcaaefb807cbcc44f65ea7 (diff) | |
download | scala-a45a78a1d4111709acdc0bca9a1ac869a8e53ea5.tar.gz scala-a45a78a1d4111709acdc0bca9a1ac869a8e53ea5.tar.bz2 scala-a45a78a1d4111709acdc0bca9a1ac869a8e53ea5.zip |
Merge commit '644eb7078a' into wip/fresh-merge2
Conflicts:
build.xml
src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
Diffstat (limited to 'test/files/jvm')
7 files changed, 127 insertions, 0 deletions
diff --git a/test/files/jvm/bytecode-test-example.check b/test/files/jvm/bytecode-test-example.check new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/test/files/jvm/bytecode-test-example.check @@ -0,0 +1 @@ +2 diff --git a/test/files/jvm/bytecode-test-example/Foo_1.scala b/test/files/jvm/bytecode-test-example/Foo_1.scala new file mode 100644 index 0000000000..4f679d156f --- /dev/null +++ b/test/files/jvm/bytecode-test-example/Foo_1.scala @@ -0,0 +1,9 @@ +class Foo_1 { + def foo(x: AnyRef): Int = { + val bool = x == null + if (x != null) + 1 + else + 0 + } +} diff --git a/test/files/jvm/bytecode-test-example/Test.scala b/test/files/jvm/bytecode-test-example/Test.scala new file mode 100644 index 0000000000..d668059cb7 --- /dev/null +++ b/test/files/jvm/bytecode-test-example/Test.scala @@ -0,0 +1,32 @@ +import scala.tools.partest.BytecodeTest + +import scala.tools.nsc.util.JavaClassPath +import java.io.InputStream +import scala.tools.asm +import asm.ClassReader +import asm.tree.{ClassNode, InsnList} +import scala.collection.JavaConverters._ + +object Test extends BytecodeTest { + def show: Unit = { + val classNode = loadClassNode("Foo_1") + val methodNode = getMethod(classNode, "foo") + println(countNullChecks(methodNode.instructions)) + } + + def countNullChecks(insnList: InsnList): Int = { + /** Is given instruction a null check? + * NOTE + * This will detect direct null compparsion as in + * if (x == null) ... + * and not indirect as in + * val foo = null + * if (x == foo) ... + */ + def isNullCheck(node: asm.tree.AbstractInsnNode): Boolean = { + val opcode = node.getOpcode + (opcode == asm.Opcodes.IFNULL) || (opcode == asm.Opcodes.IFNONNULL) + } + insnList.iterator.asScala.count(isNullCheck) + } +} diff --git a/test/files/jvm/throws-annot-from-java.check b/test/files/jvm/throws-annot-from-java.check new file mode 100644 index 0000000000..be3ba412f8 --- /dev/null +++ b/test/files/jvm/throws-annot-from-java.check @@ -0,0 +1,47 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> :power +** Power User mode enabled - BEEP WHIR GYVE ** +** :phase has been set to 'typer'. ** +** scala.tools.nsc._ has been imported ** +** global._, definitions._ also imported ** +** Try :help, :vals, power.<tab> ** + +scala> :paste +// Entering paste mode (ctrl-D to finish) + +{ + val clazz = rootMirror.getClassByName(newTermName("test.ThrowsDeclaration_2")); + { + val method = clazz.info.member(newTermName("foo")) + val throwsAnn = method.annotations.head + val atp = throwsAnn.atp + println("foo") + println("atp.typeParams.isEmpty: " + atp.typeParams.isEmpty) + println(throwsAnn) + } + println + + { + val method = clazz.info.member(newTermName("bar")) + val throwsAnn = method.annotations.head + val Literal(const) = throwsAnn.args.head + val tp = const.typeValue + println("bar") + println("tp.typeParams.isEmpty: " + tp.typeParams.isEmpty) + println(throwsAnn) + } +} + +// Exiting paste mode, now interpreting. + +foo +atp.typeParams.isEmpty: true +throws[IllegalStateException](classOf[java.lang.IllegalStateException]) + +bar +tp.typeParams.isEmpty: true +throws[test.PolymorphicException[_]](classOf[test.PolymorphicException]) + +scala> diff --git a/test/files/jvm/throws-annot-from-java/PolymorphicException_1.scala b/test/files/jvm/throws-annot-from-java/PolymorphicException_1.scala new file mode 100644 index 0000000000..58fa536f0b --- /dev/null +++ b/test/files/jvm/throws-annot-from-java/PolymorphicException_1.scala @@ -0,0 +1,3 @@ +package test + +class PolymorphicException[T] extends Exception diff --git a/test/files/jvm/throws-annot-from-java/Test_3.scala b/test/files/jvm/throws-annot-from-java/Test_3.scala new file mode 100644 index 0000000000..de1d984573 --- /dev/null +++ b/test/files/jvm/throws-annot-from-java/Test_3.scala @@ -0,0 +1,29 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """:power +:paste +{ + val clazz = rootMirror.getClassByName(newTermName("test.ThrowsDeclaration_2")); + { + val method = clazz.info.member(newTermName("foo")) + val throwsAnn = method.annotations.head + val atp = throwsAnn.atp + println("foo") + println("atp.typeParams.isEmpty: " + atp.typeParams.isEmpty) + println(throwsAnn) + } + println + + { + val method = clazz.info.member(newTermName("bar")) + val throwsAnn = method.annotations.head + val Literal(const) = throwsAnn.args.head + val tp = const.typeValue + println("bar") + println("tp.typeParams.isEmpty: " + tp.typeParams.isEmpty) + println(throwsAnn) + } +} +""" +} diff --git a/test/files/jvm/throws-annot-from-java/ThrowsDeclaration_2.java b/test/files/jvm/throws-annot-from-java/ThrowsDeclaration_2.java new file mode 100644 index 0000000000..3708fe626b --- /dev/null +++ b/test/files/jvm/throws-annot-from-java/ThrowsDeclaration_2.java @@ -0,0 +1,6 @@ +package test; + +public class ThrowsDeclaration_2 { + public void foo() throws IllegalStateException {}; + public void bar() throws PolymorphicException {}; +} |