Skip to content

Instantly share code, notes, and snippets.

@fikr4n
Last active February 14, 2016 07:15
Show Gist options
  • Save fikr4n/2a4a688ecc94ba67f0f8 to your computer and use it in GitHub Desktop.
Save fikr4n/2a4a688ecc94ba67f0f8 to your computer and use it in GitHub Desktop.
'Superkill' JVM type signatures to Java types converter
import re
p = re.compile(r'(\[*)([ZBCSIJFDV]|L([^;\s]+);)')
prims = {'Z': 'boolean', 'B': 'byte', 'C': 'char', 'S': 'short', 'I': 'int', 'J': 'long', 'F': 'float', 'D': 'double', 'V': 'void'}
def tr(s):
return [(i.group(3).replace('/', '.') if i.group(3) else prims[i.group(2)]) + ('[]' * len(i.group(1)))
for i in p.finditer(s)]
@fikr4n
Copy link
Author

fikr4n commented Feb 14, 2016

Example:

>>> tr('')
[]
>>> tr('Z')
['boolean']
>>> tr('V')
['void']
>>> tr('FIS')
['float', 'int', 'short']
>>> tr('Ljava/lang/String;I[[SJ')
['java.lang.String', 'int', 'short[][]', 'long']
>>> tr('[V')  # notice that this is actually invalid
['void[]']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment