mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-08 19:30:47 +08:00
print diagnose verbose using java style descriptor
This commit is contained in:
parent
1ff6ec5961
commit
196dffc73d
@ -14,6 +14,7 @@ public class ByteCodeConst {
|
||||
public static final byte TYPE_VOID = 'V';
|
||||
public static final byte PARAM_END = ')';
|
||||
public static final byte CLASS_END = ';';
|
||||
public static final byte PKG_SEGMENT = '/';
|
||||
public static final byte TYPE_ARRAY = '[';
|
||||
|
||||
}
|
||||
|
@ -137,6 +137,72 @@ public class MethodUtil {
|
||||
* @return java style descriptor
|
||||
*/
|
||||
private static String toJavaParameterDesc(String desc) {
|
||||
return desc;
|
||||
if (desc.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean isArray = false;
|
||||
boolean isTravellingClass = false;
|
||||
for (byte b : desc.getBytes()) {
|
||||
if (isTravellingClass) {
|
||||
switch (b) {
|
||||
case CLASS_END:
|
||||
sb.append(isArray ? "[]" : "");
|
||||
isArray = false;
|
||||
isTravellingClass = false;
|
||||
break;
|
||||
case PKG_SEGMENT:
|
||||
sb.append('.');
|
||||
break;
|
||||
default:
|
||||
sb.append((char)b);
|
||||
}
|
||||
} else {
|
||||
switch (b) {
|
||||
case TYPE_ARRAY:
|
||||
isArray = true;
|
||||
break;
|
||||
case TYPE_BYTE:
|
||||
sb.append(",byte").append(isArray ? "[]" : "");
|
||||
isArray = false;
|
||||
break;
|
||||
case TYPE_CHAR:
|
||||
sb.append(",char").append(isArray ? "[]" : "");
|
||||
isArray = false;
|
||||
break;
|
||||
case TYPE_DOUBLE:
|
||||
sb.append(",double").append(isArray ? "[]" : "");
|
||||
isArray = false;
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
sb.append(",float").append(isArray ? "[]" : "");
|
||||
isArray = false;
|
||||
break;
|
||||
case TYPE_INT:
|
||||
sb.append(",int").append(isArray ? "[]" : "");
|
||||
isArray = false;
|
||||
break;
|
||||
case TYPE_LONG:
|
||||
sb.append(",long").append(isArray ? "[]" : "");
|
||||
isArray = false;
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
sb.append(",short").append(isArray ? "[]" : "");
|
||||
isArray = false;
|
||||
break;
|
||||
case TYPE_BOOL:
|
||||
sb.append(",boolean").append(isArray ? "[]" : "");
|
||||
isArray = false;
|
||||
break;
|
||||
case TYPE_CLASS:
|
||||
sb.append(",");
|
||||
isTravellingClass = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.substring(1);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.alibaba.testable.agent.util;
|
||||
|
||||
import com.alibaba.testable.core.accessor.PrivateAccessor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -37,5 +38,15 @@ class MethodUtilTest {
|
||||
assertEquals("", MethodUtil.getFirstParameter("()V"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_able_to_convert_bytecode_parameters() {
|
||||
assertEquals("", PrivateAccessor.invokeStatic(MethodUtil.class, "toJavaParameterDesc", ""));
|
||||
assertEquals("char", PrivateAccessor.invokeStatic(MethodUtil.class, "toJavaParameterDesc", "C"));
|
||||
assertEquals("int,long", PrivateAccessor.invokeStatic(MethodUtil.class, "toJavaParameterDesc", "IJ"));
|
||||
assertEquals("int[],long[]", PrivateAccessor.invokeStatic(MethodUtil.class, "toJavaParameterDesc", "[I[J"));
|
||||
assertEquals("int,java.lang.String", PrivateAccessor.invokeStatic(MethodUtil.class, "toJavaParameterDesc", "ILjava/lang/String;"));
|
||||
assertEquals("java.lang.String,int,long[]", PrivateAccessor.invokeStatic(MethodUtil.class, "toJavaParameterDesc", "Ljava/lang/String;I[J"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user