Merge remote-tracking branch 'origin/master'

This commit is contained in:
Roman Shevchenko
2014-10-16 20:08:45 +02:00
4 changed files with 75 additions and 20 deletions
@@ -15,6 +15,7 @@
*/
package com.intellij.debugger.engine;
import com.intellij.codeInsight.CodeInsightUtil;
import com.intellij.debugger.engine.evaluation.EvaluateException;
import com.intellij.debugger.engine.evaluation.EvaluationContextImpl;
import com.intellij.debugger.engine.evaluation.TextWithImports;
@@ -24,17 +25,21 @@ import com.intellij.debugger.impl.EditorTextProvider;
import com.intellij.debugger.ui.impl.watch.NodeManagerImpl;
import com.intellij.debugger.ui.impl.watch.WatchItemDescriptor;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.xdebugger.XExpression;
import com.intellij.xdebugger.XSourcePosition;
import com.intellij.xdebugger.evaluation.EvaluationMode;
import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
import com.intellij.xdebugger.impl.breakpoints.XExpressionImpl;
import com.intellij.xdebugger.impl.ui.XDebuggerEditorBase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -126,4 +131,16 @@ public class JavaDebuggerEvaluator extends XDebuggerEvaluator {
}
return null;
}
@Override
public XExpression getEditorExpression(@NotNull Editor editor, @Nullable PsiFile psiFile) {
String text = editor.getSelectionModel().getSelectedText();
if (psiFile == null || StringUtil.isEmpty(text)) {
return super.getEditorExpression(editor, psiFile);
}
PsiElement[] range = CodeInsightUtil.findStatementsInRange(psiFile, editor.getSelectionModel().getSelectionStart(),
editor.getSelectionModel().getSelectionEnd());
return new XExpressionImpl(formatTextForEvaluation(text), XDebuggerEditorBase.getFileTypeLanguage(psiFile.getFileType()), null,
range.length > 1 ? EvaluationMode.CODE_FRAGMENT : EvaluationMode.EXPRESSION);
}
}
@@ -16,10 +16,14 @@
package com.intellij.xdebugger.evaluation;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiFile;
import com.intellij.xdebugger.XDebugSession;
import com.intellij.xdebugger.XDebuggerUtil;
import com.intellij.xdebugger.XExpression;
import com.intellij.xdebugger.XSourcePosition;
import com.intellij.xdebugger.breakpoints.XBreakpoint;
@@ -169,6 +173,30 @@ public abstract class XDebuggerEvaluator {
return text;
}
/**
* Returns expression that is selected or under the cursor in the Editor
*/
public XExpression getEditorExpression(@NotNull Editor editor, @Nullable PsiFile psiFile) {
String text = editor.getSelectionModel().getSelectedText();
if (text != null) {
text = formatTextForEvaluation(text);
}
else if (editor.getProject() != null) {
Document document = editor.getDocument();
ExpressionInfo info = getExpressionInfoAtOffset(editor.getProject(), document, editor.getCaretModel().getOffset(), true);
if (info != null) {
text = info.getExpressionText();
if (text == null) {
text = document.getText(info.getTextRange());
}
}
}
if (!StringUtil.isEmpty(text)) {
return XDebuggerUtil.getInstance().createExpression(text, null, null, text.contains("\n") ? EvaluationMode.CODE_FRAGMENT : EvaluationMode.EXPRESSION);
}
return null;
}
@Deprecated
/**
* @return delay before showing value tooltip (in ms)
@@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.xdebugger.XDebugSession;
@@ -53,23 +54,34 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler {
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
String selectedText = editor != null ? editor.getSelectionModel().getSelectedText() : null;
if (selectedText != null) {
selectedText = evaluator.formatTextForEvaluation(selectedText);
}
String text = selectedText;
if (text == null && editor != null) {
text = getExpressionText(evaluator, CommonDataKeys.PROJECT.getData(dataContext), editor);
XExpression expression = null;
if (editor != null) {
expression = evaluator.getEditorExpression(editor, CommonDataKeys.PSI_FILE.getData(dataContext));
}
if (text == null) {
Language language = calcLanguage(stackFrame, dataContext);
if (expression != null && !Comparing.equal(language, expression.getLanguage())) { // may need to change language
expression = new XExpressionImpl(expression.getExpression(), language, expression.getCustomInfo(), expression.getMode());
}
if (expression == null) {
XValue value = XDebuggerTreeActionBase.getSelectedValue(dataContext);
if (value != null) {
text = value.getEvaluationExpression();
String text = value.getEvaluationExpression();
if (!StringUtil.isEmpty(text)) {
expression = new XExpressionImpl(text, language, null);
}
}
}
if (expression == null) {
expression = new XExpressionImpl("", language, null);
}
new XDebuggerEvaluationDialog(session, editorsProvider, evaluator, expression, stackFrame == null ? null : stackFrame.getSourcePosition()).show();
}
private static Language calcLanguage(XStackFrame stackFrame, DataContext dataContext) {
Language language = null;
if (stackFrame != null) {
XSourcePosition position = stackFrame.getSourcePosition();
@@ -83,8 +95,7 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler {
language = XDebuggerEditorBase.getFileTypeLanguage(file.getFileType());
}
}
XExpression expression = new XExpressionImpl(StringUtil.notNullize(text), language, null);
new XDebuggerEvaluationDialog(session, editorsProvider, evaluator, expression, stackFrame == null ? null : stackFrame.getSourcePosition()).show();
return language;
}
@Nullable
@@ -144,6 +144,9 @@ public class XDebuggerEvaluationDialog extends DialogWrapper {
if (mode == EvaluationMode.CODE_FRAGMENT && !myIsCodeFragmentEvaluationSupported) {
mode = EvaluationMode.EXPRESSION;
}
if (mode == EvaluationMode.EXPRESSION && text.getMode() == EvaluationMode.CODE_FRAGMENT && myIsCodeFragmentEvaluationSupported) {
mode = EvaluationMode.CODE_FRAGMENT;
}
switchToMode(mode, text);
init();
}
@@ -230,8 +233,6 @@ public class XDebuggerEvaluationDialog extends DialogWrapper {
private void switchToMode(EvaluationMode mode, XExpression text) {
if (myMode == mode) return;
XDebuggerSettingsManager.getInstanceImpl().getGeneralSettings().setEvaluationDialogMode(mode);
myMode = mode;
if (mode == EvaluationMode.EXPRESSION) {
@@ -331,12 +332,10 @@ public class XDebuggerEvaluationDialog extends DialogWrapper {
@Override
public void actionPerformed(ActionEvent e) {
XExpression text = getInputEditor().getExpression();
if (myMode == EvaluationMode.EXPRESSION) {
switchToMode(EvaluationMode.CODE_FRAGMENT, text);
}
else {
switchToMode(EvaluationMode.EXPRESSION, text);
}
EvaluationMode newMode = (myMode == EvaluationMode.EXPRESSION) ? EvaluationMode.CODE_FRAGMENT : EvaluationMode.EXPRESSION;
// remember only on user selection
XDebuggerSettingsManager.getInstanceImpl().getGeneralSettings().setEvaluationDialogMode(newMode);
switchToMode(newMode, text);
}
}
}