Using asm from jruby
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <[email protected]> |
I'm a novice asm user, and I've been using jruby for a long time. When I
started using asm, it seemed like there might be some things that would be
simpler in jruby than in Java.
If you haven't played with asm + jruby, take a look. You can do some
interesting things with not much code. For example, here's the jruby to visit
a set of class files (given on the command line), printing out every call to
visit*:
(You'll need to specify a -I option to tell jruby where to find the asm-3.3.1
jar - in my case: jruby -I /Users/james/experimements/AsmSample/libs
SomeFile.class)
require 'java'
require 'asm-3.3.1'
# This lets me type org.objectweb.asm::... instead of
Java::OrgObjectwebAsm::...
def org
Java::Org
end
class SampleVisitor
include org.objectweb.asm::MethodVisitor
include org.objectweb.asm::ClassVisitor
include org.objectweb.asm::FieldVisitor
include org.objectweb.asm::AnnotationVisitor
include org.objectweb.asm.signature::SignatureVisitor
def method_missing name, *args
name_string = name.to_s
if name_string =~ /visit.*/
puts "#{name}\t#{args}"
self
else
super
end
end
end
# Loop through each .class file given on the command line
ARGV.each do |classfile|
puts " ---------------- Reading file #{classfile}"
f = java.io.File.new classfile
fis = java.io.FileInputStream.new f
class_reader = org.objectweb.asm::ClassReader.new fis
v = SampleVisitor.new
class_reader.accept v, 0
puts
end
--
James Moore
[email protected]
http://blog.restphone.com/
message-footer.txt
(text/plain, 238 B)
-- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws