Groovy web console

subscribe to the feed Subscribe
to this
site

fdsasdfsdfa

Published 2 weeks ago by Anonymous
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic

@CompileDynamic
class SRG {
public static final PATTERN = /(\[*?(?:L[^;]*|[A-Z]))/

private static Map<String, Closure<String>> TYPES = [
Z: { "boolean" },
B: { "byte" },
C: { "char" },
S: { "short" },
I: { "int" },
J: { "long" },
F: { "float" },
D: { "double" },
V: { "void" },
L: { String it -> readClass it.substring(1) },    
].withDefault { return { it } }     
private static List<String> readSig(String sig) {        
(sig =~ PATTERN).collect { List it ->            
String token = it[0]            
def split = token.split "\\["            
token = split[-1]            
Closure<String> c = TYPES[token[0]]            
c.call(token) + "[]" * (split.size() - 1)        
println "sig ${sig}: ${c.call(token) + "[]" * (split.size() - 1)}".toString()
}    
}     
private static String readClass(String s) { s.replace('/', '.') }

private def handle = [
    "MD:": { String from, String fromsigstr, String to, String tosigstr ->          
        println from
        println fromsigstr
        println to
        println tosigstr
        def fromsig = readSig fromsigstr
        def tosig = readSig tosigstr
        println "${fromsig[-1]} ${readClass from}(${fromsig[0..<-1].join(", ")})".toString()
        println "${tosig[-1]} ${readClass to}(${tosig[0..<-1].join(", ")})".toString()                
    }
]

static void main(String[] args) {
    SRG s = new SRG()
    def tokens = "MD: zz/a (Lzx;Lwn;Ladm;Lcj;Lcq;FFF)Z net/minecraft/item/ItemLead/func_180614_a (Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/world/World;Lnet/minecraft/util/BlockPos;Lnet/minecraft/util/EnumFacing;FFF)Z".split(" ")*.replace('/', '.')            
    s.handle[tokens.head()](*tokens.tail())
}


}