/**
* Evaluate <code>expression</code> to boolean
+ *
* @param expression expression to evaluate
* @return result
- *
- * @deprecated This method is used to evaluate breakpoints' conditions only. Instead of implementing it you should evaluate breakpoint's condition
- * in your code and call {@link XDebugSession#breakpointReached(XBreakpoint, XSuspendContext)}
- * only if the condition evaluates to <code>true</code>.
- *
* @see XBreakpoint#getCondition()
+ * @deprecated This method is used to evaluate breakpoints' conditions only. Instead of implementing it you should evaluate breakpoint's condition
+ * in your code and call {@link XDebugSession#breakpointReached(XBreakpoint, XSuspendContext)}
+ * only if the condition evaluates to <code>true</code>.
*/
@Deprecated
public boolean evaluateCondition(@NotNull String expression) {
/**
* Evaluate <code>expression</code> to string
+ *
* @param expression expression to evaluate
* @return result
- *
* @deprecated This method is used to evaluate breakpoints' log messages only. Instead of implementing it you should evaluate breakpoint's
- * log message in your code and pass it to {@link XDebugSession#breakpointReached(XBreakpoint, String, XSuspendContext)}.
+ * log message in your code and pass it to {@link XDebugSession#breakpointReached(XBreakpoint, String, XSuspendContext)}.
*/
@Deprecated
@Nullable
/**
* Start evaluating expression.
+ *
* @param expression expression to evaluate
- * @param callback used to notify that the expression has been evaluated or an error occurs
+ * @param callback used to notify that the expression has been evaluated or an error occurs
*/
public void evaluate(@NotNull String expression, XEvaluationCallback callback, @Nullable XSourcePosition expressionPosition) {
evaluate(expression, callback);
public void evaluate(@NotNull String expression, XEvaluationCallback callback) {
}
+
+ /**
+ * @return true if CopyValue action should execute evaluateCopy method
+ * @param node
+ */
+ public boolean isEvaluateOnCopy(String name, String value) {
+ return false;
+ }
+
+ public void evaluateFull(@NotNull String expression, XEvaluationCallback callback, @Nullable XSourcePosition expressionPosition) {
+ evaluate(expression, callback, expressionPosition);
+ }
+
/**
* Return text range of expression which can be evaluated.
- * @param project project
+ *
+ * @param project project
* @param document document
- * @param offset offset
+ * @param offset offset
* @return text range of expression
*/
@Nullable
*/
package com.intellij.xdebugger.impl.ui.tree.actions;
-import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ide.CopyPasteManager;
+import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
+import com.intellij.xdebugger.frame.XSuspendContext;
+import com.intellij.xdebugger.frame.XValue;
+import com.intellij.xdebugger.impl.XDebuggerUtilImpl;
+import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
import org.jetbrains.annotations.NotNull;
import java.awt.datatransfer.StringSelection;
*/
public class XCopyValueAction extends XDebuggerTreeActionBase {
protected void perform(final XValueNodeImpl node, @NotNull final String nodeName, final AnActionEvent e) {
- //todo[nik] is it correct? Perhaps we should use evaluator.evaluateMessage here
- String value = node.getValue();
+ XSuspendContext suspendContext = node.getTree().getSession().getSuspendContext();
+ XDebuggerEvaluator evaluator = XDebuggerUtilImpl.getEvaluator(suspendContext);
+ if (evaluator != null && evaluator.isEvaluateOnCopy(node.getName(), node.getValue())) {
+ evaluator.evaluateFull(node.getName(), new XDebuggerEvaluator.XEvaluationCallback() {
+ @Override
+ public void evaluated(@NotNull XValue result) {
+ String value = result.getModifier().getInitialValueEditorText();
+ setCopyContents(value);
+ }
+
+ @Override
+ public void errorOccurred(@NotNull String errorMessage) {
+ String value = node.getValue();
+ setCopyContents(value);
+ }
+ }, null);
+ } else {
+ String value = node.getValue();
+ setCopyContents(value);
+ }
+
+ }
+
+ private static void setCopyContents(String value) {
CopyPasteManager.getInstance().setContents(new StringSelection(value));
}