From 4019c206a61a42696118b49554304f2c0f611942 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 21 Oct 2014 19:10:42 +0400 Subject: [PATCH 1/7] decompiler: fixed line mapping in try-catch block --- .../decompiler/stats/CatchAllStatement.java | 20 ++++++-------- ...lassSimpleBytecodeMapping$InnerClass.class | Bin 647 -> 647 bytes ...assSimpleBytecodeMapping$InnerClass2.class | Bin 650 -> 650 bytes .../pkg/TestClassSimpleBytecodeMapping.class | Bin 1234 -> 1338 bytes .../classes/pkg/TestTryCatchFinally.class | Bin 890 -> 1172 bytes .../TestClassSimpleBytecodeMapping.dec | 26 ++++++++++-------- .../testData/results/TestTryCatchFinally.dec | 15 ++++++++++ .../pkg/TestClassSimpleBytecodeMapping.java | 2 ++ .../testData/src/pkg/TestTryCatchFinally.java | 16 +++++++++++ 9 files changed, 55 insertions(+), 24 deletions(-) diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java index f2321ac47bfb..a3d597d8bc69 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java @@ -26,7 +26,6 @@ import org.jetbrains.java.decompiler.modules.decompiler.StatEdge; import org.jetbrains.java.decompiler.modules.decompiler.exps.VarExprent; import org.jetbrains.java.decompiler.modules.decompiler.vars.VarProcessor; import org.jetbrains.java.decompiler.struct.gen.VarType; -import org.jetbrains.java.decompiler.util.InterpreterUtil; import java.util.ArrayList; import java.util.Arrays; @@ -113,9 +112,6 @@ public class CatchAllStatement extends Statement { } public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { - String indstr = InterpreterUtil.getIndentString(indent); - String indstr1 = null; - String new_line_separator = DecompilerContext.getNewLineSeparator(); TextBuffer buf = new TextBuffer(); @@ -124,7 +120,7 @@ public class CatchAllStatement extends Statement { boolean labeled = isLabeled(); if (labeled) { - buf.append(indstr).append("label").append(this.id.toString()).append(":").append(new_line_separator); + buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator(); tracer.incrementCurrentSourceLine(); } @@ -133,33 +129,33 @@ public class CatchAllStatement extends Statement { !labeled && !first.isLabeled() && (lstSuccs.isEmpty() || !lstSuccs.get(0).explicit)) { TextBuffer content = ExprProcessor.jmpWrapper(first, indent, true, tracer); content.setLength(content.length() - new_line_separator.length()); + tracer.incrementCurrentSourceLine(-1); buf.append(content); } else { - buf.append(indstr).append("try {").append(new_line_separator); + buf.appendIndent(indent).append("try {").appendLineSeparator(); tracer.incrementCurrentSourceLine(); buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer)); - buf.append(indstr).append("}"); + buf.appendIndent(indent).append("}"); } buf.append(isFinally ? " finally" : - " catch (" + vars.get(0).toJava(indent, tracer) + ")").append(" {").append(new_line_separator); + " catch (" + vars.get(0).toJava(indent, tracer) + ")").append(" {").appendLineSeparator(); tracer.incrementCurrentSourceLine(); if (monitor != null) { - indstr1 = InterpreterUtil.getIndentString(indent + 1); - buf.append(indstr1).append("if(").append(monitor.toJava(indent, tracer)).append(") {").append(new_line_separator); + buf.appendIndent(indent+1).append("if(").append(monitor.toJava(indent, tracer)).append(") {").appendLineSeparator(); tracer.incrementCurrentSourceLine(); } buf.append(ExprProcessor.jmpWrapper(handler, indent + 1 + (monitor != null ? 1 : 0), true, tracer)); if (monitor != null) { - buf.append(indstr1).append("}").append(new_line_separator); + buf.appendIndent(indent + 1).append("}").appendLineSeparator(); tracer.incrementCurrentSourceLine(); } - buf.append(indstr).append("}").append(new_line_separator); + buf.appendIndent(indent).append("}").appendLineSeparator(); tracer.incrementCurrentSourceLine(); return buf; diff --git a/plugins/java-decompiler/engine/testData/classes/pkg/TestClassSimpleBytecodeMapping$InnerClass.class b/plugins/java-decompiler/engine/testData/classes/pkg/TestClassSimpleBytecodeMapping$InnerClass.class index bd3481b595d2962323804b5798c3af2f8536d2af..7c87161ed506b83d595000fb4e80ac07b527bb4e 100644 GIT binary patch delta 23 ecmZo?ZD-wJ$;7BN*@{VzRfmCtL3eU4lN10yZ3M0W delta 23 ecmZo?ZD-wJ$;7BJ*@{VzRf~axL3?s8lN10yGX$sr diff --git a/plugins/java-decompiler/engine/testData/classes/pkg/TestClassSimpleBytecodeMapping$InnerClass2.class b/plugins/java-decompiler/engine/testData/classes/pkg/TestClassSimpleBytecodeMapping$InnerClass2.class index b28c357352dddde5e162f26a2954c2098c9371a0..64638d907d634d5735c4c6dbabe5313df6a5567f 100644 GIT binary patch delta 23 ecmeBT?PA?v!^CJZ*_KI<)r^6I!F+N7lN10!c?8=4 delta 23 ecmeBT?PA?v!^CJb*_KI<)r5hA!E|x~lN10!KLphP diff --git a/plugins/java-decompiler/engine/testData/classes/pkg/TestClassSimpleBytecodeMapping.class b/plugins/java-decompiler/engine/testData/classes/pkg/TestClassSimpleBytecodeMapping.class index 010c748a4b0e901939b82ec4ac0a9fd151508f08..2d9a8beca899d1c4d239c59b703dae9264fea809 100644 GIT binary patch delta 629 zcmYk3TTc^F6otPtZ8_7^0b4+&MFra0DlL>&RJ`E@0Z~C?ygUy&DrPb@t?`nW^e;&I z=&Om(XoAXvzH8!x|H8!IVB9m&)Opxz@3q(2dz~{sk~^mJ_4m$aV3uo!LCQ%EaoA?k zP@$@sG9;KbWT@H9gjhE;IASwvILa}bTpsg)q`S_{70ZZ{N8 zukzZOvkDV2n=k$NoaWr-&s$?7WHsjen4$Wq8OFf7m>Ea zeUT*BeG^+&qupPza_4~bW2mY$#kRz7&MPdL47JKfoICHZ2K%>(zhz=o^6ECbdep$$ zzkKS;mQ0f6q#1~?ATcfWLbM_$C6bcoMN^`mGU<*qGZaNslI>-wN=(ZS4{fE0UDr(9 z(BzGj^1OfT6$C9|bmbFiMem{}qU&|}&(|x+{x!rvk+(f@!-(6k-6D$U_(;sDkL7$<3VMZ+3 zfCuCP+8Fg2bC?e(Fz)jr;3X55N!K~m!Zb6MSC(1J>)J}nyr~@?n916|@4X4SEN?^J z@!rt9R@vCyuUO_nK9H)fn&HI+^C8bj8_amfQ&N_XA)iD`x-l$jou7*fgYq2A|is1w|S0p2QvtlbWVO OvN3gb3gbfet?VAAjy2=} diff --git a/plugins/java-decompiler/engine/testData/classes/pkg/TestTryCatchFinally.class b/plugins/java-decompiler/engine/testData/classes/pkg/TestTryCatchFinally.class index 16dc30dc15fb6b2ac725db6c2c0b506e0cbf9540..244dfad62acaff777b67a3cdb983b0607dfb458a 100644 GIT binary patch literal 1172 zcmaJ>OHUJF6g|@iGYkWT@>Z}E6!=#Og%b^|1K$&T#Q*;!lkdl`FW&&nU{ysI;;k6PeFYCxJj9rSaTy5( zNfi@FDVUUzR-q!UU`qImFpq?pmho7|6A3K~re(TI5`u~3YYCw>yJ$#=Y?+p^Q#;x- zoV>nQW+vd^LT*tIZSy9-YbM?aEwqEh@WZ?~%k@1vGMeRRI zHzlY!yXF*(4O7e+$P=4)j@NXzu)kqidbxZ&B_?W!qFcr@4bL%4K2^KsQpKExdGt$= z-}+by-A#V$9|}grHEpYbr{t`L1>7UP(OW`)6YuL;t(oPb;jm`iacoD!B9??%*6;!= zET|loGPlr_(AjLYyLVs|DEdmu?|zM7e&4a*`wPAbJg&ON5wC<2xi){{rk#1kZM*DZ z=ttShHrLbCRS}>v6?ZksY+9~S5{i_H?oDzAf#w9nF!nxP*zRYa$ zKX}EpFO~NsZUVE2qmy5<_yr+}Tc+*dX_#K34^Ny!I%B|H(6)HVC~Y75X$AB<0tnO3 zeL^4_tRp0RnEnKbZ4t{}9NKB-JLms`216HTUb({AEo?Z17(JjMMca)L&!>>~e88hI zg*N`zOH7RXM~LcUHwdRFtZViQPDV~B&PY0%+N1WxllmjyQEtrSCuSdOa(CV E2TVZoBLDyZ delta 394 zcmXw#IZFdk5XXOSbG*%F6E)^G8jWWTk9apCiik~=pp9ib3NeUrHes!8ZERFn zMZv<-%F@qbAY`jb`&wGh7FEZ8iviz?AT=^6DPfg&ahc8W1!FL9yQdW#Rg=vw&&W91QF%^+%0;VuQfQ%SQilr1qiK}E~w;5JtuL 16 28 <-> 17 34 <-> 23 -42 <-> 42 -47 <-> 31 -52 <-> 36 +44 <-> 44 +49 <-> 33 +54 <-> 38 diff --git a/plugins/java-decompiler/engine/testData/results/TestTryCatchFinally.dec b/plugins/java-decompiler/engine/testData/results/TestTryCatchFinally.dec index 1524da840379..9840bfccb285 100644 --- a/plugins/java-decompiler/engine/testData/results/TestTryCatchFinally.dec +++ b/plugins/java-decompiler/engine/testData/results/TestTryCatchFinally.dec @@ -1,6 +1,21 @@ package pkg; public class TestTryCatchFinally { + public void test1(String var1) { + try { + System.out.println("sout1"); + } catch (Exception var9) { + try { + System.out.println("sout2"); + } catch (Exception var8) { + ; + } + } finally { + System.out.println("finally"); + } + + } + public int test(String var1) { try { int var2 = Integer.parseInt(var1); diff --git a/plugins/java-decompiler/engine/testData/src/pkg/TestClassSimpleBytecodeMapping.java b/plugins/java-decompiler/engine/testData/src/pkg/TestClassSimpleBytecodeMapping.java index bc07e46bcaa8..0b9df2e79252 100644 --- a/plugins/java-decompiler/engine/testData/src/pkg/TestClassSimpleBytecodeMapping.java +++ b/plugins/java-decompiler/engine/testData/src/pkg/TestClassSimpleBytecodeMapping.java @@ -34,6 +34,8 @@ public class TestClassSimpleBytecodeMapping { Integer.parseInt(a); } catch (Exception e) { System.out.println(e); + } finally { + System.out.println("Finally"); } } diff --git a/plugins/java-decompiler/engine/testData/src/pkg/TestTryCatchFinally.java b/plugins/java-decompiler/engine/testData/src/pkg/TestTryCatchFinally.java index 2e244be22e8a..da3588a3eb50 100644 --- a/plugins/java-decompiler/engine/testData/src/pkg/TestTryCatchFinally.java +++ b/plugins/java-decompiler/engine/testData/src/pkg/TestTryCatchFinally.java @@ -16,6 +16,22 @@ package pkg; public class TestTryCatchFinally { + public void test1(String x) { + try { + System.out.println("sout1"); + } catch (Exception e) { + try { + System.out.println("sout2"); + } catch (Exception e2) { + // Empty + // Empty + // Empty + } + } finally { + System.out.println("finally"); + } + } + public int test(String a) { try { return Integer.parseInt(a); From 55a7608f865ca6345525cf369fac4aae3545d8f0 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Tue, 21 Oct 2014 19:13:20 +0400 Subject: [PATCH 2/7] PY-11180 Template Create dialog is too small PY-11959 Add inspection options to force pycharm inspection suggesting first current app template folder to create a new template file PY-13501 Wrong location on html template file creation option. --- .../openapi/ui/ComponentWithBrowseButton.java | 5 ++--- .../platform-api/src/com/intellij/ui/GuiUtils.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java b/platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java index 906e2496296e..5ee7a73b73a6 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java @@ -32,6 +32,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.ui.GuiUtils; import com.intellij.ui.UIBundle; import com.intellij.util.Consumer; import com.intellij.util.ui.UIUtil; @@ -88,9 +89,7 @@ public class ComponentWithBrowseButton extends JPanel i public void setTextFieldPreferredWidth(final int charCount) { final Comp comp = getChildComponent(); - Dimension size = comp.getPreferredSize(); - FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont()); - size.width = fontMetrics.charWidth('a') * charCount; + Dimension size = GuiUtils.getSizeByChars(charCount, comp); comp.setPreferredSize(size); final Dimension preferredSize = myBrowseButton.getPreferredSize(); setPreferredSize(new Dimension(size.width + preferredSize.width + 2, UIUtil.isUnderAquaLookAndFeel() ? preferredSize.height : preferredSize.height + 2)); diff --git a/platform/platform-api/src/com/intellij/ui/GuiUtils.java b/platform/platform-api/src/com/intellij/ui/GuiUtils.java index d0bd138ec31f..ce60c6b53de5 100644 --- a/platform/platform-api/src/com/intellij/ui/GuiUtils.java +++ b/platform/platform-api/src/com/intellij/ui/GuiUtils.java @@ -390,4 +390,18 @@ public class GuiUtils { public static JTextField createUndoableTextField() { return new JBTextField(); } + + /** + * Returns dimension with width required to type certain number of chars in provided component + * @param charCount number of chars + * @param comp component + * @return dimension with width enough to insert provided number of chars into component + */ + @NotNull + public static Dimension getSizeByChars(int charCount, @NotNull JComponent comp) { + Dimension size = comp.getPreferredSize(); + FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont()); + size.width = fontMetrics.charWidth('a') * charCount; + return size; + } } From 0232e6d8d6b312561758392324b8edeecb704a28 Mon Sep 17 00:00:00 2001 From: Liana Bakradze Date: Tue, 21 Oct 2014 19:16:42 +0400 Subject: [PATCH 3/7] EDU-182 Tell user to go to the next task window when show hint action is invoked outside of any task window --- .../edu/actions/StudyShowHintAction.java | 71 +++++++++++-------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/python/edu/learn-python/src/com/jetbrains/python/edu/actions/StudyShowHintAction.java b/python/edu/learn-python/src/com/jetbrains/python/edu/actions/StudyShowHintAction.java index a464996d877a..c46b2cd48a73 100644 --- a/python/edu/learn-python/src/com/jetbrains/python/edu/actions/StudyShowHintAction.java +++ b/python/edu/learn-python/src/com/jetbrains/python/edu/actions/StudyShowHintAction.java @@ -21,12 +21,15 @@ import com.jetbrains.python.edu.course.TaskWindow; import com.jetbrains.python.edu.editor.StudyEditor; import icons.StudyIcons; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; public class StudyShowHintAction extends DumbAwareAction { public static final String ACTION_ID = "ShowHintAction"; public static final String SHORTCUT = "ctrl pressed 7"; + public static final String OUTSIDE_TASK_WINDOW_MESSAGE = "Put caret to task window to get hint for it."; + public static final String HINT_NOT_AVAILABLE = "There is no hint for this task window"; public StudyShowHintAction() { super("Show hint", "Show hint", StudyIcons.ShowHint); @@ -53,41 +56,49 @@ public class StudyShowHintAction extends DumbAwareAction { final Editor editor = studyState.getEditor(); LogicalPosition pos = editor.getCaretModel().getLogicalPosition(); TaskWindow taskWindow = studyState.getTaskFile().getTaskWindow(editor.getDocument(), pos); - if (file == null || taskWindow == null) { + if (file == null) { return; } - String hint = taskWindow.getHint(); - if (hint == null) { - return; + String hintText = OUTSIDE_TASK_WINDOW_MESSAGE; + if (taskWindow != null) { + hintText = getHintText(taskWindow, course); } - File resourceFile = new File(course.getResourcePath()); - File resourceRoot = resourceFile.getParentFile(); - if (resourceRoot == null || !resourceRoot.exists()) { - return; - } - File hintsDir = new File(resourceRoot, Course.HINTS_DIR); - if (hintsDir.exists()) { - String hintText = StudyUtils.getFileText(hintsDir.getAbsolutePath(), hint, true); - int offset = editor.getDocument().getLineStartOffset(pos.line) + pos.column; - PsiElement element = file.findElementAt(offset); - if (hintText == null || element == null) { - return; - } + int offset = editor.getDocument().getLineStartOffset(pos.line) + pos.column; + PsiElement element = file.findElementAt(offset); + DocumentationManager documentationManager = DocumentationManager.getInstance(project); + DocumentationComponent component = new DocumentationComponent(documentationManager); + component.setData(element != null ? element : file, element != null ? hintText : OUTSIDE_TASK_WINDOW_MESSAGE, true, null); + showHintPopUp(project, editor, component); + } - DocumentationManager documentationManager = DocumentationManager.getInstance(project); - DocumentationComponent component = new DocumentationComponent(documentationManager); - component.setData(element, hintText, true, null); - final JBPopup popup = - JBPopupFactory.getInstance().createComponentPopupBuilder(component, component) - .setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false) - .setResizable(true) - .setMovable(true) - .setRequestFocus(true) - .createPopup(); - component.setHint(popup); - popup.showInBestPositionFor(editor); - Disposer.dispose(component); + @Nullable + private static String getHintText(@NotNull final TaskWindow taskWindow, @NotNull final Course course) { + String hintFileName = taskWindow.getHint(); + String hintText = HINT_NOT_AVAILABLE; + if (hintFileName != null && !hintFileName.isEmpty()) { + File resourceFile = new File(course.getResourcePath()); + File resourceRoot = resourceFile.getParentFile(); + if (resourceRoot != null && resourceRoot.exists()) { + File hintsDir = new File(resourceRoot, Course.HINTS_DIR); + if (hintsDir.exists()) { + hintText = StudyUtils.getFileText(hintsDir.getAbsolutePath(), hintFileName, true); + } + } } + return hintText != null ? hintText : OUTSIDE_TASK_WINDOW_MESSAGE; + } + + private static void showHintPopUp(Project project, Editor editor, DocumentationComponent component) { + final JBPopup popup = + JBPopupFactory.getInstance().createComponentPopupBuilder(component, component) + .setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false) + .setResizable(true) + .setMovable(true) + .setRequestFocus(true) + .createPopup(); + component.setHint(popup); + popup.showInBestPositionFor(editor); + Disposer.dispose(component); } @Override From 72f8febed8151ecb23e67d38bf0798c082cd9d7c Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 21 Oct 2014 16:54:17 +0200 Subject: [PATCH 4/7] move to JS debugger module --- .../backend/src/org/jetbrains/debugger/ScriptManager.java | 3 +++ .../src/org/jetbrains/debugger/ScriptManagerBase.java | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptManager.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptManager.java index c16ffe5d4b81..60b8690e44a0 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptManager.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptManager.java @@ -38,6 +38,9 @@ public interface ScriptManager { @Nullable Script findScriptByUrl(@NotNull String rawUrl); + @Nullable + Script findScriptById(@NotNull String id); + @Nullable ActionCallback getScriptSourceMapLoadCallback(@NotNull Script script); } \ No newline at end of file diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptManagerBase.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptManagerBase.java index e19deb1b6dc9..f22514ca704f 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptManagerBase.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/ScriptManagerBase.java @@ -56,4 +56,10 @@ public abstract class ScriptManagerBase