diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebuggerEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebuggerEvaluator.java
index 68c15d4e73c9..6649ff3516ac 100644
--- a/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebuggerEvaluator.java
+++ b/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebuggerEvaluator.java
@@ -25,12 +25,10 @@ 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;
@@ -39,7 +37,6 @@ 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;
@@ -133,14 +130,11 @@ public class JavaDebuggerEvaluator extends XDebuggerEvaluator {
}
@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);
+ public EvaluationMode getEvaluationMode(@NotNull String text, int startOffset, int endOffset, @Nullable PsiFile psiFile) {
+ if (psiFile != null) {
+ PsiElement[] range = CodeInsightUtil.findStatementsInRange(psiFile, startOffset, endOffset);
+ return range.length > 1 ? EvaluationMode.CODE_FRAGMENT : EvaluationMode.EXPRESSION;
}
- 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);
+ return super.getEvaluationMode(text, startOffset, endOffset, null);
}
}
diff --git a/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTest.java b/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTest.java
index 5d1c5051ee2e..8811ebcfad89 100644
--- a/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTest.java
+++ b/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTest.java
@@ -16,13 +16,8 @@
package com.intellij.psi;
import com.intellij.openapi.application.ex.PathManagerEx;
-import com.intellij.openapi.command.CommandProcessor;
-import com.intellij.openapi.command.WriteCommandAction;
-import com.intellij.psi.codeStyle.JavaCodeStyleManager;
-import com.intellij.psi.impl.source.PostprocessReformattingAspect;
-import com.intellij.testFramework.PsiTestCase;
-public class OptimizeImportsTest extends PsiTestCase{
+public class OptimizeImportsTest extends OptimizeImportsTestCase {
private static final String BASE_PATH = PathManagerEx.getTestDataPath() + "/psi/optimizeImports";
@Override
@@ -44,37 +39,6 @@ public class OptimizeImportsTest extends PsiTestCase{
public void testNewImportListIsEmptyAndJavaDocWithInvalidCodePreserved() throws Exception { doTest(); }
private void doTest() throws Exception {
- final String extension = ".java";
- doTest(extension);
- }
-
- private void doTest(final String extension) throws Exception {
- CommandProcessor.getInstance().executeCommand(
- getProject(), new Runnable() {
- @Override
- public void run() {
- WriteCommandAction.runWriteCommandAction(null, new Runnable() {
- @Override
- public void run() {
- String fileName = getTestName(false) + extension;
- try {
- String text = loadFile(fileName);
- PsiFile file = createFile(fileName, text);
-
- JavaCodeStyleManager.getInstance(myProject).optimizeImports(file);
- PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
- PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
- String textAfter = loadFile(getTestName(false) + "_after" + extension);
- String fileText = file.getText();
- assertEquals(textAfter, fileText);
- }
- catch (Exception e) {
- LOG.error(e);
- }
- }
- });
- }
- }, "", "");
-
+ doTest(".java");
}
}
diff --git a/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTestCase.java b/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTestCase.java
new file mode 100644
index 000000000000..5c03989d6144
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTestCase.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.psi;
+
+import com.intellij.openapi.command.CommandProcessor;
+import com.intellij.openapi.command.WriteCommandAction;
+import com.intellij.psi.codeStyle.JavaCodeStyleManager;
+import com.intellij.psi.impl.source.PostprocessReformattingAspect;
+import com.intellij.testFramework.PsiTestCase;
+
+/**
+ * @author Dmitry Avdeev
+ */
+public abstract class OptimizeImportsTestCase extends PsiTestCase {
+ protected void doTest(final String extension) throws Exception {
+ CommandProcessor.getInstance().executeCommand(
+ getProject(), new Runnable() {
+ @Override
+ public void run() {
+ WriteCommandAction.runWriteCommandAction(null, new Runnable() {
+ @Override
+ public void run() {
+ String fileName = getTestName(false) + extension;
+ try {
+ String text = loadFile(fileName);
+ PsiFile file = createFile(fileName, text);
+
+ JavaCodeStyleManager.getInstance(myProject).optimizeImports(file);
+ PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
+ PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
+ String textAfter = loadFile(getTestName(false) + "_after" + extension);
+ String fileText = file.getText();
+ assertEquals(textAfter, fileText);
+ }
+ catch (Exception e) {
+ LOG.error(e);
+ }
+ }
+ });
+ }
+ }, "", "");
+
+ }
+}
diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/evaluation/XDebuggerEvaluator.java b/platform/xdebugger-api/src/com/intellij/xdebugger/evaluation/XDebuggerEvaluator.java
index d06459244216..e008252ecf85 100644
--- a/platform/xdebugger-api/src/com/intellij/xdebugger/evaluation/XDebuggerEvaluator.java
+++ b/platform/xdebugger-api/src/com/intellij/xdebugger/evaluation/XDebuggerEvaluator.java
@@ -174,27 +174,10 @@ public abstract class XDebuggerEvaluator {
}
/**
- * Returns expression that is selected or under the cursor in the Editor
+ * Returns mode which should be used to evaluate the text
*/
- 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;
+ public EvaluationMode getEvaluationMode(@NotNull String text, int startOffset, int endOffset, @Nullable PsiFile psiFile) {
+ return text.contains("\n") ? EvaluationMode.CODE_FRAGMENT : EvaluationMode.EXPRESSION;
}
@Deprecated
diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerEvaluateActionHandler.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerEvaluateActionHandler.java
index ca06ab25a13f..b6875bec0664 100644
--- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerEvaluateActionHandler.java
+++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerEvaluateActionHandler.java
@@ -21,12 +21,12 @@ 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;
import com.intellij.xdebugger.XExpression;
import com.intellij.xdebugger.XSourcePosition;
+import com.intellij.xdebugger.evaluation.EvaluationMode;
import com.intellij.xdebugger.evaluation.ExpressionInfo;
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
@@ -54,34 +54,28 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler {
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
- XExpression expression = null;
- if (editor != null) {
- expression = evaluator.getEditorExpression(editor, CommonDataKeys.PSI_FILE.getData(dataContext));
+ EvaluationMode mode = EvaluationMode.EXPRESSION;
+ String selectedText = editor != null ? editor.getSelectionModel().getSelectedText() : null;
+ if (selectedText != null) {
+ selectedText = evaluator.formatTextForEvaluation(selectedText);
+ mode = evaluator.getEvaluationMode(selectedText,
+ editor.getSelectionModel().getSelectionStart(),
+ editor.getSelectionModel().getSelectionEnd(),
+ CommonDataKeys.PSI_FILE.getData(dataContext));
+ }
+ String text = selectedText;
+
+ if (text == null && editor != null) {
+ text = getExpressionText(evaluator, CommonDataKeys.PROJECT.getData(dataContext), editor);
}
- 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) {
+ if (text == null) {
XValue value = XDebuggerTreeActionBase.getSelectedValue(dataContext);
if (value != null) {
- String text = value.getEvaluationExpression();
- if (!StringUtil.isEmpty(text)) {
- expression = new XExpressionImpl(text, language, null);
- }
+ text = value.getEvaluationExpression();
}
}
- 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();
@@ -95,7 +89,8 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler {
language = XDebuggerEditorBase.getFileTypeLanguage(file.getFileType());
}
}
- return language;
+ XExpression expression = new XExpressionImpl(StringUtil.notNullize(text), language, null, mode);
+ new XDebuggerEvaluationDialog(session, editorsProvider, evaluator, expression, stackFrame == null ? null : stackFrame.getSourcePosition()).show();
}
@Nullable
diff --git a/plugins/java-decompiler/engine/build.xml b/plugins/java-decompiler/engine/build.xml
index 8dde32e6adda..6ed39f0a45cc 100644
--- a/plugins/java-decompiler/engine/build.xml
+++ b/plugins/java-decompiler/engine/build.xml
@@ -46,13 +46,14 @@
-
+
+
diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java
index 6cbaa839eb4f..0f1bb4da0267 100644
--- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java
+++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/collectors/BytecodeSourceMapper.java
@@ -1,9 +1,6 @@
package org.jetbrains.java.decompiler.main.collectors;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
import java.util.Map.Entry;
import org.jetbrains.java.decompiler.main.DecompilerContext;
@@ -14,13 +11,13 @@ public class BytecodeSourceMapper {
private int offset_total;
// class, method, bytecode offset, source line
- private HashMap>> mapping = new HashMap>>();
+ private final HashMap>> mapping = new LinkedHashMap>>(); // need to preserve order
public void addMapping(String classname, String methodname, int bytecode_offset, int source_line) {
HashMap> class_mapping = mapping.get(classname);
if(class_mapping == null) {
- mapping.put(classname, class_mapping = new HashMap>());
+ mapping.put(classname, class_mapping = new LinkedHashMap>()); // need to preserve order
}
HashMap method_mapping = class_mapping.get(methodname);
diff --git a/plugins/java-decompiler/engine/testData/results/TestClassSimpleBytecodeMapping.dec b/plugins/java-decompiler/engine/testData/results/TestClassSimpleBytecodeMapping.dec
index 8b3c3dffb7aa..3742f9658b58 100644
--- a/plugins/java-decompiler/engine/testData/results/TestClassSimpleBytecodeMapping.dec
+++ b/plugins/java-decompiler/engine/testData/results/TestClassSimpleBytecodeMapping.dec
@@ -22,11 +22,14 @@ public class TestClassSimpleBytecodeMapping {
}
}
-class pkg/TestClassSimpleBytecodeMapping{
- method run (Ljava/lang/Runnable;)V{
- 1 20
+class pkg/TestClassSimpleBytecodeMapping$1{
+ method run ()V{
+ 0 7
+ 3 7
+ 5 7
}
-
+}
+class pkg/TestClassSimpleBytecodeMapping{
method test ()I{
0 4
3 4
@@ -47,11 +50,8 @@ class pkg/TestClassSimpleBytecodeMapping{
2e 15
2f 15
}
-}
-class pkg/TestClassSimpleBytecodeMapping$1{
- method run ()V{
- 0 7
- 3 7
- 5 7
+
+ method run (Ljava/lang/Runnable;)V{
+ 1 20
}
}