Skip to content

Commit

Permalink
InstrumentClass.addDelegatorMethod() returns InstrumentMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
lioolli committed Sep 3, 2015
1 parent de38a27 commit d94037c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Expand Up @@ -87,7 +87,7 @@ public interface InstrumentClass {
* You should check that class already have Declared method.
* If class already have method, this method throw exception.
*/
void addDelegatorMethod(String methodName, String[] args) throws InstrumentException;
InstrumentMethod addDelegatorMethod(String methodName, String... paramTypes) throws InstrumentException;

byte[] toBytecode() throws InstrumentException;

Expand Down
Expand Up @@ -302,21 +302,23 @@ public void weave(String adviceClassName) throws InstrumentException {
}

@Override
public void addDelegatorMethod(String methodName, String[] args) throws InstrumentException {
if (getCtMethod0(ctClass, methodName, args) != null) {
public InstrumentMethod addDelegatorMethod(String methodName, String... paramTypes) throws InstrumentException {
if (getCtMethod0(ctClass, methodName, paramTypes) != null) {
throw new InstrumentException(getName() + "already have method(" + methodName + ").");
}

try {
final CtClass superClass = ctClass.getSuperclass();
CtMethod superMethod = getCtMethod0(superClass, methodName, args);
CtMethod superMethod = getCtMethod0(superClass, methodName, paramTypes);

if (superMethod == null) {
throw new NotFoundInstrumentException(methodName + Arrays.toString(args) + " is not found in " + superClass.getName());
throw new NotFoundInstrumentException(methodName + Arrays.toString(paramTypes) + " is not found in " + superClass.getName());
}

CtMethod delegatorMethod = CtNewMethod.delegator(superMethod, ctClass);
ctClass.addMethod(delegatorMethod);

return new JavassistMethod(pluginContext, interceptorRegistryBinder, this, delegatorMethod);
} catch (NotFoundException ex) {
throw new InstrumentException(getName() + "don't have super class(" + getSuperClass() + "). Cause:" + ex.getMessage(), ex);
} catch (CannotCompileException ex) {
Expand Down

0 comments on commit d94037c

Please sign in to comment.