@Override public void edit(NewExpr e) throws CannotCompileException { String code = "Object instance =" + MockGateway.class.getName() + ".newInstanceCall($type,$args,$sig);" + "if(instance != " + MockGateway.class.getName() + ".PROCEED) {" + " if(instance instanceof java.lang.reflect.Constructor) {" + " $_ = ($r) sun.reflect.ReflectionFactory.getReflectionFactory().newConstructorForSerialization($type, java.lang.Object.class.getDeclaredConstructor(null)).newInstance(null);" + " } else {" + " $_ = ($r) instance;" + " }" + "} else {" + " $_ = $proceed($$);" + "}"; // TODO Change to objenisis instead e.replace(code); }
@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;"); } }
/** Replaces constructor call with standard non optimized invocation code. Up to subclasses to override this behaviour */ protected void replaceConCallInCon(ConByConDetail cd)throws CannotCompileException, NotFoundException { String replaced = conByConInfoFromWeakReference("info", cd.callerInfoField) + "if (info.getInterceptors() != (org.jboss.aop.advice.Interceptor[])null) { " + "$_ = ($r)aop$classAdvisor$aop.invokeConCalledByCon(info, this, $args);" + //+ cd.callingIndex + ", $args, " + cd.callerInfoField + "); " + "} else { " + "$_ = $proceed($$); " + "}"; cd.call.replace(replaced); }
@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;"); } }
/** @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);"); } }
protected void replaceConCallInCon(ConByConDetail cd)throws CannotCompileException, NotFoundException { String advisor = "((" + GeneratedAdvisorInstrumentor.getAdvisorFQN(callingClass) + ")" + GeneratedAdvisorInstrumentor.GET_CURRENT_ADVISOR + ")"; final int paramsLength = cd.calledConstructor.getParameterTypes().length; String args = "this" + ((paramsLength > 0)?", $$": ""); String replaced = "$_ = " + advisor + "." + cd.callerInfoField + "(" + args + ");"; try { cd.call.replace(replaced); } catch(CannotCompileException e) { logger.error("Error for " + cd.callingIndex + " code:" + replaced); throw e; } } }
@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);
/** Replaces constructor call with standard non optimized invocation code. Up to subclasses to override this behaviour */ protected void replaceConCallInMethod(ConByMethodDetail cd) throws NotFoundException, CannotCompileException { String callingObject = "null"; if (!Modifier.isStatic(cd.where.getModifiers())) { callingObject = "this"; } String replaced = conByMethodInfoFromWeakReference("info", cd.callerInfoField) + "if (info.getInterceptors() != (org.jboss.aop.advice.Interceptor[])null) { " + "java.lang.Object callingObject = " + callingObject + "; " + "$_ = ($r)aop$classAdvisor$aop.invokeConCalledByMethod(info, " + callingObject + ", $args);" + //+ cd.callingHash + "L, $args, " + cd.callerInfoField + ", callingObject); " + "} else { " + "$_ = $proceed($$); " + "}"; cd.call.replace(replaced); }
protected void replaceConCallInCon(ConByConDetail cd)throws CannotCompileException, NotFoundException { //If target constructor is advisable we do not want to create an optimized invocation class //since the interceptor chain for its execution pointcut does not get invoked. if (cd.isTgtConAdvised) { super.replaceConCallInCon(cd); return; } String invocationClassName = callerInfos.get(cd.callerInfoField); String replaced = conByConInfoFromWeakReference("info", cd.callerInfoField) + "if (info.getInterceptors() != (org.jboss.aop.advice.Interceptor[])null) { " + invocationClassName + " invocation = new " + invocationClassName + "(info, this, $args, info.getInterceptors());" + OptimizedBehaviourInvocations.setArguments(cd.calledConstructor.getParameterTypes().length) + "$_ = ($r)invocation.invokeNext();" + "} else { " + "$_ = $proceed($$); " + "}"; cd.call.replace(replaced); } }
@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);
protected void replaceConCallInMethod(ConByMethodDetail cd) throws NotFoundException, CannotCompileException { final int paramsLength = cd.calledConstructor.getParameterTypes().length; String args = null; String advisor = null; if (!Modifier.isStatic(cd.where.getModifiers())) { args = "this" + ((paramsLength > 0) ? ", $$" : ""); advisor = "((" + GeneratedAdvisorInstrumentor.getAdvisorFQN(callingClass) + ")" + GeneratedAdvisorInstrumentor.GET_CURRENT_ADVISOR + ")"; } else { args = ((paramsLength > 0) ? "$$" : ""); advisor = " ((" + GeneratedAdvisorInstrumentor.getAdvisorFQN(callingClass) + ")" + Instrumentor.HELPER_FIELD_NAME + ")"; } String replaced = "$_ = " + advisor + "." + cd.callerInfoField + "(" + args + ");"; try { cd.call.replace(replaced); } catch(CannotCompileException e) { logger.error("Error for " + cd.where + " code:" + replaced); throw e; } }
protected void replaceConCallInMethod(ConByMethodDetail cd) throws NotFoundException, CannotCompileException { //If target constructor is advisable we do not want to create an optimized invocation class //since the interceptor chain for its execution pointcut does not get invoked. if (cd.isTgtConAdvised) { super.replaceConCallInMethod(cd); return; } String callingObject = "null"; if (!Modifier.isStatic(cd.where.getModifiers())) { callingObject = "this"; } String invocationClassName = callerInfos.get(cd.callerInfoField); String replaced = conByMethodInfoFromWeakReference("info", cd.callerInfoField) + "if (info.getInterceptors() != (org.jboss.aop.advice.Interceptor[])null) { " + "java.lang.Object callingObject = " + callingObject + "; " + invocationClassName + " invocation = new " + invocationClassName + " (info," + callingObject + ", $args, info.getInterceptors());" + OptimizedBehaviourInvocations.setArguments(cd.calledConstructor.getParameterTypes().length) + "$_ = ($r)invocation.invokeNext();" + "} else { " + "$_ = $proceed($$); " + "}"; cd.call.replace(replaced); }