mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, "", "");
|
||||
|
||||
}
|
||||
}
|
||||
+3
-20
@@ -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
|
||||
|
||||
+18
-23
@@ -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
|
||||
|
||||
@@ -46,13 +46,14 @@
|
||||
</target>
|
||||
|
||||
<target name="test" depends="init,test-compile">
|
||||
<junit printsummary="true" haltonfailure="true">
|
||||
<junit printsummary="true" failureproperty="tests.failed">
|
||||
<classpath path="${test-out}:${out}"/>
|
||||
<classpath refid="junit"/>
|
||||
<batchtest>
|
||||
<fileset dir="${test-src}" includes="**/*Test.java"/>
|
||||
</batchtest>
|
||||
</junit>
|
||||
<fail if="tests.failed" message="Tests failed."/>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
|
||||
+3
-6
@@ -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<String, HashMap<String, HashMap<Integer, Integer>>> mapping = new HashMap<String, HashMap<String, HashMap<Integer, Integer>>>();
|
||||
private final HashMap<String, HashMap<String, HashMap<Integer, Integer>>> mapping = new LinkedHashMap<String, HashMap<String, HashMap<Integer, Integer>>>(); // need to preserve order
|
||||
|
||||
public void addMapping(String classname, String methodname, int bytecode_offset, int source_line) {
|
||||
|
||||
HashMap<String, HashMap<Integer, Integer>> class_mapping = mapping.get(classname);
|
||||
if(class_mapping == null) {
|
||||
mapping.put(classname, class_mapping = new HashMap<String, HashMap<Integer, Integer>>());
|
||||
mapping.put(classname, class_mapping = new LinkedHashMap<String, HashMap<Integer, Integer>>()); // need to preserve order
|
||||
}
|
||||
|
||||
HashMap<Integer, Integer> method_mapping = class_mapping.get(methodname);
|
||||
|
||||
+10
-10
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user