CtConstructor cons = CtNewConstructor.make(c.getParameterTypes(), c.getExceptionTypes(), this); cons.setModifiers(mod & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE)); addConstructor(cons);
CtConstructor cons = CtNewConstructor.make(c.getParameterTypes(), c.getExceptionTypes(), this); cons.setModifiers(mod & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE)); addConstructor(cons);
@Override public int getNumberOfSpecifiedExceptions() { try { return ctConstructor.getExceptionTypes().length; } catch (NotFoundException e) { throw new RuntimeException(e); } }
@Override public int getNumberOfSpecifiedExceptions() { try { return ctConstructor.getExceptionTypes().length; } catch (NotFoundException e) { throw new RuntimeException(e); } }
@Override public int getNumberOfSpecifiedExceptions() { try { return ctConstructor.getExceptionTypes().length; } catch (NotFoundException e) { throw new RuntimeException(e); } }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(String.format("No exception with index %d. Number of exceptions: %d", index, getNumberOfSpecifiedExceptions())); } try { return JavassistFactory.typeUsageFor(ctConstructor.getExceptionTypes()[index], typeSolver); } catch (NotFoundException e) { throw new RuntimeException(e); } }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(String.format("No exception with index %d. Number of exceptions: %d", index, getNumberOfSpecifiedExceptions())); } try { return JavassistFactory.typeUsageFor(ctConstructor.getExceptionTypes()[index], typeSolver); } catch (NotFoundException e) { throw new RuntimeException(e); } } }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(String.format("No exception with index %d. Number of exceptions: %d", index, getNumberOfSpecifiedExceptions())); } try { return JavassistFactory.typeUsageFor(ctConstructor.getExceptionTypes()[index], typeSolver); } catch (NotFoundException e) { throw new RuntimeException(e); } } }
private void addInvokeJoinPointDispatchMethod() throws CannotCompileException, NotFoundException { //This dispatch method will be called by the invokeJoinPoint() method if the joinpoint has no around advices String body = "{" + " " + advisedClass.getName() + " obj = new " + advisedClass.getName() + "($$);" + " setTargetObject(obj);" + " return obj;" + "}"; try { CtMethod dispatch = CtNewMethod.make( advisedClass, JoinPointGenerator.DISPATCH, params, advisedCtor.getExceptionTypes(), body, jp); dispatch.setModifiers(Modifier.PROTECTED); jp.addMethod(dispatch); } catch (CannotCompileException e) { throw new RuntimeException("Could not compile code " + body + " for method " + getMethodString(jp, JoinPointGenerator.DISPATCH, params), e); } }
private void addInvokeNextDispatchMethod() throws CannotCompileException, NotFoundException { //This dispatch method will be called by the invokeNext() methods for around advice String body = "{ return null;}"; try { CtMethod dispatch = CtNewMethod.make( CtClass.voidType, JoinPointGenerator.DISPATCH, EMPTY_CTCLASS_ARRAY, advisedCtor.getExceptionTypes(), body, jp); dispatch.setModifiers(Modifier.PROTECTED); jp.addMethod(dispatch); } catch (CannotCompileException e) { throw new RuntimeException("Could not compile code " + body + " for method " + getMethodString(jp, JoinPointGenerator.DISPATCH, EMPTY_CTCLASS_ARRAY), e); } }
JoinPointGenerator.DISPATCH, getInvokeJoinPointParameters(), targetCtor.getExceptionTypes(), body, jp);
private void addInvokeJoinPointDispatchMethod() throws CannotCompileException, NotFoundException { //This dispatch method will be called by the invokeJoinPoint() method if the joinpoint has no around advices String body = "{ return null;}"; try { CtMethod dispatch = CtNewMethod.make( CtClass.voidType, JoinPointGenerator.DISPATCH, params, advisedCtor.getExceptionTypes(), body, jp); dispatch.setModifiers(Modifier.PROTECTED); jp.addMethod(dispatch); } catch (CannotCompileException e) { throw new RuntimeException("Could not compile code " + body + " for method " + getMethodString(jp, JoinPointGenerator.DISPATCH, params), e); } } }
private CtMethod createWrapperMethod(CtConstructor constructor, String wrapperName, String body)throws CannotCompileException, NotFoundException { final CtClass genadvisor = ((GeneratedAdvisorInstrumentor)instrumentor).getGenadvisor(); CtClass[] params = constructor.getParameterTypes(); CtClass[] wrapperParams = new CtClass[params.length + 1]; wrapperParams[0] = constructor.getDeclaringClass(); System.arraycopy(params, 0, wrapperParams, 1, params.length); CtMethod wrapper = CtNewMethod.make( CtClass.voidType, wrapperName, wrapperParams, constructor.getExceptionTypes(), body, genadvisor); Instrumentor.addSyntheticAttribute(wrapper); genadvisor.addMethod(wrapper); return wrapper; }
public ClassInfo[] getExceptionTypes() { if (exceptionTypes == null) { try { CtClass[] types = ctConstructor.getExceptionTypes(); exceptionTypes = new ClassInfo[types.length]; for (int i = 0; i < types.length; ++i) exceptionTypes[i] = (ClassInfo) typeInfo.getFactory().getTypeInfo(types[i]); } catch (NotFoundException e) { throw JavassistTypeInfoFactoryImpl.raiseClassNotFound("for exception types of constructor", e); } } return exceptionTypes; }
/** * * @param pool The AOPClassPool to create the optimized invocation class in * @param makeInnerClass If true creates the new class as an inner class of className * @param outerClass The class to create the invocation class as an inner class of if makeInnerClass==true * @param className The full class name (including package info) of the invocation class to be created * @param superInvocation The super class of this invocation * @return The created invocation class */ public static CtClass makeInvocationClass(ClassPool pool, boolean makeInnerClass, CtClass outerClass, String className, CtClass superInvocation)throws CannotCompileException, NotFoundException { CtClass invocation = makeInvocationClassNoCtors(pool, makeInnerClass, outerClass, className, superInvocation); //Add the invocation constructor CtConstructor[] cons = superInvocation.getDeclaredConstructors(); for (int i = 0; i < cons.length; i++) { CtConstructor conTemplate = superInvocation.getDeclaredConstructors()[i]; CtConstructor icon = CtNewConstructor.make(conTemplate.getParameterTypes(), conTemplate.getExceptionTypes(), invocation); invocation.addConstructor(icon); } return invocation; }
CtConstructor cons = CtNewConstructor.make(c.getParameterTypes(), c.getExceptionTypes(), this); cons.setModifiers(mod & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE)); addConstructor(cons);
CtConstructor cons = CtNewConstructor.make(c.getParameterTypes(), c.getExceptionTypes(), this); cons.setModifiers(mod & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE)); addConstructor(cons);
template.getExceptionTypes(), invocation); invocation.addConstructor(icon);
ctors[i].getExceptionTypes(), CtNewConstructor.PASS_PARAMS, null,
protected void initialiseWrapper(int mod, CtConstructor constructor, int index) throws NotFoundException, CannotCompileException { CtClass clazz = constructor.getDeclaringClass(); CtClass[] exceptions = constructor.getExceptionTypes(); String name = clazz.getSimpleName(); CtClass type = constructor.getDeclaringClass(); CtMethod wmethod = CtNewMethod.make(type, constructorFactory(name), constructor.getParameterTypes(), exceptions, null, clazz); wmethod.setModifiers(mod); setTemporaryWrapperCode(type, wmethod); Instrumentor.addSyntheticAttribute(wmethod); clazz.addMethod(wmethod); // copy attribute signature MethodInfo constructorInfo = constructor.getMethodInfo2(); SignatureAttribute attribute = (SignatureAttribute) constructorInfo.getAttribute(SignatureAttribute.tag); if (attribute != null) { MethodInfo wrapperInfo = wmethod.getMethodInfo2(); @SuppressWarnings("unchecked") HashMap map = new HashMap(); wrapperInfo.addAttribute(attribute.copy(wrapperInfo.getConstPool(), map)); } // prepare ForWrapping getWrapper().prepareForWrapping(constructor, CONSTRUCTOR_STATUS); }