本文整理汇总了Java中javassist.expr.MethodCall类的典型用法代码示例。如果您正苦于以下问题:Java MethodCall类的具体用法?Java MethodCall怎么用?Java MethodCall使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MethodCall类属于javassist.expr包,在下文中一共展示了MethodCall类的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: analyzeMethodCalls
import javassist.expr.MethodCall; //导入依赖的package包/类
private AnalyzedMethod analyzeMethodCalls(CtMethod ctMethod) {
final List<AnalyzedMethod> methodsCalled = new ArrayList<AnalyzedMethod>();
try {
ctMethod.instrument(new ExprEditor() {
@Override
public void edit(MethodCall m) throws CannotCompileException {
if (analyzisConfig.classFilter().test(m.getClassName())) {
methodsCalled.add(asAnalyzedMethod(m));
}
}
});
} catch (CannotCompileException e) {
throw new RuntimeException(e);
}
AnalyzedMethod method = asAnalyzedMethod(ctMethod);
method.setCalledMethods(methodsCalled);
return method;
}
示例4: hackBackgroundFrame
import javassist.expr.MethodCall; //导入依赖的package包/类
private static void hackBackgroundFrame() {
// Hack method
try {
final ClassPool cp = new ClassPool(true);
cp.insertClassPath(new ClassClassPath(IdeBackgroundUtil.class));
final CtClass ctClass = cp.get("com.intellij.openapi.wm.impl.IdePanePanel");
final CtMethod paintBorder = ctClass.getDeclaredMethod("getBackground");
paintBorder.instrument(new ExprEditor() {
@Override
public void edit(final MethodCall m) throws CannotCompileException {
if (m.getMethodName().equals("getIdeBackgroundColor")) {
m.replace("{ $_ = javax.swing.UIManager.getColor(\"Viewport.background\"); }");
}
}
});
ctClass.toClass();
} catch (final Exception e) {
e.printStackTrace();
}
}
示例5: grabAllMethod
import javassist.expr.MethodCall; //导入依赖的package包/类
private void grabAllMethod(CtClass cc) {
for (CtMethod method : cc.getMethods()) {
System.err.println(method.getLongName() + "-" + method.getSignature() + " at line " + method.getMethodInfo().getLineNumber(0));
try {
method.instrument(
new ExprEditor() {
public void edit(MethodCall m) throws CannotCompileException {
System.err.println("method invoke into the method observe "+m.getClassName() + "." + m.getMethodName() + " " + m.getSignature());
}
});
} catch (CannotCompileException e) {
System.err.println("Cannot Compil Exception"+e.getMessage());
}
}
for (CtConstructor c : cc.getConstructors()) {
System.err.println(c.getLongName() + "-" + c.getSignature()+" at line "+c.getMethodInfo().getLineNumber(0));
}
}
示例6: 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);
}
}
}
示例7: 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);
}
}
示例8: getMethodEntry
import javassist.expr.MethodCall; //导入依赖的package包/类
public static MethodEntry getMethodEntry(MethodCall call) {
return new MethodEntry(
new ClassEntry(Descriptor.toJvmName(call.getClassName())),
call.getMethodName(),
new Signature(call.getSignature())
);
}
示例9: getMethodElem
import javassist.expr.MethodCall; //导入依赖的package包/类
private String getMethodElem(MethodCall e) {
int bci = e.indexOfOriginalBytecode();
String mName;
if (currentMethod instanceof CtConstructor) {
mName = ((CtConstructor) currentMethod).isClassInitializer() ?
"<clinit>" : "<init>";
} else {
mName = currentMethod.getName();
}
String mSign = currentMethod.getSignature();
String cName = currentClass.getName();
MethodElem me = new MethodElem(bci, mName, mSign, cName);
return "\"" + me.toString() + "\"";
}
示例10: hackTitleLabel
import javassist.expr.MethodCall; //导入依赖的package包/类
/**
* For better dialog titles (since I have no idea how to know when dialogs appear, I can't attach events so I'm directly hacking
* the source code). I hate doing this.
*/
public static void hackTitleLabel() {
// Hack method
try {
final ClassPool cp = new ClassPool(true);
cp.insertClassPath(new ClassClassPath(CaptionPanel.class));
final CtClass ctClass = cp.get("com.intellij.ui.TitlePanel");
final CtConstructor declaredConstructor = ctClass.getDeclaredConstructor(new CtClass[] {
cp.get("javax.swing.Icon"),
cp.get("javax.swing" +
".Icon")});
declaredConstructor.instrument(new ExprEditor() {
@Override
public void edit(final MethodCall m) throws CannotCompileException {
if (m.getMethodName().equals("empty")) {
// Replace insets
m.replace("{ $1 = 10; $2 = 10; $3 = 10; $4 = 10; $_ = $proceed($$); }");
} else if (m.getMethodName().equals("setHorizontalAlignment")) {
// Set title at the left
m.replace("{ $1 = javax.swing.SwingConstants.LEFT; $_ = $proceed($$); }");
} else if (m.getMethodName().equals("setBorder")) {
// Bigger heading
m.replace("{ $_ = $proceed($$); myLabel.setFont(myLabel.getFont().deriveFont(1, com.intellij.util.ui.JBUI.scale(16.0f))); }");
}
}
});
ctClass.toClass();
} catch (final Exception e) {
e.printStackTrace();
}
}
示例11: hackTabsGetHeight
import javassist.expr.MethodCall; //导入依赖的package包/类
/**
* Hack TabsUtil,getHeight to override SDK
*/
private void hackTabsGetHeight() throws
NotFoundException,
CannotCompileException {
final ClassPool cp = new ClassPool(true);
cp.insertClassPath(new ClassClassPath(TabInfo.class));
final CtClass ctClass = cp.get("com.intellij.ui.tabs.impl.TabLabel");
final CtMethod ctMethod = ctClass.getDeclaredMethod("getPreferredSize");
ctMethod.instrument(new ExprEditor() {
@Override
public void edit(final MethodCall m) throws CannotCompileException {
if (m.getClassName().equals("com.intellij.ui.tabs.TabsUtil") && m.getMethodName().equals("getTabsHeight")) {
final String code = String.format("com.intellij.ide.util.PropertiesComponent.getInstance().getInt(\"%s\", 25)", TABS_HEIGHT);
final String isDebugTab = "myInfo.getTabActionPlace() != null ? myInfo.getTabActionPlace().contains(\"debugger\") : true";
m.replace(String.format("{ $_ = com.intellij.util.ui.JBUI.scale(%s); }", code));
}
}
});
ctClass.toClass();
// Hack JBRunnerTabs
final CtClass tabLabelClass = cp.get("com.intellij.execution.ui.layout.impl.JBRunnerTabs$MyTabLabel");
final CtMethod ctMethod2 = tabLabelClass.getDeclaredMethod("getPreferredSize");
ctMethod2.instrument(new ExprEditor() {
@Override
public void edit(final FieldAccess f) throws CannotCompileException {
if (f.getFieldName().equals("height") && f.isReader()) {
f.replace("{ $_ = com.intellij.util.ui.JBUI.scale(25); }");
}
}
});
tabLabelClass.toClass();
}
示例12: getMethodBody
import javassist.expr.MethodCall; //导入依赖的package包/类
private String getMethodBody(MethodCall methodCall, String afterAction) {
return "{" +
" foo.bar.SQLAgentMethodProcessor.preInvoke(\"" + methodCall.getMethodName() + "\", $args);" +
" try { " +
" $_ = $proceed($$); " +
" } finally {" +
" if (foo.bar.SQLAgentMethodProcessor.postInvoke()) {" +
" " + afterAction +
" }" +
" }" +
"}";
}
示例13: edit
import javassist.expr.MethodCall; //导入依赖的package包/类
public void edit(final MethodCall methodCall) throws CannotCompileException {
isSameMethodName = methodCall.getMethodName().equals(expectedMethodCalledName);
isSameSignature = methodCall.getSignature().equals(parentMethodSignature);
try {
isSameGenericSignature = methodCall.getMethod().getGenericSignature() != null
? methodCall.getMethod().getGenericSignature().equals(parentMethodGenericSignature) : true;
isExpectedCalledClass = methodCall.getMethod().getDeclaringClass().getName().equals(
expectedCalledClass);
} catch (NotFoundException e) {
e.printStackTrace();
}
}
示例14: 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);
}
}
}
}
示例15: edit
import javassist.expr.MethodCall; //导入依赖的package包/类
@Override
public void edit(MethodCall calledMethod) {
try {
methodCalled = methodCalled || expectedMethod.equals(calledMethod.getMethod());
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
}