Created
March 17, 2013 05:31
-
-
Save VijayKrishna/5180279 to your computer and use it in GitHub Desktop.
Method descriptor parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DescSplitter { | |
public static void main(String[] args) { | |
splitMethodDesc(desc); | |
//simple test cases. | |
splitMethodDesc("([IFB[[[[[Ljava/lang/String;Ljava/lang/String;[I[S[BBLjava/lang/BLtring;)"); | |
splitMethodDesc("Ljava/lang/String;BBBBLjava/lang/String;"); | |
splitMethodDesc("ZBCSIFDJ[Z[B[C[S[I[F[D[JLZBCSIFDJ;LZBCSIFDJ;[LZBCSIFDJ;LZBCSIFDJ;[LZBCSIFDJ;"); | |
} | |
public static void splitMethodDesc(String desc) { | |
//\[*L[^;]+;|\[[ZBCSIFDJ]|[ZBCSIFDJ] | |
int beginIndex = desc.indexOf('('); | |
int endIndex = desc.lastIndexOf(')'); | |
if((beginIndex == -1 && endIndex != -1) || (beginIndex != -1 && endIndex == -1)) { | |
System.err.println(beginIndex); | |
System.err.println(endIndex); | |
throw new RuntimeException(); | |
} | |
String x0; | |
if(beginIndex == -1 && endIndex == -1) { | |
x0 = desc; | |
} | |
else { | |
x0 = desc.substring(beginIndex + 1, endIndex); | |
} | |
Pattern pattern = Pattern.compile("\\[*L[^;]+;|\\[[ZBCSIFDJ]|[ZBCSIFDJ]"); | |
Matcher matcher = pattern.matcher(x0); | |
ArrayList<String> listMatches = new ArrayList<String>(); | |
while(matcher.find()) | |
{ | |
listMatches.add(matcher.group()); | |
} | |
for(String s : listMatches) | |
{ | |
System.out.print(s + " "); | |
} | |
System.out.println(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment