diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateModuleLibraryChooser.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateModuleLibraryChooser.java index 6af4271da6a6..7cc91c66cbcf 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateModuleLibraryChooser.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateModuleLibraryChooser.java @@ -68,7 +68,9 @@ public class CreateModuleLibraryChooser implements ClasspathElementChooser EP_NAME = ExtensionPointName.create("com.intellij.selectionDequotingFilter"); private TextRange myReplacedTextRange; + private int myCaretPosition; @Override public Result checkAutoPopup(char c, Project project, Editor editor, PsiFile psiFile) { @@ -44,8 +46,8 @@ public class SelectionQuotingTypedHandler extends TypedHandlerDelegate { if (selectedText.length() < 1) { return super.checkAutoPopup(c, project, editor, psiFile); } - char c2 = getMatchingDelimiter(c); - if (selectedText.length() > 1) { + myCaretPosition = editor.getCaretModel().getOffset(); + if (selectedText.length() > 1 && !Registry.is("editor.smarterSelectionQuoting")) { final char firstChar = selectedText.charAt(0); if (isSimilarDelimiters(firstChar, c) && selectedText.charAt(selectedText.length() - 1) == getMatchingDelimiter(firstChar) && @@ -55,10 +57,15 @@ public class SelectionQuotingTypedHandler extends TypedHandlerDelegate { selectedText = selectedText.substring(1, selectedText.length() - 1); } } - int caretOffset = editor.getSelectionModel().getSelectionStart(); + final int caretOffset = editor.getSelectionModel().getSelectionStart(); + final char c2 = getMatchingDelimiter(c); final String newText = String.valueOf(c) + selectedText + c2; EditorModificationUtil.insertStringAtCaret(editor, newText); - myReplacedTextRange = new TextRange(caretOffset, caretOffset + newText.length()); + if (Registry.is("editor.smarterSelectionQuoting")) { + myReplacedTextRange = new TextRange(caretOffset + 1, caretOffset + newText.length() - 1); + } else { + myReplacedTextRange = new TextRange(caretOffset, caretOffset + newText.length()); + } return Result.STOP; } return super.checkAutoPopup(c, project, editor, psiFile); @@ -101,6 +108,9 @@ public class SelectionQuotingTypedHandler extends TypedHandlerDelegate { if (myReplacedTextRange != null) { if (myReplacedTextRange.getEndOffset() <= editor.getDocument().getTextLength()) { editor.getSelectionModel().setSelection(myReplacedTextRange.getStartOffset(), myReplacedTextRange.getEndOffset()); + if (Registry.is("editor.smarterSelectionQuoting")) { + editor.getCaretModel().moveToOffset(myCaretPosition + 1); + } } myReplacedTextRange = null; return Result.STOP; diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java index a8bf37c44ac2..24787249a25b 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java @@ -67,6 +67,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.plaf.PanelUI; import javax.swing.tree.TreeNode; import java.awt.*; import java.awt.event.MouseAdapter; @@ -169,6 +170,12 @@ public class NavBarPanel extends JPanel implements DataProvider, PopupOwner, Dis getNavBarUI().clearItems(); } + @Override + public void setUI(PanelUI ui) { + getNavBarUI().clearItems(); + super.setUI(ui); + } + public NavBarUpdateQueue getUpdateQueue() { return myUpdateQueue; } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeader.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeader.java index 3e3f27c3e8cf..4ce4648448d0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeader.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeader.java @@ -38,8 +38,10 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import javax.swing.*; +import javax.swing.plaf.PanelUI; import java.awt.*; import java.awt.event.*; +import java.awt.image.BufferedImage; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -63,6 +65,8 @@ public abstract class ToolWindowHeader extends JPanel implements Disposable { private ToolWindow myToolWindow; private WindowInfoImpl myInfo; private final ToolWindowHeader.ActionButton myHideButton; + private BufferedImage myImage; + private BufferedImage myActiveImage; public ToolWindowHeader(final ToolWindowImpl toolWindow, WindowInfoImpl info, @NotNull final Producer gearProducer) { setLayout(new BorderLayout()); @@ -213,40 +217,80 @@ public abstract class ToolWindowHeader extends JPanel implements Disposable { @Override protected void paintComponent(Graphics g) { Rectangle r = getBounds(); - Graphics2D g2d = (Graphics2D)g; - Shape clip = g2d.getClip(); - g2d.setColor(UIUtil.getPanelBackground()); - g2d.fill(clip); - - g2d.setPaint(new GradientPaint(0, 0, new Color(0, 0, 0, 5), 0, r.height, new Color(0, 0, 0, 20))); - g2d.fill(clip); - - g2d.setColor(new Color(0, 0, 0, 90)); - g2d.drawLine(r.x, r.y, r.width - 1, r.y); - g2d.drawLine(r.x, r.height - 1, r.width - 1, r.height - 1); - - g2d.setColor(new Color(255, 255, 255, 100)); - g2d.drawLine(r.x, r.y + 1, r.width - 1, r.y + 1); - + Image image; if (isActive()) { - g2d.setColor(new Color(100, 150, 230, 50)); - g2d.fill(clip); + if (myActiveImage == null || myActiveImage.getHeight() != r.height) { + myActiveImage = drawToBuffer(true, r.height); + } + + image = myActiveImage; + } else { + if (myImage == null || myImage.getHeight() != r.height) { + myImage = drawToBuffer(false, r.height); + } + + image = myImage; } + + Rectangle clipBounds = clip.getBounds(); + for (int x = clipBounds.x; x < clipBounds.x + clipBounds.width; x+=150) { + g2d.drawImage(image, x, 0, null); + } + } + + private static BufferedImage drawToBuffer(boolean active, int height) { + final int width = 150; + + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + Graphics2D _g = image.createGraphics(); + + _g.setColor(UIUtil.getPanelBackground()); + _g.fillRect(0, 0, width, height); + + _g.setPaint(new GradientPaint(0, 0, new Color(0, 0, 0, 5), 0, height, new Color(0, 0, 0, 20))); + _g.fillRect(0, 0, width, height); + + _g.setColor(new Color(0, 0, 0, 90)); + _g.drawLine(0, 0, width, 0); + _g.drawLine(0, height - 1, width, height - 1); + + _g.setColor(new Color(255, 255, 255, 100)); + _g.drawLine(0, 1, width, 1); + + if (active) { + _g.setColor(new Color(100, 150, 230, 50)); + _g.fillRect(0, 0, width, height); + } + + _g.dispose(); + return image; + } + + @Override + public void setUI(PanelUI ui) { + myImage = null; + myActiveImage = null; + + super.setUI(ui); } @Override protected void paintChildren(Graphics g) { - super.paintChildren(g); + Graphics2D graphics = (Graphics2D) g.create(); + + UIUtil.applyRenderingHints(graphics); + super.paintChildren(graphics); Rectangle r = getBounds(); - Graphics2D g2d = (Graphics2D)g; if (!isActive()) { - g2d.setColor(new Color(255, 255, 255, 30)); - g2d.fill(r); + graphics.setColor(new Color(255, 255, 255, 30)); + graphics.fill(r); } + + graphics.dispose(); } protected abstract boolean isActive(); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ComboContentLayout.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ComboContentLayout.java index c30dfd2749c4..22dfd22b7dfd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ComboContentLayout.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ComboContentLayout.java @@ -21,11 +21,13 @@ import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentManagerEvent; import java.awt.*; +import java.awt.image.BufferedImage; class ComboContentLayout extends ContentLayout { BaseLabel myIdLabel; ContentComboLabel myComboLabel; + private BufferedImage myImage; ComboContentLayout(ToolWindowContentUi ui) { super(ui); @@ -43,6 +45,7 @@ class ComboContentLayout extends ContentLayout { public void reset() { myIdLabel = null; myComboLabel = null; + myImage = null; } @Override @@ -71,25 +74,28 @@ class ComboContentLayout extends ContentLayout { public void paintComponent(Graphics g) { if (!isToDrawCombo()) return; - final Graphics2D g2d = (Graphics2D)g; - - final GraphicsConfig c = new GraphicsConfig(g); - c.setAntialiasing(true); - Rectangle r = myComboLabel.getBounds(); - - //g2d.setPaint(new GradientPaint(r.x, r.y, new SameColor(200), r.x, r.y + r.height, new SameColor(190))); - g2d.setPaint(new GradientPaint(r.x, r.y, new Color(0, 0, 0, 10), r.x, r.y + r.height, new Color(0, 0, 0, 30))); - g2d.fillRect(r.x, r.y, r.width, r.height); - - g2d.setColor(new Color(0, 0, 0, 60)); - g2d.drawLine(r.x, r.y, r.x, r.y + r.height); - g2d.drawLine(r.x + r.width - 1, r.y, r.x + r.width - 1, r.y + r.height); - g2d.setColor(new Color(255, 255, 255, 80)); - g2d.drawRect(r.x + 1, r.y, r.width - 3, r.height - 1); - - c.restore(); + if (myImage == null || myImage.getHeight() != r.height || myImage.getWidth() != r.width) { + myImage = new BufferedImage(r.width, r.height, BufferedImage.TYPE_INT_ARGB); + final Graphics2D g2d = myImage.createGraphics(); + final GraphicsConfig c = new GraphicsConfig(g); + c.setAntialiasing(true); + + g2d.setPaint(new GradientPaint(0, 0, new Color(0, 0, 0, 10), 0, r.height, new Color(0, 0, 0, 30))); + g2d.fillRect(0, 0, r.width, r.height); + + g2d.setColor(new Color(0, 0, 0, 60)); + g2d.drawLine(0, 0, 0, r.height); + g2d.drawLine(r.width - 1, 0, r.width - 1, r.height); + + g2d.setColor(new Color(255, 255, 255, 80)); + g2d.drawRect(1, 0, r.width - 3, r.height - 1); + + g2d.dispose(); + } + + g.drawImage(myImage, r.x, r.y, null); } @Override @@ -132,6 +138,11 @@ class ComboContentLayout extends ContentLayout { public void contentRemoved(ContentManagerEvent event) { } + @Override + public boolean shouldDrawDecorations() { + return isToDrawCombo(); + } + @Override public void showContentPopup(ListPopup listPopup) { listPopup.setMinimumSize(new Dimension(myComboLabel.getPreferredSize().width, 0)); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentLayout.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentLayout.java index e11785928eb0..3006bcc46738 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentLayout.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentLayout.java @@ -63,8 +63,10 @@ abstract class ContentLayout { public abstract void contentRemoved(ContentManagerEvent event); + public abstract boolean shouldDrawDecorations(); + protected void updateIdLabel(BaseLabel label) { - label.setText(myUi.myWindow.getId()); + label.setText(myUi.myWindow.getId() + (shouldDrawDecorations() ? ":" : "")); label.setBorder(new EmptyBorder(0, 2, 0, 8)); if (myUi.myManager.getContentCount() == 1) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentTabLabel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentTabLabel.java index 8beb7717fade..df151dee08a4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentTabLabel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentTabLabel.java @@ -79,7 +79,7 @@ class ContentTabLabel extends BaseLabel { @Override protected Color getPassiveFg(boolean selected) { if (contentManager().getContentCount() > 1) { - return selected ? new SameColor(220) : super.getPassiveFg(selected); + return selected ? new SameColor(255) : super.getPassiveFg(selected); } return super.getPassiveFg(selected); } @@ -95,7 +95,7 @@ class ContentTabLabel extends BaseLabel { @Override protected Graphics _getGraphics(Graphics2D g) { if (isSelected() && contentManager().getContentCount() > 1) { - return new EngravedTextGraphics(g, 1, 1, myUi.myWindow.isActive() ? new Color(0, 0, 0, 200) : new Color(0, 0, 0, 130)); + return new EngravedTextGraphics(g, 1, 1, myUi.myWindow.isActive() ? new Color(0, 0, 0, 120) : new Color(0, 0, 0, 130)); } return super._getGraphics(g); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/TabContentLayout.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/TabContentLayout.java index b1a7b72eb2ed..4ef8a68285bb 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/TabContentLayout.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/TabContentLayout.java @@ -30,6 +30,7 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -45,6 +46,8 @@ class TabContentLayout extends ContentLayout { ArrayList myTabs = new ArrayList(); final Map myContent2Tabs = new HashMap(); + private Map myCached = new com.intellij.util.containers.HashMap(); + BaseLabel myIdLabel; private final MoreIcon myMoreIcon = new MoreIcon() { @@ -247,7 +250,6 @@ class TabContentLayout extends ContentLayout { myLastLayout = data; } - static void dropTab(final LayoutData data, final ContentTabLabel toDropLabel) { data.requiredWidth -= (toDropLabel.getPreferredSize().width + 1); data.toDrop.add(toDropLabel); @@ -287,76 +289,91 @@ class TabContentLayout extends ContentLayout { public void paintComponent(Graphics g) { if (!isToDrawTabs()) return; - final Graphics2D g2d = (Graphics2D)g; - - final GraphicsConfig c = new GraphicsConfig(g); - c.setAntialiasing(true); - boolean prevSelected = false; for (int i = 0; i < myTabs.size(); i++) { boolean last = i == myTabs.size() - 1; ContentTabLabel each = myTabs.get(i); Rectangle r = each.getBounds(); + + StringBuilder key = new StringBuilder().append(i); + if (each.isSelected()) key.append('s'); + if (prevSelected) key.append('p'); + if (last) key.append('l'); + if (myUi.myWindow.isActive()) key.append('a'); + + BufferedImage image = myCached.get(key.toString()); + if (image == null || image.getWidth() != r.width || image.getHeight() != r.height) { + image = drawToBuffer(r, each.isSelected(), last, prevSelected, myUi.myWindow.isActive()); + myCached.put(key.toString(), image); + } - if (each.isSelected()) { - g2d.setColor(new Color(0, 0, 0, 150)); - g2d.fillRect(r.x, r.y, r.width, r.height); - - g2d.setColor(new Color(0, 0, 0, 90)); - g2d.drawLine(r.x, r.y, r.x + r.width - 1, r.y); - g2d.drawLine(r.x, r.y + 1, r.x, r.y + r.height - 1); - - g2d.setColor(new Color(0, 0, 0, 20)); - g2d.drawLine(r.x + 1, r.y + 1, r.x + r.width - 1, r.y + 1); - g2d.drawLine(r.x + 1, r.y + 2, r.x + 1, r.y + r.height - 2); - - g2d.setColor(new Color(0, 0, 0, 20)); - g2d.drawLine(r.x + r.width - 1, r.y + 2, r.x + r.width - 1, r.y + r.height - 2); - g2d.drawLine(r.x + 1, r.y + r.height - 1, r.x + r.width - 1, r.y + r.height - 1); - - if (myUi.myWindow.isActive()) { - g2d.setColor(new Color(100, 150, 230, 50)); - g2d.fill(r); - } - } - else { - g2d.setPaint(new GradientPaint(r.x, r.y, new Color(0, 0, 0, 10), r.x, r.y + r.height, new Color(0, 0, 0, 30))); - g2d.fillRect(r.x, r.y, r.width, r.height); - - if (last) { - if (prevSelected) { - g2d.setColor(new Color(255, 255, 255, 80)); - g2d.drawRect(r.x, r.y, r.width - 1, r.height - 1); - - } else { - g2d.setColor(new Color(255, 255, 255, 80)); - g2d.drawRect(r.x + 1, r.y, r.width - 2, r.height - 1); - - g2d.setColor(new Color(0, 0, 0, 60)); - g2d.drawLine(r.x, r.y, r.x, r.y + r.height); - } - - g2d.setColor(new Color(0, 0, 0, 60)); - g2d.drawLine(r.x + r.width, r.y, r.x + r.width, r.y + r.height); - } else { - if (prevSelected) { - g2d.setColor(new Color(255, 255, 255, 80)); - g2d.drawRect(r.x, r.y, r.width - 1, r.height - 1); - } - else { - g2d.setColor(new Color(255, 255, 255, 80)); - g2d.drawRect(r.x + 1, r.y, r.width - 2, r.height - 1); - - g2d.setColor(new Color(0, 0, 0, 60)); - g2d.drawLine(r.x, r.y, r.x, r.y + r.height); - } - } - } + g.drawImage(image, r.x, r.y, null); prevSelected = each.isSelected(); } + } + + private static BufferedImage drawToBuffer(Rectangle r, boolean selected, boolean last, boolean prevSelected, boolean active) { + BufferedImage image = new BufferedImage(r.width, r.height, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2d = image.createGraphics(); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + if (selected) { + g2d.setColor(active ? new Color(0, 0, 0, 70) : new Color(0, 0, 0, 90)); + g2d.fillRect(0, 0, r.width, r.height); - c.restore(); + g2d.setColor(new Color(0, 0, 0, 140)); + g2d.drawLine(0, 0, r.width - 1, 0); + g2d.drawLine(0, 1, 0, r.height - 1); + + g2d.setColor(new Color(0, 0, 0, 20)); + g2d.drawLine(1, 1, r.width - 1, 1); + g2d.drawLine(1, 2, 1, r.height - 2); + g2d.drawLine(1, r.height - 1, r.width - 1, r.height - 1); + + g2d.setColor(new Color(0, 0, 0, 60)); + g2d.drawLine(r.width - 1, 1, r.width - 1, r.height - 2); + + if (active) { + g2d.setColor(new Color(100, 150, 230, 50)); + g2d.fill(new Rectangle(0, 0, r.width, r.height)); + } + } + else { + g2d.setPaint(new GradientPaint(0, 0, new Color(0, 0, 0, 10), 0, r.height, new Color(0, 0, 0, 30))); + g2d.fillRect(0, 0, r.width, r.height); + + if (last) { + if (prevSelected) { + g2d.setColor(new Color(255, 255, 255, 80)); + g2d.drawRect(0, 0, r.width - 2, r.height - 1); + } else { + g2d.setColor(new Color(255, 255, 255, 80)); + g2d.drawRect(1, 0, r.width - 3, r.height - 1); + + g2d.setColor(new Color(0, 0, 0, 60)); + g2d.drawLine(0, 0, 0, r.height); + } + + g2d.setColor(new Color(0, 0, 0, 60)); + g2d.drawLine(r.width - 1, 0, r.width - 1, r.height); + } else { + if (prevSelected) { + g2d.setColor(new Color(255, 255, 255, 80)); + g2d.drawRect(0, 0, r.width - 1, r.height - 1); + } + else { + g2d.setColor(new Color(255, 255, 255, 80)); + g2d.drawRect(1, 0, r.width - 2, r.height - 1); + + g2d.setColor(new Color(0, 0, 0, 60)); + g2d.drawLine(0, 0, 0, r.height); + } + } + } + + g2d.dispose(); + return image; } @Override @@ -388,6 +405,8 @@ class TabContentLayout extends ContentLayout { myUi.add(each); myUi.initMouseListeners(each, myUi); } + + myCached.clear(); } @Override @@ -395,6 +414,8 @@ class TabContentLayout extends ContentLayout { final ContentTabLabel tab = new ContentTabLabel(event.getContent(), this); myTabs.add(event.getIndex(), tab); myContent2Tabs.put(event.getContent(), tab); + + myCached.clear(); } @Override @@ -404,6 +425,13 @@ class TabContentLayout extends ContentLayout { myTabs.remove(tab); myContent2Tabs.remove(event.getContent()); } + + myCached.clear(); + } + + @Override + public boolean shouldDrawDecorations() { + return isToDrawTabs(); } @Override diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 2672c2edfcd5..defbbf58363a 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -95,6 +95,7 @@ editor.balloonHints=true editor.mouseSelectionStateResetTimeout=1000 editor.mouseSelectionStateResetDeadzone=4 editor.use.new.tabs=true +editor.smarterSelectionQuoting=false ide.tabbedPane.bufferedPaint=true ide.tabbedPane.dragOutMultiplier=1.2 diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XFramesView.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XFramesView.java index 92876b857c75..b3f3a5b3786f 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XFramesView.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XFramesView.java @@ -216,9 +216,11 @@ public class XFramesView extends XDebugViewBase { public void errorOccurred(final String errorMessage) { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { - myErrorMessage = errorMessage; - addFrameListElements(Collections.singletonList(errorMessage), true); - myRunning = false; + if (myErrorMessage == null) { + myErrorMessage = errorMessage; + addFrameListElements(Collections.singletonList(errorMessage), true); + myRunning = false; + } } }); } @@ -253,7 +255,7 @@ public class XFramesView extends XDebugViewBase { } public void start() { - if (myExecutionStack == null) { + if (myExecutionStack == null || myErrorMessage != null) { return; } myRunning = true; diff --git a/plugins/github/src/org/jetbrains/plugins/github/RepositoryInfo.java b/plugins/github/src/org/jetbrains/plugins/github/RepositoryInfo.java index 08e37fab6ea5..f9c6632466f4 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/RepositoryInfo.java +++ b/plugins/github/src/org/jetbrains/plugins/github/RepositoryInfo.java @@ -35,7 +35,7 @@ public class RepositoryInfo { } public String getUrl() { - return myRepository.getChildText("url"); + return myRepository.getChildText("url") + ".git"; } @Override diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/InvertIfIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/InvertIfIntention.java index 6b55e4d7938a..4407678fa92c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/InvertIfIntention.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/InvertIfIntention.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.intentions.base.Intention; import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrBlockStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; @@ -31,8 +32,6 @@ public class InvertIfIntention extends Intention { GrIfStatement parentIf = (GrIfStatement)parent; GroovyPsiElementFactory groovyPsiElementFactory = GroovyPsiElementFactory.getInstance(project); - GrStatement thenBranch = parentIf.getThenBranch(); - GrStatement elseBranch = parentIf.getElseBranch(); GrExpression condition = parentIf.getCondition(); if (condition == null) { @@ -47,30 +46,43 @@ public class InvertIfIntention extends Intention { } } - if (negatedCondition==null) { + if (negatedCondition == null) { // Now check whether this is a simple expression condition = stripParenthesis(condition); String negatedExpressionText; if (condition instanceof GrCallExpression || condition instanceof GrReferenceExpression) { negatedExpressionText = "!" + condition.getText(); - } else { + } + else { negatedExpressionText = "!(" + condition.getText() + ")"; } negatedCondition = groovyPsiElementFactory.createExpressionFromText(negatedExpressionText, parentIf); } - GrIfStatement newIf = (GrIfStatement)groovyPsiElementFactory.createStatementFromText( - "if (" + negatedCondition.getText() + ") " + - (elseBranch != null ? elseBranch.getText() : "{}") + " else " + - (thenBranch != null ? thenBranch.getText() : "{}"), parentIf.getContext() - ); + + GrStatement thenBranch = parentIf.getThenBranch(); + GrStatement elseBranch = parentIf.getElseBranch(); + String newIfText = "if (" + negatedCondition.getText() + ") " + (elseBranch != null ? elseBranch.getText() : "{}"); + + boolean isThenEmpty = thenBranch == null || (thenBranch instanceof GrBlockStatement) && ((GrBlockStatement)thenBranch).getBlock().getStatements().length == 0; + if (!isThenEmpty) { + newIfText += " else " + thenBranch.getText(); + } + + + GrIfStatement newIf = (GrIfStatement)groovyPsiElementFactory.createStatementFromText(newIfText, parentIf.getContext()); parentIf.replace(newIf); } + @NotNull private static GrExpression stripParenthesis(GrExpression operand) { while (operand instanceof GrParenthesizedExpression) { - operand = ((GrParenthesizedExpression) operand).getOperand(); + GrExpression innerExpression = ((GrParenthesizedExpression)operand).getOperand(); + if (innerExpression == null) { + break; + } + operand = innerExpression; } return operand; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java index 236cbb92b808..c74f573f62d6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java @@ -586,6 +586,11 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { @Override public void visitCaseSection(GrCaseSection caseSection) { + GrExpression value = caseSection.getCaseLabel().getValue(); + if (value != null) { + value.accept(this); + } + for (GrStatement statement : caseSection.getStatements()) { statement.accept(this); } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/InvertIfTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/InvertIfTest.groovy index 102faf3f5b33..a982565a217c 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/InvertIfTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/InvertIfTest.groovy @@ -112,4 +112,16 @@ if (a) { ''' } + public void testEmptyThenBlockIsRemoved() throws Exception { + doTest ''' +if (a) { +} else { + no_succes } +''', '''if (!a) { + no_succes +} +''' + } + +} \ No newline at end of file diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy index 5b7fd922bb4c..76ade3fc24a0 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy @@ -187,6 +187,7 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase { public void testUnusedVariable() throws Exception { doTest(new UnusedDefInspection()); } public void testDefinitionUsedInClosure() throws Exception { doTest(new UnusedDefInspection()); } public void testDefinitionUsedInClosure2() throws Exception { doTest(new UnusedDefInspection()); } + public void testDefinitionUsedInSwitchCase() throws Exception { doTest(new UnusedDefInspection()); } public void testDuplicateInnerClass() throws Throwable{doTest();} public void testThisInStaticContext() throws Throwable {doTest();} diff --git a/plugins/groovy/testdata/highlighting/DefinitionUsedInSwitchCase.groovy b/plugins/groovy/testdata/highlighting/DefinitionUsedInSwitchCase.groovy new file mode 100644 index 000000000000..e864e59f0b8e --- /dev/null +++ b/plugins/groovy/testdata/highlighting/DefinitionUsedInSwitchCase.groovy @@ -0,0 +1,9 @@ +def m = [a: 1, b: 2] +def m1 = [a: 1, b: 2] +def val = 'a' + +switch (val) { + case m: "key in map"; break +// equivalent to case { val in m }: ... + default: "not in map" +} \ No newline at end of file diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java index 1555d8a4d68e..e3bd50133df9 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java @@ -80,7 +80,7 @@ public abstract class DomInvocationHandler" + parameter.getName()); + LOG.error("No converter specified: String<->" + parameter.getName() + "; method=" + method); } return converter; }