mirror of
https://github.com/alibaba/testable-mock.git
synced 2026-09-04 05:32:58 +08:00
refact and remove unused method
This commit is contained in:
@@ -22,6 +22,10 @@ abstract public class BaseClassHandler implements Opcodes {
|
||||
return cw.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform class byte code
|
||||
* @param cn original class node
|
||||
*/
|
||||
abstract protected void transform(ClassNode cn);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,18 @@
|
||||
package com.alibaba.testable.agent.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author flin
|
||||
*/
|
||||
public class MethodInfo {
|
||||
|
||||
private String name;
|
||||
private String desc;
|
||||
private final String name;
|
||||
private final String desc;
|
||||
|
||||
public MethodInfo(String name, String desc) {
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public static Set<String> descSet(Collection<MethodInfo> methodInfos) {
|
||||
Set<String> set = new HashSet<String>();
|
||||
for (MethodInfo m : methodInfos) {
|
||||
set.add(m.desc);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.Set;
|
||||
*/
|
||||
public class TestableClassTransformer implements ClassFileTransformer {
|
||||
|
||||
private static final Set<String> loadedClassNames = new HashSet<String>();
|
||||
private final Set<String> loadedClassNames = new HashSet<String>();
|
||||
|
||||
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
|
||||
ProtectionDomain protectionDomain, byte[] classFileBuffer) {
|
||||
|
||||
@@ -33,14 +33,17 @@ public class PrivateAccessor {
|
||||
|
||||
public static <T> T invoke(Object ref, String method, Object... args) {
|
||||
try {
|
||||
Class[] cls = TypeUtil.getClassesFromObjects(args);
|
||||
Class<?>[] cls = TypeUtil.getClassesFromObjects(args);
|
||||
Method declaredMethod = TypeUtil.getMethodByNameAndParameterTypes(ref.getClass().getDeclaredMethods(), method, cls);
|
||||
declaredMethod.setAccessible(true);
|
||||
return (T)declaredMethod.invoke(ref, args);
|
||||
if (declaredMethod != null) {
|
||||
declaredMethod.setAccessible(true);
|
||||
return (T)declaredMethod.invoke(ref, args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,9 +17,14 @@ public abstract class BaseTranslator extends TreeTranslator {
|
||||
}
|
||||
return List.from(es);
|
||||
}
|
||||
return null;
|
||||
return List.nil();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exchange private method invoke with private accessor
|
||||
* @param expr original expression
|
||||
* @return exchanged expression
|
||||
*/
|
||||
protected abstract JCExpression checkAndExchange(JCExpression expr);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user