diff options
author | michelou <michelou@epfl.ch> | 2010-12-30 23:53:00 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2010-12-30 23:53:00 +0000 |
commit | bf375f7d6375a2e437342a6d3b935048fa3ec545 (patch) | |
tree | 34a6d17021ee734f365c6044c4ceea1ad3cde8ea /test/files/jvm | |
parent | 096bc81a90b746ea3fa8a5bd8eb9009c08a71082 (diff) | |
download | scala-bf375f7d6375a2e437342a6d3b935048fa3ec545.tar.gz scala-bf375f7d6375a2e437342a6d3b935048fa3ec545.tar.bz2 scala-bf375f7d6375a2e437342a6d3b935048fa3ec545.zip |
fixed issue with EnclosingMethod attribute.
The above issue was made explicit using the dx tool for the Android SDK
to convert Java bytecode to Dalvik bytecode.
Diffstat (limited to 'test/files/jvm')
-rw-r--r-- | test/files/jvm/cf-attributes.check | 50 | ||||
-rw-r--r-- | test/files/jvm/cf-attributes.scala | 146 |
2 files changed, 196 insertions, 0 deletions
diff --git a/test/files/jvm/cf-attributes.check b/test/files/jvm/cf-attributes.check new file mode 100644 index 0000000000..018febb81b --- /dev/null +++ b/test/files/jvm/cf-attributes.check @@ -0,0 +1,50 @@ + +{{ anonymousFunctions$ }} + +{{ anonymousFunctions$bar$ }} + public final class anonymousFunctions$bar$$anonfun$4 of class anonymousFunctions$bar$ +anonymousClasses$$anon$1 + +{{ anonymousClasses$ }} + +[[ anonymousFunctions$ ]] + InnerClass: + public final #66 of #90; //class anonymousFunctions$$anonfun$1 of class anonymousFunctions + public final #77; //class anonymousFunctions$$anonfun$2 + public final #24; //class anonymousFunctions$$anonfun$3 + public final #49; //class anonymousFunctions$$anonfun$foo$1 + + +[[ anonymousFunctions$bar$ ]] + InnerClass: + public final #28 of #9; //class anonymousFunctions$bar$$anonfun$4 of class anonymousFunctions$bar$ + public final #52; //class anonymousFunctions$bar$$anonfun$5 + + +[[ anonymousClasses$ ]] + InnerClass: + public abstract #33= #30 of #32; //Foo=class anonymousClasses$Foo of class anonymousClasses + public final #25 of #32; //class anonymousClasses$$anon$1 of class anonymousClasses + public abstract #36= #35 of #32; //Foo$class=class anonymousClasses$Foo$class of class anonymousClasses + + +[[ anonymousFunctions$$anonfun$3 ]] + InnerClass: + public final #8; //class anonymousFunctions$$anonfun$3 + + +[[ anonymousFunctions$$anonfun$foo$1 ]] + InnerClass: + public final #8; //class anonymousFunctions$$anonfun$foo$1 + + +[[ anonymousFunctions$bar$$anonfun$4 ]] + InnerClass: + public final #8 of #41; //class anonymousFunctions$bar$$anonfun$4 of class anonymousFunctions$bar$ + + +[[ anonymousClasses$$anon$1 ]] + InnerClass: + public abstract #46= #43 of #45; //Foo=class anonymousClasses$Foo of class anonymousClasses + public final #48 of #45; //class anonymousClasses$$anon$1 of class anonymousClasses + diff --git a/test/files/jvm/cf-attributes.scala b/test/files/jvm/cf-attributes.scala new file mode 100644 index 0000000000..b5dd7eb386 --- /dev/null +++ b/test/files/jvm/cf-attributes.scala @@ -0,0 +1,146 @@ +object Test extends Application { + InnerClassTest1 + InnerClassTest2 +} + +object InnerClassTest1 extends Test1 { + printClass(anonymousFunctions.getClass) + printClass(anonymousFunctions.bar.getClass) + println(anonymousClasses.x) // see run/t1167.scala + printClass(anonymousClasses.getClass) +} + +object InnerClassTest2 extends Test2 { + printClass(anonymousFunctions.getClass) + printClass(anonymousFunctions.bar.getClass) + printClass(anonymousClasses.getClass) + // not accessible via the Java reflection API + printClass("anonymousFunctions$$anonfun$3") + printClass("anonymousFunctions$$anonfun$foo$1") + printClass("anonymousFunctions$bar$$anonfun$4") + printClass("anonymousClasses$$anon$1") +} + +object anonymousFunctions { + //InnerClass: + // public final #_ of #_; //class anonymousFunctions$$anonfun$1 of class InnerClass$ + val twice = (x: Int) => 2*x + + //InnerClass: + // public final #_ of #_; //class anonymousFunctions$$anonfun$2 + List(0).map(x => x+1) + + def foo { + //InnerClass: + // public final #_ of #_; class anonymousFunctions$$anonfun$3 + val square = (x: Int) => x*x + + //InnerClass: + // public final #_ of #_; class anonymousFunctions$$anonfun$foo$1 + Array(1).filter(_ % 2 == 0) + } + + object bar { + //InnerClass: + // public final #_ of #_; class anonymousFunctions$bar$$anonfun$4 of class anonymousFunctions$bar$ + val cube = (x: Int) => x*x*x + + //InnerClass: + // public final #_ of #_; class anonymousFunctions$bar$$anonfun$5 + Set(1, 2, 3).exists(_ == 2) + } +} + +object anonymousClasses { + //InnerClass: + // public abstract #_= #_ of #_; //Foo=class anonymousClasses$Foo of class anonymousClasses$ + // public abstract #_= #_ of #_; //Foo$class=class anonymousClasses$Foo$class of class anonymousClasses$ + trait Foo { + def foo() { println("foo"); } + override def toString = getClass.getName + } + //InnerClass: + // public final #_; //class anonymousClasses$$anon$1 of class anonymousClasses$ + val x = new Foo() { + override def foo() { println("foo (overriden)"); } + def dummy = 0 + } +} + +// Auxiliary functions + +trait Test1 { + private var kind: String = _ + private var mods: String = _ + def printInnerClasses(cls: Class[_]) { + for (c <- cls.getDeclaredClasses) { + mods = AccessFlags.asString(c.getModifiers) + kind = if (c.isInterface) "interface" else "class" + println(" "+mods+kind+" "+c.getName+ + " of class "+c.getEnclosingClass.getName) + } + } + def printClass(cls: Class[_]) { + println("\n{{ "+cls.getName+" }}") + printInnerClasses(cls) + } +} + +trait Test2 { + @throws(classOf[Exception]) + def printInnerClasses(cls: Class[_]) { + import java.io._, ch.epfl.lamp.fjbg._ + val fjbgContext = new FJBGContext(49, 0) + val outDir = System.getProperty("partest.output", "cf-attributes.obj") + val fileName = outDir+File.separator+cls.getName+".class" + val in = new DataInputStream(new FileInputStream(fileName)) + val jclass = fjbgContext.JClass(in) + println(jclass.getInnerClasses) + in.close() + } + def printClass(name: String) { + try { printClass(Class.forName(name)) } + catch { case e: Exception => println(e) } + } + def printClass(cls: Class[_]) { + println("\n[[ "+cls.getName+" ]]"); + try { printInnerClasses(cls) } + catch { case e: Exception => println(e) } + } +} + +object AccessFlags { + val ACC_PUBLIC = 0x0001 + val ACC_PRIVATE = 0x0002 + val ACC_PROTECTED = 0x0004 + val ACC_STATIC = 0x0008 + val ACC_FINAL = 0x0010 + val ACC_ABSTRACT = 0x0400 + + def asString(accessFlags: Int): String = { + val buf = new StringBuilder() + if ((accessFlags & ACC_PUBLIC) != 0) buf.append("public ") + else if ((accessFlags & ACC_PROTECTED) != 0) buf.append("protected ") + else if ((accessFlags & ACC_PRIVATE) != 0) buf.append("private ") + if ((accessFlags & ACC_ABSTRACT) != 0) buf.append("abstract ") + else if ((accessFlags & ACC_FINAL) != 0) buf.append("final ") + buf.toString + } +} + +/* + implicit def stringToLines(s: String) = new { + def lines(n: Int): String = { + val buf = new StringBuilder(); + var i = 0 + var from = 0 + while (i < n && 0 <= from && from < s.length) { + val pos = s.indexOf('\n', from) + if (pos >= 0) { i += 1; buf.append(s.substring(from, pos + 1)); } + from = pos + 1 + } + buf.toString() + } + } +*/ + |