fix imporve split methodInfo/invokeInfo. #1860

This commit is contained in:
hengyunabc 2021-07-22 15:22:07 +08:00
parent e2d5c3c445
commit 2e161d621d
2 changed files with 9 additions and 4 deletions

View File

@ -957,15 +957,18 @@ public abstract class StringUtils {
return text.substring(pos + after.length());
}
// print|(ILjava/util/List;)V
public static String[] splitMethodInfo(String methodInfo) {
int index = methodInfo.indexOf('|');
return new String[] { methodInfo.substring(0, index), methodInfo.substring(index + 1, methodInfo.length()) };
}
// demo/MathGame|primeFactors|(I)Ljava/util/List;|24
public static String[] splitInvokeInfo(String invokeInfo) {
int index1 = invokeInfo.indexOf('|');
int index2 = invokeInfo.indexOf('|', index1 + 1);
int index3 = invokeInfo.indexOf('|', index2 + 1);
return new String[] { invokeInfo.substring(0, index1), invokeInfo.substring(index1 + 1, index2),
invokeInfo.substring(index2 + 1, invokeInfo.length()) };
invokeInfo.substring(index2 + 1, index3), invokeInfo.substring(index3 + 1, invokeInfo.length()) };
}
}

View File

@ -17,12 +17,14 @@ public class SpyImplTest {
Assertions.assertThat(StringUtils.splitMethodInfo("a|b")).containsExactly("a", "b");
Assertions.assertThat(StringUtils.splitMethodInfo("xxxxxxxxxx|fffffffffff")).containsExactly("xxxxxxxxxx",
"fffffffffff");
Assertions.assertThat(StringUtils.splitMethodInfo("print|(ILjava/util/List;)V")).containsExactly("print",
"(ILjava/util/List;)V");
}
@Test
public void testSplitInvokeInfo() throws Throwable {
Assertions.assertThat(StringUtils.splitInvokeInfo("a|b|c")).containsExactly("a", "b", "c");
Assertions.assertThat(StringUtils.splitInvokeInfo("xxxxxxxxxx|fffffffffff|yyy")).containsExactly("xxxxxxxxxx",
"fffffffffff", "yyy");
Assertions.assertThat(StringUtils.splitInvokeInfo("demo/MathGame|primeFactors|(I)Ljava/util/List;|24"))
.containsExactly("demo/MathGame", "primeFactors", "(I)Ljava/util/List;", "24");
}
}