@Override public void edit(NewExpr e) throws CannotCompileException { try { put(e.getConstructor().getDeclaringClass().getName() + "." + "<init>" + "(" + parameterNames(e.getConstructor().getMethodInfo()) + ")", e.getLineNumber(), key); } catch (NotFoundException e1) { throw new ReflectionsException("Could not find new instance usage in " + key, e1); } }
int codeSize = canReplace(); int end = pos + codeSize; for (int i = pos; i < end; ++i) iterator.writeByte(NOP, i); ConstPool constPool = getConstPool(); pos = currentPos; int methodIndex = iterator.u16bitAt(pos + 1); // constructor int paramVar = ca.getMaxLocals(); jc.recordParams(newTypeName, params, true, paramVar, withinStatic()); int retVar = jc.recordReturnType(newType, true); jc.recordProceed(new ProceedForNew(newType, newIndex, checkResultValue(newType, statement); storeStack(params, true, paramVar, bytecode); jc.recordLocalVariables(ca, pos); bytecode.addAload(retVar); replace0(pos, bytecode, bytecodeSize);
/** * Returns the constructor called for creating the object. */ public CtConstructor getConstructor() throws NotFoundException { ConstPool cp = getConstPool(); int index = iterator.u16bitAt(currentPos + 1); String desc = cp.getMethodrefType(index); return getCtClass().getConstructor(desc); }
@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);
/** * Get the signature of the constructor * * The signature is represented by a character string * called method descriptor, which is defined in the JVM specification. * * @see javassist.CtBehavior#getSignature() * @see javassist.bytecode.Descriptor * @return the signature */ public String getSignature() { ConstPool constPool = getConstPool(); int methodIndex = iterator.u16bitAt(currentPos + 1); // constructor return constPool.getMethodrefType(methodIndex); }
&& minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr);
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. } }
ConByConDetail(CallerExprEditor editor, NewExpr call, String classname)throws NotFoundException { this.call = call; con = (CtConstructor) call.where(); callingIndex = editor.constructors.indexOf(con); calledHash = JavassistMethodHashing.constructorHash(call.getConstructor()); callerInfoField = getConByConInfoName(callingIndex, classname, calledHash); calledConstructor = call.getConstructor(); this.classname = classname; isTgtConAdvised = isTargetConstructorAdvised(calledConstructor); } }
public Object visit(ASTHasField node, Object data) { ASTField f = (ASTField) node.jjtGetChild(0); CtConstructor con = null; try { con = call.getConstructor(); } catch (NotFoundException e) { throw new RuntimeException(e); //To change body of catch statement use Options | File Templates. } return new Boolean(Util.has(con.getDeclaringClass(), f, advisor)); } }
@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);
/** * Get the signature of the constructor * * The signature is represented by a character string * called method descriptor, which is defined in the JVM specification. * * @see javassist.CtBehavior#getSignature() * @see javassist.bytecode.Descriptor * @return the signature */ public String getSignature() { ConstPool constPool = getConstPool(); int methodIndex = iterator.u16bitAt(currentPos + 1); // constructor return constPool.getMethodrefType(methodIndex); }
&& minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr);
ConByMethodDetail(CallerExprEditor editor, NewExpr call, String classname)throws NotFoundException { this.call = call; where = (CtMethod) call.where(); callingHash = JavassistMethodHashing.methodHash(where); calledHash = JavassistMethodHashing.constructorHash(call.getConstructor()); callerInfoField = getConByMethodInfoName(callingHash, classname, calledHash); calledConstructor = call.getConstructor(); this.classname = classname; isTgtConAdvised = isTargetConstructorAdvised(calledConstructor); } }
public Object visit(ASTHas node, Object data) { try { Node n = node.jjtGetChild(0); CtConstructor con = call.getConstructor(); if (n instanceof ASTMethod) { return new Boolean(Util.has(con.getDeclaringClass(), (ASTMethod) n, advisor)); } else { return new Boolean(Util.has(con.getDeclaringClass(), (ASTConstructor) n, advisor)); } } catch (NotFoundException e) { throw new RuntimeException(e); //To change body of catch statement use Options | File Templates. } }
int codeSize = canReplace(); int end = pos + codeSize; for (int i = pos; i < end; ++i) iterator.writeByte(NOP, i); ConstPool constPool = getConstPool(); pos = currentPos; int methodIndex = iterator.u16bitAt(pos + 1); // constructor int paramVar = ca.getMaxLocals(); jc.recordParams(newTypeName, params, true, paramVar, withinStatic()); int retVar = jc.recordReturnType(newType, true); jc.recordProceed(new ProceedForNew(newType, newIndex, checkResultValue(newType, statement); storeStack(params, true, paramVar, bytecode); jc.recordLocalVariables(ca, pos); bytecode.addAload(retVar); replace0(pos, bytecode, bytecodeSize);
/** * Returns the constructor called for creating the object. */ public CtConstructor getConstructor() throws NotFoundException { ConstPool cp = getConstPool(); int index = iterator.u16bitAt(currentPos + 1); String desc = cp.getMethodrefType(index); return getCtClass().getConstructor(desc); }
@Override public void edit(NewExpr e) throws CannotCompileException { try { put(e.getConstructor().getDeclaringClass().getName() + "." + "<init>" + "(" + parameterNames(e.getConstructor().getMethodInfo()) + ")", e.getLineNumber(), key); } catch (NotFoundException e1) { throw new ReflectionsException("Could not find new instance usage in " + key, e1); } }
/** * Get the signature of the constructor * * The signature is represented by a character string * called method descriptor, which is defined in the JVM specification. * * @see javassist.CtBehavior#getSignature() * @see javassist.bytecode.Descriptor * @return the signature */ public String getSignature() { ConstPool constPool = getConstPool(); int methodIndex = iterator.u16bitAt(currentPos + 1); // constructor return constPool.getMethodrefType(methodIndex); }
&& minfo.getConstPool().isConstructor(newList.type, iterator.u16bitAt(pos + 1)) > 0) { expr = new NewExpr(pos, iterator, clazz, minfo, newList.type, newList.pos); edit((NewExpr)expr);
CtBehavior caller = newcall.where(); if (caller instanceof CtConstructor) addConstructor(sb, con); sb.append(" calls "); addConstructor(sb, newcall.getConstructor()); addMethod(sb, met); sb.append(" calls "); addConstructor(sb, newcall.getConstructor());