@Override public void edit(final NewExpr expr) throws CannotCompileException { final String name = expr.getClassName(); if (name.startsWith("java.awt.Menu") || name.equals("java.awt.PopupMenu") || name.startsWith("java.awt.Checkbox") || name.equals("java.awt.Frame")) { expr.replace("$_ = null;"); } else if (expr.getClassName().equals("ij.gui.StackWindow")) { expr.replace("$1.show(); $_ = null;"); } }
@Override public void edit(final NewExpr expr) throws CannotCompileException { final String name = expr.getClassName(); if (name.startsWith("java.awt.Menu") || name.equals("java.awt.PopupMenu") || name.startsWith("java.awt.Checkbox") || name.equals("java.awt.Frame")) { expr.replace("$_ = null;"); } else if (expr.getClassName().equals("ij.gui.StackWindow")) { expr.replace("$1.show(); $_ = null;"); } }
@Override public void edit(final NewExpr expr) throws CannotCompileException { if (debug) { System.err.println("editing call " + expr.getClassName() + "#" + "<init>" + " (wanted " + calledClass + "#" + calledMethodName + ")"); } if ("<init>".equals(calledMethodName) && expr.getClassName().equals(calledClass)) { if (onlyNth > 0 && ++counter != onlyNth) return; expr.replace(newCode); markEdited(); } } }.instrument(method);
@Override public void edit(final NewExpr expr) throws CannotCompileException { if (debug) { System.err.println("editing call " + expr.getClassName() + "#" + "<init>" + " (wanted " + calledClass + "#" + calledMethodName + ")"); } if ("<init>".equals(calledMethodName) && expr.getClassName().equals(calledClass)) { if (onlyNth > 0 && ++counter != onlyNth) return; expr.replace(newCode); markEdited(); } } }.instrument(method);
/** @param newExpr @throws CannotCompileException */ public void edit(NewExpr newExpr) throws CannotCompileException { String signature = newExpr.getClassName() + newExpr.getSignature(); if (exceptionCtors.contains(signature)) { newExpr.replace("$_ = " + EXCEPTION_HELPER + ".createExceptionWithCause($class, $args);"); } else if (CTOR_TIMER1.equals(signature)) { newExpr.replace("$_ = new " + TIMER + "();"); } else if (CTOR_TIMER2.equals(signature)) { newExpr.replace("$_ = new " + TIMER + "($2);"); } }
@Override public void edit(final NewExpr expr) throws CannotCompileException { if (expr.getClassName().equals(newClassName)) try { final CtClass[] parameterTypes = expr.getConstructor().getParameterTypes(); if (parameterTypes[parameterIndex - 1] != CodeHacker.this .getClass("java.lang.String")) { maybeThrow(new IllegalArgumentException("Parameter " + parameterIndex + " of " + expr.getConstructor() + " is not a String!")); return; } final String replace = replaceAppName(parameterIndex, parameterTypes.length, replacement); expr.replace("$_ = new " + newClassName + replace + ";"); markEdited(); } catch (final NotFoundException e) { maybeThrow(new IllegalArgumentException( "Cannot find the parameters of the constructor of " + newClassName, e)); } } }.instrument(method);
@Override public void edit(final NewExpr expr) throws CannotCompileException { if (expr.getClassName().equals(newClassName)) try { final CtClass[] parameterTypes = expr.getConstructor().getParameterTypes(); if (parameterTypes[parameterIndex - 1] != CodeHacker.this .getClass("java.lang.String")) { maybeThrow(new IllegalArgumentException("Parameter " + parameterIndex + " of " + expr.getConstructor() + " is not a String!")); return; } final String replace = replaceAppName(parameterIndex, parameterTypes.length, replacement); expr.replace("$_ = new " + newClassName + replace + ";"); markEdited(); } catch (final NotFoundException e) { maybeThrow(new IllegalArgumentException( "Cannot find the parameters of the constructor of " + newClassName, e)); } } }.instrument(method);
String classname = call.getClassName(); if (classname.startsWith("org.jboss.aop.") || !Instrumentor.isTransformable(callingClass))
public Object visit(ASTCall node, Object data) { try { if (!(node.getBehavior() instanceof ASTConstructor)) return Boolean.FALSE; ASTConstructor astCon = (ASTConstructor) node.getBehavior(); // do simple checks to avoid loading CtClasses if (astCon.getClazz().isSimple()) { if (!astCon.getClazz().matches(call.getClassName())) return Boolean.FALSE; } CtConstructor calledCon = call.getConstructor(); ClassAdvisor calledAdvisor = AspectManager.instance().getTempClassAdvisor(calledCon.getDeclaringClass()); ConstructorMatcher conMatcher = new ConstructorMatcher(calledAdvisor, calledCon, null); return conMatcher.matches(astCon); } catch (Exception e) { throw new RuntimeException(e); //To change body of catch statement use Options | File Templates. } }