public MethodVisitor visitMethod()

in src/main/java/com/intellij/rt/debugger/agent/CaptureAgent.java [172:223]


    public MethodVisitor visitMethod(final int access, String name, final String desc, String signature, String[] exceptions) {
      if ((access & Opcodes.ACC_BRIDGE) == 0) {
        for (final InstrumentPoint point : myInstrumentPoints) {
          if (point.matchesMethod(name, desc)) {
            final String methodDisplayName = getMethodDisplayName(point.myClassName, name, desc);
            if (CaptureStorage.DEBUG) {
              System.out.println(
                "Capture agent: instrumented " + (point.myCapture ? "capture" : "insert") + " point at " + methodDisplayName);
            }
            if (point.myCapture) { // capture
              // for constructors and "this" key - move capture to after the super constructor call
              if (CONSTRUCTOR.equals(name) && point.myKeyProvider == THIS_KEY_PROVIDER) {
                return new MethodVisitor(api, super.visitMethod(access, name, desc, signature, exceptions)) {
                  boolean captured = false;

                  @Override
                  public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
                    super.visitMethodInsn(opcode, owner, name, desc, itf);
                    if (opcode == Opcodes.INVOKESPECIAL &&
                        !captured &&
                        owner.equals(mySuperName) &&
                        name.equals(CONSTRUCTOR)) { // super constructor
                      capture(mv, point.myKeyProvider, (access & Opcodes.ACC_STATIC) != 0,
                              Type.getMethodType(desc).getArgumentTypes(), methodDisplayName);
                      captured = true;
                    }
                  }
                };
              }
              else {
                return new MethodVisitor(api, super.visitMethod(access, name, desc, signature, exceptions)) {
                  @Override
                  public void visitCode() {
                    capture(mv, point.myKeyProvider, (access & Opcodes.ACC_STATIC) != 0, Type.getMethodType(desc).getArgumentTypes(),
                            methodDisplayName);
                    super.visitCode();
                  }
                };
              }
            }
            else { // insert
              if (CONSTRUCTOR.equals(name)) {
                throw new IllegalStateException("Unable to create insert point at " + methodDisplayName +". Constructors are not yet supported.");
              }
              generateWrapper(access, name, desc, signature, exceptions, point, methodDisplayName);
              return super.visitMethod(access, getNewName(name), desc, signature, exceptions);
            }
          }
        }
      }
      return super.visitMethod(access, name, desc, signature, exceptions);
    }