package jetbrains.mps.debugger.java.runtime.ui.actions;
/*Generated by MPS */
import jetbrains.mps.workbench.action.BaseAction;
import javax.swing.Icon;
import org.jetbrains.annotations.NotNull;
import com.intellij.openapi.actionSystem.AnActionEvent;
import java.util.Map;
import jetbrains.mps.debug.api.programState.IValue;
import jetbrains.mps.debugger.api.ui.tree.VariablesTree;
import jetbrains.mps.debugger.java.api.state.proxy.JavaValue;
import jetbrains.mps.debugger.api.ui.DebugActionsUtil;
import jetbrains.mps.debug.api.AbstractUiState;
import jetbrains.mps.debugger.java.api.state.JavaUiState;
import com.sun.jdi.ThreadReference;
import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes;
import jetbrains.mps.debugger.java.api.evaluation.EvaluationUtils;
import jetbrains.mps.ide.datatransfer.CopyPasteUtil;
import jetbrains.mps.debug.api.AbstractDebugSession;
import jetbrains.mps.debugger.java.api.state.proxy.JavaThread;
public class CopyValueAction_Action extends BaseAction {
private static final Icon ICON = null;
public CopyValueAction_Action() {
super("Copy Value", "", ICON);
this.setIsAlwaysVisible(false);
this.setExecuteOutsideCommand(false);
}
@Override
public boolean isDumbAware() {
return true;
}
@Override
public void doUpdate(@NotNull AnActionEvent event, final Map<String, Object> _params) {
IValue value = VariablesTree.MPS_DEBUGGER_VALUE.getData(event.getDataContext());
event.getPresentation().setVisible(value != null && value instanceof JavaValue && DebugActionsUtil.getEvaluationProvider(event) != null);
}
@Override
public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) {
final IValue value = VariablesTree.MPS_DEBUGGER_VALUE.getData(event.getDataContext());
if (value == null || !(value instanceof JavaValue)) {
return;
}
AbstractUiState uiState = check_d54g7t_a0d0a(DebugActionsUtil.getDebugSession(event));
if (uiState == null || !(uiState instanceof JavaUiState)) {
return;
}
JavaUiState javaUiState = (JavaUiState) uiState;
final ThreadReference thread = check_d54g7t_a0h0a(javaUiState.getThread());
if (thread == null) {
return;
}
String result = javaUiState.invokeEvaluationSynchronously(new _FunctionTypes._return_P0_E0<String>() {
public String invoke() {
return EvaluationUtils.getInstance().getStringPresentation(((JavaValue) value).getValue().getJDIValue(), thread);
}
});
if ((result != null && result.length() > 0)) {
CopyPasteUtil.copyTextToClipboard(result);
}
}
private static AbstractUiState check_d54g7t_a0d0a(AbstractDebugSession checkedDotOperand) {
if (null != checkedDotOperand) {
return checkedDotOperand.getUiState();
}
return null;
}
private static ThreadReference check_d54g7t_a0h0a(JavaThread checkedDotOperand) {
if (null != checkedDotOperand) {
return checkedDotOperand.getThread();
}
return null;
}
}