Script: Write out ASM Code to generate Java class - No Fluff Just Stuff

Script: Write out ASM Code to generate Java class

Posted by: Robert Fischer on November 5, 2010

Edit: Updated version of the script here.


Here’s a nifty little Groovy script to write out the ASM code to generate a given Java class.
#!/usr/bin/env groovy
 
import org.objectweb.asm.util.ASMifierClassVisitor as V
import org.objectweb.asm.ClassReader as R
 
@Grab(group='asm', module='asm-all', version='[3.3,)')
private class JustHereForGrab {}
 
new R(new File(this.args[0]).newInputStream()).accept(new V(new PrintWriter(System.out)), 0)

You will have to update your ~/.groovy/grapeConfig.xml file to point to a repo with ASM in it. I’ve posted my grapeConfig.xml at http://repo.smokejumperit.com/grapeConfig.xml.


Comments


This post was by Robert Fischer, written on November 5, 2010.
Comment on this post: http://enfranchisedmind.com/blog/posts/groovy-shell-script-asm-to-java/#respond
Public Permalink: http://enfranchisedmind.com/blog/posts/groovy-shell-script-asm-to-java/
Creative Commons License
This article was a post on the EnfranchisedMind blog. EnfranchisedMind Blog by Robert Fischer, Brian Hurt, and Other Authors is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

(Digital Fingerprint: bcecb67d74ab248f06f068724220e340 (67.192.109.108) )

Robert Fischer

About Robert Fischer

Robert Fischer is a multi-language open source developer currently specializing in Groovy in Grails. In the past, his specialties have been in Perl, Java, Ruby, and OCaml. In the future, his specialty will probably be F# or (preferably) a functional JVM language like Scala or Clojure.

Robert is the author of Grails Persistence in GORM and GSQL, a regular contributor to GroovyMag and JSMag, the founder of the JConch Java concurrency library, and the author/maintainer of Liquibase-DSL and the Autobase database migration plugin for Grails.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »