Skip to content

Instantly share code, notes, and snippets.

@VijayKrishna
Created March 17, 2013 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VijayKrishna/5180279 to your computer and use it in GitHub Desktop.
Save VijayKrishna/5180279 to your computer and use it in GitHub Desktop.
Method descriptor parser
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