本文整理汇总了Java中javassist.expr.MethodCall.replace方法的典型用法代码示例。如果您正苦于以下问题:Java MethodCall.replace方法的具体用法?Java MethodCall.replace怎么用?Java MethodCall.replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.expr.MethodCall
的用法示例。
在下文中一共展示了MethodCall.replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: edit
import javassist.expr.MethodCall; //导入方法依赖的package包/类
@Override
public void edit(MethodCall m) throws CannotCompileException {
StringBuilder rb = new StringBuilder();
if (codeBlock.body.isEmpty()) return;
switch (codeBlock.where) {
case AFTER_SUPER:
case BEFORE_SUPER:
if (!m.isSuper()) return;
rb.append(codeBlock.body);
break;
case AFTER_A_CALL:
case BEFORE_A_CALL:
case AROUND_A_CALL:
if (!m.getMethodName().equals(codeBlock.aroundMethodCall)) return;
rb.append(codeBlock.body);
}
m.replace(rb.toString());
super.edit(m);
}
示例2: edit
import javassist.expr.MethodCall; //导入方法依赖的package包/类
@Override
public void edit(MethodCall m) throws CannotCompileException {
if (m.getMethodName().equals(insertionMethod)) {
String origMethodCall = "$_ = $proceed($$);;\n";
if (insertAfter) {
origMethodCall = origMethodCall + bodyToInsert;
} else {
origMethodCall = bodyToInsert + origMethodCall;
}
log.info("Injected : " + origMethodCall);
log.info("Class " + classToTransform.getName() + " has been enhanced.");
m.replace(origMethodCall);
isSuccessful = true;
}
}
示例3: edit
import javassist.expr.MethodCall; //导入方法依赖的package包/类
/**
* Edits a method call.
*
* @param mc the method call
* @throws CannotCompileException in case that compile errors occur
*/
public void edit(MethodCall mc) throws CannotCompileException {
if (mc.getMethodName().equals("byteAt")) {
try {
String opcode = Opcode.class.getName();
CtMethod method = mc.getMethod();
CtClass declaring = method.getDeclaringClass();
if (declaring.getName().equals(
CodeIterator.class.getName())) {
mc.replace("$_ = $proceed($$); "
+ "if (disableInstanceof && $_=="
+ opcode + ".INSTANCEOF)"
+ "{return false;}"
+ "if (disableCast && $_=="
+ opcode + ".CHECKCAST)"
+ "{return false;}");
}
} catch (NotFoundException e) {
throw new CannotCompileException(e);
}
}
}
示例4: edit
import javassist.expr.MethodCall; //导入方法依赖的package包/类
/**
* Is called when a method call occurs. Replaces calls to
* constructors or classes to be removed by the value expression
* in the annotation or by the default value.
*
* @param call the method call to be processed
* @throws CannotCompileException in case of errors in the generated
* byte code
*/
@Override
public void edit(MethodCall call) throws CannotCompileException {
try {
CtMethod method = call.getMethod();
if (removals.containsKey(method.getLongName())
|| classesForRemoval.contains(method.getDeclaringClass())) {
if (CtClass.voidType == method.getReturnType()) {
call.replace(";");
} else {
Variability var = Annotations.getAnnotationRec(method,
Variability.class, config.checkRecursively());
String override = null;
if (null != var) {
override = var.value();
}
call.replace("$_ = " + Types.getDefaultValue(
method.getReturnType(), override) + ";");
}
}
} catch (NotFoundException ex) {
throw new CannotCompileException(ex);
}
}
示例5: edit
import javassist.expr.MethodCall; //导入方法依赖的package包/类
@Override
public void edit(MethodCall methodCall) throws CannotCompileException {
final boolean joinPointMethod = isJoinPointMethod(jointPointList, methodCall.getMethodName(), methodCall.getSignature());
if (joinPointMethod) {
if (!methodCall.getSignature().equals(replaceMethod.getSignature())) {
throw new CannotCompileException("Signature miss match. method:" + sourceMethod.getName() + " source:" + sourceMethod.getSignature() + " jointPoint:" + replaceMethod.getSignature());
}
final String invokeSource = invokeSourceMethod();
if (logger.isDebugEnabled()) {
logger.debug("JointPoint method {}{} -> invokeOriginal:{}", methodCall.getMethodName(), methodCall.getSignature(), invokeSource);
}
methodCall.replace(invokeSource);
} else {
if (isSubClass) {
// validate super class method
try {
CtMethod method = methodCall.getMethod();
CtClass declaringClass = method.getDeclaringClass();
if (sourceClass.subclassOf(declaringClass)) {
sourceClass.getMethod(methodCall.getMethodName(), methodCall.getSignature());
}
} catch (NotFoundException e) {
throw new CannotCompileException(e.getMessage(), e);
}
}
}
}
示例6: edit
import javassist.expr.MethodCall; //导入方法依赖的package包/类
/**
* Edits a method call, searches for system exit and inserts if
* present the given {@link #code}.
*
* @param mc the method call to consider
* @throws CannotCompileException in case of any compile error in the
* new code
*/
public void edit(MethodCall mc) throws CannotCompileException {
try {
if (null != code) {
CtMethod method = mc.getMethod();
if ("exit".equals(method.getName())
&& method.getDeclaringClass().getName().equals(
System.class.getName())) {
mc.replace(code + " $_ = $proceed($$);");
code = null;
}
}
} catch (NotFoundException nf) {
}
}
示例7: replacePrepareStatement
import javassist.expr.MethodCall; //导入方法依赖的package包/类
@ProcessMethodCall(targetClass = Connection.class, methodName = "prepareStatement")
public void replacePrepareStatement(MethodCall methodCall) throws CannotCompileException {
methodCall.replace(getMethodBody(methodCall, "foo.bar.SQLAgentMethodProcessor.prepareStatement($_, $1);"));
}
示例8: replaceAddBatch
import javassist.expr.MethodCall; //导入方法依赖的package包/类
@ProcessMethodCall(targetClass = Statement.class, methodName = "addBatch")
public void replaceAddBatch(MethodCall methodCall) throws CannotCompileException {
methodCall.replace(getMethodBody(methodCall, "foo.bar.SQLAgentMethodProcessor.prepareStatement($0, $1);"));
}
示例9: replaceClearBatch
import javassist.expr.MethodCall; //导入方法依赖的package包/类
@ProcessMethodCall(targetClass = Statement.class, methodName = "clearBatch")
public void replaceClearBatch(MethodCall methodCall) throws CannotCompileException {
methodCall.replace(getMethodBody(methodCall, "foo.bar.SQLAgentMethodProcessor.clearStatements($0);"));
}
示例10: replaceExecuteStatement
import javassist.expr.MethodCall; //导入方法依赖的package包/类
@ProcessMethodCall(targetClass = Statement.class, methodName = "execute(?!Batch).*")
public void replaceExecuteStatement(MethodCall methodCall) throws Exception {
methodCall.replace(getMethodBody(methodCall, "foo.bar.SQLAgentMethodProcessor.notifyExecution($1);"));
}
示例11: replaceExecuteBatch
import javassist.expr.MethodCall; //导入方法依赖的package包/类
@ProcessMethodCall(targetClass = Statement.class, methodName = "executeBatch")
public void replaceExecuteBatch(MethodCall methodCall) throws Exception {
methodCall.replace(getMethodBody(methodCall, "foo.bar.SQLAgentMethodProcessor.notifyExecution($0);"));
}
示例12: replaceExecutePreparedStatement
import javassist.expr.MethodCall; //导入方法依赖的package包/类
@ProcessMethodCall(targetClass = PreparedStatement.class, methodName = "execute.*")
public void replaceExecutePreparedStatement(MethodCall methodCall) throws CannotCompileException {
methodCall.replace(getMethodBody(methodCall, "foo.bar.SQLAgentMethodProcessor.notifyExecution($0);"));
}
示例13: replaceClosePreparedStatement
import javassist.expr.MethodCall; //导入方法依赖的package包/类
@ProcessMethodCall(targetClass = PreparedStatement.class, methodName = "close")
public void replaceClosePreparedStatement(MethodCall methodCall) throws CannotCompileException {
methodCall.replace(getMethodBody(methodCall, "foo.bar.SQLAgentMethodProcessor.notifyClose($0);"));
}
示例14: edit
import javassist.expr.MethodCall; //导入方法依赖的package包/类
@Override
public void edit(MethodCall m) throws CannotCompileException {
switch (mode) {
case AFTER_SUPER:
case BEFORE_SUPER:
case REPLACE_SUPER:
if (!m.isSuper()) {
log.warning("An invocation of method " + insertionMethod.getName() + " was detected, without a call to super in " + m.getMethodName()
+ " while asking to mimic method with mode " + mode);
return;
}
break;
default:
break;
}
String invokeCopy;
try {
invokeCopy = createInvocation(originalMethod, copiedMethodName);
} catch (NotFoundException e) {
throw new CannotCompileException(e);
}
// call to super
if (m.getMethodName().equals(insertionMethod.getName())) {
log.fine("Insertion point detected: " + insertionMethod.getName());
String replacement = "";
switch (mode) {
case AFTER_SUPER:
case AFTER:
replacement = "$_ = $proceed($$);\n" + invokeCopy;
break;
case BEFORE_SUPER:
case BEFORE:
replacement = invokeCopy + "$_ = $proceed($$);\n";
break;
case REPLACE_SUPER:
replacement = "$_ = " + invokeCopy;
break;
default:
break;
}
log.fine("Replaced by " + replacement);
m.replace(replacement);
isSuccessful = true;
}
super.edit(m);
}
示例15: edit
import javassist.expr.MethodCall; //导入方法依赖的package包/类
@Override
public void edit(MethodCall m) throws CannotCompileException {
String callerClassName = m.getFileName();
String className = m.getClassName();
String method = m.getMethodName();
try {
// this traverses the class hierarchy up
className = m.getMethod().getDeclaringClass().getName();
} catch (NotFoundException e) {
// throw new
// RuntimeException("Cannot instrument call to "
// + className + "." + method + "() in "
// + string, e);
logger.debug("Cannot instrument call to " + className + "."
+ method + "() in " + callerClassName + " " + e);
// e.printStackTrace();
// return;
}
if (className == null || method == null) {
return;
}
// redirect calls to System.currentTimeMillis()
if (className.equals("java.lang.System")
&& method.equals("currentTimeMillis")) {
m.replace("{ $_ = " + s + ".currentTimeMillis(); }");
return;
}
// redirect calls to System.nanoTime()
if (className.equals("java.lang.System") && method.equals("nanoTime")) {
m.replace("{ $_ = " + s + ".nanoTime(); }");
return;
}
// redirect calls to Thread.sleep()
if (className.equals("java.lang.Thread") && method.equals("sleep")) {
m.replace("{ " + s + ".sleep($$); }");
return;
}
// redirect calls to Thread.start()
if (className.equals("java.lang.Thread") && method.equals("start")) {
m.replace("{ " + s + ".start(); }");
return;
}
// make sure the SHA1PRNG is used in SecureRandom
if (className.equals("java.security.SecureRandom")
&& method.equals("getPrngAlgorithm")) {
m.replace("{ $_ = null; }");
// System.err.println("REPLACED SECURE_RANDOM");
return;
}
// redirect calls to TimeZone.getDefault()
if (className.equals("java.util.TimeZone")
&& method.equals("getDefaultRef")) {
m.replace("{ $_ = " + s + ".getDefaultTimeZone(); }");
return;
}
}