diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java b/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java index dc68a6619986..bf29c7090f09 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java @@ -471,7 +471,9 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo mySettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS); } else if (childType == JavaTokenType.LPARENTH && nodeType == JavaElementType.PARAMETER_LIST) { - Wrap wrapToUse = getMethodParametersWrap(); + ASTNode parent = myNode.getTreeParent(); + boolean isLambdaParameterList = parent != null && parent.getElementType() == JavaElementType.LAMBDA_EXPRESSION; + Wrap wrapToUse = isLambdaParameterList ? null : getMethodParametersWrap(); WrappingStrategy wrapStrategy = WrappingStrategy.createDoNotWrapCommaStrategy(wrapToUse); child = processParenthesisBlock(result, child, wrapStrategy, mySettings.ALIGN_MULTILINE_PARAMETERS); } diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterWrapTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterWrapTest.java index fa960980d297..32091952a51c 100644 --- a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterWrapTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterWrapTest.java @@ -15,13 +15,10 @@ */ package com.intellij.psi.formatter.java; -import com.intellij.idea.Bombed; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; -import java.util.Calendar; - /** * Is intended to hold specific java formatting tests for 'wrapping' settings. * @@ -475,5 +472,30 @@ public class JavaFormatterWrapTest extends AbstractJavaFormatterTest { ); } + public void test_Wrap_On_Method_Parameter_Declaration() { + getSettings().METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED; + doClassTest( + " public static void main(String[] args) {\n" + + " boolean ssuuuuuuuuuuuuuuuuuuupaaaaaaaaaaaaa = false;\n" + + " soo.ifTrue(ssuuuuuuuuuuuuuuuuuuupaaaaaaaaaaaaa, (v) -> v.setText(\"syyycuuuuuuuuurrrrrrrrrrrrrrennnnnnnnnnnnnnnnnnnnnt\"));\n" + + "}", + "public static void main(String[] args) {\n" + + " boolean ssuuuuuuuuuuuuuuuuuuupaaaaaaaaaaaaa = false;\n" + + " soo.ifTrue(ssuuuuuuuuuuuuuuuuuuupaaaaaaaaaaaaa, (v) -> v.setText(\"syyycuuuuuuuuurrrrrrrrrrrrrrennnnnnnnnnnnnnnnnnnnnt\"));\n" + + "}" + ); + getSettings().CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED; + doClassTest( + " public static void main(String[] args) {\n" + + " boolean ssuuuuuuuuuuuuuuuuuuupaaaaaaaaaaaaa = false;\n" + + " soo.ifTrue(ssuuuuuuuuuuuuuuuuuuupaaaaaaaaaaaaa, (v) -> v.setText(\"syyycuuuuuuuuurrrrrrrrrrrrrrennnnnnnnnnnnnnnnnnnnnt\"));\n" + + "}", + "public static void main(String[] args) {\n" + + " boolean ssuuuuuuuuuuuuuuuuuuupaaaaaaaaaaaaa = false;\n" + + " soo.ifTrue(ssuuuuuuuuuuuuuuuuuuupaaaaaaaaaaaaa,\n" + + " (v) -> v.setText(\"syyycuuuuuuuuurrrrrrrrrrrrrrennnnnnnnnnnnnnnnnnnnnt\"));\n" + + "}" + ); + } } diff --git a/platform/diff-impl/src/com/intellij/diff/contents/FileAwareDocumentContent.java b/platform/diff-impl/src/com/intellij/diff/contents/FileAwareDocumentContent.java index 3fd88499d197..eae71d723669 100644 --- a/platform/diff-impl/src/com/intellij/diff/contents/FileAwareDocumentContent.java +++ b/platform/diff-impl/src/com/intellij/diff/contents/FileAwareDocumentContent.java @@ -7,7 +7,6 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.fileTypes.PlainTextFileType; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vfs.CharsetToolkit; @@ -100,10 +99,7 @@ public class FileAwareDocumentContent extends DocumentContentImpl { @NotNull private Builder create(@NotNull byte[] content) { assert myCharset != null; - // TODO: detect charset like in LoadTextUtil (Native2Ascii, etc) ? - Pair pair = CharsetToolkit.bytesToStringWithCharset(content, myCharset); - myCharset = pair.second; - return create(pair.first); + return create(CharsetToolkit.decodeString(content, myCharset)); } @NotNull diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/MacroParser.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/MacroParser.java index 5700498b13d2..7b41550ee73c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/MacroParser.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/MacroParser.java @@ -22,15 +22,18 @@ import com.intellij.codeInsight.template.Macro; import com.intellij.codeInsight.template.macro.MacroFactory; import com.intellij.lexer.Lexer; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @VisibleForTesting public class MacroParser { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.template.impl.MacroParser"); - - //----------------------------------------------------------------------------------- - public static Expression parse(String expression) { - if (expression.length() == 0) { + + @NotNull + public static Expression parse(@Nullable String expression) { + if (StringUtil.isEmpty(expression)) { return new ConstantNode(""); } Lexer lexer = new MacroLexer(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/Variable.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/Variable.java index ca41a692f53b..ffe70d8b1389 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/Variable.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/Variable.java @@ -17,20 +17,23 @@ package com.intellij.codeInsight.template.impl; import com.intellij.codeInsight.template.Expression; +import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class Variable implements Cloneable { private final String myName; private boolean myAlwaysStopAt; - private String myExpressionString; + @Nullable private String myExpressionString; private Expression myExpression = null; private String myDefaultValueString; private Expression myDefaultValueExpression; private final boolean mySkipOnStart; - public Variable(@NotNull String name, Expression expression, Expression defaultValueExpression, boolean alwaysStopAt, boolean skipOnStart) { + public Variable(@NotNull String name, @Nullable Expression expression, @Nullable Expression defaultValueExpression, + boolean alwaysStopAt, boolean skipOnStart) { myName = name; myExpression = expression; myDefaultValueExpression = defaultValueExpression; @@ -38,23 +41,25 @@ public class Variable implements Cloneable { mySkipOnStart = skipOnStart; } - public Variable(String name, String expression, String defaultValueString, boolean alwaysStopAt) { + public Variable(@NotNull String name, @Nullable String expression, @Nullable String defaultValueString, boolean alwaysStopAt) { myName = name; - myExpressionString = expression; - myDefaultValueString = defaultValueString; + myExpressionString = StringUtil.notNullize(expression); + myDefaultValueString = StringUtil.notNullize(defaultValueString); myAlwaysStopAt = alwaysStopAt; mySkipOnStart = false; } + @NotNull public String getExpressionString() { - return myExpressionString; + return StringUtil.notNullize(myExpressionString); } - public void setExpressionString(String expressionString) { + public void setExpressionString(@Nullable String expressionString) { myExpressionString = expressionString; myExpression = null; } + @NotNull public Expression getExpression() { if (myExpression == null) { if (myName.equals(TemplateImpl.SELECTION)) { @@ -67,15 +72,17 @@ public class Variable implements Cloneable { return myExpression; } + @NotNull public String getDefaultValueString() { - return myDefaultValueString; + return StringUtil.notNullize(myDefaultValueString); } - public void setDefaultValueString(String defaultValueString) { + public void setDefaultValueString(@Nullable String defaultValueString) { myDefaultValueString = defaultValueString; myDefaultValueExpression = null; } + @NotNull public Expression getDefaultValueExpression() { if (myDefaultValueExpression == null) { myDefaultValueExpression = MacroParser.parse(myDefaultValueString); @@ -112,14 +119,14 @@ public class Variable implements Cloneable { if (mySkipOnStart != variable.mySkipOnStart) return false; if (myDefaultValueString != null ? !myDefaultValueString.equals(variable.myDefaultValueString) : variable.myDefaultValueString != null) return false; if (myExpressionString != null ? !myExpressionString.equals(variable.myExpressionString) : variable.myExpressionString != null) return false; - if (myName != null ? !myName.equals(variable.myName) : variable.myName != null) return false; + if (!myName.equals(variable.myName)) return false; return true; } public int hashCode() { int result; - result = (myName != null ? myName.hashCode() : 0); + result = myName.hashCode(); result = 29 * result + (myAlwaysStopAt ? 1 : 0); result = 29 * result + (mySkipOnStart ? 1 : 0); result = 29 * result + (myExpressionString != null ? myExpressionString.hashCode() : 0); diff --git a/platform/platform-impl/src/com/intellij/internal/inspector/UiInspectorAction.java b/platform/platform-impl/src/com/intellij/internal/inspector/UiInspectorAction.java index 9be46fabd5a8..65c1c14861ae 100644 --- a/platform/platform-impl/src/com/intellij/internal/inspector/UiInspectorAction.java +++ b/platform/platform-impl/src/com/intellij/internal/inspector/UiInspectorAction.java @@ -249,7 +249,10 @@ public class UiInspectorAction extends ToggleAction implements DumbAware { } private static class ComponentTreeCellRenderer extends ColoredTreeCellRenderer { - ComponentTreeCellRenderer() { + private final Component myInitialSelection; + + ComponentTreeCellRenderer(Component initialSelection) { + myInitialSelection = initialSelection; setFont(JBUI.Fonts.label(11)); setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); } @@ -266,7 +269,7 @@ public class UiInspectorAction extends ToggleAction implements DumbAware { Color background = selected ? UIUtil.getTreeSelectionBackground() : null; if (value instanceof HierarchyTree.ComponentNode) { HierarchyTree.ComponentNode componentNode = (HierarchyTree.ComponentNode)value; - Component component = componentNode.getOwnComponent(); + Component component = componentNode.getComponent(); Class clazz0 = component.getClass(); Class clazz = clazz0.isAnonymousClass() ? clazz0.getSuperclass() : clazz0; String name = component.getName(); @@ -284,7 +287,7 @@ public class UiInspectorAction extends ToggleAction implements DumbAware { foreground = PlatformColors.BLUE; } - if (componentNode.getToSelect() == componentNode.getOwnComponent()) { + if (myInitialSelection == componentNode.getComponent()) { background = new Color(31, 128, 8, 58); } } @@ -309,13 +312,23 @@ public class UiInspectorAction extends ToggleAction implements DumbAware { } } + private static TreeModel buildModel(Component c) { + Component parent = c.getParent(); + while (parent != null) { + c = parent; + parent = c.getParent();//Find root window + } + return new DefaultTreeModel(new UiInspectorAction.HierarchyTree.ComponentNode(c)); + } + + private abstract static class HierarchyTree extends JTree implements TreeSelectionListener { final Component myComponent; private HierarchyTree(Component c) { myComponent = c; setModel(buildModel(c)); - setCellRenderer(new ComponentTreeCellRenderer()); + setCellRenderer(new ComponentTreeCellRenderer(c)); getSelectionModel().addTreeSelectionListener(this); new TreeSpeedSearch(this); } @@ -323,7 +336,7 @@ public class UiInspectorAction extends ToggleAction implements DumbAware { public void expandPath() { TreeUtil.expandAll(this); int count = getRowCount(); - ComponentNode node = new ComponentNode(myComponent, myComponent.getParent()); + ComponentNode node = new ComponentNode(myComponent); for (int i = 0; i < count; i++) { TreePath row = getPathForRow(i); @@ -344,59 +357,49 @@ public class UiInspectorAction extends ToggleAction implements DumbAware { } Object component = path.getLastPathComponent(); if (component instanceof ComponentNode) { - Component c = ((ComponentNode)component).getOwnComponent(); + Component c = ((ComponentNode)component).getComponent(); onComponentChanged(c); } } - private static TreeModel buildModel(Component c) { - return new DefaultTreeModel(new ComponentNode(c, null)); - } - public abstract void onComponentChanged(Component c); private static class ComponentNode extends DefaultMutableTreeNode { - private final Component myParent; - private final Component myToSelect; + private final Component myComponent; - private ComponentNode(Object userObject, Component parent) { - super(userObject); - myParent = parent == null ? SwingUtilities.getWindowAncestor((Component) userObject) : parent; - myToSelect = (Component)userObject; - children = prepareChildren(myToSelect, parent); + private ComponentNode(@NotNull Component component) { + super(component); + myComponent = component; + children = prepareChildren(myComponent); } - public Component getOwnComponent() { - return myParent; - } - - public Component getToSelect() { - return myToSelect; + Component getComponent() { + return myComponent; } @Override public String toString() { - return myParent.getClass().getName(); + return myComponent.getClass().getName(); } @Override public boolean equals(Object obj) { - return obj instanceof ComponentNode && ((ComponentNode)obj).getOwnComponent() == getOwnComponent(); + return obj instanceof ComponentNode && ((ComponentNode)obj).getComponent() == getComponent(); } @SuppressWarnings("UseOfObsoleteCollectionType") - private static Vector prepareChildren(Component toSelect, Component parent) { + private static Vector prepareChildren(Component parent) { Vector result = new Vector(); - if (parent == null) { - Container root = SwingUtilities.windowForComponent(toSelect); - for (Component component : root.getComponents()) { - result.add(new ComponentNode(toSelect, component)); + if (parent instanceof Container) { + for (Component component : ((Container)parent).getComponents()) { + result.add(new ComponentNode(component)); } - } else { - if (parent instanceof Container) { - for (Component component : ((Container)parent).getComponents()) { - result.add(new ComponentNode(toSelect, component)); - } + } + if (parent instanceof Window) { + Window[] children = ((Window)parent).getOwnedWindows(); + for (Window child : children) { + if (child instanceof InspectorWindow) continue; + result.add(new ComponentNode(child)); } } @@ -817,6 +820,10 @@ public class UiInspectorAction extends ToggleAction implements DumbAware { public void showInspector(@NotNull Component c) { InspectorWindow window = myComponentToInspector.get(c); if (window != null) { + window.myHierarchyTree.setModel(buildModel(c)); + window.myHierarchyTree.setCellRenderer(new ComponentTreeCellRenderer(c)); + window.myHierarchyTree.expandPath(); + window.switchInfo(c); window.setHighlightingEnabled(true); window.setVisible(true); diff --git a/platform/platform-resources-en/src/messages/CommonBundle.properties b/platform/platform-resources-en/src/messages/CommonBundle.properties index a8f41d9f5cf0..683703be061e 100644 --- a/platform/platform-resources-en/src/messages/CommonBundle.properties +++ b/platform/platform-resources-en/src/messages/CommonBundle.properties @@ -148,7 +148,7 @@ cannot.start.other.instance.is.running.error.message={0} was unable to create a button.load.file=Load File date.frequency=Once {0} name.label.text=Na&me: -smth.already.exist.error.message={0} with name ''{1}'' already exist. +smth.already.exist.error.message={0} with name ''{1}'' already exists comparison.policy.default.name=Default comparison.policy.trim.space.name=Trim space comparison.policy.ignore.spaces.name=Ignore spaces diff --git a/platform/util/src/com/intellij/openapi/vfs/CharsetToolkit.java b/platform/util/src/com/intellij/openapi/vfs/CharsetToolkit.java index 1b31e2b8bbb1..25a44601e7e6 100644 --- a/platform/util/src/com/intellij/openapi/vfs/CharsetToolkit.java +++ b/platform/util/src/com/intellij/openapi/vfs/CharsetToolkit.java @@ -15,7 +15,6 @@ */ package com.intellij.openapi.vfs; -import com.intellij.openapi.util.Pair; import com.intellij.util.ArrayUtil; import gnu.trove.THashMap; import org.jetbrains.annotations.NonNls; @@ -297,16 +296,16 @@ public class CharsetToolkit { @NotNull public static String bytesToString(@NotNull byte[] bytes, @NotNull final Charset defaultCharset) { - return bytesToStringWithCharset(bytes, defaultCharset).getFirst(); + Charset charset = new CharsetToolkit(bytes, defaultCharset).guessEncoding(bytes.length); + if (charset == null) charset = defaultCharset; // binary content. This is silly but method contract says to return something anyway + return decodeString(bytes, charset); } @NotNull - public static Pair bytesToStringWithCharset(@NotNull byte[] bytes, @NotNull final Charset defaultCharset) { - Charset charset = new CharsetToolkit(bytes, defaultCharset).guessEncoding(bytes.length); - if (charset == null) charset = defaultCharset; // binary content. This is silly but method contract says to return something anyway + public static String decodeString(@NotNull byte[] bytes, @NotNull final Charset charset) { int bomLength = getBOMLength(bytes, charset); final CharBuffer charBuffer = charset.decode(ByteBuffer.wrap(bytes, bomLength, bytes.length - bomLength)); - return Pair.create(charBuffer.toString(), charset); + return charBuffer.toString(); } public enum GuessedEncoding { diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/errorhandling/try_identical_catches/TryIdenticalCatches.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/errorhandling/try_identical_catches/TryIdenticalCatches.java index 09694491d69d..9c7d4122b642 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/errorhandling/try_identical_catches/TryIdenticalCatches.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/errorhandling/try_identical_catches/TryIdenticalCatches.java @@ -69,7 +69,7 @@ class TryIdenticalCatches { catch(ClassNotFoundException cnfe) { System.out.println(); } - catch(NumberFormatException nfe) { + catch(NumberFormatException nfe) { System.out.println(); } } @@ -86,7 +86,7 @@ class TryIdenticalCatches { catch(ClassNotFoundException cnfe) { log(cnfe); } - catch(NumberFormatException nfe) { + catch(NumberFormatException nfe) { log(nfe); } } @@ -103,9 +103,9 @@ class TryIdenticalCatches { try { } catch (E4 e) { - } catch (E2 e) { - } catch (E3 e) { - } catch (E1 e) { + } catch (E2 e) { + } catch (E3 e) { + } catch (E1 e) { } } @@ -127,9 +127,9 @@ class TryIdenticalCatches { throw new NullPointerException(); } catch (final NullPointerException e) { causeException = e; - } catch (final IllegalArgumentException e) { + } catch (final IllegalArgumentException e) { causeException = e; - } catch (final IndexOutOfBoundsException e) { + } catch (final IndexOutOfBoundsException e) { causeException = e; } System.out.println("causeException = " + causeException); diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/naming/static_method_naming_convention/StaticMethodNamingConvention.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/naming/static_method_naming_convention/StaticMethodNamingConvention.java index e4c7c37486c5..a8b22d340e7f 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/naming/static_method_naming_convention/StaticMethodNamingConvention.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/naming/static_method_naming_convention/StaticMethodNamingConvention.java @@ -2,7 +2,7 @@ package com.siyeh.igtest.naming.static_method_naming_convention; public class StaticMethodNamingConvention { - public static void UpperaseMethod() + public static void UpperaseMethod() { } diff --git a/plugins/git4idea/src/git4idea/actions/GitRebaseActionBase.java b/plugins/git4idea/src/git4idea/actions/GitRebaseActionBase.java index 4cc13114fe17..8254ed35f811 100644 --- a/plugins/git4idea/src/git4idea/actions/GitRebaseActionBase.java +++ b/plugins/git4idea/src/git4idea/actions/GitRebaseActionBase.java @@ -74,7 +74,7 @@ public abstract class GitRebaseActionBase extends GitRepositoryAction { GitRepositoryManager manager = GitUtil.getRepositoryManager(project); manager.updateRepository(root); root.refresh(false, true); - notifyAboutResult(result, resultListener, exceptions, project); + notifyAboutResult(result, resultListener, editor.wasNoopSituationDetected(), exceptions, project); } finally { DvcsUtil.workingTreeChangeFinished(project, token); @@ -85,6 +85,7 @@ public abstract class GitRebaseActionBase extends GitRepositoryAction { private static void notifyAboutResult(@NotNull GitCommandResult commandResult, @NotNull GitRebaseLineListener resultListener, + boolean noopSituation, @NotNull List exceptions, @NotNull Project project) { final GitRebaseLineListener.Result result = resultListener.getResult(); @@ -110,6 +111,9 @@ public abstract class GitRebaseActionBase extends GitRepositoryAction { case FINISHED: isError = false; messageId = "rebase.result.success"; + if (noopSituation) { + message = "Current branch was reset to the base branch"; + } break; default: throw new IllegalStateException("Unsupported rebase result: " + result.status); diff --git a/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java b/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java index 0c1dba06ed74..ec1427c7736a 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java +++ b/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java @@ -67,6 +67,8 @@ public class GitInteractiveRebaseEditorHandler implements Closeable, GitRebaseEd */ protected boolean myRebaseEditorShown = false; + private boolean myNoopSituation; + /** * The constructor from fields that is expected to be * accessed only from {@link git4idea.rebase.GitRebaseEditorService}. @@ -138,6 +140,7 @@ public class GitInteractiveRebaseEditorHandler implements Closeable, GitRebaseEd CommonBundle.getCancelButtonText(), Messages.getQuestionIcon()); if (rebase == Messages.OK) { isSuccess.set(true); + myNoopSituation = true; return; } } @@ -183,4 +186,11 @@ public class GitInteractiveRebaseEditorHandler implements Closeable, GitRebaseEd public int getHandlerNo() { return myHandlerNo; } + + /** + * Tells if there was a "noop" situation during rebase (no commits were rebase, just the label was moved). + */ + public boolean wasNoopSituationDetected() { + return myNoopSituation; + } } diff --git a/plugins/git4idea/src/git4idea/rebase/GitRebaseEditor.java b/plugins/git4idea/src/git4idea/rebase/GitRebaseEditor.java index 51edcf439623..51769afc1277 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRebaseEditor.java +++ b/plugins/git4idea/src/git4idea/rebase/GitRebaseEditor.java @@ -15,6 +15,11 @@ */ package git4idea.rebase; +import com.intellij.ide.CopyProvider; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.text.StringUtil; @@ -27,11 +32,13 @@ import com.intellij.ui.table.JBTable; import com.intellij.util.ArrayUtil; import com.intellij.util.ListWithSelection; import com.intellij.util.PairFunction; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.ComboBoxTableCellRenderer; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; import git4idea.GitUtil; import git4idea.i18n.GitBundle; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -42,6 +49,7 @@ import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableColumn; +import java.awt.datatransfer.StringSelection; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; @@ -53,7 +61,7 @@ import java.util.List; * Editor for rebase entries. It allows reordering of * the entries and changing commit status. */ -public class GitRebaseEditor extends DialogWrapper { +public class GitRebaseEditor extends DialogWrapper implements DataProvider { /** * The table that lists all commits */ @@ -79,6 +87,8 @@ public class GitRebaseEditor extends DialogWrapper { */ private final MyTableModel myTableModel; + @NotNull private final CopyProvider myCopyProvider; + /** * The constructor * @@ -143,6 +153,7 @@ public class GitRebaseEditor extends DialogWrapper { }); installSpeedSearch(); + myCopyProvider = new MyCopyProvider(); adjustColumnWidth(0); adjustColumnWidth(1); @@ -224,6 +235,15 @@ public class GitRebaseEditor extends DialogWrapper { return myTableModel.myEntries; } + @Nullable + @Override + public Object getData(@NonNls String dataId) { + if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) { + return myCopyProvider; + } + return null; + } + /** * The table model for the commits @@ -325,6 +345,15 @@ public class GitRebaseEditor extends DialogWrapper { } } + @Nullable + public String getStringToCopy(int row) { + if (row < 0 || row >= myEntries.size()) { + return null; + } + GitRebaseEntry e = myEntries.get(row); + return e.getCommit() + " " + e.getSubject(); + } + private void setSelection(ContiguousIntIntervalTracker intervalBuilder) { myCommitsTable.getSelectionModel().setSelectionInterval(intervalBuilder.getMin(), intervalBuilder.getMax()); } @@ -373,6 +402,7 @@ public class GitRebaseEditor extends DialogWrapper { assert rowIndex < myEntries.size(); } } + } private static class ContiguousIntIntervalTracker { @@ -445,4 +475,24 @@ public class GitRebaseEditor extends DialogWrapper { } } + private class MyCopyProvider implements CopyProvider { + @Override + public void performCopy(@NotNull DataContext dataContext) { + List data = ContainerUtil.newArrayList(); + for (int row : myCommitsTable.getSelectedRows()) { + data.add(myTableModel.getStringToCopy(row)); + } + CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.join(data, "\n"))); + } + + @Override + public boolean isCopyEnabled(@NotNull DataContext dataContext) { + return myCommitsTable.getSelectedRowCount() > 0; + } + + @Override + public boolean isCopyVisible(@NotNull DataContext dataContext) { + return true; + } + } } diff --git a/plugins/groovy/testdata/highlighting/RangeType.groovy b/plugins/groovy/testdata/highlighting/RangeType.groovy index 3c2fb4060fb4..d85aa9b7ce3d 100644 --- a/plugins/groovy/testdata/highlighting/RangeType.groovy +++ b/plugins/groovy/testdata/highlighting/RangeType.groovy @@ -1,4 +1,4 @@ class Foo { } -print new Foo()..new Foo() \ No newline at end of file +print new Foo()..new Foo() \ No newline at end of file diff --git a/python/src/com/jetbrains/python/editor/PythonEnterHandler.java b/python/src/com/jetbrains/python/editor/PythonEnterHandler.java index 39b9f594b224..10486dd6d0a8 100644 --- a/python/src/com/jetbrains/python/editor/PythonEnterHandler.java +++ b/python/src/com/jetbrains/python/editor/PythonEnterHandler.java @@ -48,7 +48,9 @@ public class PythonEnterHandler extends EnterHandlerDelegateAdapter { private int myPostprocessShift = 0; public static final Class[] IMPLICIT_WRAP_CLASSES = new Class[] { - PySequenceExpression.class, + PyListLiteralExpression.class, + PySetLiteralExpression.class, + PyDictLiteralExpression.class, PyDictLiteralExpression.class, PyParenthesizedExpression.class, PyArgumentList.class, diff --git a/python/testSrc/com/jetbrains/python/PyEditingTest.java b/python/testSrc/com/jetbrains/python/PyEditingTest.java index f5ca9f64e85a..d5ca55bc6f80 100644 --- a/python/testSrc/com/jetbrains/python/PyEditingTest.java +++ b/python/testSrc/com/jetbrains/python/PyEditingTest.java @@ -464,4 +464,13 @@ public class PyEditingTest extends PyTestCase { doTestEnter("(\"some string\", 1)", "(\"some \"\n" + " \"string\", 1)"); } + + // PY-15609 + public void testEnterInStringInTupleWithoutParenthesis() { + doTestEnter("def hello_world():\n" + + " return bar, 'some'", + "def hello_world():\n" + + " return bar, 'so' \\\n" + + " 'me'"); + } }