package com.intellij.debugger.streams.trace.smart.handler;

import com.intellij.debugger.streams.trace.EvaluateExpressionTracerBase;
import com.intellij.debugger.streams.trace.smart.handler.type.GenericType;
import com.intellij.debugger.streams.wrapper.StreamCall;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author Vitaliy.Bibaev
 */
public class PeekTracerHandler extends HandlerBase {
  private final HashMapVariableImpl myBeforeVariable;
  private final HashMapVariableImpl myAfterVariable;

  public PeekTracerHandler(int num, @NotNull String name) {
    final String variablePrefix = String.format("%sPeek%d", name, num);
    myBeforeVariable = new HashMapVariableImpl(variablePrefix + "before", GenericType.INT, GenericType.OBJECT, true);
    myAfterVariable = new HashMapVariableImpl(variablePrefix + "after", GenericType.INT, GenericType.OBJECT, true);
  }

  @NotNull
  @Override
  public List<StreamCall> additionalCallsBefore() {
    final String beforeMapName = myBeforeVariable.getName();
    return Collections.singletonList(new PeekCall(String.format("x -> %s.put(time.get(), x)", beforeMapName)));
  }

  @NotNull
  @Override
  public List<StreamCall> additionalCallsAfter() {
    final String afterMapName = myBeforeVariable.getName();
    return Collections.singletonList(new PeekCall(String.format("x -> %s.put(time.incrementAndGet(), x)", afterMapName)));
  }

  @NotNull
  @Override
  public String prepareResult() {
    final String beforeConversion = myBeforeVariable.convertToArray("beforeArray", true, false);
    final String afterConversion = myAfterVariable.convertToArray("afterArray", true, false);
    return beforeConversion + EvaluateExpressionTracerBase.LINE_SEPARATOR + afterConversion;
  }

  @NotNull
  @Override
  public String getResultExpression() {
    return "new Object[] {beforeArray, afterArray}";
  }

  @NotNull
  @Override
  protected List<Variable> getVariables() {
    return Arrays.asList(myBeforeVariable, myAfterVariable);
  }
}

@@ -1299,38 +1299,37 @@
 fterMapName = my
-Before
+After
 Variable.getName
@@ -1452,32 +1452,214 @@
 apName)));%0A  %7D%0A%0A
+  @NotNull%0A  public String getBeforeMapName() %7B%0A    return myBeforeVariable.getName();%0A  %7D%0A%0A  @NotNull%0A  public String getAfterMapName() %7B%0A    return myAfterVariable.getName();%0A  %7D%0A%0A
   @NotNull%0A  @Ov

Fix type, add getter names of peek trace variables