From 142fec3ff008e31d4c4d952d6a781bdaa2deea6d Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Thu, 5 May 2011 15:29:37 +0400 Subject: [PATCH 001/250] IDEA-60082 Invalid nodes appear in Project Tree after Undo Move a class from a file if the class has usages in the current file --- .../intellij/ide/util/treeView/AbstractTreeUpdater.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java index 58b5b2efb36d..ce728a1e7080 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java @@ -116,7 +116,7 @@ public class AbstractTreeUpdater implements Disposable, Activatable { for (Iterator iterator = myNodeQueue.iterator(); iterator.hasNext();) { final TreeUpdatePass passInQueue = iterator.next(); - if (toAdd.isUpdateChildren() && toAdd.isUpdateStructure()) { + if (toAdd.isUpdateStructure() == passInQueue.isUpdateStructure()) { if (passInQueue == toAdd) { toAdd.expire(); break; @@ -133,11 +133,6 @@ public class AbstractTreeUpdater implements Disposable, Activatable { iterator.remove(); passInQueue.expire(); } - } else if (!passInQueue.isUpdateStructure()) { - if (passInQueue.getNode().isNodeAncestor(toAdd.getNode()) ) { - iterator.remove(); - passInQueue.expire(); - } } } } From ba6326af5ec74e42b2bd8169a3073c8b98353268 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Fri, 6 May 2011 14:28:39 +0400 Subject: [PATCH 002/250] [xena] mnemonics fix for dialogs in balloons --- .../openapi/ui/popup/BalloonBuilder.java | 4 + .../src/com/intellij/ide/IdeEventQueue.java | 16 +++ .../editor/impl/EditorComponentImpl.java | 6 +- .../keymap/impl/IdeKeyEventDispatcher.java | 10 +- .../keymap/impl/MnemonicContainer.java | 26 +++++ .../openapi/wm/impl/IdeGlassPaneEx.java | 3 + .../openapi/wm/impl/IdeGlassPaneImpl.java | 14 +++ .../src/com/intellij/ui/BalloonImpl.java | 100 ++++++++++++++---- .../ui/popup/BalloonPopupBuilderImpl.java | 11 +- .../src/misc/registry.properties | 1 + 10 files changed, 163 insertions(+), 28 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/openapi/keymap/impl/MnemonicContainer.java diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/BalloonBuilder.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/BalloonBuilder.java index 1bbaf6010828..125f1377b32f 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/BalloonBuilder.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/BalloonBuilder.java @@ -72,5 +72,9 @@ public interface BalloonBuilder { boolean isHideOnAction(); + @NotNull BalloonBuilder setHideOnAction(boolean hideOnAction); + + @NotNull + BalloonBuilder setDialogMode(boolean dialogMode); } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index b9818b10140a..d6e80485eae4 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -131,6 +131,8 @@ public class IdeEventQueue extends EventQueue { private boolean myKeyboardBusy; private boolean myDispatchingFocusEvent; + private int myInputMethodLock; + private static class IdeEventQueueHolder { private static final IdeEventQueue INSTANCE = new IdeEventQueue(); } @@ -903,4 +905,18 @@ public class IdeEventQueue extends EventQueue { return !dispatch; } } + + public boolean isInputMethodEnabled() { + return !SystemInfo.isMac || myInputMethodLock == 0; + } + + public void disableInputMethods(Disposable parentDisposable) { + myInputMethodLock++; + Disposer.register(parentDisposable, new Disposable() { + @Override + public void dispose() { + myInputMethodLock--; + } + }); + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java index cabfc5795562..5481bcc4eecf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.editor.impl; +import com.intellij.ide.IdeEventQueue; import com.intellij.ide.ui.UISettings; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.PlatformDataKeys; @@ -24,11 +25,14 @@ import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.ui.Queryable; import com.intellij.openapi.ui.TypingTarget; import com.intellij.openapi.util.ActionCallback; +import com.intellij.util.ReflectionUtil; import javax.swing.*; import java.awt.*; import java.awt.event.ComponentEvent; +import java.awt.event.FocusEvent; import java.awt.event.InputMethodEvent; +import java.awt.im.InputContext; import java.awt.im.InputMethodRequests; import java.util.Map; @@ -108,7 +112,7 @@ public class EditorComponentImpl extends JComponent implements Scrollable, DataP } public InputMethodRequests getInputMethodRequests() { - return myEditor.getInputMethodRequests(); + return IdeEventQueue.getInstance().isInputMethodEnabled() ? myEditor.getInputMethodRequests() : null; } public void paintComponent(Graphics g) { diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java index 339a66949045..bd19fb67559a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java @@ -384,10 +384,12 @@ public final class IdeKeyEventDispatcher implements Disposable { } if (SystemInfo.isMac) { - if (e.getModifiersEx() == InputEvent.ALT_DOWN_MASK && - (e.getID() == KeyEvent.KEY_PRESSED && hasMnemonicInWindow(focusOwner, e.getKeyCode()) || - e.getID() == KeyEvent.KEY_TYPED && hasMnemonicInWindow(focusOwner, e.getKeyChar()))) - { + boolean keyTyped = e.getID() == KeyEvent.KEY_TYPED; + boolean hasMnemonicsInWindow = e.getID() == KeyEvent.KEY_PRESSED && hasMnemonicInWindow(focusOwner, e.getKeyCode()) || + keyTyped && hasMnemonicInWindow(focusOwner, e.getKeyChar()); + boolean imEnabled = IdeEventQueue.getInstance().isInputMethodEnabled(); + + if (e.getModifiersEx() == InputEvent.ALT_DOWN_MASK && (hasMnemonicsInWindow || (!imEnabled && keyTyped))) { setPressedWasProcessed(true); setState(KeyState.STATE_PROCESSED); return false; diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/MnemonicContainer.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/MnemonicContainer.java new file mode 100644 index 000000000000..7587f5ac5268 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/MnemonicContainer.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2011 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.openapi.keymap.impl; + +/** + * Created by IntelliJ IDEA. + * User: kirillk + * Date: 5/5/11 + * Time: 1:25 PM + * To change this template use File | Settings | File Templates. + */ +public interface MnemonicContainer { +} diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneEx.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneEx.java index 210a8f8d1fa1..a2541a388de3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneEx.java @@ -17,6 +17,7 @@ package com.intellij.openapi.wm.impl; import com.intellij.openapi.wm.IdeGlassPane; +import javax.swing.*; import java.awt.*; /** @@ -30,4 +31,6 @@ public interface IdeGlassPaneEx extends IdeGlassPane { Component getComponent(int index); boolean isInModalContext(); + + JComponent getProxyComponent(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java index 27836ada7e5d..274671581e2c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java @@ -49,11 +49,20 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent private Cursor myLastOriginalCursor; private MouseEvent myPrevPressEvent; + private JPanel myFocusProxy = new JPanel(); + public IdeGlassPaneImpl(JRootPane rootPane) { myRootPane = rootPane; setOpaque(false); setVisible(false); setLayout(null); + + myFocusProxy.setOpaque(false); + myFocusProxy.setPreferredSize(new Dimension(0, 0)); + myFocusProxy.setFocusable(true); + UIUtil.setFocusProxy(myFocusProxy, true); + add(myFocusProxy); + myFocusProxy.setBounds(0, 0, 0, 0); } public boolean dispatch(final AWTEvent e) { @@ -542,4 +551,9 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent public boolean isOptimizedDrawingEnabled() { return !hasPainters() && super.isOptimizedDrawingEnabled(); } + + @Override + public JComponent getProxyComponent() { + return myFocusProxy; + } } diff --git a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java index 72311f96546b..5fff400a9967 100644 --- a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java @@ -15,6 +15,7 @@ */ package com.intellij.ui; +import com.intellij.ide.IdeEventQueue; import com.intellij.ide.IdeTooltip; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.ActionManager; @@ -27,9 +28,14 @@ import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.ui.popup.JBPopupListener; import com.intellij.openapi.ui.popup.LightweightWindow; import com.intellij.openapi.ui.popup.LightweightWindowEvent; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.IconLoader; -import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.*; +import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.wm.FocusRequestor; +import com.intellij.openapi.wm.IdeFocusManager; +import com.intellij.openapi.wm.IdeGlassPane; +import com.intellij.openapi.wm.IdeGlassPaneUtil; +import com.intellij.openapi.wm.impl.IdeGlassPaneEx; +import com.intellij.openapi.wm.impl.IdeGlassPaneImpl; import com.intellij.openapi.wm.impl.content.GraphicsConfig; import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.components.panels.NonOpaquePanel; @@ -38,25 +44,10 @@ import com.intellij.util.Alarm; import com.intellij.util.IJSwingUtilities; import com.intellij.util.Range; import com.intellij.util.containers.HashSet; -import com.intellij.util.ui.Animator; -import com.intellij.util.ui.BaseButtonBehavior; -import com.intellij.util.ui.PositionTracker; -import com.intellij.util.ui.TimedDeadzone; -import com.intellij.util.ui.Tree; -import com.intellij.util.ui.UIUtil; +import com.intellij.util.ui.*; import org.jetbrains.annotations.Nullable; -import javax.swing.Icon; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JLayeredPane; -import javax.swing.JPanel; -import javax.swing.JRootPane; -import javax.swing.JTree; -import javax.swing.JWindow; -import javax.swing.SwingUtilities; +import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; import java.awt.event.AWTEventListener; @@ -156,6 +147,8 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi private int myPositionChangeXShift; private int myPositionChangeYShift; + private boolean myDialogMode; + private IdeFocusManager myFocusManager; public boolean isInsideBalloon(MouseEvent me) { return isInside(new RelativePoint(me)); @@ -207,7 +200,8 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi int animationCycle, int calloutShift, int positioChangeXShfit, - int positionChangeYShift) { + int positionChangeYShift, + boolean dialogMode) { myBorderColor = borderColor; myFillColor = fillColor; myContent = content; @@ -222,6 +216,30 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi myCalloutshift = calloutShift; myPositionChangeXShift = positioChangeXShfit; myPositionChangeYShift = positionChangeYShift; + myDialogMode = dialogMode; + + + if (!myDialogMode) { + new AwtVisitor(content) { + @Override + public boolean visit(Component component) { + if (component instanceof JLabel) { + JLabel label = (JLabel)component; + if (label.getDisplayedMnemonic() != '\0' || label.getDisplayedMnemonicIndex() >= 0) { + myDialogMode = true; + return true; + } + } else if (component instanceof JCheckBox) { + JCheckBox checkBox = (JCheckBox)component; + if (checkBox.getMnemonic() >= 0 || checkBox.getDisplayedMnemonicIndex() >= 0) { + myDialogMode = true; + return true; + } + } + return false; + } + }; + } myFadeoutTime = fadeoutTime; myAnimationCycle = animationCycle; @@ -312,6 +330,34 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi myPosition = position; UIUtil.setFutureRootPane(myContent, root); + myFocusManager = IdeFocusManager.findInstanceByComponent(myLayeredPane); + final Ref originalFocusOwner = new Ref(); + final Ref focusRequestor = new Ref(); + final Ref proxyFocusRequest = new Ref(new ActionCallback.Done()); + + boolean mnemonicsFix = myDialogMode && SystemInfo.isMac && Registry.is("ide.mac.inplaceDialogMnemonicsFix"); + if (mnemonicsFix) { + final IdeGlassPaneEx glassPane = (IdeGlassPaneEx)IdeGlassPaneUtil.find(myLayeredPane); + assert glassPane != null; + + proxyFocusRequest.set(new ActionCallback()); + + myFocusManager.doWhenFocusSettlesDown(new ExpirableRunnable() { + @Override + public boolean isExpired() { + return isDisposed(); + } + + @Override + public void run() { + IdeEventQueue.getInstance().disableInputMethods(BalloonImpl.this); + originalFocusOwner.set(myFocusManager.getFocusOwner()); + myFocusManager.requestFocus(glassPane.getProxyComponent(), true).notify(proxyFocusRequest.get()); + focusRequestor.set(myFocusManager.getFurtherRequestor()); + } + }); + } + myLayeredPane.addComponentListener(myComponentListener); myTargetPoint = myPosition.getShiftedPoint(myTracker.recalculateLocation(this).getPoint(myLayeredPane), myCalloutshift); @@ -377,6 +423,16 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi myLayeredPane.repaint(); + + if (mnemonicsFix) { + proxyFocusRequest.get().doWhenDone(new Runnable() { + @Override + public void run() { + focusRequestor.get().requestFocus(originalFocusOwner.get(), true); + } + }); + } + Toolkit.getDefaultToolkit().addAWTEventListener(myAwtActivityListener, MouseEvent.MOUSE_EVENT_MASK | MouseEvent.MOUSE_MOTION_EVENT_MASK | KeyEvent.KEY_EVENT_MASK); @@ -1246,7 +1302,7 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi //pane.setBorder(new LineBorder(Color.blue)); - balloon.set(new BalloonImpl(new JLabel("FUCK"), Color.black, MessageType.ERROR.getPopupBackground(), true, true, true, true, true, 0, true, null, false, 500, 5, 0, 0)); + balloon.set(new BalloonImpl(new JLabel("FUCK"), Color.black, MessageType.ERROR.getPopupBackground(), true, true, true, true, true, 0, true, null, false, 500, 5, 0, 0, false)); balloon.get().setShowPointer(true); if (e.isShiftDown()) { diff --git a/platform/platform-impl/src/com/intellij/ui/popup/BalloonPopupBuilderImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/BalloonPopupBuilderImpl.java index 8023a052d83d..084d2d255af3 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/BalloonPopupBuilderImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/BalloonPopupBuilderImpl.java @@ -47,6 +47,7 @@ public class BalloonPopupBuilderImpl implements BalloonBuilder { private int myPositionChangeXShift; private int myPositionChangeYShift; private boolean myHideOnAction = true; + private boolean myDialogMode; public BalloonPopupBuilderImpl(@NotNull final JComponent content) { myContent = content; @@ -58,11 +59,19 @@ public class BalloonPopupBuilderImpl implements BalloonBuilder { } @Override + @NotNull public BalloonBuilder setHideOnAction(boolean hideOnAction) { myHideOnAction = hideOnAction; return this; } + @NotNull + @Override + public BalloonBuilder setDialogMode(boolean dialogMode) { + myDialogMode = dialogMode; + return this; + } + @NotNull public BalloonBuilder setPreferredPosition(final Balloon.Position position) { myPrefferedPosition = position; @@ -135,7 +144,7 @@ public class BalloonPopupBuilderImpl implements BalloonBuilder { @NotNull public Balloon createBalloon() { return new BalloonImpl(myContent, myBorder, myFill, myHideOnMouseOutside, myHideOnKeyOutside, myHideOnAction, myShowCalllout, myCloseButtonEnabled, myFadeoutTime, myHideOnFrameResize, myClickHandler, myCloseOnClick, myAnimationCycle, - myCalloutShift, myPositionChangeXShift, myPositionChangeYShift); + myCalloutShift, myPositionChangeXShift, myPositionChangeYShift, myDialogMode); } @NotNull diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 026671cd81da..06d5bbe79dcf 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -89,6 +89,7 @@ ide.tabbedPane.dragOutMultiplier=1.2 ide.mac.filechooser.showhidden.files=false ide.mac.filechooser.native=true +ide.mac.inplaceDialogMnemonicsFix=true debugger.valueTooltipAutoShow=true debugger.valueTooltipAutoShow.description=Auto show tooltip on mouse over From 61fd47910e333926543e681da1a4a2cc4d9242b5 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Fri, 6 May 2011 16:07:18 +0400 Subject: [PATCH 003/250] [xena] mnemonics fix for dialogs in balloons - 2 --- platform/platform-impl/src/com/intellij/ui/BalloonImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java index 5fff400a9967..e5dd37475b91 100644 --- a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java @@ -428,7 +428,7 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi proxyFocusRequest.get().doWhenDone(new Runnable() { @Override public void run() { - focusRequestor.get().requestFocus(originalFocusOwner.get(), true); + myFocusManager.requestFocus(originalFocusOwner.get(), true); } }); } From dd946e51ae0fa3ffe8e9b6538b7daa7a86346014 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 May 2011 11:34:36 +0200 Subject: [PATCH 004/250] IDEA-68610 - final --- .../src/org/intellij/lang/xpath/XPath2TokenTypes.java | 1 + .../lang/xpath/psi/impl/XPathBinaryExpressionImpl.java | 4 ++-- .../lang/xpath/validation/ExpectedTypeUtil.java | 2 +- .../test/org/intellij/lang/xpath/XPath2TypeTest.java | 10 ++++++++++ .../highlighting/types/durationIDivNumeric.xpath2 | 1 + .../highlighting/types/numericIDivDuration.xpath2 | 1 + 6 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/durationIDivNumeric.xpath2 create mode 100644 plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/numericIDivDuration.xpath2 diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPath2TokenTypes.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPath2TokenTypes.java index 54f311c69f95..ebc633d67968 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPath2TokenTypes.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/XPath2TokenTypes.java @@ -75,6 +75,7 @@ public final class XPath2TokenTypes { public static final TokenSet OCCURRENCE_OPS = TokenSet.create(XPathTokenTypes.PLUS, XPathTokenTypes.STAR, QUEST); public static final TokenSet BOOLEAN_OPERATIONS = TokenSet.orSet(XPathTokenTypes.BOOLEAN_OPERATIONS, COMP_OPS); + public static final TokenSet NUMBER_OPERATIONS = TokenSet.orSet(XPathTokenTypes.NUMBER_OPERATIONS, TokenSet.create(IDIV)); public static final TokenSet KEYWORDS = TokenSet.orSet( diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathBinaryExpressionImpl.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathBinaryExpressionImpl.java index 1452cb4672b8..72ecafcb103a 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathBinaryExpressionImpl.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathBinaryExpressionImpl.java @@ -68,7 +68,7 @@ public class XPathBinaryExpressionImpl extends XPathElementImpl implements XPath return XPathType.BOOLEAN; } else if (operator == XPath2TokenTypes.IDIV) { return XPath2Type.INTEGER; - } else if (XPathTokenTypes.NUMBER_OPERATIONS.contains(operator)) { + } else if (XPath2TokenTypes.NUMBER_OPERATIONS.contains(operator)) { final XPathExpression lop = getLOperand(); final XPathExpression rop = getROperand(); if (is(lop, XPathType.UNKNOWN) || is(rop, XPathType.UNKNOWN)) { @@ -88,7 +88,7 @@ public class XPathBinaryExpressionImpl extends XPathElementImpl implements XPath if (XPathTokenTypes.MUL_OPS.contains(operator)) { if (is(lop, XPath2Type.DURATION) || is(rop, XPath2Type.DURATION)) { - return lop.getType(); + return lop != null ? lop.getType() : XPath2Type.DURATION; } } else { if (is(lop, XPath2Type.DATE) || is(lop, XPath2Type.DATETIME)) { diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ExpectedTypeUtil.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ExpectedTypeUtil.java index 4a2705cffa6c..fe574f52db9a 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ExpectedTypeUtil.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ExpectedTypeUtil.java @@ -181,7 +181,7 @@ public class ExpectedTypeUtil { final XPathExpression lop = parent.getLOperand(); if (op == XPathTokenTypes.AND || op == XPathTokenTypes.OR) { myExpectedType = XPathType.BOOLEAN; - } else if (XPathTokenTypes.NUMBER_OPERATIONS.contains(op)) { + } else if (XPath2TokenTypes.NUMBER_OPERATIONS.contains(op)) { if (isXPath1(myExpression)) { myExpectedType = XPathType.NUMBER; } else { diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java index 1d3ba7019bf5..3d2292fbc0cf 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java @@ -140,11 +140,21 @@ public class XPath2TypeTest extends XPath2HighlightingTestBase { doXPathHighlighting(); } + public void testNumericIDivDuration() throws Throwable { + ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + doXPathHighlighting(); + } + public void testDurationDivNumeric() throws Throwable { ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; doXPathHighlighting(); } + public void testDurationIDivNumeric() throws Throwable { + ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + doXPathHighlighting(); + } + public void testNumericMultString() throws Throwable { doXPathHighlighting(); } diff --git a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/durationIDivNumeric.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/durationIDivNumeric.xpath2 new file mode 100644 index 000000000000..fe4ef2f6c3f4 --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/durationIDivNumeric.xpath2 @@ -0,0 +1 @@ +'P0DTOH' cast as xs:dayTimeDuration idiv 4 \ No newline at end of file diff --git a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/numericIDivDuration.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/numericIDivDuration.xpath2 new file mode 100644 index 000000000000..cf68eae22783 --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/numericIDivDuration.xpath2 @@ -0,0 +1 @@ +4 idiv 'P0DTOH' cast as xs:dayTimeDuration \ No newline at end of file From 9f86047a1288c9f2b56218ceac63be47e6d901fc Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 May 2011 11:56:04 +0200 Subject: [PATCH 005/250] IDEA-68608 - final --- .../lang/xpath/validation/ExpectedTypeUtil.java | 2 +- .../test/org/intellij/lang/xpath/XPath2TypeTest.java | 12 ++++++++++++ .../highlighting/types/dateTimeMinusDateTime.xpath2 | 1 + .../xpath2/highlighting/types/timeMinusDate.xpath2 | 1 + .../xpath2/highlighting/types/timeMinusTime.xpath2 | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/dateTimeMinusDateTime.xpath2 create mode 100644 plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/timeMinusDate.xpath2 create mode 100644 plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/timeMinusTime.xpath2 diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ExpectedTypeUtil.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ExpectedTypeUtil.java index fe574f52db9a..063ffa3e1777 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ExpectedTypeUtil.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ExpectedTypeUtil.java @@ -71,7 +71,7 @@ public class ExpectedTypeUtil { } else if (XPathType.isAssignable(XPath2Type.DATE, type) || XPathType.isAssignable(XPath2Type.TIME, type) || XPathType.isAssignable(XPath2Type.DATETIME, type)) { - return XPathType.ChoiceType.create(XPath2Type.DATE, XPath2Type.DURATION); + return XPathType.ChoiceType.create((XPath2Type)type, XPath2Type.DURATION); } else if (XPathType.isAssignable(XPath2Type.DURATION, type)) { return XPath2Type.DURATION; } diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java index 3d2292fbc0cf..ca66af649416 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java @@ -125,6 +125,18 @@ public class XPath2TypeTest extends XPath2HighlightingTestBase { doXPathHighlighting(); } + public void testTimeMinusTime() throws Throwable { + doXPathHighlighting(); + } + + public void testDateTimeMinusDateTime() throws Throwable { + doXPathHighlighting(); + } + + public void testTimeMinusDate() throws Throwable { + doXPathHighlighting(); + } + public void testDateMinusDuration() throws Throwable { ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; doXPathHighlighting(); diff --git a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/dateTimeMinusDateTime.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/dateTimeMinusDateTime.xpath2 new file mode 100644 index 000000000000..3de05644f779 --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/dateTimeMinusDateTime.xpath2 @@ -0,0 +1 @@ +current-dateTime() - current-dateTime() \ No newline at end of file diff --git a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/timeMinusDate.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/timeMinusDate.xpath2 new file mode 100644 index 000000000000..c6f2ee7c890d --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/timeMinusDate.xpath2 @@ -0,0 +1 @@ +current-time() - current-date() \ No newline at end of file diff --git a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/timeMinusTime.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/timeMinusTime.xpath2 new file mode 100644 index 000000000000..5d007817e184 --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/timeMinusTime.xpath2 @@ -0,0 +1 @@ +current-time() - current-time() \ No newline at end of file From b0f90e9f8fee73dc8d82542bc88260a9eb1d2f49 Mon Sep 17 00:00:00 2001 From: Sascha Weinreuter Date: Thu, 5 May 2011 15:47:11 +0200 Subject: [PATCH 006/250] IDEA-69207: Support xpath-default-namespace --- .../xpath/completion/CompletionLists.java | 37 +++++++++++++------ .../lang/xpath/context/NamespaceContext.java | 3 ++ .../validation/inspections/CheckNodeTest.java | 24 +++++++++--- .../xslt/context/XsltNamespaceContext.java | 26 +++++++++++++ .../lang/xpath/TestNamespaceContext.java | 7 ++++ .../xpathView/ui/EditContextDialog.java | 5 +++ .../xpathView/ui/InputExpressionDialog.java | 5 +++ 7 files changed, 90 insertions(+), 17 deletions(-) diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/completion/CompletionLists.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/completion/CompletionLists.java index 88a65a507968..51c491ddefe8 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/completion/CompletionLists.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/completion/CompletionLists.java @@ -176,7 +176,7 @@ public class CompletionLists { final ContextProvider contextProvider = ContextProvider.getContextProvider(element); final XmlElement context = contextProvider.getContextElement(); - final boolean insidePrefix = suffix.indexOf(INTELLIJ_IDEA_RULEZ + ":") != -1; + final boolean insidePrefix = suffix.contains(INTELLIJ_IDEA_RULEZ + ":"); final Set list = new HashSet(); addNameCompletions(contextProvider, element, list); @@ -230,12 +230,12 @@ public class CompletionLists { final XPathNodeTest.PrincipalType principalType = element.getPrincipalType(); if (principalType == XPathNodeTest.PrincipalType.ELEMENT) { - final Set elementNames = contextProvider.getElements(false); + final Set elementNames = contextProvider.getElements(false); if (elementNames != null) { - for (javax.xml.namespace.QName pair : elementNames) { + for (QName pair : elementNames) { if ("*".equals(pair.getLocalPart())) continue; - if (namespaceMatches(prefixedName, pair.getNamespaceURI(), namespaceContext, context)) { + if (namespaceMatches(prefixedName, pair.getNamespaceURI(), namespaceContext, context, true)) { if (prefixedName.getPrefix() == null && namespaceContext != null) { final String p = namespaceContext.getPrefixForURI(pair.getNamespaceURI(), context); list.add(new NodeLookup(makePrefix(p) + pair.getLocalPart(), XPathNodeTest.PrincipalType.ELEMENT)); @@ -246,12 +246,12 @@ public class CompletionLists { } } } else if (principalType == XPathNodeTest.PrincipalType.ATTRIBUTE) { - final Set attributeNames = contextProvider.getAttributes(false); + final Set attributeNames = contextProvider.getAttributes(false); if (attributeNames != null) { - for (javax.xml.namespace.QName pair : attributeNames) { + for (QName pair : attributeNames) { if ("*".equals(pair.getLocalPart())) continue; - if (namespaceMatches(prefixedName, pair.getNamespaceURI(), namespaceContext, context)) { + if (namespaceMatches(prefixedName, pair.getNamespaceURI(), namespaceContext, context, false)) { if (prefixedName.getPrefix() == null && namespaceContext != null) { final String p = namespaceContext.getPrefixForURI(pair.getNamespaceURI(), context); list.add(new NodeLookup(makePrefix(p) + pair.getLocalPart(), XPathNodeTest.PrincipalType.ATTRIBUTE)); @@ -300,7 +300,7 @@ public class CompletionLists { final PrefixedName _prefixedName = nodeTest.getQName(); if (_prefixedName != null && prefixedName != null) { final String localName = _prefixedName.getLocalName(); - if (!"*".equals(localName) && localName.indexOf(INTELLIJ_IDEA_RULEZ) == -1) { + if (!"*".equals(localName) && !localName.contains(INTELLIJ_IDEA_RULEZ)) { if (Comparing.equal(_prefixedName.getPrefix(), prefixedName.getPrefix())) { list.add(new NodeLookup(localName, _principalType)); } else if (prefixedName.getPrefix() == null) { @@ -316,9 +316,24 @@ public class CompletionLists { } } - private static boolean namespaceMatches(PrefixedName prefixedName, String uri, NamespaceContext namespaceContext, XmlElement context) { - if (namespaceContext == null || prefixedName.getPrefix() == null || uri == null) return true; - return uri.equals(namespaceContext.getNamespaceURI(prefixedName.getPrefix(), context)); + private static boolean namespaceMatches(PrefixedName prefixedName, + String uri, + NamespaceContext namespaceContext, + XmlElement context, + boolean allowDefault) { + if (namespaceContext == null) return true; + if (uri == null) return true; + + final String namespaceURI; + if (prefixedName.getPrefix() != null) { + namespaceURI = namespaceContext.getNamespaceURI(prefixedName.getPrefix(), context); + } else { + if (!allowDefault) return false; + if ((namespaceURI = namespaceContext.getDefaultNamespace(context)) == null) { + return false; + } + } + return uri.equals(namespaceURI); } public static Collection getNodeTypeCompletions(XPathElement context) { diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/NamespaceContext.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/NamespaceContext.java index 4f34c58cbdbc..6e5433fd76cb 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/NamespaceContext.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/NamespaceContext.java @@ -39,4 +39,7 @@ public interface NamespaceContext { PsiElement resolve(String prefix, XmlElement context); IntentionAction[] getUnresolvedNamespaceFixes(PsiReference reference, String localName); + + @Nullable + String getDefaultNamespace(XmlElement context); } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/inspections/CheckNodeTest.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/inspections/CheckNodeTest.java index c1ed5b1aa935..d321c7435e6b 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/inspections/CheckNodeTest.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/inspections/CheckNodeTest.java @@ -23,6 +23,7 @@ import com.intellij.psi.xml.XmlElement; import org.intellij.lang.xpath.XPathFileType; import org.intellij.lang.xpath.context.ContextProvider; import org.intellij.lang.xpath.context.NamespaceContext; +import org.intellij.lang.xpath.context.XPathVersion; import org.intellij.lang.xpath.psi.PrefixedName; import org.intellij.lang.xpath.psi.XPathNodeTest; import org.jetbrains.annotations.NonNls; @@ -82,7 +83,7 @@ public class CheckNodeTest extends XPathInspection { if (elementNames != null) { found = false; for (QName pair : elementNames) { - if (matches(nodeTest.getQName(), pair, namespaceContext, contextNode)) { + if (matches(nodeTest.getQName(), pair, namespaceContext, contextNode, true)) { found = true; break; } @@ -96,7 +97,7 @@ public class CheckNodeTest extends XPathInspection { if (attributeNames != null) { found = false; for (QName pair : attributeNames) { - if (matches(nodeTest.getQName(), pair, namespaceContext, contextNode)) { + if (matches(nodeTest.getQName(), pair, namespaceContext, contextNode, false)) { found = true; break; } @@ -129,13 +130,24 @@ public class CheckNodeTest extends XPathInspection { addProblem(myManager.createProblemDescriptor(nodeTest, "Unknown " + type + " name " + name + "", myOnTheFly, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING)); } - private static boolean matches(@Nullable PrefixedName prefixedName, QName element, NamespaceContext namespaceContext, XmlElement context) { + private static boolean matches(@Nullable PrefixedName prefixedName, + QName element, + NamespaceContext namespaceContext, + XmlElement context, + boolean allowDefaultNamespace) + { if (prefixedName == null) return false; + boolean b = prefixedName.getLocalName().equals(element.getLocalPart()) || "*".equals(element.getLocalPart()); - if (prefixedName.getPrefix() != null) { - b = b && element.getNamespaceURI().equals(namespaceContext.getNamespaceURI(prefixedName.getPrefix(), context)); + + final String prefix = prefixedName.getPrefix(); + if (prefix != null || allowDefaultNamespace) { + if (!"*".equals(prefix)) { + final String namespaceURI = prefix != null ? namespaceContext.getNamespaceURI(prefix, context) : namespaceContext.getDefaultNamespace(context); + b = b && element.getNamespaceURI().equals(namespaceURI); + } } else { - b = b && element.getNamespaceURI().length() == 0; + b = b && element.getNamespaceURI().length() == 0; } return b; } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltNamespaceContext.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltNamespaceContext.java index 3219be2807c7..fa80d007c812 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltNamespaceContext.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltNamespaceContext.java @@ -33,6 +33,8 @@ import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.IncorrectOperationException; import org.intellij.lang.xpath.context.NamespaceContext; +import org.intellij.lang.xpath.xslt.XsltSupport; +import org.intellij.lang.xpath.xslt.impl.XsltChecker; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -120,6 +122,30 @@ public class XsltNamespaceContext implements NamespaceContext { return getUnresolvedNamespaceFixesStatic(reference, localName); } + @Override + public String getDefaultNamespace(XmlElement context) { + if (context != null) { + if (XsltSupport.getXsltLanguageLevel(context.getContainingFile()) == XsltChecker.LanguageLevel.V2) { + context = PsiTreeUtil.getParentOfType(context, XmlTag.class, false); + + if (context != null) { + do { + final XmlTag tag = (XmlTag)context; + String uri; + if ((uri = tag.getAttributeValue("xpath-default-namespace", null)) != null || + (uri = tag.getAttributeValue("xpath-default-namespace", XsltSupport.XSLT_NS)) != null) { + return uri; + } + context = PsiTreeUtil.getParentOfType(context, XmlTag.class, true); + } + while (context != null); + } + } + } + + return null; + } + public static IntentionAction[] getUnresolvedNamespaceFixesStatic(PsiReference reference, String localName) { final XmlElementFactory factory = XmlElementFactory.getInstance(reference.getElement().getProject()); final XmlTag tag = factory.createTagFromText("<" + reference.getCanonicalText() + ":" + localName + " />", XMLLanguage.INSTANCE); diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/TestNamespaceContext.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/TestNamespaceContext.java index 83b41542194a..22e028b51f19 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/TestNamespaceContext.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/TestNamespaceContext.java @@ -22,6 +22,7 @@ import com.intellij.psi.xml.XmlElement; import org.intellij.lang.xpath.context.NamespaceContext; import org.intellij.lang.xpath.psi.XPath2Type; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Collections; @@ -54,4 +55,10 @@ class TestNamespaceContext implements NamespaceContext { public IntentionAction[] getUnresolvedNamespaceFixes(PsiReference reference, String localName) { return IntentionAction.EMPTY_ARRAY; } + + @Nullable + @Override + public String getDefaultNamespace(XmlElement context) { + return null; + } } \ No newline at end of file diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/EditContextDialog.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/EditContextDialog.java index 36ccd7d3ea2f..e316ad38fd03 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/EditContextDialog.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/EditContextDialog.java @@ -469,6 +469,11 @@ public class EditContextDialog extends DialogWrapper { public IntentionAction[] getUnresolvedNamespaceFixes(PsiReference reference, String localName) { return new IntentionAction[0]; } + + @Override + public String getDefaultNamespace(XmlElement context) { + return null; + } } private class MyVariableContext extends AbstractVariableContext { diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java index 0f3747bc3d65..b89a173e82ac 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java @@ -564,6 +564,11 @@ public abstract class InputExpressionDialog extends public IntentionAction[] getUnresolvedNamespaceFixes(PsiReference reference, String localName) { return new IntentionAction[]{ new MyRegisterPrefixAction(reference) }; } + + @Override + public String getDefaultNamespace(XmlElement context) { + return null; + } } private class MyRegisterPrefixAction implements IntentionAction { From bc1f45093106d75b58496d4942aef76e54ac84b5 Mon Sep 17 00:00:00 2001 From: Sascha Weinreuter Date: Fri, 6 May 2011 09:41:36 +0200 Subject: [PATCH 007/250] renamed, cleanup --- ...bstractVariableContext.java => SimpleVariableContext.java} | 4 ++-- .../org/intellij/plugins/xpathView/ui/EditContextDialog.java | 4 ++-- .../intellij/plugins/xpathView/ui/InputExpressionDialog.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) rename plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/{AbstractVariableContext.java => SimpleVariableContext.java} (85%) diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/AbstractVariableContext.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/SimpleVariableContext.java similarity index 85% rename from plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/AbstractVariableContext.java rename to plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/SimpleVariableContext.java index d0b18b86a782..e699a367a183 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/AbstractVariableContext.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/SimpleVariableContext.java @@ -12,7 +12,7 @@ import org.intellij.lang.xpath.psi.XPathVariableReference; * User: sweinreuter * Date: 08.01.2008 */ -public abstract class AbstractVariableContext implements VariableContext { +public abstract class SimpleVariableContext implements VariableContext { public XPathVariable resolve(XPathVariableReference reference) { return null; @@ -24,7 +24,7 @@ public abstract class AbstractVariableContext implements VariableContex @NotNull public IntentionAction[] getUnresolvedVariableFixes(XPathVariableReference reference) { - return new IntentionAction[0]; + return IntentionAction.EMPTY_ARRAY; } public boolean isReferenceTo(PsiElement element, XPathVariableReference reference) { diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/EditContextDialog.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/EditContextDialog.java index e316ad38fd03..5cdac117cd22 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/EditContextDialog.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/EditContextDialog.java @@ -467,7 +467,7 @@ public class EditContextDialog extends DialogWrapper { } public IntentionAction[] getUnresolvedNamespaceFixes(PsiReference reference, String localName) { - return new IntentionAction[0]; + return IntentionAction.EMPTY_ARRAY; } @Override @@ -476,7 +476,7 @@ public class EditContextDialog extends DialogWrapper { } } - private class MyVariableContext extends AbstractVariableContext { + private class MyVariableContext extends SimpleVariableContext { @NotNull public String[] getVariablesInScope(XPathElement element) { final Collection variables = myVariableTableModel.getVariables(); diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java index b89a173e82ac..a51148adf776 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/ui/InputExpressionDialog.java @@ -53,7 +53,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.intellij.lang.xpath.XPathFileType; -import org.intellij.lang.xpath.context.AbstractVariableContext; +import org.intellij.lang.xpath.context.SimpleVariableContext; import org.intellij.lang.xpath.context.ContextProvider; import org.intellij.lang.xpath.context.ContextType; import org.intellij.lang.xpath.context.NamespaceContext; @@ -451,7 +451,7 @@ public abstract class InputExpressionDialog extends } } - private static class MyVariableResolver extends AbstractVariableContext { + private static class MyVariableResolver extends SimpleVariableContext { private final HistoryModel myModel; public MyVariableResolver(HistoryModel model) { From 8f3a8937fdb14033f990030e093652095d2bb161 Mon Sep 17 00:00:00 2001 From: Sascha Weinreuter Date: Fri, 6 May 2011 11:08:26 +0200 Subject: [PATCH 008/250] IDEA-69207: Support xpath-default-namespace (2) --- .../lang/xpath/context/ContextProvider.java | 18 +++++++++++++++--- .../xslt/context/XsltNamespaceContext.java | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/ContextProvider.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/ContextProvider.java index c4455bdb66d2..2b5ee9669df2 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/ContextProvider.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/ContextProvider.java @@ -170,9 +170,15 @@ public abstract class ContextProvider { final XmlElement element = PsiTreeUtil.getContextOfType(context, XmlElement.class, true); final String namespaceURI = namespaceContext.getNamespaceURI(prefix, element); return namespaceURI != null && namespaceURI.length() > 0 ? new QName(namespaceURI, qName.getLocalName(), prefix) : null; - } else { - return new QName(null, qName.getLocalName(), ""); + } else if (context.getXPathVersion() == XPathVersion.V2){ + if (isDefaultCapableElement(context)) { + final String namespace = namespaceContext.getDefaultNamespace(getContextElement()); + if (namespace != null) { + return new QName(namespace, qName.getLocalName()); + } + } } + return new QName(null, qName.getLocalName(), ""); } else if (qName.getPrefix() == null) { return QName.valueOf(qName.getLocalName()); } else { @@ -180,7 +186,13 @@ public abstract class ContextProvider { } } - public static boolean hasXPathInjections(XmlFile file) { + private static boolean isDefaultCapableElement(XPathElement context) { + // http://www.w3.org/TR/xslt20/#unprefixed-qnames + return (context instanceof XPathNodeTest && ((XPathNodeTest)context).getPrincipalType() == XPathNodeTest.PrincipalType.ELEMENT) + || context instanceof XPath2TypeElement; + } + + public static boolean hasXPathInjections(XmlFile file) { return Boolean.TRUE.equals(file.getUserData(XML_FILE_WITH_XPATH_INJECTTION)); } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltNamespaceContext.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltNamespaceContext.java index fa80d007c812..a30b4f54aa67 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltNamespaceContext.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltNamespaceContext.java @@ -134,7 +134,7 @@ public class XsltNamespaceContext implements NamespaceContext { String uri; if ((uri = tag.getAttributeValue("xpath-default-namespace", null)) != null || (uri = tag.getAttributeValue("xpath-default-namespace", XsltSupport.XSLT_NS)) != null) { - return uri; + return uri.length() > 0 ? uri : null; } context = PsiTreeUtil.getParentOfType(context, XmlTag.class, true); } From a6cedd8df2468fecfb9b2c1df95a19c2e408e485 Mon Sep 17 00:00:00 2001 From: Sascha Weinreuter Date: Fri, 6 May 2011 13:50:36 +0200 Subject: [PATCH 009/250] correct return type for date/duration operations --- .../xpath/psi/impl/XPathBinaryExpressionImpl.java | 15 ++++++++++----- .../org/intellij/lang/xpath/XPath2TypeTest.java | 5 +++++ .../highlighting/types/dateMinusDuration2.xpath2 | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/dateMinusDuration2.xpath2 diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathBinaryExpressionImpl.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathBinaryExpressionImpl.java index 72ecafcb103a..8cc203fb5d5a 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathBinaryExpressionImpl.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathBinaryExpressionImpl.java @@ -81,15 +81,15 @@ public class XPathBinaryExpressionImpl extends XPathElementImpl implements XPath return mostSpecificType(lop, rop, XPath2Type.NUMERIC); } - if (sameType(lop, rop)) { - assert lop != null : unexpectedPsiAssertion(); - return lop.getType(); - } - if (XPathTokenTypes.MUL_OPS.contains(operator)) { if (is(lop, XPath2Type.DURATION) || is(rop, XPath2Type.DURATION)) { return lop != null ? lop.getType() : XPath2Type.DURATION; } + + if (sameType(lop, rop)) { + assert lop != null : unexpectedPsiAssertion(); + return lop.getType(); + } } else { if (is(lop, XPath2Type.DATE) || is(lop, XPath2Type.DATETIME)) { return XPath2Type.DURATION; @@ -102,6 +102,11 @@ public class XPathBinaryExpressionImpl extends XPathElementImpl implements XPath } } + if (sameType(lop, rop)) { + assert lop != null : unexpectedPsiAssertion(); + return lop.getType(); + } + if (is(lop, XPath2Type.NUMERIC) || is(rop, XPath2Type.NUMERIC) ) { return XPath2Type.NUMERIC; } diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java index ca66af649416..dcccd6dc39f3 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java @@ -142,6 +142,11 @@ public class XPath2TypeTest extends XPath2HighlightingTestBase { doXPathHighlighting(); } + public void testDateMinusDuration2() throws Throwable { + ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + doXPathHighlighting(); + } + public void testDurationMinusDate() throws Throwable { ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; doXPathHighlighting(); diff --git a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/dateMinusDuration2.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/dateMinusDuration2.xpath2 new file mode 100644 index 000000000000..3fd7bacb5a58 --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/dateMinusDuration2.xpath2 @@ -0,0 +1 @@ +'P0DT0H' cast as xs:dayTimeDuration - (current-date() - 'P0DT0H' cast as xs:dayTimeDuration) \ No newline at end of file From caa94260a04981a4d5aca0e6894c2f14322851a2 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 9 May 2011 10:30:07 +0200 Subject: [PATCH 010/250] fix typo --- .../src/com/intellij/cvsSupport2/CvsBundle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties index 620513981c14..0ddbb69dcde2 100644 --- a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties +++ b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties @@ -34,7 +34,7 @@ operation.name.view.editors=View Editors message.error.no.editors.for.file=There are no editors for {0} message.error.no.editors.for.file.title=Editors message.editors.for.file=Editors for {0} -operation.name.veiw.watchers=Veiw Watchers +operation.name.veiw.watchers=View Watchers message.error.no.watchers.for.file=There are no watchers for {0} message.error.no.watchers.for.file.title=Watchers message.watchers.for.file=Watchers for {0} @@ -233,8 +233,8 @@ operation.name.get.file.status=Get File Status exception.text.revision.has.been.deleted=Revision does not exist progress.text.reading.data.from.server=Reading data from server progress.text.sending.data.to.server=Sending data to server -progress.text.kb.read=Kb read -progress.text.kb.sent=Kb sent +progress.text.kb.read=KB read +progress.text.kb.sent=KB sent keyword.substitution.binary=binary keyword.substitution.compression=compression keyword.substitution.expansion=expansion From f552f39575e77d4514353e0d99111e5e3923b60a Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 9 May 2011 10:32:20 +0200 Subject: [PATCH 011/250] cleanup cvs configuration a little bit --- .../intellij/cvsSupport2/CvsBundle.properties | 2 +- .../config/ui/CvsConfigurationPanel.form | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties index 0ddbb69dcde2..c72aa561699d 100644 --- a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties +++ b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties @@ -342,7 +342,7 @@ label.import.options.log.message=&Log message: label.import.options.release.tag=&Release tag: border.title.show.changes.additional.files=Additional Files: command.name.rollback.file.creation=Rollback file creation -border.title.update.options.other.settings=Other Settings: +border.title.update.options.other.settings=Other Settings border.title.update.options.updating.group=Updating border.title.ext.protocol.settings=Ext Protocol Settings border.title.configure.ssh.private.key.file=Private Key File diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsConfigurationPanel.form b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsConfigurationPanel.form index 2be86e4968bb..d0dc35bce41b 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsConfigurationPanel.form +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsConfigurationPanel.form @@ -1,6 +1,6 @@
- + @@ -8,11 +8,6 @@ - - - - - @@ -34,6 +29,7 @@ + @@ -42,6 +38,7 @@ + @@ -50,6 +47,7 @@ + @@ -77,11 +75,11 @@ - + - + @@ -91,7 +89,7 @@ - + @@ -105,6 +103,11 @@ + + + + + From 54f0e7787c4fbd84a5c487e9cb0dea8bc3eb91e5 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 9 May 2011 12:08:50 +0200 Subject: [PATCH 012/250] IDEA-16044 (Improve CVS Keyword Substitution names in CVS Dialogs) IDEA-41681 (Add actual switch values to Keyword expansion selections in CVS dialogs) --- .../intellij/cvsSupport2/CvsBundle.properties | 12 ++-- .../config/ui/CvsConfigurationPanel.java | 5 +- .../cvsoperations/cvsAdd/AddedFileInfo.java | 19 +++--- .../cvsAdd/ui/AddFileConfirmationPanel.java | 19 +++--- .../cvsUpdate/ui/UpdateOptionsPanel.java | 44 ++++++-------- .../KeywordSubstitutionListWithSelection.java | 12 ++-- .../KeywordSubstitutionWrapper.java | 60 +++++++++++++------ .../ui/ChangeKeywordSubstitutionPanel.form | 53 ---------------- .../ui/ChangeKeywordSubstitutionPanel.java | 39 +++++++----- .../KeywordSubstitutionComboBoxWrapper.java | 49 --------------- .../ui/experts/checkout/CheckoutWizard.java | 17 +++--- .../experts/checkout/ChooseCheckoutMode.java | 53 ++++++++-------- .../ui/experts/importToCvs/FileExtension.java | 7 +-- 13 files changed, 146 insertions(+), 243 deletions(-) delete mode 100644 plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/ChangeKeywordSubstitutionPanel.form delete mode 100644 plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/KeywordSubstitutionComboBoxWrapper.java diff --git a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties index c72aa561699d..80a77af646d2 100644 --- a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties +++ b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties @@ -235,12 +235,12 @@ progress.text.reading.data.from.server=Reading data from server progress.text.sending.data.to.server=Sending data to server progress.text.kb.read=KB read progress.text.kb.sent=KB sent -keyword.substitution.binary=binary -keyword.substitution.compression=compression -keyword.substitution.expansion=expansion -keyword.substitution.expansion.locker=expansion locker -keyword.substitution.no.substitution=no substitution -keyword.substitution.replacement=replacement +keyword.substitution.binary=binary (-kb) +keyword.substitution.compression=keyword only (-kk) +keyword.substitution.expansion=keyword \\& value (-kkv) +keyword.substitution.expansion.locker=keyword, value \\& locker (-kkvl) +keyword.substitution.no.substitution=original string (-ko) +keyword.substitution.replacement=value only (-kv) tab.title.errors=Errors tab.title.cvs.output=Cvs Output dialog.title.restore.directories.information=Information diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsConfigurationPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsConfigurationPanel.java index 71178a63a3fd..4dde0552544c 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsConfigurationPanel.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsConfigurationPanel.java @@ -18,7 +18,6 @@ package com.intellij.cvsSupport2.config.ui; import com.intellij.cvsSupport2.config.CvsApplicationLevelConfiguration; import com.intellij.cvsSupport2.config.CvsConfiguration; import com.intellij.cvsSupport2.config.CvsRootConfiguration; -import com.intellij.cvsSupport2.keywordSubstitution.KeywordSubstitutionListWithSelection; import com.intellij.cvsSupport2.keywordSubstitution.KeywordSubstitutionWrapper; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileChooser.FileChooserDescriptor; @@ -97,10 +96,8 @@ public class CvsConfigurationPanel { myOnFileMergedWithConflictGroup[config.SHOW_CORRUPTED_PROJECT_FILES].setSelected(true); - //noinspection MismatchedQueryAndUpdateOfCollection - KeywordSubstitutionListWithSelection keywordSubstitutions = new KeywordSubstitutionListWithSelection(); myDefaultTextFileKeywordSubstitution.removeAllItems(); - for (final KeywordSubstitutionWrapper keywordSubstitution : keywordSubstitutions) { + for (final KeywordSubstitutionWrapper keywordSubstitution : KeywordSubstitutionWrapper.values()) { myDefaultTextFileKeywordSubstitution.addItem(keywordSubstitution); } myDefaultTextFileKeywordSubstitution.setSelectedItem( diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/AddedFileInfo.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/AddedFileInfo.java index ec770ec00598..f4371cb2b18d 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/AddedFileInfo.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/AddedFileInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -25,7 +25,6 @@ import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vcs.impl.VcsPathPresenter; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.IconUtil; -import com.intellij.util.ListWithSelection; import org.jetbrains.annotations.NotNull; import org.netbeans.lib.cvsclient.command.KeywordSubstitution; @@ -38,8 +37,9 @@ import java.util.*; * author: lesya */ public class AddedFileInfo extends DefaultMutableTreeNode { + private final VirtualFile myAddedFile; - private ListWithSelection mySubstitution = new ListWithSelection(); + private final KeywordSubstitutionListWithSelection mySubstitution; private boolean myIncluded = true; private AddedFileInfo myParent; private final MyComparator myComparator = new MyComparator(); @@ -59,7 +59,7 @@ public class AddedFileInfo extends DefaultMutableTreeNode { return null; } else { - return ((KeywordSubstitutionWrapper)mySubstitution.getSelection()).getSubstitution(); + return mySubstitution.getSelection().getSubstitution(); } } @@ -86,14 +86,14 @@ public class AddedFileInfo extends DefaultMutableTreeNode { excludeAllChildren(); } else { - encludeAllParents(); + includeAllParents(); } myExcludedObservable.setChanged(); myExcludedObservable.notifyObservers(); } - private void encludeAllParents() { + private void includeAllParents() { if (myParent != null) myParent.setIncluded(true); } @@ -141,12 +141,12 @@ public class AddedFileInfo extends DefaultMutableTreeNode { public void sort() { if (children == null) return; Collections.sort(children, myComparator); - for (Iterator each = children.iterator(); each.hasNext();) { - ((AddedFileInfo)each.next()).sort(); + for (Object aChildren : children) { + ((AddedFileInfo)aChildren).sort(); } } - public ListWithSelection getKeywordSubstitutionsWithSelection() { + public KeywordSubstitutionListWithSelection getKeywordSubstitutionsWithSelection() { return mySubstitution; } @@ -204,5 +204,4 @@ public class AddedFileInfo extends DefaultMutableTreeNode { CvsStorageComponent cvsStorageComponent = CvsStorageSupportingDeletionComponent.getInstance(myProject); cvsStorageComponent.deleteIfAdminDirCreated(myAddedFile); } - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/ui/AddFileConfirmationPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/ui/AddFileConfirmationPanel.java index 9744b66c410a..42d560f61547 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/ui/AddFileConfirmationPanel.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/ui/AddFileConfirmationPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -17,9 +17,8 @@ package com.intellij.cvsSupport2.cvsoperations.cvsAdd.ui; import com.intellij.cvsSupport2.cvsoperations.cvsAdd.AddedFileInfo; import com.intellij.cvsSupport2.keywordSubstitution.KeywordSubstitutionWrapper; -import com.intellij.cvsSupport2.ui.KeywordSubstitutionComboBoxWrapper; -import com.intellij.util.ui.FileLabel; import com.intellij.util.ui.FileLabel; +import org.netbeans.lib.cvsclient.command.KeywordSubstitution; import javax.swing.*; import java.awt.*; @@ -30,6 +29,7 @@ import java.awt.event.ActionListener; * author: lesya */ public class AddFileConfirmationPanel extends AbstractAddFileConfirmationPanel { + private JComboBox mySubstitutionComboBox; private FileLabel myFileLabel; private JPanel myPanel; @@ -38,21 +38,17 @@ public class AddFileConfirmationPanel extends AbstractAddFileConfirmationPanel { public AddFileConfirmationPanel(AddedFileInfo addedFileInfo) { super(addedFileInfo); - KeywordSubstitutionWrapper defaultSubst = (KeywordSubstitutionWrapper)myAddedFileInfo.getKeywordSubstitutionsWithSelection() - .getSelection(); - final KeywordSubstitutionComboBoxWrapper wrapper = new KeywordSubstitutionComboBoxWrapper(mySubstitutionComboBox, - defaultSubst.getStringRepresentation() - ); - + KeywordSubstitution defaultSubstitution = myAddedFileInfo.getKeywordSubstitution(); + KeywordSubstitutionWrapper.fillComboBox(mySubstitutionComboBox, defaultSubstitution); mySubstitutionComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - myAddedFileInfo.setKeywordSubstitution(wrapper.getSelection().getSubstitution()); + final KeywordSubstitutionWrapper selectedItem = (KeywordSubstitutionWrapper)mySubstitutionComboBox.getSelectedItem(); + myAddedFileInfo.setKeywordSubstitution(selectedItem.getSubstitution()); } }); init(); - } public Component getPanel() { @@ -62,5 +58,4 @@ public class AddFileConfirmationPanel extends AbstractAddFileConfirmationPanel { protected FileLabel getFileLabel() { return myFileLabel; } - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsUpdate/ui/UpdateOptionsPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsUpdate/ui/UpdateOptionsPanel.java index 1282fc5fd87d..a7ff47fc2e54 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsUpdate/ui/UpdateOptionsPanel.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsUpdate/ui/UpdateOptionsPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,6 +15,7 @@ */ package com.intellij.cvsSupport2.cvsoperations.cvsUpdate.ui; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.config.CvsConfiguration; import com.intellij.cvsSupport2.cvsoperations.cvsTagOrBranch.TagsHelper; import com.intellij.cvsSupport2.cvsoperations.cvsTagOrBranch.TagsProviderOnVirtualFiles; @@ -25,7 +26,7 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.vcs.FilePath; -import com.intellij.CvsBundle; +import org.netbeans.lib.cvsclient.command.KeywordSubstitution; import javax.swing.*; import java.awt.*; @@ -62,10 +63,11 @@ public class UpdateOptionsPanel { public UpdateOptionsPanel(Project project, final Collection files) { myProject = project; + final CvsConfiguration configuration = CvsConfiguration.getInstance(myProject); myChangeKeywordSubstitutionPanel = - new ChangeKeywordSubstitutionPanel(CvsConfiguration.getInstance(myProject).UPDATE_KEYWORD_SUBSTITUTION); - CvsConfiguration.getInstance(myProject).CLEAN_COPY = false; - CvsConfiguration.getInstance(myProject).RESET_STICKY = false; + new ChangeKeywordSubstitutionPanel(KeywordSubstitution.getValue(configuration.UPDATE_KEYWORD_SUBSTITUTION)); + configuration.CLEAN_COPY = false; + configuration.RESET_STICKY = false; myMergingGroup = new JRadioButton[]{myDoNotMerge, myMergeWithBranch, myMergeTwoBranches}; myKeywordSubstitutionPanel.setLayout(new BorderLayout()); @@ -78,9 +80,7 @@ public class UpdateOptionsPanel { TagsHelper.addChooseBranchAction(myBranch, files, project); - TagsHelper.addChooseBranchAction(myBranch2, files, project); - } public void reset() { @@ -105,31 +105,23 @@ public class UpdateOptionsPanel { } enableBranchField(); - } private void enableBranchField() { int mergingMode = getSelected(myMergingGroup); switch (mergingMode) { case CvsConfiguration.DO_NOT_MERGE: - { - myBranch.setEnabled(false); - myBranch2.setEnabled(false); - return; - } + myBranch.setEnabled(false); + myBranch2.setEnabled(false); + break; case CvsConfiguration.MERGE_WITH_BRANCH: - { - myBranch.setEnabled(true); - myBranch2.setEnabled(false); - return; - } + myBranch.setEnabled(true); + myBranch2.setEnabled(false); + break; case CvsConfiguration.MERGE_TWO_BRANCHES: - { - myBranch.setEnabled(true); - myBranch2.setEnabled(true); - return; - } - + myBranch.setEnabled(true); + myBranch2.setEnabled(true); + break; } } @@ -145,15 +137,13 @@ public class UpdateOptionsPanel { } } - configuration.PRUNE_EMPTY_DIRECTORIES = myPruneEmptyDirectories.isSelected(); configuration.MERGING_MODE = getSelected(myMergingGroup); configuration.MERGE_WITH_BRANCH1_NAME = myBranch.getText(); configuration.MERGE_WITH_BRANCH2_NAME = myBranch2.getText(); configuration.RESET_STICKY = mySwitchToHeadRevision.isSelected(); configuration.CREATE_NEW_DIRECTORIES = myCreateNewDirectories.isSelected(); - configuration.UPDATE_KEYWORD_SUBSTITUTION = myChangeKeywordSubstitutionPanel.getKeywordSubstitution(); - + configuration.UPDATE_KEYWORD_SUBSTITUTION = myChangeKeywordSubstitutionPanel.getKeywordSubstitution().toString(); myDateOrRevisionOrTagSettings.saveTo(configuration.UPDATE_DATE_OR_REVISION_SETTINGS); } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/keywordSubstitution/KeywordSubstitutionListWithSelection.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/keywordSubstitution/KeywordSubstitutionListWithSelection.java index 0c11f023495e..8e0200f7d7dd 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/keywordSubstitution/KeywordSubstitutionListWithSelection.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/keywordSubstitution/KeywordSubstitutionListWithSelection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -25,13 +25,12 @@ import com.intellij.util.ListWithSelection; public class KeywordSubstitutionListWithSelection extends ListWithSelection { public KeywordSubstitutionListWithSelection() { - - add(KeywordSubstitutionWrapper.BINARY); - add(KeywordSubstitutionWrapper.KEYWORD_COMPRESSION); add(KeywordSubstitutionWrapper.KEYWORD_EXPANSION); add(KeywordSubstitutionWrapper.KEYWORD_EXPANSION_LOCKER); - add(KeywordSubstitutionWrapper.KEYWORD_REPLACEMENT); + add(KeywordSubstitutionWrapper.KEYWORD_COMPRESSION); add(KeywordSubstitutionWrapper.NO_SUBSTITUTION); + add(KeywordSubstitutionWrapper.BINARY); + add(KeywordSubstitutionWrapper.KEYWORD_REPLACEMENT); } public static KeywordSubstitutionListWithSelection createOnFileName(String fileName, @@ -41,7 +40,6 @@ public class KeywordSubstitutionListWithSelection extends ListWithSelection values = null; private KeywordSubstitutionWrapper(KeywordSubstitution keywordSubstitution, String displayName) { myKeywordSubstitution = keywordSubstitution; myDisplayName = displayName; } - public KeywordSubstitution getSubstitution(){ + public KeywordSubstitution getSubstitution() { return myKeywordSubstitution; } @@ -51,17 +59,33 @@ public class KeywordSubstitutionWrapper{ } public static KeywordSubstitutionWrapper getValue(KeywordSubstitution substitution) { - if (substitution == KeywordSubstitution.BINARY) return KeywordSubstitutionWrapper.BINARY; - if (substitution == KeywordSubstitution.KEYWORD_COMPRESSION) return KeywordSubstitutionWrapper.KEYWORD_COMPRESSION; - if (substitution == KeywordSubstitution.KEYWORD_EXPANSION) return KeywordSubstitutionWrapper.KEYWORD_EXPANSION; - if (substitution == KeywordSubstitution.KEYWORD_EXPANSION_LOCKER) return KeywordSubstitutionWrapper.KEYWORD_EXPANSION_LOCKER; - if (substitution == KeywordSubstitution.NO_SUBSTITUTION) return KeywordSubstitutionWrapper.NO_SUBSTITUTION; - if (substitution == KeywordSubstitution.KEYWORD_REPLACEMENT) return KeywordSubstitutionWrapper.KEYWORD_REPLACEMENT; + if (substitution == KeywordSubstitution.BINARY) return BINARY; + if (substitution == KeywordSubstitution.KEYWORD_COMPRESSION) return KEYWORD_COMPRESSION; + if (substitution == KeywordSubstitution.KEYWORD_EXPANSION) return KEYWORD_EXPANSION; + if (substitution == KeywordSubstitution.KEYWORD_EXPANSION_LOCKER) return KEYWORD_EXPANSION_LOCKER; + if (substitution == KeywordSubstitution.NO_SUBSTITUTION) return NO_SUBSTITUTION; + if (substitution == KeywordSubstitution.KEYWORD_REPLACEMENT) return KEYWORD_REPLACEMENT; return null; } - public String getStringRepresentation(){ - if (myKeywordSubstitution == null) return null; - return myKeywordSubstitution.toString(); + public static void fillComboBox(JComboBox comboBox, KeywordSubstitution defaultSubstitution) { + for (KeywordSubstitutionWrapper value : values()) { + comboBox.addItem(value); + } + comboBox.setSelectedItem(getValue(defaultSubstitution)); + } + + public static List values() { + if (values == null) { + final ArrayList list = new ArrayList(); + list.add(KEYWORD_EXPANSION); + list.add(KEYWORD_EXPANSION_LOCKER); + list.add(KEYWORD_COMPRESSION); + list.add(NO_SUBSTITUTION); + list.add(BINARY); + list.add(KEYWORD_REPLACEMENT); + values = Collections.unmodifiableList(list); + } + return values; } } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/ChangeKeywordSubstitutionPanel.form b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/ChangeKeywordSubstitutionPanel.form deleted file mode 100644 index 9c6bc9f9b352..000000000000 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/ChangeKeywordSubstitutionPanel.form +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/ChangeKeywordSubstitutionPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/ChangeKeywordSubstitutionPanel.java index 7331d275b317..9a2bc2590915 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/ChangeKeywordSubstitutionPanel.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/ChangeKeywordSubstitutionPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,7 +15,9 @@ */ package com.intellij.cvsSupport2.ui; -import org.jetbrains.annotations.NonNls; +import com.intellij.CvsBundle; +import com.intellij.cvsSupport2.keywordSubstitution.KeywordSubstitutionWrapper; +import org.netbeans.lib.cvsclient.command.KeywordSubstitution; import javax.swing.*; import java.awt.*; @@ -26,25 +28,35 @@ import java.awt.event.ActionListener; * author: lesya */ public class ChangeKeywordSubstitutionPanel { - private JComboBox myKeywordSubstitutionComboBox; - private JCheckBox myChangeCheckbox; - private final KeywordSubstitutionComboBoxWrapper myComboBoxWrapper; - private JPanel myPanel; - public ChangeKeywordSubstitutionPanel(String defaultSubst) { - myComboBoxWrapper = new KeywordSubstitutionComboBoxWrapper(myKeywordSubstitutionComboBox, defaultSubst); + private final JComboBox myKeywordSubstitutionComboBox; + private final JCheckBox myChangeCheckbox; + private final JPanel myPanel; + + public ChangeKeywordSubstitutionPanel(KeywordSubstitution defaultSubstitution) { + myPanel = new JPanel(new GridBagLayout()); + myChangeCheckbox = new JCheckBox(CvsBundle.message("checkbox.change.keyword.substitution.to")); + myKeywordSubstitutionComboBox = new JComboBox(); + KeywordSubstitutionWrapper.fillComboBox(myKeywordSubstitutionComboBox, defaultSubstitution); + myChangeCheckbox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setEnabling(); } }); + final GridBagConstraints constraints = new GridBagConstraints(); + constraints.anchor = GridBagConstraints.BASELINE_LEADING; + myPanel.add(myChangeCheckbox, constraints); + constraints.gridx = 1; + constraints.weightx = 1.0; + myPanel.add(myKeywordSubstitutionComboBox, constraints); setEnabling(); } private void setEnabling() { myKeywordSubstitutionComboBox.setEnabled(myChangeCheckbox.isSelected()); - if (myKeywordSubstitutionComboBox.isEnabled() && (myKeywordSubstitutionComboBox.getSelectedIndex() == -1)){ + if (myKeywordSubstitutionComboBox.getSelectedIndex() == -1){ myKeywordSubstitutionComboBox.setSelectedIndex(0); } } @@ -53,13 +65,10 @@ public class ChangeKeywordSubstitutionPanel { return myPanel; } - public String getKeywordSubstitution() { + public KeywordSubstitution getKeywordSubstitution() { if (!myChangeCheckbox.isSelected()) { - //noinspection HardCodedStringLiteral - return "NONE"; - } - else { - return myComboBoxWrapper.getSelection().getStringRepresentation(); + return null; } + return ((KeywordSubstitutionWrapper)myKeywordSubstitutionComboBox.getSelectedItem()).getSubstitution(); } } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/KeywordSubstitutionComboBoxWrapper.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/KeywordSubstitutionComboBoxWrapper.java deleted file mode 100644 index 1dfb88625b9c..000000000000 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/KeywordSubstitutionComboBoxWrapper.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2000-2009 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.cvsSupport2.ui; - -import com.intellij.cvsSupport2.keywordSubstitution.KeywordSubstitutionListWithSelection; -import com.intellij.cvsSupport2.keywordSubstitution.KeywordSubstitutionWrapper; -import com.intellij.cvsSupport2.keywordSubstitution.KeywordSubstitutionListWithSelection; - -import javax.swing.*; -import java.util.Iterator; - -/** - * author: lesya - */ - -public class KeywordSubstitutionComboBoxWrapper{ - private final JComboBox myComboBox; - - public KeywordSubstitutionComboBoxWrapper(JComboBox comboBox, - String defaultSubst) { - KeywordSubstitutionListWithSelection values = new KeywordSubstitutionListWithSelection(); - values.select(KeywordSubstitutionWrapper.getValue(defaultSubst)); - myComboBox = comboBox; - for (Iterator iterator = values.iterator(); iterator.hasNext();) { - myComboBox.addItem(iterator.next()); - } - - myComboBox.setSelectedItem(values.getSelection()); - } - - - - public KeywordSubstitutionWrapper getSelection(){ - return (KeywordSubstitutionWrapper)myComboBox.getSelectedItem(); - } -} diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/checkout/CheckoutWizard.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/checkout/CheckoutWizard.java index 2c28bd1b38c6..d1d71f96aa45 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/checkout/CheckoutWizard.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/checkout/CheckoutWizard.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,6 +15,7 @@ */ package com.intellij.cvsSupport2.ui.experts.checkout; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.config.CvsApplicationLevelConfiguration; import com.intellij.cvsSupport2.config.CvsRootConfiguration; import com.intellij.cvsSupport2.cvsBrowser.CvsElement; @@ -31,6 +32,7 @@ import java.io.File; * author: lesya */ public class CheckoutWizard extends CvsWizard { + private final SelectCVSConfigurationStep mySelectCVSConfigurationStep; private final SelectCvsElementStep mySelectCvsElementStep; private final SelectLocationStep mySelectLocationStep; @@ -38,9 +40,9 @@ public class CheckoutWizard extends CvsWizard { private final ChooseCheckoutMode myChooseModeStep; public CheckoutWizard(final Project project) { - super(com.intellij.CvsBundle.message("dialog.tittle.check.out.from.cvs.repository"), project); + super(CvsBundle.message("dialog.tittle.check.out.from.cvs.repository"), project); mySelectCVSConfigurationStep = new SelectCVSConfigurationStep(project, this); - mySelectCvsElementStep = new SelectCvsElementStep(com.intellij.CvsBundle.message("dialog.title.select.cvs.element.to.check.out"), + mySelectCvsElementStep = new SelectCvsElementStep(CvsBundle.message("dialog.title.select.cvs.element.to.check.out"), this, project, mySelectCVSConfigurationStep, true, TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION, false, true); @@ -50,7 +52,6 @@ public class CheckoutWizard extends CvsWizard { addStep(mySelectCVSConfigurationStep); addStep(mySelectCvsElementStep); addStep(mySelectLocationStep); - addStep(myChooseModeStep); init(); @@ -59,14 +60,13 @@ public class CheckoutWizard extends CvsWizard { protected void doOKAction() { CvsApplicationLevelConfiguration config = CvsApplicationLevelConfiguration.getInstance(); - config.MAKE_CHECKED_OUT_FILES_READONLY = myChooseModeStep.getMakeNewFielsReadOnly(); + config.MAKE_CHECKED_OUT_FILES_READONLY = myChooseModeStep.getMakeNewFilesReadOnly(); config.CHECKOUT_PRUNE_EMPTY_DIRECTORIES = myChooseModeStep.getPruneEmptyDirectories(); - config.CHECKOUT_KEYWORD_SUBSTITUTION = myChooseModeStep.getKeywordSubstitution(); + config.CHECKOUT_KEYWORD_SUBSTITUTION = myChooseModeStep.getKeywordSubstitution().toString(); super.doOKAction(); } - public CvsElement[] getSelectedElements() { return mySelectCvsElementStep.getSelectedCvsElements(); } @@ -89,7 +89,7 @@ public class CheckoutWizard extends CvsWizard { private class MySelectLocationStep extends SelectLocationStep { public MySelectLocationStep(Project project) { - super(com.intellij.CvsBundle.message("dialog.title.select.check.out.location"), CheckoutWizard.this, project); + super(CvsBundle.message("dialog.title.select.check.out.location"), CheckoutWizard.this, project); init(); } } @@ -97,5 +97,4 @@ public class CheckoutWizard extends CvsWizard { protected String getHelpID() { return "cvs.checkOutPrj"; } - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/checkout/ChooseCheckoutMode.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/checkout/ChooseCheckoutMode.java index 914b432bdc45..d020f13af633 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/checkout/ChooseCheckoutMode.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/checkout/ChooseCheckoutMode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,6 +15,7 @@ */ package com.intellij.cvsSupport2.ui.experts.checkout; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.config.CvsApplicationLevelConfiguration; import com.intellij.cvsSupport2.cvsBrowser.CvsElement; import com.intellij.cvsSupport2.cvsBrowser.CvsFile; @@ -31,6 +32,7 @@ import com.intellij.util.Icons; import com.intellij.util.containers.HashSet; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; +import org.netbeans.lib.cvsclient.command.KeywordSubstitution; import javax.swing.*; import javax.swing.event.ListSelectionEvent; @@ -38,17 +40,19 @@ import javax.swing.event.ListSelectionListener; import java.awt.*; import java.io.File; import java.util.*; +import java.util.List; /** * author: lesya */ public class ChooseCheckoutMode extends WizardStep { + private File mySelectedLocation; private final Collection myCvsPaths = new ArrayList(); private final DefaultListModel myCheckoutModeModel = new DefaultListModel(); private final JList myCheckoutModeList = new JBList(myCheckoutModeModel); - private final JCheckBox myMakeNewFielsReadOnly = new JCheckBox(com.intellij.CvsBundle.message("checkbox.make.new.files.read.only")); - private final JCheckBox myPruneEmptyDirectories = new JCheckBox(com.intellij.CvsBundle.message("checkbox.prune.empty.directories")); + private final JCheckBox myMakeNewFilesReadOnly = new JCheckBox(CvsBundle.message("checkbox.make.new.files.read.only")); + private final JCheckBox myPruneEmptyDirectories = new JCheckBox(CvsBundle.message("checkbox.prune.empty.directories")); private final ChangeKeywordSubstitutionPanel myChangeKeywordSubstitutionPanel; private final CheckoutWizard myOwner; @@ -84,9 +88,10 @@ public class ChooseCheckoutMode extends WizardStep { myCheckoutModeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); CvsApplicationLevelConfiguration config = CvsApplicationLevelConfiguration.getInstance(); - myMakeNewFielsReadOnly.setSelected(config.MAKE_CHECKED_OUT_FILES_READONLY); + myMakeNewFilesReadOnly.setSelected(config.MAKE_CHECKED_OUT_FILES_READONLY); myPruneEmptyDirectories.setSelected(config.CHECKOUT_PRUNE_EMPTY_DIRECTORIES); - myChangeKeywordSubstitutionPanel = new ChangeKeywordSubstitutionPanel(config.CHECKOUT_KEYWORD_SUBSTITUTION); + myChangeKeywordSubstitutionPanel = + new ChangeKeywordSubstitutionPanel(KeywordSubstitution.getValue(config.CHECKOUT_KEYWORD_SUBSTITUTION)); myCenterPanel.add(LIST, ScrollPaneFactory.createScrollPane(myCheckoutModeList)); JPanel messagePanel = new JPanel(new BorderLayout(2,4)); @@ -117,7 +122,7 @@ public class ChooseCheckoutMode extends WizardStep { private JPanel createOptionsPanel() { JPanel result = new JPanel(new GridLayout(0, 1)); - result.add(myMakeNewFielsReadOnly); + result.add(myMakeNewFilesReadOnly); result.add(myPruneEmptyDirectories); result.add(myChangeKeywordSubstitutionPanel.getPanel()); @@ -145,7 +150,7 @@ public class ChooseCheckoutMode extends WizardStep { rebuildList(); } else { - setStepTitle(com.intellij.CvsBundle.message("info.text.selected.modules.will.be.checked.out.to")); + setStepTitle(CvsBundle.message("info.text.selected.modules.will.be.checked.out.to")); StringBuffer message = composeLocationsMessage(); myMessage.setText(message.toString()); show(MESSAGE); @@ -165,8 +170,7 @@ public class ChooseCheckoutMode extends WizardStep { message.append("

"); message.append(mySelectedLocation.getAbsolutePath()); message.append("

"); - for (Iterator each = myCvsPaths.iterator(); each.hasNext();) { - File file = (File)each.next(); + for (File file : myCvsPaths) { message.append("

"); message.append("        -"); message.append(file.getPath()); @@ -179,15 +183,13 @@ public class ChooseCheckoutMode extends WizardStep { Collection allFiles = new HashSet(); CvsElement[] selection = myOwner.getSelectedElements(); if (selection == null) return allFiles; - for (int i = 0; i < selection.length; i++) { - CvsElement cvsElement = selection[i]; + for (CvsElement cvsElement : selection) { allFiles.add(new File(cvsElement.getCheckoutPath())); } ArrayList result = new ArrayList(); - for (Iterator each = allFiles.iterator(); each.hasNext();) { - File file = (File)each.next(); + for (File file : allFiles) { if (!hasParentIn(allFiles, file)) result.add(file); } @@ -199,10 +201,9 @@ public class ChooseCheckoutMode extends WizardStep { return result; } - private boolean hasParentIn(Collection allFiles, File file) { + private static boolean hasParentIn(Collection allFiles, File file) { String filePath = file.getPath(); - for (Iterator each = allFiles.iterator(); each.hasNext();) { - File file1 = (File)each.next(); + for (File file1 : allFiles) { if (file1.equals(file)) continue; if (filePath.startsWith(file1.getPath())) return true; } @@ -211,16 +212,15 @@ public class ChooseCheckoutMode extends WizardStep { private void rebuildList() { File selected = myCvsPaths.iterator().next(); - setStepTitle(com.intellij.CvsBundle.message("dialog.title.check.out.to", selected)); + setStepTitle(CvsBundle.message("dialog.title.check.out.to", selected)); myCheckoutModeModel.removeAllElements(); CheckoutStrategy[] strategies = CheckoutStrategy.createAllStrategies(mySelectedLocation, selected, myOwner.getSelectedElements()[0] instanceof CvsFile); - Collection results = new HashSet(); - java.util.List resultModes = new ArrayList(); - for (int i = 0; i < strategies.length; i++) { - CheckoutStrategy strategy = strategies[i]; + Collection results = new HashSet(); + List resultModes = new ArrayList(); + for (CheckoutStrategy strategy : strategies) { File resultFile = strategy.getResult(); if (resultFile != null && !results.contains(resultFile)) { results.add(resultFile); @@ -230,8 +230,8 @@ public class ChooseCheckoutMode extends WizardStep { Collections.sort(resultModes); - for (Iterator each = resultModes.iterator(); each.hasNext();) { - myCheckoutModeModel.addElement(each.next()); + for (CheckoutStrategy resultMode : resultModes) { + myCheckoutModeModel.addElement(resultMode); } myCheckoutModeList.setSelectedIndex(0); @@ -241,8 +241,8 @@ public class ChooseCheckoutMode extends WizardStep { ((CardLayout)myCenterPanel.getLayout()).show(myCenterPanel, mode); } - public boolean getMakeNewFielsReadOnly() { - return myMakeNewFielsReadOnly.isSelected(); + public boolean getMakeNewFilesReadOnly() { + return myMakeNewFilesReadOnly.isSelected(); } public boolean getPruneEmptyDirectories() { @@ -267,8 +267,7 @@ public class ChooseCheckoutMode extends WizardStep { } } - public String getKeywordSubstitution() { + public KeywordSubstitution getKeywordSubstitution() { return myChangeKeywordSubstitutionPanel.getKeywordSubstitution(); } - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/FileExtension.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/FileExtension.java index 0ffdeec88a27..725926285fe5 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/FileExtension.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/FileExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -17,7 +17,6 @@ package com.intellij.cvsSupport2.ui.experts.importToCvs; import com.intellij.cvsSupport2.keywordSubstitution.KeywordSubstitutionListWithSelection; import com.intellij.cvsSupport2.keywordSubstitution.KeywordSubstitutionWrapper; -import com.intellij.cvsSupport2.keywordSubstitution.KeywordSubstitutionListWithSelection; /** * author: lesya @@ -64,8 +63,6 @@ public class FileExtension { } public KeywordSubstitutionWrapper getKeywordSubstitution() { - return (KeywordSubstitutionWrapper)getKeywordSubstitutionsWithSelection().getSelection(); + return getKeywordSubstitutionsWithSelection().getSelection(); } - - } From 21e83059acba839a5e8f7659a91ff446c05b756b Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 9 May 2011 12:10:11 +0200 Subject: [PATCH 013/250] CVS cancel instead of don't add --- .../src/com/intellij/cvsSupport2/CvsBundle.properties | 1 - .../cvsAdd/ui/AbstractAddFileConfirmationPanel.java | 8 ++------ .../cvsAdd/ui/AbstractAddOptionsDialog.java | 11 +++-------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties index 80a77af646d2..77fadeca5025 100644 --- a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties +++ b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties @@ -165,7 +165,6 @@ exception.text.unknown.error=Unknown Error progress.text.command.running.for.file=Command ''{0}'' running for {1} progress.text.searching.for.cvs.root=Searching for CVS Root button.text.add.to.cvs=&Add to CVS -button.text.dont.add.to.cvs=Do&n't Add dialog.title.add.files.to.cvs=Add Files to CVS action.name.select.all=Select All action.name.unselect.all=Unselect All diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/ui/AbstractAddFileConfirmationPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/ui/AbstractAddFileConfirmationPanel.java index 05ec846db0ed..9c53a61539aa 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/ui/AbstractAddFileConfirmationPanel.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/ui/AbstractAddFileConfirmationPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -16,9 +16,6 @@ package com.intellij.cvsSupport2.cvsoperations.cvsAdd.ui; import com.intellij.cvsSupport2.cvsoperations.cvsAdd.AddedFileInfo; -import com.intellij.cvsSupport2.util.CvsVfsUtil; -import com.intellij.cvsSupport2.cvsoperations.cvsAdd.AddedFileInfo; -import com.intellij.util.ui.FileLabel; import com.intellij.util.ui.FileLabel; import java.awt.*; @@ -31,8 +28,7 @@ public abstract class AbstractAddFileConfirmationPanel { public static AbstractAddFileConfirmationPanel createOn(AddedFileInfo info){ return info.getFile().isDirectory() ? - new AddDirectoryConfirmationPanel(info) : - (AbstractAddFileConfirmationPanel)new AddFileConfirmationPanel(info); + new AddDirectoryConfirmationPanel(info) : new AddFileConfirmationPanel(info); } public AbstractAddFileConfirmationPanel(AddedFileInfo addedFileInfo) { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/ui/AbstractAddOptionsDialog.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/ui/AbstractAddOptionsDialog.java index 2ba92d2b9032..89ab10920d1e 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/ui/AbstractAddOptionsDialog.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAdd/ui/AbstractAddOptionsDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,17 +15,14 @@ */ package com.intellij.cvsSupport2.cvsoperations.cvsAdd.ui; -import com.intellij.cvsSupport2.cvsoperations.cvsAdd.AddedFileInfo; -import com.intellij.cvsSupport2.cvsoperations.cvsAdd.AddedFileInfo; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.cvsoperations.cvsAdd.AddedFileInfo; import com.intellij.cvsSupport2.ui.Options; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.util.ui.OptionsDialog; -import com.intellij.util.ui.OptionsDialog; import com.intellij.util.ui.UIUtil; -import javax.swing.*; import java.util.Collection; /** @@ -54,9 +51,7 @@ public abstract class AbstractAddOptionsDialog extends OptionsDialog { public AbstractAddOptionsDialog(Project project, Options options) { super(project); myOptions = options; - UIUtil.setActionNameAndMnemonic(com.intellij.CvsBundle.message("button.text.add.to.cvs"), getOKAction()); - UIUtil.setActionNameAndMnemonic(com.intellij.CvsBundle.message("button.text.dont.add.to.cvs"), getCancelAction()); - + UIUtil.setActionNameAndMnemonic(CvsBundle.message("button.text.add.to.cvs"), getOKAction()); } protected boolean isToBeShown() { From a4fc0d9d17031df77d16bbc3d453d811558c7ee4 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 9 May 2011 12:24:06 +0200 Subject: [PATCH 014/250] IDEA-40291 (Logging of CVS client/server output expects IDEA's bin directory to be writable) --- .../src/com/intellij/cvsSupport2/CvsBundle.properties | 5 +++-- .../cvsSupport2/config/ui/GlobalCvsSettingsPanel.form | 4 ++-- .../intellij/cvsSupport2/javacvsImpl/io/StreamLogger.java | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties index 77fadeca5025..0aeb52672205 100644 --- a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties +++ b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties @@ -283,9 +283,10 @@ label.cvs.root.repository=Repository: label.cvs.root.host=Host: label.cvs.root.user=User: label.cvs.root.method=Method: -checkbox.log.cvs.client.server.output=Log cvs client/server output to cvs.output file +checkbox.log.cvs.client.server.output=Log cvs client/server output to cvs.log file label.charset.combo.label=Charset: -checkbox.global.settings.use.gzip.compression=Use gzip compression +checkbox.use.gzip.compression=Use gzip compression +checkbox.send.environment.variables=Send &environment variables to server label.configure.ext.additional.parameters=&Additional parameters: label.configure.ext.path.to.private.key.file=Path to &private key file: label.configure.ext.path.to.e&xternal.rsh=Path to e&xternal rsh: diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/GlobalCvsSettingsPanel.form b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/GlobalCvsSettingsPanel.form index 0eba3e390d2f..27dec3549fb0 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/GlobalCvsSettingsPanel.form +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/GlobalCvsSettingsPanel.form @@ -34,7 +34,7 @@ - + @@ -82,7 +82,7 @@ - + diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/javacvsImpl/io/StreamLogger.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/javacvsImpl/io/StreamLogger.java index be36e3b4445c..408c0254d0ee 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/javacvsImpl/io/StreamLogger.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/javacvsImpl/io/StreamLogger.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -16,6 +16,7 @@ package com.intellij.cvsSupport2.javacvsImpl.io; import com.intellij.cvsSupport2.config.CvsApplicationLevelConfiguration; +import com.intellij.openapi.application.PathManager; import com.intellij.openapi.util.io.FileUtil; import org.netbeans.lib.cvsclient.io.IStreamLogger; import org.jetbrains.annotations.NonNls; @@ -39,7 +40,7 @@ public class StreamLogger implements IStreamLogger { private OutputStream myLogOutput; private static final long MAX_OUTPUT_SIZE = 1000000; - @NonNls private static final String OUTPUT_PATHNAME = "cvs.output"; + @NonNls private static final String OUTPUT_FILE_NAME = "cvs.log"; private static OutputStream createFileOutputStream(final File cvsOutputFile) { try { @@ -113,7 +114,7 @@ public class StreamLogger implements IStreamLogger { private void initLogOutput() { if (CvsApplicationLevelConfiguration.getInstance().DO_OUTPUT) { - File cvsOutputFile = new File(OUTPUT_PATHNAME); + File cvsOutputFile = new File(PathManager.getLogPath(), OUTPUT_FILE_NAME); if (cvsOutputFile.isFile() && cvsOutputFile.length() > MAX_OUTPUT_SIZE) { FileUtil.delete(cvsOutputFile); } From 0b9a7cc05e8de388bd58fb7155fc7c355301fc66 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 9 May 2011 13:35:46 +0200 Subject: [PATCH 015/250] IDEA-16669 (Remember "create tag" considered harmful) --- .../cvsSupport2/CvsCheckinHandlerFactory.java | 5 +++-- .../AdditionalOptionsPanel.form | 2 +- .../AdditionalOptionsPanel.java | 22 +++++++++---------- .../cvsTagOrBranch/ui/CvsTagDialog.java | 6 ++--- .../cvsTagOrBranch/ui/TagNameFieldOwner.java | 5 +++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsCheckinHandlerFactory.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsCheckinHandlerFactory.java index b704711ac2ea..2f0fa0a6c757 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsCheckinHandlerFactory.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsCheckinHandlerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -30,6 +30,7 @@ import org.jetbrains.annotations.Nullable; * @author yole */ class CvsCheckinHandlerFactory extends VcsCheckinHandlerFactory { + CvsCheckinHandlerFactory() { super(CvsVcs2.getKey()); } @@ -40,7 +41,7 @@ class CvsCheckinHandlerFactory extends VcsCheckinHandlerFactory { return new CheckinHandler() { @Nullable public RefreshableOnComponent getAfterCheckinConfigurationPanel(Disposable parentDisposable) { - return new AdditionalOptionsPanel(true, CvsConfiguration.getInstance(panel.getProject())); + return new AdditionalOptionsPanel(CvsConfiguration.getInstance(panel.getProject())); } }; } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/checkinProject/AdditionalOptionsPanel.form b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/checkinProject/AdditionalOptionsPanel.form index ad8a4b9a727a..14b6d418f6ee 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/checkinProject/AdditionalOptionsPanel.form +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/checkinProject/AdditionalOptionsPanel.form @@ -49,7 +49,7 @@ - + diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/checkinProject/AdditionalOptionsPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/checkinProject/AdditionalOptionsPanel.java index 6e26ae044080..99b6083df016 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/checkinProject/AdditionalOptionsPanel.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/checkinProject/AdditionalOptionsPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,6 +15,7 @@ */ package com.intellij.cvsSupport2.checkinProject; +import com.intellij.CvsBundle; import com.intellij.cvsSupport2.config.CvsConfiguration; import com.intellij.cvsSupport2.cvsoperations.cvsTagOrBranch.ui.TagNameFieldOwner; import com.intellij.cvsSupport2.ui.experts.importToCvs.CvsFieldValidator; @@ -35,10 +36,9 @@ public class AdditionalOptionsPanel implements RefreshableOnComponent, TagNameFi private final CvsConfiguration myConfiguration; private boolean myIsCorrect = true; private String myErrorMessage; - private JCheckBox myOverrideExistings; + private JCheckBox myOverrideExisting; - public AdditionalOptionsPanel(boolean checkinProject, - CvsConfiguration configuration) { + public AdditionalOptionsPanel(CvsConfiguration configuration) { myConfiguration = configuration; myTag.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -51,24 +51,22 @@ public class AdditionalOptionsPanel implements RefreshableOnComponent, TagNameFi private void updateEnable() { boolean tag = myTag.isSelected(); myTagName.setEditable(tag); - myOverrideExistings.setEnabled(tag); + myOverrideExisting.setEnabled(tag); } public void refresh() { - myTag.setSelected(myConfiguration.TAG_AFTER_PROJECT_COMMIT); myTagName.setText(myConfiguration.TAG_AFTER_PROJECT_COMMIT_NAME); - myOverrideExistings.setSelected(myConfiguration.OVERRIDE_EXISTING_TAG_FOR_PROJECT); + myOverrideExisting.setSelected(myConfiguration.OVERRIDE_EXISTING_TAG_FOR_PROJECT); updateEnable(); } public void saveState() { if (!myIsCorrect) { - throw new InputException(com.intellij.CvsBundle.message("error.message.incorrect.tag.name", myErrorMessage), myTagName); + throw new InputException(CvsBundle.message("error.message.incorrect.tag.name", myErrorMessage), myTagName); } myConfiguration.TAG_AFTER_PROJECT_COMMIT = myTag.isSelected(); - myConfiguration.OVERRIDE_EXISTING_TAG_FOR_PROJECT = myOverrideExistings.isSelected(); + myConfiguration.OVERRIDE_EXISTING_TAG_FOR_PROJECT = myOverrideExisting.isSelected(); myConfiguration.TAG_AFTER_PROJECT_COMMIT_NAME = myTagName.getText().trim(); - } public void restoreState() { @@ -83,9 +81,9 @@ public class AdditionalOptionsPanel implements RefreshableOnComponent, TagNameFi myIsCorrect = true; } - public void disableOkAction(String errorMeesage) { + public void disableOkAction(String errorMessage) { myIsCorrect = false; - myErrorMessage = errorMeesage; + myErrorMessage = errorMessage; } public boolean tagFieldIsActive() { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/CvsTagDialog.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/CvsTagDialog.java index 5cb3d0f30cd6..bc41191977f9 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/CvsTagDialog.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/CvsTagDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -21,6 +21,7 @@ import com.intellij.openapi.ui.DialogWrapper; * author: lesya */ public abstract class CvsTagDialog extends DialogWrapper implements TagNameFieldOwner { + public CvsTagDialog() { super(true); } @@ -29,8 +30,7 @@ public abstract class CvsTagDialog extends DialogWrapper implements TagNameField setOKActionEnabled(true); } - public void disableOkAction(String errorMeesage){ + public void disableOkAction(String errorMessage){ setOKActionEnabled(false); } - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/TagNameFieldOwner.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/TagNameFieldOwner.java index 17512496f90a..c3adfbc2208f 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/TagNameFieldOwner.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsTagOrBranch/ui/TagNameFieldOwner.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -16,9 +16,10 @@ package com.intellij.cvsSupport2.cvsoperations.cvsTagOrBranch.ui; public interface TagNameFieldOwner { + void enableOkAction(); - void disableOkAction(String errorMeesage); + void disableOkAction(String errorMessage); boolean tagFieldIsActive(); } \ No newline at end of file From e4cd1e033a508d53741fb4654df50267f69535fe Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Mon, 9 May 2011 13:05:44 +0400 Subject: [PATCH 016/250] test fix --- .../refactoring/convertGroovyToJava/codeBlock/prefixInc.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/codeBlock/prefixInc.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/codeBlock/prefixInc.java index fdea2abfaad2..f773a296e766 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/codeBlock/prefixInc.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/codeBlock/prefixInc.java @@ -1,4 +1,4 @@ Upper upper = new Upper(); println(upper.getTest().setBar(upper.getTest().getBar().next())); Test test = new Test(); -(test.state = test.state.next()); +test.state = test.state.next(); From ab0e4702bff8b6fef4e2f6ec4b9866ee4a95f531 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Mon, 9 May 2011 14:48:46 +0400 Subject: [PATCH 017/250] anonymous class converting --- .../convertToJava/ArgumentListGenerator.java | 2 +- .../convertToJava/ExpressionGenerator.java | 11 ++++-- .../convertToJava/FileGenerationTest.groovy | 2 + .../convertGroovyToJava/file/anonymous.groovy | 10 +++++ .../convertGroovyToJava/file/anonymous.java | 26 +++++++++++++ .../file/anonymous2.groovy | 17 +++++++++ .../convertGroovyToJava/file/anonymous2.java | 37 +++++++++++++++++++ 7 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous.groovy create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous.java create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous2.groovy create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous2.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ArgumentListGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ArgumentListGenerator.java index 4940bc6741e8..d1f49622a95a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ArgumentListGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ArgumentListGenerator.java @@ -38,7 +38,7 @@ import java.util.Arrays; * @author Maxim.Medvedev */ class ArgumentListGenerator { - private Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.refactoring.convertToJava.ArgumentListGenerator"); + private static Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.refactoring.convertToJava.ArgumentListGenerator"); private final StringBuilder myBuilder; private final ExpressionGenerator myExpressionGenerator; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java index 851f7a2dbaef..1e216be5384a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java @@ -283,8 +283,10 @@ public class ExpressionGenerator extends Generator { } private void writeTypeBody(StringBuilder builder, GrAnonymousClassDefinition anonymous) { - //todo write type body for anonymous class - throw new UnsupportedOperationException(); + builder.append("{\n"); + new ClassGenerator(context.project, new GeneratorClassNameProvider(), new ClassItemGeneratorImpl(context.project)) + .writeMembers(builder, anonymous, true); + builder.append('}'); } @Override @@ -684,7 +686,10 @@ public class ExpressionGenerator extends Generator { final PsiElement resolved = expr.resolve(); LOG.assertTrue(resolved instanceof PsiClass); - builder.append(((PsiClass)resolved).getQualifiedName()).append(".").append(expr.getReferenceName()); + if (!(resolved instanceof PsiAnonymousClass)) { + builder.append(((PsiClass)resolved).getQualifiedName()).append("."); + } + builder.append(expr.getReferenceName()); } @Override diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy index 61432ec41a6a..14b09ca510c2 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy @@ -58,4 +58,6 @@ class FileGenerationTest extends LightGroovyTestCase { void testConcurency() {doTest()} void testHash() {doTest()} + void testAnonymous() {doTest()} + void testAnonymous2() {doTest()} } diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous.groovy b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous.groovy new file mode 100644 index 000000000000..09d88f77e31c --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous.groovy @@ -0,0 +1,10 @@ +def foo = 2 +def an = new Runnable() { + void run() { + println foo + } +} + +an.run() + +println foo \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous.java new file mode 100644 index 000000000000..9a84ea66616e --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous.java @@ -0,0 +1,26 @@ +public class anonymous extends groovy.lang.Script { +public static void main(java.lang.String[] args) { +new anonymous(new groovy.lang.Binding(args)).run(); +} + +public java.lang.Object run() { +java.lang.Integer foo = 2; +java.lang.Runnable an = new java.lang.Runnable(){ +public void run() { +org.codehaus.groovy.runtime.DefaultGroovyMethods.println(this, foo); +} + +}; +an.run(); +println(foo); +return null; + +} + +public anonymous(groovy.lang.Binding binding) { +super(binding); +} +public anonymous() { +super(); +} +} diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous2.groovy b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous2.groovy new file mode 100644 index 000000000000..ffa27167a9e5 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous2.groovy @@ -0,0 +1,17 @@ +def an = new Anon(3) { + void run() { + println foo + } +} + +an.run() + +abstract class Anon { + def foo + + Anon(def foo) { + this.foo = foo + } + + abstract void run() +} \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous2.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous2.java new file mode 100644 index 000000000000..a2d9b2657fde --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous2.java @@ -0,0 +1,37 @@ +public abstract class Anon extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { +public Anon(java.lang.Object foo) { +Anon.this.foo = foo; +} +public abstract void run() ; +public java.lang.Object getFoo() { + return foo; +} +public void setFoo(java.lang.Object foo) { +this.foo = foo; +} +private java.lang.Object foo; +} +public class anonymous2 extends groovy.lang.Script { +public static void main(java.lang.String[] args) { +new anonymous2(new groovy.lang.Binding(args)).run(); +} + +public java.lang.Object run() { +Anon an = new Anon(3){ +public void run() { +org.codehaus.groovy.runtime.DefaultGroovyMethods.println(this, getFoo()); +} + +}; +an.run(); +return null; + +} + +public anonymous2(groovy.lang.Binding binding) { +super(binding); +} +public anonymous2() { +super(); +} +} From 2e21a566393f2948451c3d08249e774aa39f3497 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 9 May 2011 15:17:47 +0200 Subject: [PATCH 018/250] EA-27420 (NPE: StringUtil.splitByLines) --- ...kageDotHtmlMayBePackageInfoInspection.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/javadoc/PackageDotHtmlMayBePackageInfoInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/javadoc/PackageDotHtmlMayBePackageInfoInspection.java index 73efd2d9a634..ca76719cdda2 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/javadoc/PackageDotHtmlMayBePackageInfoInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/javadoc/PackageDotHtmlMayBePackageInfoInspection.java @@ -43,6 +43,7 @@ import com.siyeh.ig.InspectionGadgetsFix; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class PackageDotHtmlMayBePackageInfoInspection extends BaseInspection { @@ -151,10 +152,13 @@ public class PackageDotHtmlMayBePackageInfoInspection extends BaseInspection { file.getVirtualFile()); final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); - final String packageInfoText = getPackageInfoText(xmlFile); + String packageInfoText = getPackageInfoText(xmlFile); + if (packageInfoText == null) { + packageInfoText = xmlFile.getText(); + } + final StringBuilder commentText = new StringBuilder("/**\n"); final String[] lines = StringUtil.splitByLines(packageInfoText); - final StringBuilder commentText = new StringBuilder("/**\n"); boolean appended = false; for (String line : lines) { if (!appended && line.length() == 0) { @@ -168,10 +172,14 @@ public class PackageDotHtmlMayBePackageInfoInspection extends BaseInspection { final PsiDocComment comment = elementFactory.createDocCommentFromText( commentText.toString()); - final PsiPackageStatement packageStatement = - elementFactory.createPackageStatement(aPackage); - final PsiElement addedElement = file.add(packageStatement); - file.addBefore(comment, addedElement); + if (aPackage.length() > 0) { + final PsiPackageStatement packageStatement = + elementFactory.createPackageStatement(aPackage); + final PsiElement addedElement = file.add(packageStatement); + file.addBefore(comment, addedElement); + } else { + file.add(comment); + } element.delete(); if (!isOnTheFly()) { return; @@ -200,6 +208,7 @@ public class PackageDotHtmlMayBePackageInfoInspection extends BaseInspection { }.execute(); } + @Nullable private static String getPackageInfoText(XmlFile xmlFile) { final XmlTag rootTag = xmlFile.getRootTag(); if (rootTag == null) { From d4f41935bab10d88b2d1cdf1f4a7f2ff8bca1619 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 9 May 2011 15:19:07 +0200 Subject: [PATCH 019/250] IDEA-69006 (StringConcatenation - "Ignore for JUnit assert statements") --- .../siyeh/InspectionGadgetsBundle.properties | 1 + .../StringConcatenationInspection.java | 19 +++++++++++++++++++ .../StringConcatenation.html | 3 +++ 3 files changed, 23 insertions(+) diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties index da86a6bb3b7a..8ad3df687cf1 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties @@ -350,6 +350,7 @@ string.concatenation.ignore.system.err.option=Ignore for 'System.err.print' argu string.concatenation.ignore.assert.option=Ignore for assert statement arguments string.concatenation.ignore.exceptions.option=Ignore for throwable arguments string.concatenation.ignore.constant.initializers.option=Ignore for initializers of constants +string.concatenation.ignore.in.test.code=Ignore in test code string.equalsignorecase.call.display.name=Call to 'String.equalsIgnoreCase()' string.equalsignorecase.call.problem.descriptor=String.#ref() using internationalized strings #loc string.equals.call.display.name=Call to 'String.equals()' diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/internationalization/StringConcatenationInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/internationalization/StringConcatenationInspection.java index 9dd176fb50ed..b0e3f37b4943 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/internationalization/StringConcatenationInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/internationalization/StringConcatenationInspection.java @@ -16,6 +16,7 @@ package com.siyeh.ig.internationalization; import com.intellij.codeInsight.AnnotationUtil; +import com.intellij.codeInsight.TestUtil; import com.intellij.codeInsight.intention.AddAnnotationFix; import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel; import com.intellij.psi.*; @@ -27,6 +28,7 @@ import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.DelegatingFix; import com.siyeh.ig.InspectionGadgetsFix; +import com.siyeh.ig.psiutils.TestUtils; import com.siyeh.ig.psiutils.TypeUtils; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -53,6 +55,9 @@ public class StringConcatenationInspection extends BaseInspection { @SuppressWarnings({"PublicField"}) public boolean ignoreConstantInitializers = false; + @SuppressWarnings({"PublicField"}) + public boolean ignoreInTestCode = false; + @Override @NotNull public String getDisplayName() { @@ -139,6 +144,9 @@ public class StringConcatenationInspection extends BaseInspection { optionsPanel.addCheckbox(InspectionGadgetsBundle.message( "string.concatenation.ignore.constant.initializers.option"), "ignoreConstantInitializers"); + optionsPanel.addCheckbox(InspectionGadgetsBundle.message( + "string.concatenation.ignore.in.test.code"), + "ignoreInTestCode"); return optionsPanel; } @@ -176,6 +184,17 @@ public class StringConcatenationInspection extends BaseInspection { if (isInsideAnnotation(expression)) { return; } + if (ignoreInTestCode) { + if (TestUtils.isPartOfJUnitTestMethod(expression)) { + return; + } + final PsiClass containingClass = + PsiTreeUtil.getParentOfType(expression, PsiClass.class); + if (containingClass != null && + TestUtil.isTestClass(containingClass)) { + return; + } + } if (ignoreAsserts) { final PsiAssertStatement assertStatement = PsiTreeUtil.getParentOfType(expression, diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/StringConcatenation.html b/plugins/InspectionGadgets/src/inspectionDescriptions/StringConcatenation.html index bee86f4edf5b..16c3ef44ad6f 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/StringConcatenation.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/StringConcatenation.html @@ -12,6 +12,9 @@ for a call to any of the System.out.print() methods. for a call to any of the System.err.print() methods.
Use the fourth checkbox to ignore string concatenations used as arguments in the construction of any subclass of java.lang.Throwable +
Use the fifth checkbox to ignore string concatenations in the initializers +of constant fields. +
Use the sixth checkbox to ignore string concatenations in test code.

Powered by InspectionGadgets From 42f29e84726cea792c550847ae790c553b41d4d9 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 9 May 2011 15:31:26 +0200 Subject: [PATCH 020/250] IDEA-69004 (MethodOnlyUsedFromInnerClass - False positive when method used by constructor to anonymous inner class.) --- ...ethodOnlyUsedFromInnerClassInspection.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/MethodOnlyUsedFromInnerClassInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/MethodOnlyUsedFromInnerClassInspection.java index e03e3ec8165e..6cedfebb428c 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/MethodOnlyUsedFromInnerClassInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/MethodOnlyUsedFromInnerClassInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 Bas Leijdekkers + * Copyright 2005-2011 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -154,6 +154,7 @@ public class MethodOnlyUsedFromInnerClassInspection extends BaseInspection { methodClass = method.getContainingClass(); } + @Override public boolean process(PsiReference reference) { final PsiElement element = reference.getElement(); final PsiMethod containingMethod = @@ -167,10 +168,19 @@ public class MethodOnlyUsedFromInnerClassInspection extends BaseInspection { onlyAccessedFromInnerClass = false; return false; } - if (ignoreMethodsAccessedFromAnonymousClass && - containingClass instanceof PsiAnonymousClass) { - onlyAccessedFromInnerClass = false; - return false; + if (containingClass instanceof PsiAnonymousClass) { + final PsiAnonymousClass anonymousClass = + (PsiAnonymousClass) containingClass; + final PsiExpressionList argumentList = + anonymousClass.getArgumentList(); + if (PsiTreeUtil.isAncestor(argumentList, element, true)) { + onlyAccessedFromInnerClass = false; + return false; + } + if (ignoreMethodsAccessedFromAnonymousClass) { + onlyAccessedFromInnerClass = false; + return false; + } } if (cache != null) { if (!cache.equals(containingClass)) { From 5c7b0a4ecfdb279e37a3c8855d5697e3f6cbdd52 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Mon, 9 May 2011 15:42:15 +0200 Subject: [PATCH 021/250] make outputRoot nullable --- .../compiler/impl/TranslatingCompilerFilesMonitor.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java index 9742ca6a98f0..c044e46dfa65 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java @@ -282,7 +282,7 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { return IndexInfrastructure.findFileById((PersistentFS)ManagingFS.getInstance(), id); } - public void update(final CompileContext context, final String outputRoot, final Collection successfullyCompiled, final VirtualFile[] filesToRecompile) + public void update(final CompileContext context, @Nullable final String outputRoot, final Collection successfullyCompiled, final VirtualFile[] filesToRecompile) throws IOException { final Project project = context.getProject(); final int projectId = getProjectId(project); @@ -316,11 +316,10 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { final VirtualFile outputFile = lfs.findFileByPath(outputPath); //assert outputFile != null : "Virtual file was not found for \"" + outputPath + "\""; - assert outputRoot != null; if (outputFile != null) { if (!sourceFile.equals(outputFile)) { - final String className = MakeUtil.relativeClassPathToQName(outputPath.substring(outputRoot.length()), '/'); + final String className = outputRoot == null? null : MakeUtil.relativeClassPathToQName(outputPath.substring(outputRoot.length()), '/'); if (isSourceValid) { srcInfo.addOutputPath(projectId, outputPath); saveOutputInfo(outputFile, new OutputFileInfo(sourceFile.getPath(), className)); From 02fe384e783560fba42ae8ddc391007660e920da Mon Sep 17 00:00:00 2001 From: Sascha Weinreuter Date: Mon, 9 May 2011 19:00:40 +0200 Subject: [PATCH 022/250] EA-27619 --- .../org/intellij/lang/xpath/psi/impl/XPathStringImpl.java | 8 ++++++-- .../org/intellij/lang/xpath/XPathHighlightingTest.java | 4 ++++ .../xpath/highlighting/malformedEmptyStringLiteral.xpath | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 plugins/xpath/xpath-lang/testData/xpath/highlighting/malformedEmptyStringLiteral.xpath diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathStringImpl.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathStringImpl.java index ec3eb3ce16ea..cb0b6c92df71 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathStringImpl.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathStringImpl.java @@ -35,7 +35,7 @@ public class XPathStringImpl extends XPathElementImpl implements XPathString { public boolean isWellFormed() { final String text = getUnescapedText(); final char quoteChar = getQuoteChar(); - if (!text.endsWith(String.valueOf(quoteChar))) { + if (!text.endsWith(String.valueOf(quoteChar)) || text.indexOf(quoteChar) == text.lastIndexOf(quoteChar)) { return false; } @@ -62,7 +62,11 @@ public class XPathStringImpl extends XPathElementImpl implements XPathString { private String getStringBetweenQuotes() { final String text = getUnescapedText(); - return text.endsWith(String.valueOf(getQuoteChar())) ? text.substring(1, text.length() - 1) : text.substring(1, text.length()); + if (text.endsWith(String.valueOf(getQuoteChar())) && text.length() > 1) { + return text.substring(1, text.length() - 1); + } else { + return text.substring(1, text.length()); + } } private char getQuoteChar() { diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathHighlightingTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathHighlightingTest.java index 8d0190d57a84..a7435194e5f4 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathHighlightingTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPathHighlightingTest.java @@ -68,6 +68,10 @@ public class XPathHighlightingTest extends TestBase { doXPathHighlighting(); } + public void testMalformedEmptyStringLiteral() throws Throwable { + doXPathHighlighting(); + } + public void testQuotedStringLiteral() throws Throwable { doXPathHighlighting(); } diff --git a/plugins/xpath/xpath-lang/testData/xpath/highlighting/malformedEmptyStringLiteral.xpath b/plugins/xpath/xpath-lang/testData/xpath/highlighting/malformedEmptyStringLiteral.xpath new file mode 100644 index 000000000000..4dd29d588002 --- /dev/null +++ b/plugins/xpath/xpath-lang/testData/xpath/highlighting/malformedEmptyStringLiteral.xpath @@ -0,0 +1 @@ +' \ No newline at end of file From f29ff43a8e33fa0ba7ea5bb8f2d452f2c203c8a6 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 9 May 2011 16:25:38 +0200 Subject: [PATCH 023/250] never, ever, ever use getDefaultProject() unless you really know what you're doing (IDEA-69401) [r=peter] --- .../src/com/intellij/util/indexing/SubstitutedFileType.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/SubstitutedFileType.java b/platform/lang-impl/src/com/intellij/util/indexing/SubstitutedFileType.java index d0f40e7078eb..8e9cc82dc8f9 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/SubstitutedFileType.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/SubstitutedFileType.java @@ -19,7 +19,6 @@ import com.intellij.lang.Language; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.LanguageSubstitutors; import org.jetbrains.annotations.NotNull; @@ -42,7 +41,7 @@ public class SubstitutedFileType extends LanguageFileType{ public static FileType substituteFileType(VirtualFile file, @NotNull FileType fileType, Project project) { if (project == null) { - project = ProjectManager.getInstance().getDefaultProject(); + return fileType; } if (fileType instanceof LanguageFileType) { final Language language = ((LanguageFileType)fileType).getLanguage(); From 886c005cd7edb516cfbbec12f0bbe30cf46abf03 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 9 May 2011 17:25:07 +0200 Subject: [PATCH 024/250] calling System.exit() from inside component manager lock can cause deadlock with shutdown thread (IDEA-69134) [r=max] --- .../com/intellij/openapi/application/impl/ApplicationImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index d679cecbe8db..39c61712019d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -308,8 +308,9 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application else { //noinspection UseOfSystemOutOrSystemErr System.out.println(errorMessage); + System.exit(1); } - System.exit(1); + return; // do not call super } else if (fatal) { LOG.error(ex); From 294f733e835f5279a6eb04fe969c77178b8a8798 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 9 May 2011 17:35:36 +0200 Subject: [PATCH 025/250] broken plugins shouldn't break IDEA, even for the sake of diagnostics [r=peter] --- .../codeInsight/navigation/actions/GotoDeclarationAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.java index b49218702b60..4e9f43ffc6df 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.java @@ -200,7 +200,7 @@ public class GotoDeclarationAction extends BaseCodeInsightAction implements Code } } catch (AbstractMethodError e) { - throw new RuntimeException(handler.toString(), e); + LOG.error(handler.toString(), e); } } From 81cbe1ca5ebcf792a34a33753ae62a3e337517fe Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 9 May 2011 18:08:35 +0200 Subject: [PATCH 026/250] EA-26070 - assert: MessageBusImpl.checkNotDisposed [r=peter] --- .../openapi/vcs/changes/committed/CommittedChangesCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesCache.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesCache.java index c5fb3ad68351..a70e6e7f6d72 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesCache.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesCache.java @@ -789,7 +789,7 @@ public class CommittedChangesCache implements PersistentStateComponent Date: Mon, 9 May 2011 18:22:31 +0200 Subject: [PATCH 027/250] found some dead code --- .../src/com/intellij/pom/PomElement.java | 25 ----------- .../src/com/intellij/pom/PomPresentation.java | 43 ------------------- .../src/com/intellij/pom/Presentable.java | 20 --------- 3 files changed, 88 deletions(-) delete mode 100644 platform/lang-api/src/com/intellij/pom/PomElement.java delete mode 100644 platform/platform-api/src/com/intellij/pom/PomPresentation.java delete mode 100644 platform/platform-api/src/com/intellij/pom/Presentable.java diff --git a/platform/lang-api/src/com/intellij/pom/PomElement.java b/platform/lang-api/src/com/intellij/pom/PomElement.java deleted file mode 100644 index 525801217607..000000000000 --- a/platform/lang-api/src/com/intellij/pom/PomElement.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2000-2009 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.pom; - -import com.intellij.openapi.util.UserDataHolder; - -public interface PomElement extends UserDataHolder, Presentable, Navigatable { - PomModel getModel(); - - long getModificationStamp(); - boolean isValid(); -} \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/pom/PomPresentation.java b/platform/platform-api/src/com/intellij/pom/PomPresentation.java deleted file mode 100644 index 55d0bcb99c65..000000000000 --- a/platform/platform-api/src/com/intellij/pom/PomPresentation.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2000-2009 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.pom; - -import javax.swing.*; - -public interface PomPresentation { - /** - * @return object name to be presented in most renderers across the program. - */ - String getName(); - - /** - * @return location info to be used by some renderers to present additional info on item's location. Usually displayed as grayed text next to item name (like class's package) - */ - String getLocationString(); - - /** - * @param open only meaningful when used in a tree renderers. false is passed when icon for other renderers is required. - * @return icon - */ - Icon getIcon(boolean open); - - /** - * Some structures (project view) are to sort entities by their type meaning subdirectories should go prior files in the directory. - * This weight value is used to perform sorting. - * @return type weight value. The lesser value is the higher item would be placed in the hierarchy. - */ - int getWeight(); -} \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/pom/Presentable.java b/platform/platform-api/src/com/intellij/pom/Presentable.java deleted file mode 100644 index ade9dbad8ece..000000000000 --- a/platform/platform-api/src/com/intellij/pom/Presentable.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2000-2009 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.pom; - -public interface Presentable { - PomPresentation getPresentation(); -} \ No newline at end of file From 955ecda91d7655d5181f62f091f115eb4fd0e022 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 9 May 2011 18:42:09 +0200 Subject: [PATCH 028/250] EA-27369 - NPE: ProjectTreeBuilder.updateNodesContaining --- .../intellij/ide/projectView/impl/ProjectTreeBuilder.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectTreeBuilder.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectTreeBuilder.java index b60b7b4c7c3e..83dc5f1c918f 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectTreeBuilder.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectTreeBuilder.java @@ -35,12 +35,10 @@ import com.intellij.openapi.vcs.FileStatusManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.problems.WolfTheProblemSolver; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.util.Alarm; import com.intellij.util.SmartList; import com.intellij.util.messages.MessageBusConnection; -import com.intellij.util.xmlb.DefaultSerializationFilter; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; @@ -192,7 +190,10 @@ public class ProjectTreeBuilder extends BaseProjectTreeBuilder { synchronized (myFilesToRefresh) { filesToRefresh = new THashSet(myFilesToRefresh); } - updateNodesContaining(filesToRefresh, getRootNode()); + final DefaultMutableTreeNode rootNode = getRootNode(); + if (rootNode != null) { + updateNodesContaining(filesToRefresh, rootNode); + } synchronized (myFilesToRefresh) { myFilesToRefresh.removeAll(filesToRefresh); } From c7f37a885c6a9fba66e0625bedc12458bd3f060f Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 9 May 2011 18:55:29 +0200 Subject: [PATCH 029/250] EA-27463 - NPE: UIDesignerToolWindowManager.refreshErrors --- .../UIDesignerToolWindowManager.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/UIDesignerToolWindowManager.java b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/UIDesignerToolWindowManager.java index e5176107d6bf..c628acde799b 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/UIDesignerToolWindowManager.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/UIDesignerToolWindowManager.java @@ -194,12 +194,16 @@ public class UIDesignerToolWindowManager implements ProjectComponent { } public void refreshErrors() { - myComponentTree.refreshIntentionHint(); - myComponentTree.repaint(myComponentTree.getVisibleRect()); + if (myComponentTree != null) { + myComponentTree.refreshIntentionHint(); + myComponentTree.repaint(myComponentTree.getVisibleRect()); + } // PropertyInspector - myPropertyInspector.refreshIntentionHint(); - myPropertyInspector.repaint(myPropertyInspector.getVisibleRect()); + if (myPropertyInspector != null) { + myPropertyInspector.refreshIntentionHint(); + myPropertyInspector.repaint(myPropertyInspector.getVisibleRect()); + } } public void updateComponentTree() { From 3f1689f700f8d6295c1915ab02ba280e7c17b87e Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Mon, 9 May 2011 22:19:58 +0200 Subject: [PATCH 030/250] correctly implement exclusions from annotation processing (IDEA-69349) --- .../impl/javaCompiler/AnnotationProcessingCompiler.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/AnnotationProcessingCompiler.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/AnnotationProcessingCompiler.java index 77d2a7653f80..36cf64ae998c 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/AnnotationProcessingCompiler.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/AnnotationProcessingCompiler.java @@ -115,9 +115,12 @@ public class AnnotationProcessingCompiler implements TranslatingCompiler{ } private boolean isExcludedFromAnnotationProcessing(VirtualFile file, CompileContext context) { + if (!context.isAnnotationProcessorsEnabled()) { + return true; + } final Module module = context.getModuleByFile(file); if (module != null) { - if (!context.isAnnotationProcessorsEnabled()) { + if (!myConfig.isAnnotationProcessingEnabled(module)) { return true; } final String path = CompilerPaths.getAnnotationProcessorsGenerationPath(module); @@ -141,7 +144,7 @@ public class AnnotationProcessingCompiler implements TranslatingCompiler{ } private JavacCompiler getBackEndCompiler() { - CompilerConfigurationImpl configuration = (CompilerConfigurationImpl)CompilerConfiguration.getInstance(myProject); + CompilerConfigurationImpl configuration = (CompilerConfigurationImpl)myConfig; return configuration.getJavacCompiler(); } From 03308f250763a1f9d3226822250c0847bfa430bb Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Tue, 10 May 2011 10:47:58 +0400 Subject: [PATCH 031/250] one context per one generation --- .../convertToJava/ClassItemGeneratorImpl.java | 30 ++++++++++--------- .../convertToJava/ClosureGenerator.java | 2 +- .../convertToJava/ExpressionGenerator.java | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java index 251d69647ef5..0b555ff7b3a4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java @@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.impl.light.LightMethodBuilder; import com.intellij.util.ArrayUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.codeInspection.noReturnMethod.MissingReturnInspection; import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; @@ -35,7 +36,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumConstantInitializer; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.*; -import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureSignature; import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass; import org.jetbrains.plugins.groovy.lang.psi.impl.types.GrClosureSignatureUtil; @@ -52,13 +52,17 @@ import static org.jetbrains.plugins.groovy.refactoring.convertToJava.GenerationU * @author Maxim.Medvedev */ public class ClassItemGeneratorImpl implements ClassItemGenerator { - private Project myProject; private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.refactoring.convertToJava.ClassItemGeneratorImpl"); private ClassNameProvider classNameProvider; + private ExpressionContext context; public ClassItemGeneratorImpl(Project project) { - myProject = project; + this(new ExpressionContext(project)); + } + + public ClassItemGeneratorImpl(@NotNull ExpressionContext context) { classNameProvider = new GeneratorClassNameProvider(); + this.context = context; } @Override @@ -66,11 +70,10 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { builder.append(constant.getName()); final GrArgumentList argumentList = constant.getArgumentList(); - final ExpressionContext context = new ExpressionContext(myProject); if (argumentList != null) { final GroovyResolveResult resolveResult = constant.resolveConstructorGenerics(); GrClosureSignature signature = GrClosureSignatureUtil.createSignature(resolveResult); - new ArgumentListGenerator(builder, context).generate( + new ArgumentListGenerator(builder, context.extend()).generate( signature, argumentList.getExpressionArguments(), argumentList.getNamedArguments(), @@ -82,7 +85,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { final GrEnumConstantInitializer anonymousBlock = constant.getConstantInitializer(); if (anonymousBlock != null) { builder.append("{\n"); - new ClassGenerator(myProject, classNameProvider, this).writeMembers(builder, anonymousBlock, true); + new ClassGenerator(context.project, classNameProvider, this).writeMembers(builder, anonymousBlock, true); builder.append("\n}"); } @@ -157,7 +160,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { builder.append("default "); GrAnnotationMemberValue defaultValue = defaultAnnotationValue.getDefaultValue(); if (defaultValue != null) { - defaultValue.accept(new AnnotationGenerator(builder, myProject)); + defaultValue.accept(new AnnotationGenerator(builder, context.project)); } } } @@ -169,7 +172,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { /************* body **********/ if (method instanceof GrMethod) { if (skipOptional == 0) { - new CodeBlockGenerator(builder, myProject).generateMethodBody((GrMethod)method); + new CodeBlockGenerator(builder, context.extend()).generateMethodBody((GrMethod)method); } else { builder.append("{\n").append(generateDelegateCall((GrMethod)method, actualParams)).append("\n}\n"); @@ -222,7 +225,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { } builder.delete(builder.length() - 2, builder.length()); builder.append(")"); - final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myProject); + final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(context.project); final GrStatement delegateCall; PsiElement context = method.getContainingClass() == null ? method : method.getContainingClass(); @@ -234,7 +237,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { } final StringBuilder result = new StringBuilder(); - delegateCall.accept(new CodeBlockGenerator(result, myProject)); + delegateCall.accept(new CodeBlockGenerator(result, this.context.extend())); return result; } @@ -256,7 +259,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { LOG.assertTrue(((GroovyFile)scriptFile).isScript()); final List exitPoints = ControlFlowUtils.collectReturns(scriptFile); - new CodeBlockGenerator(builder, new ExpressionContext(myProject), exitPoints) + new CodeBlockGenerator(builder, context.extend(), exitPoints) .visitStatementOwner((GroovyFile)scriptFile, MissingReturnInspection.methodMissesSomeReturns((GroovyFile)scriptFile, true)); builder.append("\n}\n"); } @@ -296,8 +299,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { @Override public void writeVariableDeclarations(StringBuilder builder, GrVariableDeclaration variableDeclaration) { - final ExpressionContext context = new ExpressionContext(myProject); - GenerationUtil.writeSimpleVarDeclaration(variableDeclaration, builder, context); + GenerationUtil.writeSimpleVarDeclaration(variableDeclaration, builder, context.extend()); builder.append('\n'); } @@ -306,7 +308,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { List result = new ArrayList(Arrays.asList(typeDefinition.getMethods())); if (typeDefinition instanceof GroovyScriptClass) { - final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myProject); + final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(context.project); final String name = typeDefinition.getName(); result.add(factory.createConstructorFromText(name, new String[]{"groovy.lang.Binding"}, new String[]{"binding"}, "{super(binding);}", typeDefinition)); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClosureGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClosureGenerator.java index de9596d5f593..b907396b9c07 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClosureGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClosureGenerator.java @@ -53,7 +53,7 @@ public class ClosureGenerator { builder.append(owner).append(", ").append(owner).append(") {\n"); final GrMethod method = generateClosureMethod(closure); - ClassGenerator.writeAllSignaturesOfMethod(builder, method, new ClassItemGeneratorImpl(context.project)); + ClassGenerator.writeAllSignaturesOfMethod(builder, method, new ClassItemGeneratorImpl(context)); builder.append("}"); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java index 1e216be5384a..f899911397a4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java @@ -284,7 +284,7 @@ public class ExpressionGenerator extends Generator { private void writeTypeBody(StringBuilder builder, GrAnonymousClassDefinition anonymous) { builder.append("{\n"); - new ClassGenerator(context.project, new GeneratorClassNameProvider(), new ClassItemGeneratorImpl(context.project)) + new ClassGenerator(context.project, new GeneratorClassNameProvider(), new ClassItemGeneratorImpl(context.extend())) .writeMembers(builder, anonymous, true); builder.append('}'); } From 98c6bd231a6d662fb9058319834cb3d95df578c9 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 10 May 2011 08:59:14 +0200 Subject: [PATCH 032/250] add annotate binary flag --- .../command/annotate/AnnotateCommand.java | 186 ++++++++++-------- 1 file changed, 100 insertions(+), 86 deletions(-) diff --git a/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/command/annotate/AnnotateCommand.java b/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/command/annotate/AnnotateCommand.java index bb08c912e0a9..ab353704b898 100644 --- a/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/command/annotate/AnnotateCommand.java +++ b/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/command/annotate/AnnotateCommand.java @@ -37,108 +37,122 @@ import java.io.IOException; */ public final class AnnotateCommand extends AbstractCommand { - // Fields ================================================================= + // Fields ================================================================= - private boolean useHeadIfNotFound; - private String date; - private String revisionOrTag; + private boolean useHeadIfNotFound; + private String date; + private String revisionOrTag; + private boolean annotateBinary; - // Setup ================================================================== + // Setup ================================================================== - public AnnotateCommand() { - } + public AnnotateCommand() { + } - // Implemented ============================================================ + // Implemented ============================================================ - public boolean execute(IRequestProcessor requestProcessor, IEventSender eventManager, ICvsListenerRegistry listenerRegistry, IClientEnvironment clientEnvironment, IProgressViewer progressViewer) throws CommandException, - AuthenticationException { - final ICvsFiles cvsFiles; - try { - cvsFiles = scanFileSystem(getFileObjects(), clientEnvironment); - } - catch (IOException ex) { - throw new IOCommandException(ex); - } + public boolean execute(IRequestProcessor requestProcessor, IEventSender eventManager, ICvsListenerRegistry listenerRegistry, IClientEnvironment clientEnvironment, IProgressViewer progressViewer) throws CommandException, + AuthenticationException { + final ICvsFiles cvsFiles; + try { + cvsFiles = scanFileSystem(getFileObjects(), clientEnvironment); + } + catch (IOException ex) { + throw new IOCommandException(ex); + } - final Requests requests = new Requests(CommandRequest.ANNOTATE, clientEnvironment); - requests.addArgumentRequest(isUseHeadIfNotFound(), "-f"); - requests.addArgumentRequest(getDate(), "-D"); - requests.addArgumentRequest(getRevisionOrTag(), "-r"); - addFileRequests(cvsFiles, requests, clientEnvironment); - requests.addLocalPathDirectoryRequest(); - addArgumentRequests(requests); + final Requests requests = new Requests(CommandRequest.ANNOTATE, clientEnvironment); + requests.addArgumentRequest(isUseHeadIfNotFound(), "-f"); + requests.addArgumentRequest(getDate(), "-D"); + requests.addArgumentRequest(getRevisionOrTag(), "-r"); + requests.addArgumentRequest(isAnnotateBinary(), "-F"); + addFileRequests(cvsFiles, requests, clientEnvironment); + requests.addLocalPathDirectoryRequest(); + addArgumentRequests(requests); - final ICvsListener parser = new AnnotateMessageParser(eventManager, clientEnvironment.getCvsFileSystem()); - parser.registerListeners(listenerRegistry); - try { - return requestProcessor.processRequests(requests, FileStateRequestsProgressHandler.create(progressViewer, cvsFiles)); - } - finally { - parser.unregisterListeners(listenerRegistry); - } - } + final ICvsListener parser = new AnnotateMessageParser(eventManager, clientEnvironment.getCvsFileSystem()); + parser.registerListeners(listenerRegistry); + try { + return requestProcessor.processRequests(requests, FileStateRequestsProgressHandler.create(progressViewer, cvsFiles)); + } + finally { + parser.unregisterListeners(listenerRegistry); + } + } - public void resetCvsCommand() { - super.resetCvsCommand(); - setRecursive(true); - setDate(null); - setAnnotateByRevisionOrTag(null); - setUseHeadIfNotFound(false); - } + public void resetCvsCommand() { + super.resetCvsCommand(); + setRecursive(true); + setDate(null); + setAnnotateByRevisionOrTag(null); + setUseHeadIfNotFound(false); + setAnnotateBinary(false); + } - public String getCvsCommandLine() { - @NonNls final StringBuffer cvsCommandLine = new StringBuffer("annotate "); - cvsCommandLine.append(getCvsArguments()); - appendFileArguments(cvsCommandLine); - return cvsCommandLine.toString(); - } + public String getCvsCommandLine() { + @NonNls final StringBuffer cvsCommandLine = new StringBuffer("annotate "); + cvsCommandLine.append(getCvsArguments()); + appendFileArguments(cvsCommandLine); + return cvsCommandLine.toString(); + } - // Accessing ============================================================== + // Accessing ============================================================== - private String getDate() { - return date; - } + private String getDate() { + return date; + } - public void setDate(String date) { - this.date = date; - } + public void setDate(String date) { + this.date = date; + } - private String getRevisionOrTag() { - return revisionOrTag; - } + private String getRevisionOrTag() { + return revisionOrTag; + } - public void setAnnotateByRevisionOrTag(String annotateByRevision) { - this.revisionOrTag = annotateByRevision; - } + public void setAnnotateByRevisionOrTag(String annotateByRevision) { + this.revisionOrTag = annotateByRevision; + } - private boolean isUseHeadIfNotFound() { - return useHeadIfNotFound; - } + private boolean isUseHeadIfNotFound() { + return useHeadIfNotFound; + } - private void setUseHeadIfNotFound(boolean useHeadIfNotFound) { - this.useHeadIfNotFound = useHeadIfNotFound; - } + private void setUseHeadIfNotFound(boolean useHeadIfNotFound) { + this.useHeadIfNotFound = useHeadIfNotFound; + } - // Utils ================================================================== + private boolean isAnnotateBinary() { + return annotateBinary; + } - private String getCvsArguments() { - @NonNls final StringBuffer cvsArguments = new StringBuffer(""); - if (!isRecursive()) { - cvsArguments.append("-l "); - } - if (getRevisionOrTag() != null) { - cvsArguments.append("-r "); - cvsArguments.append(getRevisionOrTag()); - cvsArguments.append(" "); - } - if (getDate() != null) { - cvsArguments.append("-D "); - cvsArguments.append(getDate()); - cvsArguments.append(" "); - } - if (isUseHeadIfNotFound()) { - cvsArguments.append("-f "); - } - return cvsArguments.toString(); - } + public void setAnnotateBinary(boolean annotateBinary) { + this.annotateBinary = annotateBinary; + } + + // Utils ================================================================== + + private String getCvsArguments() { + @NonNls final StringBuilder cvsArguments = new StringBuilder(""); + if (!isRecursive()) { + cvsArguments.append("-l "); + } + if (getRevisionOrTag() != null) { + cvsArguments.append("-r "); + cvsArguments.append(getRevisionOrTag()); + cvsArguments.append(" "); + } + if (getDate() != null) { + cvsArguments.append("-D "); + cvsArguments.append(getDate()); + cvsArguments.append(" "); + } + if (isUseHeadIfNotFound()) { + cvsArguments.append("-f "); + } + if (isAnnotateBinary()) { + cvsArguments.append("-F"); + } + return cvsArguments.toString(); + } } From da3d2695b5b3e48c125970511438bfc1fa65d0c2 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Tue, 10 May 2011 11:04:26 +0400 Subject: [PATCH 033/250] EA-27528 - : DocumentWrapper.getLine Commented test for the disabled functionality --- .../com/intellij/openapi/editor/impl/CharArrayTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/testSrc/com/intellij/openapi/editor/impl/CharArrayTest.java b/platform/platform-impl/testSrc/com/intellij/openapi/editor/impl/CharArrayTest.java index 84fe8a9eb3cc..ff49fe9d7a01 100644 --- a/platform/platform-impl/testSrc/com/intellij/openapi/editor/impl/CharArrayTest.java +++ b/platform/platform-impl/testSrc/com/intellij/openapi/editor/impl/CharArrayTest.java @@ -88,8 +88,14 @@ public class CharArrayTest { myMockery.assertIsSatisfied(); } - @Config(text = "1234", deferred = true) @Test + public void dummy() { + // We want to un-comment the other test(s) as soon as the problem with deferred processing is solved + } + + @Config(text = "1234", deferred = true) + //TODO den uncomment + //@Test public void deferredReplace() { replace(1, 3, "abc"); checkText("1abc4"); From f26342666c895742d342271848c207e0ea40f918 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 10 May 2011 09:05:04 +0200 Subject: [PATCH 034/250] simple tracking of roots/servers which do not support annotate binary --- .../cvsAnnotate/AnnotateOperation.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAnnotate/AnnotateOperation.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAnnotate/AnnotateOperation.java index 5e55fdff699c..bcae101c8c8a 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAnnotate/AnnotateOperation.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAnnotate/AnnotateOperation.java @@ -29,6 +29,8 @@ import org.netbeans.lib.cvsclient.command.annotate.AnnotateCommand; import java.io.File; import java.text.ParseException; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.List; /** @@ -38,6 +40,8 @@ public class AnnotateOperation extends LocalPathIndifferentOperation { private static final Logger LOG = Logger.getInstance("#com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.AnnotateOperation"); + private static final Collection ourDoNotSupportingAnnotateBinaryRoots = new HashSet(); + private final String myRevision; private final List myAnnotations = new ArrayList(); private final StringBuffer myBuffer = new StringBuffer(); @@ -67,9 +71,18 @@ public class AnnotateOperation extends LocalPathIndifferentOperation { AnnotateCommand result = new AnnotateCommand(); myHelper.addFilesTo(result); result.setAnnotateByRevisionOrTag(myRevision); + + if (!ourDoNotSupportingAnnotateBinaryRoots.contains(root.getCvsRootAsString())) { + result.setAnnotateBinary(true); + } + return result; } + public static void doesNotSupportAnnotateBinary(CvsEnvironment root) { + ourDoNotSupportingAnnotateBinaryRoots.add(root.getCvsRootAsString()); + } + public Annotation[] getLineAnnotations(){ return myAnnotations.toArray(new Annotation[myAnnotations.size()]); } From ce9ba0c6021c245f874f3eace2b47eca0c86d1dd Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 10 May 2011 09:09:57 +0200 Subject: [PATCH 035/250] collect all annotation handling code in a single place --- .../src/com/intellij/cvsSupport2/CvsVcs2.java | 117 +---------------- .../annotate/CvsAnnotationProvider.java | 120 +++++++++++++++++- 2 files changed, 116 insertions(+), 121 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java index 89de8f83eb02..4d142917c269 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -19,7 +19,6 @@ package com.intellij.cvsSupport2; import com.intellij.CvsBundle; import com.intellij.cvsSupport2.actions.merge.CvsMergeProvider; import com.intellij.cvsSupport2.annotate.CvsAnnotationProvider; -import com.intellij.cvsSupport2.annotate.CvsFileAnnotation; import com.intellij.cvsSupport2.application.CvsEntriesManager; import com.intellij.cvsSupport2.application.CvsStorageComponent; import com.intellij.cvsSupport2.changeBrowser.CvsCommittedChangesProvider; @@ -34,8 +33,6 @@ import com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler; import com.intellij.cvsSupport2.cvshandlers.CvsHandler; import com.intellij.cvsSupport2.cvsoperations.common.CvsOperation; import com.intellij.cvsSupport2.cvsoperations.common.FindAllRootsHelper; -import com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.AnnotateOperation; -import com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.Annotation; import com.intellij.cvsSupport2.cvsoperations.cvsEdit.ui.EditOptionsDialog; import com.intellij.cvsSupport2.cvsstatuses.CvsChangeProvider; import com.intellij.cvsSupport2.cvsstatuses.CvsEntriesListener; @@ -46,7 +43,6 @@ import com.intellij.openapi.cvsIntegration.CvsResult; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.*; -import com.intellij.openapi.vcs.actions.VcsContextFactory; import com.intellij.openapi.vcs.annotate.AnnotationProvider; import com.intellij.openapi.vcs.annotate.FileAnnotation; import com.intellij.openapi.vcs.changes.ChangeProvider; @@ -54,7 +50,6 @@ import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; import com.intellij.openapi.vcs.checkin.CheckinEnvironment; import com.intellij.openapi.vcs.diff.DiffProvider; import com.intellij.openapi.vcs.diff.RevisionSelector; -import com.intellij.openapi.vcs.history.VcsFileRevision; import com.intellij.openapi.vcs.history.VcsHistoryProvider; import com.intellij.openapi.vcs.history.VcsRevisionNumber; import com.intellij.openapi.vcs.merge.MergeProvider; @@ -65,9 +60,7 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.File; -import java.io.IOException; -import java.util.*; +import java.util.List; /** * This class intended to be an adapter of AbstractVcs and ProjectComponent interfaces for CVS @@ -161,17 +154,8 @@ public class CvsVcs2 extends AbstractVcs implements TransactionProvider, EditFil myCvsStandardOperationsProvider.rollback(); } - - public byte[] getFileContent(String path) throws VcsException { - return myCvsStandardOperationsProvider.getFileContent(path); - } - - public CvsStandardOperationsProvider getStandardOperationsProvider() { - return myCvsStandardOperationsProvider; - } /* =========================================================*/ - public static CvsVcs2 getInstance(Project project) { return (CvsVcs2) ProjectLevelVcsManager.getInstance(project).findVcsByName(NAME); } @@ -309,103 +293,8 @@ public class CvsVcs2 extends AbstractVcs implements TransactionProvider, EditFil return myCvsAnnotationProvider; } - private static class RevisionPresentation implements VcsFileRevision { - private final VcsRevisionNumber myNumber; - private final String myAuthor; - private final Date myDate; - - private RevisionPresentation(final String revision, final String author, final Date date) { - myNumber = new CvsRevisionNumber(revision); - myAuthor = author; - myDate = date; - } - - public VcsRevisionNumber getRevisionNumber() { - return myNumber; - } - - public String getBranchName() { - return null; - } - - public Date getRevisionDate() { - return myDate; - } - - public String getAuthor() { - return myAuthor; - } - - public String getCommitMessage() { - return null; - } - - public void loadContent() throws VcsException { - } - - public byte[] getContent() throws IOException { - return new byte[0]; - } - } - public FileAnnotation createAnnotation(VirtualFile cvsVirtualFile, String revision, CvsEnvironment environment) throws VcsException { - // the VirtualFile has a full path if annotate is called from history (when we have a real file on disk), - // and has the path equal to a CVS module name if annotate is called from the CVS repository browser - // (when there's no real path) - boolean hasLocalFile = false; - File cvsFile = new File(cvsVirtualFile.getPath()); - if (cvsFile.isAbsolute()) { - hasLocalFile = true; - cvsFile = new File(CvsUtil.getModuleName(cvsVirtualFile)); - } - final AnnotateOperation annotateOperation = new AnnotateOperation(cvsFile, revision, environment); - CvsOperationExecutor executor = new CvsOperationExecutor(myProject); - executor.performActionSync(new CommandCvsHandler(CvsBundle.getAnnotateOperationName(), annotateOperation), - CvsOperationExecutorCallback.EMPTY); - - if (executor.getResult().hasNoErrors()) { - final List revisions; - final Annotation[] lineAnnotations = annotateOperation.getLineAnnotations(); - if (hasLocalFile) { - final CvsHistoryProvider historyProvider = (CvsHistoryProvider)getVcsHistoryProvider(); - final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(cvsVirtualFile); - revisions = historyProvider.createRevisions(filePath); - // in annotation cvs returns only 8 symbols of username - // try to find usernames in history and use them - adjustAnnotation(revisions, lineAnnotations); - } - else { - // imitation - revisions = new ArrayList(); - final Set usedRevisions = new HashSet(); - for (Annotation annotation : lineAnnotations) { - if (! usedRevisions.contains(annotation.getRevision())) { - revisions.add(new RevisionPresentation(annotation.getRevision(), annotation.getUserName(), annotation.getDate())); - usedRevisions.add(annotation.getRevision()); - } - } - } - return new CvsFileAnnotation(annotateOperation.getContent(), lineAnnotations, revisions, cvsVirtualFile); - } - else { - throw executor.getResult().composeError(); - } - - } - - public static void adjustAnnotation(@Nullable List revisions, @NotNull Annotation[] lineAnnotations) { - if (revisions != null) { - final Map usersMap = new HashMap(); - for (VcsFileRevision vcsFileRevision : revisions) { - usersMap.put(vcsFileRevision.getRevisionNumber(), vcsFileRevision.getAuthor()); - } - for (Annotation lineAnnotation : lineAnnotations) { - final String name = usersMap.get(new CvsRevisionNumber(lineAnnotation.getRevision())); - if (name != null) { - lineAnnotation.setUser(name); - } - } - } + return myCvsAnnotationProvider.annotate(cvsVirtualFile, revision, environment); } public DiffProvider getDiffProvider() { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/annotate/CvsAnnotationProvider.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/annotate/CvsAnnotationProvider.java index 75e85771b4d0..0fae1e6c00ba 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/annotate/CvsAnnotationProvider.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/annotate/CvsAnnotationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -16,16 +16,18 @@ package com.intellij.cvsSupport2.annotate; import com.intellij.CvsBundle; +import com.intellij.cvsSupport2.CvsUtil; import com.intellij.cvsSupport2.CvsVcs2; import com.intellij.cvsSupport2.application.CvsEntriesManager; import com.intellij.cvsSupport2.connections.CvsConnectionSettings; +import com.intellij.cvsSupport2.connections.CvsEnvironment; import com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutor; import com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutorCallback; import com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler; import com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.AnnotateOperation; import com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.Annotation; import com.intellij.cvsSupport2.history.CvsHistoryProvider; -import com.intellij.openapi.application.ModalityState; +import com.intellij.cvsSupport2.history.CvsRevisionNumber; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.VcsException; @@ -33,10 +35,13 @@ import com.intellij.openapi.vcs.actions.VcsContextFactory; import com.intellij.openapi.vcs.annotate.AnnotationProvider; import com.intellij.openapi.vcs.annotate.FileAnnotation; import com.intellij.openapi.vcs.history.VcsFileRevision; +import com.intellij.openapi.vcs.history.VcsRevisionNumber; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; -import java.util.List; +import java.util.*; public class CvsAnnotationProvider implements AnnotationProvider{ private final Project myProject; @@ -47,7 +52,7 @@ public class CvsAnnotationProvider implements AnnotationProvider{ public FileAnnotation annotate(VirtualFile file) throws VcsException { final AnnotateOperation operation = AnnotateOperation.createForFile(new File(file.getPath())); - final CvsOperationExecutor executor = new CvsOperationExecutor(true, myProject, ModalityState.defaultModalityState()); + final CvsOperationExecutor executor = new CvsOperationExecutor(myProject); executor.performActionSync(new CommandCvsHandler(CvsBundle.getAnnotateOperationName(), operation), CvsOperationExecutorCallback.EMPTY); if (executor.getResult().hasNoErrors()) { @@ -56,7 +61,7 @@ public class CvsAnnotationProvider implements AnnotationProvider{ final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file); final List revisions = historyProvider.createRevisions(filePath); final Annotation[] lineAnnotations = operation.getLineAnnotations(); - CvsVcs2.adjustAnnotation(revisions, lineAnnotations); + adjustAnnotation(revisions, lineAnnotations); return new CvsFileAnnotation(operation.getContent(), lineAnnotations, revisions, file); } else { throw executor.getFirstError(); @@ -65,10 +70,111 @@ public class CvsAnnotationProvider implements AnnotationProvider{ public FileAnnotation annotate(VirtualFile file, VcsFileRevision revision) throws VcsException { final CvsConnectionSettings settings = CvsEntriesManager.getInstance().getCvsConnectionSettingsFor(file.getParent()); - return CvsVcs2.getInstance(myProject).createAnnotation(file, revision.getRevisionNumber().asString(), settings); + return annotate(file, revision.getRevisionNumber().asString(), settings); } - public boolean isAnnotationValid( VcsFileRevision rev ){ + public boolean isAnnotationValid(VcsFileRevision rev){ return true; } + + public FileAnnotation annotate(VirtualFile cvsVirtualFile, String revision, CvsEnvironment environment) throws VcsException { + // the VirtualFile has a full path if annotate is called from history (when we have a real file on disk), + // and has the path equal to a CVS module name if annotate is called from the CVS repository browser + // (when there's no real path) + boolean hasLocalFile = false; + File cvsFile = new File(cvsVirtualFile.getPath()); + if (cvsFile.isAbsolute()) { + hasLocalFile = true; + cvsFile = new File(CvsUtil.getModuleName(cvsVirtualFile)); + } + final AnnotateOperation annotateOperation = new AnnotateOperation(cvsFile, revision, environment); + CvsOperationExecutor executor = new CvsOperationExecutor(myProject); + executor.performActionSync(new CommandCvsHandler(CvsBundle.getAnnotateOperationName(), annotateOperation), + CvsOperationExecutorCallback.EMPTY); + + if (executor.getResult().hasNoErrors()) { + final List revisions; + final Annotation[] lineAnnotations = annotateOperation.getLineAnnotations(); + if (hasLocalFile) { + final CvsVcs2 cvsVcs2 = CvsVcs2.getInstance(myProject); + final CvsHistoryProvider historyProvider = (CvsHistoryProvider) cvsVcs2.getVcsHistoryProvider(); + final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(cvsVirtualFile); + revisions = historyProvider.createRevisions(filePath); + // in annotation cvs returns only 8 symbols of username + // try to find usernames in history and use them + adjustAnnotation(revisions, lineAnnotations); + } + else { + // imitation + revisions = new ArrayList(); + final Set usedRevisions = new HashSet(); + for (Annotation annotation : lineAnnotations) { + if (! usedRevisions.contains(annotation.getRevision())) { + revisions.add(new RevisionPresentation(annotation.getRevision(), annotation.getUserName(), annotation.getDate())); + usedRevisions.add(annotation.getRevision()); + } + } + } + return new CvsFileAnnotation(annotateOperation.getContent(), lineAnnotations, revisions, cvsVirtualFile); + } + else { + throw executor.getResult().composeError(); + } + + } + + private static void adjustAnnotation(@Nullable List revisions, @NotNull Annotation[] lineAnnotations) { + if (revisions != null) { + final Map usersMap = new HashMap(); + for (VcsFileRevision vcsFileRevision : revisions) { + usersMap.put(vcsFileRevision.getRevisionNumber(), vcsFileRevision.getAuthor()); + } + for (Annotation lineAnnotation : lineAnnotations) { + final String name = usersMap.get(new CvsRevisionNumber(lineAnnotation.getRevision())); + if (name != null) { + lineAnnotation.setUser(name); + } + } + } + } + + private static class RevisionPresentation implements VcsFileRevision { + private final VcsRevisionNumber myNumber; + private final String myAuthor; + private final Date myDate; + + private RevisionPresentation(final String revision, final String author, final Date date) { + myNumber = new CvsRevisionNumber(revision); + myAuthor = author; + myDate = date; + } + + public VcsRevisionNumber getRevisionNumber() { + return myNumber; + } + + public String getBranchName() { + return null; + } + + public Date getRevisionDate() { + return myDate; + } + + public String getAuthor() { + return myAuthor; + } + + public String getCommitMessage() { + return null; + } + + public void loadContent() throws VcsException { + } + + public byte[] getContent() { + return new byte[0]; + } + } + } From 436ae7f546190014e08f2b1013672bb6f7cc40d1 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Tue, 10 May 2011 11:55:38 +0400 Subject: [PATCH 036/250] tooltip are not shown for combobox actions in the pressed state --- .../com/intellij/openapi/actionSystem/ex/ComboBoxAction.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java index d57ff6899e8d..2e43be3fccc6 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java @@ -120,6 +120,11 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent popup.showUnderneathOf(this); } + @Override + public String getToolTipText() { + return myForcePressed ? null : super.getToolTipText(); + } + protected ListPopup createPopup(Runnable onDispose) { DefaultActionGroup group = createPopupActionGroup(this); From 4c53e4059d3365afea5770aa8facc273baa0bc92 Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Tue, 10 May 2011 11:59:36 +0400 Subject: [PATCH 037/250] fix compile --- .../cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java index 4d142917c269..cf716ea728d3 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java @@ -153,6 +153,14 @@ public class CvsVcs2 extends AbstractVcs implements TransactionProvider, EditFil public void rollbackTransaction(Object parameters) { myCvsStandardOperationsProvider.rollback(); } + + public byte[] getFileContent(String path) throws VcsException { + return myCvsStandardOperationsProvider.getFileContent(path); + } + + public CvsStandardOperationsProvider getStandardOperationsProvider() { + return myCvsStandardOperationsProvider; + } /* =========================================================*/ From bb47bc34fa323f063f1e21b8542ff0889aa2e2ad Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Tue, 10 May 2011 12:07:20 +0400 Subject: [PATCH 038/250] [mac] do not show version in frame title for snapshot builds --- .../src/com/intellij/openapi/wm/impl/IdeFrameImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java index 6ca45152cbe9..eacd43b86de8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java @@ -249,7 +249,7 @@ public class IdeFrameImpl extends JFrame implements IdeFrame, DataProvider { if (SystemInfo.isMac) { builder.append(fileTitle).append(title) .append(ProjectManager.getInstance().getOpenProjects().length == 0 - || ((ApplicationInfoEx)ApplicationInfo.getInstance()).isEAP() ? applicationName : null); + || ((ApplicationInfoEx)ApplicationInfo.getInstance()).isEAP() && !applicationName.endsWith("SNAPSHOT") ? applicationName : null); } else { builder.append(title).append(fileTitle).append(applicationName); } From 38da2bb6cefcc98982cae2edbfc60f5a72d3a0fb Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 10:16:50 +0200 Subject: [PATCH 039/250] more realistic groovydoc enter tests --- .../groovy/enterAction/buildGdocPrecededByGNewLine.test | 4 ++-- plugins/groovy/testdata/groovy/enterAction/gdoc10.test | 4 ++-- plugins/groovy/testdata/groovy/enterAction/gdoc6.test | 2 ++ plugins/groovy/testdata/groovy/enterAction/gdoc7.test | 2 ++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/groovy/testdata/groovy/enterAction/buildGdocPrecededByGNewLine.test b/plugins/groovy/testdata/groovy/enterAction/buildGdocPrecededByGNewLine.test index a12d07940c73..343b15a98413 100644 --- a/plugins/groovy/testdata/groovy/enterAction/buildGdocPrecededByGNewLine.test +++ b/plugins/groovy/testdata/groovy/enterAction/buildGdocPrecededByGNewLine.test @@ -2,7 +2,7 @@ def foo() {} /** -def bar(aaa, bbb) {} +def bar(aaa, bbb) { 2 } ----- def foo() {} @@ -12,4 +12,4 @@ def foo() {} * @param bbb * @return */ -def bar(aaa, bbb) {} \ No newline at end of file +def bar(aaa, bbb) { 2 } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/enterAction/gdoc10.test b/plugins/groovy/testdata/groovy/enterAction/gdoc10.test index e23d901a79ea..986cecf24998 100644 --- a/plugins/groovy/testdata/groovy/enterAction/gdoc10.test +++ b/plugins/groovy/testdata/groovy/enterAction/gdoc10.test @@ -1,5 +1,5 @@ /** -def foo(int x, int y){} +def foo(int x, int y){2} ----- /** * @@ -8,4 +8,4 @@ def foo(int x, int y){} * @return */ -def foo(int x, int y){} \ No newline at end of file +def foo(int x, int y){2} \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/enterAction/gdoc6.test b/plugins/groovy/testdata/groovy/enterAction/gdoc6.test index 75f346cccd93..e73ddfc46b10 100644 --- a/plugins/groovy/testdata/groovy/enterAction/gdoc6.test +++ b/plugins/groovy/testdata/groovy/enterAction/gdoc6.test @@ -1,4 +1,5 @@ /**def foo() { + 2 } ----- /** @@ -6,4 +7,5 @@ * @return */ def foo() { + 2 } \ No newline at end of file diff --git a/plugins/groovy/testdata/groovy/enterAction/gdoc7.test b/plugins/groovy/testdata/groovy/enterAction/gdoc7.test index 93d1901b8040..706ea170ded5 100644 --- a/plugins/groovy/testdata/groovy/enterAction/gdoc7.test +++ b/plugins/groovy/testdata/groovy/enterAction/gdoc7.test @@ -1,5 +1,6 @@ /** def foo() { + 2 } ----- /** @@ -8,4 +9,5 @@ def foo() { */ def foo() { + 2 } \ No newline at end of file From 3b5872c1a0ff59dc8e326436fb29280a7d253fd3 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 10:17:39 +0200 Subject: [PATCH 040/250] don't infer groovy method return types if they're written and unless you have to (e.g. tuples) --- .../typedef/members/GrMethodBaseImpl.java | 103 ++++++++++-------- .../convertGroovyToJava/file/return2.java | 2 +- .../convertGroovyToJava/file/returns.java | 2 +- 3 files changed, 60 insertions(+), 47 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java index 0be57b0b12b1..82c63baecb80 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java @@ -28,7 +28,6 @@ import com.intellij.psi.search.SearchScope; import com.intellij.psi.stubs.IStubElementType; import com.intellij.psi.util.MethodSignature; import com.intellij.psi.util.MethodSignatureBackedByPsiMethod; -import com.intellij.psi.util.TypeConversionUtil; import com.intellij.ui.RowIcon; import com.intellij.util.*; import org.jetbrains.annotations.NonNls; @@ -50,6 +49,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnnotationTypeDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; @@ -128,6 +128,10 @@ public abstract class GrMethodBaseImpl extends GrStubElementBase i } public PsiType getInferredReturnType() { + if (isConstructor()) { + return null; + } + if (!ApplicationManager.getApplication().isUnitTestMode()) { //todo uncomment when EAP is on //LOG.assertTrue(!ApplicationManager.getApplication().isDispatchThread()); //this is a potentially long action @@ -156,60 +160,61 @@ public abstract class GrMethodBaseImpl extends GrStubElementBase i return new GrMember[]{this}; } - private static final Function ourTypesCalculator = new NullableFunction() { - public PsiType fun(GrMethod method) { - PsiType nominal = method.getReturnType(); - if (nominal != null && nominal.equals(PsiType.VOID)) return nominal; + private static final Function ourTypesCalculator = new NullableFunction() { + private boolean hasTypeParametersToInfer(PsiClassType classType) { + final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics(); + PsiClass aClass = resolveResult.getElement(); + if (aClass == null) return false; - if (GppTypeConverter.hasTypedContext(method)) { - if (nominal != null) return nominal; - - return PsiType.getJavaLangObject(method.getManager(), method.getResolveScope()); + final Iterable iterable = com.intellij.psi.util.PsiUtil.typeParametersIterable(aClass); + if (!iterable.iterator().hasNext()) { + return false; } - PsiType inferred = getInferredType(method); - if (nominal == null) { - if (inferred == null) { - return PsiType.getJavaLangObject(method.getManager(), method.getResolveScope()); + for (PsiTypeParameter parameter : iterable) { + PsiType type = resolveResult.getSubstitutor().substitute(parameter); + if (type != null) { + if (!(type instanceof PsiWildcardType) || ((PsiWildcardType)type).getBound() != null) { + return false; + } } - return inferred; } - if (inferred != null && inferred != PsiType.NULL) { - if (inferred instanceof PsiClassType && nominal instanceof PsiClassType) { - final PsiClassType.ClassResolveResult declaredResult = ((PsiClassType)nominal).resolveGenerics(); - final PsiClass declaredClass = declaredResult.getElement(); - if (declaredClass != null) { - final PsiClassType.ClassResolveResult initializerResult = ((PsiClassType)inferred).resolveGenerics(); - final PsiClass initializerClass = initializerResult.getElement(); - if (initializerClass != null && - com.intellij.psi.util.PsiUtil.isRawSubstitutor(initializerClass, initializerResult.getSubstitutor())) { - if (declaredClass == initializerClass) return nominal; - final PsiSubstitutor declaredResultSubstitutor = declaredResult.getSubstitutor(); - final PsiSubstitutor superSubstitutor = - TypeConversionUtil.getClassSubstitutor(declaredClass, initializerClass, declaredResultSubstitutor); + return true; + } - if (superSubstitutor != null) { - return JavaPsiFacade.getInstance(method.getProject()).getElementFactory() - .createType(declaredClass, TypesUtil.composeSubstitutors(declaredResultSubstitutor, superSubstitutor)); - } + public PsiType fun(GrMethodBaseImpl method) { + PsiType nominal = method.getNominalType(); + if (nominal != null) { + if (!(nominal instanceof PsiClassType) || !hasTypeParametersToInfer((PsiClassType)nominal)) { + if (!(method.getContainingClass() instanceof GrAnnotationTypeDefinition)) { + nominal = TypesUtil.boxPrimitiveType(nominal, method.getManager(), method.getResolveScope()); //for converter + } + return nominal; + } + } + + if (!GppTypeConverter.hasTypedContext(method)) { + assert method.isValid() : "invalid method"; + + final GrOpenBlock block = method.getBlock(); + if (block != null) { + assert block.isValid() : "invalid code block"; + PsiType inferred = GroovyPsiManager.inferType(method, new MethodTypeInferencer(block)); + if (inferred != null) { + if (nominal == null && inferred != PsiType.VOID || //for converter + nominal != null && nominal.isAssignableFrom(inferred)) { + return inferred; } } } - if (nominal.isAssignableFrom(inferred)) return inferred; } - return nominal; + if (nominal != null) { + return nominal; + } + + return PsiType.getJavaLangObject(method.getManager(), method.getResolveScope()); } - @Nullable - private PsiType getInferredType(GrMethod method) { - assert method.isValid() : "invalid method"; - - final GrOpenBlock block = method.getBlock(); - if (block == null) return null; - assert block.isValid() : "invalid code block"; - - return GroovyPsiManager.inferType(method, new MethodTypeInferencer(block)); - } }; @Nullable @@ -218,12 +223,20 @@ public abstract class GrMethodBaseImpl extends GrStubElementBase i return null; } + final PsiType type = getNominalType(); + if (type != null) { + return type; + } + + return PsiType.getJavaLangObject(getManager(), getResolveScope()); + } + + private PsiType getNominalType() { final GrTypeElement element = getReturnTypeElementGroovy(); if (element != null) { return element.getType(); } - - return PsiType.getJavaLangObject(getManager(), getResolveScope()); + return null; } @Nullable diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/return2.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/return2.java index e370bd4a5e5c..46dbfaec64da 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/return2.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/return2.java @@ -8,7 +8,7 @@ return null; } -public boolean foo() { +public java.lang.Boolean foo() { java.lang.Integer a = 5; org.codehaus.groovy.runtime.DefaultGroovyMethods.times(a, new groovy.lang.Closure(this, this) { public java.lang.Integer doCall(java.lang.Object it) { diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/returns.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/returns.java index 711ec7d9f234..2bd0daacecdd 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/returns.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/returns.java @@ -8,7 +8,7 @@ public void foo2() { org.codehaus.groovy.runtime.DefaultGroovyMethods.print(returns.this, "foo"); } -public int foo3() { +public java.lang.Integer foo3() { org.codehaus.groovy.runtime.DefaultGroovyMethods.print(returns.this, "foo"); return null; } From e44daca15ee634c64b21f1d53624c2b20d18c24d Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Tue, 10 May 2011 12:24:38 +0400 Subject: [PATCH 041/250] [xena] TreUi: getReady callbacks singal rejected if tree ui gets disposed during works, used to cause NPEs - 2 (ready callbacks fixed --- .../ide/util/treeView/AbstractTreeUi.java | 3 ++- .../com/intellij/openapi/util/BusyObject.java | 15 +++++++++---- .../ide/util/treeView/TreeUiTest.java | 21 +++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java index ab15fb6b5b55..6346a21b9d90 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java @@ -1933,7 +1933,8 @@ public class AbstractTreeUi { "isCancelProcessed=" + isCancelProcessed() + "\n" + " isCancelRequested=" + myCancelRequest + "\n" + " isResettingToReadyNow=" + myResettingToReadyNow + "\n" + - "canInitiateNewActivity=" + canInitiateNewActivity(); + "canInitiateNewActivity=" + canInitiateNewActivity() + + "batchIndicators=" + myBatchIndicators; } public boolean hasPendingWork() { diff --git a/platform/platform-api/src/com/intellij/openapi/util/BusyObject.java b/platform/platform-api/src/com/intellij/openapi/util/BusyObject.java index ce911700edd8..c42f18fac9c4 100644 --- a/platform/platform-api/src/com/intellij/openapi/util/BusyObject.java +++ b/platform/platform-api/src/com/intellij/openapi/util/BusyObject.java @@ -41,10 +41,17 @@ public interface BusyObject { public final void onReady(@Nullable Object readyRequestor) { if (!isReady()) return; - Pair> callbacks = getReadyCallbacks(readyRequestor); - callbacks.getFirst().setDone(); - for (ActionCallback each : callbacks.getSecond()) { - each.setRejected(); + if (readyRequestor != null) { + Pair> callbacks = getReadyCallbacks(readyRequestor); + callbacks.getFirst().setDone(); + for (ActionCallback each : callbacks.getSecond()) { + each.setRejected(); + } + } else { + ActionCallback[] callbacks = getReadyCallbacks(); + for (ActionCallback each : callbacks) { + each.setDone(); + } } } diff --git a/platform/platform-impl/testSrc/com/intellij/ide/util/treeView/TreeUiTest.java b/platform/platform-impl/testSrc/com/intellij/ide/util/treeView/TreeUiTest.java index c53a1f31e10d..37b0a8f634bb 100644 --- a/platform/platform-impl/testSrc/com/intellij/ide/util/treeView/TreeUiTest.java +++ b/platform/platform-impl/testSrc/com/intellij/ide/util/treeView/TreeUiTest.java @@ -115,6 +115,20 @@ public class TreeUiTest extends AbstractTreeBuilderTest { final ActionCallback done = new ActionCallback(); final Ref indicatorRef = new Ref(); + final Ref ready = new Ref(); + + myElementUpdateHook = new ElementUpdateHook() { + @Override + public void onElementAction(String action, Object element) { + if (new NodeElement("jetbrains").equals(element) && ready.get() == null) { + ActionCallback readyCallback = new ActionCallback(); + assertFalse(getBuilder().getUi().isReady()); + getBuilder().getReady(this).notify(readyCallback); + ready.set(readyCallback); + } + } + }; + invokeLaterIfNeeded(new Runnable() { @Override public void run() { @@ -137,6 +151,8 @@ public class TreeUiTest extends AbstractTreeBuilderTest { }); assertTrue(done.isDone()); + assertNotNull(ready.get()); + assertTrue(ready.get().isDone()); assertTree("-/\n" + " -com\n" + @@ -2359,6 +2375,11 @@ public class TreeUiTest extends AbstractTreeBuilderTest { public YieldingUpdate() { super(true, false); } + + @Override + public void testBatchUpdate() throws Exception { + super.testBatchUpdate(); + } } public static class BgLoadingSyncUpdate extends TreeUiTest { From 243ca3fed090f50cb07bd503f9582ee4871e79df Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Tue, 10 May 2011 13:03:38 +0400 Subject: [PATCH 042/250] runToolbarExists deadlock (preloadActions) --- .../NavBarRootPaneExtension.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java index 1dbb8e797260..d808a28ed1a0 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java @@ -64,11 +64,12 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { return new NavBarRootPaneExtension(myProject); } - public static boolean isMainToolbarVisible() { - return UISettings.getInstance().SHOW_MAIN_TOOLBAR || !runToolbarExists(); + public static boolean isMainToolbarVisible(final Project project) { + return UISettings.getInstance().SHOW_MAIN_TOOLBAR || !runToolbarExists(project); } - private static boolean runToolbarExists() { + private static boolean runToolbarExists(final Project project) { + if (project != null && !project.isInitialized()) return false; final AnAction navBarToolBar = ActionManager.getInstance().getAction("NavBarToolBar"); return navBarToolBar instanceof DefaultActionGroup && ((DefaultActionGroup)navBarToolBar).getChildrenCount() > 0; } @@ -79,7 +80,7 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { @Override protected void paintChildren(Graphics g) { super.paintChildren(g); - if (UIUtil.isUnderAquaLookAndFeel() && !isMainToolbarVisible()) { + if (UIUtil.isUnderAquaLookAndFeel() && !isMainToolbarVisible(myProject)) { final Rectangle r = getBounds(); g.setColor(new Color(255, 255, 255, 90)); g.drawLine(0, r.height - 4, r.width, r.height - 4); @@ -98,7 +99,7 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { } final Rectangle r = getBounds(); - if (isMainToolbarVisible()) { + if (isMainToolbarVisible(myProject)) { g.setColor(new Color(200, 200, 200)); g.fillRect(0, 0, r.width, r.height); } @@ -126,7 +127,7 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { } private void toggleRunPanel(final boolean show) { - if (show && myRunPanel == null && runToolbarExists()) { + if (show && myRunPanel == null && runToolbarExists(myProject)) { final ActionManager manager = ActionManager.getInstance(); final AnAction toolbarRunGroup = manager.getAction("NavBarToolBar"); if (toolbarRunGroup instanceof DefaultActionGroup) { @@ -186,7 +187,7 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { if (UIUtil.isUnderAquaLookAndFeel()) { final Rectangle r = getBounds(); final Graphics2D g2d = (Graphics2D)g; - if (!isMainToolbarVisible()) { + if (!isMainToolbarVisible(myProject)) { //UIUtil.drawGradientHToolbarBackground(g, r.width, r.height); final Dimension d = getPreferredSize(); @@ -286,7 +287,7 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { if (myWrapperPanel.getComponentCount() > 0) { final Component c = myWrapperPanel.getComponent(0); if (c instanceof JComponent) ((JComponent)c).setOpaque( - !UIUtil.isUnderAquaLookAndFeel() || isMainToolbarVisible()); + !UIUtil.isUnderAquaLookAndFeel() || isMainToolbarVisible(myProject)); } } } From be1309485ee8ade08a6524caa895bd6f3715c3fb Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 10 May 2011 10:41:05 +0400 Subject: [PATCH 043/250] injected element presentation --- .../InjectedSelfElementInfo.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/InjectedSelfElementInfo.java b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/InjectedSelfElementInfo.java index 70d09ae91ebb..07289cc4434a 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/InjectedSelfElementInfo.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/InjectedSelfElementInfo.java @@ -15,8 +15,10 @@ */ package com.intellij.psi.impl.smartPointers; +import com.intellij.injected.editor.DocumentWindow; import com.intellij.lang.Language; import com.intellij.lang.injection.InjectedLanguageManager; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.Segment; @@ -32,7 +34,7 @@ import java.util.List; * User: cdr */ class InjectedSelfElementInfo extends SelfElementInfo { - private final SmartPsiFileRange myInjectedFileRangeInHostElement; + private final SmartPsiFileRange myInjectedFileRangeInHostFile; private final Class anchorClass; private final Language anchorLanguage; @@ -40,9 +42,9 @@ class InjectedSelfElementInfo extends SelfElementInfo { super(project, context); SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(project); TextRange range = InjectedLanguageManager.getInstance(project).injectedToHost(anchor, anchor.getTextRange()); - myInjectedFileRangeInHostElement = smartPointerManager.createSmartPsiFileRangePointer(context.getContainingFile(), range); + myInjectedFileRangeInHostFile = smartPointerManager.createSmartPsiFileRangePointer(context.getContainingFile(), range); anchorClass = anchor.getClass(); - anchorLanguage = anchor.getLanguage(); + anchorLanguage = anchor.getContainingFile().getLanguage(); } @Override @@ -57,35 +59,36 @@ class InjectedSelfElementInfo extends SelfElementInfo { PsiElement host = super.restoreElement(); if (host == null) return null; - Segment segment = myInjectedFileRangeInHostElement.getRange(); + Segment segment = myInjectedFileRangeInHostFile.getRange(); if (segment == null) return null; - final TextRange rangeInHostElement = TextRange.create(segment); + final TextRange rangeInHostFile = TextRange.create(segment); final Ref result = new Ref(); + final InjectedLanguageManager manager = InjectedLanguageManager.getInstance(getProject()); InjectedLanguageUtil.enumerate(host, host.getContainingFile(), new PsiLanguageInjectionHost.InjectedPsiVisitor() { @Override public void visit(@NotNull PsiFile injectedPsi, @NotNull List places) { if (result.get() != null) return; - TextRange hostRange = - InjectedLanguageManager.getInstance(getProject()).injectedToHost(injectedPsi, new TextRange(0, injectedPsi.getTextLength())); - if (hostRange.contains(rangeInHostElement)) { - TextRange rangeInside = rangeInHostElement.shiftRight(-hostRange.getStartOffset()); - PsiElement element = findElementInside(injectedPsi, rangeInside.getStartOffset(), rangeInside.getEndOffset(), anchorClass, - anchorLanguage); + TextRange hostRange = manager.injectedToHost(injectedPsi, new TextRange(0, injectedPsi.getTextLength())); + Document document = PsiDocumentManager.getInstance(getProject()).getDocument(injectedPsi); + if (hostRange.contains(rangeInHostFile) && document instanceof DocumentWindow) { + int start = ((DocumentWindow)document).hostToInjected(rangeInHostFile.getStartOffset()); + int end = ((DocumentWindow)document).hostToInjected(rangeInHostFile.getEndOffset()); + PsiElement element = findElementInside(injectedPsi, start, end, anchorClass, anchorLanguage); result.set(element); } } }, false); - return result.get(); + return result.get(); } @Override public boolean pointsToTheSameElementAs(@NotNull SmartPointerElementInfo other) { if (getClass() != other.getClass()) return false; if (!super.pointsToTheSameElementAs(other)) return false; - SmartPointerElementInfo myElementInfo = ((SmartPsiElementPointerImpl)myInjectedFileRangeInHostElement).getElementInfo(); - SmartPointerElementInfo oElementInfo = ((SmartPsiElementPointerImpl)((InjectedSelfElementInfo)other).myInjectedFileRangeInHostElement).getElementInfo(); + SmartPointerElementInfo myElementInfo = ((SmartPsiElementPointerImpl)myInjectedFileRangeInHostFile).getElementInfo(); + SmartPointerElementInfo oElementInfo = ((SmartPsiElementPointerImpl)((InjectedSelfElementInfo)other).myInjectedFileRangeInHostFile).getElementInfo(); return myElementInfo.pointsToTheSameElementAs(oElementInfo); } } From 61ce87b4b14b15858e45f19c58bbee59b45fbefa Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Tue, 10 May 2011 13:12:18 +0400 Subject: [PATCH 044/250] IDEA-69363 Quick Documentation popup (Ctrl+Q) does not respect Unicode escape sequences ... Unicode symbols are decoded for javadoc description now --- .../com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java index ab834d83e958..42e851215252 100644 --- a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java +++ b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java @@ -987,7 +987,7 @@ public class JavaDocInfoGenerator { } } else { - buffer.append(element.getText()); + buffer.append(StringUtil.unescapeStringCharacters(element.getText())); } } } From a0143934fa2f7dc1ae05d150d1b124be39c0d65f Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Tue, 10 May 2011 14:25:18 +0400 Subject: [PATCH 045/250] IDEA-69432 Navbar UI painted incorrectly --- .../NavBarRootPaneExtension.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java index d808a28ed1a0..0fe084574760 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java @@ -47,6 +47,7 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { private final Project myProject; private NavBarPanel myNavigationBar; private JPanel myRunPanel; + private boolean myNavToolbarGroupExist; public NavBarRootPaneExtension(Project project) { myProject = project; @@ -57,6 +58,9 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { toggleRunPanel(!source.SHOW_MAIN_TOOLBAR); } }, this); + + final AnAction navBarToolBar = ActionManager.getInstance().getAction("NavBarToolBar"); + myNavToolbarGroupExist = navBarToolBar instanceof DefaultActionGroup && ((DefaultActionGroup)navBarToolBar).getChildrenCount() > 0; } @Override @@ -64,12 +68,11 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { return new NavBarRootPaneExtension(myProject); } - public static boolean isMainToolbarVisible(final Project project) { - return UISettings.getInstance().SHOW_MAIN_TOOLBAR || !runToolbarExists(project); + public boolean isMainToolbarVisible() { + return UISettings.getInstance().SHOW_MAIN_TOOLBAR || !myNavToolbarGroupExist; } - private static boolean runToolbarExists(final Project project) { - if (project != null && !project.isInitialized()) return false; + private static boolean runToolbarExists() { final AnAction navBarToolBar = ActionManager.getInstance().getAction("NavBarToolBar"); return navBarToolBar instanceof DefaultActionGroup && ((DefaultActionGroup)navBarToolBar).getChildrenCount() > 0; } @@ -80,7 +83,7 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { @Override protected void paintChildren(Graphics g) { super.paintChildren(g); - if (UIUtil.isUnderAquaLookAndFeel() && !isMainToolbarVisible(myProject)) { + if (UIUtil.isUnderAquaLookAndFeel() && !isMainToolbarVisible()) { final Rectangle r = getBounds(); g.setColor(new Color(255, 255, 255, 90)); g.drawLine(0, r.height - 4, r.width, r.height - 4); @@ -99,7 +102,7 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { } final Rectangle r = getBounds(); - if (isMainToolbarVisible(myProject)) { + if (isMainToolbarVisible()) { g.setColor(new Color(200, 200, 200)); g.fillRect(0, 0, r.width, r.height); } @@ -127,7 +130,7 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { } private void toggleRunPanel(final boolean show) { - if (show && myRunPanel == null && runToolbarExists(myProject)) { + if (show && myRunPanel == null && runToolbarExists()) { final ActionManager manager = ActionManager.getInstance(); final AnAction toolbarRunGroup = manager.getAction("NavBarToolBar"); if (toolbarRunGroup instanceof DefaultActionGroup) { @@ -187,7 +190,7 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { if (UIUtil.isUnderAquaLookAndFeel()) { final Rectangle r = getBounds(); final Graphics2D g2d = (Graphics2D)g; - if (!isMainToolbarVisible(myProject)) { + if (!isMainToolbarVisible()) { //UIUtil.drawGradientHToolbarBackground(g, r.width, r.height); final Dimension d = getPreferredSize(); @@ -287,7 +290,7 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { if (myWrapperPanel.getComponentCount() > 0) { final Component c = myWrapperPanel.getComponent(0); if (c instanceof JComponent) ((JComponent)c).setOpaque( - !UIUtil.isUnderAquaLookAndFeel() || isMainToolbarVisible(myProject)); + !UIUtil.isUnderAquaLookAndFeel() || isMainToolbarVisible()); } } } From 4300b7fb3fe3e6e96bb1f345fab4f24b5deb0eda Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 17:12:00 +0200 Subject: [PATCH 046/250] inline some groovy completion filters --- .../GroovyCompletionContributor.java | 2 + .../lang/completion/GroovyCompletionData.java | 151 ++++++++++++++++-- .../filters/toplevel/AnnotationFilter.java | 58 ------- .../toplevel/ClassInterfaceEnumFilter.java | 77 --------- .../filters/toplevel/ImportFilter.java | 56 ------- .../filters/toplevel/PackageFilter.java | 73 --------- 6 files changed, 136 insertions(+), 281 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/AnnotationFilter.java delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/ClassInterfaceEnumFilter.java delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/ImportFilter.java delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/PackageFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java index 579bca31beee..08c398df11c1 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java @@ -317,6 +317,8 @@ public class GroovyCompletionContributor extends CompletionContributor { } private static void addKeywords(CompletionParameters parameters, CompletionResultSet result) { + GroovyCompletionData.addGroovyKeywords(parameters, result); + PsiElement position = parameters.getPosition(); final Set lookupSet = new LinkedHashSet(); final Set keywordVariants = new HashSet(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 541a0eb988d2..2d1d310857e6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -25,12 +25,14 @@ import com.intellij.codeInsight.completion.CompletionVariant; import com.intellij.codeInsight.lookup.*; import com.intellij.patterns.PlatformPatterns; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiErrorElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiReference; import com.intellij.psi.filters.*; import com.intellij.psi.filters.position.LeftNeighbour; import com.intellij.psi.filters.position.ParentElementFilter; import com.intellij.psi.impl.source.tree.LeafPsiElement; +import com.intellij.psi.templateLanguages.OuterLanguageElement; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.completion.filters.classdef.ExtendsFilter; @@ -43,17 +45,21 @@ import org.jetbrains.plugins.groovy.lang.completion.filters.control.additional.E import org.jetbrains.plugins.groovy.lang.completion.filters.exprs.InstanceOfFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.exprs.SimpleExpressionFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.modifiers.*; -import org.jetbrains.plugins.groovy.lang.completion.filters.toplevel.AnnotationFilter; -import org.jetbrains.plugins.groovy.lang.completion.filters.toplevel.ClassInterfaceEnumFilter; -import org.jetbrains.plugins.groovy.lang.completion.filters.toplevel.ImportFilter; -import org.jetbrains.plugins.groovy.lang.completion.filters.toplevel.PackageFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.types.BuiltInTypeAsArgumentFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.types.BuiltInTypeFilter; import org.jetbrains.plugins.groovy.lang.completion.getters.SuggestedVariableNamesGetter; import org.jetbrains.plugins.groovy.lang.groovydoc.lexer.GroovyDocTokenTypes; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocInlinedTag; +import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; +import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; +import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; +import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral; +import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; import java.util.Set; @@ -71,13 +77,39 @@ public class GroovyCompletionData extends CompletionData { registerAllCompletions(); } + public static void addGroovyKeywords(CompletionParameters parameters, CompletionResultSet result) { + PsiElement position = parameters.getPosition(); + if (!PlatformPatterns.psiElement().afterLeaf(".", ".&").accepts(position)) { + if (suggestPackage(position)) { + result.addElement(keyword("package")); + } + if (suggestImport(position)) { + result.addElement(keyword("import")); + } + //--- + if (suggestClassInterfaceEnum(position)) { + result.addElement(keyword("class")); + result.addElement(keyword("interface")); + result.addElement(keyword("enum")); + } + if (afterAtInType(position)) { + result.addElement(keyword("interface")); + } + //--- + + + } + } + + private static TailTypeDecorator keyword(final String keyword) { + return TailTypeDecorator + .withTail(LookupElementBuilder.create(keyword).setBold().setInsertHandler(GroovyInsertHandler.INSTANCE), TailType.SPACE); + } + /** * Registers completions on top level of Groovy script file */ private void registerAllCompletions() { - registerPackageCompletion(); - registerImportCompletion(); - registerClassInterfaceEnumAnnotationCompletion(); registerControlCompletion(); registerSimpleExprsCompletion(); @@ -101,13 +133,7 @@ public class GroovyCompletionData extends CompletionData { } - private void registerPackageCompletion() { - registerStandardCompletion(new PackageFilter(), "package"); - } - private void registerClassInterfaceEnumAnnotationCompletion() { - registerStandardCompletion(new ClassInterfaceEnumFilter(), "class", "interface", "enum"); - registerStandardCompletion(new AnnotationFilter(), "interface"); registerStandardCompletion(new ExtendsFilter(), "extends"); registerStandardCompletion(new ImplementsFilter(), "implements"); } @@ -154,10 +180,6 @@ public class GroovyCompletionData extends CompletionData { registerStandardCompletion(new SynchronizedFilter(), "synchronized"); } - private void registerImportCompletion() { - registerStandardCompletion(new ImportFilter(), "import"); - } - private void registerInstanceofCompletion() { registerStandardCompletion(new InstanceOfFilter(), "instanceof", "in"); } @@ -243,4 +265,99 @@ public class GroovyCompletionData extends CompletionData { } } } + + private static boolean suggestPackage(PsiElement context) { + if (context.getParent() != null && + !(context.getParent() instanceof PsiErrorElement) && + context.getParent().getParent() instanceof GroovyFile && + ((GroovyFile) context.getParent().getParent()).getPackageDefinition() == null) { + if (context.getParent() instanceof GrReferenceExpression) { + return true; + } + if (context.getParent() instanceof GrApplicationStatement && + ((GrApplicationStatement) context.getParent()).getExpressionArguments()[0] instanceof GrReferenceExpression) { + return true; + } + return false; + } + if (context.getTextRange().getStartOffset() == 0 && !(context instanceof OuterLanguageElement)) { + return true; + } + + final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(context.getTextRange().getStartOffset() - 1, context); + if (leaf != null) { + PsiElement parent = leaf.getParent(); + if (parent instanceof GroovyFile) { + GroovyFile groovyFile = (GroovyFile) parent; + if (groovyFile.getPackageDefinition() == null) { + return GroovyCompletionUtil.isNewStatement(context, false); + } + } + } + + return false; + } + + private static boolean suggestImport(PsiElement context) { + if (context.getParent() != null && + !(context.getParent() instanceof PsiErrorElement) && + GroovyCompletionUtil.isNewStatement(context, false) && + context.getParent().getParent() instanceof GroovyFile) { + return true; + } + final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(context.getTextRange().getStartOffset() - 1, context); + if (leaf != null) { + PsiElement parent = leaf.getParent(); + if (parent instanceof GroovyFile) { + return GroovyCompletionUtil.isNewStatement(context, false); + } + } + return context.getTextRange().getStartOffset() == 0 && !(context instanceof OuterLanguageElement); + } + + public static boolean suggestClassInterfaceEnum(PsiElement context) { + if (context.getParent() != null && + (context.getParent() instanceof GrReferenceExpression) && + context.getParent().getParent() instanceof GroovyFile) { + return true; + } + if (context.getParent() != null && + (context.getParent() instanceof GrReferenceExpression) && + (context.getParent().getParent() instanceof GrApplicationStatement || + context.getParent().getParent() instanceof GrCall) && + context.getParent().getParent().getParent() instanceof GroovyFile) { + return true; + } + final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(context.getTextRange().getStartOffset() - 1, context); + if (leaf != null) { + PsiElement prev = leaf; + prev = PsiImplUtil.realPrevious(prev); + if (prev instanceof GrModifierList && + prev.getParent() != null && + prev.getParent().getParent() instanceof GroovyFile) + return true; + + PsiElement parent = leaf.getParent(); + if (parent instanceof GroovyFile) { + return GroovyCompletionUtil.isNewStatement(context, false); + } + } + + return false; + } + + public static boolean afterAtInType(PsiElement context) { + PsiElement previous = PsiImplUtil.realPrevious(context.getPrevSibling()); + if (previous != null && + GroovyTokenTypes.mAT.equals(previous.getNode().getElementType()) && + context.getParent() != null && + context.getParent().getParent() instanceof GroovyFile) { + return true; + } + if (context.getParent() instanceof PsiErrorElement && + context.getParent().getParent() instanceof GrAnnotation) { + return true; + } + return false; + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/AnnotationFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/AnnotationFilter.java deleted file mode 100644 index bc0985e7ff70..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/AnnotationFilter.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.toplevel; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiErrorElement; -import com.intellij.psi.filters.ElementFilter; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; -import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes; -import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation; -import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; - -/** - * @author ilyas - */ -public class AnnotationFilter implements ElementFilter, GroovyElementTypes { - - - public boolean isAcceptable(Object element, PsiElement context) { - PsiElement previous = PsiImplUtil.realPrevious(context.getPrevSibling()); - if (previous != null && - GroovyTokenTypes.mAT.equals(previous.getNode().getElementType()) && - context.getParent() != null && - context.getParent().getParent() instanceof GroovyFile) { - return true; - } - if (context.getParent() instanceof PsiErrorElement && - context.getParent().getParent() instanceof GrAnnotation) { - return true; - } - return false; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "@interface keyword filter"; - } -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/ClassInterfaceEnumFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/ClassInterfaceEnumFilter.java deleted file mode 100644 index e7faeccdb59d..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/ClassInterfaceEnumFilter.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.toplevel; - - -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.tree.TokenSet; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes; -import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; -import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; - -/** - * @author ilyas - */ -public class ClassInterfaceEnumFilter implements ElementFilter, GroovyElementTypes { - - public boolean isAcceptable(Object element, PsiElement context) { - if (context.getParent() != null && - (context.getParent() instanceof GrReferenceExpression) && - context.getParent().getParent() instanceof GroovyFile) { - return true; - } - if (context.getParent() != null && - (context.getParent() instanceof GrReferenceExpression) && - (context.getParent().getParent() instanceof GrApplicationStatement || - context.getParent().getParent() instanceof GrCall) && - context.getParent().getParent().getParent() instanceof GroovyFile) { - return true; - } - final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(context.getTextRange().getStartOffset() - 1, context); - if (leaf != null) { - PsiElement prev = leaf; - prev = PsiImplUtil.realPrevious(prev); - if (prev instanceof GrModifierList && - prev.getParent() != null && - prev.getParent().getParent() instanceof GroovyFile) - return true; - - PsiElement parent = leaf.getParent(); - if (parent instanceof GroovyFile) { - return GroovyCompletionUtil.isNewStatement(context, false); - } - } - - return false; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "'class', 'interface', 'enum' keywords filter"; - } -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/ImportFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/ImportFilter.java deleted file mode 100644 index e99cf5a70b35..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/ImportFilter.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.toplevel; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiErrorElement; -import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.templateLanguages.OuterLanguageElement; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; - -/** - * @author ilyas - */ -public class ImportFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - if (context.getParent() != null && - !(context.getParent() instanceof PsiErrorElement) && - GroovyCompletionUtil.isNewStatement(context, false) && - context.getParent().getParent() instanceof GroovyFile) { - return true; - } - final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(context.getTextRange().getStartOffset() - 1, context); - if (leaf != null) { - PsiElement parent = leaf.getParent(); - if (parent instanceof GroovyFile) { - return GroovyCompletionUtil.isNewStatement(context, false); - } - } - return context.getTextRange().getStartOffset() == 0 && !(context instanceof OuterLanguageElement); - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "'import' keyword filter"; - } -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/PackageFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/PackageFilter.java deleted file mode 100644 index 21490ebd15b3..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/toplevel/PackageFilter.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.toplevel; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiErrorElement; -import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.templateLanguages.OuterLanguageElement; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; - -/** - * @author ilyas - */ -public class PackageFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - if (context.getParent() != null && - !(context.getParent() instanceof PsiErrorElement) && - context.getParent().getParent() instanceof GroovyFile && - ((GroovyFile) context.getParent().getParent()).getPackageDefinition() == null) { - if (context.getParent() instanceof GrReferenceExpression) { - return true; - } - if (context.getParent() instanceof GrApplicationStatement && - ((GrApplicationStatement) context.getParent()).getExpressionArguments()[0] instanceof GrReferenceExpression) { - return true; - } - return false; - } - if (context.getTextRange().getStartOffset() == 0 && !(context instanceof OuterLanguageElement)) { - return true; - } - - final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(context.getTextRange().getStartOffset() - 1, context); - if (leaf != null) { - PsiElement parent = leaf.getParent(); - if (parent instanceof GroovyFile) { - GroovyFile groovyFile = (GroovyFile) parent; - if (groovyFile.getPackageDefinition() == null) { - return GroovyCompletionUtil.isNewStatement(context, false); - } - } - } - - return false; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "'package' keyword filter"; - } -} \ No newline at end of file From a42d1d0bb9186b066ddf53c01af0ff3574e352a6 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 17:12:57 +0200 Subject: [PATCH 047/250] privatization --- .../plugins/groovy/lang/completion/GroovyCompletionData.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 2d1d310857e6..954039c51033 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -315,7 +315,7 @@ public class GroovyCompletionData extends CompletionData { return context.getTextRange().getStartOffset() == 0 && !(context instanceof OuterLanguageElement); } - public static boolean suggestClassInterfaceEnum(PsiElement context) { + private static boolean suggestClassInterfaceEnum(PsiElement context) { if (context.getParent() != null && (context.getParent() instanceof GrReferenceExpression) && context.getParent().getParent() instanceof GroovyFile) { @@ -346,7 +346,7 @@ public class GroovyCompletionData extends CompletionData { return false; } - public static boolean afterAtInType(PsiElement context) { + private static boolean afterAtInType(PsiElement context) { PsiElement previous = PsiImplUtil.realPrevious(context.getPrevSibling()); if (previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType()) && From 6ba498f880bb7b7d6342d843d80af44c8219ab76 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 17:22:11 +0200 Subject: [PATCH 048/250] inlined and improved extends/implements completion copy-paste --- .../lang/completion/GroovyCompletionData.java | 68 ++++++++++++++----- .../filters/classdef/ExtendsFilter.java | 61 ----------------- .../filters/classdef/ImplementsFilter.java | 64 ----------------- 3 files changed, 50 insertions(+), 143 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/classdef/ExtendsFilter.java delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/classdef/ImplementsFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 954039c51033..8ee5fcea6291 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -35,8 +35,6 @@ import com.intellij.psi.impl.source.tree.LeafPsiElement; import com.intellij.psi.templateLanguages.OuterLanguageElement; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.groovy.lang.completion.filters.classdef.ExtendsFilter; -import org.jetbrains.plugins.groovy.lang.completion.filters.classdef.ImplementsFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.control.BranchFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.control.ControlStructureFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.control.additional.CaseDefaultFilter; @@ -59,7 +57,9 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplic import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.*; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; +import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; import java.util.Set; @@ -86,21 +86,59 @@ public class GroovyCompletionData extends CompletionData { if (suggestImport(position)) { result.addElement(keyword("import")); } - //--- - if (suggestClassInterfaceEnum(position)) { - result.addElement(keyword("class")); - result.addElement(keyword("interface")); - result.addElement(keyword("enum")); - } - if (afterAtInType(position)) { - result.addElement(keyword("interface")); - } - //--- + addTypeDefinitionKeywords(result, position); + addExtendsImplements(position, result); } } + private static void addTypeDefinitionKeywords(CompletionResultSet result, PsiElement position) { + if (suggestClassInterfaceEnum(position)) { + result.addElement(keyword("class")); + result.addElement(keyword("interface")); + result.addElement(keyword("enum")); + } + if (afterAtInType(position)) { + result.addElement(keyword("interface")); + } + } + + private static void addExtendsImplements(PsiElement context, CompletionResultSet result) { + if (context.getParent() == null) { + return; + } + + PsiElement elem = context.getParent(); + boolean ext = !(elem instanceof GrExtendsClause); + boolean impl = !(elem instanceof GrImplementsClause); + + if (elem instanceof GrTypeDefinitionBody) { //inner class + elem = PsiUtil.skipWhitespaces(context.getPrevSibling(), false); + } + else { + elem = PsiUtil.skipWhitespaces(elem.getPrevSibling(), false); + } + + ext &= elem instanceof GrInterfaceDefinition || elem instanceof GrClassDefinition; + impl &= elem instanceof GrEnumTypeDefinition || elem instanceof GrClassDefinition; + if (!ext && !impl) return; + + PsiElement[] children = elem.getChildren(); + for (PsiElement child : children) { + ext &= !(child instanceof GrExtendsClause); + if (child instanceof GrImplementsClause || child instanceof GrTypeDefinitionBody) { + return; + } + } + if (ext) { + result.addElement(keyword("extends")); + } + if (impl) { + result.addElement(keyword("implements")); + } + } + private static TailTypeDecorator keyword(final String keyword) { return TailTypeDecorator .withTail(LookupElementBuilder.create(keyword).setBold().setInsertHandler(GroovyInsertHandler.INSTANCE), TailType.SPACE); @@ -110,7 +148,6 @@ public class GroovyCompletionData extends CompletionData { * Registers completions on top level of Groovy script file */ private void registerAllCompletions() { - registerClassInterfaceEnumAnnotationCompletion(); registerControlCompletion(); registerSimpleExprsCompletion(); registerBuiltInTypeCompletion(); @@ -133,11 +170,6 @@ public class GroovyCompletionData extends CompletionData { } - private void registerClassInterfaceEnumAnnotationCompletion() { - registerStandardCompletion(new ExtendsFilter(), "extends"); - registerStandardCompletion(new ImplementsFilter(), "implements"); - } - private void registerControlCompletion() { String[] controlKeywords = {"try", "while", "with", "switch", "for", "return", "throw", "assert", "synchronized",}; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/classdef/ExtendsFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/classdef/ExtendsFilter.java deleted file mode 100644 index 8133e441c1b4..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/classdef/ExtendsFilter.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.classdef; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.ElementFilter; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.*; -import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; - -/** - * @author ilyas - */ -public class ExtendsFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - if (context.getParent() == null || context.getParent() instanceof GrExtendsClause) { - return false; - } - PsiElement elem = context.getParent(); - if (elem instanceof GrTypeDefinitionBody) { //inner class - elem = PsiUtil.skipWhitespaces(context.getPrevSibling(), false); - } - else { - elem = PsiUtil.skipWhitespaces(elem.getPrevSibling(), false); - } - if (!(elem instanceof GrInterfaceDefinition || elem instanceof GrClassDefinition)) { - return false; - } - PsiElement[] children = elem.getChildren(); - for (PsiElement child : children) { - if (child instanceof GrImplementsClause || child instanceof GrExtendsClause || child instanceof GrTypeDefinitionBody) { - return false; - } - } - return true; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "'extends' keyword filter"; - } - -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/classdef/ImplementsFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/classdef/ImplementsFilter.java deleted file mode 100644 index 241c8b9c5113..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/classdef/ImplementsFilter.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.classdef; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.ElementFilter; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrClassDefinition; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumTypeDefinition; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody; -import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; - -/** - * @author ilyas - */ -public class ImplementsFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - if (context.getParent() == null || context.getParent() instanceof GrImplementsClause) { - return false; - } - PsiElement elem = context.getParent(); - if (elem instanceof GrTypeDefinitionBody) { - elem = PsiUtil.skipWhitespaces(context.getPrevSibling(), false); - } - else { - elem = PsiUtil.skipWhitespaces(elem.getPrevSibling(), false); - } - - if (!(elem instanceof GrEnumTypeDefinition) && (!(elem instanceof GrClassDefinition))) { - return false; - } - PsiElement[] children = elem.getChildren(); - for (PsiElement child : children) { - if (child instanceof GrImplementsClause || child instanceof GrTypeDefinitionBody) { - return false; - } - } - return true; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "'implements' keyword filter"; - } -} From 7965670d0d998f48f160c81832c34ac3422a30d6 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 17:24:45 +0200 Subject: [PATCH 049/250] shorter --- .../groovy/lang/completion/GroovyCompletionData.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 8ee5fcea6291..e900e8d06bd0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -95,9 +95,7 @@ public class GroovyCompletionData extends CompletionData { private static void addTypeDefinitionKeywords(CompletionResultSet result, PsiElement position) { if (suggestClassInterfaceEnum(position)) { - result.addElement(keyword("class")); - result.addElement(keyword("interface")); - result.addElement(keyword("enum")); + addKeywords(result, "class", "interface", "enum"); } if (afterAtInType(position)) { result.addElement(keyword("interface")); @@ -139,6 +137,12 @@ public class GroovyCompletionData extends CompletionData { } } + private static void addKeywords(CompletionResultSet result, String... keywords) { + for (String s : keywords) { + result.addElement(keyword(s)); + } + } + private static TailTypeDecorator keyword(final String keyword) { return TailTypeDecorator .withTail(LookupElementBuilder.create(keyword).setBold().setInsertHandler(GroovyInsertHandler.INSTANCE), TailType.SPACE); From fe62eb15e957c4308da1d0332e283da85b516e79 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 17:30:18 +0200 Subject: [PATCH 050/250] inline control structure filters --- .../lang/completion/GroovyCompletionData.java | 152 ++++++++++++++++-- .../control/ControlStructureFilter.java | 91 ----------- .../control/additional/CaseDefaultFilter.java | 56 ------- .../additional/CatchFinallyFilter.java | 70 -------- .../control/additional/ElseFilter.java | 67 -------- 5 files changed, 135 insertions(+), 301 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/ControlStructureFilter.java delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/additional/CaseDefaultFilter.java delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/additional/CatchFinallyFilter.java delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/additional/ElseFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index e900e8d06bd0..d17f8187dab1 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -23,6 +23,7 @@ import com.intellij.codeInsight.completion.CompletionParameters; import com.intellij.codeInsight.completion.CompletionResultSet; import com.intellij.codeInsight.completion.CompletionVariant; import com.intellij.codeInsight.lookup.*; +import com.intellij.lang.ASTNode; import com.intellij.patterns.PlatformPatterns; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiErrorElement; @@ -36,10 +37,6 @@ import com.intellij.psi.templateLanguages.OuterLanguageElement; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.completion.filters.control.BranchFilter; -import org.jetbrains.plugins.groovy.lang.completion.filters.control.ControlStructureFilter; -import org.jetbrains.plugins.groovy.lang.completion.filters.control.additional.CaseDefaultFilter; -import org.jetbrains.plugins.groovy.lang.completion.filters.control.additional.CatchFinallyFilter; -import org.jetbrains.plugins.groovy.lang.completion.filters.control.additional.ElseFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.exprs.InstanceOfFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.exprs.SimpleExpressionFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.modifiers.*; @@ -49,15 +46,17 @@ import org.jetbrains.plugins.groovy.lang.completion.getters.SuggestedVariableNam import org.jetbrains.plugins.groovy.lang.groovydoc.lexer.GroovyDocTokenTypes; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocInlinedTag; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; +import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; +import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.*; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseSection; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.*; +import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; @@ -89,7 +88,7 @@ public class GroovyCompletionData extends CompletionData { addTypeDefinitionKeywords(result, position); addExtendsImplements(position, result); - + registerControlCompletion(position, result); } } @@ -152,7 +151,6 @@ public class GroovyCompletionData extends CompletionData { * Registers completions on top level of Groovy script file */ private void registerAllCompletions() { - registerControlCompletion(); registerSimpleExprsCompletion(); registerBuiltInTypeCompletion(); registerBuiltInTypesAsArgumentCompletion(); @@ -174,15 +172,21 @@ public class GroovyCompletionData extends CompletionData { } - private void registerControlCompletion() { + private static void registerControlCompletion(PsiElement context, CompletionResultSet result) { String[] controlKeywords = {"try", "while", "with", "switch", "for", "return", "throw", "assert", "synchronized",}; - registerStandardCompletion(new ControlStructureFilter(), controlKeywords); - registerStandardCompletion(new CaseDefaultFilter(), "case", "default"); - registerStandardCompletion(new CatchFinallyFilter(), "catch", "finally"); - registerStandardCompletion(new ElseFilter(), "else"); - - + if (isControlStructure(context)) { + addKeywords(result, controlKeywords); + } + if (inCaseSection(context)) { + addKeywords(result, "case", "default"); + } + if (afterTry(context)) { + addKeywords(result, "catch", "finally"); + } + if (afterIfOrElse(context)) { + addKeywords(result, "else"); + } } private void registerBuiltInTypeCompletion() { @@ -396,4 +400,118 @@ public class GroovyCompletionData extends CompletionData { } return false; } + + private static boolean isControlStructure(PsiElement context) { + final int offset = context.getTextRange().getStartOffset(); + PsiElement prevSibling = context.getPrevSibling(); + if (context.getParent() instanceof GrReferenceElement && prevSibling != null && prevSibling.getNode() != null) { + ASTNode node = prevSibling.getNode(); + return !TokenSets.DOTS.contains(node.getElementType()); + } + if (GroovyCompletionUtil.isNewStatement(context, true)) { + final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(offset - 1, context); + if (leaf != null && leaf.getParent() instanceof GrStatementOwner) { + return true; + } + } + + if (context.getParent() != null) { + PsiElement parent = context.getParent(); + + if (parent instanceof GrExpression && + parent.getParent() instanceof GroovyFile) { + return true; + } + + if (parent instanceof GrReferenceExpression) { + + PsiElement superParent = parent.getParent(); + if (superParent instanceof GrExpression) { + superParent = superParent.getParent(); + } + + if (superParent instanceof GrStatementOwner || + superParent instanceof GrIfStatement || + superParent instanceof GrForStatement || + superParent instanceof GrWhileStatement) { + return true; + } + } + + return false; + } + + return false; + } + + private static boolean inCaseSection(PsiElement context) { + if (context.getParent() instanceof GrReferenceExpression && + context.getParent().getParent() instanceof GrCaseSection) { + return true; + } + final PsiElement left = GroovyCompletionUtil.nearestLeftSibling(context); + if (left != null && left.getParent() != null && + left.getParent() instanceof GrSwitchStatement && + left.getPrevSibling() != null && + left.getPrevSibling().getNode() != null && + GroovyTokenTypes.mLCURLY.equals(left.getPrevSibling().getNode().getElementType())) { + return true; + } + return false; + } + + private static boolean afterTry(PsiElement context) { + if (context != null && + GroovyCompletionUtil.nearestLeftSibling(context) instanceof GrTryCatchStatement) { + GrTryCatchStatement tryStatement = (GrTryCatchStatement) GroovyCompletionUtil.nearestLeftSibling(context); + if (tryStatement == null) return false; + if (tryStatement.getFinallyClause() == null) { + return true; + } + } + if (context != null && + GroovyCompletionUtil.nearestLeftSibling(context) instanceof PsiErrorElement && + GroovyCompletionUtil.nearestLeftSibling(context).getPrevSibling() instanceof GrTryCatchStatement) { + GrTryCatchStatement tryStatement = (GrTryCatchStatement) GroovyCompletionUtil.nearestLeftSibling(context).getPrevSibling(); + if (tryStatement == null) return false; + if (tryStatement.getFinallyClause() == null) { + return true; + } + } + if (context != null && + (context.getParent() instanceof GrReferenceExpression || context.getParent() instanceof PsiErrorElement) && + GroovyCompletionUtil.nearestLeftSibling(context.getParent()) instanceof GrTryCatchStatement) { + GrTryCatchStatement tryStatement = (GrTryCatchStatement) GroovyCompletionUtil.nearestLeftSibling(context.getParent()); + if (tryStatement == null) return false; + if (tryStatement.getFinallyClause() == null) { + return true; + } + } + return false; + } + + private static boolean afterIfOrElse(PsiElement context) { + if (context.getParent() != null && + GroovyCompletionUtil.nearestLeftSibling(context.getParent()) instanceof GrIfStatement) { + GrIfStatement statement = (GrIfStatement) GroovyCompletionUtil.nearestLeftSibling(context.getParent()); + return true; + } + if (context.getParent() != null && + GroovyCompletionUtil.nearestLeftSibling(context) != null && + GroovyCompletionUtil.nearestLeftSibling(context).getPrevSibling() instanceof GrIfStatement) { + GrIfStatement statement = (GrIfStatement) GroovyCompletionUtil.nearestLeftSibling(context).getPrevSibling(); + if (statement.getElseBranch() == null) { + return true; + } + } + if (context.getParent() != null && + context.getParent().getParent() instanceof GrCommandArgumentList && + context.getParent().getParent().getParent().getParent() instanceof GrIfStatement) { + GrIfStatement statement = (GrIfStatement) context.getParent().getParent().getParent().getParent(); + if (statement.getElseBranch() == null) { + return true; + } + } + return false; + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/ControlStructureFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/ControlStructureFilter.java deleted file mode 100644 index 8c13c1643d5d..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/ControlStructureFilter.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.control; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.ElementFilter; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; -import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; -import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrWhileStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner; - -/** - * @author ilyas - */ - - -public class ControlStructureFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - final int offset = context.getTextRange().getStartOffset(); - PsiElement prevSibling = context.getPrevSibling(); - if (context.getParent() instanceof GrReferenceElement && prevSibling != null && prevSibling.getNode() != null) { - ASTNode node = prevSibling.getNode(); - return !TokenSets.DOTS.contains(node.getElementType()); - } - if (GroovyCompletionUtil.isNewStatement(context, true)) { - final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(offset - 1, context); - if (leaf != null && leaf.getParent() instanceof GrStatementOwner) { - return true; - } - } - - if (context.getParent() != null) { - PsiElement parent = context.getParent(); - - if (parent instanceof GrExpression && - parent.getParent() instanceof GroovyFile) { - return true; - } - - if (parent instanceof GrReferenceExpression) { - - PsiElement superParent = parent.getParent(); - if (superParent instanceof GrExpression) { - superParent = superParent.getParent(); - } - - if (superParent instanceof GrStatementOwner || - superParent instanceof GrIfStatement || - superParent instanceof GrForStatement || - superParent instanceof GrWhileStatement) { - return true; - } - } - - return false; - } - - return false; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "Control structure keywords filter"; - } -} \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/additional/CaseDefaultFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/additional/CaseDefaultFilter.java deleted file mode 100644 index aac5b6807d20..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/additional/CaseDefaultFilter.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.control.additional; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.ElementFilter; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrSwitchStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseSection; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; -import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; - -/** - * @author ilyas - */ -public class CaseDefaultFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - if (context.getParent() instanceof GrReferenceExpression && - context.getParent().getParent() instanceof GrCaseSection) { - return true; - } - final PsiElement left = GroovyCompletionUtil.nearestLeftSibling(context); - if (left != null && left.getParent() != null && - left.getParent() instanceof GrSwitchStatement && - left.getPrevSibling() != null && - left.getPrevSibling().getNode() != null && - GroovyTokenTypes.mLCURLY.equals(left.getPrevSibling().getNode().getElementType())) { - return true; - } - return false; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "filter for 'case' and 'default' keywords "; - } -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/additional/CatchFinallyFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/additional/CatchFinallyFilter.java deleted file mode 100644 index cbf8d75c7fac..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/additional/CatchFinallyFilter.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.control.additional; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiErrorElement; -import com.intellij.psi.filters.ElementFilter; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTryCatchStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; - -/** - * @author ilyas - */ -public class CatchFinallyFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - if (context != null && - GroovyCompletionUtil.nearestLeftSibling(context) instanceof GrTryCatchStatement) { - GrTryCatchStatement tryStatement = (GrTryCatchStatement) GroovyCompletionUtil.nearestLeftSibling(context); - if (tryStatement == null) return false; - if (tryStatement.getFinallyClause() == null) { - return true; - } - } - if (context != null && - GroovyCompletionUtil.nearestLeftSibling(context) instanceof PsiErrorElement && - GroovyCompletionUtil.nearestLeftSibling(context).getPrevSibling() instanceof GrTryCatchStatement) { - GrTryCatchStatement tryStatement = (GrTryCatchStatement) GroovyCompletionUtil.nearestLeftSibling(context).getPrevSibling(); - if (tryStatement == null) return false; - if (tryStatement.getFinallyClause() == null) { - return true; - } - } - if (context != null && - (context.getParent() instanceof GrReferenceExpression || context.getParent() instanceof PsiErrorElement) && - GroovyCompletionUtil.nearestLeftSibling(context.getParent()) instanceof GrTryCatchStatement) { - GrTryCatchStatement tryStatement = (GrTryCatchStatement) GroovyCompletionUtil.nearestLeftSibling(context.getParent()); - if (tryStatement == null) return false; - if (tryStatement.getFinallyClause() == null) { - return true; - } - } - return false; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "filter fo 'catch' and 'finally' keywords"; - } - -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/additional/ElseFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/additional/ElseFilter.java deleted file mode 100644 index ab2ec966572a..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/additional/ElseFilter.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.control.additional; - -import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; - -/** - * @author ilyas - */ -public class ElseFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - if (context.getParent() != null && - GroovyCompletionUtil.nearestLeftSibling(context.getParent()) instanceof GrIfStatement) { - GrIfStatement statement = (GrIfStatement) GroovyCompletionUtil.nearestLeftSibling(context.getParent()); - if (statement.getElseBranch() == null) { - return true; - } - return true; - } - if (context.getParent() != null && - GroovyCompletionUtil.nearestLeftSibling(context) != null && - GroovyCompletionUtil.nearestLeftSibling(context).getPrevSibling() instanceof GrIfStatement) { - GrIfStatement statement = (GrIfStatement) GroovyCompletionUtil.nearestLeftSibling(context).getPrevSibling(); - if (statement.getElseBranch() == null) { - return true; - } - } - if (context.getParent() != null && - context.getParent().getParent() instanceof GrCommandArgumentList && - context.getParent().getParent().getParent().getParent() instanceof GrIfStatement) { - GrIfStatement statement = (GrIfStatement) context.getParent().getParent().getParent().getParent(); - if (statement.getElseBranch() == null) { - return true; - } - } - return false; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "filter for 'else' keyword"; - } - -} \ No newline at end of file From fb65f8d121799d1bf32fbafbdb9ed88a8392e137 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 17:32:54 +0200 Subject: [PATCH 051/250] inline simple expression filters --- .../lang/completion/GroovyCompletionData.java | 17 ++----- .../filters/exprs/SimpleExpressionFilter.java | 47 ------------------- 2 files changed, 4 insertions(+), 60 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/exprs/SimpleExpressionFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index d17f8187dab1..86e60d61575b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -38,7 +38,6 @@ import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.completion.filters.control.BranchFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.exprs.InstanceOfFilter; -import org.jetbrains.plugins.groovy.lang.completion.filters.exprs.SimpleExpressionFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.modifiers.*; import org.jetbrains.plugins.groovy.lang.completion.filters.types.BuiltInTypeAsArgumentFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.types.BuiltInTypeFilter; @@ -89,6 +88,10 @@ public class GroovyCompletionData extends CompletionData { addTypeDefinitionKeywords(result, position); addExtendsImplements(position, result); registerControlCompletion(position, result); + + if (position.getParent() instanceof GrExpression && !(position.getParent() instanceof GrLiteral)) { + addKeywords(result, "true", "false", "null", "super", "new", "this", "as"); + } } } @@ -151,7 +154,6 @@ public class GroovyCompletionData extends CompletionData { * Registers completions on top level of Groovy script file */ private void registerAllCompletions() { - registerSimpleExprsCompletion(); registerBuiltInTypeCompletion(); registerBuiltInTypesAsArgumentCompletion(); registerInstanceofCompletion(); @@ -198,16 +200,6 @@ public class GroovyCompletionData extends CompletionData { registerStandardCompletion(filter, BUILT_IN_TYPES); } - private void registerSimpleExprsCompletion() { - String[] exprs = {"true", "false", "null", "super", "new", "this", "as"}; - registerStandardCompletion(new SimpleExpressionFilter() { - @Override - public boolean isAcceptable(Object element, PsiElement context) { - return super.isAcceptable(element, context) && !(context.getParent() instanceof GrLiteral); - } - }, exprs); - } - private void registerThrowsCompletion() { registerStandardCompletion(new ThrowsFilter(), "throws"); } @@ -493,7 +485,6 @@ public class GroovyCompletionData extends CompletionData { private static boolean afterIfOrElse(PsiElement context) { if (context.getParent() != null && GroovyCompletionUtil.nearestLeftSibling(context.getParent()) instanceof GrIfStatement) { - GrIfStatement statement = (GrIfStatement) GroovyCompletionUtil.nearestLeftSibling(context.getParent()); return true; } if (context.getParent() != null && diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/exprs/SimpleExpressionFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/exprs/SimpleExpressionFilter.java deleted file mode 100644 index 459d0e967337..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/exprs/SimpleExpressionFilter.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.exprs; - -import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.PsiElement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; -import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; -import org.jetbrains.annotations.NonNls; - -/** - * @author ilyas - */ -public class SimpleExpressionFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - if (context.getParent() != null && - context.getParent() instanceof GrExpression) { - return true; - } - - return false; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "Simple expressions keywords filter"; - } -} \ No newline at end of file From 0f6f3c0ab03446b2c2fb3713d5d8fefe8069edcd Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 17:37:53 +0200 Subject: [PATCH 052/250] inline primitives filters --- .../lang/completion/GroovyCompletionData.java | 76 +++++++++++++-- .../filters/modifiers/ThrowsFilter.java | 22 +---- .../filters/types/BuiltInTypeFilter.java | 92 ------------------- 3 files changed, 72 insertions(+), 118 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/types/BuiltInTypeFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 86e60d61575b..9a9595da0f25 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -34,13 +34,13 @@ import com.intellij.psi.filters.position.LeftNeighbour; import com.intellij.psi.filters.position.ParentElementFilter; import com.intellij.psi.impl.source.tree.LeafPsiElement; import com.intellij.psi.templateLanguages.OuterLanguageElement; +import com.intellij.psi.util.PsiTreeUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.completion.filters.control.BranchFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.exprs.InstanceOfFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.modifiers.*; import org.jetbrains.plugins.groovy.lang.completion.filters.types.BuiltInTypeAsArgumentFilter; -import org.jetbrains.plugins.groovy.lang.completion.filters.types.BuiltInTypeFilter; import org.jetbrains.plugins.groovy.lang.completion.getters.SuggestedVariableNamesGetter; import org.jetbrains.plugins.groovy.lang.groovydoc.lexer.GroovyDocTokenTypes; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocInlinedTag; @@ -51,10 +51,16 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation; import org.jetbrains.plugins.groovy.lang.psi.api.statements.*; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseSection; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.*; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; +import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement; +import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; @@ -92,6 +98,10 @@ public class GroovyCompletionData extends CompletionData { if (position.getParent() instanceof GrExpression && !(position.getParent() instanceof GrLiteral)) { addKeywords(result, "true", "false", "null", "super", "new", "this", "as"); } + + if (suggestPrimitiveTypes(position) && !suggestThrows(position)) { + addKeywords(result, BUILT_IN_TYPES); + } } } @@ -154,7 +164,6 @@ public class GroovyCompletionData extends CompletionData { * Registers completions on top level of Groovy script file */ private void registerAllCompletions() { - registerBuiltInTypeCompletion(); registerBuiltInTypesAsArgumentCompletion(); registerInstanceofCompletion(); registerThrowsCompletion(); @@ -191,10 +200,6 @@ public class GroovyCompletionData extends CompletionData { } } - private void registerBuiltInTypeCompletion() { - registerStandardCompletion(new AndFilter(new BuiltInTypeFilter(), new NotFilter(new ThrowsFilter())), BUILT_IN_TYPES); - } - private void registerBuiltInTypesAsArgumentCompletion() { AndFilter filter = new AndFilter(new BuiltInTypeAsArgumentFilter(), new NotFilter(new ThrowsFilter())); registerStandardCompletion(filter, BUILT_IN_TYPES); @@ -505,4 +510,63 @@ public class GroovyCompletionData extends CompletionData { } return false; } + + public static boolean suggestThrows(PsiElement context) { + PsiElement candidate = null; + if (GroovyCompletionUtil.isInTypeDefinitionBody(context)) { + PsiElement run = context; + while(!(run.getParent() instanceof GrTypeDefinitionBody)) { + run = run.getParent(); + assert run != null; + } + candidate = PsiTreeUtil.getPrevSiblingOfType(run, GrMember.class); + } + else if (context.getParent() instanceof PsiErrorElement) { + candidate = context.getParent().getPrevSibling(); + } + + return candidate instanceof GrMethod && ((GrMethod) candidate).getBlock() == null; + } + + private static boolean suggestPrimitiveTypes(PsiElement context) { + if (InstanceOfFilter.isInfixOperatorPosition(context)) { + return false; + } + + final PsiElement parent = context.getParent(); + if (parent == null) return false; + + PsiElement previous = PsiImplUtil.realPrevious(parent.getPrevSibling()); + if (previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType())) { + return false; + } + if (GroovyCompletionUtil.asSimpleVariable(context) || + GroovyCompletionUtil.asTypedMethod(context) || + GroovyCompletionUtil.asVariableInBlock(context)) { + return true; + } + if ((parent instanceof GrParameter && + ((GrParameter)parent).getTypeElementGroovy() == null) || + parent instanceof GrReferenceElement && + !(parent.getParent() instanceof GrImportStatement) && + !(parent.getParent() instanceof GrPackageDefinition) && + !(parent.getParent() instanceof GrArgumentList)) { + PsiElement prevSibling = context.getPrevSibling(); + if (parent instanceof GrReferenceElement && prevSibling != null && prevSibling.getNode() != null) { + ASTNode node = prevSibling.getNode(); + return !TokenSets.DOTS.contains(node.getElementType()); + } else { + return true; + } + } + if (PsiImplUtil.realPrevious(parent.getPrevSibling()) instanceof GrModifierList) { + return true; + } + if (PsiImplUtil.realPrevious(context.getPrevSibling()) instanceof GrModifierList) { + return true; + } + return parent instanceof GrExpression && + parent.getParent() instanceof GroovyFile && + GroovyCompletionUtil.isNewStatement(context, false); + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/ThrowsFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/ThrowsFilter.java index dedd83d298b9..39a0ffa4430b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/ThrowsFilter.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/ThrowsFilter.java @@ -17,14 +17,9 @@ package org.jetbrains.plugins.groovy.lang.completion.filters.modifiers; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiErrorElement; import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember; +import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionData; /** * @author ilyas @@ -32,20 +27,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMe public class ThrowsFilter implements ElementFilter { public boolean isAcceptable(Object element, PsiElement context) { - PsiElement candidate = null; - if (GroovyCompletionUtil.isInTypeDefinitionBody(context)) { - PsiElement run = context; - while(!(run.getParent() instanceof GrTypeDefinitionBody)) { - run = run.getParent(); - assert run != null; - } - candidate = PsiTreeUtil.getPrevSiblingOfType(run, GrMember.class); - } - else if (context.getParent() instanceof PsiErrorElement) { - candidate = context.getParent().getPrevSibling(); - } - - return candidate instanceof GrMethod && ((GrMethod) candidate).getBlock() == null; + return GroovyCompletionData.suggestThrows(context); } public boolean isClassAcceptable(Class hintClass) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/types/BuiltInTypeFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/types/BuiltInTypeFilter.java deleted file mode 100644 index 9c522dfefa92..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/types/BuiltInTypeFilter.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.types; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.ElementFilter; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.plugins.groovy.lang.completion.filters.exprs.InstanceOfFilter; -import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; -import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; -import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; -import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; -import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition; -import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; - -/** - * @author ilyas - */ -public class BuiltInTypeFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - if (InstanceOfFilter.isInfixOperatorPosition(context)) { - return false; - } - - final PsiElement parent = context.getParent(); - if (parent == null) return false; - - PsiElement previous = PsiImplUtil.realPrevious(parent.getPrevSibling()); - if (previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType())) { - return false; - } - if (GroovyCompletionUtil.asSimpleVariable(context) || - GroovyCompletionUtil.asTypedMethod(context) || - GroovyCompletionUtil.asVariableInBlock(context)) { - return true; - } - if ((parent instanceof GrParameter && - ((GrParameter)parent).getTypeElementGroovy() == null) || - parent instanceof GrReferenceElement && - !(parent.getParent() instanceof GrImportStatement) && - !(parent.getParent() instanceof GrPackageDefinition) && - !(parent.getParent() instanceof GrArgumentList)) { - PsiElement prevSibling = context.getPrevSibling(); - if (parent instanceof GrReferenceElement && prevSibling != null && prevSibling.getNode() != null) { - ASTNode node = prevSibling.getNode(); - return !TokenSets.DOTS.contains(node.getElementType()); - } else { - return true; - } - } - if (PsiImplUtil.realPrevious(parent.getPrevSibling()) instanceof GrModifierList) { - return true; - } - if (PsiImplUtil.realPrevious(context.getPrevSibling()) instanceof GrModifierList) { - return true; - } - return parent instanceof GrExpression && - parent.getParent() instanceof GroovyFile && - GroovyCompletionUtil.isNewStatement(context, false); - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "built-in-types keywords filter"; - } - -} From a3f3ab35201c816f5d88d89e0ed57ee48d496805 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 17:43:18 +0200 Subject: [PATCH 053/250] inline yet another primitives filter --- .../lang/completion/GroovyCompletionData.java | 19 ++++-- .../types/BuiltInTypeAsArgumentFilter.java | 64 ------------------- .../groovy/oldCompletion/keyword/ins2.test | 1 - 3 files changed, 12 insertions(+), 72 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/types/BuiltInTypeAsArgumentFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 9a9595da0f25..3a1ccf5085d6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -40,7 +40,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.completion.filters.control.BranchFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.exprs.InstanceOfFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.modifiers.*; -import org.jetbrains.plugins.groovy.lang.completion.filters.types.BuiltInTypeAsArgumentFilter; import org.jetbrains.plugins.groovy.lang.completion.getters.SuggestedVariableNamesGetter; import org.jetbrains.plugins.groovy.lang.groovydoc.lexer.GroovyDocTokenTypes; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocInlinedTag; @@ -164,7 +163,6 @@ public class GroovyCompletionData extends CompletionData { * Registers completions on top level of Groovy script file */ private void registerAllCompletions() { - registerBuiltInTypesAsArgumentCompletion(); registerInstanceofCompletion(); registerThrowsCompletion(); registerBranchCompletion(); @@ -200,11 +198,6 @@ public class GroovyCompletionData extends CompletionData { } } - private void registerBuiltInTypesAsArgumentCompletion() { - AndFilter filter = new AndFilter(new BuiltInTypeAsArgumentFilter(), new NotFilter(new ThrowsFilter())); - registerStandardCompletion(filter, BUILT_IN_TYPES); - } - private void registerThrowsCompletion() { registerStandardCompletion(new ThrowsFilter(), "throws"); } @@ -537,6 +530,18 @@ public class GroovyCompletionData extends CompletionData { if (parent == null) return false; PsiElement previous = PsiImplUtil.realPrevious(parent.getPrevSibling()); + if (parent instanceof GrReferenceElement && parent.getParent() instanceof GrArgumentList) { + PsiElement prevSibling = context.getPrevSibling(); + if (prevSibling != null && prevSibling.getNode() != null) { + if (!TokenSets.DOTS.contains(prevSibling.getNode().getElementType())) { + return true; + } + } else if (!(previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType()))) { + return true; + } + + } + if (previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType())) { return false; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/types/BuiltInTypeAsArgumentFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/types/BuiltInTypeAsArgumentFilter.java deleted file mode 100644 index 57ab3de591ba..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/types/BuiltInTypeAsArgumentFilter.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.types; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.ElementFilter; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; -import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; -import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; -import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; - -/** - * @author ilyas - */ -public class BuiltInTypeAsArgumentFilter implements ElementFilter { - - - public boolean isAcceptable(Object element, PsiElement context) { - final PsiElement parent = context.getParent(); - if (parent == null) { - throw new AssertionError("No parent for " + context); - } - - PsiElement previous = PsiImplUtil.realPrevious(parent.getPrevSibling()); - if (parent instanceof GrReferenceElement && parent.getParent() instanceof GrArgumentList) { - PsiElement prevSibling = context.getPrevSibling(); - if (prevSibling != null && prevSibling.getNode() != null) { - ASTNode node = prevSibling.getNode(); - return !TokenSets.DOTS.contains(node.getElementType()); - } else { - return !(previous != null && GroovyTokenTypes.mAT.equals(previous.getNode().getElementType())); - } - - } - return false; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "built-in-types as arguments filter"; - } - -} diff --git a/plugins/groovy/testdata/groovy/oldCompletion/keyword/ins2.test b/plugins/groovy/testdata/groovy/oldCompletion/keyword/ins2.test index bfbaa5076bc8..40b82525c00e 100644 --- a/plugins/groovy/testdata/groovy/oldCompletion/keyword/ins2.test +++ b/plugins/groovy/testdata/groovy/oldCompletion/keyword/ins2.test @@ -2,4 +2,3 @@ boolean a = b in D ----- in instanceof -int From 12f77436ded33da9885e2d8ddd0e9f7678b8b916 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 17:47:36 +0200 Subject: [PATCH 054/250] inline infix operator & throws filters --- .../lang/completion/GroovyCompletionData.java | 51 +++++++++---- .../filters/exprs/InstanceOfFilter.java | 74 ------------------- 2 files changed, 35 insertions(+), 90 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/exprs/InstanceOfFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 3a1ccf5085d6..d9df838e9549 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -38,7 +38,6 @@ import com.intellij.psi.util.PsiTreeUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.completion.filters.control.BranchFilter; -import org.jetbrains.plugins.groovy.lang.completion.filters.exprs.InstanceOfFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.modifiers.*; import org.jetbrains.plugins.groovy.lang.completion.getters.SuggestedVariableNamesGetter; import org.jetbrains.plugins.groovy.lang.groovydoc.lexer.GroovyDocTokenTypes; @@ -98,7 +97,11 @@ public class GroovyCompletionData extends CompletionData { addKeywords(result, "true", "false", "null", "super", "new", "this", "as"); } - if (suggestPrimitiveTypes(position) && !suggestThrows(position)) { + if (isInfixOperatorPosition(position)) { + addKeywords(result, "in", "instanceof"); + } else if (suggestThrows(position)) { + addKeywords(result, "throws"); + } else if (suggestPrimitiveTypes(position)) { addKeywords(result, BUILT_IN_TYPES); } } @@ -163,8 +166,6 @@ public class GroovyCompletionData extends CompletionData { * Registers completions on top level of Groovy script file */ private void registerAllCompletions() { - registerInstanceofCompletion(); - registerThrowsCompletion(); registerBranchCompletion(); registerModifierCompletion(); registerSynchronizedCompletion(); @@ -198,10 +199,6 @@ public class GroovyCompletionData extends CompletionData { } } - private void registerThrowsCompletion() { - registerStandardCompletion(new ThrowsFilter(), "throws"); - } - private void registerFinalCompletion() { registerStandardCompletion(new AndFilter(new FinalFilter(), new NotFilter(new ThrowsFilter())), "final", "def"); } @@ -210,10 +207,6 @@ public class GroovyCompletionData extends CompletionData { registerStandardCompletion(new SynchronizedFilter(), "synchronized"); } - private void registerInstanceofCompletion() { - registerStandardCompletion(new InstanceOfFilter(), "instanceof", "in"); - } - private void registerBranchCompletion() { registerStandardCompletion(new BranchFilter(), "break", "continue"); } @@ -522,10 +515,6 @@ public class GroovyCompletionData extends CompletionData { } private static boolean suggestPrimitiveTypes(PsiElement context) { - if (InstanceOfFilter.isInfixOperatorPosition(context)) { - return false; - } - final PsiElement parent = context.getParent(); if (parent == null) return false; @@ -574,4 +563,34 @@ public class GroovyCompletionData extends CompletionData { parent.getParent() instanceof GroovyFile && GroovyCompletionUtil.isNewStatement(context, false); } + + private static boolean isInfixOperatorPosition(PsiElement context) { + if (context.getParent() != null && + context.getParent() instanceof GrReferenceExpression && + context.getParent().getParent() != null && + context.getParent().getParent() instanceof GrCommandArgumentList) { + return true; + } + if (GroovyCompletionUtil.nearestLeftSibling(context) instanceof PsiErrorElement && + GroovyCompletionUtil.endsWithExpression(GroovyCompletionUtil.nearestLeftSibling(context).getPrevSibling())) { + return true; + } + if (context.getParent() instanceof PsiErrorElement) { + PsiElement leftSibling = GroovyCompletionUtil.nearestLeftSibling(context.getParent()); + if (leftSibling != null && leftSibling.getLastChild() instanceof GrExpression) { + return true; + } + } + if (context.getParent() instanceof GrReferenceExpression && + GroovyCompletionUtil.nearestLeftSibling(context.getParent()) instanceof PsiErrorElement && + GroovyCompletionUtil.endsWithExpression(GroovyCompletionUtil.nearestLeftSibling(context.getParent()).getPrevSibling())) { + return true; + } + if (context.getParent() instanceof PsiErrorElement && + GroovyCompletionUtil.endsWithExpression(GroovyCompletionUtil.nearestLeftSibling(context.getParent()))) { + return true; + } + + return false; + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/exprs/InstanceOfFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/exprs/InstanceOfFilter.java deleted file mode 100644 index 6368134d11f2..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/exprs/InstanceOfFilter.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.exprs; - -import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiErrorElement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.annotations.NonNls; - -/** - * @author ilyas - */ -public class InstanceOfFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - return isInfixOperatorPosition(context); - } - - public static boolean isInfixOperatorPosition(PsiElement context) { - if (context.getParent() != null && - context.getParent() instanceof GrReferenceExpression && - context.getParent().getParent() != null && - context.getParent().getParent() instanceof GrCommandArgumentList) { - return true; - } - if (GroovyCompletionUtil.nearestLeftSibling(context) instanceof PsiErrorElement && - GroovyCompletionUtil.endsWithExpression(GroovyCompletionUtil.nearestLeftSibling(context).getPrevSibling())) { - return true; - } - if (context.getParent() instanceof PsiErrorElement) { - PsiElement leftSibling = GroovyCompletionUtil.nearestLeftSibling(context.getParent()); - if (leftSibling != null && leftSibling.getLastChild() instanceof GrExpression) { - return true; - } - } - if (context.getParent() instanceof GrReferenceExpression && - GroovyCompletionUtil.nearestLeftSibling(context.getParent()) instanceof PsiErrorElement && - GroovyCompletionUtil.endsWithExpression(GroovyCompletionUtil.nearestLeftSibling(context.getParent()).getPrevSibling())) { - return true; - } - if (context.getParent() instanceof PsiErrorElement && - GroovyCompletionUtil.endsWithExpression(GroovyCompletionUtil.nearestLeftSibling(context.getParent()))) { - return true; - } - - return false; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "'instanceof' keyword filter"; - } -} \ No newline at end of file From 8535cba37947f94b2b9f009b8a43db545c41b09e Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 17:52:07 +0200 Subject: [PATCH 055/250] inline break-continue filter --- .../lang/completion/GroovyCompletionData.java | 19 +++--- .../filters/control/BranchFilter.java | 58 ------------------- 2 files changed, 12 insertions(+), 65 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/BranchFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index d9df838e9549..348a187f8810 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -37,7 +37,6 @@ import com.intellij.psi.templateLanguages.OuterLanguageElement; import com.intellij.psi.util.PsiTreeUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.groovy.lang.completion.filters.control.BranchFilter; import org.jetbrains.plugins.groovy.lang.completion.filters.modifiers.*; import org.jetbrains.plugins.groovy.lang.completion.getters.SuggestedVariableNamesGetter; import org.jetbrains.plugins.groovy.lang.groovydoc.lexer.GroovyDocTokenTypes; @@ -65,6 +64,9 @@ import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; import java.util.Set; +import static com.intellij.patterns.PsiJavaPatterns.psiElement; +import static com.intellij.patterns.StandardPatterns.or; + /** * @author ilyas */ @@ -81,6 +83,7 @@ public class GroovyCompletionData extends CompletionData { public static void addGroovyKeywords(CompletionParameters parameters, CompletionResultSet result) { PsiElement position = parameters.getPosition(); + PsiElement parent = position.getParent(); if (!PlatformPatterns.psiElement().afterLeaf(".", ".&").accepts(position)) { if (suggestPackage(position)) { result.addElement(keyword("package")); @@ -93,7 +96,7 @@ public class GroovyCompletionData extends CompletionData { addExtendsImplements(position, result); registerControlCompletion(position, result); - if (position.getParent() instanceof GrExpression && !(position.getParent() instanceof GrLiteral)) { + if (parent instanceof GrExpression && !(parent instanceof GrLiteral)) { addKeywords(result, "true", "false", "null", "super", "new", "this", "as"); } @@ -104,6 +107,13 @@ public class GroovyCompletionData extends CompletionData { } else if (suggestPrimitiveTypes(position)) { addKeywords(result, BUILT_IN_TYPES); } + + if (psiElement(GrReferenceExpression.class).inside(or(psiElement(GrWhileStatement.class), psiElement(GrForStatement.class))).accepts(parent)) { + addKeywords(result, "break", "continue"); + } + else if (psiElement(GrReferenceExpression.class).inside(GrCaseSection.class).accepts(parent)) { + addKeywords(result, "break"); + } } } @@ -166,7 +176,6 @@ public class GroovyCompletionData extends CompletionData { * Registers completions on top level of Groovy script file */ private void registerAllCompletions() { - registerBranchCompletion(); registerModifierCompletion(); registerSynchronizedCompletion(); registerFinalCompletion(); @@ -207,10 +216,6 @@ public class GroovyCompletionData extends CompletionData { registerStandardCompletion(new SynchronizedFilter(), "synchronized"); } - private void registerBranchCompletion() { - registerStandardCompletion(new BranchFilter(), "break", "continue"); - } - private void registerModifierCompletion() { registerStandardCompletion(new ModifiersFilter(), MODIFIERS); registerStandardCompletion(new LeftNeighbour(new PreviousModifierFilter()), "private", "public", "protected", "transient", "abstract", diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/BranchFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/BranchFilter.java deleted file mode 100644 index 074dab1eeee8..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/control/BranchFilter.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.control; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.ElementFilter; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrWhileStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseSection; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; - -/** - * @author ilyas - */ -public class BranchFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - if (context.getParent() != null) { - PsiElement parent = context.getParent(); - return parent instanceof GrReferenceExpression && treeWalkUp(parent); - } - return false; - } - - private boolean treeWalkUp(PsiElement elem) { - PsiElement parent = elem.getParent(); - while (parent != null && - !(parent instanceof GrWhileStatement || - parent instanceof GrForStatement || - parent instanceof GrCaseSection)) { - parent = parent.getParent(); - } - return parent != null; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "'break' and 'continue' keywords filter"; - } -} \ No newline at end of file From c68b24ae2ce4a7f819f978e4144e81cffac00451 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 18:36:30 +0200 Subject: [PATCH 056/250] static is a modifier --- .../groovy/lang/completion/GroovyCompletionData.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 348a187f8810..4a799e7df0e5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -72,7 +72,7 @@ import static com.intellij.patterns.StandardPatterns.or; */ public class GroovyCompletionData extends CompletionData { public static final String[] BUILT_IN_TYPES = {"boolean", "byte", "char", "short", "int", "float", "long", "double", "void"}; - public static final String[] MODIFIERS = new String[]{"private", "public", "protected", "transient", "abstract", "native", "volatile", "strictfp"}; + public static final String[] MODIFIERS = new String[]{"private", "public", "protected", "transient", "abstract", "native", "volatile", "strictfp", "static"}; static final String[] INLINED_DOC_TAGS = {"code", "docRoot", "inheritDoc", "link", "linkplain", "literal"}; static final String[] DOC_TAGS = {"author", "deprecated", "exception", "param", "return", "see", "serial", "serialData", "serialField", "since", "throws", "version"}; @@ -114,6 +114,10 @@ public class GroovyCompletionData extends CompletionData { else if (psiElement(GrReferenceExpression.class).inside(GrCaseSection.class).accepts(parent)) { addKeywords(result, "break"); } + + if (psiElement().afterLeaf("import").withSuperParent(2, GrImportStatement.class).accepts(position)) { + addKeywords(result, "static"); + } } } @@ -218,9 +222,8 @@ public class GroovyCompletionData extends CompletionData { private void registerModifierCompletion() { registerStandardCompletion(new ModifiersFilter(), MODIFIERS); - registerStandardCompletion(new LeftNeighbour(new PreviousModifierFilter()), "private", "public", "protected", "transient", "abstract", - "native", "volatile", "strictfp", "synchronized", "static"); - registerStandardCompletion(new StaticFilter(), "static"); + registerStandardCompletion(new LeftNeighbour(new PreviousModifierFilter()), MODIFIERS); + registerStandardCompletion(new LeftNeighbour(new PreviousModifierFilter()), "synchronized"); } From e2ba7962d5217cccab7a3bc51e064eeb18b40f7e Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 18:37:11 +0200 Subject: [PATCH 057/250] remove the inlined static filter --- .../filters/modifiers/StaticFilter.java | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/StaticFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/StaticFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/StaticFilter.java deleted file mode 100644 index 145dca070a53..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/StaticFilter.java +++ /dev/null @@ -1,31 +0,0 @@ - -package org.jetbrains.plugins.groovy.lang.completion.filters.modifiers; - -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; - -/** - * @author ilyas - */ -public class StaticFilter extends ModifiersFilter{ - - public boolean isAcceptable(Object element, PsiElement context) { - if (context != null && - context.getParent() != null && - context.getParent().getParent() instanceof GrImportStatement) { - PsiElement left = GroovyCompletionUtil.nearestLeftSibling(context.getParent()); - boolean b = left != null && left.getNode() != null && GroovyTokenTypes.kIMPORT.equals(left.getNode().getElementType()); - if (b) return b; - } - return super.isAcceptable(element, context); - } - - @NonNls - public String toString() { - return "Filter for 'static' keyword"; - } - -} From 045eaad38c7d4d9c4bd8abfdaff4115269b024c5 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 18:45:35 +0200 Subject: [PATCH 058/250] inline the modifiers filter --- .../lang/completion/GroovyCompletionData.java | 82 +++++++++++++---- .../filters/modifiers/ModifiersFilter.java | 90 ------------------- .../modifiers/PreviousModifierFilter.java | 53 ----------- 3 files changed, 64 insertions(+), 161 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/ModifiersFilter.java delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/PreviousModifierFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 4a799e7df0e5..e2ef3fdc6fd8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -25,10 +25,7 @@ import com.intellij.codeInsight.completion.CompletionVariant; import com.intellij.codeInsight.lookup.*; import com.intellij.lang.ASTNode; import com.intellij.patterns.PlatformPatterns; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiErrorElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiReference; +import com.intellij.psi.*; import com.intellij.psi.filters.*; import com.intellij.psi.filters.position.LeftNeighbour; import com.intellij.psi.filters.position.ParentElementFilter; @@ -58,6 +55,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMe import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement; import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition; +import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; @@ -101,22 +99,31 @@ public class GroovyCompletionData extends CompletionData { } if (isInfixOperatorPosition(position)) { - addKeywords(result, "in", "instanceof"); + addKeywords(result, "in", PsiKeyword.INSTANCEOF); } else if (suggestThrows(position)) { - addKeywords(result, "throws"); + addKeywords(result, PsiKeyword.THROWS); } else if (suggestPrimitiveTypes(position)) { addKeywords(result, BUILT_IN_TYPES); } if (psiElement(GrReferenceExpression.class).inside(or(psiElement(GrWhileStatement.class), psiElement(GrForStatement.class))).accepts(parent)) { - addKeywords(result, "break", "continue"); + addKeywords(result, PsiKeyword.BREAK, PsiKeyword.CONTINUE); } else if (psiElement(GrReferenceExpression.class).inside(GrCaseSection.class).accepts(parent)) { - addKeywords(result, "break"); + addKeywords(result, PsiKeyword.BREAK); } - if (psiElement().afterLeaf("import").withSuperParent(2, GrImportStatement.class).accepts(position)) { - addKeywords(result, "static"); + if (psiElement().withSuperParent(2, GrImportStatement.class).accepts(position)) { + if (psiElement().afterLeaf(PsiKeyword.IMPORT).accepts(position)) { + addKeywords(result, PsiKeyword.STATIC); + } + } else { + if (suggestModifiers(position)) { + addKeywords(result, MODIFIERS); + } + if (psiElement().afterLeaf(MODIFIERS).accepts(position)) { + addKeywords(result, PsiKeyword.SYNCHRONIZED); + } } } } @@ -180,7 +187,6 @@ public class GroovyCompletionData extends CompletionData { * Registers completions on top level of Groovy script file */ private void registerAllCompletions() { - registerModifierCompletion(); registerSynchronizedCompletion(); registerFinalCompletion(); @@ -220,13 +226,6 @@ public class GroovyCompletionData extends CompletionData { registerStandardCompletion(new SynchronizedFilter(), "synchronized"); } - private void registerModifierCompletion() { - registerStandardCompletion(new ModifiersFilter(), MODIFIERS); - registerStandardCompletion(new LeftNeighbour(new PreviousModifierFilter()), MODIFIERS); - registerStandardCompletion(new LeftNeighbour(new PreviousModifierFilter()), "synchronized"); - } - - @Override public void completeReference(final PsiReference reference, final Set set, @@ -601,4 +600,51 @@ public class GroovyCompletionData extends CompletionData { return false; } + + private static boolean suggestModifiers(PsiElement context) { + if (GroovyCompletionUtil.asSimpleVariable(context) || GroovyCompletionUtil.asTypedMethod(context)) { + return true; + } + if (GroovyCompletionUtil.isFirstElementAfterPossibleModifiersInVariableDeclaration(context, false)) { + return true; + } + + if (psiElement().afterLeaf(MODIFIERS).accepts(context) || psiElement().afterLeaf("synchronized").accepts(context)) { + return true; + } + + final PsiElement contextParent = context.getParent(); + if (contextParent instanceof GrReferenceElement && contextParent.getParent() instanceof GrTypeElement) { + PsiElement parent = contextParent.getParent().getParent(); + if (parent instanceof GrVariableDeclaration && + (parent.getParent() instanceof GrTypeDefinitionBody || parent.getParent() instanceof GroovyFile) || parent instanceof GrMethod) { + return true; + } + } + if (contextParent instanceof GrField) { + final GrVariable variable = (GrVariable)contextParent; + if (variable.getTypeElementGroovy() == null) { + return true; + } + } + if (contextParent instanceof GrExpression && + contextParent.getParent() instanceof GroovyFile && + GroovyCompletionUtil.isNewStatement(context, false)) { + return true; + } + if (context.getTextRange().getStartOffset() == 0 && !(context instanceof OuterLanguageElement)) { + return true; + } + final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(context.getTextRange().getStartOffset() - 1, context); + if (leaf != null && GroovyCompletionUtil.isNewStatement(context, false)) { + PsiElement parent = leaf.getParent(); + if (parent instanceof GroovyFile) { + return true; + } + } + return contextParent instanceof GrExpression && + contextParent.getParent() instanceof GrApplicationStatement && + contextParent.getParent().getParent() instanceof GroovyFile && + GroovyCompletionUtil.isNewStatement(context, false); + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/ModifiersFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/ModifiersFilter.java deleted file mode 100644 index f6e0e44963e1..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/ModifiersFilter.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.modifiers; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.templateLanguages.OuterLanguageElement; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; -import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; -import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; - -/** - * @author ilyas - */ -public class ModifiersFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - if (GroovyCompletionUtil.asSimpleVariable(context) || GroovyCompletionUtil.asTypedMethod(context)) { - return true; - } - if (GroovyCompletionUtil.isFirstElementAfterPossibleModifiersInVariableDeclaration(context, false)) { - return true; - } - final PsiElement contextParent = context.getParent(); - if (contextParent instanceof GrReferenceElement && contextParent.getParent() instanceof GrTypeElement) { - PsiElement parent = contextParent.getParent().getParent(); - if (parent instanceof GrVariableDeclaration && - (parent.getParent() instanceof GrTypeDefinitionBody || parent.getParent() instanceof GroovyFile) || parent instanceof GrMethod) { - return true; - } - } - if (contextParent instanceof GrField) { - final GrVariable variable = (GrVariable)contextParent; - if (variable.getTypeElementGroovy() == null) { - return true; - } - } - if (contextParent instanceof GrExpression && - contextParent.getParent() instanceof GroovyFile && - GroovyCompletionUtil.isNewStatement(context, false)) { - return true; - } - if (context.getTextRange().getStartOffset() == 0 && !(context instanceof OuterLanguageElement)) { - return true; - } - final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(context.getTextRange().getStartOffset() - 1, context); - if (leaf != null && GroovyCompletionUtil.isNewStatement(context, false)) { - PsiElement parent = leaf.getParent(); - if (parent instanceof GroovyFile) { - return true; - } - } - return contextParent instanceof GrExpression && - contextParent.getParent() instanceof GrApplicationStatement && - contextParent.getParent().getParent() instanceof GroovyFile && - GroovyCompletionUtil.isNewStatement(context, false); - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "First filter for modifier keywords"; - } - -} \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/PreviousModifierFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/PreviousModifierFilter.java deleted file mode 100644 index 6ba84393d111..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/PreviousModifierFilter.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.modifiers; - -import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; -import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; - -/** - * @author ilyas - */ -public class PreviousModifierFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - String[] modifiers = new String[]{"private", "public", "protected", "transient", "final", "abstract", - "native", "threadsafe", "volatile", "strictfp", "synchronized"}; - if (element instanceof PsiElement) { - PsiElement psiElement = (PsiElement) element; - - for (String modifier : modifiers) { - if (modifier.equals(psiElement.getText().trim())) { - return true; - } - } - } - return false; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "Second filter for modifier keywords"; - } - -} \ No newline at end of file From d3c189b3cab5d258c9fa9835d8d9d32b2ed94f3c Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 18:46:50 +0200 Subject: [PATCH 059/250] inline synchronized filter --- .../lang/completion/GroovyCompletionData.java | 8 +--- .../filters/modifiers/SynchronizedFilter.java | 42 ------------------- 2 files changed, 2 insertions(+), 48 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/SynchronizedFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index e2ef3fdc6fd8..f00e17f2bfad 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -121,7 +121,8 @@ public class GroovyCompletionData extends CompletionData { if (suggestModifiers(position)) { addKeywords(result, MODIFIERS); } - if (psiElement().afterLeaf(MODIFIERS).accepts(position)) { + if (psiElement().afterLeaf(MODIFIERS).accepts(position) || + GroovyCompletionUtil.isInTypeDefinitionBody(position) && GroovyCompletionUtil.isNewStatement(position, true)) { addKeywords(result, PsiKeyword.SYNCHRONIZED); } } @@ -187,7 +188,6 @@ public class GroovyCompletionData extends CompletionData { * Registers completions on top level of Groovy script file */ private void registerAllCompletions() { - registerSynchronizedCompletion(); registerFinalCompletion(); registerSuggestVariableNameCompletion(); @@ -222,10 +222,6 @@ public class GroovyCompletionData extends CompletionData { registerStandardCompletion(new AndFilter(new FinalFilter(), new NotFilter(new ThrowsFilter())), "final", "def"); } - private void registerSynchronizedCompletion() { - registerStandardCompletion(new SynchronizedFilter(), "synchronized"); - } - @Override public void completeReference(final PsiReference reference, final Set set, diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/SynchronizedFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/SynchronizedFilter.java deleted file mode 100644 index 35aef2f0e9d1..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/SynchronizedFilter.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.modifiers; - -import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.PsiElement; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.annotations.NonNls; - -/** - * @author ilyas - */ -public class SynchronizedFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - return GroovyCompletionUtil.isInTypeDefinitionBody(context) && - GroovyCompletionUtil.isNewStatement(context, true); - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "Synchronized keyword filter"; - } - -} \ No newline at end of file From e18d17a9b2d32ccbd092ac83a3066da504da3ee8 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 18:48:37 +0200 Subject: [PATCH 060/250] inline final filter --- .../lang/completion/GroovyCompletionData.java | 35 +++++++-- .../filters/modifiers/FinalFilter.java | 71 ------------------- 2 files changed, 28 insertions(+), 78 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/FinalFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index f00e17f2bfad..81ed5322a5eb 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -34,7 +34,6 @@ import com.intellij.psi.templateLanguages.OuterLanguageElement; import com.intellij.psi.util.PsiTreeUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.groovy.lang.completion.filters.modifiers.*; import org.jetbrains.plugins.groovy.lang.completion.getters.SuggestedVariableNamesGetter; import org.jetbrains.plugins.groovy.lang.groovydoc.lexer.GroovyDocTokenTypes; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocInlinedTag; @@ -125,6 +124,9 @@ public class GroovyCompletionData extends CompletionData { GroovyCompletionUtil.isInTypeDefinitionBody(position) && GroovyCompletionUtil.isNewStatement(position, true)) { addKeywords(result, PsiKeyword.SYNCHRONIZED); } + if (suggestFinalDef(position)) { + addKeywords(result, PsiKeyword.FINAL, "def"); + } } } } @@ -188,8 +190,6 @@ public class GroovyCompletionData extends CompletionData { * Registers completions on top level of Groovy script file */ private void registerAllCompletions() { - registerFinalCompletion(); - registerSuggestVariableNameCompletion(); } @@ -218,10 +218,6 @@ public class GroovyCompletionData extends CompletionData { } } - private void registerFinalCompletion() { - registerStandardCompletion(new AndFilter(new FinalFilter(), new NotFilter(new ThrowsFilter())), "final", "def"); - } - @Override public void completeReference(final PsiReference reference, final Set set, @@ -643,4 +639,29 @@ public class GroovyCompletionData extends CompletionData { contextParent.getParent().getParent() instanceof GroovyFile && GroovyCompletionUtil.isNewStatement(context, false); } + + public static boolean suggestFinalDef(PsiElement context) { + if (GroovyCompletionUtil.asSimpleVariable(context) || + GroovyCompletionUtil.asTypedMethod(context) || + GroovyCompletionUtil.asVariableInBlock(context)) { + return true; + } + if ((context.getParent() instanceof GrParameter && + ((GrParameter) context.getParent()).getTypeElementGroovy() == null) || + context.getParent() instanceof GrReferenceElement && + !(context.getParent() instanceof GrReferenceExpression) && + !(context.getParent().getParent() instanceof GrImportStatement) && + !(context.getParent().getParent() instanceof GrPackageDefinition)) { + return true; + } + if (PsiImplUtil.realPrevious(context.getParent().getPrevSibling()) instanceof GrModifierList) { + return true; + } + if (PsiImplUtil.realPrevious(context.getPrevSibling()) instanceof GrModifierList) { + return true; + } + return context.getParent() instanceof GrExpression && + context.getParent().getParent() instanceof GroovyFile && + GroovyCompletionUtil.isNewStatement(context, false); + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/FinalFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/FinalFilter.java deleted file mode 100644 index 50d427513c00..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/FinalFilter.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.modifiers; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.ElementFilter; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil; -import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; -import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; -import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition; -import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; - -/** - * @author ilyas - */ -public class FinalFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - if (GroovyCompletionUtil.asSimpleVariable(context) || - GroovyCompletionUtil.asTypedMethod(context) || - GroovyCompletionUtil.asVariableInBlock(context)) { - return true; - } - if ((context.getParent() instanceof GrParameter && - ((GrParameter) context.getParent()).getTypeElementGroovy() == null) || - context.getParent() instanceof GrReferenceElement && - !(context.getParent() instanceof GrReferenceExpression) && - !(context.getParent().getParent() instanceof GrImportStatement) && - !(context.getParent().getParent() instanceof GrPackageDefinition)) { - return true; - } - if (PsiImplUtil.realPrevious(context.getParent().getPrevSibling()) instanceof GrModifierList) { - return true; - } - if (PsiImplUtil.realPrevious(context.getPrevSibling()) instanceof GrModifierList) { - return true; - } - return context.getParent() instanceof GrExpression && - context.getParent().getParent() instanceof GroovyFile && - GroovyCompletionUtil.isNewStatement(context, false); - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "'final' keyword filter"; - } - -} \ No newline at end of file From da0d2c83093827e40486728bfe321c8ed1395cf0 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 18:49:18 +0200 Subject: [PATCH 061/250] cleanup --- .../filters/modifiers/ThrowsFilter.java | 42 ---------------- .../filters/types/ParameterTypeFilter.java | 48 ------------------- 2 files changed, 90 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/ThrowsFilter.java delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/types/ParameterTypeFilter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/ThrowsFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/ThrowsFilter.java deleted file mode 100644 index 39a0ffa4430b..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/modifiers/ThrowsFilter.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.modifiers; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.ElementFilter; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionData; - -/** - * @author ilyas - */ -public class ThrowsFilter implements ElementFilter { - - public boolean isAcceptable(Object element, PsiElement context) { - return GroovyCompletionData.suggestThrows(context); - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "'throws' keyword filter"; - } - -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/types/ParameterTypeFilter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/types/ParameterTypeFilter.java deleted file mode 100644 index 5437903126c2..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/filters/types/ParameterTypeFilter.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.filters.types; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.filters.ElementFilter; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; - -/** - * @author ilyas - */ -public class ParameterTypeFilter implements ElementFilter { - public boolean isAcceptable(Object element, PsiElement context) { - PsiElement parent = context.getParent(); - if (parent instanceof GrParameter) { - GrParameter parameter = (GrParameter) parent; - if (parameter.getTypeElementGroovy() == null) { - return true; - } - } - - return false; - } - - public boolean isClassAcceptable(Class hintClass) { - return true; - } - - @NonNls - public String toString() { - return "Method parameter type filter"; - } -} \ No newline at end of file From b39cfc84d39a58d1cfc9f018e84572adbf9d64f3 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 9 May 2011 18:54:01 +0200 Subject: [PATCH 062/250] inline variable name suggester, no more variants in GroovyCompletionData --- .../GroovyCompletionContributor.java | 36 +++++++++++ .../lang/completion/GroovyCompletionData.java | 26 ++------ .../getters/SuggestedVariableNamesGetter.java | 64 ------------------- 3 files changed, 40 insertions(+), 86 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/getters/SuggestedVariableNamesGetter.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java index 08c398df11c1..27a41637693b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java @@ -28,6 +28,9 @@ import com.intellij.patterns.ElementPattern; import com.intellij.patterns.PsiElementPattern; import com.intellij.patterns.StandardPatterns; import com.intellij.psi.*; +import com.intellij.psi.codeStyle.JavaCodeStyleManager; +import com.intellij.psi.codeStyle.SuggestedNameInfo; +import com.intellij.psi.codeStyle.VariableKind; import com.intellij.psi.filters.ElementFilter; import com.intellij.psi.filters.FilterPositionUtil; import com.intellij.psi.filters.TrueFilter; @@ -50,6 +53,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlo import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod; @@ -58,6 +62,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatem import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; +import org.jetbrains.plugins.groovy.refactoring.inline.InlineMethodConflictSolver; import java.util.*; @@ -269,6 +274,9 @@ public class GroovyCompletionContributor extends CompletionContributor { addKeywords(parameters, result); PsiElement position = parameters.getPosition(); + + suggestVariableNames(position, result); + final PsiElement parent = position.getParent(); if (parent instanceof GrReferenceElement) { GrReferenceElement reference = (GrReferenceElement)parent; @@ -613,4 +621,32 @@ public class GroovyCompletionContributor extends CompletionContributor { } return true; } + + public static void suggestVariableNames(PsiElement context, CompletionResultSet result) { + final PsiElement parent = context.getParent(); + if (parent instanceof GrVariable) { + final GrVariable variable = (GrVariable) parent; + if (context.equals(variable.getNameIdentifierGroovy())) { + final PsiType type = variable.getTypeGroovy(); + if (type != null) { + final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(context.getProject()); + VariableKind kind = variable instanceof GrParameter ? VariableKind.PARAMETER : + variable instanceof GrField ? VariableKind.FIELD : VariableKind.LOCAL_VARIABLE; + SuggestedNameInfo suggestedNameInfo = codeStyleManager.suggestVariableName(kind, null, null, type); + String[] names = suggestedNameInfo.names; + if (names.length > 0) { + String name = names[0]; + String newName = InlineMethodConflictSolver.suggestNewName(name, null, parent); + if (!name.equals(newName)) { + result.addElement(LookupElementBuilder.create(newName)); + return; + } + } + for (String name : names) { + result.addElement(LookupElementBuilder.create(name)); + } + } + } + } + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 81ed5322a5eb..bd24d8fb5acc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -26,15 +26,16 @@ import com.intellij.codeInsight.lookup.*; import com.intellij.lang.ASTNode; import com.intellij.patterns.PlatformPatterns; import com.intellij.psi.*; -import com.intellij.psi.filters.*; +import com.intellij.psi.filters.AndFilter; +import com.intellij.psi.filters.ElementFilter; +import com.intellij.psi.filters.NotFilter; +import com.intellij.psi.filters.TextFilter; import com.intellij.psi.filters.position.LeftNeighbour; -import com.intellij.psi.filters.position.ParentElementFilter; import com.intellij.psi.impl.source.tree.LeafPsiElement; import com.intellij.psi.templateLanguages.OuterLanguageElement; import com.intellij.psi.util.PsiTreeUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.groovy.lang.completion.getters.SuggestedVariableNamesGetter; import org.jetbrains.plugins.groovy.lang.groovydoc.lexer.GroovyDocTokenTypes; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocInlinedTag; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; @@ -74,10 +75,6 @@ public class GroovyCompletionData extends CompletionData { static final String[] DOC_TAGS = {"author", "deprecated", "exception", "param", "return", "see", "serial", "serialData", "serialField", "since", "throws", "version"}; - public GroovyCompletionData() { - registerAllCompletions(); - } - public static void addGroovyKeywords(CompletionParameters parameters, CompletionResultSet result) { PsiElement position = parameters.getPosition(); PsiElement parent = position.getParent(); @@ -186,21 +183,6 @@ public class GroovyCompletionData extends CompletionData { .withTail(LookupElementBuilder.create(keyword).setBold().setInsertHandler(GroovyInsertHandler.INSTANCE), TailType.SPACE); } - /** - * Registers completions on top level of Groovy script file - */ - private void registerAllCompletions() { - registerSuggestVariableNameCompletion(); - } - - private void registerSuggestVariableNameCompletion() { - CompletionVariant variant = new CompletionVariant(new ParentElementFilter(new ClassFilter(GrVariable.class))); - variant.includeScopeClass(LeafPsiElement.class); - variant.addCompletion(new SuggestedVariableNamesGetter(), TailType.NONE); - registerVariant(variant); - } - - private static void registerControlCompletion(PsiElement context, CompletionResultSet result) { String[] controlKeywords = {"try", "while", "with", "switch", "for", "return", "throw", "assert", "synchronized",}; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/getters/SuggestedVariableNamesGetter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/getters/SuggestedVariableNamesGetter.java deleted file mode 100644 index 764f9fb30abc..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/getters/SuggestedVariableNamesGetter.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.plugins.groovy.lang.completion.getters; - -import com.intellij.codeInsight.completion.CompletionContext; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiType; -import com.intellij.psi.codeStyle.JavaCodeStyleManager; -import com.intellij.psi.codeStyle.SuggestedNameInfo; -import com.intellij.psi.codeStyle.VariableKind; -import com.intellij.psi.filters.ContextGetter; -import com.intellij.util.ArrayUtil; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; -import org.jetbrains.plugins.groovy.refactoring.inline.InlineMethodConflictSolver; - -/** - * @author ven - */ -public class SuggestedVariableNamesGetter implements ContextGetter { - public Object[] get(PsiElement context, CompletionContext completionContext) { - //complete variable names - if (context != null) { - final PsiElement parent = context.getParent(); - if (parent instanceof GrVariable) { - final GrVariable variable = (GrVariable) parent; - if (context.equals(variable.getNameIdentifierGroovy())) { - final PsiType type = variable.getTypeGroovy(); - if (type != null) { - final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(context.getProject()); - VariableKind kind = variable instanceof GrParameter ? VariableKind.PARAMETER : - variable instanceof GrField ? VariableKind.FIELD : VariableKind.LOCAL_VARIABLE; - SuggestedNameInfo suggestedNameInfo = codeStyleManager.suggestVariableName(kind, null, null, type); - String[] names = suggestedNameInfo.names; - if (names.length > 0) { - String name = names[0]; - String newName = InlineMethodConflictSolver.suggestNewName(name, null, parent); - if (!name.equals(newName)) { - return new String[]{newName}; - } - } - return names; - } - } - } - } - - return ArrayUtil.EMPTY_OBJECT_ARRAY; - } -} From 1c108b2ed0b135341a68b20ff608b1b76917d7fc Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 12:29:11 +0200 Subject: [PATCH 063/250] GroovyCompletionData is no more CompletionData --- .../GroovyCompletionContributor.java | 20 +---- .../lang/completion/GroovyCompletionData.java | 81 ++----------------- 2 files changed, 8 insertions(+), 93 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java index 27a41637693b..b4e484f65b85 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java @@ -271,7 +271,8 @@ public class GroovyCompletionContributor extends CompletionContributor { protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull final CompletionResultSet result) { - addKeywords(parameters, result); + GroovyCompletionData.addGroovyKeywords(parameters, result); + GroovyCompletionData.addGroovyDocKeywords(parameters, result); PsiElement position = parameters.getPosition(); @@ -324,23 +325,6 @@ public class GroovyCompletionContributor extends CompletionContributor { } - private static void addKeywords(CompletionParameters parameters, CompletionResultSet result) { - GroovyCompletionData.addGroovyKeywords(parameters, result); - - PsiElement position = parameters.getPosition(); - final Set lookupSet = new LinkedHashSet(); - final Set keywordVariants = new HashSet(); - final GroovyCompletionData completionData = new GroovyCompletionData(); - completionData.addKeywordVariants(keywordVariants, position, parameters.getOriginalFile()); - completionData.completeKeywordsBySet(lookupSet, keywordVariants, position, result.getPrefixMatcher(), parameters.getOriginalFile()); - - for (final LookupElement item : lookupSet) { - result.addElement(item); - } - - GroovyCompletionData.addGroovyDocKeywords(parameters, result); - } - @Override public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index bd24d8fb5acc..49ba7bd94fb3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -18,24 +18,17 @@ package org.jetbrains.plugins.groovy.lang.completion; import com.intellij.codeInsight.TailType; -import com.intellij.codeInsight.completion.CompletionData; import com.intellij.codeInsight.completion.CompletionParameters; import com.intellij.codeInsight.completion.CompletionResultSet; -import com.intellij.codeInsight.completion.CompletionVariant; -import com.intellij.codeInsight.lookup.*; +import com.intellij.codeInsight.lookup.LookupElementBuilder; +import com.intellij.codeInsight.lookup.TailTypeDecorator; import com.intellij.lang.ASTNode; import com.intellij.patterns.PlatformPatterns; -import com.intellij.psi.*; -import com.intellij.psi.filters.AndFilter; -import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.filters.NotFilter; -import com.intellij.psi.filters.TextFilter; -import com.intellij.psi.filters.position.LeftNeighbour; -import com.intellij.psi.impl.source.tree.LeafPsiElement; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiErrorElement; +import com.intellij.psi.PsiKeyword; import com.intellij.psi.templateLanguages.OuterLanguageElement; import com.intellij.psi.util.PsiTreeUtil; -import gnu.trove.THashSet; -import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.groovydoc.lexer.GroovyDocTokenTypes; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocInlinedTag; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; @@ -60,15 +53,13 @@ import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; -import java.util.Set; - import static com.intellij.patterns.PsiJavaPatterns.psiElement; import static com.intellij.patterns.StandardPatterns.or; /** * @author ilyas */ -public class GroovyCompletionData extends CompletionData { +public class GroovyCompletionData { public static final String[] BUILT_IN_TYPES = {"boolean", "byte", "char", "short", "int", "float", "long", "double", "void"}; public static final String[] MODIFIERS = new String[]{"private", "public", "protected", "transient", "abstract", "native", "volatile", "strictfp", "static"}; static final String[] INLINED_DOC_TAGS = {"code", "docRoot", "inheritDoc", "link", "linkplain", "literal"}; @@ -200,66 +191,6 @@ public class GroovyCompletionData extends CompletionData { } } - @Override - public void completeReference(final PsiReference reference, - final Set set, - @NotNull final PsiElement position, - final PsiFile file, - final int offset) { - super.completeReference(reference, set, position, file, offset); - Set result = new THashSet(); - for (final LookupElement element : set) { - result.add(LookupElementDecorator.withInsertHandler(element, new GroovyInsertHandlerAdapter())); - } - set.clear(); - set.addAll(result); - } - - - /** - * Template to add all standard keywords completions - * - * @param filter - Semantic filter for given keywords - * @param keywords - Keywords to be completed - */ - private void registerStandardCompletion(ElementFilter filter, String... keywords) { - LeftNeighbour afterDotFilter = new LeftNeighbour(new TextFilter(".", ".&")); - CompletionVariant variant = new CompletionVariant(new AndFilter(new NotFilter(afterDotFilter), filter)); - variant.setItemProperty(LookupItem.HIGHLIGHTED_ATTR, ""); - variant.includeScopeClass(LeafPsiElement.class); - variant.setInsertHandler(new GroovyInsertHandlerAdapter()); - addCompletions(variant, keywords); - registerVariant(variant); - } - - - public String findPrefix(PsiElement insertedElement, int offset) { - if (insertedElement == null) return ""; - final String text = insertedElement.getText(); - final int offsetInElement = offset - insertedElement.getTextRange().getStartOffset(); - int start = offsetInElement - 1; - while (start >= 0) { - final char c = text.charAt(start); - if (!Character.isJavaIdentifierPart(c) && c != '\'') break; - --start; - } - - return text.substring(start + 1, offsetInElement).trim(); - } - - /** - * Adds all completion variants in sequence - * - * @param comps Given completions - * @param variant Variant for completions - */ - private void addCompletions(CompletionVariant variant, String... comps) { - for (String completion : comps) { - variant.addCompletion(completion, TailType.SPACE); - } - } - - public static void addGroovyDocKeywords(CompletionParameters parameters, CompletionResultSet result) { PsiElement position = parameters.getPosition(); if (PlatformPatterns.psiElement(GroovyDocTokenTypes.mGDOC_TAG_NAME).andNot(PlatformPatterns.psiElement().afterLeaf(".")).accepts(position)) { From 3dccdea9c6f4ad152beb5c9d90047730ffcdb870 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 12:50:19 +0200 Subject: [PATCH 064/250] add the lost completion variant, remove duplication --- .../groovy/lang/completion/GroovyCompletionData.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 49ba7bd94fb3..5dd733d78783 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -71,10 +71,10 @@ public class GroovyCompletionData { PsiElement parent = position.getParent(); if (!PlatformPatterns.psiElement().afterLeaf(".", ".&").accepts(position)) { if (suggestPackage(position)) { - result.addElement(keyword("package")); + result.addElement(keyword(PsiKeyword.PACKAGE)); } if (suggestImport(position)) { - result.addElement(keyword("import")); + result.addElement(keyword(PsiKeyword.IMPORT)); } addTypeDefinitionKeywords(result, position); @@ -82,7 +82,7 @@ public class GroovyCompletionData { registerControlCompletion(position, result); if (parent instanceof GrExpression && !(parent instanceof GrLiteral)) { - addKeywords(result, "true", "false", "null", "super", "new", "this", "as"); + addKeywords(result, PsiKeyword.TRUE, PsiKeyword.FALSE, PsiKeyword.NULL, PsiKeyword.SUPER, PsiKeyword.NEW, PsiKeyword.THIS, "as"); } if (isInfixOperatorPosition(position)) { @@ -121,10 +121,10 @@ public class GroovyCompletionData { private static void addTypeDefinitionKeywords(CompletionResultSet result, PsiElement position) { if (suggestClassInterfaceEnum(position)) { - addKeywords(result, "class", "interface", "enum"); + addKeywords(result, PsiKeyword.CLASS, PsiKeyword.INTERFACE, PsiKeyword.ENUM); } if (afterAtInType(position)) { - result.addElement(keyword("interface")); + result.addElement(keyword(PsiKeyword.INTERFACE)); } } @@ -163,7 +163,7 @@ public class GroovyCompletionData { } } - private static void addKeywords(CompletionResultSet result, String... keywords) { + public static void addKeywords(CompletionResultSet result, String... keywords) { for (String s : keywords) { result.addElement(keyword(s)); } From 8433f2c4da908999f64424c11ef67c91bf6d7af4 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 12:59:32 +0200 Subject: [PATCH 065/250] capitals after asterisk should only match word starts --- platform/util/src/com/intellij/psi/codeStyle/NameUtil.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java b/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java index 6e1d5c082166..0af1ceaa513d 100644 --- a/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java +++ b/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java @@ -572,6 +572,7 @@ public class NameUtil { } String nextChar = String.valueOf(myPattern[patternIndex]); + boolean wordStart = isWordStart(myPattern[patternIndex]); int fromIndex = nameIndex; while (true) { @@ -579,6 +580,11 @@ public class NameUtil { if (next < 0) { break; } + if (wordStart && next > 0 && next != nextWord(name, next - 1)) { + fromIndex = next + 1; + continue; + } + FList ranges = matchName(name, patternIndex, next); if (ranges != null) { return ranges; From 0e6a79b80bd2d489cb7fd3b452130e3957d1b014 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 May 2011 15:06:12 +0400 Subject: [PATCH 066/250] ea-27613 --- .../refactorings/introduce/IntroducePropertyAction.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/refactorings/introduce/IntroducePropertyAction.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/refactorings/introduce/IntroducePropertyAction.java index 6d1a031c3b58..a8f1db45a43e 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/refactorings/introduce/IntroducePropertyAction.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/refactorings/introduce/IntroducePropertyAction.java @@ -12,6 +12,7 @@ import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Factory; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; @@ -257,6 +258,10 @@ public class IntroducePropertyAction extends BaseRefactoringAction { for (MavenDomProjectModel model : MavenDomProjectProcessorUtils.getChildrenProjects(myModel)) { collectUsages(model); } + + for (UsageInfo2UsageAdapter adapter : UsageInfo2UsageAdapter.convert(usages.toArray(new UsageInfo[usages.size()]))) { + processor.process(adapter); + } } private void collectUsages(@NotNull MavenDomProjectModel model) { @@ -290,10 +295,6 @@ public class IntroducePropertyAction extends BaseRefactoringAction { } } }); - - for (UsageInfo2UsageAdapter adapter : UsageInfo2UsageAdapter.convert(usages.toArray(new UsageInfo[usages.size()]))) { - processor.process(adapter); - } } }; } From db9211631b8a0dd875f743c22691b4fd0288fa23 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Tue, 10 May 2011 15:39:40 +0400 Subject: [PATCH 067/250] detect local vars to wrap into Reference or make final --- .../lang/psi/util/GroovyCommonClassNames.java | 2 + .../convertToJava/ClassItemGeneratorImpl.java | 6 +- .../convertToJava/CodeBlockGenerator.java | 10 +- .../convertToJava/ExpressionContext.java | 11 +- .../convertToJava/ExpressionGenerator.java | 67 +++++++++- .../convertToJava/GenerationUtil.java | 48 ++++++- .../convertToJava/LocalVarAnalyzer.java | 125 ++++++++++++++++++ .../convertToJava/FileGenerationTest.groovy | 3 + .../convertGroovyToJava/file/anonymous.java | 2 +- .../convertGroovyToJava/file/concurency.java | 2 +- .../convertGroovyToJava/file/hash.java | 2 +- .../file/refInAnonymous.groovy | 12 ++ .../file/refInAnonymous.java | 14 ++ .../file/refInClosureInMethod.groovy | 14 ++ .../file/refInClosureInMethod.java | 27 ++++ .../file/refInClosureInScript.groovy | 9 ++ .../file/refInClosureInScript.java | 32 +++++ 17 files changed, 361 insertions(+), 25 deletions(-) create mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/LocalVarAnalyzer.java create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInAnonymous.groovy create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInAnonymous.java create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.groovy create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.java create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInScript.groovy create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInScript.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyCommonClassNames.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyCommonClassNames.java index 9e6e5a2423db..55f48d48a2b5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyCommonClassNames.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GroovyCommonClassNames.java @@ -40,6 +40,8 @@ public final class GroovyCommonClassNames { public static final String GROOVY_TRANSFORM_TUPLE_CONSTRUCTOR = "groovy.transform.TupleConstructor"; public static final String GROOVY_TRANSFORM_IMMUTABLE = "groovy.transform.Immutable"; public static final String GROOVY_TRANSFORM_CANONICAL = "groovy.transform.Canonical"; + @NonNls public static final String GROOVY_LANG_REFERENCE = "groovy.lang.Reference"; + private GroovyCommonClassNames() { } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java index 0b555ff7b3a4..3c161ea067a7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java @@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.codeInspection.noReturnMethod.MissingReturnInspection; import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue; @@ -259,7 +260,10 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { LOG.assertTrue(((GroovyFile)scriptFile).isScript()); final List exitPoints = ControlFlowUtils.collectReturns(scriptFile); - new CodeBlockGenerator(builder, context.extend(), exitPoints) + + ExpressionContext extended = context.extend(); + extended.searchForLocalVarsToWrap((GroovyPsiElement)scriptFile); + new CodeBlockGenerator(builder, extended, exitPoints) .visitStatementOwner((GroovyFile)scriptFile, MissingReturnInspection.methodMissesSomeReturns((GroovyFile)scriptFile, true)); builder.append("\n}\n"); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java index d48c12aaab8d..5438f9e0a1ea 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java @@ -16,7 +16,6 @@ package org.jetbrains.plugins.groovy.refactoring.convertToJava; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.util.containers.hash.HashSet; import org.jetbrains.annotations.Nullable; @@ -74,10 +73,6 @@ public class CodeBlockGenerator extends Generator { } } - public CodeBlockGenerator(StringBuilder builder, Project project) { - this(builder, new ExpressionContext(project)); - } - @Override public StringBuilder getBuilder() { return builder; @@ -89,6 +84,7 @@ public class CodeBlockGenerator extends Generator { } public void generateMethodBody(GrMethod method) { + context.searchForLocalVarsToWrap(method); final GrOpenBlock block = method.getBlock(); boolean shouldInsertReturnNull = false; @@ -105,7 +101,7 @@ public class CodeBlockGenerator extends Generator { @Override public void visitMethod(GrMethod method) { - LOG.assertTrue(false, "don't invoke it!!!"); + LOG.error("don't invoke it!!!"); } @Override @@ -159,7 +155,7 @@ public class CodeBlockGenerator extends Generator { } public void visitStatement(GrStatement statement) { - LOG.assertTrue(false, "all statements must be overloaded"); + LOG.error("all statements must be overloaded"); } @Override diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionContext.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionContext.java index f3efa8ebd29c..01f1795a474e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionContext.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionContext.java @@ -15,9 +15,11 @@ */ package org.jetbrains.plugins.groovy.refactoring.convertToJava; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.util.containers.hash.HashMap; import com.intellij.util.containers.hash.HashSet; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import java.util.ArrayList; import java.util.List; @@ -27,8 +29,9 @@ import java.util.Set; class ExpressionContext implements Cloneable { List myStatements = new ArrayList(); Set myUsedVarNames; - Project project; + LocalVarAnalyzer.Result analyzedVars = LocalVarAnalyzer.initialResult(); + Project project; private Map myProps = new HashMap(); private static final String myShouldInsertCurlyBrackets = "shouldInsertCurly"; private static final String myInAnonymousContext = "inAnonymousContext"; @@ -50,6 +53,7 @@ class ExpressionContext implements Cloneable { ExpressionContext copy() { final ExpressionContext expressionContext = new ExpressionContext(project, myUsedVarNames); expressionContext.myProps.putAll(myProps); + expressionContext.analyzedVars = analyzedVars; return expressionContext; } @@ -58,6 +62,7 @@ class ExpressionContext implements Cloneable { usedVarNames.addAll(myUsedVarNames); final ExpressionContext expressionContext = new ExpressionContext(project, usedVarNames); expressionContext.myProps.putAll(myProps); + expressionContext.analyzedVars = analyzedVars; return expressionContext; } @@ -81,4 +86,8 @@ class ExpressionContext implements Cloneable { public void setInAnonymousContext(boolean inAnonymousContext) { myProps.put(myInAnonymousContext, inAnonymousContext); } + + public void searchForLocalVarsToWrap(GroovyPsiElement root) { + analyzedVars = LocalVarAnalyzer.searchForVarsToWrap(root, analyzedVars); + } } \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java index f899911397a4..184f449e1921 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java @@ -326,13 +326,31 @@ public class ExpressionGenerator extends Generator { GrExpression rValue = expression.getRValue(); final IElementType token = expression.getOperationToken(); + boolean toWrap = false; + + PsiElement realLValue = PsiUtil.skipParentheses(lValue, false); + if (realLValue instanceof GrReferenceExpression) { + PsiElement resolved = ((GrReferenceExpression)realLValue).resolve(); + if (resolved instanceof GrVariable && context.analyzedVars.toWrap((GrVariable)resolved)) toWrap = true; + } + + if (token == mASSIGN) { lValue.accept(this); - builder.append(" = "); + + if (toWrap) { + builder.append(".set("); + } + else { + builder.append(" = "); + } if (rValue != null) { rValue.accept(this); } + if (toWrap) { + builder.append(')'); + } return; } @@ -341,23 +359,44 @@ public class ExpressionGenerator extends Generator { if (resolved instanceof PsiMethod) { lValue.accept(this); - builder.append(" = "); + if (toWrap) { + builder.append(".set("); + } + else { + builder.append(" = "); + } + if (rValue == null) { rValue = factory.createExpressionFromText("null"); } invokeMethodOn( ((PsiMethod)resolved), - lValue, + (GrExpression)lValue.copy(), new GrExpression[]{rValue}, GrNamedArgument.EMPTY_ARRAY, GrClosableBlock.EMPTY_ARRAY, resolveResult.getSubstitutor(), expression ); + if (toWrap) { + builder.append(')'); + } } else { + if (toWrap) { + lValue.accept(this); + builder.append(".set("); + + GrBinaryExpression bin = + (GrBinaryExpression)factory.createExpressionFromText("a" + expression.getOpToken().getText().charAt(0) + "b", expression); + GrExpression newLValue = (GrExpression)bin.getLeftOperand().replace(lValue); + GrExpression newRValue = rValue == null ? null : (GrExpression)bin.getRightOperand().replace(rValue); + writeSimpleBinaryExpression(bin.getOperationToken(), newLValue, newRValue); + builder.append(')'); + } writeSimpleBinaryExpression(expression.getOpToken(), lValue, rValue); } + } @Override @@ -521,15 +560,25 @@ public class ExpressionGenerator extends Generator { if (addParentheses) { builder.append('('); } - operand.accept(this); - builder.append(" = "); + boolean wrap = context.analyzedVars.toWrap((GrVariable)resolved); + if (wrap) { + operand.accept(this); + builder.append(".set("); + } + else { + operand.accept(this); + builder.append(" = "); + } invokeMethodOn( method, - operand, + (GrExpression)operand.copy(), GrExpression.EMPTY_ARRAY, GrNamedArgument.EMPTY_ARRAY, GrClosableBlock.EMPTY_ARRAY, resolveResult.getSubstitutor(), unary ); + if (wrap) { + builder.append(')'); + } if (addParentheses) { builder.append(')'); } @@ -635,6 +684,12 @@ public class ExpressionGenerator extends Generator { if (resolved instanceof PsiNamedElement) { final String refName = ((PsiNamedElement)resolved).getName(); builder.append(refName); + if (context.analyzedVars != null && + resolved instanceof GrVariable && + context.analyzedVars.toWrap((GrVariable)resolved) && + !PsiUtil.isAccessedForWriting(referenceExpression)) { + builder.append(".get()"); + } } else { final String refName = referenceExpression.getReferenceName(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java index 4f8686dccfbb..ef2724df3adb 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java @@ -36,6 +36,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; +import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; import org.jetbrains.plugins.groovy.refactoring.DefaultGroovyVariableNameValidator; @@ -372,9 +373,9 @@ public class GenerationUtil { ExpressionContext expressionContext) { GrVariable[] variables = variableDeclaration.getVariables(); - Set types = getVarTypes(variableDeclaration); + //Set types = getVarTypes(variableDeclaration); - if (types.size() > 1) { + //if (types.size() > 1) { if (variableDeclaration.getParent() instanceof GrControlStatement) { expressionContext.setInsertCurlyBrackets(); } @@ -382,8 +383,11 @@ public class GenerationUtil { writeVariableSeparately(variable, builder, expressionContext); builder.append(";\n"); } - return; + builder.delete(builder.length() - 1, builder.length()); + /*return; } + + ModifierListGenerator.writeModifiers(builder, variableDeclaration.getModifierList()); PsiType type = getVarType(variables[0]); @@ -397,26 +401,56 @@ public class GenerationUtil { if (variables.length > 0) { builder.delete(builder.length() - 2, builder.length()); } - builder.append(";"); + builder.append(";");*/ } - static void writeVariableWithoutType(StringBuilder builder, ExpressionContext expressionContext, GrVariable variable) { + static void writeVariableWithoutType(StringBuilder builder, + ExpressionContext expressionContext, + GrVariable variable, + boolean wrapped, + PsiType original) { builder.append(variable.getName()); final GrExpression initializer = variable.getInitializerGroovy(); if (initializer != null) { builder.append(" = "); + if (wrapped) { + builder.append("new ").append(GroovyCommonClassNames.GROOVY_LANG_REFERENCE); + if (original != null) { + builder.append('<'); + writeType(builder, original, variable, new GeneratorClassNameProvider()); + builder.append('>'); + } + builder.append('('); + } initializer.accept(new ExpressionGenerator(builder, expressionContext)); + if (wrapped) { + builder.append(')'); + } } } static void writeVariableSeparately(GrVariable variable, StringBuilder builder, ExpressionContext expressionContext) { PsiType type = getVarType(variable); - ModifierListGenerator.writeModifiers(builder, variable.getModifierList()); + PsiType originalType = type; + LocalVarAnalyzer.Result analyzedVars = expressionContext.analyzedVars; + boolean wrapped = false; + if (analyzedVars != null) { + if (analyzedVars.toMakeFinal(variable) && !variable.hasModifierProperty(PsiModifier.FINAL)) { + builder.append(PsiModifier.FINAL).append(' '); + } + else if (analyzedVars.toWrap(variable)) { + builder.append(PsiModifier.FINAL).append(' '); + type = JavaPsiFacade.getElementFactory(expressionContext.project).createTypeFromText( + GroovyCommonClassNames.GROOVY_LANG_REFERENCE + "<" + getTypeText(type, variable) + ">", variable); + wrapped = true; + } + } + writeType(builder, type, variable); builder.append(" "); - writeVariableWithoutType(builder, expressionContext, variable); + writeVariableWithoutType(builder, expressionContext, variable, wrapped, originalType); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/LocalVarAnalyzer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/LocalVarAnalyzer.java new file mode 100644 index 000000000000..f88f66d525c2 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/LocalVarAnalyzer.java @@ -0,0 +1,125 @@ +/* + * Copyright 2000-2011 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 org.jetbrains.plugins.groovy.refactoring.convertToJava; + +import com.intellij.psi.PsiAnonymousClass; +import com.intellij.psi.PsiElement; +import com.intellij.util.containers.HashSet; +import gnu.trove.TObjectIntHashMap; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; +import org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; +import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; +import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringUtil; + +import java.util.Set; + +/** + * @author Medvedev Max + */ +class LocalVarAnalyzer extends GroovyRecursiveElementVisitor { + static class Result { + private final Set toMakeFinal; + private final Set toWrap; + + private Result(Set toMakeFinal, Set toWrap) { + this.toMakeFinal = toMakeFinal; + this.toWrap = toWrap; + } + + boolean toWrap(GrVariable variable) { + return toWrap.contains(variable); + } + boolean toMakeFinal(GrVariable variable) { + return toMakeFinal.contains(variable); + } + } + + + public static Result searchForVarsToWrap(GroovyPsiElement root, Result analyzedVars) { + LocalVarAnalyzer visitor = new LocalVarAnalyzer(); + root.accept(visitor); + + Set toWrap = analyzedVars == null ? new HashSet() : analyzedVars.toWrap; + Set toMakeFinal = analyzedVars == null ? new HashSet() : analyzedVars.toMakeFinal; + for (GrVariable v : visitor.touched) { + if (visitor.rewritten.contains(v)) { + toWrap.add(v); + } + else { + toMakeFinal.add(v); + } + } + return analyzedVars == null ? new Result(toMakeFinal, toWrap) : analyzedVars; + } + + public static Result initialResult() { + return new Result(new HashSet(), new HashSet()); + } + + private final Set touched = new HashSet(); + private final Set rewritten = new HashSet(); + private final TObjectIntHashMap allVars = new TObjectIntHashMap(); + + private int grade = 0; + + private LocalVarAnalyzer() { + } + + + @Override + public void visitClosure(GrClosableBlock closure) { + grade++; + super.visitClosure(closure); + grade--; + } + + @Override + public void visitTypeDefinition(GrTypeDefinition typeDefinition) { + if (!(typeDefinition instanceof PsiAnonymousClass)) return; + grade++; + super.visitTypeDefinition(typeDefinition); + grade--; + } + + @Override + public void visitVariable(GrVariable variable) { + super.visitVariable(variable); + if (!GroovyRefactoringUtil.isLocalVariable(variable)) return; + allVars.put(variable, grade); + } + + @Override + public void visitReferenceExpression(GrReferenceExpression ref) { + super.visitReferenceExpression(ref); + PsiElement resolved = ref.resolve(); + if (!allVars.contains(resolved)) return; + GrVariable var = (GrVariable)resolved; + + if (PsiUtil.isAccessedForWriting(ref)) { + rewritten.add(var); + } + + if (allVars.get(var) < grade) { + touched.add((GrVariable)resolved); + } + } + + +} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy index 14b09ca510c2..03a5b1e7be76 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy @@ -60,4 +60,7 @@ class FileGenerationTest extends LightGroovyTestCase { void testHash() {doTest()} void testAnonymous() {doTest()} void testAnonymous2() {doTest()} + void testRefInAnonymous() {doTest()} + void testRefInClosureInMethod() {doTest()} + void testRefInClosureInScript() {doTest()} } diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous.java index 9a84ea66616e..14d72b9f59d8 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/anonymous.java @@ -4,7 +4,7 @@ new anonymous(new groovy.lang.Binding(args)).run(); } public java.lang.Object run() { -java.lang.Integer foo = 2; +final java.lang.Integer foo = 2; java.lang.Runnable an = new java.lang.Runnable(){ public void run() { org.codehaus.groovy.runtime.DefaultGroovyMethods.println(this, foo); diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/concurency.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/concurency.java index 41b5b8888498..af7bfcd52511 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/concurency.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/concurency.java @@ -4,7 +4,7 @@ new concurency(new groovy.lang.Binding(args)).run(); } public java.lang.Object run() { -java.util.concurrent.atomic.AtomicInteger counter = new java.util.concurrent.atomic.AtomicInteger(); +final java.util.concurrent.atomic.AtomicInteger counter = new java.util.concurrent.atomic.AtomicInteger(); java.lang.Thread th = org.codehaus.groovy.runtime.DefaultGroovyStaticMethods.start(null, new groovy.lang.Closure(this, this) { public void doCall(java.lang.Object it) { for(java.lang.Integer i : new groovy.lang.IntRange(1, 8)){ diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/hash.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/hash.java index e349f9777ff8..70e19f5c688c 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/hash.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/hash.java @@ -12,7 +12,7 @@ println("Invalid file " + java.lang.String.valueOf(f) + " provided"); println("Usage: groovy sha1.groovy "); } -java.lang.Object messageDigest = hash.this.getBinding().getProperty("MessageDigest").getInstance.call("SHA1"); +final java.lang.Object messageDigest = hash.this.getBinding().getProperty("MessageDigest").getInstance.call("SHA1"); long start = java.lang.System.currentTimeMillis(); org.codehaus.groovy.runtime.DefaultGroovyMethods.eachByte(f, MB, new groovy.lang.Closure(this, this) { public java.lang.Object doCall(java.lang.Byte[] buf, int bytesRead) { diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInAnonymous.groovy b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInAnonymous.groovy new file mode 100644 index 000000000000..4eb3bfb09123 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInAnonymous.groovy @@ -0,0 +1,12 @@ +class A { + def foo () { + def x = 2 + + new Runnable() { + void run() { + x = 4 + print x + } + }.run() + } +} \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInAnonymous.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInAnonymous.java new file mode 100644 index 000000000000..efc07c54b20f --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInAnonymous.java @@ -0,0 +1,14 @@ +public class A extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { +public java.lang.Object foo() { +final groovy.lang.Reference x = new groovy.lang.Reference(2); +new java.lang.Runnable(){ +public void run() { +x.set(4); +org.codehaus.groovy.runtime.DefaultGroovyMethods.print(this, x.get()); +} + +}.run(); +return null; +} + +} diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.groovy b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.groovy new file mode 100644 index 000000000000..1132445dd1d3 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.groovy @@ -0,0 +1,14 @@ +class X { + def foo() { + def ab = 4 + + each { + each { + ab = 2 + + } + } + + print ab + } +} \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.java new file mode 100644 index 000000000000..c2a0a110318e --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.java @@ -0,0 +1,27 @@ +public class X extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { +public java.lang.Object foo() { +final groovy.lang.Reference ab = new groovy.lang.Reference(4); +org.codehaus.groovy.runtime.DefaultGroovyMethods.each(X.this, new groovy.lang.Closure(this, this) { +public java.lang.Object doCall(java.lang.Object it) { +return org.codehaus.groovy.runtime.DefaultGroovyMethods.each(X.this, new groovy.lang.Closure(this, this) { +public java.lang.Integer doCall(java.lang.Object it) { +return ab.set(2); +} + +public java.lang.Integer doCall() { +return doCall(null); +} + +}); +} + +public java.lang.Object doCall() { +return doCall(null); +} + +}); +org.codehaus.groovy.runtime.DefaultGroovyMethods.print(X.this, ab.get()); +return null; +} + +} diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInScript.groovy b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInScript.groovy new file mode 100644 index 000000000000..f88c9f8e3bd8 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInScript.groovy @@ -0,0 +1,9 @@ +def foo = 2 + +3.times { + foo++ + foo+=2 + foo = foo - 1 + foo = 4 + print foo +} \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInScript.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInScript.java new file mode 100644 index 000000000000..5091c1cfaef5 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInScript.java @@ -0,0 +1,32 @@ +public class refInClosureInScript extends groovy.lang.Script { +public static void main(java.lang.String[] args) { +new refInClosureInScript(new groovy.lang.Binding(args)).run(); +} + +public java.lang.Object run() { +final groovy.lang.Reference foo = new groovy.lang.Reference(2); +org.codehaus.groovy.runtime.DefaultGroovyMethods.times(3, new groovy.lang.Closure(this, this) { +public void doCall(java.lang.Object it) { +foo.set(foo.get().next()); +foo.set(foo.get().plus(2)); +foo.set(foo.get() - 1); +foo.set(4); +org.codehaus.groovy.runtime.DefaultGroovyMethods.print(refInClosureInScript.this, foo.get()); +} + +public void doCall() { +doCall(null); +} + +}); +return null; + +} + +public refInClosureInScript(groovy.lang.Binding binding) { +super(binding); +} +public refInClosureInScript() { +super(); +} +} From 21150e7405759fbc6342175253a50ad35bd6fbde Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Tue, 10 May 2011 15:46:47 +0400 Subject: [PATCH 068/250] *.sh scripts updated: [[ .. ]] -> [ .. ] --- bin/nix/idea.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/nix/idea.sh b/bin/nix/idea.sh index 0f579b0c9aec..dab17aec3948 100755 --- a/bin/nix/idea.sh +++ b/bin/nix/idea.sh @@ -9,7 +9,7 @@ # Before you run IntelliJ IDEA specify the location of the # JDK 1.6 installation directory which will be used for running IDEA # --------------------------------------------------------------------- -[[ `uname -s` = "Darwin" ]] && OS_TYPE="MAC" || OS_TYPE="NOT_MAC" +[ `uname -s` = "Darwin" ] && OS_TYPE="MAC" || OS_TYPE="NOT_MAC" if [ -z "$IDEA_JDK" ]; then IDEA_JDK=$JDK_HOME @@ -23,7 +23,7 @@ if [ -z "$IDEA_JDK" ]; then if [ -n "$JAVA_BIN_PATH" ]; then # Mac readlink doesn't support -f option. - [[ "$OS_TYPE" = "MAC" ]] && CANONICALIZE_OPTION="" || CANONICALIZE_OPTION="-f" + [ "$OS_TYPE" = "MAC" ] && CANONICALIZE_OPTION="" || CANONICALIZE_OPTION="-f" JAVA_LOCATION=`readlink $CANONICALIZE_OPTION $JAVA_BIN_PATH | xargs dirname | xargs dirname | xargs dirname` if [ "$OS_TYPE" = "MAC" ]; then @@ -100,7 +100,7 @@ if [ -z "$IDEA_VM_OPTIONS" ]; then IDEA_VM_OPTIONS="$IDEA_HOME/bin/idea.vmoptions" fi -[[ -e $IDEA_HOME/Contents/Info.plist ]] && BUNDLE_TYPE="MAC" || BUNDLE_TYPE="NOT_MAC" +[ -e $IDEA_HOME/Contents/Info.plist ] && BUNDLE_TYPE="MAC" || BUNDLE_TYPE="NOT_MAC" # If vmoptions file exists - use it if [ -e "$IDEA_VM_OPTIONS" ]; then @@ -109,11 +109,11 @@ if [ -e "$IDEA_VM_OPTIONS" ]; then # don't extract vm options from Info.plist in mac bundle INFO_PLIST_PARSER_OPTIONS="" else - [[ "$BUNDLE_TYPE" = "MAC" ]] && [[ "$BITS" == "64" ]] && INFO_PLIST_PARSER_OPTIONS=" 64" || INFO_PLIST_PARSER_OPTIONS=" 32" + [ "$BUNDLE_TYPE" = "MAC" ] && [ "$BITS" == "64" ] && INFO_PLIST_PARSER_OPTIONS=" 64" || INFO_PLIST_PARSER_OPTIONS=" 32" fi # In MacOS ./Contents/Info.plist describes all vm options & system properties -[[ "$OS_TYPE" = "MAC" ]] && [[ "$BUNDLE_TYPE" = "MAC" ]] && [[ -z "$IDEA_PROPERTIES_PROPERTY" ]] && MAC_IDEA_PROPERTIES="`osascript \"$IDEA_BIN_HOME/info_plist_parser.scpt\"$INFO_PLIST_PARSER_OPTIONS`" || MAC_IDEA_PROPERTIES="" +[ "$OS_TYPE" = "MAC" ] && [ "$BUNDLE_TYPE" = "MAC" ] && [ -z "$IDEA_PROPERTIES_PROPERTY" ] && MAC_IDEA_PROPERTIES="`osascript \"$IDEA_BIN_HOME/info_plist_parser.scpt\"$INFO_PLIST_PARSER_OPTIONS`" || MAC_IDEA_PROPERTIES="" REQUIRED_JVM_ARGS="-Xbootclasspath/a:../lib/boot.jar -Didea.paths.selector=@@system_selector@@ $IDEA_PROPERTIES_PROPERTY $REQUIRED_JVM_ARGS $MAC_IDEA_PROPERTIES" JVM_ARGS=`eval echo $JVM_ARGS $REQUIRED_JVM_ARGS` From ef01c7daaf8a0bb2e36a0612ed3ed311487d6cdd Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Tue, 10 May 2011 15:44:21 +0400 Subject: [PATCH 069/250] OptionsTree: NPE fixes [r=pegov] --- .../filtered/FilteringTreeBuilder.java | 3 ++- .../options/newEditor/OptionsEditor.java | 27 +++++++++++++++++-- .../options/newEditor/OptionsTree.java | 2 ++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/treeStructure/filtered/FilteringTreeBuilder.java b/platform/platform-api/src/com/intellij/ui/treeStructure/filtered/FilteringTreeBuilder.java index 8b639153546d..8f744e8f715a 100644 --- a/platform/platform-api/src/com/intellij/ui/treeStructure/filtered/FilteringTreeBuilder.java +++ b/platform/platform-api/src/com/intellij/ui/treeStructure/filtered/FilteringTreeBuilder.java @@ -202,7 +202,8 @@ public class FilteringTreeBuilder extends AbstractTreeBuilder { } public FilteringTreeStructure.Node getVisibleNodeFor(Object nodeObject) { - return getFilteredStructure().getVisibleNodeFor(nodeObject); + FilteringTreeStructure structure = getFilteredStructure(); + return structure != null ? structure.getVisibleNodeFor(nodeObject) : null; } public Object getOriginalNode(Object node) { diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java index 17e216ba5441..344f6c0ac90a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java @@ -332,7 +332,13 @@ public class OptionsEditor extends JPanel implements DataProvider, Place.Navigat return result; } + private void assertIsDispatchThread() { + ApplicationManager.getApplication().assertIsDispatchThread(); + } + private ActionCallback getUiFor(final Configurable configurable) { + assertIsDispatchThread(); + if (myDisposed) { return new ActionCallback.Rejected(); } @@ -870,6 +876,12 @@ public class OptionsEditor extends JPanel implements DataProvider, Place.Navigat } public void dispose() { + assertIsDispatchThread(); + + if (myDisposed) { + return; + } + myDisposed = true; myProperties.setValue(MAIN_SPLITTER_PROPORTION, String.valueOf(myMainSplitter.getProportion())); @@ -882,8 +894,19 @@ public class OptionsEditor extends JPanel implements DataProvider, Place.Navigat final Set configurables = new HashSet(); configurables.addAll(myConfigurable2Content.keySet()); configurables.addAll(myConfigurable2LoadCallback.keySet()); - for (Configurable each : configurables) { - each.disposeUIResources(); + for (final Configurable each : configurables) { + ActionCallback loadCb = myConfigurable2LoadCallback.get(each); + if (loadCb != null) { + loadCb.doWhenProcessed(new Runnable() { + @Override + public void run() { + assertIsDispatchThread(); + each.disposeUIResources(); + } + }); + } else { + each.disposeUIResources(); + } } Disposer.clearOwnFields(this); diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java index 1bd749692730..210d7822a790 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java @@ -186,6 +186,8 @@ public class OptionsTree extends JPanel implements Disposable, OptionsEditorColl public void run() { final EditorNode editorNode = myConfigurable2Node.get(configurable); FilteringTreeStructure.Node editorUiNode = myBuilder.getVisibleNodeFor(editorNode); + if (editorUiNode == null) return; + if (!myBuilder.getSelectedElements().contains(editorUiNode)) { myBuilder.select(editorUiNode, new Runnable() { public void run() { From d26fd3c685a2d8cfdcc519a19bbef1950f803e4d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 May 2011 15:51:48 +0400 Subject: [PATCH 070/250] ea-27473 --- ...icationStatisticsPersistenceComponent.java | 311 +++++++++--------- 1 file changed, 157 insertions(+), 154 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java index 23b03085c414..efab7c59fead 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java @@ -32,6 +32,7 @@ import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ProjectManagerListener; +import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Function; @@ -47,189 +48,191 @@ import java.util.Map; import java.util.Set; @State( - name = "StatisticsApplicationUsages", - storages = { - @Storage( - id = "statistics.application.usages", - file = "$APP_CONFIG$/statistics.application.usages.xml" - )} + name = "StatisticsApplicationUsages", + storages = { + @Storage( + id = "statistics.application.usages", + file = "$APP_CONFIG$/statistics.application.usages.xml" + )} ) public class ApplicationStatisticsPersistenceComponent extends ApplicationStatisticsPersistence - implements ApplicationComponent, PersistentStateComponent { - private boolean persistOnClosing = true; + implements ApplicationComponent, PersistentStateComponent { + private boolean persistOnClosing = true; - private static final String TOKENIZER = ","; + private static final String TOKENIZER = ","; - @NonNls - private static final String GROUP_TAG = "group"; - @NonNls - private static final String GROUP_NAME_ATTR = "name"; + @NonNls + private static final String GROUP_TAG = "group"; + @NonNls + private static final String GROUP_NAME_ATTR = "name"; - @NonNls - private static final String PROJECT_TAG = "project"; - @NonNls - private static final String PROJECT_ID_ATTR = "id"; - @NonNls - private static final String VALUES_ATTR = "values"; + @NonNls + private static final String PROJECT_TAG = "project"; + @NonNls + private static final String PROJECT_ID_ATTR = "id"; + @NonNls + private static final String VALUES_ATTR = "values"; - public ApplicationStatisticsPersistenceComponent() { - } + public ApplicationStatisticsPersistenceComponent() { + } - public static ApplicationStatisticsPersistenceComponent getInstance() { - return ApplicationManager.getApplication().getComponent(ApplicationStatisticsPersistenceComponent.class); - } + public static ApplicationStatisticsPersistenceComponent getInstance() { + return ApplicationManager.getApplication().getComponent(ApplicationStatisticsPersistenceComponent.class); + } - public void loadState(final Element element) { - List groups = element.getChildren(GROUP_TAG); + public void loadState(final Element element) { + List groups = element.getChildren(GROUP_TAG); - for (Object group : groups) { - Element groupElement = (Element) group; - String groupName = groupElement.getAttributeValue(GROUP_NAME_ATTR); + for (Object group : groups) { + Element groupElement = (Element)group; + String groupName = groupElement.getAttributeValue(GROUP_NAME_ATTR); - final GroupDescriptor groupDescriptor = GroupDescriptor.create(groupName); + final GroupDescriptor groupDescriptor = GroupDescriptor.create(groupName); - List projectsList = groupElement.getChildren(PROJECT_TAG); - for (Object project : projectsList) { - Element projectElement = (Element) project; - String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR); - String frameworks = projectElement.getAttributeValue(VALUES_ATTR); - if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(frameworks)) { - Set frameworkDescriptors = new HashSet(); - for (String key : StringUtil.split(frameworks, TOKENIZER)) { - frameworkDescriptors.add(new UsageDescriptor(key, 1)); - } - getApplicationData(groupDescriptor).put(projectId, frameworkDescriptors); - } - } + List projectsList = groupElement.getChildren(PROJECT_TAG); + for (Object project : projectsList) { + Element projectElement = (Element)project; + String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR); + String frameworks = projectElement.getAttributeValue(VALUES_ATTR); + if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(frameworks)) { + Set frameworkDescriptors = new HashSet(); + for (String key : StringUtil.split(frameworks, TOKENIZER)) { + frameworkDescriptors.add(new UsageDescriptor(key, 1)); + } + getApplicationData(groupDescriptor).put(projectId, frameworkDescriptors); } + } } + } - public Element getState() { - Element element = new Element("state"); + public Element getState() { + Element element = new Element("state"); - for (Map.Entry>> appData : getApplicationData().entrySet()) { - Element groupElement = new Element(GROUP_TAG); - groupElement.setAttribute(GROUP_NAME_ATTR, appData.getKey().getId()); - boolean isEmptyGroup = true; + for (Map.Entry>> appData : getApplicationData().entrySet()) { + Element groupElement = new Element(GROUP_TAG); + groupElement.setAttribute(GROUP_NAME_ATTR, appData.getKey().getId()); + boolean isEmptyGroup = true; - for (Map.Entry> projectData : appData.getValue().entrySet()) { - Element projectElement = new Element(PROJECT_TAG); - projectElement.setAttribute(PROJECT_ID_ATTR, projectData.getKey()); - final Set projectDataValue = projectData.getValue(); - if (!projectDataValue.isEmpty()) { - projectElement.setAttribute(VALUES_ATTR, joinUsages(projectDataValue)); - groupElement.addContent(projectElement); - isEmptyGroup = false; - } - } - - if (!isEmptyGroup) { - element.addContent(groupElement); - } + for (Map.Entry> projectData : appData.getValue().entrySet()) { + Element projectElement = new Element(PROJECT_TAG); + projectElement.setAttribute(PROJECT_ID_ATTR, projectData.getKey()); + final Set projectDataValue = projectData.getValue(); + if (!projectDataValue.isEmpty()) { + projectElement.setAttribute(VALUES_ATTR, joinUsages(projectDataValue)); + groupElement.addContent(projectElement); + isEmptyGroup = false; } + } - return element; + if (!isEmptyGroup) { + element.addContent(groupElement); + } } - private static String joinUsages(@NotNull Set usages) { - return StringUtil.join(usages, new Function() { - @Override - public String fun(UsageDescriptor usageDescriptor) { - return usageDescriptor.getKey(); - } - }, TOKENIZER); - } + return element; + } - @NotNull - @NonNls - public File[] getExportFiles() { - return new File[]{PathManager.getOptionsFile("framework.usages")}; - } - - @NotNull - public String getPresentableName() { - return "Application Usages Statistics"; - } - - @NonNls - @NotNull - public String getComponentName() { - return "ApplicationStatisticsPersistenceComponent"; - } - - public void initComponent() { - onAppClosing(); - onProjectClosing(); - } - - private void onProjectClosing() { - ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() { - @Override - public void projectOpened(Project project) { - } - - @Override - public boolean canCloseProject(Project project) { - return true; - } - - @Override - public void projectClosed(Project project) { - } - - @Override - public void projectClosing(Project project) { - if (project != null) { - if (persistOnClosing) { - doPersistProjectUsages(project); - } - } - } - }); - } - - private static void doPersistProjectUsages(@NotNull Project project) { - for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) { - if (usagesCollector instanceof AbstractApplicationUsagesCollector) { - ((AbstractApplicationUsagesCollector) usagesCollector).persistProjectUsages(project); - } + private static String joinUsages(@NotNull Set usages) { + return StringUtil.join(usages, new Function() { + @Override + public String fun(UsageDescriptor usageDescriptor) { + return usageDescriptor.getKey(); } + }, TOKENIZER); + } + + @NotNull + @NonNls + public File[] getExportFiles() { + return new File[]{PathManager.getOptionsFile("framework.usages")}; + } + + @NotNull + public String getPresentableName() { + return "Application Usages Statistics"; + } + + @NonNls + @NotNull + public String getComponentName() { + return "ApplicationStatisticsPersistenceComponent"; + } + + public void initComponent() { + onAppClosing(); + onProjectClosing(); + } + + private void onProjectClosing() { + ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() { + @Override + public void projectOpened(Project project) { + } + + @Override + public boolean canCloseProject(Project project) { + return true; + } + + @Override + public void projectClosed(Project project) { + } + + @Override + public void projectClosing(Project project) { + if (project != null && project.isInitialized()) { + if (persistOnClosing) { + doPersistProjectUsages(project); + } + } + } + }); + } + + private static void doPersistProjectUsages(@NotNull Project project) { + for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) { + if (usagesCollector instanceof AbstractApplicationUsagesCollector) { + ((AbstractApplicationUsagesCollector)usagesCollector).persistProjectUsages(project); + } } + } - private void onAppClosing() { - final MessageBus messageBus = ApplicationManager.getApplication().getMessageBus(); + private void onAppClosing() { + final MessageBus messageBus = ApplicationManager.getApplication().getMessageBus(); - messageBus.connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { - @Override - public void appFrameCreated(String[] commandLineArgs, @NotNull Ref willOpenProject) { - } + messageBus.connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { + @Override + public void appFrameCreated(String[] commandLineArgs, @NotNull Ref willOpenProject) { + } - @Override - public void appStarting(Project projectFromCommandLine) { - } + @Override + public void appStarting(Project projectFromCommandLine) { + } - @Override - public void projectFrameClosed() { - } + @Override + public void projectFrameClosed() { + } - @Override - public void projectOpenFailed() { - } + @Override + public void projectOpenFailed() { + } - @Override - public void welcomeScreenDisplayed() { - } + @Override + public void welcomeScreenDisplayed() { + } - @Override - public void appClosing() { - for (Project project : ProjectManager.getInstance().getOpenProjects()) { - doPersistProjectUsages(project); - } - persistOnClosing = false; - } - }); - } + @Override + public void appClosing() { + for (Project project : ProjectManager.getInstance().getOpenProjects()) { + if (project.isInitialized()) { + doPersistProjectUsages(project); + } + } + persistOnClosing = false; + } + }); + } - public void disposeComponent() { - } + public void disposeComponent() { + } } From 2e75d12b4b65468753a07e7381bde305390b7132 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 10 May 2011 13:55:01 +0200 Subject: [PATCH 071/250] DebuggerManagerThread.invokeAndWait fix: "release() called too early" --- .../debugger/engine/SuspendContextImpl.java | 9 ++++++--- .../intellij/debugger/impl/DebuggerTaskImpl.java | 13 +++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java index 2d7baf56ee96..4ce8162fcd66 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java @@ -88,7 +88,7 @@ public abstract class SuspendContextImpl implements SuspendContext { myKeptReferences.clear(); } - for(SuspendContextCommandImpl cmd = myPostponedCommands.poll(); cmd != null; cmd = myPostponedCommands.poll()) { + for(SuspendContextCommandImpl cmd = pollPostponedCommand(); cmd != null; cmd = pollPostponedCommand()) { cmd.notifyCancelled(); } @@ -199,8 +199,11 @@ public abstract class SuspendContextImpl implements SuspendContext { } } - public void postponeCommand(final SuspendContextCommandImpl command) { + public final void postponeCommand(final SuspendContextCommandImpl command) { if (!isResumed()) { + // Important! when postponing increment the holds counter, so that the action is not released too early. + // This will ensure that the counter becomes zero only when the command is actually executed or canceled + command.hold(); myPostponedCommands.add(command); } else { @@ -208,7 +211,7 @@ public abstract class SuspendContextImpl implements SuspendContext { } } - public SuspendContextCommandImpl pollPostponedCommand() { + public final SuspendContextCommandImpl pollPostponedCommand() { return myPostponedCommands.poll(); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerTaskImpl.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerTaskImpl.java index 03cda8d8e839..6e75e661145b 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerTaskImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerTaskImpl.java @@ -19,21 +19,22 @@ package com.intellij.debugger.impl; * @author lex */ public abstract class DebuggerTaskImpl implements DebuggerTask { - private boolean myOnHold = false; + private int myHolds = 0; public synchronized final void release() { - if (myOnHold) { - myOnHold = false; - notifyAll(); + if (myHolds > 0) { + if (--myHolds == 0) { + notifyAll(); + } } } public synchronized final void hold() { - myOnHold = true; + myHolds++; } public synchronized final void waitFor() { - while (myOnHold) { + while (myHolds > 0) { try { wait(); } From f87f22eb03a16c41e5d7c29a8083736a56b16bea Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 13:41:03 +0200 Subject: [PATCH 072/250] some assertions for invalid closure parameter (EA-27611) --- .../GrReferenceExpressionImpl.java | 22 +++++++++++++++---- .../resolve/processors/ResolverProcessor.java | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java index bb4699b8a6a7..6bbb27ffcdf3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java @@ -209,6 +209,9 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl shapeResults = resolveByShape(allVariants, upToArgument); if (!genericsMatter && !allVariants && shapeResults.first) { + for (GroovyResolveResult candidate : shapeResults.second) { + assert candidate.getElement().isValid(); + } return shapeResults.second; } @@ -278,7 +281,11 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl(); myCandidates.add(candidate); } From eee83ddffb576f2531a34149c161201ee0b48e76 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 13:44:40 +0200 Subject: [PATCH 073/250] some assertions for invalid class (EA-27530) --- .../plugins/groovy/lang/resolve/CollectClassMembersUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/CollectClassMembersUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/CollectClassMembersUtil.java index 8cec6f4db9ff..be91d1acaf24 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/CollectClassMembersUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/CollectClassMembersUtil.java @@ -55,9 +55,11 @@ public class CollectClassMembersUtil { private static Trinity, Map>, Map> getCachedMembers( PsiClass aClass, boolean includeSynthetic) { + LOG.assertTrue(aClass.isValid()); Key, Map>, Map>>> key = includeSynthetic ? CACHED_MEMBERS_INCLUDING_SYNTHETIC : CACHED_MEMBERS; - CachedValue, Map>, Map>> cachedValue = aClass.getUserData(key); + CachedValue, Map>, Map>> cachedValue = + aClass.getUserData(key); if (cachedValue == null) { cachedValue = buildCache(aClass, includeSynthetic); aClass.putUserData(key, cachedValue); From 522210460eb3a8a79545db0a6f3a43aeb3a63f69 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 14:17:08 +0200 Subject: [PATCH 074/250] default to by-shape resolve in groovy, no recursion check for it (=> no cache prevention) --- .../expressions/GrReferenceExpression.java | 2 ++ .../GrReferenceExpressionImpl.java | 22 ++++++++++--------- .../groovy/lang/GroovyStressTest.groovy | 11 +++++++++- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrReferenceExpression.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrReferenceExpression.java index 5966814e4be7..4a511800684d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrReferenceExpression.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrReferenceExpression.java @@ -52,4 +52,6 @@ public interface GrReferenceExpression extends GrExpression, GrReferenceElement< GroovyResolveResult[] getSameNameVariants(); GrReferenceExpression bindToElementViaStaticImport(@NotNull PsiClass qualifierClass); + + GroovyResolveResult[] resolveByShape(); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java index 6bbb27ffcdf3..66100d5e8c6a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java @@ -431,7 +431,18 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl() { + @Override + public Result compute() { + return Result.create(doPolyResolve(false, false), PsiModificationTracker.MODIFICATION_COUNT); + } + }); } private static final ResolveCache.PolyVariantResolver POLY_RESOLVER = @@ -440,15 +451,6 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl Date: Tue, 10 May 2011 17:02:07 +0400 Subject: [PATCH 075/250] IDEA-69383 Path variable get substituted under windows --- .../com/intellij/application/options/PathMacrosImpl.java | 6 +++++- .../intellij/application/options/ReplacePathToMacroMap.java | 1 + .../application/options/pathMacros/PathMacroTable.java | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/application/options/PathMacrosImpl.java b/platform/platform-impl/src/com/intellij/application/options/PathMacrosImpl.java index c8ef009e92c1..a28055b8527f 100644 --- a/platform/platform-impl/src/com/intellij/application/options/PathMacrosImpl.java +++ b/platform/platform-impl/src/com/intellij/application/options/PathMacrosImpl.java @@ -270,11 +270,15 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent, for (Object aChildren : children) { Element macro = (Element)aChildren; final String name = macro.getAttributeValue(NAME_ATTR); - final String value = macro.getAttributeValue(VALUE_ATTR); + String value = macro.getAttributeValue(VALUE_ATTR); if (name == null || value == null) { throw new InvalidDataException(); } + if (value.length() > 1 && value.charAt(value.length() - 1) == '/') { + value = value.substring(0, value.length() - 1); + } + myMacros.put(name, value); } diff --git a/platform/platform-impl/src/com/intellij/application/options/ReplacePathToMacroMap.java b/platform/platform-impl/src/com/intellij/application/options/ReplacePathToMacroMap.java index f3dcfee1d783..4d26ae701515 100644 --- a/platform/platform-impl/src/com/intellij/application/options/ReplacePathToMacroMap.java +++ b/platform/platform-impl/src/com/intellij/application/options/ReplacePathToMacroMap.java @@ -106,6 +106,7 @@ public class ReplacePathToMacroMap extends PathMacroMap { final StringBuilder newText = StringBuilderSpinAllocator.alloc(); try { //check that this is complete path (ends with "/" or "!/") + // do not collapse partial paths, i.e. do not substitute "/a/b/cd" in paths like "/a/b/cdef" int endOfOccurence = path.length(); final boolean isWindowsRoot = path.endsWith(":/"); if (!isWindowsRoot && diff --git a/platform/platform-impl/src/com/intellij/application/options/pathMacros/PathMacroTable.java b/platform/platform-impl/src/com/intellij/application/options/pathMacros/PathMacroTable.java index bce85816c63d..4d4abca1a052 100644 --- a/platform/platform-impl/src/com/intellij/application/options/pathMacros/PathMacroTable.java +++ b/platform/platform-impl/src/com/intellij/application/options/pathMacros/PathMacroTable.java @@ -127,7 +127,9 @@ public class PathMacroTable extends Table { for (Pair pair : myMacros) { final String value = pair.getSecond(); if (value != null && value.trim().length() > 0) { - myPathMacros.setMacro(pair.getFirst(), value.replace(File.separatorChar, '/')); + String path = value.replace(File.separatorChar, '/'); + if (path.endsWith("/")) path = path.substring(0, path.length() - 1); + myPathMacros.setMacro(pair.getFirst(), path); } } } From fa1fd307135e36214c6b6305cada09001a2da662 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 10 May 2011 16:27:39 +0400 Subject: [PATCH 076/250] update DiffApplication to work with dirs and jars --- .../openapi/diff/DiffApplication.java | 66 +++++++++++++++---- .../intellij/openapi/diff/DirDiffManager.java | 4 ++ .../ide/diff/VirtualFileDiffElement.java | 8 ++- .../diff/impl/dir/DirDiffManagerImpl.java | 21 +++++- .../openapi/diff/impl/dir/DirDiffPanel.java | 26 ++++---- .../diff/impl/dir/DirDiffTableModel.java | 15 ++++- 6 files changed, 107 insertions(+), 33 deletions(-) rename platform/{platform-impl => platform-api}/src/com/intellij/openapi/diff/DirDiffManager.java (91%) diff --git a/platform/platform-api/src/com/intellij/openapi/diff/DiffApplication.java b/platform/platform-api/src/com/intellij/openapi/diff/DiffApplication.java index 9c87b23f9f54..60a4cc365860 100644 --- a/platform/platform-api/src/com/intellij/openapi/diff/DiffApplication.java +++ b/platform/platform-api/src/com/intellij/openapi/diff/DiffApplication.java @@ -15,10 +15,14 @@ */ package com.intellij.openapi.diff; +import com.intellij.ide.diff.DiffElement; +import com.intellij.ide.diff.DirDiffSettings; import com.intellij.openapi.application.ApplicationNamesInfo; import com.intellij.openapi.application.ApplicationStarterEx; import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; @@ -27,7 +31,9 @@ import java.io.FileNotFoundException; /** * @author max + * @author Konstantin Bulenkov */ +@SuppressWarnings({"UseOfSystemOutOrSystemErr"}) public class DiffApplication implements ApplicationStarterEx { public String getCommandName() { return "diff"; @@ -54,6 +60,7 @@ public class DiffApplication implements ApplicationStarterEx { } catch (Exception e) { e.printStackTrace(); + System.exit(1); } finally { System.exit(0); @@ -77,21 +84,54 @@ public class DiffApplication implements ApplicationStarterEx { } private static void processDiffCommand(String[] args) throws FileNotFoundException { - String path1 = args[1]; - String path2 = args[2]; - VirtualFile file1 = findFile(path1); - VirtualFile file2 = findFile(path2); - SimpleDiffRequest request = SimpleDiffRequest.compareFiles(file1, file2, null); - request.addHint(DiffTool.HINT_SHOW_MODAL_DIALOG); - DiffManager.getInstance().getIdeaDiffTool().show(request); - FileDocumentManager.getInstance().saveAllDocuments(); + final String path1 = args[1]; + final String path2 = args[2]; + final VirtualFile file1 = findFile(path1); + final VirtualFile file2 = findFile(path2); + final boolean isDirs = isDirs(file1, file2); + final boolean isJars = isJars(file1, file2); + if (isDirs || isJars) { + final DirDiffManager diffManager = DirDiffManager.getInstance(ProjectManager.getInstance().getDefaultProject()); + final DiffElement d1 = diffManager.createDiffElement(file1); + final DiffElement d2 = diffManager.createDiffElement(file2); + if (d1 == null) { + System.err.println("Can't create diff element from " + path1); + return; + } + if (d2 == null) { + System.err.println("Can't create diff element from " + path2); + return; + } + if (!diffManager.canShow(d1, d2)) { + System.err.println("Diff manager can't compare '" + path1 + "' and '" + path2 + "'"); + return; + } + + final DirDiffSettings settings = new DirDiffSettings(); + settings.showInFrame = false; + diffManager.showDiff(d1, d2, settings); + } else { + SimpleDiffRequest request = SimpleDiffRequest.compareFiles(file1, file2, null); + request.addHint(DiffTool.HINT_SHOW_MODAL_DIALOG); + DiffManager.getInstance().getIdeaDiffTool().show(request); + FileDocumentManager.getInstance().saveAllDocuments(); + } } - private static VirtualFile findFile(final String path1) throws FileNotFoundException { - final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(path1)); - if (vFile == null) { - throw new FileNotFoundException(DiffBundle.message("cannot.file.file.error.message", path1)); + private static boolean isJars(VirtualFile file1, VirtualFile file2) { + return JarFileSystem.PROTOCOL.equalsIgnoreCase(file1.getExtension()) + && JarFileSystem.PROTOCOL.equalsIgnoreCase(file2.getExtension()); + } + + private static boolean isDirs(VirtualFile file1, VirtualFile file2) { + return file1.isDirectory() && file2.isDirectory(); + } + + private static VirtualFile findFile(final String path) throws FileNotFoundException { + final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(path)); + if (file == null) { + throw new FileNotFoundException(DiffBundle.message("cannot.file.file.error.message", path)); } - return vFile; + return file; } } diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/DirDiffManager.java b/platform/platform-api/src/com/intellij/openapi/diff/DirDiffManager.java similarity index 91% rename from platform/platform-impl/src/com/intellij/openapi/diff/DirDiffManager.java rename to platform/platform-api/src/com/intellij/openapi/diff/DirDiffManager.java index 6a7fc044dfb5..20368ef73b19 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/DirDiffManager.java +++ b/platform/platform-api/src/com/intellij/openapi/diff/DirDiffManager.java @@ -20,6 +20,7 @@ import com.intellij.ide.diff.DirDiffSettings; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Konstantin Bulenkov @@ -32,4 +33,7 @@ public abstract class DirDiffManager { public abstract void showDiff(@NotNull DiffElement dir1, @NotNull DiffElement dir2, DirDiffSettings settings); public abstract boolean canShow(@NotNull DiffElement dir1, @NotNull DiffElement dir2); + + @Nullable + public abstract DiffElement createDiffElement(Object obj); } diff --git a/platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.java b/platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.java index a9198a4d0db3..c8d9907c7856 100644 --- a/platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.java +++ b/platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.java @@ -141,8 +141,12 @@ public class VirtualFileDiffElement extends DiffElement { @Override protected DiffRequest createRequestForBinaries(Project project, @NotNull VirtualFile src, @NotNull VirtualFile trg) { - - return super.createRequestForBinaries(project, src, trg); + if (FileEditorProviderManager.getInstance().getProviders(project, src).length > 0 + && FileEditorProviderManager.getInstance().getProviders(project, trg).length > 0) { + return super.createRequestForBinaries(project, src, trg); + } else { + return null; + } } @Override diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffManagerImpl.java index 659adc9376a7..fb8f966b9127 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffManagerImpl.java @@ -17,8 +17,12 @@ package com.intellij.openapi.diff.impl.dir; import com.intellij.ide.diff.DiffElement; import com.intellij.ide.diff.DirDiffSettings; +import com.intellij.ide.diff.JarFileDiffElement; +import com.intellij.ide.diff.VirtualFileDiffElement; import com.intellij.openapi.diff.DirDiffManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.JarFileSystem; +import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; /** @@ -37,7 +41,11 @@ public class DirDiffManagerImpl extends DirDiffManager { if (settings.showInFrame) { new DirDiffFrame(myProject, model, settings).show(); } else { - new DirDiffDialog(myProject, model, settings).show(); + final DirDiffDialog dirDiffDialog = new DirDiffDialog(myProject, model, settings); + if (myProject == null || myProject.isDefault()) { + dirDiffDialog.setModal(true); + } + dirDiffDialog.show(); } } @@ -45,4 +53,15 @@ public class DirDiffManagerImpl extends DirDiffManager { public boolean canShow(@NotNull DiffElement dir1, @NotNull DiffElement dir2) { return dir1.isContainer() && dir2.isContainer(); } + + @Override + public DiffElement createDiffElement(Object obj) { + //TODO make EP + if (obj instanceof VirtualFile) { + final VirtualFile file = (VirtualFile)obj; + return JarFileSystem.PROTOCOL.equalsIgnoreCase(file.getExtension()) + ? new JarFileDiffElement(file) : new VirtualFileDiffElement(file); + } + return null; + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java index ac3d53d2b965..75ff1b0075f2 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java @@ -112,7 +112,6 @@ public class DirDiffPanel implements Disposable { myDiffPanel.revalidate(); myDiffPanel.repaint(); } - } else { final DiffElement object; if (element.getType() == DType.ERROR) { @@ -190,18 +189,6 @@ public class DirDiffPanel implements Disposable { myToolBarPanel.add(toolbar.getComponent(), BorderLayout.CENTER); final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), wnd.getDisposable()); loadingPanel.add(myComponent, BorderLayout.CENTER); - //final LoadingDecorator decorator = new LoadingDecorator(myComponent, wnd.getDisposable(), -1) { - // @Override - // protected NonOpaquePanel customizeLoadingLayer(JPanel parent, JLabel text, AsyncProcessIcon icon) { - // final NonOpaquePanel panel = super.customizeLoadingLayer(parent, text, icon); - // final Font font = text.getFont(); - // text.setFont(font.deriveFont(font.getStyle(), font.getSize() + 6)); - // text.setForeground(new Color(0,0,0,150)); - // return panel; - // } - //}; - //mySplitPanel.setTopComponent(decorator.getComponent()); - //decorator.getComponent().setMinimumSize(new Dimension(400, 100)); myTable.putClientProperty(myModel.DECORATOR, loadingPanel); myTable.addComponentListener(new ComponentAdapter() { @Override @@ -235,7 +222,7 @@ public class DirDiffPanel implements Disposable { } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { e.consume(); - IdeFocusManager.getInstance(project).requestFocus(myTable, true); + focusTable(); } } }); @@ -288,6 +275,17 @@ public class DirDiffPanel implements Disposable { } } + public void focusTable() { + final IdeFocusManager focusManager = myModel.getProject().isDefault() + ? IdeFocusManager.getGlobalInstance() : IdeFocusManager.getInstance(myModel.getProject()); + focusManager.doWhenFocusSettlesDown(new Runnable() { + @Override + public void run() { + focusManager.requestFocus(myTable, true); + } + }); + } + public JTextField getFilter() { return myFilter; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java index 75b3aa4bd35d..2f47c1d055d9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java @@ -18,6 +18,7 @@ package com.intellij.openapi.diff.impl.dir; import com.intellij.ide.diff.DiffElement; import com.intellij.ide.diff.DirDiffSettings; import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; @@ -110,6 +111,7 @@ public class DirDiffTableModel extends AbstractTableModel implements Disposable fireTableDataChanged(); myUpdating.set(false); selectFirstRow(); + myPanel.focusTable(); } private void selectFirstRow() { @@ -198,12 +200,13 @@ public class DirDiffTableModel extends AbstractTableModel implements Disposable updater.start(); } } - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + final Application app = ApplicationManager.getApplication(); + app.executeOnPooledThread(new Runnable() { public void run() { myTree.updateVisibility(mySettings); final ArrayList elements = new ArrayList(); fillElements(myTree, elements); - ApplicationManager.getApplication().invokeLater(new Runnable() { + final Runnable uiThread = new Runnable() { public void run() { clear(); myElements.addAll(elements); @@ -215,7 +218,12 @@ public class DirDiffTableModel extends AbstractTableModel implements Disposable loadingPanel.stopLoading(); } } - }); + }; + if (myProject.isDefault()) { + SwingUtilities.invokeLater(uiThread); + } else { + app.invokeLater(uiThread); + } } }); } @@ -447,6 +455,7 @@ public class DirDiffTableModel extends AbstractTableModel implements Disposable updater.start(); } else { updater = null; + myPanel.focusTable(); } } } From 2e68fb4ae9fff221645361207c5e412ebba5145b Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Tue, 10 May 2011 18:43:08 +0400 Subject: [PATCH 077/250] [xena] IDEA-69390 Cant edit method body template when invoked from editor [r=anna.kozlova]] --- .../DefaultFileTemplateUsageInspection.java | 17 ++++++++++++----- .../impl/FileTemplateConfigurable.java | 8 +++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/defaultFileTemplateUsage/DefaultFileTemplateUsageInspection.java b/java/java-impl/src/com/intellij/codeInspection/defaultFileTemplateUsage/DefaultFileTemplateUsageInspection.java index 82791501a049..8271e1aa035e 100644 --- a/java/java-impl/src/com/intellij/codeInspection/defaultFileTemplateUsage/DefaultFileTemplateUsageInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/defaultFileTemplateUsage/DefaultFileTemplateUsageInspection.java @@ -19,6 +19,7 @@ import com.intellij.codeInspection.*; import com.intellij.ide.fileTemplates.FileTemplate; import com.intellij.ide.fileTemplates.FileTemplateManager; import com.intellij.ide.fileTemplates.impl.FileTemplateConfigurable; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; @@ -142,17 +143,23 @@ public class DefaultFileTemplateUsageInspection extends BaseJavaLocalInspectionT return getName(); } - public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { + public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { final FileTemplateConfigurable configurable = new FileTemplateConfigurable(); SwingUtilities.invokeLater(new Runnable(){ public void run() { configurable.setTemplate(myTemplateToEdit, null); + + boolean ok = ShowSettingsUtil.getInstance().editConfigurable(project, configurable); + if (ok) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + myReplaceTemplateFix.applyFix(project, descriptor); + } + }); + } } }); - boolean ok = ShowSettingsUtil.getInstance().editConfigurable(project, configurable); - if (ok) { - myReplaceTemplateFix.applyFix(project, descriptor); - } } } } diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateConfigurable.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateConfigurable.java index 48d46ffbcd0a..6e67cc883136 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateConfigurable.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateConfigurable.java @@ -105,9 +105,11 @@ public class FileTemplateConfigurable implements Configurable { public void setTemplate(FileTemplate template, URL defaultDescription) { myDefaultDescriptionUrl = defaultDescription; myTemplate = template; - reset(); - myNameField.selectAll(); - myExtensionField.selectAll(); + if (myMainPanel != null) { + reset(); + myNameField.selectAll(); + myExtensionField.selectAll(); + } } public void setShowInternalMessage(String message) { From 997314fd1147490ca2e6ebe07328084f9d8779e9 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 10 May 2011 14:52:03 +0200 Subject: [PATCH 078/250] cache extensions root area (EA-27436 - IAE: Extensions.getArea) [r=peter] --- .../com/intellij/openapi/extensions/Extensions.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java b/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java index 4e9b6f4a697d..8d32554056e4 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java @@ -34,14 +34,11 @@ public class Extensions { public static final ExtensionPointName AREA_LISTENER_EXTENSION_POINT = new ExtensionPointName("com.intellij.arealistener"); private static final Map ourAreaInstance2area = new HashMap(); + private static final ExtensionsAreaImpl ourRootArea = createRootArea(); private static final MultiMap ourAreaClass2instances = new MultiMap(); private static final Map ourAreaInstance2class = new HashMap(); private static final Map ourAreaClass2Configuration = new HashMap(); - static { - createRootArea(); - } - private static ExtensionsAreaImpl createRootArea() { ExtensionsAreaImpl rootArea = new ExtensionsAreaImpl(null, null, null, ourLogger); rootArea.registerExtensionPoint(AREA_LISTENER_EXTENSION_POINT.getName(), AreaListener.class.getName()); @@ -53,11 +50,14 @@ public class Extensions { } public static ExtensionsArea getRootArea() { - return getArea(null); + return ourRootArea; } @NotNull public static ExtensionsArea getArea(@Nullable AreaInstance areaInstance) { + if (areaInstance == null) { + return ourRootArea; + } ExtensionsAreaImpl area = ourAreaInstance2area.get(areaInstance); if (area == null) { throw new IllegalArgumentException("No area instantiated for: " + areaInstance); From 6acb2ae938fda23a9dce9a8ec84efec40f0aecae Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 10 May 2011 15:18:37 +0200 Subject: [PATCH 079/250] EA-17747 - IAE: ElementSignatureProvider.restoreElementInternal --- .../codeInsight/folding/impl/XmlElementSignatureProvider.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xml/impl/src/com/intellij/codeInsight/folding/impl/XmlElementSignatureProvider.java b/xml/impl/src/com/intellij/codeInsight/folding/impl/XmlElementSignatureProvider.java index c1fe0df73ea3..5549fa3ddf2c 100644 --- a/xml/impl/src/com/intellij/codeInsight/folding/impl/XmlElementSignatureProvider.java +++ b/xml/impl/src/com/intellij/codeInsight/folding/impl/XmlElementSignatureProvider.java @@ -64,6 +64,9 @@ public class XmlElementSignatureProvider extends ElementSignatureProvider { if (parent instanceof XmlFile) { parent = ((XmlFile)parent).getDocument(); + if (parent == null) { + return null; + } } try { From 4033289bdcde9aa586788419a4ba47e9ac916f16 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 10 May 2011 15:28:49 +0200 Subject: [PATCH 080/250] show plugin update error dialog in EDT (EA-27654 - ISE: DialogWrapper.ensureEventDispatchThread) --- .../openapi/updateSettings/impl/UpdateChecker.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java index 6416ec90bc51..63cd68b481bb 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java @@ -52,6 +52,7 @@ import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.UrlConnectionUtil; import com.intellij.util.net.HttpConfigurable; import com.intellij.util.text.DateFormatUtil; +import com.intellij.util.ui.UIUtil; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; @@ -157,7 +158,12 @@ public final class UpdateChecker { if (!failed.isEmpty()) { final String failedMessage = IdeBundle.message("connection.failed.message", StringUtil.join(failed, ",")); if (showErrorDialog) { - Messages.showErrorDialog(failedMessage, IdeBundle.message("title.connection.error")); + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + Messages.showErrorDialog(failedMessage, IdeBundle.message("title.connection.error")); + } + }); } else { LOG.info(failedMessage); From 7f9d45dd993a794b027bb20b91b2ee476493cfdb Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 10 May 2011 15:36:45 +0200 Subject: [PATCH 081/250] exception when smart enter is invoked at offset 0 (EA-26799 - IOOBE: SegmentArray.findSegmentIndex) --- .../editorActions/smartEnter/SmartEnterProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-api/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterProcessor.java b/platform/lang-api/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterProcessor.java index 4c88a5aede99..2e92ef17d017 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterProcessor.java +++ b/platform/lang-api/src/com/intellij/codeInsight/editorActions/smartEnter/SmartEnterProcessor.java @@ -56,7 +56,7 @@ public abstract class SmartEnterProcessor { final Document doc = editor.getDocument(); CharSequence chars = doc.getCharsSequence(); - int offset = CharArrayUtil.shiftBackward(chars, caret - 1, " \t"); + int offset = caret == 0 ? 0 : CharArrayUtil.shiftBackward(chars, caret - 1, " \t"); if (doc.getLineNumber(offset) < doc.getLineNumber(caret)) { offset = CharArrayUtil.shiftForward(chars, caret, " \t"); } From e3979c6e5caf732536e5a6200cd83242cb6b81ea Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 10 May 2011 15:43:48 +0200 Subject: [PATCH 082/250] use project as parent for JetBrainsAccountDialog if parent component is no longer showing (EA-26928 - IAE: DialogWrapperPeerImpl.) --- .../src/com/intellij/diagnostic/ITNReporter.java | 9 ++++++++- .../com/intellij/diagnostic/JetBrainsAccountDialog.java | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/diagnostic/ITNReporter.java b/platform/platform-impl/src/com/intellij/diagnostic/ITNReporter.java index 73c9e1907bec..e6e63081678f 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/ITNReporter.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/ITNReporter.java @@ -156,7 +156,14 @@ public class ITNReporter extends ErrorReportSubmitter { } else { if (e instanceof NoSuchEAPUserException) { - new JetBrainsAccountDialog(parentComponent).show(); + final JetBrainsAccountDialog dialog; + if (parentComponent != null && parentComponent.isShowing()) { + dialog = new JetBrainsAccountDialog(parentComponent); + } + else { + dialog = new JetBrainsAccountDialog(project); + } + dialog.show(); } ApplicationManager.getApplication().invokeLater(new Runnable() { @Override diff --git a/platform/platform-impl/src/com/intellij/diagnostic/JetBrainsAccountDialog.java b/platform/platform-impl/src/com/intellij/diagnostic/JetBrainsAccountDialog.java index e07f6992710d..cdf447387bd3 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/JetBrainsAccountDialog.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/JetBrainsAccountDialog.java @@ -16,6 +16,7 @@ package com.intellij.diagnostic; import com.intellij.ide.BrowserUtil; +import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.util.net.HTTPProxySettingsDialog; @@ -50,7 +51,12 @@ public class JetBrainsAccountDialog extends DialogWrapper { public JetBrainsAccountDialog(Component parent) throws HeadlessException { super(parent, false); - init (); + init(); + } + + public JetBrainsAccountDialog(Project project) throws HeadlessException { + super(project, false); + init(); } protected JPanel myMainPanel; From ba9bdb82d50997c81ee9ac10b96840d2efe68e9c Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 10 May 2011 16:03:11 +0200 Subject: [PATCH 083/250] dispose old editors when recreating all tree nodes in reset() (EA-26601 - assert: EditorFactoryImpl.fireEditorNotReleasedError) --- .../openapi/ui/MasterDetailsComponent.java | 16 ++++++++++------ .../openapi/ui/NamedItemsListEditor.java | 7 ++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java index c8baff067dbe..aad5c5c971b0 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java @@ -401,6 +401,16 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom myAutoScrollHandler.cancelAllRequests(); myDetails.disposeUIResources(); myInitializedConfigurables.clear(); + clearChildren(); + final String key = getComponentStateKey(); + final MasterDetailsStateService stateService = getStateService(); + if (key != null && stateService != null) { + stateService.setComponentState(key, getState()); + } + myCurrentConfigurable = null; + } + + protected void clearChildren() { TreeUtil.traverseDepth(myRoot, new TreeUtil.Traverse() { public boolean accept(Object node) { if (node instanceof MyNode) { @@ -414,12 +424,6 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom } }); myRoot.removeAllChildren(); - final String key = getComponentStateKey(); - final MasterDetailsStateService stateService = getStateService(); - if (key != null && stateService != null) { - stateService.setComponentState(key, getState()); - } - myCurrentConfigurable = null; } @Nullable diff --git a/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java b/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java index a31e681be63d..aab9abd29fa4 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java @@ -81,7 +81,7 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { myResultItems = myOriginalItems; myItems.clear(); - myRoot.removeAllChildren(); + clearChildren(); for (T item : myOriginalItems) { addNewNode(myCloner.cloneOf(item)); } @@ -178,6 +178,11 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { return result.get(); } + @Override + public void disposeUIResources() { + super.disposeUIResources(); //To change body of overridden methods use File | Settings | File Templates. + } + private class ItemConfigurable extends NamedConfigurable { private final T myItem; private final UnnamedConfigurable myConfigurable; From 65215651162eb06e7b46f8a5bc111b2278e08b11 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 15:40:02 +0200 Subject: [PATCH 084/250] more debug info for disposed lookup (EA-27533, EA-27503) and wrong lookup start offset (EA-27494) --- .../com/intellij/codeInsight/lookup/impl/LookupImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index f37c7f62f020..1903d0f978b0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -335,7 +335,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable void appendPrefix(char c) { checkReused(); - LOG.assertTrue(!myDisposed); + LOG.assertTrue(!myDisposed, disposeTrace); myAdditionalPrefix += c; myInitialPrefix = null; myFrozenItems.clear(); @@ -377,7 +377,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable if (!ApplicationManager.getApplication().isUnitTestMode()) { ApplicationManager.getApplication().assertIsDispatchThread(); } - assert !myDisposed; + assert !myDisposed : disposeTrace; final Pair,Iterable>> snapshot = myModel.getModelSnapshot(); @@ -720,8 +720,8 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable int lookupStart = caretOffset - prefix.length(); int len = myEditor.getDocument().getTextLength(); - LOG.assertTrue(lookupStart >= 0 && lookupStart <= len, "ls: " + lookupStart + "doc: " + len); - LOG.assertTrue(caretOffset >= 0 && caretOffset <= len, "co: " + caretOffset + "doc: " + len); + LOG.assertTrue(lookupStart >= 0 && lookupStart <= len, "ls: " + lookupStart + "caret: " + caretOffset + " prefix:" + prefix + " doc: " + len); + LOG.assertTrue(caretOffset >= 0 && caretOffset <= len, "co: " + caretOffset + " doc: " + len); myEditor.getDocument().replaceString(lookupStart, caretOffset, lookupString); From 3de48a93c0d61451ce58dfbb187376423d2046c6 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 15:54:59 +0200 Subject: [PATCH 085/250] diagnose null lookup in actionPerformed (EA-27476) --- .../lookup/impl/actions/ChooseItemAction.java | 18 ++++++++++++------ .../ChooseItemCompleteStatementAction.java | 4 +--- .../impl/actions/ChooseItemReplaceAction.java | 15 +++++---------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemAction.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemAction.java index 4f7cd99b196d..44ab57a49cd5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemAction.java @@ -31,16 +31,22 @@ public class ChooseItemAction extends EditorAction { super(new Handler()); } + @NotNull + static LookupImpl getLookup(Editor editor) { + LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); + if (lookup == null) { + Project project = editor.getProject(); + throw new AssertionError(editor + "; " + (project == null ? null : LookupManager.getInstance(project).getActiveLookup())); + } + return lookup; + } + private static class Handler extends EditorActionHandler { public void execute(@NotNull final Editor editor, final DataContext dataContext) { - LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); - if (lookup == null) { - Project project = editor.getProject(); - throw new AssertionError(editor + "; " + (project == null ? null : LookupManager.getInstance(project).getActiveLookup())); - } - lookup.finishLookup(Lookup.NORMAL_SELECT_CHAR); + getLookup(editor).finishLookup(Lookup.NORMAL_SELECT_CHAR); } + @Override public boolean isEnabled(Editor editor, DataContext dataContext) { LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemCompleteStatementAction.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemCompleteStatementAction.java index 1008b394d25b..95310e8227ab 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemCompleteStatementAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemCompleteStatementAction.java @@ -35,9 +35,7 @@ public class ChooseItemCompleteStatementAction extends EditorAction { @Override public void execute(Editor editor, DataContext dataContext) { FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_SMART_ENTER); - - LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); - lookup.finishLookup(Lookup.COMPLETE_STATEMENT_SELECT_CHAR); + ChooseItemAction.getLookup(editor).finishLookup(Lookup.COMPLETE_STATEMENT_SELECT_CHAR); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemReplaceAction.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemReplaceAction.java index 7acd6a675dbf..9697f81aa7a9 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemReplaceAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/actions/ChooseItemReplaceAction.java @@ -41,15 +41,10 @@ public class ChooseItemReplaceAction extends EditorAction { } private static class Handler extends EditorActionHandler { - private boolean lastEnabled; @Override public void execute(Editor editor, DataContext dataContext) { FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_REPLACE); - LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); - if (lookup == null) { - throw new AssertionError("Null lookup: lastEnabled=" + lastEnabled); - } - lookup.finishLookup(Lookup.REPLACE_SELECT_CHAR); + ChooseItemAction.getLookup(editor).finishLookup(Lookup.REPLACE_SELECT_CHAR); } @Override @@ -60,16 +55,16 @@ public class ChooseItemReplaceAction extends EditorAction { CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion(); if (completion != null && completion.isAutopopupCompletion() && hasTemplatePrefix(lookup, TemplateSettings.TAB_CHAR)) { - return lastEnabled = false; + return false; } if (lookup.isFocused()) { - return lastEnabled = true; + return true; } - return lastEnabled = !lookup.getItems().isEmpty(); + return !lookup.getItems().isEmpty(); } - return lastEnabled = false; + return false; } } From 51559d6f331bb67aff53de0abca84c7ea1166730 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 16:01:22 +0200 Subject: [PATCH 086/250] who kills the range marker? (EA-27458) --- .../com/intellij/codeInsight/lookup/impl/LookupImpl.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index 1903d0f978b0..31a78737355f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -37,6 +37,7 @@ import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.event.*; +import com.intellij.openapi.editor.ex.RangeMarkerEx; import com.intellij.openapi.keymap.KeymapUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.JBPopup; @@ -756,16 +757,22 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable public void performGuardedChange(Runnable change) { LOG.assertTrue(!myDisposed, disposeTrace); + assert myLookupStartMarker.isValid(); assert !myChangeGuard; + myChangeGuard = true; + RangeMarkerEx marker = (RangeMarkerEx) myEditor.getDocument().createRangeMarker(myLookupStartMarker.getStartOffset(), myLookupStartMarker.getEndOffset()); + marker.trackInvalidation(true); try { change.run(); } finally { + marker.trackInvalidation(false); myChangeGuard = false; } LOG.assertTrue(!myDisposed, disposeTrace); - LOG.assertTrue(myLookupStartMarker.isValid()); + LOG.assertTrue(myLookupStartMarker.isValid(), "invalid lookup start"); + LOG.assertTrue(marker.isValid(), "invalid marker"); if (isVisible()) { updateLookupBounds(); } From 9efa2a77d8c6f38d20441be2639c81e711b472df Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Tue, 10 May 2011 19:11:04 +0400 Subject: [PATCH 087/250] [mac] show library/jdk name or jar name in frame title for class files --- .../intellij/openapi/project/ProjectUtil.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/platform/lang-api/src/com/intellij/openapi/project/ProjectUtil.java b/platform/lang-api/src/com/intellij/openapi/project/ProjectUtil.java index 03cb18ed4ee2..f48aa47fb429 100644 --- a/platform/lang-api/src/com/intellij/openapi/project/ProjectUtil.java +++ b/platform/lang-api/src/com/intellij/openapi/project/ProjectUtil.java @@ -23,8 +23,12 @@ import com.intellij.ide.highlighter.InternalFileType; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.roots.JdkOrderEntry; +import com.intellij.openapi.roots.OrderEntry; +import com.intellij.openapi.roots.libraries.LibraryUtil; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFilePathWrapper; import com.intellij.util.SystemProperties; @@ -87,6 +91,23 @@ public class ProjectUtil { } } final Module module = ModuleUtil.findModuleForFile(file, project); + + if (SystemInfo.isMac && file.getFileSystem() instanceof JarFileSystem) { + final VirtualFile fileForJar = ((JarFileSystem)file.getFileSystem()).getVirtualFileForJar(file); + if (fileForJar != null) { + final OrderEntry libraryEntry = LibraryUtil.findLibraryEntry(file, project); + if (libraryEntry != null) { + if (libraryEntry instanceof JdkOrderEntry) { + url = new StringBuilder(url).append(" - [").append(((JdkOrderEntry)libraryEntry).getJdkName()).append("]").toString(); + } else { + url = new StringBuilder(url).append(" - [").append(libraryEntry.getPresentableName()).append("]").toString(); + } + } else { + url = new StringBuilder(url).append(" - [").append(fileForJar.getName()).append("]").toString(); + } + } + } + if (module == null) return url; return SystemInfo.isMac ? new StringBuffer().append(url).append(" - [").append(module.getName()).append("]").toString() : new StringBuffer().append("[").append(module.getName()).append("] - ").append(url).toString(); From 12a06ab57787c4cfb1d095f5c089d25fe895df09 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 17:01:22 +0200 Subject: [PATCH 088/250] don't suggest classes whose package is enum, in java >5 (EA-27371) --- .../com/intellij/psi/filters/getters/ClassLiteralGetter.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/filters/getters/ClassLiteralGetter.java b/java/java-impl/src/com/intellij/psi/filters/getters/ClassLiteralGetter.java index 5228a5c8f4bc..81586deea85d 100644 --- a/java/java-impl/src/com/intellij/psi/filters/getters/ClassLiteralGetter.java +++ b/java/java-impl/src/com/intellij/psi/filters/getters/ClassLiteralGetter.java @@ -85,8 +85,7 @@ public class ClassLiteralGetter { try { resultSet.consume(AutoCompletionPolicy.NEVER_AUTOCOMPLETE.applyPolicy(new ClassLiteralLookupElement((PsiClassType)type, context))); } - catch (IncorrectOperationException e) { - LOG.error(e); + catch (IncorrectOperationException ignored) { } } } From 0f55679cc597295d66adb6f42f1ea081e03c6f28 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Tue, 10 May 2011 19:17:18 +0400 Subject: [PATCH 089/250] type inference in converter --- .../statements/typedef/members/GrMethod.java | 1 - .../typedef/members/GrMethodBaseImpl.java | 11 +-- .../AnonymousFromMapGenerator.java | 2 +- .../convertToJava/ClassGenerator.java | 13 +--- .../convertToJava/ClassItemGeneratorImpl.java | 11 ++- .../convertToJava/CodeBlockGenerator.java | 10 ++- .../convertToJava/ConvertToJavaProcessor.java | 2 +- .../convertToJava/ExpressionGenerator.java | 2 +- .../convertToJava/GenerationUtil.java | 19 +---- .../convertToJava/GroovyToJavaGenerator.java | 6 +- .../convertToJava/StubGenerator.java | 26 +------ .../convertToJava/TypeProvider.java | 77 +++++++++++++++++++ .../convertGroovyToJava/file/concurency.java | 3 +- .../file/refInAnonymous.java | 3 +- .../file/refInClosureInMethod.java | 3 +- .../convertGroovyToJava/file/return2.java | 3 +- .../convertGroovyToJava/file/returns.java | 10 +-- .../file/staticProperty.java | 3 +- .../convertGroovyToJava/file/useAnno.java | 3 +- 19 files changed, 117 insertions(+), 91 deletions(-) create mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/TypeProvider.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/typedef/members/GrMethod.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/typedef/members/GrMethod.java index a1067d193d16..beed799aa0c3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/typedef/members/GrMethod.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/typedef/members/GrMethod.java @@ -41,7 +41,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterListOwner; public interface GrMethod extends GrMembersDeclaration, GrNamedElement, PsiMethod, GrMember, GrParametersOwner, GrTopLevelDefinition, GrTypeParameterListOwner, GrDocCommentOwner { GrMethod[] EMPTY_ARRAY = new GrMethod[0]; - Key BUILDER_METHOD = Key.create("BUILDER_METHOD"); ArrayFactory ARRAY_FACTORY = new ArrayFactory() { @Override public GrMethod[] create(int count) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java index 82c63baecb80..8cfa22545c97 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java @@ -49,7 +49,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnnotationTypeDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; @@ -61,7 +60,6 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.GrStubElementBase; import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl; import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; -import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; import org.jetbrains.plugins.groovy.lang.psi.stubs.GrMethodStub; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; import org.jetbrains.plugins.groovy.lang.resolve.MethodTypeInferencer; @@ -185,10 +183,7 @@ public abstract class GrMethodBaseImpl extends GrStubElementBase i public PsiType fun(GrMethodBaseImpl method) { PsiType nominal = method.getNominalType(); if (nominal != null) { - if (!(nominal instanceof PsiClassType) || !hasTypeParametersToInfer((PsiClassType)nominal)) { - if (!(method.getContainingClass() instanceof GrAnnotationTypeDefinition)) { - nominal = TypesUtil.boxPrimitiveType(nominal, method.getManager(), method.getResolveScope()); //for converter - } + if (!(nominal instanceof PsiClassType && hasTypeParametersToInfer((PsiClassType)nominal))) { return nominal; } } @@ -201,8 +196,7 @@ public abstract class GrMethodBaseImpl extends GrStubElementBase i assert block.isValid() : "invalid code block"; PsiType inferred = GroovyPsiManager.inferType(method, new MethodTypeInferencer(block)); if (inferred != null) { - if (nominal == null && inferred != PsiType.VOID || //for converter - nominal != null && nominal.isAssignableFrom(inferred)) { + if (nominal == null || nominal.isAssignableFrom(inferred)) { return inferred; } } @@ -231,6 +225,7 @@ public abstract class GrMethodBaseImpl extends GrStubElementBase i return PsiType.getJavaLangObject(getManager(), getResolveScope()); } + @Nullable private PsiType getNominalType() { final GrTypeElement element = getReturnTypeElementGroovy(); if (element != null) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/AnonymousFromMapGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/AnonymousFromMapGenerator.java index f8fe25a27632..575652bbe692 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/AnonymousFromMapGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/AnonymousFromMapGenerator.java @@ -105,7 +105,7 @@ public class AnonymousFromMapGenerator { PsiType returnType; if (found != null) { - returnType = substitutor.substitute(found.getReturnType()); + returnType = substitutor.substitute(TypeProvider.getReturnType(found)); } else { returnType = signature.getReturnType(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassGenerator.java index 502d138632ee..3da9d806a7b2 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassGenerator.java @@ -15,8 +15,6 @@ */ package org.jetbrains.plugins.groovy.refactoring.convertToJava; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.Project; import com.intellij.psi.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; @@ -40,14 +38,11 @@ import static org.jetbrains.plugins.groovy.refactoring.convertToJava.GenerationU * @author Maxim.Medvedev */ public class ClassGenerator { - private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.refactoring.convertToJava.ClassGenerator"); - private Project myProject; private ClassNameProvider classNameProvider; private ClassItemGenerator classItemGenerator; - public ClassGenerator(Project project, ClassNameProvider classNameProvider, ClassItemGenerator classItemGenerator) { - myProject = project; + public ClassGenerator(ClassNameProvider classNameProvider, ClassItemGenerator classItemGenerator) { this.classNameProvider = classNameProvider; this.classItemGenerator = classItemGenerator; } @@ -191,9 +186,9 @@ public class ClassGenerator { private static boolean shouldBeGenerated(PsiMethod method) { for (PsiMethod psiMethod : method.findSuperMethods()) { if (!psiMethod.hasModifierProperty(PsiModifier.ABSTRACT)) { - final PsiType type = method.getReturnType(); - final PsiType superType = psiMethod.getReturnType(); - if (type != null && superType != null && !superType.isAssignableFrom(type)) { + final PsiType type = TypeProvider.getReturnType(method); + final PsiType superType = TypeProvider.getReturnType(psiMethod); + if (!superType.isAssignableFrom(type)) { return false; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java index 3c161ea067a7..882b3b6c336e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java @@ -40,7 +40,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.*; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureSignature; import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass; import org.jetbrains.plugins.groovy.lang.psi.impl.types.GrClosureSignatureUtil; -import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; import java.util.ArrayList; import java.util.Arrays; @@ -86,11 +85,9 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { final GrEnumConstantInitializer anonymousBlock = constant.getConstantInitializer(); if (anonymousBlock != null) { builder.append("{\n"); - new ClassGenerator(context.project, classNameProvider, this).writeMembers(builder, anonymousBlock, true); + new ClassGenerator(classNameProvider, this).writeMembers(builder, anonymousBlock, true); builder.append("\n}"); } - - //todo make something with context??? } @Override @@ -123,7 +120,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { //append return type if (!method.isConstructor()) { - PsiType retType = PsiUtil.getSmartReturnType(method); + PsiType retType = TypeProvider.getReturnType(method); /* if (!method.hasModifierProperty(PsiModifier.STATIC)) { @@ -206,7 +203,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { builder.append("this"); } else { - if (method.getReturnType() != PsiType.VOID) { + if (TypeProvider.getReturnType(method) != PsiType.VOID) { builder.append("return "); } builder.append(method.getName()); @@ -242,6 +239,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { return result; } + @SuppressWarnings({"MethodMayBeStatic"}) private void writeMainScriptMethodBody(StringBuilder builder, PsiMethod method) { final PsiClass containingClass = method.getContainingClass(); LOG.assertTrue(containingClass instanceof GroovyScriptClass); @@ -295,6 +293,7 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { } } + @SuppressWarnings({"MethodMayBeStatic"}) private PsiClassType[] getMethodExceptions(PsiMethod method) { return method.getThrowsList().getReferencedTypes(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java index 5438f9e0a1ea..a468483a2cc0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java @@ -89,9 +89,11 @@ public class CodeBlockGenerator extends Generator { boolean shouldInsertReturnNull = false; myExitPoints.clear(); - if (!method.isConstructor() && method.getReturnType() != PsiType.VOID) { + PsiType returnType = TypeProvider.getReturnType(method); + if (!method.isConstructor() && returnType != PsiType.VOID) { myExitPoints.addAll(ControlFlowUtils.collectReturns(block)); - shouldInsertReturnNull = MissingReturnInspection.methodMissesSomeReturns(block, method.getReturnType() != null); + shouldInsertReturnNull = !(returnType instanceof PsiPrimitiveType) && + MissingReturnInspection.methodMissesSomeReturns(block, method.getReturnTypeElementGroovy() != null); } if (block != null) { @@ -356,7 +358,7 @@ public class CodeBlockGenerator extends Generator { private static void writeVariableWithoutSemicolonAndInitializer(StringBuilder builder, GrVariable var) { ModifierListGenerator.writeModifiers(builder, var.getModifierList()); - GenerationUtil.writeType(builder, GenerationUtil.getVarType(var), var); + GenerationUtil.writeType(builder, TypeProvider.getVarType(var), var); builder.append(" ").append(var.getName()); } @@ -477,7 +479,7 @@ public class CodeBlockGenerator extends Generator { final GrModifierList modifierList = variableDeclaration.getModifierList(); for (final GrVariable v : variables) { ModifierListGenerator.writeModifiers(builder, modifierList); - final PsiType type = GenerationUtil.getVarType(v); + final PsiType type = TypeProvider.getVarType(v); GenerationUtil.writeType(builder, type, variableDeclaration); builder.append(" ").append(v.getName()); builder.append(" = ").append(iteratorName).append(".hasNext() ? ").append(iteratorName).append(".next() : null;"); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ConvertToJavaProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ConvertToJavaProcessor.java index f1186367ef06..2bf6d0018485 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ConvertToJavaProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ConvertToJavaProcessor.java @@ -74,7 +74,7 @@ public class ConvertToJavaProcessor extends BaseRefactoringProcessor { @Override protected void performRefactoring(UsageInfo[] usages) { final GeneratorClassNameProvider classNameProvider = new GeneratorClassNameProvider(); - final ClassGenerator classGenerator = new ClassGenerator(myProject, classNameProvider, new ClassItemGeneratorImpl(myProject)); + final ClassGenerator classGenerator = new ClassGenerator(classNameProvider, new ClassItemGeneratorImpl(myProject)); for (GroovyFile file : myFiles) { final PsiClass[] classes = file.getClasses(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java index 184f449e1921..ba06cf873ab7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java @@ -284,7 +284,7 @@ public class ExpressionGenerator extends Generator { private void writeTypeBody(StringBuilder builder, GrAnonymousClassDefinition anonymous) { builder.append("{\n"); - new ClassGenerator(context.project, new GeneratorClassNameProvider(), new ClassItemGeneratorImpl(context.extend())) + new ClassGenerator(new GeneratorClassNameProvider(), new ClassItemGeneratorImpl(context.extend())) .writeMembers(builder, anonymous, true); builder.append('}'); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java index ef2724df3adb..ad9391d015f4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java @@ -239,10 +239,6 @@ public class GenerationUtil { return curClass; } - static PsiType findOutParameterType(PsiParameter parameter) { - return parameter.getType(); //todo make smarter - } - static boolean isAbstractInJava(PsiMethod method) { if (method.hasModifierProperty(PsiModifier.ABSTRACT)) { return true; @@ -286,7 +282,7 @@ public class GenerationUtil { if (parameter == null) continue; if (i > 0) text.append(", "); //append ',' - writeType(text, findOutParameterType(parameter), parameter, classNameProvider); + writeType(text, TypeProvider.getParameterType(parameter), parameter, classNameProvider); text.append(" "); text.append(parameter.getName()); @@ -357,17 +353,6 @@ public class GenerationUtil { return actual; } - public static PsiType getVarType(GrVariable variable) { - PsiType type = variable.getDeclaredType(); - if (type == null) { - type = variable.getTypeGroovy(); - } - if (type == null) { - type = variable.getType(); - } - return type; - } - public static void writeSimpleVarDeclaration(GrVariableDeclaration variableDeclaration, StringBuilder builder, ExpressionContext expressionContext) { @@ -430,7 +415,7 @@ public class GenerationUtil { } static void writeVariableSeparately(GrVariable variable, StringBuilder builder, ExpressionContext expressionContext) { - PsiType type = getVarType(variable); + PsiType type = TypeProvider.getVarType(variable); ModifierListGenerator.writeModifiers(builder, variable.getModifierList()); PsiType originalType = type; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GroovyToJavaGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GroovyToJavaGenerator.java index 9a858c856a38..93b11653df36 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GroovyToJavaGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GroovyToJavaGenerator.java @@ -114,8 +114,8 @@ public class GroovyToJavaGenerator { try { StringBuilder text = new StringBuilder(); final ClassNameProvider classNameProvider = new StubClassNameProvider(myAllToCompile); - ClassItemGenerator classItemGenerator = new StubGenerator(classNameProvider, myProject); - new ClassGenerator(myProject, classNameProvider, classItemGenerator).writeTypeDefinition(text, typeDefinition, true, true); + ClassItemGenerator classItemGenerator = new StubGenerator(classNameProvider); + new ClassGenerator(classNameProvider, classItemGenerator).writeTypeDefinition(text, typeDefinition, true, true); return text; } catch (ProcessCanceledException e) { @@ -138,7 +138,7 @@ public class GroovyToJavaGenerator { return method.getText(); } - final ClassItemGenerator generator = new StubGenerator(new StubClassNameProvider(Collections.emptySet()), method.getProject()); + final ClassItemGenerator generator = new StubGenerator(new StubClassNameProvider(Collections.emptySet())); final StringBuilder buffer = new StringBuilder(); if (method instanceof GrConstructor) { generator.writeConstructor(buffer, (GrConstructor)method, 0, false); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java index 8b69cf74dfd1..c04ffca8c38d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java @@ -17,7 +17,6 @@ package org.jetbrains.plugins.groovy.refactoring.convertToJava; import com.intellij.codeInsight.generation.OverrideImplementUtil; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.impl.light.LightMethodBuilder; @@ -41,7 +40,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrCo import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; -import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; import java.util.*; @@ -65,12 +63,10 @@ public class StubGenerator implements ClassItemGenerator { }; private ClassNameProvider classNameProvider; - private Project myProject; private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.refactoring.convertToJava.StubGenerator"); - public StubGenerator(ClassNameProvider classNameProvider, Project project) { + public StubGenerator(ClassNameProvider classNameProvider) { this.classNameProvider = classNameProvider; - myProject = project; } public void writeEnumConstant(StringBuilder text, GrEnumConstant enumConstant) { @@ -101,7 +97,7 @@ public class StubGenerator implements ClassItemGenerator { for (int j = 0; j < superParams.length; j++) { if (j > 0) text.append(", "); text.append("("); - final PsiType type = GenerationUtil.findOutParameterType(superParams[j]); + final PsiType type = TypeProvider.getParameterType(superParams[j]); writeType(text, substitutor.substitute(type), invocation, classNameProvider); text.append(")").append(GroovyToJavaGenerator.getDefaultValueText(type.getCanonicalText())); } @@ -189,7 +185,7 @@ public class StubGenerator implements ClassItemGenerator { } //append return type - PsiType retType = findOutReturnTypeOfMethod(method); + PsiType retType = TypeProvider.getReturnType(method, true); if (!method.hasModifierProperty(PsiModifier.STATIC)) { final List superSignatures = method.findSuperMethodSignaturesIncludingStatic(true); @@ -266,20 +262,6 @@ public class StubGenerator implements ClassItemGenerator { return null; } - private PsiType findOutReturnTypeOfMethod(PsiMethod method) { - final PsiType returnType = method.getReturnType(); - if (returnType != null) return returnType; - - if (classNameProvider.forStubs()) return TypesUtil.getJavaLangObject(method); - - final PsiType smartReturnType = org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.getSmartReturnType(method); - if (smartReturnType != null) return smartReturnType; - - //todo make smarter. search for usages and infer type from them - return TypesUtil.getJavaLangObject(method); - //final Collection collection = MethodReferencesSearch.search(method).findAll(); - } - public Collection collectMethods(PsiClass typeDefinition, boolean classDef) { List methods = new ArrayList(); ContainerUtil.addAll(methods, typeDefinition.getMethods()); @@ -338,7 +320,7 @@ public class StubGenerator implements ClassItemGenerator { final LightMethodBuilder builder = new LightMethodBuilder(method.getManager(), method.getName()); substitutor = substitutor.putAll(TypeConversionUtil.getSuperClassSubstitutor(baseClass, typeDefinition, PsiSubstitutor.EMPTY)); for (PsiParameter parameter : method.getParameterList().getParameters()) { - builder.addParameter(StringUtil.notNullize(parameter.getName()), substitutor.substitute(GenerationUtil.findOutParameterType(parameter))); + builder.addParameter(StringUtil.notNullize(parameter.getName()), substitutor.substitute(TypeProvider.getParameterType(parameter))); } builder.setReturnType(substitutor.substitute(method.getReturnType())); for (String modifier : STUB_MODIFIERS) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/TypeProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/TypeProvider.java new file mode 100644 index 000000000000..24879e233640 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/TypeProvider.java @@ -0,0 +1,77 @@ +/* + * Copyright 2000-2011 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 org.jetbrains.plugins.groovy.refactoring.convertToJava; + +import com.intellij.psi.PsiMethod; +import com.intellij.psi.PsiParameter; +import com.intellij.psi.PsiType; +import com.intellij.psi.PsiVariable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; +import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; +import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; +import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; + +/** + * @author Medvedev Max + */ +public class TypeProvider { + + private TypeProvider() { + } + + @NotNull + public static PsiType getReturnType(PsiMethod method) { + return getReturnType(method, false); + } + + @NotNull + public static PsiType getReturnType(PsiMethod method, boolean forStubs) { + + if (forStubs) { + PsiType returnType = method.getReturnType(); + if (returnType != null) return returnType; + return TypesUtil.getJavaLangObject(method); + } + if (method instanceof GrMethod) { + GrTypeElement typeElement = ((GrMethod)method).getReturnTypeElementGroovy(); + if (typeElement != null) return typeElement.getType(); + } + final PsiType smartReturnType = PsiUtil.getSmartReturnType(method); + if (smartReturnType != null) return smartReturnType; + + //todo make smarter. search for usages and infer type from them + return TypesUtil.getJavaLangObject(method); + } + + @NotNull + public static PsiType getVarType(GrVariable variable) { + PsiType type = variable.getDeclaredType(); + if (type == null) { + type = variable.getTypeGroovy(); + } + if (type == null) { + type = variable.getType(); + } + return type; + } + + @NotNull + public static PsiType getParameterType(PsiParameter parameter) { + return parameter.getType(); //todo make smarter + } +} diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/concurency.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/concurency.java index af7bfcd52511..398d6e05b5d9 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/concurency.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/concurency.java @@ -32,9 +32,8 @@ return null; } -public synchronized java.lang.Object out(java.lang.Object message) { +public synchronized void out(java.lang.Object message) { println(message); -return null; } public concurency(groovy.lang.Binding binding) { diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInAnonymous.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInAnonymous.java index efc07c54b20f..efff59501608 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInAnonymous.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInAnonymous.java @@ -1,5 +1,5 @@ public class A extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { -public java.lang.Object foo() { +public void foo() { final groovy.lang.Reference x = new groovy.lang.Reference(2); new java.lang.Runnable(){ public void run() { @@ -8,7 +8,6 @@ org.codehaus.groovy.runtime.DefaultGroovyMethods.print(this, x.get()); } }.run(); -return null; } } diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.java index c2a0a110318e..116505543de1 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.java @@ -1,5 +1,5 @@ public class X extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { -public java.lang.Object foo() { +public void foo() { final groovy.lang.Reference ab = new groovy.lang.Reference(4); org.codehaus.groovy.runtime.DefaultGroovyMethods.each(X.this, new groovy.lang.Closure(this, this) { public java.lang.Object doCall(java.lang.Object it) { @@ -21,7 +21,6 @@ return doCall(null); }); org.codehaus.groovy.runtime.DefaultGroovyMethods.print(X.this, ab.get()); -return null; } } diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/return2.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/return2.java index 46dbfaec64da..2177f8c1c7e0 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/return2.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/return2.java @@ -8,7 +8,7 @@ return null; } -public java.lang.Boolean foo() { +public boolean foo() { java.lang.Integer a = 5; org.codehaus.groovy.runtime.DefaultGroovyMethods.times(a, new groovy.lang.Closure(this, this) { public java.lang.Integer doCall(java.lang.Object it) { @@ -21,7 +21,6 @@ return doCall(null); } }); -return null; } public return2(groovy.lang.Binding binding) { diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/returns.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/returns.java index 2bd0daacecdd..48a66f58393c 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/returns.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/returns.java @@ -1,16 +1,14 @@ public class returns extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { -public java.lang.Object foo1() { +public void foo1() { org.codehaus.groovy.runtime.DefaultGroovyMethods.print(returns.this, "foo"); -return null; } public void foo2() { org.codehaus.groovy.runtime.DefaultGroovyMethods.print(returns.this, "foo"); } -public java.lang.Integer foo3() { +public int foo3() { org.codehaus.groovy.runtime.DefaultGroovyMethods.print(returns.this, "foo"); -return null; } public java.lang.Integer foo4() { @@ -21,7 +19,7 @@ public java.lang.Integer foo5() { return 2; } -public java.lang.Integer foo6() { +public int foo6() { return 2; } @@ -29,7 +27,7 @@ public java.lang.Integer foo7() { if (true)return 3; else return 4; } -public java.lang.Integer foo8() { +public int foo8() { if (true)return 3; else return 4; } diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/staticProperty.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/staticProperty.java index f8b86591c9c1..4b5419fca287 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/staticProperty.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/staticProperty.java @@ -1,7 +1,6 @@ public class Foo extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { -public java.lang.Object print() { +public void print() { org.codehaus.groovy.runtime.DefaultGroovyMethods.print(Foo.this, CONST); -return null; } public static java.lang.Integer getCONST() { diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/useAnno.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/useAnno.java index 151cf9727d89..db0e0707ee2f 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/useAnno.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/useAnno.java @@ -18,9 +18,8 @@ return null; } -@p.I public java.lang.Object foo(java.lang.Object x) { +@p.I public void foo(java.lang.Object x) { @p.I java.lang.Object a; -return null; } public useAnno(groovy.lang.Binding binding) { From e5512988aaac32db35cf6d24da143c54466cd7b0 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Tue, 10 May 2011 19:32:00 +0400 Subject: [PATCH 090/250] [xena] IDEA-69290 Drag-and-drop doesnt work in 107.18EAP [r=pegov] --- .../platform-impl/src/com/intellij/ide/dnd/DnDEventImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/ide/dnd/DnDEventImpl.java b/platform/platform-impl/src/com/intellij/ide/dnd/DnDEventImpl.java index f87f2321d830..441bc42b49e2 100644 --- a/platform/platform-impl/src/com/intellij/ide/dnd/DnDEventImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/dnd/DnDEventImpl.java @@ -101,6 +101,9 @@ public class DnDEventImpl extends UserDataHolderBase implements Transferable, Dn else if (myAttachedObject instanceof FileFlavorProvider) { return new DataFlavor[]{ourDataFlavor, DataFlavor.javaFileListFlavor}; } + else if (myAttachedObject instanceof DnDNativeTarget.EventInfo) { + return ((DnDNativeTarget.EventInfo)myAttachedObject).getFlavors(); + } return new DataFlavor[]{ourDataFlavor}; } From 6584bc1f2201e10d5f6cecb0ab7128532da58ba2 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 10 May 2011 17:32:44 +0200 Subject: [PATCH 091/250] IDEA-34917 (CVS: use -F option for annotate command) retry without -F on old cvs servers which cannot handle it --- .../src/com/intellij/cvsSupport2/CvsUtil.java | 4 +- .../src/com/intellij/cvsSupport2/CvsVcs2.java | 11 +- .../annotate/CvsAnnotationProvider.java | 110 ++++++++++-------- .../cvsAnnotate/AnnotateOperation.java | 15 +-- 4 files changed, 70 insertions(+), 70 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsUtil.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsUtil.java index 26a9a076a802..ff7e75bba3bc 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsUtil.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsUtil.java @@ -76,6 +76,7 @@ public class CvsUtil { @NonNls public static final String STICKY_NON_BRANCH_TAG_PREFIX = "N"; @NonNls public static final String HEAD = "HEAD"; @NonNls public static final String BASE = "Base"; + @NonNls public static final String REVISION_PATTERN = "\\d+(\\.\\d+)*"; public static void skip(InputStream inputStream, int length) throws IOException { int skipped = 0; @@ -496,8 +497,7 @@ public class CvsUtil { private static void deleteAllOtherRevisions(final VirtualFile file, final String storedFilename) { File ioFile = new File(file.getPath()); - final Pattern pattern = Pattern.compile("\\\u002E#" + ioFile.getName().replace(".", "\\\u002E") + "\u002E" + - CvsVcs2.staticRevisionPattern()); + final Pattern pattern = Pattern.compile("\\\u002E#" + ioFile.getName().replace(".", "\\\u002E") + "\u002E" + REVISION_PATTERN); final File dir = new File(getAdminDir(ioFile.getParentFile()), BASE_REVISIONS_DIR); File[] files = dir.listFiles(new FilenameFilter() { public boolean accept(final File dir, final String name) { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java index 4d142917c269..73a81c24d64c 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsVcs2.java @@ -56,7 +56,6 @@ import com.intellij.openapi.vcs.merge.MergeProvider; import com.intellij.openapi.vcs.rollback.RollbackEnvironment; import com.intellij.openapi.vcs.update.UpdateEnvironment; import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -74,8 +73,6 @@ public class CvsVcs2 extends AbstractVcs implements TransactionProvider, EditFil private static final VcsKey ourKey = createKey(NAME); private final Cvs2Configurable myConfigurable; - @NonNls private static final String ourRevisionPattern = "\\d+(\\.\\d+)*"; - private CvsStorageComponent myStorageComponent = CvsStorageComponent.ABSENT_STORAGE; private final CvsHistoryProvider myCvsHistoryProvider; private final CvsCheckinEnvironment myCvsCheckinEnvironment; @@ -110,7 +107,7 @@ public class CvsVcs2 extends AbstractVcs implements TransactionProvider, EditFil myConfigurable = new Cvs2Configurable(getProject()); myStorageComponent = cvsStorageComponent; - myCvsAnnotationProvider = new CvsAnnotationProvider(myProject); + myCvsAnnotationProvider = new CvsAnnotationProvider(myProject, myCvsHistoryProvider); myDiffProvider = new CvsDiffProvider(myProject); myCommittedChangesProvider = new CvsCommittedChangesProvider(myProject); @@ -329,11 +326,7 @@ public class CvsVcs2 extends AbstractVcs implements TransactionProvider, EditFil @Override public String getRevisionPattern() { - return ourRevisionPattern; - } - - public static String staticRevisionPattern() { - return ourRevisionPattern; + return CvsUtil.REVISION_PATTERN; } @Override diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/annotate/CvsAnnotationProvider.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/annotate/CvsAnnotationProvider.java index 0fae1e6c00ba..b4019f8adce1 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/annotate/CvsAnnotationProvider.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/annotate/CvsAnnotationProvider.java @@ -17,7 +17,6 @@ package com.intellij.cvsSupport2.annotate; import com.intellij.CvsBundle; import com.intellij.cvsSupport2.CvsUtil; -import com.intellij.cvsSupport2.CvsVcs2; import com.intellij.cvsSupport2.application.CvsEntriesManager; import com.intellij.cvsSupport2.connections.CvsConnectionSettings; import com.intellij.cvsSupport2.connections.CvsEnvironment; @@ -28,6 +27,7 @@ import com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.AnnotateOperation; import com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.Annotation; import com.intellij.cvsSupport2.history.CvsHistoryProvider; import com.intellij.cvsSupport2.history.CvsRevisionNumber; +import com.intellij.openapi.cvsIntegration.CvsResult; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.VcsException; @@ -37,6 +37,7 @@ import com.intellij.openapi.vcs.annotate.FileAnnotation; import com.intellij.openapi.vcs.history.VcsFileRevision; import com.intellij.openapi.vcs.history.VcsRevisionNumber; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,28 +45,30 @@ import java.io.File; import java.util.*; public class CvsAnnotationProvider implements AnnotationProvider{ - private final Project myProject; - public CvsAnnotationProvider(final Project project) { + @NonNls private static final String INVALID_OPTION_F = "invalid option -- F"; + + private final Project myProject; + private final CvsHistoryProvider myCvsHistoryProvider; + + public CvsAnnotationProvider(final Project project, CvsHistoryProvider cvsHistoryProvider) { myProject = project; + myCvsHistoryProvider = cvsHistoryProvider; } - public FileAnnotation annotate(VirtualFile file) throws VcsException { - final AnnotateOperation operation = AnnotateOperation.createForFile(new File(file.getPath())); - final CvsOperationExecutor executor = new CvsOperationExecutor(myProject); - executor.performActionSync(new CommandCvsHandler(CvsBundle.getAnnotateOperationName(), operation), - CvsOperationExecutorCallback.EMPTY); - if (executor.getResult().hasNoErrors()) { - final CvsVcs2 cvsVcs2 = CvsVcs2.getInstance(myProject); - final CvsHistoryProvider historyProvider = (CvsHistoryProvider) cvsVcs2.getVcsHistoryProvider(); - final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file); - final List revisions = historyProvider.createRevisions(filePath); - final Annotation[] lineAnnotations = operation.getLineAnnotations(); - adjustAnnotation(revisions, lineAnnotations); - return new CvsFileAnnotation(operation.getContent(), lineAnnotations, revisions, file); - } else { - throw executor.getFirstError(); - } + public FileAnnotation annotate(VirtualFile virtualFile) throws VcsException { + final File file = new File(virtualFile.getPath()); + File cvsLightweightFile = CvsUtil.getCvsLightweightFileForFile(file); + String revision = CvsUtil.getRevisionFor(file); + final CvsConnectionSettings root = + CvsEntriesManager.getInstance().getCvsConnectionSettingsFor(file.getParentFile()); + final AnnotateOperation operation = executeOperation(cvsLightweightFile, revision, root, true); + + final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(virtualFile); + final List revisions = myCvsHistoryProvider.createRevisions(filePath); + final Annotation[] lineAnnotations = operation.getLineAnnotations(); + adjustAnnotation(revisions, lineAnnotations); + return new CvsFileAnnotation(operation.getContent(), lineAnnotations, revisions, virtualFile); } public FileAnnotation annotate(VirtualFile file, VcsFileRevision revision) throws VcsException { @@ -87,40 +90,53 @@ public class CvsAnnotationProvider implements AnnotationProvider{ hasLocalFile = true; cvsFile = new File(CvsUtil.getModuleName(cvsVirtualFile)); } - final AnnotateOperation annotateOperation = new AnnotateOperation(cvsFile, revision, environment); - CvsOperationExecutor executor = new CvsOperationExecutor(myProject); - executor.performActionSync(new CommandCvsHandler(CvsBundle.getAnnotateOperationName(), annotateOperation), - CvsOperationExecutorCallback.EMPTY); - if (executor.getResult().hasNoErrors()) { - final List revisions; - final Annotation[] lineAnnotations = annotateOperation.getLineAnnotations(); - if (hasLocalFile) { - final CvsVcs2 cvsVcs2 = CvsVcs2.getInstance(myProject); - final CvsHistoryProvider historyProvider = (CvsHistoryProvider) cvsVcs2.getVcsHistoryProvider(); - final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(cvsVirtualFile); - revisions = historyProvider.createRevisions(filePath); - // in annotation cvs returns only 8 symbols of username - // try to find usernames in history and use them - adjustAnnotation(revisions, lineAnnotations); + final AnnotateOperation annotateOperation = executeOperation(cvsFile, revision, environment, true); + final Annotation[] lineAnnotations = annotateOperation.getLineAnnotations(); + final List revisions; + if (hasLocalFile) { + final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(cvsVirtualFile); + revisions = myCvsHistoryProvider.createRevisions(filePath); + // in annotation cvs returns only 8 symbols of username + // try to find usernames in history and use them + adjustAnnotation(revisions, lineAnnotations); + } + else { + // imitation + revisions = new ArrayList(); + final Set usedRevisions = new HashSet(); + for (Annotation annotation : lineAnnotations) { + if (! usedRevisions.contains(annotation.getRevision())) { + revisions.add(new RevisionPresentation(annotation.getRevision(), annotation.getUserName(), annotation.getDate())); + usedRevisions.add(annotation.getRevision()); + } } - else { - // imitation - revisions = new ArrayList(); - final Set usedRevisions = new HashSet(); - for (Annotation annotation : lineAnnotations) { - if (! usedRevisions.contains(annotation.getRevision())) { - revisions.add(new RevisionPresentation(annotation.getRevision(), annotation.getUserName(), annotation.getDate())); - usedRevisions.add(annotation.getRevision()); + } + return new CvsFileAnnotation(annotateOperation.getContent(), lineAnnotations, revisions, cvsVirtualFile); + } + + private AnnotateOperation executeOperation(File cvsLightweightFile, String revision, CvsEnvironment root, boolean retryOnFailure) + throws VcsException { + final AnnotateOperation operation = new AnnotateOperation(cvsLightweightFile, revision, root); + final CvsOperationExecutor executor = new CvsOperationExecutor(myProject); + executor.performActionSync(new CommandCvsHandler(CvsBundle.getAnnotateOperationName(), operation), + CvsOperationExecutorCallback.EMPTY); + final CvsResult result = executor.getResult(); + if (!result.hasNoErrors()) { + if (!retryOnFailure) { + throw result.composeError(); + } + for (VcsException error : result.getErrors()) { + for (String message : error.getMessages()) { + if (message.contains(INVALID_OPTION_F)) { + AnnotateOperation.doesNotSupportAnnotateBinary(root); + return executeOperation(cvsLightweightFile, revision, root, false); } } } - return new CvsFileAnnotation(annotateOperation.getContent(), lineAnnotations, revisions, cvsVirtualFile); + throw result.composeError(); } - else { - throw executor.getResult().composeError(); - } - + return operation; } private static void adjustAnnotation(@Nullable List revisions, @NotNull Annotation[] lineAnnotations) { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAnnotate/AnnotateOperation.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAnnotate/AnnotateOperation.java index bcae101c8c8a..39ad5bfd667c 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAnnotate/AnnotateOperation.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAnnotate/AnnotateOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,13 +15,11 @@ */ package com.intellij.cvsSupport2.cvsoperations.cvsAnnotate; -import com.intellij.cvsSupport2.application.CvsEntriesManager; import com.intellij.cvsSupport2.connections.CvsEnvironment; import com.intellij.cvsSupport2.connections.CvsRootProvider; -import com.intellij.cvsSupport2.cvsoperations.common.LocalPathIndifferentOperationHelper; -import com.intellij.cvsSupport2.cvsoperations.common.LocalPathIndifferentOperation; import com.intellij.cvsSupport2.cvsoperations.common.CvsExecutionEnvironment; -import com.intellij.cvsSupport2.CvsUtil; +import com.intellij.cvsSupport2.cvsoperations.common.LocalPathIndifferentOperation; +import com.intellij.cvsSupport2.cvsoperations.common.LocalPathIndifferentOperationHelper; import com.intellij.openapi.diagnostic.Logger; import org.netbeans.lib.cvsclient.command.Command; import org.netbeans.lib.cvsclient.command.annotate.AnnotateCommand; @@ -47,13 +45,6 @@ public class AnnotateOperation extends LocalPathIndifferentOperation { private final StringBuffer myBuffer = new StringBuffer(); private final LocalPathIndifferentOperationHelper myHelper; - public static AnnotateOperation createForFile(File file){ - File cvsLightweightFile = CvsUtil.getCvsLightweightFileForFile(file); - String revision = CvsUtil.getRevisionFor(file); - return new AnnotateOperation(cvsLightweightFile, - revision, CvsEntriesManager.getInstance().getCvsConnectionSettingsFor(file.getParentFile())); - } - public AnnotateOperation(File cvsLightweightFile, String revision, CvsEnvironment env) { this(cvsLightweightFile, revision, env, new LocalPathIndifferentOperationHelper(revision)); } From 23806949c5fcc3fe51fa01858b8053f9b12b204d Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Tue, 10 May 2011 19:38:54 +0400 Subject: [PATCH 092/250] IDEA-68801 Debugger views on Mac: grey text over grey background is unreadable --- .../src/com/intellij/ui/ColoredTreeCellRenderer.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/platform/platform-api/src/com/intellij/ui/ColoredTreeCellRenderer.java b/platform/platform-api/src/com/intellij/ui/ColoredTreeCellRenderer.java index 2d1d64cb6bd9..906e4fb479be 100644 --- a/platform/platform-api/src/com/intellij/ui/ColoredTreeCellRenderer.java +++ b/platform/platform-api/src/com/intellij/ui/ColoredTreeCellRenderer.java @@ -128,6 +128,9 @@ public abstract class ColoredTreeCellRenderer extends SimpleColoredComponent imp if (mySelected && (myFocused || UIUtil.isUnderNimbusLookAndFeel())) { super.append(fragment, new SimpleTextAttributes(attributes.getStyle(), UIUtil.getTreeSelectionForeground()), isMainText); } + else if (mySelected && UIUtil.isUnderAquaLookAndFeel()) { + super.append(fragment, new SimpleTextAttributes(attributes.getStyle(), UIUtil.getTreeForeground()), isMainText); + } else { super.append(fragment, attributes, isMainText); } From bf1038f962214d658f313fa5968c2f8733444f6f Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 10 May 2011 15:43:41 +0400 Subject: [PATCH 093/250] [alexander.podkhalyuzin] EA-27828 (Convert to Basic Latin intention supports only Java-like elements) --- .../codeInsight/intention/impl/ConvertToBasicLatinAction.java | 2 ++ .../intellij/codeInsight/intention/ConvertToBasicLatinTest.java | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConvertToBasicLatinAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConvertToBasicLatinAction.java index 63363e5ccae5..83cc0ce9b398 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConvertToBasicLatinAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConvertToBasicLatinAction.java @@ -18,6 +18,7 @@ package com.intellij.codeInsight.intention.impl; import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction; import com.intellij.javaee.ExternalResourceManager; +import com.intellij.lang.StdLanguages; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -49,6 +50,7 @@ public class ConvertToBasicLatinAction extends PsiElementBaseIntentionAction { @Override public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) { + if (!element.getLanguage().isKindOf(StdLanguages.JAVA)) return false; final Pair pair = findHandler(element); if (pair == null) return false; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/intention/ConvertToBasicLatinTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/intention/ConvertToBasicLatinTest.java index 3f9cc1c6907e..2fe3054ef8d3 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/intention/ConvertToBasicLatinTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/intention/ConvertToBasicLatinTest.java @@ -24,7 +24,6 @@ import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase; public class ConvertToBasicLatinTest extends JavaCodeInsightFixtureTestCase { - private String myIntention; @Override @@ -54,5 +53,4 @@ public class ConvertToBasicLatinTest extends JavaCodeInsightFixtureTestCase { protected String getTestDataPath() { return JavaTestUtil.getJavaTestDataPath() + "/codeInsight/convertToBasicLatin/"; } - } From 81ccf87e4af7415ee5b81b3a2090b416a6fac6c4 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Tue, 10 May 2011 20:18:57 +0400 Subject: [PATCH 094/250] diagnostics for findHeavywieghtCursor for Mac --- .../com/intellij/ide/IdeRepaintManager.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/ide/IdeRepaintManager.java b/platform/platform-impl/src/com/intellij/ide/IdeRepaintManager.java index 2583a1fd275f..0b8930d53c37 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeRepaintManager.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeRepaintManager.java @@ -23,6 +23,7 @@ package com.intellij.ide; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.registry.Registry; import org.jetbrains.annotations.NonNls; import javax.swing.*; @@ -30,6 +31,7 @@ import java.awt.*; import java.awt.image.VolatileImage; import java.lang.ref.WeakReference; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.Map; import java.util.WeakHashMap; @@ -78,6 +80,31 @@ public class IdeRepaintManager extends RepaintManager { } } + @Override + public void validateInvalidComponents() { + if (Registry.is("ide.debugMode")) { + try { + Field invalids = getClass().getSuperclass().getDeclaredField("invalidComponents"); + invalids.setAccessible(true); + ArrayList invalidComponents = (ArrayList)invalids.get(this); + if (invalidComponents != null) { + for (Object each : invalidComponents) { + if (each instanceof Component) { + if (SwingUtilities.getWindowAncestor((Component)each) == null) { + System.out.println("Invalid component without peer: " + each); + } + } + } + } + } + catch (Exception e) { + Thread.dumpStack(); + } + } + + super.validateInvalidComponents(); + } + @Override public void addInvalidComponent(final JComponent invalidComponent) { checkThreadViolations(invalidComponent); From 0683767f8f539512cd6272c7ae55806f38989c22 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 10 May 2011 20:12:16 +0400 Subject: [PATCH 095/250] Fixed python UT testing. --- .../testframework/sm/runner/SMTestProxy.java | 23 +++++++++++++++++++ .../sm/runner/ui/TestResultsViewer.java | 19 +++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java index cfdf4eb36c80..5a896c2db8d1 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java @@ -15,6 +15,7 @@ */ package com.intellij.execution.testframework.sm.runner; +import com.google.common.collect.Lists; import com.intellij.execution.Location; import com.intellij.execution.testframework.AbstractTestProxy; import com.intellij.execution.testframework.Filter; @@ -331,9 +332,31 @@ public class SMTestProxy extends AbstractTestProxy { myParent = parent; } + public List collectChildren(@Nullable final Filter filter) { + return filterChildren(filter, collectChildren()); + } + + public List collectChildren() { + final List allChildren = getChildren(); + + final List result = Lists.newArrayList(); + + result.addAll(allChildren); + + for (SMTestProxy p: allChildren) { + result.addAll(p.collectChildren()); + } + + return result; + } + public List getChildren(@Nullable final Filter filter) { final List allChildren = getChildren(); + return filterChildren(filter, allChildren); + } + + private static List filterChildren(@Nullable Filter filter, List allChildren) { if (filter == Filter.NO_FILTER || filter == null) { return allChildren; } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestResultsViewer.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestResultsViewer.java index c81ef7976651..3522a8dc648e 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestResultsViewer.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/TestResultsViewer.java @@ -16,8 +16,10 @@ package com.intellij.execution.testframework.sm.runner.ui; import com.intellij.execution.testframework.AbstractTestProxy; +import com.intellij.execution.testframework.TestFrameworkRunningModel; import com.intellij.execution.testframework.sm.runner.SMTestProxy; import com.intellij.openapi.Disposable; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -50,4 +52,21 @@ public interface TestResultsViewer extends Disposable { void onTestingFinished(TestResultsViewer sender); void onTestNodeAdded(TestResultsViewer sender, SMTestProxy test); } + + class SMEventsAdapter implements EventsListener { + + @Override + public void onTestingStarted(TestResultsViewer sender) {} + + @Override + public void onTestingFinished(TestResultsViewer sender) {} + + @Override + public void onTestNodeAdded(TestResultsViewer sender, SMTestProxy test) {} + + @Override + public void onSelected(@Nullable SMTestProxy selectedTestProxy, + @NotNull TestResultsViewer viewer, + @NotNull TestFrameworkRunningModel model) {} + } } From f51824afde9782853a5e321a03cf67fdc86d6d46 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 18:03:37 +0200 Subject: [PATCH 096/250] IDEA-67783 Code Completion: If IDEA window is switched to another one right before auto completion appears, the completion will popup in active window --- .../src/com/intellij/codeInsight/hint/HintManagerImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java index f595a9a94868..d0a16fcd3c0f 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java @@ -281,6 +281,7 @@ public class HintManagerImpl extends HintManager implements Disposable { } if (!ApplicationManager.getApplication().isUnitTestMode() && !editor.getContentComponent().isShowing()) return; + if (!ApplicationManager.getApplication().isActive()) return; updateLastEditor(editor); From 577e2672c5f7c668fed8626960fe99021506ddd0 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 10 May 2011 20:45:57 +0400 Subject: [PATCH 097/250] Removed duplicated tests. --- platform/smRunner/smRunner.iml | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/smRunner/smRunner.iml b/platform/smRunner/smRunner.iml index 013cdd85da4b..18c546486a69 100644 --- a/platform/smRunner/smRunner.iml +++ b/platform/smRunner/smRunner.iml @@ -15,6 +15,7 @@ + From af5640b4a2544dcd6ef5a98d4ee954dd2e2fba3b Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 10 May 2011 16:43:02 +0200 Subject: [PATCH 098/250] longer delay for the forced dumb mode right after the project is opened --- .../src/com/intellij/openapi/project/DumbModeIndicator.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/project/DumbModeIndicator.java b/platform/platform-impl/src/com/intellij/openapi/project/DumbModeIndicator.java index 4245f05eaed3..a453a8ea2577 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/DumbModeIndicator.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/DumbModeIndicator.java @@ -34,16 +34,19 @@ public class DumbModeIndicator extends AbstractProjectComponent { public void projectOpened() { myProject.getMessageBus().connect().subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() { + boolean myFirstNotification = true; // first dumb mode is always a "forced" dumb mode including initial project scan BalloonHandler myHandler; public void enteredDumbMode() { + final boolean first = myFirstNotification; + myFirstNotification = false; myAlarm.addRequest(new Runnable() { public void run() { myHandler = DumbService.getInstance(myProject).showDumbModeNotification( "Updating project indices...
" + "Refactorings, usage search and some other features will become available after indexing is complete"); } - }, 1000); + }, first? 10000 : 1000); } public void exitDumbMode() { From 1dbeb36feef1058d457268eae1949ee143cc5156 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 10 May 2011 18:42:15 +0200 Subject: [PATCH 099/250] [r=peter] performance: remove slow code from under synchronized section (IDEA-69460) --- .../ant/config/impl/AntBuildFileImpl.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntBuildFileImpl.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntBuildFileImpl.java index 7c6a7e2c0615..4b84398bac56 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntBuildFileImpl.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntBuildFileImpl.java @@ -50,6 +50,7 @@ public class AntBuildFileImpl implements AntBuildFileBase { @NonNls private static final String USER_HOME = "user.home"; @NonNls private static final String ANT_LIB = "/.ant/lib"; private volatile Map myCachedExternalProperties; + private final Object myOptionsLock = new Object(); public static final AbstractProperty ANT_INSTALLATION = new AbstractProperty() { public String getName() { @@ -273,15 +274,16 @@ public class AntBuildFileImpl implements AntBuildFileBase { } public void updateProperties() { - synchronized (this) { + final Map targetByName = + ContainerUtil.assignKeys(Arrays.asList(getModel().getTargets()).iterator(), new Convertor() { + public String convert(AntBuildTarget target) { + return target.getName(); + } + }); + targetByName.remove(null); // ensure there are no targets with 'null' name + + synchronized (myOptionsLock) { myCachedExternalProperties = null; - final Map targetByName = - ContainerUtil.assignKeys(Arrays.asList(getModel().getTargets()).iterator(), new Convertor() { - public String convert(AntBuildTarget target) { - return target.getName(); - } - }); - targetByName.remove(null); // ensure there are no targets with 'null' name final ArrayList filters = TARGET_FILTERS.getModifiableList(myAllOptions); for (Iterator iterator = filters.iterator(); iterator.hasNext();) { final TargetFilter filter = iterator.next(); @@ -325,7 +327,7 @@ public class AntBuildFileImpl implements AntBuildFileBase { } public void readWorkspaceProperties(final Element parentNode) throws InvalidDataException { - synchronized (this) { + synchronized (myOptionsLock) { myWorkspaceOptions.readExternal(parentNode); final Element expanded = parentNode.getChild("expanded"); if (expanded != null) { @@ -335,7 +337,7 @@ public class AntBuildFileImpl implements AntBuildFileBase { } public void writeWorkspaceProperties(final Element parentNode) throws WriteExternalException { - synchronized (this) { + synchronized (myOptionsLock) { myWorkspaceOptions.writeExternal(parentNode); final Element expandedElem = new Element("expanded"); expandedElem.setAttribute("value", Boolean.toString(myShouldExpand)); @@ -344,7 +346,7 @@ public class AntBuildFileImpl implements AntBuildFileBase { } public void readProperties(final Element parentNode) throws InvalidDataException { - synchronized (this) { + synchronized (myOptionsLock) { myProjectOptions.readExternal(parentNode); basicUpdateConfig(); readWorkspaceProperties(parentNode); // Compatibility with old Idea @@ -352,7 +354,7 @@ public class AntBuildFileImpl implements AntBuildFileBase { } public void writeProperties(final Element parentNode) throws WriteExternalException { - synchronized (this) { + synchronized (myOptionsLock) { myProjectOptions.writeExternal(parentNode); } } @@ -369,8 +371,9 @@ public class AntBuildFileImpl implements AntBuildFileBase { public Map getExternalProperties() { Map result = myCachedExternalProperties; if (result == null) { - synchronized (this) { - if (myCachedExternalProperties == null) { + synchronized (myOptionsLock) { + result = myCachedExternalProperties; + if (result == null) { result = new HashMap(); final DataContext context = SimpleDataContext.getProjectContext(myProject); @@ -390,9 +393,6 @@ public class AntBuildFileImpl implements AntBuildFileBase { } myCachedExternalProperties = result; } - else { - result = myCachedExternalProperties; - } } } return result; @@ -405,7 +405,7 @@ public class AntBuildFileImpl implements AntBuildFileBase { @Nullable private TargetFilter findFilter(final String targetName) { final List filters; - synchronized (this) { + synchronized (myOptionsLock) { filters = TARGET_FILTERS.get(myAllOptions); } for (TargetFilter targetFilter : filters) { From dc5412b98664a785eb5598f04a91bfc975c792b1 Mon Sep 17 00:00:00 2001 From: Yann Cebron Date: Tue, 10 May 2011 19:23:47 +0200 Subject: [PATCH 100/250] javadoc description as first sentence --- .../lang-api/src/com/intellij/psi/SmartPointerManager.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/SmartPointerManager.java b/platform/lang-api/src/com/intellij/psi/SmartPointerManager.java index dde78cba4f08..522403fb27b4 100644 --- a/platform/lang-api/src/com/intellij/psi/SmartPointerManager.java +++ b/platform/lang-api/src/com/intellij/psi/SmartPointerManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -50,10 +50,11 @@ public abstract class SmartPointerManager { @NotNull public abstract SmartPsiElementPointer createLazyPointer(@NotNull E element); /** + * This method is cheaper than dereferencing both pointers and comparing the result. + * * @param pointer1 smart pointer to compare * @param pointer2 smart pointer to compare * @return true if both pointers point to the same PSI element. - * This method is cheaper than dereferencing both pointers and comparing the result. */ public abstract boolean pointToTheSameElement(@NotNull SmartPsiElementPointer pointer1, @NotNull SmartPsiElementPointer pointer2); } From 2cc6007b24d10b7887ad10961a9fc3a91c60e80c Mon Sep 17 00:00:00 2001 From: Gregory Shrago Date: Tue, 10 May 2011 21:31:06 +0400 Subject: [PATCH 101/250] compilation fix --- .../cvsoperations/cvsAnnotate/AnnotateOperation.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAnnotate/AnnotateOperation.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAnnotate/AnnotateOperation.java index 39ad5bfd667c..fd90b4f1f011 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAnnotate/AnnotateOperation.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsAnnotate/AnnotateOperation.java @@ -15,6 +15,8 @@ */ package com.intellij.cvsSupport2.cvsoperations.cvsAnnotate; +import com.intellij.cvsSupport2.CvsUtil; +import com.intellij.cvsSupport2.application.CvsEntriesManager; import com.intellij.cvsSupport2.connections.CvsEnvironment; import com.intellij.cvsSupport2.connections.CvsRootProvider; import com.intellij.cvsSupport2.cvsoperations.common.CvsExecutionEnvironment; @@ -45,6 +47,13 @@ public class AnnotateOperation extends LocalPathIndifferentOperation { private final StringBuffer myBuffer = new StringBuffer(); private final LocalPathIndifferentOperationHelper myHelper; + public static AnnotateOperation createForFile(File file){ + File cvsLightweightFile = CvsUtil.getCvsLightweightFileForFile(file); + String revision = CvsUtil.getRevisionFor(file); + return new AnnotateOperation(cvsLightweightFile, + revision, CvsEntriesManager.getInstance().getCvsConnectionSettingsFor(file.getParentFile())); + } + public AnnotateOperation(File cvsLightweightFile, String revision, CvsEnvironment env) { this(cvsLightweightFile, revision, env, new LocalPathIndifferentOperationHelper(revision)); } From 17435f6731e569903175c06a4477ba1366e282dd Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 10 May 2011 22:15:29 +0400 Subject: [PATCH 102/250] optimize imports on commit: should pass previous executable (cherry picked from commit e70060ce0de860a5bdc70455bb113385f60f0528) --- .../vcs/checkin/OptimizeImportsBeforeCheckinHandler.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/OptimizeImportsBeforeCheckinHandler.java b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/OptimizeImportsBeforeCheckinHandler.java index cb7390cd151d..d509c88c8f01 100644 --- a/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/OptimizeImportsBeforeCheckinHandler.java +++ b/platform/lang-impl/src/com/intellij/openapi/vcs/checkin/OptimizeImportsBeforeCheckinHandler.java @@ -81,6 +81,8 @@ public class OptimizeImportsBeforeCheckinHandler extends CheckinHandler implemen if (configuration.OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT) { new OptimizeImportsProcessor(myProject, BeforeCheckinHandlerUtil.getPsiFiles(myProject, files), performCheckoutAction).run(); + } else { + finishAction.run(); } } From 64a7c47f0da2ab7997958876ff7bd4750451dc4a Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 10 May 2011 22:15:37 +0400 Subject: [PATCH 103/250] optimize imports on commit restored (IDEA-68447) (cherry picked from commit bcbd495b5922060740192f77f08ce6e7d9e29095) --- .../vcs/changes/ui/CommitChangeListDialog.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java index 342a8f23ba10..1e3defb44fff 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -666,13 +666,19 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj }; stopUpdate(); - for(CheckinHandler handler: myHandlers) { + Runnable runnable = proceedRunnable; + for(final CheckinHandler handler: myHandlers) { if (handler instanceof CheckinMetaHandler) { - ((CheckinMetaHandler) handler).runCheckinHandlers(proceedRunnable); - return; + final Runnable previousRunnable = runnable; + runnable = new Runnable() { + @Override + public void run() { + ((CheckinMetaHandler)handler).runCheckinHandlers(previousRunnable); + } + }; } } - proceedRunnable.run(); + runnable.run(); } protected void doOKAction() { From 016eae4ce800a3dc2d749aeb7b4773531fe9e86f Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 10 May 2011 22:15:44 +0400 Subject: [PATCH 104/250] NPE [spleaner] (cherry picked from commit 208497260296552be3c919b495ed17b281b785eb) --- .../introduceField/InplaceIntroduceFieldPopup.java | 2 +- .../InplaceIntroduceParameterPopup.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java index 89c365797d48..e66ccc687e4a 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java @@ -344,7 +344,7 @@ public class InplaceIntroduceFieldPopup { @Override protected void moveOffsetAfter(boolean success) { if (success) { - if (myLocalVariable == null && myInitializerExpression == null) { + if (myLocalVariable == null && myInitializerExpression == null || myFieldName == null) { super.moveOffsetAfter(false); return; } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java index be8916099161..21e183b22ebe 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java @@ -263,12 +263,12 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { protected JComponent getComponent() { if (!myInitialized) { myInitialized = true; - myWholePanel.add(myCanBeFinal, + myWholePanel.add(myCanBeFinalCb, new GridBagConstraints(0, myCbReplaceAllOccurences == null ? 2 : 3, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 2, 5), 0, 0)); if (myHasWriteAccess) { - myCanBeFinal.setSelected(false); - myCanBeFinal.setEnabled(false); + myCanBeFinalCb.setSelected(false); + myCanBeFinalCb.setEnabled(false); } } return myWholePanel; @@ -304,7 +304,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { protected void saveSettings(PsiVariable psiVariable) { final JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance(); InplaceIntroduceParameterPopup.super.saveSettings(settings); - if (myCanBeFinal.isEnabled()) { + if (myCanBeFinalCb.isEnabled()) { settings.INTRODUCE_PARAMETER_CREATE_FINALS = psiVariable.hasModifierProperty(PsiModifier.FINAL); } TypeSelectorManagerImpl.typeSelected(psiVariable.getType(), myDefaultParameterTypePointer.getType()); @@ -323,7 +323,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { isDeleteLocalVariable = isDeleteLocalVariable(); } - if (!myMethod.isValid() || myLocalVar == null && myExpr == null) { + if (!myMethod.isValid() || myParameterName == null || myLocalVar == null && myExpr == null) { super.moveOffsetAfter(false); return; } From 9e06ff1fa28737f1561831cfad09d368a2468517 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 10 May 2011 22:15:50 +0400 Subject: [PATCH 105/250] inplace introduce constant/field: initial visibility fixed (cherry picked from commit 9352e6cf4ea14953e14bae493593fefc670db40a) --- .../InplaceIntroduceConstantPopup.java | 16 +++++++++++----- .../introduceField/IntroduceFieldPopupPanel.java | 7 ++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java index 59574fd4e6f5..cc3350a9f84d 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java @@ -47,6 +47,7 @@ import com.intellij.refactoring.util.occurences.OccurenceManager; import com.intellij.ui.StateRestoringCheckBox; import com.intellij.ui.TitlePanel; import com.intellij.util.ArrayUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -206,8 +207,12 @@ public class InplaceIntroduceConstantPopup { private JPanel createLeftPanel() { final JPanel left = new JPanel(new GridBagLayout()); + String initialVisibility = JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY; + if (initialVisibility == null) { + initialVisibility = PsiModifier.PUBLIC; + } myVisibilityCombo = createVisibilityCombo(left, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0, 0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(6,5,0,0), 0, 0), - myProject); + myProject, initialVisibility); myMoveToAnotherClassCb = new JCheckBox("Move to another class"); myMoveToAnotherClassCb.setMnemonic('m'); myMoveToAnotherClassCb.setFocusable(false); @@ -217,7 +222,8 @@ public class InplaceIntroduceConstantPopup { public static JComboBox createVisibilityCombo(final JPanel left, final GridBagConstraints lgc, - final Project project) { + final Project project, + @NotNull final String initialVisibility) { final JLabel label = new JLabel("Visibility:"); label.setDisplayedMnemonic('V'); @@ -231,12 +237,12 @@ public class InplaceIntroduceConstantPopup { } }); label.setLabelFor(visibilityCombo); - visibilityCombo.setSelectedItem(JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY); + visibilityCombo.setSelectedItem(initialVisibility); appendActions(visibilityCombo, project); lgc.gridx++; lgc.insets.top = 2; - lgc.insets.left = 0; + lgc.insets.left = 2; left.add(visibilityCombo, lgc); return visibilityCombo; } @@ -437,7 +443,7 @@ public class InplaceIntroduceConstantPopup { @Override protected void moveOffsetAfter(boolean success) { if (success) { - if (myLocalVariable == null && myExpr == null) { + if (myLocalVariable == null && myExpr == null || myConstantName == null) { super.moveOffsetAfter(false); return; } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java index cca6275e4239..5ee70e5b413c 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java @@ -179,7 +179,12 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { gridBagConstraints.gridy = 1; gridBagConstraints.insets.top = 8; gridBagConstraints.insets.left = 5; - myVisibilityCombo = InplaceIntroduceConstantPopup.createVisibilityCombo(groupPanel, gridBagConstraints, myParentClass.getProject()); + String visibility = JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY; + if (visibility == null) { + visibility = PsiModifier.PRIVATE; + } + myVisibilityCombo = InplaceIntroduceConstantPopup.createVisibilityCombo(groupPanel, gridBagConstraints, myParentClass.getProject(), + visibility); mainPanel.add(groupPanel, BorderLayout.CENTER); From 4a6fc31399b1baf4e41eebb4c89aefce52488501 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 10 May 2011 22:15:56 +0400 Subject: [PATCH 106/250] final enable/disable state update: popup [spleaner] (cherry picked from commit 72aaa395981cd64aaf0ab33a17100a6ed001cdd8) --- .../refactoring/introduceVariable/IntroduceVariableBase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java index 26e83f1db733..cf94b6c891e0 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -476,7 +476,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme final PsiVariable elementToRename = variable.get().getElement(); if (elementToRename != null) { editor.getCaretModel().moveToOffset(elementToRename.getTextOffset()); - final boolean cantChangeFinalModifier = hasWriteAccess || (inFinalContext && choice == OccurrencesChooser.ReplaceChoice.ALL); + final boolean cantChangeFinalModifier = (hasWriteAccess || inFinalContext) && choice == OccurrencesChooser.ReplaceChoice.ALL; final VariableInplaceRenamer renamer = new VariableInplaceIntroducer(project, expression, editor, elementToRename, cantChangeFinalModifier, typeSelectorManager.getTypesForAll().length > 1, exprMarker, occurrenceMarkers, IntroduceVariableBase.REFACTORING_NAME); From 7b6b84249dc15dc9c41f6220672e7b7f48176ef2 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 10 May 2011 22:16:03 +0400 Subject: [PATCH 107/250] final enable/disable state update [spleaner] (cherry picked from commit b039157523eaa5ab7e0074f3120902358bf35788) --- .../introduceVariable/IntroduceVariableDialog.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java index 9ce3d058fb46..52e3d71b2661 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -207,6 +207,7 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable gbConstraints.insets = new Insets(0, 8, 0, 0); gbConstraints.gridy++; panel.add(myCbReplaceWrite, gbConstraints); + myCbReplaceWrite.addItemListener(myReplaceAllListener); } } @@ -252,7 +253,11 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable if (myDeclareFinalIfAll && myCbReplaceAll != null && myCbReplaceAll.isSelected()) { myCbFinal.setEnabled(false); myCbFinal.setSelected(true); - } else { + } else if (myCbReplaceWrite != null && myCbReplaceWrite.isEnabled() && myCbReplaceWrite.isSelected()) { + myCbFinal.setEnabled(false); + myCbFinal.setSelected(false); + } + else { myCbFinal.setEnabled(true); myCbFinal.setSelected(myCbFinalState); } From cf50ce1c7a055b63dbca9cc39c4d4e560a3df165 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 10 May 2011 22:16:11 +0400 Subject: [PATCH 108/250] do not show popup when nothing can be changed [spleaner] (cherry picked from commit 88c50620bc5057b779fdb6bb1d1f619606a59d17) --- .../VariableInplaceIntroducer.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java index 28ddcfc17f07..25400e971588 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java @@ -74,7 +74,7 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { private final List myOccurrenceMarkers; private final SmartTypePointer myDefaultType; - protected JCheckBox myCanBeFinal; + protected JCheckBox myCanBeFinalCb; private Balloon myBalloon; public VariableInplaceIntroducer(final Project project, @@ -105,10 +105,10 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { occurrenceMarkers.toArray(new RangeMarker[occurrenceMarkers.size()])); setAdvertisementText(getAdvertisementText(declarationStatement, defaultType, hasTypeSuggestion)); if (!cantChangeFinalModifier) { - myCanBeFinal = new NonFocusableCheckBox("Declare final"); - myCanBeFinal.setSelected(createFinals()); - myCanBeFinal.setMnemonic('f'); - myCanBeFinal.addActionListener(new FinalListener(project, commandName)); + myCanBeFinalCb = new NonFocusableCheckBox("Declare final"); + myCanBeFinalCb.setSelected(createFinals()); + myCanBeFinalCb.setMnemonic('f'); + myCanBeFinalCb.addActionListener(new FinalListener(project, commandName)); } } @@ -236,6 +236,7 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { @Nullable protected JComponent getComponent() { + if (myCanBeFinalCb == null) return null; final JPanel panel = new JPanel(new GridBagLayout()); panel.setBorder(null); @@ -244,8 +245,8 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { titlePanel.setText(IntroduceVariableBase.REFACTORING_NAME); panel.add(titlePanel, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); - if (myCanBeFinal != null) { - panel.add(myCanBeFinal, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); + if (myCanBeFinalCb != null) { + panel.add(myCanBeFinalCb, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); } panel.add(Box.createVerticalBox(), new GridBagConstraints(0, 2, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0,0)); @@ -393,7 +394,7 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { @Override public void actionPerformed(ActionEvent e) { - perform(myCanBeFinal.isSelected()); + perform(myCanBeFinalCb.isSelected()); } public void perform(final boolean generateFinal) { From 8dd3c824b2a143c4efb48341b9664834ab29b77e Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 10 May 2011 22:16:18 +0400 Subject: [PATCH 109/250] do not invoke progress under write action (IDEA-69387) [romka] (cherry picked from commit 5a2ecb506789cae2f863340b8dcc160eafacd37c) --- .../usageInfo/MergeMethodArguments.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/usageInfo/MergeMethodArguments.java b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/usageInfo/MergeMethodArguments.java index 236823f971b4..87fcf8bb7207 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/usageInfo/MergeMethodArguments.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/usageInfo/MergeMethodArguments.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -15,6 +15,7 @@ */ package com.intellij.refactoring.introduceparameterobject.usageInfo; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; @@ -103,9 +104,26 @@ public class MergeMethodArguments extends FixableUsageInfo { parametersInfo.add(new ParameterInfoImpl(i, parameters[i].getName(), parameters[i].getType())); } } + final SmartPsiElementPointer meth = SmartPointerManager.getInstance(getProject()).createSmartPsiElementPointer(method); - new ChangeSignatureProcessor(method.getProject(), method, myKeepMethodAsDelegate, null, method.getName(), method.getReturnType(), - parametersInfo.toArray(new ParameterInfoImpl[parametersInfo.size()])).run(); + Runnable performChangeSignatureRunnable = new Runnable() { + @Override + public void run() { + final PsiMethod psiMethod = meth.getElement(); + if (psiMethod == null) return; + final ChangeSignatureProcessor changeSignatureProcessor = + new ChangeSignatureProcessor(psiMethod.getProject(), psiMethod, + myKeepMethodAsDelegate, null, psiMethod.getName(), + psiMethod.getReturnType(), + parametersInfo.toArray(new ParameterInfoImpl[parametersInfo.size()])); + changeSignatureProcessor.run(); + } + }; + if (ApplicationManager.getApplication().isUnitTestMode()) { + performChangeSignatureRunnable.run(); + } else { + ApplicationManager.getApplication().invokeLater(performChangeSignatureRunnable); + } } private boolean isParameterToMerge(int index) { From 2360c15811f651fc13ce4a0d5a96f2141b62c9af Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Tue, 10 May 2011 22:17:17 +0400 Subject: [PATCH 110/250] Reference wrapper for parameters --- .../DefaultGroovyVariableNameValidator.java | 28 ++++++++-- .../convertToJava/CodeBlockGenerator.java | 15 +++++ .../convertToJava/ExpressionContext.java | 2 +- .../convertToJava/ExpressionGenerator.java | 15 +++-- .../convertToJava/GenerationUtil.java | 5 +- .../convertToJava/LocalVarAnalyzer.java | 56 ++++++++++++------- .../convertToJava/FileGenerationTest.groovy | 2 + .../file/closureParamInInnerClosure.groovy | 10 ++++ .../file/closureParamInInnerClosure.java | 25 +++++++++ .../file/methodParamsInClosures.groovy | 10 ++++ .../file/methodParamsInClosures.java | 17 ++++++ 11 files changed, 151 insertions(+), 34 deletions(-) create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/closureParamInInnerClosure.groovy create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/closureParamInInnerClosure.java create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamsInClosures.groovy create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamsInClosures.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/DefaultGroovyVariableNameValidator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/DefaultGroovyVariableNameValidator.java index 85660f26881b..be8007c4dbc6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/DefaultGroovyVariableNameValidator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/DefaultGroovyVariableNameValidator.java @@ -18,6 +18,7 @@ package org.jetbrains.plugins.groovy.refactoring; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiField; +import com.intellij.psi.PsiModifier; import com.intellij.psi.PsiNamedElement; import com.intellij.util.containers.hash.HashSet; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; @@ -41,14 +42,23 @@ public class DefaultGroovyVariableNameValidator implements NameValidator { private final Set mySet = new HashSet(); public DefaultGroovyVariableNameValidator(GroovyPsiElement context) { - this(context, Collections.emptyList()); + this(context, Collections.emptyList(), true, false); } public DefaultGroovyVariableNameValidator(GroovyPsiElement context, Collection restrictedNames) { - this(context, restrictedNames, true); + this(context, restrictedNames, true, false); } - public DefaultGroovyVariableNameValidator(GroovyPsiElement context, Collection restrictedNames, boolean includeFields) { + public DefaultGroovyVariableNameValidator(GroovyPsiElement context, + Collection restrictedNames, + boolean includeFields) { + this(context, restrictedNames, includeFields, false); + } + + public DefaultGroovyVariableNameValidator(GroovyPsiElement context, + Collection restrictedNames, + boolean includeFields, + final boolean checkIntoInner) { myContext = context; mySet.addAll(restrictedNames); PropertyResolverProcessor processor = new PropertyResolverProcessor(null, myContext); @@ -68,10 +78,18 @@ public class DefaultGroovyVariableNameValidator implements NameValidator { } @Override - public void visitClosure(GrClosableBlock closure) {} + public void visitClosure(GrClosableBlock closure) { + if (checkIntoInner) { + super.visitClosure(closure); + } + } @Override - public void visitTypeDefinition(GrTypeDefinition typeDefinition) {} + public void visitTypeDefinition(GrTypeDefinition typeDefinition) { + if (checkIntoInner && !typeDefinition.hasModifierProperty(PsiModifier.STATIC) ) { + super.visitTypeDefinition(typeDefinition); + } + } }); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java index a468483a2cc0..ec00a8787943 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/CodeBlockGenerator.java @@ -18,6 +18,7 @@ package org.jetbrains.plugins.groovy.refactoring.convertToJava; import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; import com.intellij.util.containers.hash.HashSet; +import org.codehaus.groovy.util.ManagedConcurrentMap; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.codeInspection.noReturnMethod.MissingReturnInspection; import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils; @@ -45,6 +46,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMe import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; import org.jetbrains.plugins.groovy.lang.psi.impl.types.GrClosureSignatureUtil; +import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames; import java.util.Collection; import java.util.Set; @@ -113,6 +115,19 @@ public class CodeBlockGenerator extends Generator { public void generateCodeBlock(GrCodeBlock block, boolean shouldInsertReturnNull) { builder.append("{\n"); + if (block.getParent() instanceof GrMethod) { + GrMethod method = (GrMethod)block.getParent(); + GrParameter[] parameters = method.getParameters(); + for (GrParameter parameter : parameters) { + if (context.analyzedVars.toWrap(parameter)) { + StringBuilder typeText = new StringBuilder(GroovyCommonClassNames.GROOVY_LANG_REFERENCE); + GenerationUtil.writeTypeParameters(typeText, new PsiType[]{TypeProvider.getParameterType(parameter)}, method, + new GeneratorClassNameProvider()); + builder.append("final ").append(typeText).append(' ').append(context.analyzedVars.toVarName(parameter)) + .append(" = new ").append(typeText).append('(').append(parameter.getName()).append(");\n"); + } + } + } visitStatementOwner(block, shouldInsertReturnNull); builder.append("}\n"); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionContext.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionContext.java index 01f1795a474e..0a6c86c9e329 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionContext.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionContext.java @@ -88,6 +88,6 @@ class ExpressionContext implements Cloneable { } public void searchForLocalVarsToWrap(GroovyPsiElement root) { - analyzedVars = LocalVarAnalyzer.searchForVarsToWrap(root, analyzedVars); + analyzedVars = LocalVarAnalyzer.searchForVarsToWrap(root, analyzedVars, this); } } \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java index ba06cf873ab7..d6717773bdd4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java @@ -683,12 +683,15 @@ public class ExpressionGenerator extends Generator { } if (resolved instanceof PsiNamedElement) { final String refName = ((PsiNamedElement)resolved).getName(); - builder.append(refName); - if (context.analyzedVars != null && - resolved instanceof GrVariable && - context.analyzedVars.toWrap((GrVariable)resolved) && - !PsiUtil.isAccessedForWriting(referenceExpression)) { - builder.append(".get()"); + + if (resolved instanceof GrVariable && context.analyzedVars.toWrap((GrVariable)resolved)) { + builder.append(context.analyzedVars.toVarName((GrVariable)resolved)); + if (!PsiUtil.isAccessedForWriting(referenceExpression)) { + builder.append(".get()"); + } + } + else { + builder.append(refName); } } else { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java index ad9391d015f4..bdc17ed436cc 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java @@ -114,7 +114,8 @@ public class GenerationUtil { static String suggestVarName(PsiType type, GroovyPsiElement context, ExpressionContext expressionContext) { final DefaultGroovyVariableNameValidator nameValidator = - new DefaultGroovyVariableNameValidator(context, expressionContext.myUsedVarNames, true); + new DefaultGroovyVariableNameValidator(context, expressionContext.myUsedVarNames, true, true); + if (type instanceof PsiPrimitiveType) type = TypesUtil.boxPrimitiveType(type, context.getManager(), context.getResolveScope()); final String[] varNames = GroovyNameSuggestionUtil.suggestVariableNameByType(type, nameValidator); LOG.assertTrue(varNames.length > 0); @@ -428,7 +429,7 @@ public class GenerationUtil { else if (analyzedVars.toWrap(variable)) { builder.append(PsiModifier.FINAL).append(' '); type = JavaPsiFacade.getElementFactory(expressionContext.project).createTypeFromText( - GroovyCommonClassNames.GROOVY_LANG_REFERENCE + "<" + getTypeText(type, variable) + ">", variable); + GroovyCommonClassNames.GROOVY_LANG_REFERENCE + "<" + getTypeText(originalType, variable) + ">", variable); wrapped = true; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/LocalVarAnalyzer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/LocalVarAnalyzer.java index f88f66d525c2..ebf5aa95759c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/LocalVarAnalyzer.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/LocalVarAnalyzer.java @@ -15,19 +15,22 @@ */ package org.jetbrains.plugins.groovy.refactoring.convertToJava; -import com.intellij.psi.PsiAnonymousClass; -import com.intellij.psi.PsiElement; +import com.intellij.psi.*; +import com.intellij.util.containers.HashMap; import com.intellij.util.containers.HashSet; import gnu.trove.TObjectIntHashMap; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringUtil; +import java.util.Map; import java.util.Set; /** @@ -35,47 +38,62 @@ import java.util.Set; */ class LocalVarAnalyzer extends GroovyRecursiveElementVisitor { static class Result { - private final Set toMakeFinal; - private final Set toWrap; + private final Set toMakeFinal; + private final Set toWrap; + private final Map varToName; - private Result(Set toMakeFinal, Set toWrap) { + private Result(Set toMakeFinal, Set toWrap, Map varToName) { this.toMakeFinal = toMakeFinal; this.toWrap = toWrap; + this.varToName = varToName; } - boolean toWrap(GrVariable variable) { + boolean toWrap(PsiVariable variable) { return toWrap.contains(variable); } - boolean toMakeFinal(GrVariable variable) { + + boolean toMakeFinal(PsiVariable variable) { return toMakeFinal.contains(variable); } + + String toVarName(PsiVariable variable) { + return varToName.get(variable); + } } - public static Result searchForVarsToWrap(GroovyPsiElement root, Result analyzedVars) { + public static Result searchForVarsToWrap(GroovyPsiElement root, Result analyzedVars, ExpressionContext context) { LocalVarAnalyzer visitor = new LocalVarAnalyzer(); root.accept(visitor); - Set toWrap = analyzedVars == null ? new HashSet() : analyzedVars.toWrap; - Set toMakeFinal = analyzedVars == null ? new HashSet() : analyzedVars.toMakeFinal; - for (GrVariable v : visitor.touched) { + Map varToName = analyzedVars == null ? new HashMap() : analyzedVars.varToName; + Set toWrap = analyzedVars == null ? new HashSet() : analyzedVars.toWrap; + Set toMakeFinal = analyzedVars == null ? new HashSet() : analyzedVars.toMakeFinal; + for (PsiVariable v : visitor.touched) { if (visitor.rewritten.contains(v)) { toWrap.add(v); + if (v instanceof PsiParameter) { + varToName.put(v, GenerationUtil.suggestVarName(v.getType(), root, context)); + } + else { + varToName.put(v, v.getName()); + } } else { toMakeFinal.add(v); + varToName.put(v, v.getName()); } } - return analyzedVars == null ? new Result(toMakeFinal, toWrap) : analyzedVars; + return analyzedVars == null ? new Result(toMakeFinal, toWrap, varToName) : analyzedVars; } public static Result initialResult() { - return new Result(new HashSet(), new HashSet()); + return new Result(new HashSet(), new HashSet(), new HashMap()); } - private final Set touched = new HashSet(); - private final Set rewritten = new HashSet(); - private final TObjectIntHashMap allVars = new TObjectIntHashMap(); + private final Set touched = new HashSet(); + private final Set rewritten = new HashSet(); + private final TObjectIntHashMap allVars = new TObjectIntHashMap(); private int grade = 0; @@ -101,7 +119,7 @@ class LocalVarAnalyzer extends GroovyRecursiveElementVisitor { @Override public void visitVariable(GrVariable variable) { super.visitVariable(variable); - if (!GroovyRefactoringUtil.isLocalVariable(variable)) return; + if (variable instanceof GrField) return; allVars.put(variable, grade); } @@ -117,9 +135,7 @@ class LocalVarAnalyzer extends GroovyRecursiveElementVisitor { } if (allVars.get(var) < grade) { - touched.add((GrVariable)resolved); + touched.add((PsiVariable)resolved); } } - - } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy index 03a5b1e7be76..2ad7afc17ac7 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy @@ -63,4 +63,6 @@ class FileGenerationTest extends LightGroovyTestCase { void testRefInAnonymous() {doTest()} void testRefInClosureInMethod() {doTest()} void testRefInClosureInScript() {doTest()} + void testMethodParamsInClosures() {doTest()} + void testClosureParamInInnerClosure() {doTest()} } diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/closureParamInInnerClosure.groovy b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/closureParamInInnerClosure.groovy new file mode 100644 index 000000000000..a467f69a998d --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/closureParamInInnerClosure.groovy @@ -0,0 +1,10 @@ +class X { + def foo = {int x-> + + 1.each { + x = 2 + int i = 3 + + } + } +} \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/closureParamInInnerClosure.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/closureParamInInnerClosure.java new file mode 100644 index 000000000000..c260ec820ea7 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/closureParamInInnerClosure.java @@ -0,0 +1,25 @@ +public class X extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { +public groovy.lang.Closure getFoo() { + return foo; +} +public void setFoo(java.lang.Object foo) { +this.foo = foo; +} +private groovy.lang.Closure foo = new groovy.lang.Closure(this, this) { +public java.lang.Integer doCall(int x) { +final groovy.lang.Reference i1 = new groovy.lang.Reference(x); +return org.codehaus.groovy.runtime.DefaultGroovyMethods.each(1, new groovy.lang.Closure(this, this) { +public void doCall(java.lang.Object it) { +i1.set(2); +int i = 3; +} + +public void doCall() { +doCall(null); +} + +}); +} + +}; +} diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamsInClosures.groovy b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamsInClosures.groovy new file mode 100644 index 000000000000..1c70e39e93f9 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamsInClosures.groovy @@ -0,0 +1,10 @@ +class X { + def foo(int x) { + + 1.each { + x = 2 + int i = 3 + + } + } +} \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamsInClosures.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamsInClosures.java new file mode 100644 index 000000000000..b59ebd253c90 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamsInClosures.java @@ -0,0 +1,17 @@ +public class X extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { +public java.lang.Integer foo(int x) { +final groovy.lang.Reference i1 = new groovy.lang.Reference(x); +return org.codehaus.groovy.runtime.DefaultGroovyMethods.each(1, new groovy.lang.Closure(this, this) { +public void doCall(java.lang.Object it) { +i1.set(2); +int i = 3; +} + +public void doCall() { +doCall(null); +} + +}); +} + +} From dd7766b497a352211f642d6c5a75719ba2ff2ed8 Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Tue, 10 May 2011 21:32:02 +0400 Subject: [PATCH 111/250] Support for paths with whitespaces --- bin/nix/inspect.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/nix/inspect.sh b/bin/nix/inspect.sh index 8f639b16d5a5..5fdfa97c1bee 100644 --- a/bin/nix/inspect.sh +++ b/bin/nix/inspect.sh @@ -3,5 +3,5 @@ export DEFAULT_PROJECT_PATH=`pwd` # Launch inspection tool -IDEA_BIN_HOME=$(cd `dirname $0` && pwd) +IDEA_BIN_HOME="$( cd "$( dirname "$0" )" && pwd )" $IDEA_BIN_HOME/idea.sh inspect $* \ No newline at end of file From c24ef1bbeca5eab4a73c44e1dcfae23b91eb3993 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 09:05:01 +0200 Subject: [PATCH 112/250] a failing SOE test to deal with later --- .../plugins/groovy/lang/resolve/ResolveMethodTest.groovy | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy index 31ceb89f9326..98487bb45375 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy @@ -696,6 +696,15 @@ class Zoo { assertEquals("plus", assertInstanceOf(resolved, GrMethod).name) } + public void _testWrongGdkCallGenerics() { + myFixture.configureByText("a.groovy", + "Map map = [:]\n" + + "println map.get('', '')" + ); + def ref = myFixture.file.findReferenceAt(myFixture.editor.caretModel.offset) + assertInstanceOf ref.resolve(), GrGdkMethod + } + public void testStaticImportInSamePackage() { myFixture.addFileToProject "pack/Foo.groovy", """package pack class Foo { From 6c77a567e09ee55abba303fc2376d0a36433fdf6 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Wed, 11 May 2011 10:42:15 +0400 Subject: [PATCH 113/250] per-language PsiReferenceContributor --- .../completion/WordCompletionTest.java | 12 +- .../reference/PsiReferenceContributorEP.java | 57 +++++ .../reference/PsiReferenceRegistrarImpl.java | 184 +++++++++++++++++ .../reference/ReferenceProvidersRegistry.java | 195 +++--------------- .../src/META-INF/LangExtensionPoints.xml | 2 +- .../java/LanguageReferenceProvider.java | 7 +- plugins/testng/src/META-INF/plugin.xml | 2 +- plugins/ui-designer/src/META-INF/plugin.xml | 2 +- .../xpath/xpath-view/src/META-INF/plugin.xml | 2 +- xml/dom-impl/src/META-INF/DomPlugin.xml | 2 +- 10 files changed, 287 insertions(+), 178 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceContributorEP.java create mode 100644 platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceRegistrarImpl.java diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/WordCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/WordCompletionTest.java index b3470a01e3e3..87bbd9b94ad6 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/WordCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/WordCompletionTest.java @@ -1,7 +1,9 @@ package com.intellij.codeInsight.completion; import com.intellij.JavaTestUtil; +import com.intellij.lang.StdLanguages; import com.intellij.psi.*; +import com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl; import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry; import com.intellij.util.ProcessingContext; import org.jetbrains.annotations.NotNull; @@ -68,16 +70,18 @@ public class WordCompletionTest extends CompletionTestCase { }}; } }; + PsiReferenceRegistrarImpl registrar = + (PsiReferenceRegistrarImpl)ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA); try { - ReferenceProvidersRegistry.getInstance().registerReferenceProvider(PsiLiteralExpression.class, softProvider); - ReferenceProvidersRegistry.getInstance().registerReferenceProvider(PsiLiteralExpression.class, hardProvider); + registrar.registerReferenceProvider(PsiLiteralExpression.class, softProvider); + registrar.registerReferenceProvider(PsiLiteralExpression.class, hardProvider); configureByFile(BASE_PATH + "3.java"); checkResultByFile(BASE_PATH + "3_after.java"); } finally { - ReferenceProvidersRegistry.getInstance().unregisterReferenceProvider(PsiLiteralExpression.class, softProvider); - ReferenceProvidersRegistry.getInstance().unregisterReferenceProvider(PsiLiteralExpression.class, hardProvider); + registrar.unregisterReferenceProvider(PsiLiteralExpression.class, softProvider); + registrar.unregisterReferenceProvider(PsiLiteralExpression.class, hardProvider); } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceContributorEP.java b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceContributorEP.java new file mode 100644 index 000000000000..94f91b6f73d6 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceContributorEP.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2011 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.impl.source.resolve.reference; + +import com.intellij.lang.Language; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.extensions.CustomLoadingExtensionPointBean; +import com.intellij.openapi.util.NotNullLazyValue; +import com.intellij.psi.PsiReferenceContributor; +import com.intellij.util.KeyedLazyInstance; +import com.intellij.util.xmlb.annotations.Attribute; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dmitry Avdeev + */ +public class PsiReferenceContributorEP extends CustomLoadingExtensionPointBean implements KeyedLazyInstance { + + @Attribute("language") + public String language = Language.ANY.getID(); + + @Attribute("implementation") + public String implementationClass; + + private final NotNullLazyValue myHandler = new NotNullLazyValue() { + @NotNull + protected PsiReferenceContributor compute() { + try { + return (PsiReferenceContributor)instantiateExtension(implementationClass, ApplicationManager.getApplication().getPicoContainer()); + } + catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + }; + + public PsiReferenceContributor getInstance() { + return myHandler.getValue(); + } + + public String getKey() { + return language; + } +} diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceRegistrarImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceRegistrarImpl.java new file mode 100644 index 000000000000..f6781d69cb84 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceRegistrarImpl.java @@ -0,0 +1,184 @@ +/* + * Copyright 2000-2011 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.impl.source.resolve.reference; + +import com.intellij.openapi.util.Trinity; +import com.intellij.patterns.*; +import com.intellij.pom.references.PomReferenceProvider; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiReferenceProvider; +import com.intellij.psi.PsiReferenceRegistrar; +import com.intellij.psi.PsiReferenceService; +import com.intellij.psi.filters.ElementFilter; +import com.intellij.psi.filters.position.FilterPattern; +import com.intellij.util.ArrayUtil; +import com.intellij.util.ConcurrencyUtil; +import com.intellij.util.ProcessingContext; +import com.intellij.util.SmartList; +import com.intellij.util.containers.ConcurrentFactoryMap; +import com.intellij.util.containers.ConcurrentHashMap; +import com.intellij.util.containers.FactoryMap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.*; +import java.util.concurrent.ConcurrentMap; + +/** + * @author Dmitry Avdeev + */ +public class PsiReferenceRegistrarImpl extends PsiReferenceRegistrar { + + private final ConcurrentMap myBindingsMap = new ConcurrentHashMap(); + private final ConcurrentMap myNamedBindingsMap = new ConcurrentHashMap(); + private final FactoryMap> myKnownSupers = new ConcurrentFactoryMap>() { + @Override + protected List create(Class key) { + final Set result = new LinkedHashSet(); + for (Class candidate : myBindingsMap.keySet()) { + if (candidate.isAssignableFrom(key)) { + result.add(candidate); + } + } + for (Class candidate : myNamedBindingsMap.keySet()) { + if (candidate.isAssignableFrom(key)) { + result.add(candidate); + } + } + if (result.isEmpty()) { + return Collections.emptyList(); + } + return new ArrayList(result); + } + }; + + /** + * @deprecated {@see com.intellij.psi.PsiReferenceContributor + */ + public void registerReferenceProvider(@Nullable ElementFilter elementFilter, + @NotNull Class scope, + @NotNull PsiReferenceProvider provider, + double priority) { + registerReferenceProvider(PlatformPatterns.psiElement(scope).and(new FilterPattern(elementFilter)), provider, priority); + } + + public void registerReferenceProvider(@NotNull ElementPattern pattern, + @NotNull PomReferenceProvider provider, + double priority) { + } + + public void registerReferenceProvider(@NotNull ElementPattern pattern, + @NotNull PsiReferenceProvider provider, + double priority) { + myKnownSupers.clear(); // we should clear the cache + final Class scope = pattern.getCondition().getInitialCondition().getAcceptedClass(); + final List> conditions = pattern.getCondition().getConditions(); + for (int i = 0, conditionsSize = conditions.size(); i < conditionsSize; i++) { + PatternCondition _condition = conditions.get(i); + if (_condition instanceof PsiNamePatternCondition) { + final PsiNamePatternCondition nameCondition = (PsiNamePatternCondition)_condition; + List> conditions1 = nameCondition.getNamePattern().getCondition().getConditions(); + for (int i1 = 0, conditions1Size = conditions1.size(); i1 < conditions1Size; i1++) { + PatternCondition condition = conditions1.get(i1); + if (condition instanceof ValuePatternCondition) { + final Collection strings = ((ValuePatternCondition)condition).getValues(); + registerNamedReferenceProvider(ArrayUtil.toStringArray(strings), nameCondition, scope, true, provider, priority, pattern); + return; + } + if (condition instanceof CaseInsensitiveValuePatternCondition) { + final String[] strings = ((CaseInsensitiveValuePatternCondition)condition).getValues(); + registerNamedReferenceProvider(strings, nameCondition, scope, false, provider, priority, pattern); + return; + } + } + break; + } + } + + while (true) { + final SimpleProviderBinding providerBinding = myBindingsMap.get(scope); + if (providerBinding != null) { + providerBinding.registerProvider(provider, pattern, priority); + return; + } + + final SimpleProviderBinding binding = new SimpleProviderBinding(); + binding.registerProvider(provider, pattern, priority); + if (myBindingsMap.putIfAbsent(scope, binding) == null) break; + } + } + + /** + * @deprecated {@link com.intellij.psi.PsiReferenceContributor} + */ + public void registerReferenceProvider(@Nullable ElementFilter elementFilter, + @NotNull Class scope, + @NotNull PsiReferenceProvider provider) { + registerReferenceProvider(elementFilter, scope, provider, DEFAULT_PRIORITY); + } + + public void unregisterReferenceProvider(@NotNull Class scope, @NotNull PsiReferenceProvider provider) { + final ProviderBinding providerBinding = myBindingsMap.get(scope); + providerBinding.unregisterProvider(provider); + } + + + private void registerNamedReferenceProvider(final String[] names, final PsiNamePatternCondition nameCondition, + final Class scopeClass, + final boolean caseSensitive, + final PsiReferenceProvider provider, final double priority, final ElementPattern pattern) { + NamedObjectProviderBinding providerBinding = myNamedBindingsMap.get(scopeClass); + + if (providerBinding == null) { + providerBinding = ConcurrencyUtil.cacheOrGet(myNamedBindingsMap, scopeClass, new NamedObjectProviderBinding() { + protected String getName(final PsiElement position) { + return nameCondition.getPropertyValue(position); + } + }); + } + + providerBinding.registerProvider(names, pattern, caseSensitive, provider, priority); + } + + /** + * @see com.intellij.psi.PsiReferenceContributor + * @deprecated + */ + public void registerReferenceProvider(@NotNull Class scope, @NotNull PsiReferenceProvider provider) { + registerReferenceProvider(null, scope, provider); + } + + @NotNull + List> getPairsByElement(@NotNull PsiElement element, + @NotNull PsiReferenceService.Hints hints) { + final Class clazz = element.getClass(); + List> ret = null; + for (final Class aClass : myKnownSupers.get(clazz)) { + final SimpleProviderBinding simpleBinding = myBindingsMap.get(aClass); + final NamedObjectProviderBinding namedBinding = myNamedBindingsMap.get(aClass); + if (simpleBinding == null && namedBinding == null) continue; + + if (ret == null) ret = new SmartList>(); + if (simpleBinding != null) { + simpleBinding.addAcceptableReferenceProviders(element, ret, hints); + } + if (namedBinding != null) { + namedBinding.addAcceptableReferenceProviders(element, ret, hints); + } + } + return ret == null ? Collections.>emptyList() : ret; + } +} diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java index 5892762cba8d..868ab97bc056 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java @@ -16,30 +16,23 @@ package com.intellij.psi.impl.source.resolve.reference; -import com.intellij.codeInsight.completion.LegacyCompletionContributor; +import com.intellij.lang.Language; +import com.intellij.lang.LanguageExtension; import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.util.Trinity; -import com.intellij.patterns.*; -import com.intellij.pom.references.PomReferenceProvider; import com.intellij.psi.*; -import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.filters.position.FilterPattern; -import com.intellij.util.ArrayUtil; -import com.intellij.util.ConcurrencyUtil; import com.intellij.util.ProcessingContext; import com.intellij.util.SmartList; -import com.intellij.util.containers.ConcurrentFactoryMap; -import com.intellij.util.containers.ConcurrentHashMap; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.FactoryMap; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.*; -import java.util.concurrent.ConcurrentMap; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Map; /** * Created by IntelliJ IDEA. @@ -48,30 +41,9 @@ import java.util.concurrent.ConcurrentMap; * Time: 17:13:45 * To change this template use Options | File Templates. */ -public class ReferenceProvidersRegistry extends PsiReferenceRegistrar { - private static final PsiReferenceContributor[] ourExtensions = Extensions.getExtensions(PsiReferenceContributor.EP_NAME); - private final ConcurrentMap myBindingsMap = new ConcurrentHashMap(); - private final ConcurrentMap myNamedBindingsMap = new ConcurrentHashMap(); - private final FactoryMap> myKnownSupers = new ConcurrentFactoryMap>() { - @Override - protected List create(Class key) { - final Set result = new LinkedHashSet(); - for (Class candidate : myBindingsMap.keySet()) { - if (candidate.isAssignableFrom(key)) { - result.add(candidate); - } - } - for (Class candidate : myNamedBindingsMap.keySet()) { - if (candidate.isAssignableFrom(key)) { - result.add(candidate); - } - } - if (result.isEmpty()) { - return Collections.emptyList(); - } - return new ArrayList(result); - } - }; +public class ReferenceProvidersRegistry { + + private static final LanguageExtension EXTENSION = new LanguageExtension(PsiReferenceContributor.EP_NAME.getName()); private static final Comparator> PRIORITY_COMPARATOR = new Comparator>() { @@ -81,131 +53,25 @@ public class ReferenceProvidersRegistry extends PsiReferenceRegistrar { } }; + @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"}) + private final static Map ourRegistrars = new FactoryMap() { + @Override + protected PsiReferenceRegistrarImpl create(Language language) { + PsiReferenceRegistrarImpl registrar = new PsiReferenceRegistrarImpl(); + List contributors = EXTENSION.allForLanguage(language); + for (PsiReferenceContributor contributor : contributors) { + contributor.registerReferenceProviders(registrar); + } + return registrar; + } + }; + public static ReferenceProvidersRegistry getInstance() { return ServiceManager.getService(ReferenceProvidersRegistry.class); } - public ReferenceProvidersRegistry() { - for (final PsiReferenceContributor contributor : ourExtensions) { - contributor.registerReferenceProviders(this); - } - } - - /** - * @deprecated {@see com.intellij.psi.PsiReferenceContributor - */ - public void registerReferenceProvider(@Nullable ElementFilter elementFilter, - @NotNull Class scope, - @NotNull PsiReferenceProvider provider, - double priority) { - registerReferenceProvider(PlatformPatterns.psiElement(scope).and(new FilterPattern(elementFilter)), provider, priority); - } - - public void registerReferenceProvider(@NotNull ElementPattern pattern, - @NotNull PomReferenceProvider provider, - double priority) { - } - - public void registerReferenceProvider(@NotNull ElementPattern pattern, - @NotNull PsiReferenceProvider provider, - double priority) { - myKnownSupers.clear(); - final Class scope = pattern.getCondition().getInitialCondition().getAcceptedClass(); - final List> conditions = pattern.getCondition().getConditions(); - for (int i = 0, conditionsSize = conditions.size(); i < conditionsSize; i++) { - PatternCondition _condition = conditions.get(i); - if (_condition instanceof PsiNamePatternCondition) { - final PsiNamePatternCondition nameCondition = (PsiNamePatternCondition)_condition; - List> conditions1 = nameCondition.getNamePattern().getCondition().getConditions(); - for (int i1 = 0, conditions1Size = conditions1.size(); i1 < conditions1Size; i1++) { - PatternCondition condition = conditions1.get(i1); - if (condition instanceof ValuePatternCondition) { - final Collection strings = ((ValuePatternCondition)condition).getValues(); - registerNamedReferenceProvider(ArrayUtil.toStringArray(strings), nameCondition, scope, true, provider, priority, pattern); - return; - } - if (condition instanceof CaseInsensitiveValuePatternCondition) { - final String[] strings = ((CaseInsensitiveValuePatternCondition)condition).getValues(); - registerNamedReferenceProvider(strings, nameCondition, scope, false, provider, priority, pattern); - return; - } - } - break; - } - } - - while (true) { - final SimpleProviderBinding providerBinding = myBindingsMap.get(scope); - if (providerBinding != null) { - providerBinding.registerProvider(provider, pattern, priority); - return; - } - - final SimpleProviderBinding binding = new SimpleProviderBinding(); - binding.registerProvider(provider, pattern, priority); - if (myBindingsMap.putIfAbsent(scope, binding) == null) break; - } - } - - /** - * @deprecated {@link com.intellij.psi.PsiReferenceContributor} - */ - public void registerReferenceProvider(@Nullable ElementFilter elementFilter, - @NotNull Class scope, - @NotNull PsiReferenceProvider provider) { - registerReferenceProvider(elementFilter, scope, provider, DEFAULT_PRIORITY); - } - - public void unregisterReferenceProvider(@NotNull Class scope, @NotNull PsiReferenceProvider provider) { - final ProviderBinding providerBinding = myBindingsMap.get(scope); - providerBinding.unregisterProvider(provider); - } - - - private void registerNamedReferenceProvider(final String[] names, final PsiNamePatternCondition nameCondition, - final Class scopeClass, - final boolean caseSensitive, - final PsiReferenceProvider provider, final double priority, final ElementPattern pattern) { - NamedObjectProviderBinding providerBinding = myNamedBindingsMap.get(scopeClass); - - if (providerBinding == null) { - providerBinding = ConcurrencyUtil.cacheOrGet(myNamedBindingsMap, scopeClass, new NamedObjectProviderBinding() { - protected String getName(final PsiElement position) { - return nameCondition.getPropertyValue(position); - } - }); - } - - providerBinding.registerProvider(names, pattern, caseSensitive, provider, priority); - } - - /** - * @see com.intellij.psi.PsiReferenceContributor - * @deprecated - */ - public void registerReferenceProvider(@NotNull Class scope, @NotNull PsiReferenceProvider provider) { - registerReferenceProvider(null, scope, provider); - } - - @NotNull - private List> getPairsByElement(@NotNull PsiElement element, - @NotNull PsiReferenceService.Hints hints) { - final Class clazz = element.getClass(); - List> ret = null; - for (final Class aClass : myKnownSupers.get(clazz)) { - final SimpleProviderBinding simpleBinding = myBindingsMap.get(aClass); - final NamedObjectProviderBinding namedBinding = myNamedBindingsMap.get(aClass); - if (simpleBinding == null && namedBinding == null) continue; - - if (ret == null) ret = new SmartList>(); - if (simpleBinding != null) { - simpleBinding.addAcceptableReferenceProviders(element, ret, hints); - } - if (namedBinding != null) { - namedBinding.addAcceptableReferenceProviders(element, ret, hints); - } - } - return ret == null ? Collections.>emptyList() : ret; + public PsiReferenceRegistrar getRegistrar(Language language) { + return ourRegistrars.get(language); } @Deprecated @@ -217,8 +83,10 @@ public class ReferenceProvidersRegistry extends PsiReferenceRegistrar { ProgressManager.checkCanceled(); assert context.isValid() : "Invalid context: " + context; - final List> providers = - getInstance().getPairsByElement(context, hints); + PsiReferenceRegistrarImpl registrar = ourRegistrars.get(context.getLanguage()); + SmartList> providers = new SmartList>(); + providers.addAll(registrar.getPairsByElement(context, hints)); + providers.addAll(ourRegistrars.get(Language.ANY).getPairsByElement(context, hints)); if (providers.isEmpty()) { return PsiReference.EMPTY_ARRAY; } @@ -228,12 +96,7 @@ public class ReferenceProvidersRegistry extends PsiReferenceRegistrar { return firstProvider.getFirst().getReferencesByElement(context, firstProvider.getSecond()); } - ((SmartList>)providers).sort(PRIORITY_COMPARATOR); - - if (LegacyCompletionContributor.DEBUG) { - System.out.println("ReferenceProvidersRegistry.getReferencesFromProviders"); - System.out.println("providers = " + providers); - } + providers.sort(PRIORITY_COMPARATOR); List result = new ArrayList(); final double maxPriority = providers.get(0).getThird(); diff --git a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml index 43d74cb2eed8..990b69e8b29a 100644 --- a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml @@ -266,7 +266,7 @@ - + diff --git a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/LanguageReferenceProvider.java b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/LanguageReferenceProvider.java index 444f0934fe95..e8f36cab82d6 100644 --- a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/LanguageReferenceProvider.java +++ b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/LanguageReferenceProvider.java @@ -18,19 +18,20 @@ package org.intellij.plugins.intelliLang.inject.java; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Computable; import com.intellij.patterns.PatternCondition; -import static com.intellij.patterns.PsiJavaPatterns.literalExpression; import com.intellij.patterns.StandardPatterns; import com.intellij.psi.*; import com.intellij.util.ProcessingContext; import org.intellij.plugins.intelliLang.Configuration; -import org.intellij.plugins.intelliLang.util.PsiUtilEx; import org.intellij.plugins.intelliLang.util.AnnotationUtilEx; +import org.intellij.plugins.intelliLang.util.PsiUtilEx; import org.jetbrains.annotations.NotNull; +import static com.intellij.patterns.PsiJavaPatterns.literalExpression; + /** * Provides references to Language-IDs and RegExp enums for completion. */ -final class LanguageReferenceProvider extends PsiReferenceContributor { +public final class LanguageReferenceProvider extends PsiReferenceContributor { private final Configuration myConfig = Configuration.getInstance(); private final Computable ANNOTATION_NAME = new Computable() { diff --git a/plugins/testng/src/META-INF/plugin.xml b/plugins/testng/src/META-INF/plugin.xml index fc2c23df4fd4..37bd6dc007fe 100644 --- a/plugins/testng/src/META-INF/plugin.xml +++ b/plugins/testng/src/META-INF/plugin.xml @@ -13,7 +13,7 @@ - + com.theoryinpractice.testng.intention.TestNGOrderEntryFix diff --git a/plugins/ui-designer/src/META-INF/plugin.xml b/plugins/ui-designer/src/META-INF/plugin.xml index c14277c05805..e77dfbd6437c 100644 --- a/plugins/ui-designer/src/META-INF/plugin.xml +++ b/plugins/ui-designer/src/META-INF/plugin.xml @@ -104,7 +104,7 @@ - + diff --git a/plugins/xpath/xpath-view/src/META-INF/plugin.xml b/plugins/xpath/xpath-view/src/META-INF/plugin.xml index dd6cdb0ab447..5e3d671cf0e3 100644 --- a/plugins/xpath/xpath-view/src/META-INF/plugin.xml +++ b/plugins/xpath/xpath-view/src/META-INF/plugin.xml @@ -133,7 +133,7 @@ - + diff --git a/xml/dom-impl/src/META-INF/DomPlugin.xml b/xml/dom-impl/src/META-INF/DomPlugin.xml index 30f0fa8a873a..561d5a1a10bd 100644 --- a/xml/dom-impl/src/META-INF/DomPlugin.xml +++ b/xml/dom-impl/src/META-INF/DomPlugin.xml @@ -58,7 +58,7 @@ - + From 6b49b6c08e611d52e2ea6a43626e976ddb7064e5 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Wed, 11 May 2011 10:29:25 +0200 Subject: [PATCH 114/250] IDEA: local history fix --- .../revertion/ChangeRevertingVisitor.java | 6 ++++-- .../openapi/command/impl/ChangeRange.java | 16 +++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/revertion/ChangeRevertingVisitor.java b/platform/lvcs-impl/src/com/intellij/history/integration/revertion/ChangeRevertingVisitor.java index 5a6d57b1ea9a..6bc633ae63c7 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/revertion/ChangeRevertingVisitor.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/revertion/ChangeRevertingVisitor.java @@ -26,6 +26,8 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.HashSet; import com.intellij.util.io.ReadOnlyAttributeUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.ArrayList; @@ -41,10 +43,10 @@ public class ChangeRevertingVisitor extends ChangeVisitor { private boolean isReverting; - public ChangeRevertingVisitor(IdeaGateway gw, long fromChangeId, long toChangeId) { + public ChangeRevertingVisitor(IdeaGateway gw, @NotNull Long fromChangeId, @Nullable Long toChangeId) { myGateway = gw; myFromChangeId = fromChangeId; - myToChangeId = toChangeId; + myToChangeId = toChangeId == null ? -1 : toChangeId; } protected boolean shouldRevert(Change c) { diff --git a/platform/lvcs-impl/src/com/intellij/openapi/command/impl/ChangeRange.java b/platform/lvcs-impl/src/com/intellij/openapi/command/impl/ChangeRange.java index 33a07a2389fd..ebfd8dc94cbb 100644 --- a/platform/lvcs-impl/src/com/intellij/openapi/command/impl/ChangeRange.java +++ b/platform/lvcs-impl/src/com/intellij/openapi/command/impl/ChangeRange.java @@ -21,20 +21,22 @@ import com.intellij.history.core.changes.Change; import com.intellij.history.integration.IdeaGateway; import com.intellij.history.integration.revertion.ChangeRevertingVisitor; import com.intellij.openapi.util.Ref; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.IOException; public class ChangeRange { private final IdeaGateway myGateway; private final LocalHistoryFacade myVcs; - private final long myFromChangeId; - private final long myToChangeId; + private final Long myFromChangeId; + @Nullable private final Long myToChangeId; - public ChangeRange(IdeaGateway gw, LocalHistoryFacade vcs, long change) { - this(gw, vcs, change, change); + public ChangeRange(IdeaGateway gw, LocalHistoryFacade vcs, @NotNull Long changeId) { + this(gw, vcs, changeId, changeId); } - public ChangeRange(IdeaGateway gw, LocalHistoryFacade vcs, long fromChangeId, long toChangeId) { + private ChangeRange(IdeaGateway gw, LocalHistoryFacade vcs, @Nullable Long fromChangeId, @Nullable Long toChangeId) { myGateway = gw; myVcs = vcs; myFromChangeId = fromChangeId; @@ -54,13 +56,13 @@ public class ChangeRange { try { myVcs.accept(new ChangeRevertingVisitor(myGateway, myToChangeId, myFromChangeId)); } - catch(ChangeRevertingVisitor.RuntimeIOException e) { + catch (ChangeRevertingVisitor.RuntimeIOException e) { throw (IOException)e.getCause(); } finally { myVcs.removeListener(l); } - + if (reverse != null) { if (first.isNull()) first.set(reverse.myFromChangeId); if (last.isNull()) last.set(reverse.myToChangeId); From bb590d0b738dbf8b3f408e14cfa33fd750cf6cb5 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Wed, 11 May 2011 10:44:51 +0200 Subject: [PATCH 115/250] IDEA:Generate Test: committing docs before generation --- .../testIntegration/BaseGenerateTestSupportMethodAction.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/java-impl/src/com/intellij/testIntegration/BaseGenerateTestSupportMethodAction.java b/java/java-impl/src/com/intellij/testIntegration/BaseGenerateTestSupportMethodAction.java index 1d31bb4acc33..48061b33f045 100644 --- a/java/java-impl/src/com/intellij/testIntegration/BaseGenerateTestSupportMethodAction.java +++ b/java/java-impl/src/com/intellij/testIntegration/BaseGenerateTestSupportMethodAction.java @@ -156,6 +156,7 @@ public class BaseGenerateTestSupportMethodAction extends BaseGenerateAction { @Override public void run() { try { + PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments(); PsiMethod method = generateDummyMethod(editor, file); if (method == null) return; From a09c00c9f748457942bb3401a7f28702118a4458 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 10 May 2011 15:09:49 +0400 Subject: [PATCH 116/250] cleanup --- .../psi/impl/source/PsiJavaCodeReferenceElementImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java index d9f9633b048e..aec992479b97 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java @@ -559,9 +559,8 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme } final boolean preserveQualification = CodeStyleSettingsManager.getSettings(getProject()).USE_FQ_CLASS_NAMES && isFullyQualified(); - final PsiManager manager = aClass.getManager(); final PsiReferenceParameterList parameterList = getParameterList(); - String text = (parameterList != null ? qName + parameterList.getText() : qName); + String text = parameterList == null ? qName : qName + parameterList.getText(); PsiJavaCodeReferenceElement ref = facade.getParserFacade().createReferenceFromText(text, getParent()); getTreeParent().replaceChildInternal(this, (TreeElement)ref.getNode()); if (!preserveQualification /*&& (TreeUtil.findParent(ref, ElementType.DOC_COMMENT) == null)*/) { From 724d6172aedcff6fb1f59e70380736da89c11480 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 10 May 2011 15:13:27 +0400 Subject: [PATCH 117/250] bug: when run "replace all", document size can increase dramatically --- .../src/com/intellij/usageView/UsageInfo.java | 8 ++++++++ .../lang-impl/src/com/intellij/find/FindUtil.java | 13 ++++++++++--- .../find/editorHeaderActions/FindAllAction.java | 2 +- .../replaceInProject/ReplaceInProjectManager.java | 14 +++++++------- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/platform/lang-api/src/com/intellij/usageView/UsageInfo.java b/platform/lang-api/src/com/intellij/usageView/UsageInfo.java index a8dc9239a830..37d0a8506f12 100644 --- a/platform/lang-api/src/com/intellij/usageView/UsageInfo.java +++ b/platform/lang-api/src/com/intellij/usageView/UsageInfo.java @@ -16,6 +16,7 @@ package com.intellij.usageView; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.project.Project; @@ -164,6 +165,13 @@ public class UsageInfo { if (element == null) return null; TextRange range = element.getTextRange(); ProperTextRange.assertProperRange(range, element); + if (element instanceof PsiFile) { + // hack: it's actually a range inside file, use document for range checking since during the "find|replace all" operation, file range might have been changed + Document document = PsiDocumentManager.getInstance(getProject()).getDocument((PsiFile)element); + if (document != null) { + range = new ProperTextRange(0, document.getTextLength()); + } + } ProperTextRange rangeInElement = getRangeInElement(); if (rangeInElement == null) return null; return new ProperTextRange(Math.min(range.getEndOffset(), range.getStartOffset() + rangeInElement.getStartOffset()), diff --git a/platform/lang-impl/src/com/intellij/find/FindUtil.java b/platform/lang-impl/src/com/intellij/find/FindUtil.java index d2e3787f893a..8f962fdde31b 100644 --- a/platform/lang-impl/src/com/intellij/find/FindUtil.java +++ b/platform/lang-impl/src/com/intellij/find/FindUtil.java @@ -197,7 +197,7 @@ public class FindUtil { public void run() { if (model.isFindAll()) { findManager.setFindNextModel(model); - findAll(project, editor, model); + findAllAndShow(project, editor, model); return; } @@ -237,10 +237,11 @@ public class FindUtil { }); } - public static void findAll(final Project project, final Editor editor, final FindModel findModel) { + @Nullable + public static List findAll(final Project project, final Editor editor, final FindModel findModel) { final Document document = editor.getDocument(); final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document); - if (psiFile == null) return; + if (psiFile == null) return null; CharSequence text = document.getCharsSequence(); int textLength = document.getTextLength(); @@ -265,6 +266,12 @@ public class FindUtil { ++offset; } } + return usages; + } + + public static void findAllAndShow(final Project project, final Editor editor, final FindModel findModel) { + List usages = findAll(project, editor, findModel); + if (usages == null) return; final UsageTarget[] usageTargets = { new FindInProjectUtil.StringUsageTarget(findModel.getStringToFind()) }; final UsageViewPresentation usageViewPresentation = FindInProjectUtil.setupViewPresentation(false, findModel); UsageViewManager.getInstance(project).showUsages(usageTargets, usages.toArray(new Usage[usages.size()]), usageViewPresentation); diff --git a/platform/lang-impl/src/com/intellij/find/editorHeaderActions/FindAllAction.java b/platform/lang-impl/src/com/intellij/find/editorHeaderActions/FindAllAction.java index 86aa864a2ce5..e017c0165ca6 100644 --- a/platform/lang-impl/src/com/intellij/find/editorHeaderActions/FindAllAction.java +++ b/platform/lang-impl/src/com/intellij/find/editorHeaderActions/FindAllAction.java @@ -51,7 +51,7 @@ public class FindAllAction extends EditorHeaderAction implements DumbAware { String text = getEditorSearchComponent().getTextInField(); if (StringUtil.isEmpty(text)) return; realModel.setStringToFind(text); - FindUtil.findAll(project, editor, realModel); + FindUtil.findAllAndShow(project, editor, realModel); } } } diff --git a/platform/lang-impl/src/com/intellij/find/replaceInProject/ReplaceInProjectManager.java b/platform/lang-impl/src/com/intellij/find/replaceInProject/ReplaceInProjectManager.java index 99583b9aad71..5d7121fe3392 100644 --- a/platform/lang-impl/src/com/intellij/find/replaceInProject/ReplaceInProjectManager.java +++ b/platform/lang-impl/src/com/intellij/find/replaceInProject/ReplaceInProjectManager.java @@ -220,7 +220,7 @@ public class ReplaceInProjectManager { if (result == FindManager.PromptResult.OK) { Runnable runnable = new Runnable() { public void run() { - doReplace(replaceContext, usage); + doReplace(usage, replaceContext.getFindModel(), replaceContext.getExcludedSet()); replaceContext.getUsageView().removeUsage(usage); } }; @@ -248,7 +248,7 @@ public class ReplaceInProjectManager { if (!otherPsiFile.equals(psiFile)) { break; } - doReplace(replaceContext, usage); + doReplace(usage, replaceContext.getFindModel(), replaceContext.getExcludedSet()); replaceContext.getUsageView().removeUsage(usage); } if (j == usages.length) { @@ -296,7 +296,7 @@ public class ReplaceInProjectManager { private void doReplace(final ReplaceContext replaceContext, Collection usages) { for (final Usage usage : usages) { - doReplace(replaceContext, usage); + doReplace(usage, replaceContext.getFindModel(), replaceContext.getExcludedSet()); } reportNumberReplacedOccurences(myProject, usages.size()); } @@ -307,10 +307,10 @@ public class ReplaceInProjectManager { } } - private void doReplace(final ReplaceContext replaceContext, final Usage usage) { + public void doReplace(@NotNull final Usage usage, @NotNull final FindModel findModel, @NotNull final Set excludedSet) { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { - if (replaceContext.getExcludedSet().contains(usage)) { + if (excludedSet.contains(usage)) { return; } @@ -330,14 +330,14 @@ public class ReplaceInProjectManager { } FindManager findManager = FindManager.getInstance(myProject); final CharSequence foundString = document.getCharsSequence().subSequence(textOffset, textEndOffset); - FindResult findResult = findManager.findString(document.getCharsSequence(), textOffset, replaceContext.getFindModel()); + FindResult findResult = findManager.findString(document.getCharsSequence(), textOffset, findModel); if (!findResult.isStringFound()) { return true; } String stringToReplace = null; try { stringToReplace = - findManager.getStringToReplace(foundString.toString(), replaceContext.getFindModel(), textOffset, document.getText()); + findManager.getStringToReplace(foundString.toString(), findModel, textOffset, document.getText()); } catch (FindManager.MalformedReplacementStringException e) { Messages.showErrorDialog(myProject, e.getMessage(), FindBundle.message("find.replace.invalid.replacement.string.title")); From b0fbab04f28fc772862c6b08a76487df609a70ab Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 11 May 2011 12:36:52 +0400 Subject: [PATCH 118/250] do not autoimport inner classes --- .../impl/quickfix/ImportClassFixBase.java | 10 +++++++- .../codeInsight/daemon/ImportHelperTest.java | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java index 815ee1d4f9da..6dc4d1e971ab 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java @@ -145,7 +145,9 @@ public abstract class ImportClassFixBase im && (JspPsiUtil.isInJspFile(psiFile) ? CodeInsightSettings.getInstance().JSP_ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY : CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY) - && codeAnalyzer.canChangeFileSilently(psiFile)) { + && codeAnalyzer.canChangeFileSilently(psiFile) + && !autoImportWillInsertUnexpectedCharacters(classes[0]) + ) { CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() { public void run() { action.execute(); @@ -165,6 +167,12 @@ public abstract class ImportClassFixBase im return Result.POPUP_NOT_SHOWN; } + private static boolean autoImportWillInsertUnexpectedCharacters(PsiClass aClass) { + PsiClass containingClass = aClass.getContainingClass(); + // when importing inner class, the reference might be qualified with outer class name and it can be confusing + return containingClass != null; + } + private boolean canImportHere(boolean allowCaretNearRef, Editor editor, PsiFile psiFile, String exampleClassName) { return (allowCaretNearRef || !isCaretNearRef(editor, myRef)) && !hasUnresolvedImportWhichCanImport(psiFile, exampleClassName); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java index d2b42b7aff43..bf9c717b2426 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java @@ -368,4 +368,27 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase { } } + public void testAutoInsertImportForInnerClass() throws Throwable { + @NonNls String text = "package x; class S { void f(ReadLock r){} } "; + configureByText(StdFileTypes.JAVA, text); + + boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY; + CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true; + DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true); + + try { + List errs = filter(doHighlighting(), HighlightSeverity.ERROR); + assertEquals(1, errs.size()); + + assertEmpty(((PsiJavaFile)getFile()).getImportList().getAllImportStatements()); + type("/* */"); + doHighlighting(); + UIUtil.dispatchAllInvocationEvents(); + assertEmpty(((PsiJavaFile)getFile()).getImportList().getAllImportStatements()); + } + finally { + CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old; + } + } + } From f42d40d3f28d85d15eb6ee6df71f1a9bfbbf3c1d Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 11 May 2011 12:37:43 +0400 Subject: [PATCH 119/250] stop highlighting on Ctrl-N --- .../ide/util/gotoByName/ChooseByNameBase.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index bcb3f0247992..1164381cdcc6 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -17,11 +17,14 @@ package com.intellij.ide.util.gotoByName; import com.intellij.Patches; +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; +import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl; import com.intellij.ide.IdeBundle; import com.intellij.ide.actions.CopyReferenceAction; import com.intellij.ide.ui.UISettings; import com.intellij.ide.util.NavigationItemListCellRenderer; import com.intellij.ide.util.PsiElementListCellRenderer; +import com.intellij.openapi.Disposable; import com.intellij.openapi.MnemonicHelper; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; @@ -34,10 +37,7 @@ import com.intellij.openapi.keymap.KeymapManager; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.*; -import com.intellij.openapi.util.ActionCallback; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Computable; -import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.*; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.IdeFocusManager; @@ -686,6 +686,24 @@ public abstract class ChooseByNameBase { myTextPopup.setLocation(bounds.getLocation()); new MnemonicHelper().register(myTextFieldPanel); + final boolean previousUpdate; + final DaemonCodeAnalyzer daemonCodeAnalyzer = DaemonCodeAnalyzer.getInstance(myProject); + if (daemonCodeAnalyzer != null) { + previousUpdate = ((DaemonCodeAnalyzerImpl)daemonCodeAnalyzer).isUpdateByTimerEnabled(); + daemonCodeAnalyzer.setUpdateByTimerEnabled(false); + } + else { + previousUpdate = false; + } + + Disposer.register(myTextPopup, new Disposable() { + @Override + public void dispose() { + if (daemonCodeAnalyzer != null) { + daemonCodeAnalyzer.setUpdateByTimerEnabled(previousUpdate); + } + } + }); myTextPopup.show(layeredPane); } From 8ab51cc78feab3963b5565e7310da222855a6c7b Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Wed, 11 May 2011 13:22:02 +0400 Subject: [PATCH 120/250] [review: max] IDEA-69153 Editor: Improve performance of caret movement via arrow keys Disabling direct drawing/direct 3d for community version as well --- bin/idea.properties | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/idea.properties b/bin/idea.properties index d5ad5467471a..e91715890671 100644 --- a/bin/idea.properties +++ b/bin/idea.properties @@ -39,4 +39,10 @@ idea.xdebug.key=-Xdebug #----------------------------------------------------------------------- # This option controls console cyclic buffer: keeps the console output size not higher than the specified buffer size (Kb). Older lines are deleted. # In order to disable cycle buffer use idea.cycle.buffer.size=disabled -idea.cycle.buffer.size=1024 \ No newline at end of file +idea.cycle.buffer.size=1024 + +#---------------------------------------------------------------------- +# Disabling this property may lead to visual glitches like blinking and fail to repaint +# on certain display adapter cards. +#---------------------------------------------------------------------- +sun.java2d.noddraw=true \ No newline at end of file From 92708add5fa1843cace86b773d95d10b4ccc33a3 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 10 May 2011 18:57:52 +0200 Subject: [PATCH 121/250] test expanded --- .../org/jetbrains/plugins/groovy/lang/GroovyStressTest.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyStressTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyStressTest.groovy index 35e53ac7d9bb..4b434d5dc8a6 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyStressTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyStressTest.groovy @@ -95,10 +95,12 @@ class GroovyStressTest extends LightCodeInsightFixtureTestCase { public void testDeeplyNestedClosures() { String text = "println 'hi'" + String defs = "" for (i in 1..10) { text = "foo$i { $text }" + defs += "def foo$i(Closure cl) {}\n" } - myFixture.configureByText("a.groovy", text) + myFixture.configureByText("a.groovy", defs + text) IdeaTestUtil.assertTiming "slow", 10000, { myFixture.doHighlighting() } } From d48e9bd5cf67186894b9606ea00730e38e97de2e Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 12:11:11 +0200 Subject: [PATCH 122/250] fix SOE in shape-based resolve --- .../GroovyStaticImportMethodFix.java | 2 +- .../GroovyAssignabilityCheckInspection.java | 2 +- .../GrConstructorInvocationImpl.java | 2 +- .../GrReferenceExpressionImpl.java | 10 ++-------- .../enumConstant/GrEnumConstantImpl.java | 2 +- .../plugins/groovy/lang/psi/util/PsiUtil.java | 5 +++-- .../processors/MethodResolverProcessor.java | 20 +++++++++++++++---- .../lang/resolve/ResolveMethodTest.groovy | 2 +- 8 files changed, 26 insertions(+), 19 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GroovyStaticImportMethodFix.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GroovyStaticImportMethodFix.java index 7b02f701b3fb..b7051754d9c6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GroovyStaticImportMethodFix.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GroovyStaticImportMethodFix.java @@ -121,7 +121,7 @@ public class GroovyStaticImportMethodFix implements IntentionAction { //do not show methods from default package && ((PsiClassOwner)file).getPackageName().length() != 0 && PsiUtil.isAccessible(element, method)) { list.add(method); - if (PsiUtil.isApplicable(PsiUtil.getArgumentTypes(element, true), method, PsiSubstitutor.EMPTY, false, element)) { + if (PsiUtil.isApplicable(PsiUtil.getArgumentTypes(element, true), method, PsiSubstitutor.EMPTY, false, element, false)) { applicableList.add(method); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyAssignabilityCheckInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyAssignabilityCheckInspection.java index abede067a4ad..8ad87171f6cd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyAssignabilityCheckInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyAssignabilityCheckInspection.java @@ -419,7 +419,7 @@ public class GroovyAssignabilityCheckInspection extends BaseInspection { } if (argumentTypes != null && !PsiUtil.isApplicable(argumentTypes, method, methodResolveResult.getSubstitutor(), - ResolveUtil.isInUseScope(methodResolveResult), place)) { + ResolveUtil.isInUseScope(methodResolveResult), place, false)) { //check for implicit use of property getter which returns closure if (GroovyPropertyUtils.isSimplePropertyGetter(method)) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java index 5485e4e2ccb9..116aed63a3b8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java @@ -88,7 +88,7 @@ public class GrConstructorInvocationImpl extends GrCallImpl implements GrConstru } PsiType thisType = factory.createType(clazz, substitutor); MethodResolverProcessor processor = new MethodResolverProcessor(clazz.getName(), this, true, thisType, argTypes, PsiType.EMPTY_ARRAY, - allVariants); + allVariants, false); final ResolveState state = ResolveState.initial().put(PsiSubstitutor.KEY, substitutor); clazz.processDeclarations(processor, state, null, this); ResolveUtil.processNonCodeMethods(thisType, processor, this, state); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java index 66100d5e8c6a..c3d2e0ce44cd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java @@ -215,7 +215,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl 0) { signature = GrClosureSignatureUtil.removeParam(signature, 0); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java index 5f6d11dc954c..d98074d05895 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java @@ -68,11 +68,18 @@ public class MethodResolverProcessor extends ResolverProcessor { private boolean myStopExecuting = false; private Set myExitPoints; private final boolean canNotBeExitPoint; + private final boolean myByShape; public MethodResolverProcessor(String name, GroovyPsiElement place, boolean isConstructor, PsiType thisType, @Nullable PsiType[] argumentTypes, PsiType[] typeArguments) { - this(name, place, isConstructor, thisType, argumentTypes, typeArguments, false); + this(name, place, isConstructor, thisType, argumentTypes, typeArguments, false, false); } - public MethodResolverProcessor(String name, GroovyPsiElement place, boolean isConstructor, PsiType thisType, @Nullable PsiType[] argumentTypes, PsiType[] typeArguments, boolean allVariants) { + public MethodResolverProcessor(String name, + GroovyPsiElement place, + boolean isConstructor, + PsiType thisType, + @Nullable PsiType[] argumentTypes, + PsiType[] typeArguments, + boolean allVariants, final boolean byShape) { super(name, RESOLVE_KINDS_METHOD_PROPERTY, place, PsiType.EMPTY_ARRAY); myIsConstructor = isConstructor; myThisType = thisType; @@ -80,6 +87,7 @@ public class MethodResolverProcessor extends ResolverProcessor { myTypeArguments = typeArguments; myAllVariants = allVariants; canNotBeExitPoint = !canBexExitPoint(place); + myByShape = byShape; } private static boolean canBexExitPoint(PsiElement place) { @@ -106,7 +114,7 @@ public class MethodResolverProcessor extends ResolverProcessor { GroovyPsiElement resolveContext = state.get(RESOLVE_CONTEXT); boolean isStaticsOK = isStaticsOK(method, resolveContext); if (!myAllVariants && - PsiUtil.isApplicable(myArgumentTypes, method, substitutor, ResolveUtil.isInUseScope(resolveContext), (GroovyPsiElement)myPlace) && + PsiUtil.isApplicable(myArgumentTypes, method, substitutor, ResolveUtil.isInUseScope(resolveContext), (GroovyPsiElement)myPlace, myByShape) && isStaticsOK) { addCandidate(new GroovyResolveResultImpl(method, resolveContext, substitutor, isAccessible, isStaticsOK)); } else { @@ -120,6 +128,10 @@ public class MethodResolverProcessor extends ResolverProcessor { } protected PsiSubstitutor obtainSubstitutor(PsiSubstitutor substitutor, PsiMethod method, ResolveState state) { + if (myByShape) { + return substitutor; + } + final PsiTypeParameter[] typeParameters = method.getTypeParameters(); if (myTypeArguments.length == typeParameters.length) { for (int i = 0; i < typeParameters.length; i++) { @@ -146,7 +158,7 @@ public class MethodResolverProcessor extends ResolverProcessor { System.arraycopy(argTypes, 0, newArgTypes, 1, argTypes.length); argTypes = newArgTypes; - method = ((GrGdkMethod) method).getStaticMethod(); + method = ((GrGdkMethod)method).getStaticMethod(); LOG.assertTrue(method.isValid()); } else if (ResolveUtil.isInUseScope(resolveContext)) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy index 98487bb45375..97f99e630e2b 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy @@ -696,7 +696,7 @@ class Zoo { assertEquals("plus", assertInstanceOf(resolved, GrMethod).name) } - public void _testWrongGdkCallGenerics() { + public void testWrongGdkCallGenerics() { myFixture.configureByText("a.groovy", "Map map = [:]\n" + "println map.get('', '')" From 0a8f79083478f97f04755780ab21617c9629d8e3 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 12:21:53 +0200 Subject: [PATCH 123/250] don't double-check method candidate applicability in by-shape resolve --- .../GrReferenceExpressionImpl.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java index c3d2e0ce44cd..3dda83d1a10b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java @@ -215,17 +215,20 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl allCandidates = new ArrayList(); ContainerUtil.addAll(allCandidates, propertyCandidates); - ContainerUtil.addAll(allCandidates, methodResolver.getCandidates()); + ContainerUtil.addAll(allCandidates, genericsMatter ? methodResolver.getCandidates() : shapeResults.second); //search for getters for (String getterName : GroovyPropertyUtils.suggestGettersName(name)) { From fb0495bde5352211d7bf2cfdd778b8c977ac65e7 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 12:23:58 +0200 Subject: [PATCH 124/250] test expanded --- .../org/jetbrains/plugins/groovy/lang/GroovyStressTest.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyStressTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyStressTest.groovy index 4b434d5dc8a6..f196b1fadd62 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyStressTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyStressTest.groovy @@ -10,8 +10,9 @@ import org.jetbrains.plugins.groovy.LightGroovyTestCase import org.jetbrains.plugins.groovy.lang.psi.GroovyFile import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager +import org.jetbrains.plugins.groovy.codeInspection.noReturnMethod.MissingReturnInspection - /** +/** * @author peter */ class GroovyStressTest extends LightCodeInsightFixtureTestCase { @@ -101,6 +102,7 @@ class GroovyStressTest extends LightCodeInsightFixtureTestCase { defs += "def foo$i(Closure cl) {}\n" } myFixture.configureByText("a.groovy", defs + text) + myFixture.enableInspections(new MissingReturnInspection()) IdeaTestUtil.assertTiming "slow", 10000, { myFixture.doHighlighting() } } From ff9f3e7ba57439998a21b09d88be533829e1ed93 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Wed, 11 May 2011 14:08:09 +0400 Subject: [PATCH 125/250] Balloon UI: title support --- .../openapi/ui/popup/BalloonBuilder.java | 4 + .../src/com/intellij/ui/BalloonImpl.java | 107 +++++++++++++++--- .../ui/popup/BalloonPopupBuilderImpl.java | 11 +- 3 files changed, 103 insertions(+), 19 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/BalloonBuilder.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/BalloonBuilder.java index 125f1377b32f..06cef34d2c57 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/BalloonBuilder.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/BalloonBuilder.java @@ -16,6 +16,7 @@ package com.intellij.openapi.ui.popup; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.awt.*; import java.awt.event.ActionListener; @@ -77,4 +78,7 @@ public interface BalloonBuilder { @NotNull BalloonBuilder setDialogMode(boolean dialogMode); + + @NotNull + BalloonBuilder setTitle(@Nullable String title); } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java index e5dd37475b91..9ed3dfa8fa03 100644 --- a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java @@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.ex.AnActionListener; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.ui.popup.JBPopupListener; @@ -32,10 +33,8 @@ import com.intellij.openapi.util.*; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.FocusRequestor; import com.intellij.openapi.wm.IdeFocusManager; -import com.intellij.openapi.wm.IdeGlassPane; import com.intellij.openapi.wm.IdeGlassPaneUtil; import com.intellij.openapi.wm.impl.IdeGlassPaneEx; -import com.intellij.openapi.wm.impl.IdeGlassPaneImpl; import com.intellij.openapi.wm.impl.content.GraphicsConfig; import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.components.panels.NonOpaquePanel; @@ -49,6 +48,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.border.EmptyBorder; +import javax.swing.border.LineBorder; import java.awt.*; import java.awt.event.AWTEventListener; import java.awt.event.ActionEvent; @@ -59,6 +59,7 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; +import java.awt.geom.Area; import java.awt.geom.GeneralPath; import java.awt.geom.Rectangle2D; import java.awt.geom.RoundRectangle2D; @@ -149,6 +150,8 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi private int myPositionChangeYShift; private boolean myDialogMode; private IdeFocusManager myFocusManager; + private String myTitle; + private JLabel myTitleLabel; public boolean isInsideBalloon(MouseEvent me) { return isInside(new RelativePoint(me)); @@ -201,7 +204,8 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi int calloutShift, int positioChangeXShfit, int positionChangeYShift, - boolean dialogMode) { + boolean dialogMode, + String title) { myBorderColor = borderColor; myFillColor = fillColor; myContent = content; @@ -217,7 +221,7 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi myPositionChangeXShift = positioChangeXShfit; myPositionChangeYShift = positionChangeYShift; myDialogMode = dialogMode; - + myTitle = title; if (!myDialogMode) { new AwtVisitor(content) { @@ -436,14 +440,18 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi Toolkit.getDefaultToolkit().addAWTEventListener(myAwtActivityListener, MouseEvent.MOUSE_EVENT_MASK | MouseEvent.MOUSE_MOTION_EVENT_MASK | KeyEvent.KEY_EVENT_MASK); - ActionManager.getInstance().addAnActionListener(new AnActionListener.Adapter() { - @Override - public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) { - if (myHideOnAction) { - hide(); - } - } - }, this); + if (ApplicationManager.getApplication() != null) { + ActionManager.getInstance().addAnActionListener(new AnActionListener.Adapter() { + @Override + public void beforeActionPerformed(AnAction action, + DataContext dataContext, + AnActionEvent event) { + if (myHideOnAction) { + hide(); + } + } + }, this); + } } private Rectangle getRecForPosition(AbstractPosition position, boolean adjust) { @@ -705,7 +713,7 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi abstract Point getLocation(final Dimension containerSize, final Point targetPoint, final Dimension balloonSize); - void paintComponent(BalloonImpl balloon, final Rectangle bounds, final Graphics2D g, Point pointTarget) { + void paintComponent(BalloonImpl balloon, final Rectangle bounds, final Graphics2D g, Point pointTarget, JComponent component) { final GraphicsConfig cfg = new GraphicsConfig(g); cfg.setAntialiasing(true); @@ -720,10 +728,43 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi g.setColor(balloon.myFillColor); g.fill(shape); g.setColor(balloon.myBorderColor); + + if (balloon.myTitleLabel != null) { + Rectangle titleBounds = balloon.myTitleLabel.getBounds(); + + Insets inset = getTitleInsets(balloon.getNormalInset() - 1, getPointerLength(this) + 50); + + titleBounds.x -= inset.left + 1; + titleBounds.width += (inset.left + inset.right + 50); + titleBounds.y -= inset.top + 1; + titleBounds.height += (inset.top + inset.bottom + 1); + + Area area = new Area(shape); + area.intersect(new Area(titleBounds)); + + + Color fgColor = UIManager.getColor("Label.foreground"); + fgColor = new Color(fgColor.getRed(), fgColor.getGreen(), fgColor.getBlue(), 140); + g.setColor(fgColor); + g.fill(area); + + g.setColor(balloon.myBorderColor); + g.draw(area); + + //Rectangle titleBounds = balloon.myTitleLabel.getBounds(); + //titleBounds = SwingUtilities.convertRectangle(balloon.myTitleLabel.getParent(), titleBounds, component); + // + //g.setColor(balloon.myBorderColor); + //int inset = balloon.getNormalInset(); + //g.drawLine(titleBounds.x - inset, (int)titleBounds.getMaxY(), (int)titleBounds.getMaxX() + inset, (int)titleBounds.getMaxY()); + } + g.draw(shape); cfg.restore(); } + protected abstract Insets getTitleInsets(int normalInset, int pointerLength); + protected abstract Shape getPointingShape(final Rectangle bounds, final Graphics2D g, final Point pointTarget, @@ -817,6 +858,11 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi return new Point(center.x, targetPoint.y); } + @Override + protected Insets getTitleInsets(int normalInset, int pointerLength) { + return new Insets(pointerLength, normalInset, normalInset, normalInset); + } + protected void convertBoundsToContent(final Rectangle bounds, final BalloonImpl balloon) { bounds.y += balloon.getPointerLength(this); bounds.height -= balloon.getPointerLength(this) - 1; @@ -879,6 +925,11 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi return new Point(center.x, targetPoint.y - balloonSize.height); } + @Override + protected Insets getTitleInsets(int normalInset, int pointerLength) { + return new Insets(normalInset, normalInset, normalInset, normalInset); + } + protected void convertBoundsToContent(final Rectangle bounds, final BalloonImpl balloon) { bounds.height -= balloon.getPointerLength(this) - 1; } @@ -938,6 +989,11 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi return new Point(targetPoint.x, center.y); } + @Override + protected Insets getTitleInsets(int normalInset, int pointerLength) { + return new Insets(normalInset, pointerLength, normalInset, normalInset); + } + @Override protected Shape getPointingShape(final Rectangle bounds, final Graphics2D g, final Point pointTarget, final BalloonImpl balloon) { final Shaper shaper = new Shaper(balloon, bounds, pointTarget, SwingUtilities.LEFT); @@ -997,6 +1053,11 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi return new Point(targetPoint.x - balloonSize.width, center.y); } + @Override + protected Insets getTitleInsets(int normalInset, int pointerLength) { + return new Insets(normalInset, pointerLength, normalInset, normalInset); + } + protected void convertBoundsToContent(final Rectangle bounds, final BalloonImpl balloon) { bounds.width -= balloon.getPointerLength(this); } @@ -1057,14 +1118,24 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi private float myAlpha; private final BalloonImpl myBalloon; - private final Wrapper myContent; + private final JComponent myContent; private MyComponent(JComponent content, BalloonImpl balloon, EmptyBorder shapeBorder) { setOpaque(false); setLayout(null); myBalloon = balloon; - myContent = new Wrapper(content); + + myContent = new JPanel(new BorderLayout(2, 2)); + Wrapper contentWrapper = new Wrapper(content); + if (myTitle != null) { + myTitleLabel = new JLabel(myTitle, JLabel.CENTER); + myTitleLabel.setForeground(UIManager.getColor("List.background")); + myTitleLabel.setBorder(new EmptyBorder(0, 4, 0, 4)); + myContent.add(myTitleLabel, BorderLayout.NORTH); + contentWrapper.setBorder(new EmptyBorder(1, 1, 1, 1)); + } + myContent.add(contentWrapper, BorderLayout.CENTER); myContent.setBorder(shapeBorder); myContent.setOpaque(false); @@ -1120,7 +1191,7 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi if (myImage == null && myAlpha != -1) { myImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); - myBalloon.myPosition.paintComponent(myBalloon, shapeBounds, (Graphics2D)myImage.getGraphics(), pointTarget); + myBalloon.myPosition.paintComponent(myBalloon, shapeBounds, (Graphics2D)myImage.getGraphics(), pointTarget, this); } if (myImage != null && myAlpha != -1) { @@ -1129,7 +1200,7 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi g2d.drawImage(myImage, 0, 0, null); } else { - myBalloon.myPosition.paintComponent(myBalloon, shapeBounds, (Graphics2D)g, pointTarget); + myBalloon.myPosition.paintComponent(myBalloon, shapeBounds, (Graphics2D)g, pointTarget, this); } } @@ -1302,7 +1373,7 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi //pane.setBorder(new LineBorder(Color.blue)); - balloon.set(new BalloonImpl(new JLabel("FUCK"), Color.black, MessageType.ERROR.getPopupBackground(), true, true, true, true, true, 0, true, null, false, 500, 5, 0, 0, false)); + balloon.set(new BalloonImpl(new JLabel("FUCK"), Color.black, MessageType.ERROR.getPopupBackground(), true, true, true, true, true, 0, true, null, false, 500, 5, 0, 0, false, "This is the title")); balloon.get().setShowPointer(true); if (e.isShiftDown()) { diff --git a/platform/platform-impl/src/com/intellij/ui/popup/BalloonPopupBuilderImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/BalloonPopupBuilderImpl.java index 084d2d255af3..9d4e620eb73e 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/BalloonPopupBuilderImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/BalloonPopupBuilderImpl.java @@ -19,6 +19,7 @@ import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.ui.popup.BalloonBuilder; import com.intellij.ui.BalloonImpl; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -48,6 +49,7 @@ public class BalloonPopupBuilderImpl implements BalloonBuilder { private int myPositionChangeYShift; private boolean myHideOnAction = true; private boolean myDialogMode; + private String myTitle; public BalloonPopupBuilderImpl(@NotNull final JComponent content) { myContent = content; @@ -144,7 +146,7 @@ public class BalloonPopupBuilderImpl implements BalloonBuilder { @NotNull public Balloon createBalloon() { return new BalloonImpl(myContent, myBorder, myFill, myHideOnMouseOutside, myHideOnKeyOutside, myHideOnAction, myShowCalllout, myCloseButtonEnabled, myFadeoutTime, myHideOnFrameResize, myClickHandler, myCloseOnClick, myAnimationCycle, - myCalloutShift, myPositionChangeXShift, myPositionChangeYShift, myDialogMode); + myCalloutShift, myPositionChangeXShift, myPositionChangeYShift, myDialogMode, myTitle); } @NotNull @@ -166,4 +168,11 @@ public class BalloonPopupBuilderImpl implements BalloonBuilder { myCalloutShift = length; return this; } + + @NotNull + @Override + public BalloonBuilder setTitle(@Nullable String title) { + myTitle = title; + return this; + } } From 175d9158af2fce84cdcc7d9578a45852bc8f91bc Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Wed, 11 May 2011 14:36:55 +0400 Subject: [PATCH 126/250] inplace refactoring balloons with titles --- .../InplaceIntroduceConstantPopup.java | 8 +------ .../InplaceIntroduceFieldPopup.java | 8 +------ .../AbstractInplaceIntroducer.java | 4 ++-- .../InplaceIntroduceParameterPopup.java | 8 +------ .../IntroduceVariableBase.java | 2 +- .../VariableInplaceIntroducer.java | 21 +++++++++++-------- 6 files changed, 18 insertions(+), 33 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java index cc3350a9f84d..ac814659dcc8 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java @@ -132,12 +132,6 @@ public class InplaceIntroduceConstantPopup { myWholePanel = new JPanel(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0 , 0, 0), 0, 0); - final TitlePanel titlePanel = new TitlePanel(); - titlePanel.setBorder(null); - titlePanel.setText(IntroduceConstantHandler.REFACTORING_NAME); - gc.gridwidth = 2; - myWholePanel.add(titlePanel, gc); - gc.gridwidth = 1; gc.gridy = 1; myWholePanel.add(createLeftPanel(), gc); @@ -388,7 +382,7 @@ public class InplaceIntroduceConstantPopup { myEditor, field, false, myTypeSelectorManager.getTypesForAll().length > 1, myExpr != null && myExpr.isPhysical() ? myEditor.getDocument().createRangeMarker(myExpr.getTextRange()) : null, InplaceIntroduceConstantPopup.this.getOccurrenceMarkers(), - IntroduceConstantHandler.REFACTORING_NAME); + IntroduceConstantHandler.REFACTORING_NAME, IntroduceConstantHandler.REFACTORING_NAME); myDefaultParameterTypePointer = SmartTypePointerManager.getInstance(myProject).createSmartTypePointer(myTypeSelectorManager.getDefaultType()); diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java index e66ccc687e4a..acf8d5349d7a 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java @@ -36,7 +36,6 @@ import com.intellij.refactoring.introduceParameter.AbstractInplaceIntroducer; import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer; import com.intellij.refactoring.ui.TypeSelectorManagerImpl; import com.intellij.refactoring.util.occurences.OccurenceManager; -import com.intellij.ui.TitlePanel; import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.Nullable; @@ -125,15 +124,10 @@ public class InplaceIntroduceFieldPopup { myWholePanel = new JPanel(new GridBagLayout()); myWholePanel.setBorder(null); - final TitlePanel titlePanel = new TitlePanel(); - titlePanel.setBorder(null); - titlePanel.setText(IntroduceFieldHandler.REFACTORING_NAME); - GridBagConstraints gc = new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,0), 0, 0); - myWholePanel.add(titlePanel, gc); gc.gridy++; gc.insets.top = 5; @@ -253,7 +247,7 @@ public class InplaceIntroduceFieldPopup { myEditor, psiVariable, false, myTypeSelectorManager.getTypesForAll().length > 1, myInitializerExpression != null && myInitializerExpression.isPhysical() ? myEditor.getDocument().createRangeMarker(myInitializerExpression.getTextRange()) : null, InplaceIntroduceFieldPopup.this.getOccurrenceMarkers(), - IntroduceFieldHandler.REFACTORING_NAME); + IntroduceFieldHandler.REFACTORING_NAME, IntroduceFieldHandler.REFACTORING_NAME); myDefaultParameterTypePointer = SmartTypePointerManager.getInstance(myProject).createSmartTypePointer(myTypeSelectorManager.getDefaultType()); myFieldRangeStart = myEditor.getDocument().createRangeMarker(psiVariable.getTextRange()); diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractInplaceIntroducer.java index 10d3d8886f3b..c5382798e221 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractInplaceIntroducer.java @@ -57,8 +57,8 @@ public abstract class AbstractInplaceIntroducer extends VariableInplaceIntroduce boolean cantChangeFinalModifier, boolean hasTypeSuggestion, RangeMarker exprMarker, - List occurrenceMarkers, String commandName) { - super(project, expression, editor, elementToRename, cantChangeFinalModifier, hasTypeSuggestion, exprMarker, occurrenceMarkers, commandName); + List occurrenceMarkers, String commandName, String title) { + super(project, expression, editor, elementToRename, cantChangeFinalModifier, hasTypeSuggestion, exprMarker, occurrenceMarkers, commandName, title); } protected abstract boolean isReplaceAllOccurrences(); diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java index 21e183b22ebe..9761f74e80b1 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java @@ -111,12 +111,6 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { final GridBagConstraints gc = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0); - final TitlePanel titlePanel = new TitlePanel(); - titlePanel.setBorder(null); - titlePanel.setText(IntroduceParameterHandler.REFACTORING_NAME); - gc.gridwidth = 2; - myWholePanel.add(titlePanel, gc); - gc.insets = new Insets(0, 5, 0, 0); gc.gridwidth = 1; gc.fill = GridBagConstraints.NONE; @@ -255,7 +249,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { super(myProject, new TypeExpression(myProject, myTypeSelectorManager.getTypesForAll()), myEditor, parameter, myMustBeFinal, myTypeSelectorManager.getTypesForAll().length > 1, myExprMarker, InplaceIntroduceParameterPopup.this.getOccurrenceMarkers(), - IntroduceParameterHandler.REFACTORING_NAME); + IntroduceParameterHandler.REFACTORING_NAME, IntroduceParameterHandler.REFACTORING_NAME); myDefaultParameterTypePointer = SmartTypePointerManager.getInstance(myProject).createSmartTypePointer(parameter.getType()); } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java index cf94b6c891e0..6605d527652c 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java @@ -479,7 +479,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme final boolean cantChangeFinalModifier = (hasWriteAccess || inFinalContext) && choice == OccurrencesChooser.ReplaceChoice.ALL; final VariableInplaceRenamer renamer = new VariableInplaceIntroducer(project, expression, editor, elementToRename, cantChangeFinalModifier, - typeSelectorManager.getTypesForAll().length > 1, exprMarker, occurrenceMarkers, IntroduceVariableBase.REFACTORING_NAME); + typeSelectorManager.getTypesForAll().length > 1, exprMarker, occurrenceMarkers, IntroduceVariableBase.REFACTORING_NAME, IntroduceVariableBase.REFACTORING_NAME); PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument()); renamer.performInplaceRename(false, new LinkedHashSet(Arrays.asList(suggestedName.names))); } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java index 25400e971588..9394c10aabec 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java @@ -76,6 +76,7 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { protected JCheckBox myCanBeFinalCb; private Balloon myBalloon; + private String myTitle; public VariableInplaceIntroducer(final Project project, final TypeExpression expression, @@ -85,12 +86,14 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { final boolean hasTypeSuggestion, final RangeMarker exprMarker, final List occurrenceMarkers, - final String commandName) { + final String commandName, + final String title) { super(elementToRename, editor); myProject = project; myEditor = editor; myElementToRename = elementToRename; myExpression = expression; + myTitle = title; myExprMarker = exprMarker; myOccurrenceMarkers = occurrenceMarkers; @@ -240,11 +243,6 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { final JPanel panel = new JPanel(new GridBagLayout()); panel.setBorder(null); - final TitlePanel titlePanel = new TitlePanel(); - titlePanel.setBorder(null); - titlePanel.setText(IntroduceVariableBase.REFACTORING_NAME); - panel.add(titlePanel, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); - if (myCanBeFinalCb != null) { panel.add(myCanBeFinalCb, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); } @@ -360,18 +358,23 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { } + protected String getTitle() { + return myTitle; + } + private void showBalloon() { final JComponent component = getComponent(); if (component == null) return; if (ApplicationManager.getApplication().isHeadlessEnvironment()) return; final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createBalloonBuilder(component); balloonBuilder.setFadeoutTime(0) - .setFillColor(IdeTooltipManager.GRAPHITE_COLOR.brighter().brighter()) - .setAnimationCycle(0) + .setFillColor(UIManager.getColor("Panel.background")) + .setAnimationCycle(100) .setHideOnClickOutside(false) .setHideOnKeyOutside(false) .setHideOnAction(false) - .setCloseButtonEnabled(true); + .setCloseButtonEnabled(true) + .setTitle(getTitle()); final RelativePoint target = JBPopupFactory.getInstance().guessBestPopupLocation(myEditor); final Point screenPoint = target.getScreenPoint(); From a2d7ac1d50fe9297270acfbb3b7ad5235214cb3b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 10 May 2011 20:57:14 +0400 Subject: [PATCH 127/250] EA-26911 (more logging) --- .../psi/impl/compiled/ClsClassImpl.java | 52 +++++++++++++------ .../psi/impl/compiled/ClsElementImpl.java | 5 +- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java b/java/java-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java index 43f7a723d24f..df8d97f74188 100644 --- a/java/java-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -19,6 +19,7 @@ import com.intellij.navigation.ItemPresentation; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.ui.Queryable; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.Ref; import com.intellij.psi.*; import com.intellij.psi.impl.InheritanceImplUtil; import com.intellij.psi.impl.PsiClassImplUtil; @@ -395,43 +396,64 @@ public class ClsClassImpl extends ClsRepositoryPsiElement> imple public void setMirror(@NotNull TreeElement element) { setMirrorCheckingType(element, null); - PsiClass mirror = (PsiClass)SourceTreeToPsiMap.treeElementToPsi(element); + PsiClass mirror = SourceTreeToPsiMap.treeToPsiNotNull(element); - final PsiDocComment docComment = getDocComment(); + PsiDocComment docComment = getDocComment(); if (docComment != null) { - ((ClsElementImpl)docComment).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment())); + ((ClsElementImpl)docComment).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment())); } - ((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList())); - ((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier())); + ((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList())); + ((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier())); if (!isAnnotationType() && !isEnum()) { - ((ClsElementImpl)getExtendsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getExtendsList())); + ((ClsElementImpl)getExtendsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getExtendsList())); } - ((ClsElementImpl)getImplementsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getImplementsList())); - ((ClsElementImpl)getTypeParameterList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getTypeParameterList())); + ((ClsElementImpl)getImplementsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getImplementsList())); + ((ClsElementImpl)getTypeParameterList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getTypeParameterList())); + + Ref extLog = Ref.create(true); PsiField[] fields = getFields(); PsiField[] mirrorFields = mirror.getFields(); - if (LOG.assertTrue(fields.length == mirrorFields.length)) { + if (fields.length == mirrorFields.length) { for (int i = 0; i < fields.length; i++) { - ((ClsElementImpl)fields[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirrorFields[i])); + ((ClsElementImpl)fields[i]).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirrorFields[i])); } } + else { + log(this, mirror, "fields:" + fields.length + "!=" + mirrorFields.length, extLog); + } PsiMethod[] methods = getMethods(); PsiMethod[] mirrorMethods = mirror.getMethods(); - if (LOG.assertTrue(methods.length == mirrorMethods.length)) { + if (methods.length == mirrorMethods.length) { for (int i = 0; i < methods.length; i++) { - ((ClsElementImpl)methods[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirrorMethods[i])); + ((ClsElementImpl)methods[i]).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirrorMethods[i])); } } + else { + log(this, mirror, "methods:" + methods.length + "!=" + mirrorMethods.length, extLog); + } PsiClass[] classes = getInnerClasses(); PsiClass[] mirrorClasses = mirror.getInnerClasses(); - if (LOG.assertTrue(classes.length == mirrorClasses.length)) { + if (classes.length == mirrorClasses.length) { for (int i = 0; i < classes.length; i++) { - ((ClsElementImpl)classes[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirrorClasses[i])); + ((ClsElementImpl)classes[i]).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirrorClasses[i])); } } + else { + log(this, mirror, "classes:" + classes.length + "!=" + mirrorClasses.length, extLog); + } + } + + private static void log(@NotNull ClsClassImpl stub, @NotNull PsiClass mirror, @NotNull String message, @NotNull Ref verbose) { + LOG.error(message + "; file:" + stub.getContainingFile().getName()); + if (verbose.get()) { + StringBuilder builder = new StringBuilder(); + stub.appendMirrorText(0, builder); + LOG.error("\nStub:\n" + builder.toString() + "\nMirror:\n" + mirror.getText()); + verbose.set(false); + } } public void accept(@NotNull PsiElementVisitor visitor) { diff --git a/java/java-impl/src/com/intellij/psi/impl/compiled/ClsElementImpl.java b/java/java-impl/src/com/intellij/psi/impl/compiled/ClsElementImpl.java index 51a67aa2b740..495c9affc036 100644 --- a/java/java-impl/src/com/intellij/psi/impl/compiled/ClsElementImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/compiled/ClsElementImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -30,6 +30,7 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public abstract class ClsElementImpl extends PsiElementBase implements PsiCompiledElement { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsElementImpl"); @@ -233,7 +234,7 @@ public abstract class ClsElementImpl extends PsiElementBase implements PsiCompil return null; } - protected void setMirrorCheckingType(@NotNull TreeElement element, IElementType type) { + protected void setMirrorCheckingType(@NotNull TreeElement element, @Nullable IElementType type) { if (CHECK_MIRROR_ENABLED) { LOG.assertTrue(myMirror == null); } From f9234877fc1ffef9934086dcdca68f14dbd62d4b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 11 May 2011 14:56:12 +0400 Subject: [PATCH 128/250] EA-27702 (more logging) --- .../psi/impl/PsiJavaParserFacadeImpl.java | 18 ++++++++++++++++-- .../psi/impl/source/JavaDummyElement.java | 10 +++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java b/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java index c7f89d6a58d3..776d6fbfde63 100644 --- a/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/PsiJavaParserFacadeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -32,6 +32,7 @@ import com.intellij.psi.impl.source.DummyHolder; import com.intellij.psi.impl.source.DummyHolderFactory; import com.intellij.psi.impl.source.JavaDummyElement; import com.intellij.psi.impl.source.SourceTreeToPsiMap; +import com.intellij.psi.impl.source.tree.FileElement; import com.intellij.psi.impl.source.tree.TreeElement; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.javadoc.PsiDocTag; @@ -234,7 +235,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiMethod)) { - throw new IncorrectOperationException("Incorrect method \"" + text + "\" (" + element + ")."); + throw newException("Incorrect method \"" + text + "\".", holder); } return (PsiMethod)element; } @@ -453,4 +454,17 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ private static LanguageLevel level(@Nullable final PsiElement context) { return context != null ? PsiUtil.getLanguageLevel(context) : LanguageLevel.HIGHEST; } + + private static IncorrectOperationException newException(final String msg, final DummyHolder holder) { + final FileElement root = holder.getTreeElement(); + if (root instanceof JavaDummyElement) { + final Throwable cause = ((JavaDummyElement)root).getParserError(); + if (cause != null) { + return new IncorrectOperationException(msg) { + @Override public Throwable getCause() { return cause; } + }; + } + } + return new IncorrectOperationException(msg); + } } diff --git a/java/java-impl/src/com/intellij/psi/impl/source/JavaDummyElement.java b/java/java-impl/src/com/intellij/psi/impl/source/JavaDummyElement.java index 0ac0f50edee2..b1613df6c3d4 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/JavaDummyElement.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/JavaDummyElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -31,6 +31,7 @@ public class JavaDummyElement extends FileElement { private final JavaParserUtil.ParserWrapper myParser; private final LanguageLevel myLanguageLevel; private final boolean myConsumeAll; + private Throwable myParserError = null; public JavaDummyElement(@Nullable final CharSequence text, @NotNull final JavaParserUtil.ParserWrapper parser, @@ -68,6 +69,7 @@ public class JavaDummyElement extends FileElement { return super.getFirstChildNode(); } catch (AssertionError e) { + myParserError = e; return null; // masquerade parser errors } } @@ -78,7 +80,13 @@ public class JavaDummyElement extends FileElement { return super.getLastChildNode(); } catch (AssertionError e) { + myParserError = e; return null; // masquerade parser errors } } + + @Nullable + public Throwable getParserError() { + return myParserError; + } } \ No newline at end of file From b5e99fa6bbb0ad60aa001b902a4a82c35e61b8b5 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 11 May 2011 13:17:23 +0200 Subject: [PATCH 129/250] don't offer new channel if it doesn't have new version (IDEA-69430) --- .../intellij/openapi/updateSettings/impl/UpdateStrategy.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.java index a160212ada14..2d87288209f6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateStrategy.java @@ -66,7 +66,8 @@ public class UpdateStrategy { for (UpdateChannel channel : product.getChannels()) { if (!myUpdateSettings.getKnownChannelsIds().contains(channel.getId()) && channel.getMajorVersion() >= myMajorVersion && - channel.getStatus().compareTo(myChannelStatus) >= 0) { + channel.getStatus().compareTo(myChannelStatus) >= 0 && + hasNewVersion(channel)) { result.addNewChannel(channel); if (channelToPropose == null || isBetter(channelToPropose, channel)) { channelToPropose = channel; From 49d7135ab6798e4bd1bc2cf0dc9d536ea59d36f3 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 13:27:35 +0200 Subject: [PATCH 130/250] [^yole] EA-27703 - a chained call with null-safe invocation can't seem to be a qualified class name --- .../org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java | 2 ++ .../plugins/groovy/lang/resolve/TypeInferenceTest.java | 4 ++++ .../SafeInvocationInClassQualifier.groovy | 2 ++ 3 files changed, 8 insertions(+) create mode 100644 plugins/groovy/testdata/resolve/inference/safeInvocationInClassQualifier/SafeInvocationInClassQualifier.groovy diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java index 78df3148e0c9..6031a9cc659e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java @@ -1133,6 +1133,8 @@ public class PsiUtil { final PsiElement nameElement = ((GrReferenceExpression)qualifier).getReferenceNameElement(); if (((GrReferenceExpression)qualifier).getTypeArguments().length > 0) return false; if (nameElement == null || nameElement.getNode().getElementType() != GroovyTokenTypes.mIDENT) return false; + IElementType dotType = ((GrReferenceExpression)qualifier).getDotTokenType(); + if (dotType != null && dotType != GroovyTokenTypes.mDOT) return false; qualifier = ((GrReferenceExpression)qualifier).getQualifierExpression(); } return qualifier == null; diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.java index 086952506f86..595be1076ed1 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.java @@ -206,6 +206,10 @@ public class TypeInferenceTest extends GroovyResolveTestCase { assertTypeEquals("java.lang.String", "A.groovy"); } + public void testSafeInvocationInClassQualifier() { + assertTypeEquals("java.lang.Class", "SafeInvocationInClassQualifier.groovy"); + } + public void testReturnTypeFromMethodClosure() { assertTypeEquals("java.lang.String","A.groovy"); } diff --git a/plugins/groovy/testdata/resolve/inference/safeInvocationInClassQualifier/SafeInvocationInClassQualifier.groovy b/plugins/groovy/testdata/resolve/inference/safeInvocationInClassQualifier/SafeInvocationInClassQualifier.groovy new file mode 100644 index 000000000000..fbac17ac7525 --- /dev/null +++ b/plugins/groovy/testdata/resolve/inference/safeInvocationInClassQualifier/SafeInvocationInClassQualifier.groovy @@ -0,0 +1,2 @@ +def foo = [] +println foo?.prop?.class \ No newline at end of file From aa16d0686c8daabc571473f6c96c5b329a4c56cc Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Wed, 11 May 2011 10:20:09 +0400 Subject: [PATCH 131/250] test fix --- .../plugins/groovy/lang/resolve/TypeInferenceTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.java index 595be1076ed1..3899a977a96d 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.java @@ -215,7 +215,10 @@ public class TypeInferenceTest extends GroovyResolveTestCase { } public void testNoSOF() { - assertTypeEquals("java.lang.Object", "A.groovy"); + final PsiReference ref = configureByFile(getTestName(true) + "/A.groovy"); + assertInstanceOf(ref, GrReferenceExpression.class); + final PsiType type = ((GrReferenceExpression)ref).getType(); + assertNull(type); } public void testTraditionalForVar() { From b5108ffcd7ae36f6e55e8a2b33328ce6ebabb7e1 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Wed, 11 May 2011 11:09:04 +0400 Subject: [PATCH 132/250] IDEA-68757 Wrong warning on assignment to variable in for expression --- ...tOfIncrementOrDecrementUsedInspection.java | 32 ++++++++++++++++--- .../groovy/lang/GroovyHighlightingTest.java | 5 +++ .../highlighting/ResultOfIncUsed.groovy | 12 +++++++ 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 plugins/groovy/testdata/highlighting/ResultOfIncUsed.groovy diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyResultOfIncrementOrDecrementUsedInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyResultOfIncrementOrDecrementUsedInspection.java index bbd586181020..713ad4a106af 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyResultOfIncrementOrDecrementUsedInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyResultOfIncrementOrDecrementUsedInspection.java @@ -17,14 +17,21 @@ package org.jetbrains.plugins.groovy.codeInspection.confusing; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; +import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.codeInspection.BaseInspection; import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor; +import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock; +import org.jetbrains.plugins.groovy.lang.psi.api.formatter.GrControlStatement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrTraditionalForClause; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner; +import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; public class GroovyResultOfIncrementOrDecrementUsedInspection extends BaseInspection { @@ -54,14 +61,29 @@ public class GroovyResultOfIncrementOrDecrementUsedInspection extends BaseInspec public void visitUnaryExpression(GrUnaryExpression grUnaryExpression) { super.visitUnaryExpression(grUnaryExpression); - final PsiElement parent = grUnaryExpression.getParent(); - if (parent instanceof GrCodeBlock) { - return; - } + final IElementType tokenType = grUnaryExpression.getOperationTokenType(); if (!GroovyTokenTypes.mINC.equals(tokenType) && !GroovyTokenTypes.mDEC.equals(tokenType)) { return; } + + final PsiElement parent = PsiTreeUtil.skipParentsOfType(grUnaryExpression, GrParenthesizedExpression.class); + PsiElement skipped = PsiUtil.skipParentheses(grUnaryExpression, true); + assert skipped != null; + + if (ControlFlowUtils.collectReturns(ControlFlowUtils.findControlFlowOwner(parent)).contains(skipped)) { + registerError(grUnaryExpression); + return; + } + + if (parent instanceof GrStatementOwner || parent instanceof GrControlStatement) { + return; + } + + if (parent instanceof GrTraditionalForClause) { + if (PsiTreeUtil.isAncestor(((GrTraditionalForClause)parent).getUpdate(), skipped, false)) return; + } + registerError(grUnaryExpression); } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java index 277dc14a0570..6e01beb56b3a 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java @@ -24,6 +24,7 @@ import org.jetbrains.plugins.groovy.codeInspection.bugs.GroovyAccessibilityInspe import org.jetbrains.plugins.groovy.codeInspection.bugs.GroovyLabeledStatementInspection; import org.jetbrains.plugins.groovy.codeInspection.bugs.GroovyRangeTypeCheckInspection; import org.jetbrains.plugins.groovy.codeInspection.bugs.GroovyResultOfObjectAllocationIgnoredInspection; +import org.jetbrains.plugins.groovy.codeInspection.confusing.GroovyResultOfIncrementOrDecrementUsedInspection; import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialConditionalInspection; import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialIfInspection; import org.jetbrains.plugins.groovy.codeInspection.metrics.GroovyOverlyLongMethodInspection; @@ -410,4 +411,8 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase { public void testAnotherCurrying(){ doTest(new GroovyAssignabilityCheckInspection()); } + + public void testResultOfIncUsed() { + doTest(new GroovyResultOfIncrementOrDecrementUsedInspection()); + } } \ No newline at end of file diff --git a/plugins/groovy/testdata/highlighting/ResultOfIncUsed.groovy b/plugins/groovy/testdata/highlighting/ResultOfIncUsed.groovy new file mode 100644 index 000000000000..9f4a783c528a --- /dev/null +++ b/plugins/groovy/testdata/highlighting/ResultOfIncUsed.groovy @@ -0,0 +1,12 @@ +for (int i=0;i<10; i++) { + def x = i++ +} + +def x= 0 + +if (true) x++ +print x + +def foo(d) { + d++ //used in return +} \ No newline at end of file From 45038def92ae64a17a228a5211206511fc70a21c Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Wed, 11 May 2011 13:55:32 +0400 Subject: [PATCH 133/250] modifiers for params, correct ref-wrappers in expression --- ...tOfIncrementOrDecrementUsedInspection.java | 30 +-- .../plugins/groovy/lang/psi/util/PsiUtil.java | 20 +- .../AnonymousFromMapGenerator.java | 2 +- .../convertToJava/ClassItemGeneratorImpl.java | 7 +- .../convertToJava/ExpressionGenerator.java | 172 ++++++++++-------- .../convertToJava/GenerationUtil.java | 11 +- .../convertToJava/StubGenerator.java | 6 +- .../convertToJava/FileGenerationTest.groovy | 1 + .../file/closureParamInInnerClosure.java | 4 +- .../methodParamInClosureImplicitReturn.groovy | 13 ++ .../methodParamInClosureImplicitReturn.java | 46 +++++ .../file/methodParamsInClosures.java | 4 +- .../file/refInClosureInMethod.java | 3 +- .../convertGroovyToJava/file/useAnno.java | 2 +- 14 files changed, 208 insertions(+), 113 deletions(-) create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamInClosureImplicitReturn.groovy create mode 100644 plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamInClosureImplicitReturn.java diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyResultOfIncrementOrDecrementUsedInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyResultOfIncrementOrDecrementUsedInspection.java index 713ad4a106af..8a4f7e0a630b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyResultOfIncrementOrDecrementUsedInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyResultOfIncrementOrDecrementUsedInspection.java @@ -15,22 +15,14 @@ */ package org.jetbrains.plugins.groovy.codeInspection.confusing; -import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; -import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.codeInspection.BaseInspection; import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor; -import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; -import org.jetbrains.plugins.groovy.lang.psi.api.formatter.GrControlStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrTraditionalForClause; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; public class GroovyResultOfIncrementOrDecrementUsedInspection extends BaseInspection { @@ -50,7 +42,6 @@ public class GroovyResultOfIncrementOrDecrementUsedInspection extends BaseInspec @Nullable protected String buildErrorString(Object... args) { return "Result of increment or decrement expression used #loc"; - } public BaseInspectionVisitor buildVisitor() { @@ -58,7 +49,7 @@ public class GroovyResultOfIncrementOrDecrementUsedInspection extends BaseInspec } private static class Visitor extends BaseInspectionVisitor { - + public void visitUnaryExpression(GrUnaryExpression grUnaryExpression) { super.visitUnaryExpression(grUnaryExpression); @@ -67,24 +58,9 @@ public class GroovyResultOfIncrementOrDecrementUsedInspection extends BaseInspec return; } - final PsiElement parent = PsiTreeUtil.skipParentsOfType(grUnaryExpression, GrParenthesizedExpression.class); - PsiElement skipped = PsiUtil.skipParentheses(grUnaryExpression, true); - assert skipped != null; - - if (ControlFlowUtils.collectReturns(ControlFlowUtils.findControlFlowOwner(parent)).contains(skipped)) { - registerError(grUnaryExpression); - return; - } - - if (parent instanceof GrStatementOwner || parent instanceof GrControlStatement) { - return; + if (PsiUtil.resultOfExpressionUsed(grUnaryExpression)) { + registerError(grUnaryExpression); } - - if (parent instanceof GrTraditionalForClause) { - if (PsiTreeUtil.isAncestor(((GrTraditionalForClause)parent).getUpdate(), skipped, false)) return; - } - - registerError(grUnaryExpression); } } } \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java index 6031a9cc659e..8a2318319fbd 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java @@ -39,6 +39,7 @@ import gnu.trove.TIntStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.GroovyFileTypeLoader; +import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils; import org.jetbrains.plugins.groovy.config.GroovyConfigUtils; import org.jetbrains.plugins.groovy.debugger.fragments.GroovyCodeFragment; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment; @@ -1148,7 +1149,8 @@ public class PsiUtil { parent instanceof GrReturnStatement || parent instanceof GrAssertStatement || parent instanceof GrThrowStatement || - parent instanceof GrSwitchStatement) { + parent instanceof GrSwitchStatement || + parent instanceof GrVariable) { return false; } return true; @@ -1217,4 +1219,20 @@ public class PsiUtil { } return defaultValue; } + + public static boolean resultOfExpressionUsed(GrExpression expr) { + while (expr.getParent() instanceof GrParenthesizedExpression) expr = (GrExpression)expr.getParent(); + + final PsiElement parent = expr.getParent(); + if (parent instanceof GrExpression || + parent instanceof GrArgumentList || + parent instanceof GrReturnStatement || + parent instanceof GrAssertStatement || + parent instanceof GrThrowStatement || + parent instanceof GrSwitchStatement || + parent instanceof GrVariable) { + return true; + } + return ControlFlowUtils.collectReturns(ControlFlowUtils.findControlFlowOwner(expr), true).contains(expr); + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/AnonymousFromMapGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/AnonymousFromMapGenerator.java index 575652bbe692..a080c47e4260 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/AnonymousFromMapGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/AnonymousFromMapGenerator.java @@ -114,7 +114,7 @@ public class AnonymousFromMapGenerator { writeType(builder, returnType, operand); builder.append(' ').append(name); - GenerationUtil.writeParameterList(builder, parameters, new GeneratorClassNameProvider()); + GenerationUtil.writeParameterList(builder, parameters, new GeneratorClassNameProvider(), context); final ExpressionContext extended = context.extend(); extended.setInAnonymousContext(true); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java index 882b3b6c336e..307b32f2a019 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ClassItemGeneratorImpl.java @@ -141,14 +141,17 @@ public class ClassItemGeneratorImpl implements ClassItemGenerator { } builder.append(name); + if (method instanceof GroovyPsiElement) { + context.searchForLocalVarsToWrap((GroovyPsiElement)method); + } final ArrayList actualParams; if (method instanceof GrMethod) { actualParams = getActualParams((GrMethod)method, skipOptional); - GenerationUtil.writeParameterList(builder, actualParams.toArray(new GrParameter[actualParams.size()]), classNameProvider); + GenerationUtil.writeParameterList(builder, actualParams.toArray(new GrParameter[actualParams.size()]), classNameProvider, context); } else { LOG.assertTrue(skipOptional == 0); - GenerationUtil.writeParameterList(builder, method.getParameterList().getParameters(), classNameProvider); + GenerationUtil.writeParameterList(builder, method.getParameterList().getParameters(), classNameProvider, context); actualParams = null; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java index d6717773bdd4..b46050e7956f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java @@ -320,6 +320,15 @@ public class ExpressionGenerator extends Generator { elseBranch.accept(this); } + /** + * x= expr -> + * x = expr + * x.set(expr)[: x.get()] + * x+= expr -> + * x+=expr + * x= plus(x, expr) + * x.set(plus(x, expr))[:x.get()] + */ @Override public void visitAssignmentExpression(GrAssignmentExpression expression) { final GrExpression lValue = expression.getLValue(); @@ -334,69 +343,72 @@ public class ExpressionGenerator extends Generator { if (resolved instanceof GrVariable && context.analyzedVars.toWrap((GrVariable)resolved)) toWrap = true; } - - - if (token == mASSIGN) { - lValue.accept(this); - - if (toWrap) { - builder.append(".set("); - } - else { - builder.append(" = "); - } - if (rValue != null) { - rValue.accept(this); - } - if (toWrap) { - builder.append(')'); - } - return; + StringBuilder curBuilder; + ExpressionGenerator curGenerator; + boolean doNeedExpression = toWrap && PsiUtil.resultOfExpressionUsed(expression); + if (doNeedExpression) { + curBuilder = new StringBuilder(); + curGenerator = new ExpressionGenerator(curBuilder, context); + } + else { + curBuilder = builder; + curGenerator = this; } - final GroovyResolveResult resolveResult = PsiImplUtil.extractUniqueResult(expression.multiResolve(false)); - final PsiElement resolved = resolveResult.getElement(); - if (resolved instanceof PsiMethod) { - lValue.accept(this); - if (toWrap) { - builder.append(".set("); - } - else { - builder.append(" = "); - } + lValue.accept(curGenerator); + if (toWrap) { + curBuilder.append(".set("); + } + else { + curBuilder.append(" = "); + } - if (rValue == null) { - rValue = factory.createExpressionFromText("null"); - } - invokeMethodOn( - ((PsiMethod)resolved), - (GrExpression)lValue.copy(), - new GrExpression[]{rValue}, - GrNamedArgument.EMPTY_ARRAY, - GrClosableBlock.EMPTY_ARRAY, - resolveResult.getSubstitutor(), - expression - ); - if (toWrap) { - builder.append(')'); + if (token == mASSIGN) { + if (rValue != null) { + rValue.accept(curGenerator); } } else { - if (toWrap) { - lValue.accept(this); - builder.append(".set("); + final GroovyResolveResult resolveResult = PsiImplUtil.extractUniqueResult(expression.multiResolve(false)); + final PsiElement resolved = resolveResult.getElement(); - GrBinaryExpression bin = - (GrBinaryExpression)factory.createExpressionFromText("a" + expression.getOpToken().getText().charAt(0) + "b", expression); - GrExpression newLValue = (GrExpression)bin.getLeftOperand().replace(lValue); - GrExpression newRValue = rValue == null ? null : (GrExpression)bin.getRightOperand().replace(rValue); - writeSimpleBinaryExpression(bin.getOperationToken(), newLValue, newRValue); - builder.append(')'); + if (resolved instanceof PsiMethod) { + if (rValue == null) { + rValue = factory.createExpressionFromText("null"); + } + curGenerator.invokeMethodOn( + ((PsiMethod)resolved), + (GrExpression)lValue.copy(), + new GrExpression[]{rValue}, + GrNamedArgument.EMPTY_ARRAY, + GrClosableBlock.EMPTY_ARRAY, + resolveResult.getSubstitutor(), + expression + ); + } + else { + if (toWrap) { + GrBinaryExpression bin = + (GrBinaryExpression)factory.createExpressionFromText("a" + expression.getOpToken().getText().charAt(0) + "b", expression); + GrExpression newLValue = (GrExpression)bin.getLeftOperand().replace(lValue); + GrExpression newRValue = rValue == null ? null : (GrExpression)bin.getRightOperand().replace(rValue); + curGenerator.writeSimpleBinaryExpression(bin.getOperationToken(), newLValue, newRValue); + } + else { + curGenerator.writeSimpleBinaryExpression(expression.getOpToken(), lValue, rValue); + } + } + } + if (toWrap) { + curBuilder.append(')'); + if (doNeedExpression) { + curBuilder.append(';'); + context.myStatements.add(curBuilder.toString()); + lValue.accept(this); + builder.append(".get()"); } - writeSimpleBinaryExpression(expression.getOpToken(), lValue, rValue); } - } @Override @@ -552,35 +564,51 @@ public class ExpressionGenerator extends Generator { ); } else if (resolved instanceof PsiVariable) { - PsiElement parent = unary.getParent(); - boolean addParentheses = !(parent instanceof GrControlStatement || - parent instanceof GrStatementOwner || - parent instanceof GrArgumentList || - parent instanceof GrParenthesizedExpression); - if (addParentheses) { - builder.append('('); - } - boolean wrap = context.analyzedVars.toWrap((GrVariable)resolved); - if (wrap) { - operand.accept(this); - builder.append(".set("); + boolean wrap = context.analyzedVars.toWrap((PsiVariable)resolved); + boolean doNeedExpression = PsiUtil.resultOfExpressionUsed(unary); + StringBuilder curBuilder; + ExpressionGenerator curGenerator; + if (doNeedExpression && wrap) { + curBuilder = new StringBuilder(); + curGenerator = new ExpressionGenerator(curBuilder, context); } else { - operand.accept(this); - builder.append(" = "); + curBuilder = builder; + curGenerator = this; } - invokeMethodOn( + + + PsiElement parent = unary.getParent(); + boolean shouldInsertParentheses = parent instanceof GrExpression; + if (shouldInsertParentheses) { + curBuilder.append('('); + } + + operand.accept(curGenerator); + if (wrap) { + curBuilder.append(".set("); + } + else { + curBuilder.append(" = "); + } + curGenerator.invokeMethodOn( method, (GrExpression)operand.copy(), GrExpression.EMPTY_ARRAY, GrNamedArgument.EMPTY_ARRAY, GrClosableBlock.EMPTY_ARRAY, resolveResult.getSubstitutor(), unary ); - if (wrap) { - builder.append(')'); + if (shouldInsertParentheses) { + curBuilder.append(')'); } - if (addParentheses) { - builder.append(')'); + if (wrap) { + curBuilder.append(')'); + if (doNeedExpression) { + curBuilder.append(';'); + context.myStatements.add(curBuilder.toString()); + operand.accept(this); + builder.append(".get()"); + } } } return true; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java index bdc17ed436cc..335b3db02152 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/GenerationUtil.java @@ -273,7 +273,10 @@ public class GenerationUtil { text.append(">"); } - static void writeParameterList(StringBuilder text, PsiParameter[] parameters, final ClassNameProvider classNameProvider) { + static void writeParameterList(StringBuilder text, + PsiParameter[] parameters, + final ClassNameProvider classNameProvider, + @Nullable ExpressionContext context) { text.append("("); //writes myParameters @@ -283,6 +286,12 @@ public class GenerationUtil { if (parameter == null) continue; if (i > 0) text.append(", "); //append ',' + if (!classNameProvider.forStubs()) { + ModifierListGenerator.writeModifiers(text, parameter.getModifierList(), ModifierListGenerator.JAVA_MODIFIERS, true); + } + if (context != null && context.analyzedVars.toMakeFinal(parameter)) { + text.append(PsiModifier.FINAL).append(' '); + } writeType(text, TypeProvider.getParameterType(parameter), parameter, classNameProvider); text.append(" "); text.append(parameter.getName()); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java index c04ffca8c38d..44bd0dabf4b5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java @@ -116,7 +116,7 @@ public class StubGenerator implements ClassItemGenerator { /************* parameters **********/ final ArrayList actual = GenerationUtil.getActualParams(constructor, skipOptional); - GenerationUtil.writeParameterList(text, actual.toArray(new GrParameter[actual.size()]), classNameProvider); + GenerationUtil.writeParameterList(text, actual.toArray(new GrParameter[actual.size()]), classNameProvider, null); final Set throwsTypes = collectThrowsTypes(constructor, new THashSet()); if (!throwsTypes.isEmpty()) { @@ -207,11 +207,11 @@ public class StubGenerator implements ClassItemGenerator { if (method instanceof GrMethod) { final ArrayList actualParams = GenerationUtil.getActualParams(((GrMethod)method), skipOptional); - GenerationUtil.writeParameterList(text, actualParams.toArray(new GrParameter[actualParams.size()]), classNameProvider); + GenerationUtil.writeParameterList(text, actualParams.toArray(new GrParameter[actualParams.size()]), classNameProvider, null); } else { LOG.assertTrue(skipOptional==0); - GenerationUtil.writeParameterList(text, method.getParameterList().getParameters(), classNameProvider); + GenerationUtil.writeParameterList(text, method.getParameterList().getParameters(), classNameProvider, null); } writeThrowsList(text, method); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy index 2ad7afc17ac7..4deb3ff07a75 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/convertToJava/FileGenerationTest.groovy @@ -65,4 +65,5 @@ class FileGenerationTest extends LightGroovyTestCase { void testRefInClosureInScript() {doTest()} void testMethodParamsInClosures() {doTest()} void testClosureParamInInnerClosure() {doTest()} + void testMethodParamInClosureImplicitReturn() {doTest()} } diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/closureParamInInnerClosure.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/closureParamInInnerClosure.java index c260ec820ea7..331940d541e1 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/closureParamInInnerClosure.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/closureParamInInnerClosure.java @@ -7,10 +7,10 @@ this.foo = foo; } private groovy.lang.Closure foo = new groovy.lang.Closure(this, this) { public java.lang.Integer doCall(int x) { -final groovy.lang.Reference i1 = new groovy.lang.Reference(x); +final groovy.lang.Reference i2 = new groovy.lang.Reference(x); return org.codehaus.groovy.runtime.DefaultGroovyMethods.each(1, new groovy.lang.Closure(this, this) { public void doCall(java.lang.Object it) { -i1.set(2); +i2.set(2); int i = 3; } diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamInClosureImplicitReturn.groovy b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamInClosureImplicitReturn.groovy new file mode 100644 index 000000000000..3f688a14aeb9 --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamInClosureImplicitReturn.groovy @@ -0,0 +1,13 @@ +def foo(int x) { + [1, 2, 3] .each { + print x + x+=1 + } + + [1, 2, 3] .each { + print x + x++ + } + + print x +} \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamInClosureImplicitReturn.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamInClosureImplicitReturn.java new file mode 100644 index 000000000000..a6b63433eeff --- /dev/null +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamInClosureImplicitReturn.java @@ -0,0 +1,46 @@ +public class methodParamInClosureImplicitReturn extends groovy.lang.Script { +public static void main(java.lang.String[] args) { +new methodParamInClosureImplicitReturn(new groovy.lang.Binding(args)).run(); +} + +public java.lang.Object run() { +return null; + +} + +public void foo(int x) { +final groovy.lang.Reference i1 = new groovy.lang.Reference(x); +org.codehaus.groovy.runtime.DefaultGroovyMethods.each(new java.util.ArrayList(java.util.Arrays.asList(1, 2, 3)), new groovy.lang.Closure(this, this) { +public java.lang.Number doCall(java.lang.Object it) { +org.codehaus.groovy.runtime.DefaultGroovyMethods.print(methodParamInClosureImplicitReturn.this, i1.get()); +i1.set(i1.get().plus(1)); +return i1.get(); +} + +public java.lang.Number doCall() { +return doCall(null); +} + +}); +org.codehaus.groovy.runtime.DefaultGroovyMethods.each(new java.util.ArrayList(java.util.Arrays.asList(1, 2, 3)), new groovy.lang.Closure(this, this) { +public java.lang.Integer doCall(java.lang.Object it) { +org.codehaus.groovy.runtime.DefaultGroovyMethods.print(methodParamInClosureImplicitReturn.this, i1.get()); +i1.set(i1.get().next()); +return i1.get(); +} + +public java.lang.Integer doCall() { +return doCall(null); +} + +}); +print(i1.get()); +} + +public methodParamInClosureImplicitReturn(groovy.lang.Binding binding) { +super(binding); +} +public methodParamInClosureImplicitReturn() { +super(); +} +} diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamsInClosures.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamsInClosures.java index b59ebd253c90..ca758f1d9e96 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamsInClosures.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamsInClosures.java @@ -1,9 +1,9 @@ public class X extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject { public java.lang.Integer foo(int x) { -final groovy.lang.Reference i1 = new groovy.lang.Reference(x); +final groovy.lang.Reference i2 = new groovy.lang.Reference(x); return org.codehaus.groovy.runtime.DefaultGroovyMethods.each(1, new groovy.lang.Closure(this, this) { public void doCall(java.lang.Object it) { -i1.set(2); +i2.set(2); int i = 3; } diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.java index 116505543de1..b5a4233235cb 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInMethod.java @@ -5,7 +5,8 @@ org.codehaus.groovy.runtime.DefaultGroovyMethods.each(X.this, new groovy.lang.Cl public java.lang.Object doCall(java.lang.Object it) { return org.codehaus.groovy.runtime.DefaultGroovyMethods.each(X.this, new groovy.lang.Closure(this, this) { public java.lang.Integer doCall(java.lang.Object it) { -return ab.set(2); +ab.set(2); +return ab.get(); } public java.lang.Integer doCall() { diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/useAnno.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/useAnno.java index db0e0707ee2f..1ceab435ccc1 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/useAnno.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/useAnno.java @@ -18,7 +18,7 @@ return null; } -@p.I public void foo(java.lang.Object x) { +@p.I public void foo(@p.I final java.lang.Object x) { @p.I java.lang.Object a; } From c980e6e7372a9164e0dc24b6593bd73a959b9df7 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Wed, 11 May 2011 14:38:03 +0400 Subject: [PATCH 134/250] don't replace operators with methods for numbers --- .../convertToJava/ExpressionGenerator.java | 86 +++++++++++++------ .../methodParamInClosureImplicitReturn.java | 4 +- .../file/refInClosureInScript.java | 4 +- 3 files changed, 63 insertions(+), 31 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java index b46050e7956f..6d09a6d5ad59 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/ExpressionGenerator.java @@ -373,7 +373,8 @@ public class ExpressionGenerator extends Generator { final GroovyResolveResult resolveResult = PsiImplUtil.extractUniqueResult(expression.multiResolve(false)); final PsiElement resolved = resolveResult.getElement(); - if (resolved instanceof PsiMethod) { + if (resolved instanceof PsiMethod && + !shouldNotReplaceOperatorWithMethod(lValue.getType(), rValue, expression.getOperationToken())) { if (rValue == null) { rValue = factory.createExpressionFromText("null"); } @@ -439,9 +440,7 @@ public class ExpressionGenerator extends Generator { builder.append(')'); return; } - if (GenerationSettings.dontReplaceOperatorsWithMethodsForNumbers && - (TypesUtil.isNumericType(ltype) && (right == null || TypesUtil.isNumericType(right.getType())) || - op == mPLUS && ltype != null && TypesUtil.isClassType(ltype, CommonClassNames.JAVA_LANG_STRING))) { + if (shouldNotReplaceOperatorWithMethod(ltype, right, op)) { writeSimpleBinaryExpression(token, left, right); return; } @@ -471,6 +470,12 @@ public class ExpressionGenerator extends Generator { } } + private static boolean shouldNotReplaceOperatorWithMethod(PsiType ltype, @Nullable GrExpression right, IElementType op) { + return GenerationSettings.dontReplaceOperatorsWithMethodsForNumbers && + (TypesUtil.isNumericType(ltype) && (right == null || TypesUtil.isNumericType(right.getType())) || + (op == mPLUS || op == mPLUS_ASSIGN) && ltype != null && TypesUtil.isClassType(ltype, CommonClassNames.JAVA_LANG_STRING)); + } + private void writeSimpleBinaryExpression(PsiElement opToken, GrExpression left, GrExpression right) { left.accept(this); builder.append(" "); @@ -501,15 +506,20 @@ public class ExpressionGenerator extends Generator { } } - invokeMethodOn( - ((PsiMethod)resolved), - operand, - GrExpression.EMPTY_ARRAY, - GrNamedArgument.EMPTY_ARRAY, - GrClosableBlock.EMPTY_ARRAY, - resolveResult.getSubstitutor(), - expression - ); + if (operand != null && shouldNotReplaceOperatorWithMethod(operand.getType(), null, expression.getOperationTokenType())) { + writeSimpleUnary(operand, expression, this); + } + else { + invokeMethodOn( + ((PsiMethod)resolved), + operand, + GrExpression.EMPTY_ARRAY, + GrNamedArgument.EMPTY_ARRAY, + GrClosableBlock.EMPTY_ARRAY, + resolveResult.getSubstitutor(), + expression + ); + } } else if (operand != null) { if (postfix) { @@ -546,14 +556,19 @@ public class ExpressionGenerator extends Generator { if (setter == null) return false; final ExpressionGenerator generator = new ExpressionGenerator(new StringBuilder(), context); - generator.invokeMethodOn( - method, - operand, - GrExpression.EMPTY_ARRAY, GrNamedArgument.EMPTY_ARRAY, GrClosableBlock.EMPTY_ARRAY, - resolveResult.getSubstitutor(), - unary - ); + if (shouldNotReplaceOperatorWithMethod(operand.getType(), null, unary.getOperationTokenType())) { + writeSimpleUnary(operand, unary, generator); + } + else { + generator.invokeMethodOn( + method, + operand, + GrExpression.EMPTY_ARRAY, GrNamedArgument.EMPTY_ARRAY, GrClosableBlock.EMPTY_ARRAY, + resolveResult.getSubstitutor(), + unary + ); + } final GrExpression fromText = factory.createExpressionFromText(generator.toString(), unary); invokeMethodOn( setter, @@ -591,13 +606,18 @@ public class ExpressionGenerator extends Generator { else { curBuilder.append(" = "); } - curGenerator.invokeMethodOn( - method, - (GrExpression)operand.copy(), - GrExpression.EMPTY_ARRAY, GrNamedArgument.EMPTY_ARRAY, GrClosableBlock.EMPTY_ARRAY, - resolveResult.getSubstitutor(), - unary - ); + if (shouldNotReplaceOperatorWithMethod(operand.getType(), null, unary.getOperationTokenType())) { + writeSimpleUnary((GrExpression)operand.copy(), unary, curGenerator); + } + else { + curGenerator.invokeMethodOn( + method, + (GrExpression)operand.copy(), + GrExpression.EMPTY_ARRAY, GrNamedArgument.EMPTY_ARRAY, GrClosableBlock.EMPTY_ARRAY, + resolveResult.getSubstitutor(), + unary + ); + } if (shouldInsertParentheses) { curBuilder.append(')'); } @@ -614,6 +634,18 @@ public class ExpressionGenerator extends Generator { return true; } + private static void writeSimpleUnary(GrExpression operand, GrUnaryExpression unary, ExpressionGenerator generator) { + String opTokenText = unary.getOperationToken().getText(); + boolean isPrefix = !(unary instanceof GrPostfixExpression); + if (isPrefix) { + generator.getBuilder().append(opTokenText); + } + operand.accept(generator); + if (!isPrefix) { + generator.getBuilder().append(opTokenText); + } + } + @Override //doesn't visit GrString and regexps public void visitLiteralExpression(GrLiteral literal) { diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamInClosureImplicitReturn.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamInClosureImplicitReturn.java index a6b63433eeff..20ba498edba0 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamInClosureImplicitReturn.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/methodParamInClosureImplicitReturn.java @@ -13,7 +13,7 @@ final groovy.lang.Reference i1 = new groovy.lang.Reference(java.util.Arrays.asList(1, 2, 3)), new groovy.lang.Closure(this, this) { public java.lang.Number doCall(java.lang.Object it) { org.codehaus.groovy.runtime.DefaultGroovyMethods.print(methodParamInClosureImplicitReturn.this, i1.get()); -i1.set(i1.get().plus(1)); +i1.set(i1.get() + 1); return i1.get(); } @@ -25,7 +25,7 @@ return doCall(null); org.codehaus.groovy.runtime.DefaultGroovyMethods.each(new java.util.ArrayList(java.util.Arrays.asList(1, 2, 3)), new groovy.lang.Closure(this, this) { public java.lang.Integer doCall(java.lang.Object it) { org.codehaus.groovy.runtime.DefaultGroovyMethods.print(methodParamInClosureImplicitReturn.this, i1.get()); -i1.set(i1.get().next()); +i1.set(i1.get()++); return i1.get(); } diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInScript.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInScript.java index 5091c1cfaef5..4b81506a473d 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInScript.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/file/refInClosureInScript.java @@ -7,8 +7,8 @@ public java.lang.Object run() { final groovy.lang.Reference foo = new groovy.lang.Reference(2); org.codehaus.groovy.runtime.DefaultGroovyMethods.times(3, new groovy.lang.Closure(this, this) { public void doCall(java.lang.Object it) { -foo.set(foo.get().next()); -foo.set(foo.get().plus(2)); +foo.set(foo.get()++); +foo.set(foo.get() + 2); foo.set(foo.get() - 1); foo.set(4); org.codehaus.groovy.runtime.DefaultGroovyMethods.print(refInClosureInScript.this, foo.get()); From 75a4eac0e08101fe1b2a01f3b2081a7123e2fb19 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Wed, 11 May 2011 15:29:38 +0400 Subject: [PATCH 135/250] GrExpression uml --- .../statements/expressions/GrExpression.uml | 208 ++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrExpression.uml diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrExpression.uml b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrExpression.uml new file mode 100644 index 000000000000..8aad772008e3 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrExpression.uml @@ -0,0 +1,208 @@ + + + JAVA + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression + + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement + org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrInstanceOfExpression + org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrPropertySelection + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrThisSuperReferenceExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrConditionalExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrSuperReferenceExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrRegex + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrTypeCastExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrElvisExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.arithmetic.GrRangeExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBuiltinTypeClassExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrTupleExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrThisReferenceExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrSafeCastExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression + org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrPostfixExpression + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + All + private + + From fd8a40b758e6656165dca7fffc85ca4d3bb108e4 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 11 May 2011 13:33:25 +0200 Subject: [PATCH 136/250] test for IDEA-69430 --- .../intellij/ide/updates/UpdateStrategyTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/platform/platform-impl/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java b/platform/platform-impl/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java index bb40b55aabe5..f60eae12586e 100644 --- a/platform/platform-impl/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java +++ b/platform/platform-impl/testSrc/com/intellij/ide/updates/UpdateStrategyTest.java @@ -81,6 +81,20 @@ public class UpdateStrategyTest extends TestCase { Assert.assertEquals("IntelliJ IDEA X EAP", newChannel.getName()); } + public void testNewChannelWithOlderBuild() { + final TestUpdateSettings settings = new TestUpdateSettings(ChannelStatus.EAP); + //first time load + UpdateStrategy strategy = new UpdateStrategy(10, BuildNumber.fromString("IU-107.80"), UpdatesInfoXppParserTest.InfoReader.read("idea-newChannel.xml"), settings); + + final CheckForUpdateResult result = strategy.checkForUpdates(); + Assert.assertEquals(UpdateStrategy.State.LOADED, result.getState()); + final BuildInfo update = result.getNewBuildInSelectedChannel(); + Assert.assertNull(update); + + final UpdateChannel newChannel = result.getChannelToPropose(); + Assert.assertNull(newChannel); + } + public void testNewChannelAndNewBuildAppear() { //assume user has version 9 eap subscription (default or selected) //and new channels appears - eap of version 10 is there From 66de1f568e7cee703765f76b4f444d9779a50d4a Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 11 May 2011 14:18:46 +0200 Subject: [PATCH 137/250] diagnostics for failing test --- .../com/intellij/xdebugger/XBreakpointManagerTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java index 904f0e2ddf1a..759d2554fade 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XBreakpointManagerTest.java @@ -19,8 +19,10 @@ import com.intellij.xdebugger.breakpoints.SuspendPolicy; import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.XBreakpointAdapter; import com.intellij.xdebugger.breakpoints.XLineBreakpoint; -import org.jetbrains.annotations.NotNull; import org.jdom.Element; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; /** * @author nik @@ -58,7 +60,7 @@ public class XBreakpointManagerTest extends XBreakpointsTestCase { reload(); XBreakpoint[] breakpoints = myBreakpointManager.getAllBreakpoints(); - assertEquals(3, breakpoints.length); + assertEquals("Expected 3 breakpoints, actual: " + Arrays.toString(breakpoints), 3, breakpoints.length); assertTrue(myBreakpointManager.isDefaultBreakpoint(breakpoints[0])); assertEquals("default", assertInstanceOf(breakpoints[0].getProperties(), MyBreakpointProperties.class).myOption); From 8aa18db91e1ec639b4829d19f2b5b31767fa02aa Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 11 May 2011 13:39:03 +0400 Subject: [PATCH 138/250] http://ea.jetbrains.com/browser/ea_problems/27718 --- .../fileEditor/impl/FileDocumentManagerImpl.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java index e7abd37921a3..db7f37dea6e6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java @@ -139,7 +139,7 @@ public class FileDocumentManagerImpl extends FileDocumentManager implements Appl // avoid documents piling up during batch processing if (areTooManyDocumentsInTheQueue(myUnsavedDocuments)) { - saveAllDocuments(); + saveAllDocumentsLater(); } } } @@ -210,6 +210,18 @@ public class FileDocumentManagerImpl extends FileDocumentManager implements Appl myTrailingSpacesStripper.dropAll(); } + private void saveAllDocumentsLater() { + // later because some document might have been blocked by PSI right now + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + if (!ApplicationManager.getApplication().isDisposed()) { + saveAllDocuments(); + } + } + }); + } + public void saveAllDocuments() { ApplicationManager.getApplication().assertIsDispatchThread(); From 8b2a300ab058078f07280a0b443fadbc31c575fb Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 11 May 2011 14:20:04 +0400 Subject: [PATCH 139/250] optimisation: visit only overlapping highlighters during paint --- .../injected/editor/MarkupModelWindow.java | 16 +- .../openapi/editor/ex/MarkupModelEx.java | 18 +- .../impl/EditorGutterComponentImpl.java | 35 +-- .../openapi/editor/impl/EmptyMarkupModel.java | 8 +- .../openapi/editor/impl/IntervalTree.java | 2 +- .../openapi/editor/impl/IntervalTreeImpl.java | 221 ++++++++++-------- .../openapi/editor/impl/IterationState.java | 14 +- .../openapi/editor/impl/MarkupModelImpl.java | 8 +- 8 files changed, 171 insertions(+), 151 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/injected/editor/MarkupModelWindow.java b/platform/lang-impl/src/com/intellij/injected/editor/MarkupModelWindow.java index e681c577d784..6afa8d6b6d18 100644 --- a/platform/lang-impl/src/com/intellij/injected/editor/MarkupModelWindow.java +++ b/platform/lang-impl/src/com/intellij/injected/editor/MarkupModelWindow.java @@ -23,7 +23,6 @@ import com.intellij.openapi.editor.impl.event.MarkupModelListener; import com.intellij.openapi.editor.markup.HighlighterTargetArea; import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.TextAttributes; -import com.intellij.openapi.editor.impl.Interval; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.util.ProperTextRange; @@ -130,18 +129,15 @@ class MarkupModelWindow extends UserDataHolderBase implements MarkupModelEx { return false; } - public Iterator iterator() { - // todo - return null; + @NotNull + @Override + public Iterator overlappingIterator(int startOffset, int endOffset) { + // todo convert + return myHostModel.overlappingIterator(startOffset, endOffset); } - @NotNull - public Iterator iteratorFrom(@NotNull Interval interval) { - // todo convert - return myHostModel.iteratorFrom(interval); - } public boolean sweep(int start, int end, @NotNull SweepProcessor sweepProcessor) { // todo convert return myHostModel.sweep(start, end, sweepProcessor); } -} \ No newline at end of file +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/MarkupModelEx.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/MarkupModelEx.java index 21801c1691b3..7f87859f38c6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/MarkupModelEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/MarkupModelEx.java @@ -15,7 +15,6 @@ */ package com.intellij.openapi.editor.ex; -import com.intellij.openapi.editor.impl.Interval; import com.intellij.openapi.editor.impl.event.MarkupModelListener; import com.intellij.openapi.editor.markup.HighlighterTargetArea; import com.intellij.openapi.editor.markup.MarkupModel; @@ -31,7 +30,7 @@ import java.util.Iterator; /** * @author max */ -public interface MarkupModelEx extends MarkupModel, Iterable { +public interface MarkupModelEx extends MarkupModel { void dispose(); RangeHighlighter addPersistentLineHighlighter(int lineNumber, int layer, TextAttributes textAttributes); @@ -43,17 +42,18 @@ public interface MarkupModelEx extends MarkupModel, Iterable void setRangeHighlighterAttributes(@NotNull RangeHighlighter highlighter, TextAttributes textAttributes); boolean processHighlightsOverlappingWith(int start, int end, @NotNull Processor processor); + @NotNull - Iterator iteratorFrom(@NotNull Interval interval); + Iterator overlappingIterator(int startOffset, int endOffset); // optimization: creates highlighter and fires only one event: highlighterCreated RangeHighlighterEx addRangeHighlighterAndChangeAttributes(int startOffset, - int endOffset, - int layer, - TextAttributes textAttributes, - @NotNull HighlighterTargetArea targetArea, - boolean isPersistent, - Consumer changeAttributesAction); + int endOffset, + int layer, + TextAttributes textAttributes, + @NotNull HighlighterTargetArea targetArea, + boolean isPersistent, + Consumer changeAttributesAction); // runs change attributes action and fires highlighterChanged event if there were changes void changeAttributesInBatch(@NotNull RangeHighlighterEx highlighter, @NotNull Consumer changeAttributesAction); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java index 61907a85524c..c587297d2ada 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java @@ -377,18 +377,23 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse void process(RangeHighlighter highlighter); } - private void processRangeHighlighters(RangeHighlighterProcessor processor, int startOffset, int endOffset) { - final MarkupModelEx docMarkup = (MarkupModelEx)myEditor.getDocument().getMarkupModel(myEditor.getProject()); - Iterator docHighlighters = docMarkup.iterator(); + private void processRangeHighlighters(int startOffset, int endOffset, RangeHighlighterProcessor processor) { + Document document = myEditor.getDocument(); + final MarkupModelEx docMarkup = (MarkupModelEx)document.getMarkupModel(myEditor.getProject()); + // we limit highlighters to process to between line starting at startOffset and line ending at endOffset + int docLength = document.getTextLength(); + int patchedStartOffset = startOffset < docLength ? document.getLineStartOffset(document.getLineNumber(startOffset)) : docLength; + int patchedEndOffset = endOffset <= docLength ? document.getLineEndOffset(document.getLineNumber(endOffset)) + 1 : docLength; + Iterator docHighlighters = docMarkup.overlappingIterator(patchedStartOffset, patchedEndOffset); final MarkupModelEx editorMarkup = (MarkupModelEx)myEditor.getMarkupModel(); - Iterator editorHighlighters = editorMarkup.iterator(); + Iterator editorHighlighters = editorMarkup.overlappingIterator(startOffset, endOffset); RangeHighlighterEx lastDocHighlighter = null; RangeHighlighterEx lastEditorHighlighter = null; while (true) { - if (lastDocHighlighter == null && docHighlighters != null && docHighlighters.hasNext()) { + if (lastDocHighlighter == null && docHighlighters.hasNext()) { lastDocHighlighter = docHighlighters.next(); if (!lastDocHighlighter.isValid() || lastDocHighlighter.getAffectedAreaStartOffset() > endOffset) { lastDocHighlighter = null; @@ -396,12 +401,11 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse } if (lastDocHighlighter.getAffectedAreaEndOffset() < startOffset) { lastDocHighlighter = null; - //docHighlighters = null; continue; } } - if (lastEditorHighlighter == null && editorHighlighters != null && editorHighlighters.hasNext()) { + if (lastEditorHighlighter == null && editorHighlighters.hasNext()) { lastEditorHighlighter = editorHighlighters.next(); if (!lastEditorHighlighter.isValid() || lastEditorHighlighter.getAffectedAreaStartOffset() > endOffset) { lastEditorHighlighter = null; @@ -409,7 +413,6 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse } if (lastEditorHighlighter.getAffectedAreaEndOffset() < startOffset) { lastEditorHighlighter = null; - //editorHighlighters = null; continue; } } @@ -431,10 +434,10 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse if (!lowerHighlighter.isValid()) continue; int startLineIndex = lowerHighlighter.getDocument().getLineNumber(startOffset); - if (startLineIndex < 0 || startLineIndex >= myEditor.getDocument().getLineCount()) continue; + if (startLineIndex < 0 || startLineIndex >= document.getLineCount()) continue; int endLineIndex = lowerHighlighter.getDocument().getLineNumber(endOffset); - if (endLineIndex < 0 || endLineIndex >= myEditor.getDocument().getLineCount()) continue; + if (endLineIndex < 0 || endLineIndex >= document.getLineCount()) continue; if (lowerHighlighter.getEditorFilter().avaliableIn(myEditor)) { processor.process(lowerHighlighter); @@ -487,7 +490,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse private void calcIconAreaWidth() { myLineToGutterRenderers = new TIntObjectHashMap>(); - processRangeHighlighters(new RangeHighlighterProcessor() { + processRangeHighlighters(0, myEditor.getDocument().getTextLength(), new RangeHighlighterProcessor() { public void process(RangeHighlighter highlighter) { GutterIconRenderer renderer = highlighter.getGutterIconRenderer(); if (renderer == null) return; @@ -505,7 +508,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse renderers.add(renderer); } } - }, 0, myEditor.getDocument().getTextLength()); + }); myIconsAreaWidth = START_ICON_AREA_WIDTH; @@ -534,11 +537,11 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse Object hint = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); try { - processRangeHighlighters(new RangeHighlighterProcessor() { + processRangeHighlighters(firstVisibleOffset, lastVisibleOffset, new RangeHighlighterProcessor() { public void process(RangeHighlighter highlighter) { paintLineMarkerRenderer(highlighter, g); } - }, firstVisibleOffset, lastVisibleOffset); + }); } finally { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, hint); @@ -1199,7 +1202,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse int lastVisibleOffset = myEditor.logicalPositionToOffset( myEditor.xyToLogicalPosition(new Point(0, clip.y + clip.height + myEditor.getLineHeight()))); - processRangeHighlighters(new RangeHighlighterProcessor() { + processRangeHighlighters(firstVisibleOffset, lastVisibleOffset, new RangeHighlighterProcessor() { public void process(RangeHighlighter highlighter) { if (gutterRenderer[0] != null) return; Rectangle rectangle = getLineRendererRectangle(highlighter); @@ -1218,7 +1221,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse } } } - }, firstVisibleOffset, lastVisibleOffset); + }); return gutterRenderer[0]; } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EmptyMarkupModel.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EmptyMarkupModel.java index 9c7fea62df50..0fd18a8a5615 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EmptyMarkupModel.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EmptyMarkupModel.java @@ -106,14 +106,12 @@ public class EmptyMarkupModel implements MarkupModelEx { return false; } - public Iterator iterator() { + @NotNull + @Override + public Iterator overlappingIterator(int startOffset, int endOffset) { return ContainerUtil.emptyIterator(); } - @NotNull - public Iterator iteratorFrom(@NotNull Interval interval) { - return iterator(); - } public boolean sweep(int start, int end, @NotNull SweepProcessor sweepProcessor) { return false; } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IntervalTree.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IntervalTree.java index 2225a43bd179..8e3f6d0966cf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IntervalTree.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IntervalTree.java @@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull; /** * User: cdr */ -public interface IntervalTree extends Iterable { +public interface IntervalTree { boolean process(@NotNull Processor processor); boolean processOverlappingWith(int start, int end, @NotNull Processor processor); boolean processOverlappingWith(int offset, @NotNull Processor processor); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java index bdf8679ff91e..cd8adc5c54ca 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java @@ -25,10 +25,7 @@ import gnu.trove.TLongHashSet; import org.jetbrains.annotations.NotNull; import java.lang.ref.ReferenceQueue; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; +import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; @@ -37,16 +34,15 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; /** * User: cdr */ -public abstract class IntervalTreeImpl extends RedBlackTree implements IntervalTree { +public abstract class IntervalTreeImpl extends RedBlackTree implements IntervalTree/*, Iterable*/{ private int keySize; // number of all intervals, counting all duplicates, some of them maybe gced protected final ReadWriteLock l = new ReentrantReadWriteLock(); - private IntervalNode minNode; // left most node in the tree protected abstract EqualStartIntervalComparator getComparator(); private final ReferenceQueue myReferenceQueue = new ReferenceQueue(); private int deadReferenceCount; - protected class IntervalNode extends Node implements MutableInterval { + protected class IntervalNode extends RedBlackTree.Node implements MutableInterval { private volatile int myStart; private volatile int myEnd; private volatile boolean isValid = true; @@ -314,6 +310,121 @@ public abstract class IntervalTreeImpl extends RedBla } } + @NotNull + Iterator overlappingIterator(final int startOffset, final int endOffset) { + final IntervalNode firstOverlap = findMinOverlappingWith(getRoot(), new TextRangeInterval(startOffset, endOffset), modCount, 0); + if (firstOverlap == null) { + return ContainerUtil.emptyIterator(); + } + normalize(); + final int modCountBefore = modCount; + return new Iterator() { + IntervalNode currentNode = firstOverlap; + int[] deltaUpToRootExclusive = {0}; + private int indexInCurrentList = 0; + T current; + + @Override + public boolean hasNext() { + if (current != null) return true; + if (currentNode == null) return false; + + if (modCount != modCountBefore) throw new ConcurrentModificationException(); + while (indexInCurrentList != currentNode.intervals.size()) { + T t = currentNode.intervals.get(indexInCurrentList++).get(); + if (t != null) { + current = t; + return true; + } + } + indexInCurrentList = 0; + while (true) { + currentNode = nextNode(currentNode, startOffset, endOffset, deltaUpToRootExclusive); + if (currentNode == null) { + return false; + } + if (overlaps(currentNode, startOffset, endOffset, deltaUpToRootExclusive[0])) { + assert currentNode.intervalStart() >= firstOverlap.intervalStart(); + indexInCurrentList = 0; + while (indexInCurrentList != currentNode.intervals.size()) { + T t = currentNode.intervals.get(indexInCurrentList++).get(); + if (t != null) { + current = t; + return true; + } + } + indexInCurrentList = 0; + } + } + } + + @Override + public T next() { + if (!hasNext()) throw new NoSuchElementException(); + T t = current; + current = null; + return t; + } + + @Override + public void remove() { + throw new IncorrectOperationException(); + } + }; + } + + private boolean overlaps(IntervalNode root, + int startOffset, int endOffset, + int deltaUpToRootExclusive) { + if (root == null) return false; + int delta = root.delta + deltaUpToRootExclusive; + int start = root.intervalStart() + delta; + int end = root.intervalEnd() + delta; + return Math.max(start, startOffset) <= Math.min(end, endOffset); + } + + private IntervalNode nextNode(@NotNull IntervalNode root, + int startOffset, int endOffset, + @NotNull int[] newDeltaUpToRootExclusive) { + assert root.isValid(); + int deltaUpToRootExclusive = newDeltaUpToRootExclusive[0]; + int delta = deltaUpToRootExclusive + root.delta; + //int myStartOffset = root.intervalStart() + delta; + //int myEndOffset = root.intervalEnd() + delta; + int myMaxEnd = maxEndOf(root, deltaUpToRootExclusive); + assert startOffset <= myMaxEnd; + + // try to go right down + IntervalNode right = root.getRight(); + if (right != null) { + int rightMaxEnd = maxEndOf(right, delta); + if (startOffset <= rightMaxEnd) { + int rightDelta = delta + right.delta; + while (right.getLeft() != null && startOffset <= maxEndOf(right.getLeft(), rightDelta)) { + right = right.getLeft(); + rightDelta += right.delta; + } + newDeltaUpToRootExclusive[0] = rightDelta - right.delta; + return right; + } + } + + // go up + while (true) { + IntervalNode parent = root.getParent(); + if (parent == null) return null; + if (parent.intervalStart() + deltaUpToRootExclusive > endOffset) return null; // can't move right + deltaUpToRootExclusive -= parent.delta; + + if (parent.getLeft() == root) { + newDeltaUpToRootExclusive[0] = deltaUpToRootExclusive; + return parent; + } + + root = parent; + } + } + private boolean processOverlapping(IntervalNode root, int offset, Processor processor, @@ -355,7 +466,7 @@ public abstract class IntervalTreeImpl extends RedBla node.setLeft(null); node.setRight(null); - List gced = new ArrayList(); + List gced = new SmartList(); if (root == null) { root = node; } @@ -387,7 +498,6 @@ public abstract class IntervalTreeImpl extends RedBla node.delta = -delta; node.setParent(current); } - linkNode(node); correctMaxUp(node); onInsertNode(); assertUnderWriteLock(); @@ -399,29 +509,6 @@ public abstract class IntervalTreeImpl extends RedBla return node; } - private void linkNode(@NotNull IntervalNode node) { - IntervalNode previous = previous(node); - if (previous == null) { - node.next = minNode; - minNode = node; - } - else { - node.next = previous.next; - previous.next = node; - } - } - - private void unlinkNode(@NotNull IntervalNode node) { - IntervalNode previous = previous(node); - if (previous == null) { - minNode = node.next; - } - else { - previous.next = node.next; - } - node.next = null; - } - // finds previous in the in-order traversal private IntervalNode previous(@NotNull IntervalNode node) { IntervalNode left = node.getLeft(); @@ -447,7 +534,6 @@ public abstract class IntervalTreeImpl extends RedBla for (IntervalNode node : collectedAway) { removeNode(node); } - checkMax(true); } finally { l.writeLock().unlock(); @@ -493,10 +579,6 @@ public abstract class IntervalTreeImpl extends RedBla assert nodeSize() == nodeCounter.get() : "node size: "+ nodeSize() +"; actual: "+nodeCounter; assert keySize == keyCounter.get() : "key size: "+ keySize +"; actual: "+keyCounter; assert keySize >= nodeSize() : keySize + "; "+nodeSize(); - - IntervalNode left = getRoot(); - while (left != null && left.getLeft() != null) left = left.getLeft(); - assert minNode == left; } return allValid.get(); } @@ -640,7 +722,6 @@ public abstract class IntervalTreeImpl extends RedBla assertUnderWriteLock(); IntervalNode node = (IntervalNode)n; pushDeltaFromRoot(node); - unlinkNode(node); super.deleteNode(n); @@ -744,6 +825,7 @@ public abstract class IntervalTreeImpl extends RedBla if (r2 != null) r2.setParent(n1); } + // returns real max endOffset of all intervals below private int maxEndOf(IntervalNode node, int deltaUpToRootExclusive) { if (node == null) { return 0; @@ -751,6 +833,7 @@ public abstract class IntervalTreeImpl extends RedBla if (node.isValid()) { return node.maxEnd + node.delta + deltaUpToRootExclusive; } + // since node is invalid, ignore node.delta return Math.max(maxEndOf(node.getLeft(), deltaUpToRootExclusive), maxEndOf(node.getRight(), deltaUpToRootExclusive)); } @@ -831,14 +914,6 @@ public abstract class IntervalTreeImpl extends RedBla } } - public Iterator iterator() { - IntervalNode firstNode = minNode; - if (firstNode == null) { - return ContainerUtil.emptyIterator(); - } - return createIteratorFrom(firstNode); - } - private IntervalNode findMinOverlappingWith(IntervalNode root, Interval interval, int modCountBefore, int deltaUpToRootExclusive) { if (root == null) { return null; @@ -865,59 +940,7 @@ public abstract class IntervalTreeImpl extends RedBla return findMinOverlappingWith(root.getRight(), interval, modCountBefore, delta); } - @NotNull - Iterator iteratorFrom(@NotNull Interval interval) { - IntervalNode firstOverlap = findMinOverlappingWith(getRoot(), interval, modCount, 0); - if (firstOverlap == null) { - return ContainerUtil.emptyIterator(); - } - return createIteratorFrom(firstOverlap); - } - - private Iterator createIteratorFrom(@NotNull final IntervalNode firstNode) { - checkMax(true); - normalize(); - - final int modCountBefore = modCount; - return new Iterator() { - private IntervalNode node = firstNode; - private int indexInCurrentList = 0; - T current; - - public boolean hasNext() { - if (current != null) return true; - while (node != null) { - while (indexInCurrentList != node.intervals.size()) { - current = node.intervals.get(indexInCurrentList).get(); - if (current != null) return true; - indexInCurrentList++; - } - indexInCurrentList = 0; - node = node.next; - } - return false; - } - - public T next() { - assert modCount == modCountBefore : "Must not modify range markers during iterate"; - if (!hasNext()) throw new NoSuchElementException(); - - T t = current; - current = null; - - indexInCurrentList++; - return t; - } - - - public void remove() { - throw new IncorrectOperationException(); - } - }; - } - protected volatile boolean normalized = true; - public void normalize() { if (normalized) return; try { @@ -982,13 +1005,13 @@ public abstract class IntervalTreeImpl extends RedBla List gced = new ArrayList(); collectGced(getRoot(), gced); deleteNodes(gced); + checkMax(true); } @Override public void clear() { super.clear(); keySize = 0; - minNode = null; } private void collectGced(IntervalNode root, List gced) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java index a321ef03b5ed..93aff891a42e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java @@ -120,13 +120,17 @@ public final class IterationState { private Iterator myIterator; private void init(MarkupModelEx markupModel, int start) { - myIterator = markupModel.iteratorFrom(new TextRangeInterval(start, myDocument.getTextLength())); - + myIterator = markupModel.overlappingIterator(start, myDocument.getTextLength()); + int skipped = 0; while (myIterator.hasNext()) { - myNextHighlighter = myIterator.next(); - if (!skipHighlighter(myNextHighlighter)) break; - else myNextHighlighter = null; + RangeHighlighterEx highlighter = myIterator.next(); + if (!skipHighlighter(highlighter)) { + myNextHighlighter = highlighter; + break; + } + skipped++; } + int i = skipped; } private void advance() { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java index 520c16ae5868..fef5de229164 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java @@ -231,13 +231,9 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx return myHighlighterTree.processOverlappingWith(start, end, processor); } - public Iterator iterator() { - return myHighlighterTree.iterator(); - } - @NotNull - public Iterator iteratorFrom(@NotNull Interval interval) { - return myHighlighterTree.iteratorFrom(interval); + public Iterator overlappingIterator(int startOffset, int endOffset) { + return myHighlighterTree.overlappingIterator(startOffset, endOffset); } public boolean sweep(int start, int end, @NotNull SweepProcessor sweepProcessor) { From 92e1e91560032a077fe0881a72d8087bbcc8caed Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 11 May 2011 14:31:49 +0400 Subject: [PATCH 140/250] fixed excessive VFS load and assertion added in tests for accessing VFS outside the project roots --- .../openapi/vfs/LocalFileSystemTest.java | 47 ++++--- .../impl/providers/FileReference.java | 34 +++-- .../history/integration/IdeaGateway.java | 3 +- .../vfs/impl/local/LocalFileSystemBase.java | 3 +- .../vfs/newvfs/impl/VirtualDirectoryImpl.java | 125 ++++++++++++++++++ .../vfs/newvfs/persistent/PersistentFS.java | 6 + 6 files changed, 193 insertions(+), 25 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/openapi/vfs/LocalFileSystemTest.java b/java/java-tests/testSrc/com/intellij/openapi/vfs/LocalFileSystemTest.java index 017070824b74..873da529c22b 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/vfs/LocalFileSystemTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/vfs/LocalFileSystemTest.java @@ -1,6 +1,7 @@ package com.intellij.openapi.vfs; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.impl.win32.Win32LocalFileSystem; @@ -19,6 +20,22 @@ import java.util.Arrays; public class LocalFileSystemTest extends IdeaTestCase{ private static final String KEY = "filesystem.useNative"; + public static void setContentOnDisk(File file, byte[] bom, String content, Charset charset) throws IOException { + FileOutputStream stream = new FileOutputStream(file); + stream.write(bom); + OutputStreamWriter writer = new OutputStreamWriter(stream, charset); + writer.write(content); + writer.close(); + } + + public static VirtualFile createTempFile(@NonNls String ext, byte[] bom, @NonNls String content, Charset charset) throws IOException { + File temp = FileUtil.createTempFile("copy", "." + ext); + setContentOnDisk(temp, bom, content, charset); + + myFilesToDelete.add(temp); + return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(temp); + } + public void testChildrenAccessedButNotCached() throws Exception{ ApplicationManager.getApplication().runWriteAction( new Runnable() { @@ -116,7 +133,7 @@ public class LocalFileSystemTest extends IdeaTestCase{ new Runnable() { @Override public void run() { - try{ + try { File fromDir = createTempDirectory(); File toDir = createTempDirectory(); @@ -132,7 +149,7 @@ public class LocalFileSystemTest extends IdeaTestCase{ assertEquals(newName, copy.getName()); assertTrue(Arrays.equals(byteContent, copy.contentsToByteArray())); } - catch(Exception e){ + catch (Exception e) { LOG.error(e); } } @@ -222,22 +239,22 @@ public class LocalFileSystemTest extends IdeaTestCase{ } } ); - } - public static void setContentOnDisk(File file, byte[] bom, String content, Charset charset) throws IOException { - FileOutputStream stream = new FileOutputStream(file); - stream.write(bom); - OutputStreamWriter writer = new OutputStreamWriter(stream, charset); - writer.write(content); - writer.close(); - } + public void testFindRoot() { + VirtualFile file = LocalFileSystem.getInstance().findFileByPath("wrong_path"); + assertNull(file); - public static VirtualFile createTempFile(@NonNls String ext, byte[] bom, @NonNls String content, Charset charset) throws IOException { - File temp = FileUtil.createTempFile("copy", "." + ext); - setContentOnDisk(temp, bom, content, charset); + if (SystemInfo.isWindows && new File("c:").exists()) { + VirtualFile root = LocalFileSystem.getInstance().findFileByPath("c:"); + assertNotNull(root); + } + if (SystemInfo.isUnix) { + VirtualFile root = LocalFileSystem.getInstance().findFileByPath("/"); + assertNotNull(root); + } - myFilesToDelete.add(temp); - return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(temp); + VirtualFile root = LocalFileSystem.getInstance().findFileByPath(""); + assertNotNull(root); } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReference.java b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReference.java index 7a1a1ad63a57..1d08029f39ab 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReference.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReference.java @@ -30,6 +30,8 @@ import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileSystem; +import com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem; import com.intellij.psi.*; import com.intellij.psi.impl.PsiManagerImpl; import com.intellij.psi.impl.source.resolve.ResolveCache; @@ -193,21 +195,37 @@ public class FileReference implements FileReferenceOwner, PsiPolyVariantReferenc else { final String decoded = decode(text); if (decoded != null) { - processVariants(context, new PsiFileSystemItemProcessor() { - public boolean acceptItem(String name, boolean isDirectory) { - return caseSensitive ? decoded.equals(name) : decoded.compareToIgnoreCase(name) == 0; + if (context instanceof PsiDirectory && caseSensitivityApplies((PsiDirectory)context, caseSensitive)) { + // optimization: do not load all children into VFS + PsiDirectory directory = (PsiDirectory)context; + PsiFileSystemItem child = directory.findFile(decoded); + if (child == null) child = directory.findSubdirectory(decoded); + if (child != null) { + result.add(new PsiElementResolveResult(getOriginalFile(child))); } + } + else { + processVariants(context, new PsiFileSystemItemProcessor() { + public boolean acceptItem(String name, boolean isDirectory) { + return caseSensitive ? decoded.equals(name) : decoded.compareToIgnoreCase(name) == 0; + } - public boolean execute(PsiFileSystemItem element) { - result.add(new PsiElementResolveResult(getOriginalFile(element))); - return true; - } - }); + public boolean execute(PsiFileSystemItem element) { + result.add(new PsiElementResolveResult(getOriginalFile(element))); + return true; + } + }); + } } } } } + private static boolean caseSensitivityApplies(PsiDirectory context, boolean caseSensitive) { + VirtualFileSystem fs = context.getVirtualFile().getFileSystem(); + return fs instanceof NewVirtualFileSystem && ((NewVirtualFileSystem)fs).isCaseSensitive() == caseSensitive; + } + private boolean isAllowedEmptyPath(String text) { return text.length() == 0 && isLast() && (StringUtil.isEmpty(myFileReferenceSet.getPathString()) && myFileReferenceSet.isEmptyPathAllowed() || diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/IdeaGateway.java b/platform/lvcs-impl/src/com/intellij/history/integration/IdeaGateway.java index ad5b0dd2c54e..c7392ff3de74 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/IdeaGateway.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/IdeaGateway.java @@ -139,7 +139,8 @@ public class IdeaGateway { public static Iterable iterateDBChildren(VirtualFile f) { if (!(f instanceof NewVirtualFile)) return ContainerUtil.emptyIterable(); - return ((NewVirtualFile)f).iterInDbChildren(); + NewVirtualFile nf = (NewVirtualFile)f; + return nf.getCachedChildren(); } public RootEntry createTransientRootEntry() { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java index d768f5f296c6..a3fb84989b0f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java @@ -20,6 +20,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.ex.VirtualFileManagerEx; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; @@ -126,7 +127,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem { } public boolean exists(@NotNull final VirtualFile fileOrDirectory) { - if (fileOrDirectory.getParent() == null) return true; + if (StringUtil.isEmpty(fileOrDirectory.getPath())) return true; // fake top dir for Windows return convertToIOFile(fileOrDirectory).exists(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java index c78b7965e0ff..43c91a765c8c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java @@ -19,8 +19,25 @@ */ package com.intellij.openapi.vfs.newvfs.impl; +import com.intellij.openapi.application.Application; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.application.impl.ApplicationImpl; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.roots.OrderEntry; +import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.JarFileSystem; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; import com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem; @@ -28,6 +45,8 @@ import com.intellij.openapi.vfs.newvfs.RefreshQueue; import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent; import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; import com.intellij.util.ArrayUtil; +import com.intellij.util.PathUtil; +import com.intellij.util.SystemProperties; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.CaseInsensitiveStringHashingStrategy; import gnu.trove.THashMap; @@ -36,14 +55,18 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.URISyntaxException; +import java.net.URL; import java.util.*; public class VirtualDirectoryImpl extends VirtualFileSystemEntry { private static final VirtualFileSystemEntry NULL_VIRTUAL_FILE = new VirtualFileImpl("*?;%NULL", null, -42); private final NewVirtualFileSystem myFS; + private static final boolean IS_UNIT_TESTS = ApplicationManager.getApplication().isUnitTestMode(); // guarded by this private Object myChildren; // Either HashMap or VFile[] @@ -141,6 +164,7 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { } else { child = new VirtualFileImpl(name, this, id); + assertAccessInTests(child); } if (fs.markNewFilesAsDirty()) { @@ -150,6 +174,107 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { return child; } + private static void assertAccessInTests(VirtualFileSystemEntry child) { + if (IS_UNIT_TESTS && ApplicationManager.getApplication() instanceof ApplicationImpl && ((ApplicationImpl)ApplicationManager.getApplication()).isComponentsCreated()) { + NewVirtualFileSystem fileSystem = child.getFileSystem(); + if (fileSystem != LocalFileSystem.getInstance() && fileSystem != JarFileSystem.getInstance()) { + return; + } + // root' children are loaded always + if (child.getParent() == null || child.getParent().getParent() == null) return; + + Set allowed = allowedRoots(); + boolean isUnder = allowed == null; + if (!isUnder) { + for (String root : allowed) { + String childPath = child.getPath(); + if (child.getFileSystem() == JarFileSystem.getInstance()) { + VirtualFile local = JarFileSystem.getInstance().getVirtualFileForJar(child); + childPath = local.getPath(); + } + if (FileUtil.startsWith(childPath, root)) { + isUnder = true; + break; + } + if (root.startsWith(JarFileSystem.PROTOCOL_PREFIX)) { + String rootLocalPath = FileUtil.toSystemIndependentName(PathUtil.toPresentableUrl(root)); + isUnder = FileUtil.startsWith(childPath, rootLocalPath); + if (isUnder) break; + } + } + } + + if (!isUnder) { + if (!allowed.isEmpty()) { + assert false : "File accessed outside project: " + child +"; project roots: "+new ArrayList(allowed); + } + } + } + } + + // null means we were unable to get roots, so do not check access + private static Set allowedRoots() { + if (insideGettingRoots) return null; + Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); + if (openProjects.length == 0) return null; + Set allowed = new THashSet(); + String homePath = PathManager.getHomePath(); + allowed.add(FileUtil.toSystemIndependentName(homePath)); + try { + URL outUrl = Application.class.getResource("/"); + String output = new File(outUrl.toURI()).getParentFile().getParentFile().getPath(); + allowed.add(FileUtil.toSystemIndependentName(output)); + } + catch (URISyntaxException ignored) { + } + String javaHome = SystemProperties.getJavaHome(); + allowed.add(FileUtil.toSystemIndependentName(javaHome)); + String tempDirectorySpecific = new File(FileUtil.getTempDirectory()).getParent(); + allowed.add(FileUtil.toSystemIndependentName(tempDirectorySpecific)); + String tempDirectory = System.getProperty("java.io.tmpdir"); + allowed.add(FileUtil.toSystemIndependentName(tempDirectory)); + String home = SystemProperties.getUserHome(); + allowed.add(FileUtil.toSystemIndependentName(home)); + for (Project project : openProjects) { + if (!project.isInitialized()) { + return null; // all is allowed + } + for (VirtualFile root : ProjectRootManager.getInstance(project).getContentRoots()) { + allowed.add(root.getPath()); + } + for (VirtualFile root : getAllRoots(project)) { + allowed.add(StringUtil.trimEnd(root.getPath(), JarFileSystem.JAR_SEPARATOR)); + } + String location = project.getLocation(); + allowed.add(FileUtil.toSystemIndependentName(location)); + } + + return allowed; + } + + private static boolean insideGettingRoots; + private static VirtualFile[] getAllRoots(Project project) { + insideGettingRoots = true; + Set roots = new THashSet(); + final Module[] modules = ModuleManager.getInstance(project).getModules(); + for (Module module : modules) { + final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); + final OrderEntry[] orderEntries = moduleRootManager.getOrderEntries(); + for (OrderEntry entry : orderEntries) { + VirtualFile[] files; + files = entry.getFiles(OrderRootType.CLASSES); + ContainerUtil.addAll(roots, files); + files = entry.getFiles(OrderRootType.SOURCES); + ContainerUtil.addAll(roots, files); + files = entry.getFiles(OrderRootType.CLASSES_AND_OUTPUT); + ContainerUtil.addAll(roots, files); + } + } + insideGettingRoots = false; + return VfsUtil.toVirtualFileArray(roots); + } + + @Nullable private VirtualFileSystemEntry createAndFindChildWithEventFire(@NotNull String name) { final NewVirtualFileSystem delegate = getFileSystem(); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java index 733c712b36a5..1ba65d511e62 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java @@ -688,6 +688,12 @@ public class PersistentFS extends ManagingFS implements ApplicationComponent { public VirtualFile[] getChildren() { return getRoots(fs); } + + @Override + public VirtualFileSystemEntry findChild(@NotNull String name) { + if (name.length() == 0) return null; + return findRoot(name, fs); + } }; } if (!fs.exists(root)) return null; From d37218862981056b2d43a0851cac474cc6028ec8 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Wed, 11 May 2011 16:57:23 +0400 Subject: [PATCH 141/250] Balloon UI: find enclosing balloon api --- .../com/intellij/openapi/ui/popup/Balloon.java | 2 ++ .../openapi/ui/popup/JBPopupFactory.java | 3 +++ .../src/com/intellij/ui/BalloonImpl.java | 2 ++ .../com/intellij/ui/popup/PopupFactoryImpl.java | 17 +++++++++++++++++ 4 files changed, 24 insertions(+) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/Balloon.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/Balloon.java index a40cf411edf1..aadb7e8aaca9 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/Balloon.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/Balloon.java @@ -29,6 +29,8 @@ import java.awt.Rectangle; */ public interface Balloon extends Disposable { + String KEY = "Balloon.property"; + void show(PositionTracker tracker, Position preferredPosition); void show(RelativePoint target, Position preferredPosition); diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopupFactory.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopupFactory.java index ccb083ee4cd3..36563d57e6cb 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopupFactory.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopupFactory.java @@ -263,4 +263,7 @@ public abstract class JBPopupFactory { public abstract JBPopup createMessage(String text); + @Nullable + public abstract Balloon getParentBalloonFor(@Nullable Component c); + } diff --git a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java index 9ed3dfa8fa03..37e8b8f8b16e 100644 --- a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java @@ -1125,6 +1125,8 @@ public class BalloonImpl implements Disposable, Balloon, LightweightWindow, Posi setLayout(null); myBalloon = balloon; + setFocusCycleRoot(true); + putClientProperty(Balloon.KEY, BalloonImpl.this); myContent = new JPanel(new BorderLayout(2, 2)); Wrapper contentWrapper = new Wrapper(content); diff --git a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java index 1242748a288f..701feb2e7132 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java @@ -77,6 +77,23 @@ public class PopupFactoryImpl extends JBPopupFactory { return createListPopup(new BaseListPopupStep(null, new String[]{text})); } + @Override + public Balloon getParentBalloonFor(@Nullable Component c) { + if (c == null) return null; + Component eachParent = c; + while (eachParent != null) { + if (eachParent instanceof JComponent) { + Object balloon = ((JComponent)eachParent).getClientProperty(Balloon.KEY); + if (balloon instanceof Balloon) { + return (Balloon)balloon; + } + } + eachParent = eachParent.getParent(); + } + + return null; + } + public ListPopup createConfirmation(String title, final String yesText, String noText, final Runnable onYes, final Runnable onNo, int defaultOptionIndex) { final BaseListPopupStep step = new BaseListPopupStep(title, new String[]{yesText, noText}) { From e5804ef5c3b1c3640354bf2d966c2c50b5eedd06 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Wed, 11 May 2011 14:57:58 +0200 Subject: [PATCH 142/250] AppCode:Project Model: allow absent fileRef in PBXBuildFile --- .../execution/testframework/sm/runner/SMTestProxy.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java index 5a896c2db8d1..439d85b628c6 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java @@ -15,7 +15,7 @@ */ package com.intellij.execution.testframework.sm.runner; -import com.google.common.collect.Lists; +//import com.google.common.collect.Lists; import com.intellij.execution.Location; import com.intellij.execution.testframework.AbstractTestProxy; import com.intellij.execution.testframework.Filter; @@ -339,7 +339,7 @@ public class SMTestProxy extends AbstractTestProxy { public List collectChildren() { final List allChildren = getChildren(); - final List result = Lists.newArrayList(); + final List result = null;//Lists.newArrayList(); result.addAll(allChildren); From b347fb1af9f06d6c36f56c3cc43f842042189f89 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Wed, 11 May 2011 16:58:19 +0400 Subject: [PATCH 143/250] inplace refactoring balloons: ux fixes for mac --- .../InplaceIntroduceConstantPopup.java | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java index ac814659dcc8..f7c680b8ea07 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java @@ -29,8 +29,10 @@ import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; @@ -47,6 +49,7 @@ import com.intellij.refactoring.util.occurences.OccurenceManager; import com.intellij.ui.StateRestoringCheckBox; import com.intellij.ui.TitlePanel; import com.intellij.util.ArrayUtil; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -241,40 +244,54 @@ public class InplaceIntroduceConstantPopup { return visibilityCombo; } - public static void appendActions(final JComboBox visibilityCombo, final Project project) { + public static void appendActions(final JComboBox comboBox, final Project project) { + final boolean toggleStrategy = !UIUtil.isUnderAquaLookAndFeel(); final boolean[] moveFocusBack = new boolean[] {true}; - visibilityCombo.addFocusListener(new FocusAdapter() { + comboBox.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { if (!moveFocusBack[0]) { moveFocusBack[0] = true; return; } - final int size = visibilityCombo.getModel().getSize(); - int next = visibilityCombo.getSelectedIndex() + 1; - if (next < 0 || next >= size) { - if (!UISettings.getInstance().CYCLE_SCROLLING) { - return; + + if (toggleStrategy) { + final int size = comboBox.getModel().getSize(); + int next = comboBox.getSelectedIndex() + 1; + if (next < 0 || next >= size) { + if (!UISettings.getInstance().CYCLE_SCROLLING) { + return; + } + next = (next + size) % size; + } + comboBox.setSelectedIndex(next); + ToolWindowManager.getInstance(project).activateEditorComponent(); + } + else { + JBPopupFactory popupFactory = JBPopupFactory.getInstance(); + boolean fromTheSameBalloon = popupFactory.getParentBalloonFor(e.getComponent()) == popupFactory.getParentBalloonFor(e.getOppositeComponent()); + if (!fromTheSameBalloon) { + comboBox.showPopup(); } - next = (next + size) % size; } - visibilityCombo.setSelectedIndex(next); - ToolWindowManager.getInstance(project).activateEditorComponent(); } }); - visibilityCombo.addMouseListener(new MouseAdapter() { + comboBox.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { moveFocusBack[0] = false; } }); - visibilityCombo.addKeyListener(new KeyAdapter() { + comboBox.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { moveFocusBack[0] = true; + if (!toggleStrategy && e.getKeyCode() == KeyEvent.VK_ESCAPE && e.getModifiers() == 0) { + ToolWindowManager.getInstance(project).activateEditorComponent(); + } } }); - visibilityCombo.addActionListener(new ActionListener() { + comboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { moveFocusBack[0] = true; From 8f5d93edf8387d3aaecd457eb0b939d488e2ed43 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Wed, 11 May 2011 17:13:06 +0400 Subject: [PATCH 144/250] Reverted broken method. (Anton, why did you do that?) --- .../execution/testframework/sm/runner/SMTestProxy.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java index 439d85b628c6..5a896c2db8d1 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java @@ -15,7 +15,7 @@ */ package com.intellij.execution.testframework.sm.runner; -//import com.google.common.collect.Lists; +import com.google.common.collect.Lists; import com.intellij.execution.Location; import com.intellij.execution.testframework.AbstractTestProxy; import com.intellij.execution.testframework.Filter; @@ -339,7 +339,7 @@ public class SMTestProxy extends AbstractTestProxy { public List collectChildren() { final List allChildren = getChildren(); - final List result = null;//Lists.newArrayList(); + final List result = Lists.newArrayList(); result.addAll(allChildren); From 8a7832e9863fef83f503040349a7fed3946f9865 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 11 May 2011 17:22:34 +0400 Subject: [PATCH 145/250] tab/escape for live template work in injected fragment --- .../src/com/intellij/openapi/editor/actions/EscapeAction.java | 1 + .../src/com/intellij/openapi/editor/actions/TabAction.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/EscapeAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/EscapeAction.java index 6ffff109d4b5..e6c3422b4bb0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/EscapeAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/EscapeAction.java @@ -29,6 +29,7 @@ import com.intellij.openapi.editor.actionSystem.EditorActionHandler; public class EscapeAction extends EditorAction { public EscapeAction() { super(new Handler()); + setInjectedContext(true); } private static class Handler extends EditorActionHandler { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/TabAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/TabAction.java index a590a220f588..26651392f4f7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/TabAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/TabAction.java @@ -42,6 +42,7 @@ import com.intellij.openapi.vfs.VirtualFile; public class TabAction extends EditorAction { public TabAction() { super(new Handler()); + setInjectedContext(true); } private static class Handler extends EditorWriteActionHandler { @@ -89,7 +90,7 @@ public class TabAction extends EditorAction { EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, "\t", false); } else { - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(spacesToAddCount); for(int i=0; i Date: Wed, 11 May 2011 17:26:45 +0400 Subject: [PATCH 146/250] cleanup --- .../src/com/intellij/codeInsight/hint/EscapeHandler.java | 2 +- .../src/com/intellij/ide/actions/SelectAllAction.java | 7 ++++--- .../openapi/editor/actions/TextComponentEditorAction.java | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hint/EscapeHandler.java b/platform/platform-impl/src/com/intellij/codeInsight/hint/EscapeHandler.java index 8cf30f26a15e..8751f9339ae2 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hint/EscapeHandler.java +++ b/platform/platform-impl/src/com/intellij/codeInsight/hint/EscapeHandler.java @@ -30,7 +30,7 @@ public class EscapeHandler extends EditorActionHandler { public void execute(Editor editor, DataContext dataContext) { Project project = PlatformDataKeys.PROJECT.getData(dataContext); - if (project == null || !HintManagerImpl.getInstanceImpl().hideHints(HintManagerImpl.HIDE_BY_ESCAPE | HintManagerImpl.HIDE_BY_ANY_KEY, true, false)) { + if (project == null || !HintManagerImpl.getInstanceImpl().hideHints(HintManager.HIDE_BY_ESCAPE | HintManager.HIDE_BY_ANY_KEY, true, false)) { myOriginalHandler.execute(editor, dataContext); } } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/SelectAllAction.java b/platform/platform-impl/src/com/intellij/ide/actions/SelectAllAction.java index 8b2d47a7deb1..684e2fa4c27a 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/SelectAllAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/SelectAllAction.java @@ -16,10 +16,12 @@ package com.intellij.ide.actions; import com.intellij.ide.IdeBundle; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; import com.intellij.openapi.editor.actions.TextComponentEditorAction; import com.intellij.openapi.project.DumbAware; @@ -27,7 +29,6 @@ import com.intellij.openapi.project.DumbAware; public class SelectAllAction extends TextComponentEditorAction implements DumbAware { public SelectAllAction() { super(new Handler()); - setEnabledInModalContext(true); } private static class Handler extends EditorActionHandler { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/TextComponentEditorAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/TextComponentEditorAction.java index ae531890e800..95040714e5e5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/TextComponentEditorAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/TextComponentEditorAction.java @@ -31,7 +31,6 @@ import javax.swing.text.JTextComponent; public abstract class TextComponentEditorAction extends EditorAction { protected TextComponentEditorAction(final EditorActionHandler defaultHandler) { super(defaultHandler); - setEnabledInModalContext(true); } @Nullable From e08db0b4c372861844dda2759e479649be348fd9 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 May 2011 16:17:53 +0400 Subject: [PATCH 147/250] helpId && usability --- .../internal/statistic/configurable/StatisticsConfigurable.java | 2 +- .../configurable/StatisticsConfigurationComponent.form | 2 +- .../configurable/StatisticsConfigurationComponent.java | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurable.java b/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurable.java index fde991032105..ecccce03f888 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurable.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurable.java @@ -55,7 +55,7 @@ public class StatisticsConfigurable implements SearchableConfigurable { @Nullable @NonNls public String getHelpTopic() { - return null; + return "preferences.usage.statictics"; } public JComponent createComponent() { diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.form b/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.form index a0f299834ab9..abc0308b4aaf 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.form +++ b/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.form @@ -14,7 +14,7 @@ - +
diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.java b/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.java index d723b8717e61..0d4f1057eb0d 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/configurable/StatisticsConfigurationComponent.java @@ -16,6 +16,7 @@ package com.intellij.internal.statistic.configurable; import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent; +import com.intellij.openapi.application.ApplicationNamesInfo; import com.intellij.openapi.ui.ex.MultiLineLabel; import javax.swing.*; @@ -32,6 +33,7 @@ public class StatisticsConfigurationComponent { private JLabel myLabel; public StatisticsConfigurationComponent() { + myTitle.setText("Help improve "+ ApplicationNamesInfo.getInstance().getFullProductName() + " by sending anonymous usage statistics to JetBrains"); myLabel.setText("We're asking your permission to send information about your plugins configuration (what is enabled and what is not)
and feature usage statistics (e.g. how frequently you're using code completion).
This data is anonymous, does not contain any personal information, collected for use only by JetBrains
and will never be transmitted to any third party."); } From dd17c0b2cef3c5e244a1c04427e49c62b438e0d0 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 11 May 2011 15:46:36 +0200 Subject: [PATCH 148/250] fix tests [r=peter] --- .../src/com/intellij/openapi/extensions/Extensions.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java b/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java index 8d32554056e4..475e4eb9a6f4 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java @@ -34,7 +34,7 @@ public class Extensions { public static final ExtensionPointName AREA_LISTENER_EXTENSION_POINT = new ExtensionPointName("com.intellij.arealistener"); private static final Map ourAreaInstance2area = new HashMap(); - private static final ExtensionsAreaImpl ourRootArea = createRootArea(); + private static ExtensionsAreaImpl ourRootArea = createRootArea(); private static final MultiMap ourAreaClass2instances = new MultiMap(); private static final Map ourAreaInstance2class = new HashMap(); private static final Map ourAreaClass2Configuration = new HashMap(); @@ -42,7 +42,6 @@ public class Extensions { private static ExtensionsAreaImpl createRootArea() { ExtensionsAreaImpl rootArea = new ExtensionsAreaImpl(null, null, null, ourLogger); rootArea.registerExtensionPoint(AREA_LISTENER_EXTENSION_POINT.getName(), AreaListener.class.getName()); - ourAreaInstance2area.put(null, rootArea); return rootArea; } @@ -72,7 +71,7 @@ public class Extensions { oldRootArea.notifyAreaReplaced(); Disposer.register(parentDisposable, new Disposable() { public void dispose() { - ourAreaInstance2area.put(null, oldRootArea); + ourRootArea = oldRootArea; newArea.notifyAreaReplaced(); } }); From bd57a1d4fe93812b51a6cc64d4455515d6722d22 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 15:05:57 +0200 Subject: [PATCH 149/250] assertions and a possible fix for EA-27207 - item not in lookup --- .../completion/impl/LiftShorterItemsClassifier.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/LiftShorterItemsClassifier.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/LiftShorterItemsClassifier.java index eecb16174ce9..d16d88e4b38e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/LiftShorterItemsClassifier.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/LiftShorterItemsClassifier.java @@ -20,6 +20,8 @@ import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; +import gnu.trove.THashSet; +import gnu.trove.TObjectHashingStrategy; import java.util.*; @@ -76,7 +78,7 @@ class LiftShorterItemsClassifier extends Classifier { } private Iterable> liftShorterElements(List source, Set lifted) { - final Set srcSet = new HashSet(source); + final Set srcSet = new THashSet(source, TObjectHashingStrategy.IDENTITY); final Iterable> classified = myNext.classify(source); final Set processed = new HashSet(); @@ -84,6 +86,7 @@ class LiftShorterItemsClassifier extends Classifier { for (List list : classified) { final ArrayList group = new ArrayList(); for (LookupElement element : list) { + assert srcSet.contains(element) : myNext; if (processed.add(element)) { final List prefixes = new SmartList(); for (String string : getAllLookupStrings(element)) { From aa190980998bb1e6db46f7f8e462cf44c8a2918f Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 15:09:29 +0200 Subject: [PATCH 150/250] don't hide the lookup under a change guard (EA-27725) --- .../src/com/intellij/codeInsight/hint/HintManagerImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java index d0a16fcd3c0f..10355f027d52 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java @@ -405,7 +405,9 @@ public class HintManagerImpl extends HintManager implements Disposable { LOG.assertTrue(SwingUtilities.isEventDispatchThread()); List hints = new ArrayList(myHintsStack); for (HintInfo info : hints) { - info.hint.hide(); + if (!info.hint.vetoesHiding()) { + info.hint.hide(); + } } cleanup(); } From 5bcdcc6613cd9396ef47d1f57fe76965d0148acc Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 15:38:32 +0200 Subject: [PATCH 151/250] don't try to create java type from groovy expression text, use resolve to determine if a reference of a class type --- .../GrReferenceExpressionImpl.java | 32 ++----------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java index 3dda83d1a10b..fdeed0cb9b5e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java @@ -491,14 +491,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl { @Nullable public PsiType fun(GrReferenceExpressionImpl refExpr) { From d6c43e4053c48bd5568f8862bf42ca21e02c3dfc Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 15:40:37 +0200 Subject: [PATCH 152/250] reduce visibility --- .../src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java index 8a2318319fbd..12ccc64c8c3b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java @@ -1128,7 +1128,7 @@ public class PsiUtil { return ((GrListOrMap)firstArg).getNamedArguments(); } - public static boolean seemsToBeQualifiedClassName(@Nullable GrExpression qualifier) { + private static boolean seemsToBeQualifiedClassName(@Nullable GrExpression qualifier) { if (qualifier == null) return false; while (qualifier instanceof GrReferenceExpression) { final PsiElement nameElement = ((GrReferenceExpression)qualifier).getReferenceNameElement(); From 57e253d5383cc47aee38fa77d8973ec20e77bdce Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 16:23:13 +0200 Subject: [PATCH 153/250] [^cdr] tolerate empty LazyParseableElements --- .../src/com/intellij/psi/impl/source/tree/AstBufferUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/AstBufferUtil.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/AstBufferUtil.java index d21f7a81da56..d7acb0d738cb 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/AstBufferUtil.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/AstBufferUtil.java @@ -50,7 +50,7 @@ public class AstBufferUtil { if (composite instanceof LazyParseableElement) { LazyParseableElement lpe = (LazyParseableElement)composite; int lpeResult = lpe.copyTo(buffer, result[0]); - if (lpeResult > 0) { + if (lpeResult >= 0) { result[0] = lpeResult; return; } From 4e3e206038417e2e82cb29d66a9dc459aa03d72e Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Wed, 11 May 2011 18:34:42 +0400 Subject: [PATCH 154/250] IDEA-69528 Formatter: Correct processing of right-aligned wide blocks that start new line 1. Alignment on right edge is corrected; 2. Corresponding test is uncommented; --- .../AbstractBlockAlignmentProcessor.java | 7 ++-- .../formatting/AbstractBlockWrapper.java | 34 +-------------- .../formatting/BlockAlignmentProcessor.java | 6 ++- .../formatting/CoreFormatterUtil.java | 30 ++++++++++++++ .../intellij/formatting/FormatProcessor.java | 2 +- .../LeftEdgeAlignmentProcessor.java | 3 +- .../RightEdgeAlignmentProcessor.java | 41 +++++++++++++++++-- 7 files changed, 82 insertions(+), 41 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/formatting/AbstractBlockAlignmentProcessor.java b/platform/lang-impl/src/com/intellij/formatting/AbstractBlockAlignmentProcessor.java index e73e1646d491..f7b999698a4e 100644 --- a/platform/lang-impl/src/com/intellij/formatting/AbstractBlockAlignmentProcessor.java +++ b/platform/lang-impl/src/com/intellij/formatting/AbstractBlockAlignmentProcessor.java @@ -38,8 +38,7 @@ public abstract class AbstractBlockAlignmentProcessor implements BlockAlignmentP return Result.TARGET_BLOCK_PROCESSED_NOT_ALIGNED; } WhiteSpace whiteSpace = context.targetBlock.getWhiteSpace(); - if (whiteSpace.containsLineFeeds()) { - applyIndentToTheFirstBlockOnLine(indent, context); + if (whiteSpace.containsLineFeeds() && applyIndentToTheFirstBlockOnLine(indent, context)) { return Result.TARGET_BLOCK_ALIGNED; } @@ -118,8 +117,10 @@ public abstract class AbstractBlockAlignmentProcessor implements BlockAlignmentP * * @param alignmentAnchorIndent alignment anchor indent * @param context current processing context + * @return true if desired alignment indent is applied to the current block; + * false otherwise */ - protected abstract void applyIndentToTheFirstBlockOnLine(@NotNull IndentData alignmentAnchorIndent, @NotNull Context context); + protected abstract boolean applyIndentToTheFirstBlockOnLine(@NotNull IndentData alignmentAnchorIndent, @NotNull Context context); /** * Calculates the difference between alignment anchor indent and current target block indent. diff --git a/platform/lang-impl/src/com/intellij/formatting/AbstractBlockWrapper.java b/platform/lang-impl/src/com/intellij/formatting/AbstractBlockWrapper.java index debe73fdb099..6fbbc070b4dc 100644 --- a/platform/lang-impl/src/com/intellij/formatting/AbstractBlockWrapper.java +++ b/platform/lang-impl/src/com/intellij/formatting/AbstractBlockWrapper.java @@ -134,36 +134,6 @@ public abstract class AbstractBlockWrapper { if (wrap != null) wrap.reset(); } - /** - * Calculates indent for the given block and target start offset according to the given indent options. - * - * @param options indent options to use - * @param block target wrapped block - * @param tokenBlockStartOffset target wrapped block offset - * @return indent to use for the given parameters - */ - private static IndentData getIndent(CodeStyleSettings.IndentOptions options, - AbstractBlockWrapper block, - final int tokenBlockStartOffset) { - final IndentImpl indent = block.getIndent(); - if (indent.getType() == Indent.Type.CONTINUATION) { - return new IndentData(options.CONTINUATION_INDENT_SIZE); - } - if (indent.getType() == Indent.Type.CONTINUATION_WITHOUT_FIRST) { - if (block.getStartOffset() != block.getParent().getStartOffset() && block.getStartOffset() == tokenBlockStartOffset) { - return new IndentData(options.CONTINUATION_INDENT_SIZE); - } - else { - return new IndentData(0); - } - } - if (indent.getType() == Indent.Type.LABEL) return new IndentData(options.LABEL_INDENT_SIZE); - if (indent.getType() == Indent.Type.NONE) return new IndentData(0); - if (indent.getType() == Indent.Type.SPACES) return new IndentData(0, indent.getSpaces()); - return new IndentData(options.INDENT_SIZE); - - } - public IndentData getChildOffset(AbstractBlockWrapper child, CodeStyleSettings.IndentOptions options, int targetBlockStartOffset) { final boolean childStartsNewLine = child.getWhiteSpace().containsLineFeeds(); IndentImpl.Type childIndentType = child.getIndent().getType(); @@ -173,7 +143,7 @@ public abstract class AbstractBlockWrapper { if (childStartsNewLine || (!getWhiteSpace().containsLineFeeds() && RELATIVE_INDENT_TYPES.contains(childIndentType) && indentAlreadyUsedBefore(child))) { - childIndent = getIndent(options, child, targetBlockStartOffset); + childIndent = CoreFormatterUtil.getIndent(options, child, targetBlockStartOffset); } else if (child.getIndent().isEnforceIndentToChildren() && !child.getWhiteSpace().containsLineFeeds()) { // Enforce indent if child doesn't start new line, e.g. prefer the code below: @@ -231,7 +201,7 @@ public abstract class AbstractBlockWrapper { } return anchorBlock.getNumberOfSymbolsBeforeBlock(); } - childIndent = getIndent(options, child, getStartOffset()); + childIndent = CoreFormatterUtil.getIndent(options, child, getStartOffset()); } else { childIndent = new IndentData(0); diff --git a/platform/lang-impl/src/com/intellij/formatting/BlockAlignmentProcessor.java b/platform/lang-impl/src/com/intellij/formatting/BlockAlignmentProcessor.java index f46438928c2d..b245b81a13ff 100644 --- a/platform/lang-impl/src/com/intellij/formatting/BlockAlignmentProcessor.java +++ b/platform/lang-impl/src/com/intellij/formatting/BlockAlignmentProcessor.java @@ -15,6 +15,7 @@ */ package com.intellij.formatting; +import com.intellij.psi.codeStyle.CodeStyleSettings; import org.jetbrains.annotations.NotNull; import java.util.Map; @@ -64,16 +65,19 @@ public interface BlockAlignmentProcessor { @NotNull public final LeafBlockWrapper targetBlock; @NotNull public final Map> alignmentMappings; @NotNull public final Map> backwardShiftedAlignedBlocks; + @NotNull public final CodeStyleSettings.IndentOptions indentOptions; public Context(@NotNull AlignmentImpl alignment, @NotNull LeafBlockWrapper targetBlock, @NotNull Map> alignmentMappings, - @NotNull Map> backwardShiftedAlignedBlocks) + @NotNull Map> backwardShiftedAlignedBlocks, + @NotNull CodeStyleSettings.IndentOptions indentOptions) { this.alignment = alignment; this.targetBlock = targetBlock; this.alignmentMappings = alignmentMappings; this.backwardShiftedAlignedBlocks = backwardShiftedAlignedBlocks; + this.indentOptions = indentOptions; } } } diff --git a/platform/lang-impl/src/com/intellij/formatting/CoreFormatterUtil.java b/platform/lang-impl/src/com/intellij/formatting/CoreFormatterUtil.java index 1d45e6a0fb31..2909a43f5850 100644 --- a/platform/lang-impl/src/com/intellij/formatting/CoreFormatterUtil.java +++ b/platform/lang-impl/src/com/intellij/formatting/CoreFormatterUtil.java @@ -15,6 +15,7 @@ */ package com.intellij.formatting; +import com.intellij.psi.codeStyle.CodeStyleSettings; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -207,4 +208,33 @@ public class CoreFormatterUtil { return true; } + /** + * Calculates indent for the given block and target start offset according to the given indent options. + * + * @param options indent options to use + * @param block target wrapped block + * @param tokenBlockStartOffset target wrapped block offset + * @return indent to use for the given parameters + */ + public static IndentData getIndent(CodeStyleSettings.IndentOptions options, AbstractBlockWrapper block, + final int tokenBlockStartOffset) + { + final IndentImpl indent = block.getIndent(); + if (indent.getType() == Indent.Type.CONTINUATION) { + return new IndentData(options.CONTINUATION_INDENT_SIZE); + } + if (indent.getType() == Indent.Type.CONTINUATION_WITHOUT_FIRST) { + if (block.getStartOffset() != block.getParent().getStartOffset() && block.getStartOffset() == tokenBlockStartOffset) { + return new IndentData(options.CONTINUATION_INDENT_SIZE); + } + else { + return new IndentData(0); + } + } + if (indent.getType() == Indent.Type.LABEL) return new IndentData(options.LABEL_INDENT_SIZE); + if (indent.getType() == Indent.Type.NONE) return new IndentData(0); + if (indent.getType() == Indent.Type.SPACES) return new IndentData(0, indent.getSpaces()); + return new IndentData(options.INDENT_SIZE); + + } } diff --git a/platform/lang-impl/src/com/intellij/formatting/FormatProcessor.java b/platform/lang-impl/src/com/intellij/formatting/FormatProcessor.java index e5799aca2a9e..18ca02120bbf 100644 --- a/platform/lang-impl/src/com/intellij/formatting/FormatProcessor.java +++ b/platform/lang-impl/src/com/intellij/formatting/FormatProcessor.java @@ -599,7 +599,7 @@ class FormatProcessor { } BlockAlignmentProcessor.Context context = new BlockAlignmentProcessor.Context( - alignment, myCurrentBlock, myAlignmentMappings, myBackwardShiftedAlignedBlocks + alignment, myCurrentBlock, myAlignmentMappings, myBackwardShiftedAlignedBlocks, myIndentOption ); BlockAlignmentProcessor.Result result = alignmentProcessor.applyAlignment(context); switch (result) { diff --git a/platform/lang-impl/src/com/intellij/formatting/LeftEdgeAlignmentProcessor.java b/platform/lang-impl/src/com/intellij/formatting/LeftEdgeAlignmentProcessor.java index 86403b27d23e..94f719de1f98 100644 --- a/platform/lang-impl/src/com/intellij/formatting/LeftEdgeAlignmentProcessor.java +++ b/platform/lang-impl/src/com/intellij/formatting/LeftEdgeAlignmentProcessor.java @@ -56,9 +56,10 @@ public class LeftEdgeAlignmentProcessor extends AbstractBlockAlignmentProcessor } @Override - protected void applyIndentToTheFirstBlockOnLine(@NotNull IndentData alignmentAnchorIndent, @NotNull Context context) { + protected boolean applyIndentToTheFirstBlockOnLine(@NotNull IndentData alignmentAnchorIndent, @NotNull Context context) { WhiteSpace whiteSpace = context.targetBlock.getWhiteSpace(); whiteSpace.setSpaces(alignmentAnchorIndent.getSpaces(), alignmentAnchorIndent.getIndentSpaces()); + return true; } @Override diff --git a/platform/lang-impl/src/com/intellij/formatting/RightEdgeAlignmentProcessor.java b/platform/lang-impl/src/com/intellij/formatting/RightEdgeAlignmentProcessor.java index d3d6d23d110a..210826105dc7 100644 --- a/platform/lang-impl/src/com/intellij/formatting/RightEdgeAlignmentProcessor.java +++ b/platform/lang-impl/src/com/intellij/formatting/RightEdgeAlignmentProcessor.java @@ -52,15 +52,50 @@ public class RightEdgeAlignmentProcessor extends AbstractBlockAlignmentProcessor } @Override - protected void applyIndentToTheFirstBlockOnLine(@NotNull IndentData alignmentAnchorIndent, @NotNull Context context) { + protected boolean applyIndentToTheFirstBlockOnLine(@NotNull IndentData alignmentAnchorIndent, @NotNull Context context) { WhiteSpace whiteSpace = context.targetBlock.getWhiteSpace(); int indentSpaces = alignmentAnchorIndent.getIndentSpaces(); int spaces = alignmentAnchorIndent.getSpaces() - context.targetBlock.getSymbolsAtTheLastLine(); if (spaces < 0) { - indentSpaces = Math.max(0, indentSpaces + spaces); + indentSpaces += spaces; spaces = 0; } - whiteSpace.setSpaces(spaces, indentSpaces); + + if (indentSpaces >= 0) { + whiteSpace.setSpaces(spaces, indentSpaces); + return true; + } + if (whiteSpace.getTotalSpaces() > 0) { + // The general idea is that there is a possible case that particular block that starts new line is much wider than its + // preceding aligned block and its white space is not empty. We may move it to the left then trying to preserve its + // indent. + // + // Example: + // block11 block12 + // test-block-that-has-rather-big-width-and-aligned-to-block12 + // Let's say, the last block has indent '10', hence, the result would be: + // block11 block12 + // test-block-that-has-rather-big-width-and-aligned-to-block12 + CompositeBlockWrapper parent = context.targetBlock.getParent(); + if (parent != null) { + IndentData childOffset = CoreFormatterUtil.getIndent( + context.indentOptions, context.targetBlock, context.targetBlock.getStartOffset() + ); + if (whiteSpace.getTotalSpaces() > childOffset.getTotalSpaces()) { + int leftShift = whiteSpace.getTotalSpaces() - childOffset.getTotalSpaces(); + if (leftShift >= whiteSpace.getSpaces()) { + spaces = 0; + indentSpaces = whiteSpace.getIndentSpaces() - (leftShift - whiteSpace.getSpaces()); + } + else { + spaces = whiteSpace.getSpaces() - leftShift; + indentSpaces = whiteSpace.getIndentSpaces(); + } + } + whiteSpace.setSpaces(spaces, indentSpaces); + } + } + return false; } @Override From 8fbc0fb1951500a6b86ae3d7324691a0a18b3729 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Wed, 11 May 2011 16:52:08 +0200 Subject: [PATCH 155/250] IDEA-69478 (Wrong generic type on intention replace for each with iterator for loop) --- ...rEachLoopWithIteratorForLoopIntention.java | 31 +++---------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIteratorForLoopIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIteratorForLoopIntention.java index 78d865875057..d90f47a4a4c2 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIteratorForLoopIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIteratorForLoopIntention.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2009 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,19 +49,6 @@ public class ReplaceForEachLoopWithIteratorForLoopIntention extends Intention { if (iteratedValue == null) { return; } - final PsiType type = iteratedValue.getType(); - final PsiType iteratedValueParameterType; - if (type instanceof PsiClassType) { - final PsiClassType classType = (PsiClassType)type; - final PsiType[] parameterTypes = classType.getParameters(); - if (parameterTypes.length == 0) { - iteratedValueParameterType = null; - } else { - iteratedValueParameterType = parameterTypes[0]; - } - } else { - iteratedValueParameterType = null; - } @NonNls final StringBuilder newStatement = new StringBuilder(); final PsiParameter iterationParameter = statement.getIterationParameter(); @@ -71,13 +58,9 @@ public class ReplaceForEachLoopWithIteratorForLoopIntention extends Intention { statement, true); final String typeText = parameterType.getCanonicalText(); newStatement.append("for(java.util.Iterator"); - if (iteratedValueParameterType == null) { - newStatement.append(' '); - } else { - newStatement.append('<'); - newStatement.append(iteratedValueParameterType.getCanonicalText()); - newStatement.append("> "); - } + newStatement.append('<'); + newStatement.append(typeText); + newStatement.append("> "); newStatement.append(iterator); newStatement.append(" = "); if (iteratedValue instanceof PsiTypeCastExpression) { @@ -99,12 +82,6 @@ public class ReplaceForEachLoopWithIteratorForLoopIntention extends Intention { newStatement.append(' '); newStatement.append(iterationParameter.getName()); newStatement.append(" = "); - if (iteratedValueParameterType == null && ! - "java.lang.Object".equals(typeText)) { - newStatement.append('('); - newStatement.append(typeText); - newStatement.append(')'); - } newStatement.append(iterator); newStatement.append(".next();"); final PsiStatement body = statement.getBody(); From ab5d9ae1be7d08d4e717aa13dd9acd186b862194 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Wed, 11 May 2011 16:54:42 +0200 Subject: [PATCH 156/250] fix exception --- .../debugger/actions/ObjectMarkupPropertiesDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ObjectMarkupPropertiesDialog.java b/java/debugger/impl/src/com/intellij/debugger/actions/ObjectMarkupPropertiesDialog.java index fe2ac9ee5bf5..655960619a74 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ObjectMarkupPropertiesDialog.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ObjectMarkupPropertiesDialog.java @@ -40,7 +40,7 @@ public class ObjectMarkupPropertiesDialog extends ValueMarkerPresentationDialogB mySuggestAdditionalMarkup = suggestAdditionalMarkup; myDescriptionLabel.setText("If the value is referenced by a constant field of an abstract class,\n" + "IDEA could additionally mark all values referenced from this class with the names of referencing fields."); - myCbMarkAdditionalFields.setSelected(PropertiesComponent.getInstance().getBoolean(MARK_ALL_REFERENCED_VALUES_KEY, true)); + myCbMarkAdditionalFields.setSelected(suggestAdditionalMarkup && PropertiesComponent.getInstance().getBoolean(MARK_ALL_REFERENCED_VALUES_KEY, true)); init(); } @@ -65,6 +65,6 @@ public class ObjectMarkupPropertiesDialog extends ValueMarkerPresentationDialogB } public boolean isMarkAdditionalFields() { - return myCbMarkAdditionalFields.isSelected(); + return mySuggestAdditionalMarkup && myCbMarkAdditionalFields.isSelected(); } } From abd0479b8932f9131ac55e40e4d4fab3efcc4bb2 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 17:02:52 +0200 Subject: [PATCH 157/250] don't reformat the temporary space inserted during class name completion since this leads to tailOffset range marker invalidation (EA-27020) --- .../completion/JavaCompletionUtil.java | 15 ++++++++++++--- .../source/PostprocessReformattingAspect.java | 2 ++ .../psi/impl/source/codeStyle/CodeEditUtil.java | 11 +++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java index b1adde398275..c26ea53d17bb 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java @@ -22,6 +22,7 @@ import com.intellij.codeInsight.completion.scope.JavaCompletionProcessor; import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler; import com.intellij.codeInsight.guess.GuessManager; import com.intellij.codeInsight.lookup.*; +import com.intellij.lang.ASTNode; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; @@ -44,6 +45,8 @@ import com.intellij.psi.filters.element.ExcludeDeclaredFilter; import com.intellij.psi.filters.element.ExcludeSillyAssignment; import com.intellij.psi.html.HtmlTag; import com.intellij.psi.impl.source.PsiImmediateClassType; +import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; +import com.intellij.psi.impl.source.tree.TreeUtil; import com.intellij.psi.javadoc.PsiDocToken; import com.intellij.psi.scope.BaseScopeProcessor; import com.intellij.psi.scope.ElementClassFilter; @@ -764,7 +767,7 @@ public class JavaCompletionUtil { assert document != null; document.replaceString(startOffset, endOffset, name); - final RangeMarker toDelete = insertTemporary(startOffset + name.length(), document, "#"); + final RangeMarker toDelete = insertTemporary(startOffset + name.length(), document, " "); PsiDocumentManager.getInstance(project).commitAllDocuments(); @@ -781,9 +784,15 @@ public class JavaCompletionUtil { ? ((PsiImportStaticReferenceElement)ref).bindToTargetClass(psiClass) : ref.bindToElement(psiClass); - RangeMarker marker = document.createRangeMarker(newElement.getTextRange()); + ASTNode newNode = newElement.getNode(); + CodeEditUtil.disablePostponedFormatting(newNode); + ASTNode next = TreeUtil.nextLeaf(newNode); + if (next != null) { + CodeEditUtil.disablePostponedFormatting(next); + } + newElement = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(newElement); - newStartOffset = marker.getStartOffset(); + newStartOffset = newElement.getTextRange().getStartOffset(); if (!staticImport && newElement instanceof PsiJavaCodeReferenceElement && diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java b/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java index b96bcdc8ea63..ac5709d3af2d 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java @@ -477,6 +477,8 @@ public class PostprocessReformattingAspect implements PomModelAspect, Disposable protected boolean visitNode(TreeElement element) { if (nodesToProcess.contains(element)) return false; + if (CodeEditUtil.isPostponedFormattingDisabled(element)) return false; + final boolean currentNodeGenerated = CodeEditUtil.isNodeGenerated(element); CodeEditUtil.setNodeGenerated(element, false); if (currentNodeGenerated && !inGeneratedContext) { diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeEditUtil.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeEditUtil.java index a5fc25fa03bc..931f9a6d4abc 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeEditUtil.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeEditUtil.java @@ -45,6 +45,7 @@ public class CodeEditUtil { private static final Key INDENT_INFO = new Key("INDENT_INFO"); private static final Key REFORMAT_BEFORE_KEY = new Key("REFORMAT_BEFORE_KEY"); private static final Key REFORMAT_KEY = new Key("REFORMAT_KEY"); + private static final Key DISABLE_POSTPONED_REFORMAT_KEY = new Key("DISABLE_POSTPONED_REFORMAT_KEY"); private static final ThreadLocal ALLOW_TO_MARK_NODES_TO_REFORMAT = new ThreadLocal() { @Override protected Boolean initialValue() { @@ -444,6 +445,16 @@ public class CodeEditUtil { } } + public static void disablePostponedFormatting(@NotNull final ASTNode node) { + markToReformat(node, false); + markToReformatBefore(node, false); + node.putUserData(DISABLE_POSTPONED_REFORMAT_KEY, true); + } + + public static boolean isPostponedFormattingDisabled(@NotNull final ASTNode node) { + return node.getUserData(DISABLE_POSTPONED_REFORMAT_KEY) != null; + } + /** * We allow to mark particular {@link ASTNode AST nodes} to be reformatted later (e.g. we may want method definition and calls * to be reformatted when we perform 'change method signature' refactoring. Hence, we mark corresponding expressions From f29957241f08586656665524133815509402c460 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Wed, 11 May 2011 17:06:26 +0200 Subject: [PATCH 158/250] init checkbox with previous value --- .../intellij/debugger/actions/ObjectMarkupPropertiesDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ObjectMarkupPropertiesDialog.java b/java/debugger/impl/src/com/intellij/debugger/actions/ObjectMarkupPropertiesDialog.java index 655960619a74..cd4aa14b7703 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ObjectMarkupPropertiesDialog.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ObjectMarkupPropertiesDialog.java @@ -40,7 +40,7 @@ public class ObjectMarkupPropertiesDialog extends ValueMarkerPresentationDialogB mySuggestAdditionalMarkup = suggestAdditionalMarkup; myDescriptionLabel.setText("If the value is referenced by a constant field of an abstract class,\n" + "IDEA could additionally mark all values referenced from this class with the names of referencing fields."); - myCbMarkAdditionalFields.setSelected(suggestAdditionalMarkup && PropertiesComponent.getInstance().getBoolean(MARK_ALL_REFERENCED_VALUES_KEY, true)); + myCbMarkAdditionalFields.setSelected(PropertiesComponent.getInstance().getBoolean(MARK_ALL_REFERENCED_VALUES_KEY, true)); init(); } From 856eabebe9b5bcc5d4b341109f5fd8448bc8e36f Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Wed, 11 May 2011 19:11:38 +0400 Subject: [PATCH 159/250] IDEA-69316 Ctrl+D functionality can be improved by adding selected text after additional line feed. Human-readable name is given to the 'Duplicate Lines' action --- .../platform-resources-en/src/messages/ActionsBundle.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/platform-resources-en/src/messages/ActionsBundle.properties b/platform/platform-resources-en/src/messages/ActionsBundle.properties index 618d12942776..f372113e7992 100644 --- a/platform/platform-resources-en/src/messages/ActionsBundle.properties +++ b/platform/platform-resources-en/src/messages/ActionsBundle.properties @@ -120,6 +120,7 @@ action.EditorKillToWordEnd.text=Kill to Word End action.EditorKillRegion.text=Kill Selected Region action.EditorKillRingSave.text=Save to Kill Ring action.EditorDuplicate.text=Duplicate Line or Block +action.EditorDuplicateLines.text=Duplicate Lines action.EditorSelectWord.text=Select Word at Caret action.EditorUnSelectWord.text=Unselect Word at Caret action.EditorToggleInsertState.text=Toggle Insert/Overwrite From f6369d73d2429ad5c1a425763d2127ad08a81141 Mon Sep 17 00:00:00 2001 From: Alexander Kirillin Date: Wed, 11 May 2011 19:17:31 +0400 Subject: [PATCH 160/250] Temporary fix for AppCode tests --- .../intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java index 43c91a765c8c..d63a5e6d5b2f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java @@ -66,7 +66,7 @@ import java.util.*; public class VirtualDirectoryImpl extends VirtualFileSystemEntry { private static final VirtualFileSystemEntry NULL_VIRTUAL_FILE = new VirtualFileImpl("*?;%NULL", null, -42); private final NewVirtualFileSystem myFS; - private static final boolean IS_UNIT_TESTS = ApplicationManager.getApplication().isUnitTestMode(); + private static final boolean IS_UNIT_TESTS = false;//ApplicationManager.getApplication().isUnitTestMode(); // guarded by this private Object myChildren; // Either HashMap or VFile[] From 173e6ca3960bd1e59e27bf8a282e866cb6dc01da Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Wed, 11 May 2011 17:23:57 +0200 Subject: [PATCH 161/250] assertion temporarily disabled --- .../intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java index d63a5e6d5b2f..f25ba1860a17 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java @@ -206,7 +206,7 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { if (!isUnder) { if (!allowed.isEmpty()) { - assert false : "File accessed outside project: " + child +"; project roots: "+new ArrayList(allowed); + //assert false : "File accessed outside project: " + child +"; project roots: "+new ArrayList(allowed); } } } From 93a2771903f159f452fc78e98fb87fd54f4b5f24 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 17:50:43 +0200 Subject: [PATCH 162/250] cleanup the disable-postponed-formatting status --- .../source/PostprocessReformattingAspect.java | 2 ++ .../impl/source/codeStyle/CodeEditUtil.java | 31 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java b/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java index ac5709d3af2d..6a9bc57c8539 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java @@ -509,6 +509,8 @@ public class PostprocessReformattingAspect implements PomModelAspect, Disposable inGeneratedContext = oldGeneratedContext; } }); + + CodeEditUtil.enablePostponedFormattingInTree(node); } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeEditUtil.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeEditUtil.java index 931f9a6d4abc..69f5f2136fd1 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeEditUtil.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeEditUtil.java @@ -29,10 +29,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; -import com.intellij.psi.impl.source.tree.Factory; -import com.intellij.psi.impl.source.tree.LeafElement; -import com.intellij.psi.impl.source.tree.TreeElement; -import com.intellij.psi.impl.source.tree.TreeUtil; +import com.intellij.psi.impl.source.tree.*; import com.intellij.psi.templateLanguages.OuterLanguageElement; import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiUtilBase; @@ -331,12 +328,7 @@ public class CodeEditUtil { } public static void markToReformatBefore(final ASTNode right, boolean value) { - if (value) { - right.putCopyableUserData(REFORMAT_BEFORE_KEY, true); - } - else { - right.putCopyableUserData(REFORMAT_BEFORE_KEY, null); - } + right.putCopyableUserData(REFORMAT_BEFORE_KEY, value ? true : null); } private static int getBlankLines(final String text) { @@ -401,12 +393,7 @@ public class CodeEditUtil { public static void setNodeGenerated(final ASTNode next, final boolean value) { if (next == null) return; - if (value) { - next.putCopyableUserData(GENERATED_FLAG, true); - } - else { - next.putCopyableUserData(GENERATED_FLAG, null); - } + next.putCopyableUserData(GENERATED_FLAG, value ? true : null); } public static void setOldIndentation(final TreeElement treeElement, final int oldIndentation) { @@ -430,7 +417,7 @@ public class CodeEditUtil { * @return true if given node is configured to be reformatted; false otherwise */ public static boolean isMarkedToReformat(final ASTNode node) { - return node.getCopyableUserData(REFORMAT_KEY) != null && ALLOW_NODES_REFORMATTING.get(); + return node.getCopyableUserData(REFORMAT_KEY) != null && isSuspendedNodesReformattingAllowed(); } /** @@ -451,6 +438,16 @@ public class CodeEditUtil { node.putUserData(DISABLE_POSTPONED_REFORMAT_KEY, true); } + public static void enablePostponedFormattingInTree(@NotNull ASTNode root) { + ((TreeElement)root).acceptTree(new RecursiveTreeElementVisitor() { + protected boolean visitNode(TreeElement element) { + element.putUserData(DISABLE_POSTPONED_REFORMAT_KEY, null); + return true; + } + }); + + } + public static boolean isPostponedFormattingDisabled(@NotNull final ASTNode node) { return node.getUserData(DISABLE_POSTPONED_REFORMAT_KEY) != null; } From 88187193f50625abab2e4d38fb03a3f4a11d75e2 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 18:31:32 +0200 Subject: [PATCH 163/250] don't search for an alias with empty name (EA-25319) --- .../groovy/findUsages/GrAliasedImportedElementSearcher.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrAliasedImportedElementSearcher.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrAliasedImportedElementSearcher.java index 5f5e7bbeda39..1cfa50c98c8c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrAliasedImportedElementSearcher.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GrAliasedImportedElementSearcher.java @@ -16,6 +16,7 @@ package org.jetbrains.plugins.groovy.findUsages; import com.intellij.openapi.application.QueryExecutorBase; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.search.*; import com.intellij.psi.search.searches.ReferencesSearch; @@ -42,7 +43,7 @@ public class GrAliasedImportedElementSearcher extends QueryExecutorBase Date: Wed, 11 May 2011 18:01:11 +0200 Subject: [PATCH 164/250] some more diagnostics for failing test --- .../src/com/intellij/openapi/extensions/Extensions.java | 2 +- .../intellij/xdebugger/impl/breakpoints/XBreakpointBase.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java b/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java index 475e4eb9a6f4..ba6e11113c73 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java @@ -122,7 +122,7 @@ public class Extensions { if (!ourAreaClass2Configuration.containsKey(areaClass)) { throw new IllegalArgumentException("Area class is not registered: " + areaClass); } - if (ourAreaInstance2area.containsKey(areaInstance)) { + if ((areaInstance == null && ourRootArea != null) || ourAreaInstance2area.containsKey(areaInstance)) { throw new IllegalArgumentException("Area already instantiated for: " + areaInstance); } ExtensionsArea parentArea = getArea(parentAreaInstance); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointBase.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointBase.java index ef9e619d0eb3..676d44110f1b 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointBase.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointBase.java @@ -270,4 +270,9 @@ public class XBreakpointBase, P extends XBreakpointP return new XBreakpointBase>(type, breakpointManager, this); } } + + @Override + public String toString() { + return "XBreakpointBase(type=" + myType + ")"; + } } From 2e8e8ee5db8ef8ebfe5560a418aa62ea52458c3e Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 11 May 2011 18:52:55 +0200 Subject: [PATCH 165/250] [^yole] more diagnostics and a possible fix for EA-26353: the saved lookup element sorting weight mysteriously disappeared --- .../intellij/codeInsight/lookup/ComparingClassifier.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/ComparingClassifier.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/ComparingClassifier.java index 42e363939a57..6f2a0989329a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/ComparingClassifier.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/ComparingClassifier.java @@ -18,6 +18,8 @@ package com.intellij.codeInsight.lookup; import com.intellij.openapi.application.ApplicationManager; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.StripedLockConcurrentHashMap; +import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -26,7 +28,7 @@ import java.util.*; * @author peter */ public abstract class ComparingClassifier extends Classifier { - private final Map myWeights = new HashMap(); + private final Map myWeights = new StripedLockConcurrentHashMap(TObjectHashingStrategy.IDENTITY); private final Classifier myNext; private final String myName; @@ -49,7 +51,7 @@ public abstract class ComparingClassifier extends Classifier { for (T t : source) { final Comparable weight = myWeights.get(t); if (weight == null) { - throw new AssertionError(myName + "; " + myWeights.containsKey(t)); + throw new AssertionError(myName + "; " + myWeights.containsKey(t) + "; element=" + t); } List list = map.get(weight); if (list == null) { From efd3c6160a464214dff50eb7c144bd7c785feabd Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Wed, 11 May 2011 17:22:41 +0200 Subject: [PATCH 166/250] directly use API from jdk 1.6 --- .../actions/JavaMarkObjectActionHandler.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/JavaMarkObjectActionHandler.java b/java/debugger/impl/src/com/intellij/debugger/actions/JavaMarkObjectActionHandler.java index 18e54211dc45..5fe4804736bb 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/JavaMarkObjectActionHandler.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/JavaMarkObjectActionHandler.java @@ -44,7 +44,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.Collections; import java.util.List; import java.util.Map; @@ -205,20 +204,11 @@ public class JavaMarkObjectActionHandler extends MarkObjectActionHandler { } private static List getReferringObjects(ObjectReference value) { - // invoke the following method using Reflection in order to remain compilable on jdk 1.5 - // java.util.List referringObjects(long l); try { - final Method apiMethod = ObjectReference.class.getMethod("referringObjects", long.class); - //noinspection unchecked - return (List)apiMethod.invoke(value, AUTO_MARKUP_REFERRING_OBJECTS_LIMIT); + return value.referringObjects(AUTO_MARKUP_REFERRING_OBJECTS_LIMIT); } - catch (IllegalAccessException e) { - LOG.error(e); // should not happen - } - catch (InvocationTargetException e) { - throw new RuntimeException(e); - } - catch (NoSuchMethodException ignored) { + catch (UnsupportedOperationException e) { + LOG.info(e); } return Collections.emptyList(); } From 5a62c6f74f5b49d75799f290156a3b92885187b4 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Wed, 11 May 2011 20:30:46 +0200 Subject: [PATCH 167/250] use explicit method toExternalForm() instead of toString() invocation when externalizing TextWithImports objects --- .../debugger/engine/evaluation/TextWithImportsImpl.java | 9 ++++++--- .../com/intellij/debugger/impl/DebuggerUtilsImpl.java | 4 ++-- .../debugger/settings/CompoundRendererConfigurable.java | 2 +- .../com/intellij/debugger/ui/breakpoints/Breakpoint.java | 2 +- .../debugger/ui/breakpoints/FilteredRequestor.java | 2 +- .../debugger/engine/evaluation/TextWithImports.java | 9 ++++++++- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java index 87ee0491bfbe..f60ab7f2eaaa 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java @@ -23,13 +23,12 @@ import com.intellij.psi.PsiExpressionCodeFragment; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; -public class TextWithImportsImpl implements TextWithImports{ +public final class TextWithImportsImpl implements TextWithImports{ private final CodeFragmentKind myKind; private String myText; private final String myImports; - public TextWithImportsImpl (PsiExpression expression) { myKind = CodeFragmentKind.EXPRESSION; final String text = expression.getText(); @@ -92,9 +91,13 @@ public class TextWithImportsImpl implements TextWithImports{ } public String toString() { + return getText(); + } + + public String toExternalForm() { return "".equals(myImports) ? myText : myText + DebuggerEditorImpl.SEPARATOR + myImports; } - + public int hashCode() { return myText.hashCode(); } diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java index a03cd3b99eac..269799d07624 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java @@ -66,7 +66,7 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{ public Element writeTextWithImports(TextWithImports text) { Element element = new Element("TextWithImports"); - element.setAttribute("text", text.toString()); + element.setAttribute("text", text.toExternalForm()); element.setAttribute("type", text.getKind() == CodeFragmentKind.EXPRESSION ? "expression" : "code fragment"); return element; } @@ -85,7 +85,7 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{ public void writeTextWithImports(Element root, String name, TextWithImports value) { LOG.assertTrue(value.getKind() == CodeFragmentKind.EXPRESSION); - JDOMExternalizerUtil.writeField(root, name, value.toString()); + JDOMExternalizerUtil.writeField(root, name, value.toExternalForm()); } public TextWithImports readTextWithImports(Element root, String name) { diff --git a/java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java b/java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java index d28dbb4a02ec..df2b69812114 100644 --- a/java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java +++ b/java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java @@ -210,7 +210,7 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable{ exprColumn.setCellRenderer(new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final TextWithImports textWithImports = (TextWithImports)value; - String text = (textWithImports != null)? textWithImports.toString() : ""; + final String text = (textWithImports != null)? textWithImports.getText() : ""; return super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column); } }); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java index 0dafd39824e5..0943b4f3e658 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java @@ -260,7 +260,7 @@ public abstract class Breakpoint extends FilteredRequestor implements ClassPrepa public void writeExternal(Element parentNode) throws WriteExternalException { super.writeExternal(parentNode); - JDOMExternalizerUtil.writeField(parentNode, LOG_MESSAGE_OPTION_NAME, getLogMessage().toString()); + JDOMExternalizerUtil.writeField(parentNode, LOG_MESSAGE_OPTION_NAME, getLogMessage().toExternalForm()); } public TextWithImports getLogMessage() { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestor.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestor.java index f402dd47ac58..ce09ba5a67a8 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestor.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/FilteredRequestor.java @@ -143,7 +143,7 @@ public abstract class FilteredRequestor implements LocatableEventRequestor, JDOM public void writeExternal(Element parentNode) throws WriteExternalException { DefaultJDOMExternalizer.writeExternal(this, parentNode); - JDOMExternalizerUtil.writeField(parentNode, CONDITION_OPTION_NAME, getCondition().toString()); + JDOMExternalizerUtil.writeField(parentNode, CONDITION_OPTION_NAME, getCondition().toExternalForm()); DebuggerUtilsEx.writeFilters(parentNode, FILTER_OPTION_NAME, myClassFilters); DebuggerUtilsEx.writeFilters(parentNode, EXCLUSION_FILTER_OPTION_NAME, myClassExclusionFilters); DebuggerUtilsEx.writeFilters(parentNode, INSTANCE_ID_OPTION_NAME, InstanceFilter.createClassFilters(myInstanceFilters)); diff --git a/java/debugger/openapi/src/com/intellij/debugger/engine/evaluation/TextWithImports.java b/java/debugger/openapi/src/com/intellij/debugger/engine/evaluation/TextWithImports.java index 1f4b6883b92e..95cf9946c064 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/engine/evaluation/TextWithImports.java +++ b/java/debugger/openapi/src/com/intellij/debugger/engine/evaluation/TextWithImports.java @@ -19,8 +19,15 @@ import org.jetbrains.annotations.NotNull; public interface TextWithImports { String getText(); + void setText(String newText); - @NotNull String getImports(); + + @NotNull + String getImports(); + CodeFragmentKind getKind(); + boolean isEmpty(); + + String toExternalForm(); } From de0eaa8ad989cc343c357334cfb58a7e28ddab66 Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Wed, 11 May 2011 20:58:16 +0400 Subject: [PATCH 168/250] workaround for situation when user launches inspection tool for directory based project, which hasn't been ever opened/imported with IDEA --- .../src/com/intellij/conversion/impl/ConversionContextImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ConversionContextImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/ConversionContextImpl.java index bb02cadb6225..7a78fdc6fdc5 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ConversionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ConversionContextImpl.java @@ -84,7 +84,7 @@ public class ConversionContextImpl implements ConversionContext { myWorkspaceFile = new File(StringUtil.trimEnd(projectPath, ProjectFileType.DOT_DEFAULT_EXTENSION) + WorkspaceFileType.DOT_DEFAULT_EXTENSION); } - myModuleFiles = findModuleFiles(JDomConvertingUtil.loadDocument(modulesFile).getRootElement()); + myModuleFiles = modulesFile.exists() ? findModuleFiles(JDomConvertingUtil.loadDocument(modulesFile).getRootElement()) : new File[0]; } public Set getAllProjectFiles() { From 45040495e717a21949b67a03f8c90dbeff104213 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Wed, 11 May 2011 13:11:38 +0400 Subject: [PATCH 169/250] no usages found --- .../util/xmlb/annotations/Collection.java | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 platform/util/src/com/intellij/util/xmlb/annotations/Collection.java diff --git a/platform/util/src/com/intellij/util/xmlb/annotations/Collection.java b/platform/util/src/com/intellij/util/xmlb/annotations/Collection.java deleted file mode 100644 index 97888bb29ec4..000000000000 --- a/platform/util/src/com/intellij/util/xmlb/annotations/Collection.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2000-2009 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.util.xmlb.annotations; - -public @interface Collection { -} From ab3650db7a259b25bbf62afdf3c9edd95d0909af Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Wed, 11 May 2011 14:42:13 +0400 Subject: [PATCH 170/250] ElementPatternBean extracted & lazy PsiReferenceProviderBean --- .../completion/WordCompletionTest.java | 2 +- .../intellij/patterns/ElementPatternBean.java | 38 +++++++++++++++ .../intellij/psi/PsiReferenceContributor.java | 3 ++ .../intellij/psi/PsiReferenceProvider.java | 2 + .../psi/PsiReferenceProviderBean.java | 47 +++++++++++-------- .../psi/PsiReferenceContributorImpl.java | 44 ----------------- .../reference/ReferenceProvidersRegistry.java | 47 +++++++++++++++++-- .../src/META-INF/LangExtensions.xml | 2 - 8 files changed, 114 insertions(+), 71 deletions(-) create mode 100644 platform/lang-api/src/com/intellij/patterns/ElementPatternBean.java rename platform/{lang-impl => lang-api}/src/com/intellij/psi/PsiReferenceProviderBean.java (59%) delete mode 100644 platform/lang-impl/src/com/intellij/psi/PsiReferenceContributorImpl.java diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/WordCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/WordCompletionTest.java index 87bbd9b94ad6..1dcef334633d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/WordCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/WordCompletionTest.java @@ -71,7 +71,7 @@ public class WordCompletionTest extends CompletionTestCase { } }; PsiReferenceRegistrarImpl registrar = - (PsiReferenceRegistrarImpl)ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA); + ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA); try { registrar.registerReferenceProvider(PsiLiteralExpression.class, softProvider); registrar.registerReferenceProvider(PsiLiteralExpression.class, hardProvider); diff --git a/platform/lang-api/src/com/intellij/patterns/ElementPatternBean.java b/platform/lang-api/src/com/intellij/patterns/ElementPatternBean.java new file mode 100644 index 000000000000..354524c9e6fc --- /dev/null +++ b/platform/lang-api/src/com/intellij/patterns/ElementPatternBean.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2011 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.patterns; + +import com.intellij.patterns.compiler.PatternCompilerFactory; +import com.intellij.psi.PsiElement; +import com.intellij.util.xmlb.annotations.Attribute; +import com.intellij.util.xmlb.annotations.Tag; +import com.intellij.util.xmlb.annotations.Text; +import org.jetbrains.annotations.Nullable; + +@Tag("pattern") +public class ElementPatternBean { + + @Attribute("type") + public String type; + + @Text + public String text; + + @Nullable + public ElementPattern compilePattern() { + return PatternCompilerFactory.getFactory().getPatternCompiler(type).compileElementPattern(text); + } +} diff --git a/platform/lang-api/src/com/intellij/psi/PsiReferenceContributor.java b/platform/lang-api/src/com/intellij/psi/PsiReferenceContributor.java index 04d5e2f79646..55f4f0d1d8aa 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiReferenceContributor.java +++ b/platform/lang-api/src/com/intellij/psi/PsiReferenceContributor.java @@ -15,7 +15,10 @@ import com.intellij.openapi.extensions.ExtensionPointName; * Some elements return them from {@link PsiElement#getReferences()} directly though, but one should not rely on that * behavior since it may be changed in the future. * + * The alternative way to register {@link PsiReferenceProvider} is by using {@link PsiReferenceProviderBean}. + * * @author peter + * @see PsiReferenceProviderBean */ public abstract class PsiReferenceContributor implements Disposable { public static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.psi.referenceContributor"); diff --git a/platform/lang-api/src/com/intellij/psi/PsiReferenceProvider.java b/platform/lang-api/src/com/intellij/psi/PsiReferenceProvider.java index e6dcea63dc81..799428dbd824 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiReferenceProvider.java +++ b/platform/lang-api/src/com/intellij/psi/PsiReferenceProvider.java @@ -20,6 +20,8 @@ import com.intellij.util.ProcessingContext; import org.jetbrains.annotations.NotNull; /** + * Register it via {@link PsiReferenceContributor} or {@link PsiReferenceProviderBean#EP_NAME} + * * @author ik */ public abstract class PsiReferenceProvider { diff --git a/platform/lang-impl/src/com/intellij/psi/PsiReferenceProviderBean.java b/platform/lang-api/src/com/intellij/psi/PsiReferenceProviderBean.java similarity index 59% rename from platform/lang-impl/src/com/intellij/psi/PsiReferenceProviderBean.java rename to platform/lang-api/src/com/intellij/psi/PsiReferenceProviderBean.java index ec4b893043c5..643ff81c622d 100644 --- a/platform/lang-impl/src/com/intellij/psi/PsiReferenceProviderBean.java +++ b/platform/lang-api/src/com/intellij/psi/PsiReferenceProviderBean.java @@ -19,27 +19,41 @@ package com.intellij.psi; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.AbstractExtensionPointBean; +import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.patterns.ElementPattern; +import com.intellij.patterns.ElementPatternBean; import com.intellij.patterns.StandardPatterns; -import com.intellij.patterns.compiler.PatternCompilerFactory; -import com.intellij.util.xmlb.annotations.*; +import com.intellij.util.NullableFunction; +import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.xmlb.annotations.AbstractCollection; +import com.intellij.util.xmlb.annotations.Attribute; +import com.intellij.util.xmlb.annotations.Property; +import com.intellij.util.xmlb.annotations.Tag; import org.jetbrains.annotations.Nullable; +/** + * Registers a {@link PsiReferenceProvider} in plugin.xml + */ public class PsiReferenceProviderBean extends AbstractExtensionPointBean { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.PsiReferenceProviderBean"); + + public static final ExtensionPointName EP_NAME = + new ExtensionPointName("com.intellij.psi.referenceProvider"); @Attribute("providerClass") public String className; + @Tag("description") public String description; @Property(surroundWithTag = false) @AbstractCollection(surroundWithTag = false) - public Info[] patterns; + public ElementPatternBean[] patterns; public String getDescription() { return description; } + private static final Logger LOG = Logger.getInstance("#com.intellij.psi.PsiReferenceProviderBean"); + public PsiReferenceProvider instantiate() { try { return (PsiReferenceProvider)instantiate(className, ApplicationManager.getApplication().getPicoContainer()); @@ -50,30 +64,25 @@ public class PsiReferenceProviderBean extends AbstractExtensionPointBean { return null; } + private static final NullableFunction> PATTERN_NULLABLE_FUNCTION = new NullableFunction>() { + @Override + public ElementPattern fun(ElementPatternBean elementPatternBean) { + return elementPatternBean.compilePattern(); + } + }; + @Nullable public ElementPattern createElementPattern() { - final PatternCompilerFactory factory = PatternCompilerFactory.getFactory(); if (patterns.length > 1) { - final ElementPattern[] result = new ElementPattern[this.patterns.length]; - for (int i = 0, len = this.patterns.length; i < len; i++) { - result[i] = factory.getPatternCompiler(patterns[i].type).compileElementPattern(patterns[i].text); - } - return StandardPatterns.or(result); + return StandardPatterns.or(ContainerUtil.mapNotNull(patterns, + PATTERN_NULLABLE_FUNCTION).toArray(new ElementPattern[0])); } else if (patterns.length == 1) { - return factory.getPatternCompiler(patterns[0].type).compileElementPattern(patterns[0].text); + return patterns[0].compilePattern(); } else { LOG.error("At least one pattern should be specified"); return null; } } - - @Tag("pattern") - public static class Info { - @Attribute("type") - public String type; - @Text - public String text; - } } diff --git a/platform/lang-impl/src/com/intellij/psi/PsiReferenceContributorImpl.java b/platform/lang-impl/src/com/intellij/psi/PsiReferenceContributorImpl.java deleted file mode 100644 index c937b32861c9..000000000000 --- a/platform/lang-impl/src/com/intellij/psi/PsiReferenceContributorImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2000-2010 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.extensions.ExtensionPointName; -import com.intellij.patterns.ElementPattern; - -/** - * @author Gregory.Shrago - */ -public class PsiReferenceContributorImpl extends PsiReferenceContributor { - - public static final ExtensionPointName PSI_REFERENCE_PROVIDERS_EP = - new ExtensionPointName("com.intellij.psi.referenceProvider"); - @Override - public void registerReferenceProviders(PsiReferenceRegistrar registrar) { - for (PsiReferenceProviderBean providerBean : PSI_REFERENCE_PROVIDERS_EP.getExtensions()) { - registerReferenceProvider(registrar, providerBean); - } - } - - private static void registerReferenceProvider(PsiReferenceRegistrar registrar, PsiReferenceProviderBean providerBean) { - final ElementPattern pattern = providerBean.createElementPattern(); - if (pattern != null) { - final PsiReferenceProvider provider = providerBean.instantiate(); - if (provider != null) { - registrar.registerReferenceProvider(pattern, provider); - } - } - } -} diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java index 868ab97bc056..b89a486980e7 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java @@ -22,6 +22,7 @@ import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.util.Trinity; +import com.intellij.patterns.ElementPattern; import com.intellij.psi.*; import com.intellij.util.ProcessingContext; import com.intellij.util.SmartList; @@ -52,9 +53,16 @@ public class ReferenceProvidersRegistry { return o2.getThird().compareTo(o1.getThird()); } }; + public final static PsiReferenceProvider NULL_REFERENCE_PROVIDER = new PsiReferenceProvider() { + @NotNull + @Override + public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { + return PsiReference.EMPTY_ARRAY; + } + }; @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"}) - private final static Map ourRegistrars = new FactoryMap() { + private final Map myRegistrars = new FactoryMap() { @Override protected PsiReferenceRegistrarImpl create(Language language) { PsiReferenceRegistrarImpl registrar = new PsiReferenceRegistrarImpl(); @@ -70,8 +78,36 @@ public class ReferenceProvidersRegistry { return ServiceManager.getService(ReferenceProvidersRegistry.class); } - public PsiReferenceRegistrar getRegistrar(Language language) { - return ourRegistrars.get(language); + public ReferenceProvidersRegistry() { + + PsiReferenceRegistrarImpl registrar = getRegistrar(Language.ANY); + for (final PsiReferenceProviderBean providerBean : PsiReferenceProviderBean.EP_NAME.getExtensions()) { + final ElementPattern pattern = providerBean.createElementPattern(); + if (pattern != null) { + registrar.registerReferenceProvider(pattern, new PsiReferenceProvider() { + + PsiReferenceProvider myProvider; + + @NotNull + @Override + public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { + if (myProvider == null) { + + myProvider = providerBean.instantiate(); + if (myProvider == null) { + myProvider = NULL_REFERENCE_PROVIDER; + } + } + return myProvider.getReferencesByElement(element, context); + } + }); + } + } + + } + + public PsiReferenceRegistrarImpl getRegistrar(Language language) { + return myRegistrars.get(language); } @Deprecated @@ -83,10 +119,11 @@ public class ReferenceProvidersRegistry { ProgressManager.checkCanceled(); assert context.isValid() : "Invalid context: " + context; - PsiReferenceRegistrarImpl registrar = ourRegistrars.get(context.getLanguage()); + ReferenceProvidersRegistry registry = getInstance(); + PsiReferenceRegistrarImpl registrar = registry.getRegistrar(context.getLanguage()); SmartList> providers = new SmartList>(); providers.addAll(registrar.getPairsByElement(context, hints)); - providers.addAll(ourRegistrars.get(Language.ANY).getPairsByElement(context, hints)); + providers.addAll(registry.getRegistrar(Language.ANY).getPairsByElement(context, hints)); if (providers.isEmpty()) { return PsiReference.EMPTY_ARRAY; } diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index ac366c2adff5..6a88f3bb4493 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -397,8 +397,6 @@ - - From 32c06226560b18fa6cee9b4b1172bf8f078f8218 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 12 May 2011 10:59:12 +0400 Subject: [PATCH 171/250] fix UI problems when switching LaFs --- .../NavBarRootPaneExtension.java | 83 +++++++++++-------- 1 file changed, 49 insertions(+), 34 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java index 0fe084574760..4b3b06b72ee2 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java @@ -25,6 +25,7 @@ import com.intellij.ide.ui.UISettingsListener; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ComboBoxAction; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.IdeRootPaneNorthExtension; @@ -48,6 +49,8 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { private NavBarPanel myNavigationBar; private JPanel myRunPanel; private boolean myNavToolbarGroupExist; + private JScrollPane myScrollPane; + private JLabel myCloseIcon; public NavBarRootPaneExtension(Project project) { myProject = project; @@ -122,7 +125,6 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { } }; myWrapperPanel.add(buildNavBarPanel(), BorderLayout.CENTER); - myWrapperPanel.putClientProperty("NavBarPanel", myNavigationBar); toggleRunPanel(!UISettings.getInstance().SHOW_MAIN_TOOLBAR); } @@ -185,6 +187,49 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { private JComponent buildNavBarPanel() { final JComponent result = new JPanel(new BorderLayout()) { + @Override + public void updateUI() { + super.updateUI(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + removeAll(); + myScrollPane = null; + myCloseIcon = null; + if (myNavigationBar != null && !Disposer.isDisposed(myNavigationBar)) { + Disposer.dispose(myNavigationBar); + } + myNavigationBar = new NavBarPanel(myProject); + myWrapperPanel.putClientProperty("NavBarPanel", myNavigationBar); + myNavigationBar.getModel().setFixedComponent(true); + + myScrollPane = ScrollPaneFactory.createScrollPane(myNavigationBar); + myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); + myScrollPane.setHorizontalScrollBar(null); + myScrollPane.setBorder(null); + + myScrollPane.setOpaque(false); + myScrollPane.getViewport().setOpaque(false); + + setBackground(UIUtil.isUnderGTKLookAndFeel() ? Color.WHITE : UIUtil.getListBackground()); + setOpaque(!UIUtil.isUnderAquaLookAndFeel() || UISettings.getInstance().SHOW_MAIN_TOOLBAR); + setBorder(UIUtil.isUnderAquaLookAndFeel() ? BorderFactory.createEmptyBorder(2, 0, 2, 4) : new NavBarBorder(true, 0)); + myNavigationBar.setBorder(null); + add(myScrollPane, BorderLayout.CENTER); + if (!SystemInfo.isMac) { + myCloseIcon = new JLabel(CROSS_ICON); + myCloseIcon.addMouseListener(new MouseAdapter() { + public void mouseClicked(final MouseEvent e) { + UISettings.getInstance().SHOW_NAVIGATION_BAR = false; + uiSettingsChanged(UISettings.getInstance()); + } + }); + add(myCloseIcon, BorderLayout.EAST); + } + } + }); + } + @Override protected void paintComponent(Graphics g) { if (UIUtil.isUnderAquaLookAndFeel()) { @@ -231,9 +276,9 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { final Rectangle r = getBounds(); final Insets insets = getInsets(); int x = insets.left; - - final Component navBar = getComponent(0); - final Component closeLabel = getComponentCount() == 2 ? getComponent(1) : null; + if (myScrollPane == null) return; + final Component navBar = myScrollPane; + final Component closeLabel = myCloseIcon; final Dimension preferredSize = navBar.getPreferredSize(); final Dimension closePreferredSize = closeLabel == null ? new Dimension() : closeLabel.getPreferredSize(); @@ -248,37 +293,7 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { } } }; - - result.setBackground(UIUtil.isUnderGTKLookAndFeel() ? Color.WHITE : UIUtil.getListBackground()); - result.setOpaque(!UIUtil.isUnderAquaLookAndFeel() || UISettings.getInstance().SHOW_MAIN_TOOLBAR); - - myNavigationBar = new NavBarPanel(myProject); - myNavigationBar.getModel().setFixedComponent(true); - - JScrollPane scroller = ScrollPaneFactory.createScrollPane(myNavigationBar); - scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); - scroller.setHorizontalScrollBar(null); - scroller.setBorder(null); - scroller.setOpaque(false); - scroller.getViewport().setOpaque(false); - - result.add(scroller, BorderLayout.CENTER); - - if (!SystemInfo.isMac) { - JLabel closeLabel = new JLabel(CROSS_ICON); - closeLabel.addMouseListener(new MouseAdapter() { - public void mouseClicked(final MouseEvent e) { - UISettings.getInstance().SHOW_NAVIGATION_BAR = false; - uiSettingsChanged(UISettings.getInstance()); - } - }); - result.add(closeLabel, BorderLayout.EAST); - } - - result.setBorder(UIUtil.isUnderAquaLookAndFeel() ? BorderFactory.createEmptyBorder(2, 0, 2, 4) : new NavBarBorder(true, 0)); - myNavigationBar.setBorder(null); - return result; } From 747646b98e1648d376fc4299b6c040f8abf79d25 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 12 May 2011 11:15:20 +0400 Subject: [PATCH 172/250] fix plugin downloader --- .../openapi/updateSettings/impl/PluginDownloader.java | 2 +- .../util/src/com/intellij/openapi/util/io/FileUtil.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java index d8ee30ef372b..a09ec5334bda 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java @@ -208,7 +208,7 @@ public class PluginDownloader { pluginsTemp.mkdirs(); } - File file = FileUtil.createTempFile(pluginsTemp, "plugin", "download", true); + File file = FileUtil.createTempFile(pluginsTemp, "plugin", "download", true, false); int responseCode = connection.getResponseCode(); switch (responseCode) { diff --git a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java index 6ea6291bff64..3690ce20398f 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java @@ -354,12 +354,18 @@ public class FileUtil { @NotNull public static File createTempFile(@NonNls final File dir, @NotNull @NonNls String prefix, @NonNls String suffix, final boolean create) throws IOException{ + return createTempFile(dir, prefix, suffix, create, true); + } + + public static File createTempFile(@NonNls final File dir, @NotNull @NonNls String prefix, @NonNls String suffix, final boolean create, boolean removeOnExit) throws IOException { File file = doCreateTempFile(prefix, suffix, dir); file.delete(); if (create) { file.createNewFile(); } - file.deleteOnExit(); + if (removeOnExit) { + file.deleteOnExit(); + } return file; } From c89bda4d6bafbb6722aab907f9065d96dfb1165b Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 12 May 2011 11:37:10 +0400 Subject: [PATCH 173/250] show project on empty frame --- .../src/com/intellij/ide/navigationToolbar/NavBarModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarModel.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarModel.java index 6aeef1d6dfd9..d7b23d3be7d7 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarModel.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarModel.java @@ -107,7 +107,7 @@ public class NavBarModel { updateModel(psiElement); } else { - if (UISettings.getInstance().SHOW_NAVIGATION_BAR) return; + if (UISettings.getInstance().SHOW_NAVIGATION_BAR && !myModel.isEmpty()) return; Object moduleOrProject = LangDataKeys.MODULE.getData(dataContext); if (moduleOrProject == null) { From 1aa7241d17ccf2a54d8cca05e79164bb559e0bfe Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 11 May 2011 13:06:21 +0400 Subject: [PATCH 174/250] Git: moved stash/shelve classes to git4idea.stash --- .../src/git4idea/checkin/GitPushActiveBranchesDialog.java | 3 +++ .../src/git4idea/checkout/branches/GitCheckoutProcess.java | 2 +- .../src/git4idea/{update => stash}/GitChangesSaver.java | 2 +- .../src/git4idea/{update => stash}/GitShelveChangesSaver.java | 2 +- .../src/git4idea/{update => stash}/GitStashChangesSaver.java | 2 +- .../git4idea/src/git4idea/{update => stash}/GitStashUtils.java | 2 +- plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java | 2 +- plugins/git4idea/src/git4idea/update/GitUpdateProcess.java | 1 + 8 files changed, 10 insertions(+), 6 deletions(-) rename plugins/git4idea/src/git4idea/{update => stash}/GitChangesSaver.java (99%) rename plugins/git4idea/src/git4idea/{update => stash}/GitShelveChangesSaver.java (99%) rename plugins/git4idea/src/git4idea/{update => stash}/GitStashChangesSaver.java (99%) rename plugins/git4idea/src/git4idea/{update => stash}/GitStashUtils.java (99%) diff --git a/plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java b/plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java index f6939e289a44..58260620f5f4 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java +++ b/plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java @@ -51,6 +51,9 @@ import git4idea.commands.*; import git4idea.config.GitVcsSettings; import git4idea.i18n.GitBundle; import git4idea.rebase.GitRebaser; +import git4idea.stash.GitChangesSaver; +import git4idea.stash.GitShelveChangesSaver; +import git4idea.stash.GitStashChangesSaver; import git4idea.ui.GitUIUtil; import git4idea.update.*; import org.jetbrains.annotations.NotNull; diff --git a/plugins/git4idea/src/git4idea/checkout/branches/GitCheckoutProcess.java b/plugins/git4idea/src/git4idea/checkout/branches/GitCheckoutProcess.java index f0616594052a..b228b195f177 100644 --- a/plugins/git4idea/src/git4idea/checkout/branches/GitCheckoutProcess.java +++ b/plugins/git4idea/src/git4idea/checkout/branches/GitCheckoutProcess.java @@ -44,8 +44,8 @@ import git4idea.checkout.branches.GitBranchConfigurations.BranchChanges; import git4idea.checkout.branches.GitBranchConfigurations.ChangeInfo; import git4idea.checkout.branches.GitBranchConfigurations.ChangeListInfo; import git4idea.commands.*; +import git4idea.stash.GitStashUtils; import git4idea.ui.GitUIUtil; -import git4idea.update.GitStashUtils; import org.jetbrains.annotations.Nullable; import java.io.File; diff --git a/plugins/git4idea/src/git4idea/update/GitChangesSaver.java b/plugins/git4idea/src/git4idea/stash/GitChangesSaver.java similarity index 99% rename from plugins/git4idea/src/git4idea/update/GitChangesSaver.java rename to plugins/git4idea/src/git4idea/stash/GitChangesSaver.java index cd275d55b89a..69cbdf1c7fb0 100644 --- a/plugins/git4idea/src/git4idea/update/GitChangesSaver.java +++ b/plugins/git4idea/src/git4idea/stash/GitChangesSaver.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.update; +package git4idea.stash; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; diff --git a/plugins/git4idea/src/git4idea/update/GitShelveChangesSaver.java b/plugins/git4idea/src/git4idea/stash/GitShelveChangesSaver.java similarity index 99% rename from plugins/git4idea/src/git4idea/update/GitShelveChangesSaver.java rename to plugins/git4idea/src/git4idea/stash/GitShelveChangesSaver.java index 57000d3eebad..2e37e16df698 100644 --- a/plugins/git4idea/src/git4idea/update/GitShelveChangesSaver.java +++ b/plugins/git4idea/src/git4idea/stash/GitShelveChangesSaver.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.update; +package git4idea.stash; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; diff --git a/plugins/git4idea/src/git4idea/update/GitStashChangesSaver.java b/plugins/git4idea/src/git4idea/stash/GitStashChangesSaver.java similarity index 99% rename from plugins/git4idea/src/git4idea/update/GitStashChangesSaver.java rename to plugins/git4idea/src/git4idea/stash/GitStashChangesSaver.java index e9b323e94d77..ca8f4120ed40 100644 --- a/plugins/git4idea/src/git4idea/update/GitStashChangesSaver.java +++ b/plugins/git4idea/src/git4idea/stash/GitStashChangesSaver.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.update; +package git4idea.stash; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; diff --git a/plugins/git4idea/src/git4idea/update/GitStashUtils.java b/plugins/git4idea/src/git4idea/stash/GitStashUtils.java similarity index 99% rename from plugins/git4idea/src/git4idea/update/GitStashUtils.java rename to plugins/git4idea/src/git4idea/stash/GitStashUtils.java index 2c42bf58ff1c..3bfc731c3109 100644 --- a/plugins/git4idea/src/git4idea/update/GitStashUtils.java +++ b/plugins/git4idea/src/git4idea/stash/GitStashUtils.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.update; +package git4idea.stash; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; diff --git a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java index 36865fd50fdb..820749a286c6 100644 --- a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java +++ b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java @@ -33,7 +33,7 @@ import git4idea.actions.GitShowAllSubmittedFilesAction; import git4idea.commands.*; import git4idea.config.GitVersionSpecialty; import git4idea.i18n.GitBundle; -import git4idea.update.GitStashUtils; +import git4idea.stash.GitStashUtils; import git4idea.validators.GitBranchNameValidator; import org.jetbrains.annotations.NotNull; diff --git a/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java b/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java index 1b5a53be66b2..ab4dba37129d 100644 --- a/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java +++ b/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java @@ -35,6 +35,7 @@ import git4idea.merge.GitMergeConflictResolver; import git4idea.merge.GitMergeUtil; import git4idea.merge.GitMerger; import git4idea.rebase.GitRebaser; +import git4idea.stash.GitChangesSaver; import git4idea.ui.GitUIUtil; import org.jetbrains.annotations.NotNull; From 36f3599debd08550da4d4afcce7631a99a41994d Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 11 May 2011 13:18:44 +0400 Subject: [PATCH 175/250] Git: move shelving from GitStashUtils to GitShelveUtils --- .../checkout/branches/GitCheckoutProcess.java | 97 ++++----- .../git4idea/stash/GitShelveChangesSaver.java | 4 +- .../src/git4idea/stash/GitShelveUtils.java | 192 ++++++++++++++++++ .../src/git4idea/stash/GitStashUtils.java | 164 --------------- 4 files changed, 243 insertions(+), 214 deletions(-) create mode 100644 plugins/git4idea/src/git4idea/stash/GitShelveUtils.java diff --git a/plugins/git4idea/src/git4idea/checkout/branches/GitCheckoutProcess.java b/plugins/git4idea/src/git4idea/checkout/branches/GitCheckoutProcess.java index b228b195f177..c44a1deeafbb 100644 --- a/plugins/git4idea/src/git4idea/checkout/branches/GitCheckoutProcess.java +++ b/plugins/git4idea/src/git4idea/checkout/branches/GitCheckoutProcess.java @@ -44,7 +44,7 @@ import git4idea.checkout.branches.GitBranchConfigurations.BranchChanges; import git4idea.checkout.branches.GitBranchConfigurations.ChangeInfo; import git4idea.checkout.branches.GitBranchConfigurations.ChangeListInfo; import git4idea.commands.*; -import git4idea.stash.GitStashUtils; +import git4idea.stash.GitShelveUtils; import git4idea.ui.GitUIUtil; import org.jetbrains.annotations.Nullable; @@ -591,52 +591,53 @@ public class GitCheckoutProcess { }; continuation.addExceptionHandler(VcsException.class, exceptionConsumer); final GatheringContinuationContext initContext = new GatheringContinuationContext(); - GitStashUtils.doSystemUnshelve(myProject, shelve, myShelveManager, new Runnable() { - @Override - public void run() { - final HashMap, String> parsedChanges = new HashMap, String>(); - for (ChangeInfo changeInfo : changes.CHANGES) { - String before = changeInfo.BEFORE_PATH; - String after = changeInfo.AFTER_PATH; - parsedChanges.put(Pair.create(before, after), changeInfo.CHANGE_LIST_NAME); - } - try { - HashMap lists = new HashMap(); - final List existedChangeLists = myChangeManager.getChangeLists(); - for (LocalChangeList localChangeList : existedChangeLists) { - lists.put(localChangeList.getName(), localChangeList); - } - LocalChangeList defaultList = myChangeManager.getDefaultChangeList(); - for (ChangeListInfo changeListInfo : changes.CHANGE_LISTS) { - LocalChangeList changeList = lists.get(changeListInfo.NAME); - if (changeList == null) { - changeList = myChangeManager.addChangeList(changeListInfo.NAME, changeListInfo.COMMENT); - lists.put(changeListInfo.NAME, changeList); - } - if (changeListInfo.IS_DEFAULT) { - myChangeManager.setDefaultChangeList(changeList); - } - } - for (Change change : defaultList.getChanges()) { - ContentRevision beforeRevision = change.getBeforeRevision(); - String before = beforeRevision == null ? null : beforeRevision.getFile().getPath(); - ContentRevision afterRevision = change.getAfterRevision(); - String after = afterRevision == null ? null : afterRevision.getFile().getPath(); - Pair key = Pair.create(before, after); - String listName = parsedChanges.get(key); - assert listName != null : "List name should be found: " + key; - if (!listName.equals(defaultList.getName())) { - LocalChangeList changeList = lists.get(listName); - assert changeList != null : "Change List should be found: " + listName; - myChangeManager.moveChangesTo(changeList, new Change[]{change}); - } - } - } - catch (Throwable t) { - exceptionConsumer.consume(new VcsException(t)); - } - } - }, initContext); + GitShelveUtils.doSystemUnshelve(myProject, shelve, myShelveManager, new Runnable() { + @Override + public void run() { + final HashMap, String> parsedChanges = + new HashMap, String>(); + for (ChangeInfo changeInfo : changes.CHANGES) { + String before = changeInfo.BEFORE_PATH; + String after = changeInfo.AFTER_PATH; + parsedChanges.put(Pair.create(before, after), changeInfo.CHANGE_LIST_NAME); + } + try { + HashMap lists = new HashMap(); + final List existedChangeLists = myChangeManager.getChangeLists(); + for (LocalChangeList localChangeList : existedChangeLists) { + lists.put(localChangeList.getName(), localChangeList); + } + LocalChangeList defaultList = myChangeManager.getDefaultChangeList(); + for (ChangeListInfo changeListInfo : changes.CHANGE_LISTS) { + LocalChangeList changeList = lists.get(changeListInfo.NAME); + if (changeList == null) { + changeList = myChangeManager.addChangeList(changeListInfo.NAME, changeListInfo.COMMENT); + lists.put(changeListInfo.NAME, changeList); + } + if (changeListInfo.IS_DEFAULT) { + myChangeManager.setDefaultChangeList(changeList); + } + } + for (Change change : defaultList.getChanges()) { + ContentRevision beforeRevision = change.getBeforeRevision(); + String before = beforeRevision == null ? null : beforeRevision.getFile().getPath(); + ContentRevision afterRevision = change.getAfterRevision(); + String after = afterRevision == null ? null : afterRevision.getFile().getPath(); + Pair key = Pair.create(before, after); + String listName = parsedChanges.get(key); + assert listName != null : "List name should be found: " + key; + if (!listName.equals(defaultList.getName())) { + LocalChangeList changeList = lists.get(listName); + assert changeList != null : "Change List should be found: " + listName; + myChangeManager.moveChangesTo(changeList, new Change[]{change}); + } + } + } + catch (Throwable t) { + exceptionConsumer.consume(new VcsException(t)); + } + } + }, initContext); continuation.run(initContext.getList()); } @@ -742,7 +743,7 @@ public class GitCheckoutProcess { if (progress != null) { progress.setText("Creating shelve: " + description); } - ShelvedChangeList shelved = GitStashUtils.shelveChanges(myProject, myShelveManager, toShelve, description, myExceptions); + ShelvedChangeList shelved = GitShelveUtils.shelveChanges(myProject, myShelveManager, toShelve, description, myExceptions); if (shelved == null) { return null; } diff --git a/plugins/git4idea/src/git4idea/stash/GitShelveChangesSaver.java b/plugins/git4idea/src/git4idea/stash/GitShelveChangesSaver.java index 2e37e16df698..0dd56f9d70ab 100644 --- a/plugins/git4idea/src/git4idea/stash/GitShelveChangesSaver.java +++ b/plugins/git4idea/src/git4idea/stash/GitShelveChangesSaver.java @@ -62,7 +62,7 @@ public class GitShelveChangesSaver extends GitChangesSaver { String oldProgressTitle = myProgressIndicator.getText(); myProgressIndicator.setText(GitBundle.getString("update.shelving.changes")); List exceptions = new ArrayList(1); - myShelvedChangeList = GitStashUtils.shelveChanges(myProject, myShelveManager, changes, myStashMessage, exceptions); + myShelvedChangeList = GitShelveUtils.shelveChanges(myProject, myShelveManager, changes, myStashMessage, exceptions); myProgressIndicator.setText(oldProgressTitle); if (!exceptions.isEmpty()) { LOG.info("save " + exceptions, exceptions.get(0)); @@ -77,7 +77,7 @@ public class GitShelveChangesSaver extends GitChangesSaver { String oldProgressTitle = myProgressIndicator.getText(); myProgressIndicator.setText(GitBundle.getString("update.unshelving.changes")); if (myShelvedChangeList != null) { - GitStashUtils.doSystemUnshelve(myProject, myShelvedChangeList, myShelveManager, restoreListsRunnable, context); + GitShelveUtils.doSystemUnshelve(myProject, myShelvedChangeList, myShelveManager, restoreListsRunnable, context); } myProgressIndicator.setText(oldProgressTitle); } diff --git a/plugins/git4idea/src/git4idea/stash/GitShelveUtils.java b/plugins/git4idea/src/git4idea/stash/GitShelveUtils.java new file mode 100644 index 000000000000..6a9f76655236 --- /dev/null +++ b/plugins/git4idea/src/git4idea/stash/GitShelveUtils.java @@ -0,0 +1,192 @@ +/* + * Copyright 2000-2011 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 git4idea.stash; + +import com.intellij.openapi.application.ModalityState; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.progress.AsynchronousExecution; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vcs.AbstractVcsHelper; +import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.FileStatus; +import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vcs.changes.Change; +import com.intellij.openapi.vcs.changes.ChangeListManager; +import com.intellij.openapi.vcs.changes.InvokeAfterUpdateMode; +import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; +import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager; +import com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryFile; +import com.intellij.openapi.vcs.changes.shelf.ShelvedChange; +import com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.continuation.ContinuationContext; +import com.intellij.util.continuation.TaskDescriptor; +import com.intellij.util.continuation.Where; +import com.intellij.vcsUtil.VcsUtil; +import git4idea.GitUtil; +import git4idea.GitVcs; +import git4idea.commands.GitFileUtils; +import git4idea.vfs.GitVFSListener; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.event.ChangeEvent; +import java.io.File; +import java.io.IOException; +import java.util.*; + +/** + * @author Kirill Likhodedov + */ +public class GitShelveUtils { + private static final Logger LOG = Logger.getInstance(GitShelveUtils.class.getName()); + + /** + * Perform system level unshelve operation + * + * @param project the project + * @param shelvedChangeList the shelved change list + * @param shelveManager the shelve manager + * @param restoreListsRunnable + */ + @AsynchronousExecution + public static void doSystemUnshelve(final Project project, + final ShelvedChangeList shelvedChangeList, + final ShelveChangesManager shelveManager, + @NotNull final Runnable restoreListsRunnable, + final @NotNull ContinuationContext context) { + VirtualFile baseDir = project.getBaseDir(); + assert baseDir != null; + final String projectPath = baseDir.getPath() + "/"; + + context.next(new TaskDescriptor("Refreshing files before unshelve", Where.POOLED) { + @Override + public void run(ContinuationContext context) { + LOG.info("doSystemUnshelve "); + // The changes are temporary copied to the first local change list, the next operation will restore them back + // Refresh files that might be affected by unshelve + refreshFilesBeforeUnshelve(shelvedChangeList, projectPath); + + LOG.info("doSystemUnshelve files refreshed. unshelving in AWT thread."); + } + }, new TaskDescriptor("", Where.AWT) { + @Override + public void run(ContinuationContext context) { + GitVFSListener l = GitVcs.getInstance(project).getVFSListener(); + l.setEventsSuppressed(true); + + LOG.info("Unshelving in UI thread. shelvedChangeList: " + shelvedChangeList); + // we pass null as target change list for Patch Applier to do NOTHING with change lists + shelveManager.scheduleUnshelveChangeList(shelvedChangeList, shelvedChangeList.getChanges(), + shelvedChangeList.getBinaryFiles(), null, false, context); + } + }, new TaskDescriptor("", Where.AWT) { + @Override + public void run(ContinuationContext context) { + GitVcs.getInstance(project).getVFSListener().setEventsSuppressed(false); + addFilesAfterUnshelve(project, shelvedChangeList, projectPath, context); + ChangeListManager.getInstance(project).invokeAfterUpdate(new Runnable() { + @Override + public void run() { + restoreListsRunnable.run(); + } + }, InvokeAfterUpdateMode.BACKGROUND_NOT_CANCELLABLE_NOT_AWT, "Restoring changelists", ModalityState.NON_MODAL); + } + }); + } + + public static void addFilesAfterUnshelve(Project project, + ShelvedChangeList shelvedChangeList, + String projectPath, ContinuationContext context) { + Collection paths = new ArrayList(); + for (ShelvedChange c : shelvedChangeList.getChanges()) { + if (c.getBeforePath() == null || !c.getBeforePath().equals(c.getAfterPath()) || c.getFileStatus() == FileStatus.ADDED) { + paths.add(VcsUtil.getFilePath(projectPath + c.getAfterPath())); + } + } + for (ShelvedBinaryFile f : shelvedChangeList.getBinaryFiles()) { + if (f.BEFORE_PATH == null || !f.BEFORE_PATH.equals(f.AFTER_PATH) || f.getFileStatus() == FileStatus.ADDED) { + paths.add(VcsUtil.getFilePath(projectPath + f.AFTER_PATH)); + } + } + final VcsDirtyScopeManager dsm = VcsDirtyScopeManager.getInstance(project); + Map> map = GitUtil.sortGitFilePathsByGitRoot(paths); + for (Map.Entry> e : map.entrySet()) { + try { + GitFileUtils.addPaths(project, e.getKey(), e.getValue()); + dsm.filePathsDirty(e.getValue(), null); + } + catch (VcsException e1) { + if (! context.handleException(e1)) { + AbstractVcsHelper.getInstance(project).showError(e1, "Can not add file to Git"); + LOG.error("Vcs Exception not handled"); + } + } + } + } + + public static void refreshFilesBeforeUnshelve(ShelvedChangeList shelvedChangeList, String projectPath) { + HashSet filesToRefresh = new HashSet(); + for (ShelvedChange c : shelvedChangeList.getChanges()) { + if (c.getBeforePath() != null) { + filesToRefresh.add(new File(projectPath + c.getBeforePath())); + } + if (c.getAfterPath() != null) { + filesToRefresh.add(new File(projectPath + c.getAfterPath())); + } + } + for (ShelvedBinaryFile f : shelvedChangeList.getBinaryFiles()) { + if (f.BEFORE_PATH != null) { + filesToRefresh.add(new File(projectPath + f.BEFORE_PATH)); + } + if (f.AFTER_PATH != null) { + filesToRefresh.add(new File(projectPath + f.BEFORE_PATH)); + } + } + LocalFileSystem.getInstance().refreshIoFiles(filesToRefresh); + } + + /** + * Shelve changes + * + * @param project the context project + * @param shelveManager the shelve manager + * @param changes the changes to process + * @param description the description of for the shelve + * @param exceptions the generated exceptions + * @return created shelved change list or null in case failure + */ + @Nullable + public static ShelvedChangeList shelveChanges(final Project project, final ShelveChangesManager shelveManager, Collection changes, + final String description, + final List exceptions) { + try { + ShelvedChangeList shelve = shelveManager.shelveChanges(changes, description); + project.getMessageBus().syncPublisher(ShelveChangesManager.SHELF_TOPIC).stateChanged(new ChangeEvent(GitStashUtils.class)); + return shelve; + } + catch (IOException e) { + //noinspection ThrowableInstanceNeverThrown + exceptions.add(new VcsException("Shelving changes failed: " + description, e)); + return null; + } + catch (VcsException e) { + exceptions.add(e); + return null; + } + } +} diff --git a/plugins/git4idea/src/git4idea/stash/GitStashUtils.java b/plugins/git4idea/src/git4idea/stash/GitStashUtils.java index 3bfc731c3109..89b3b8ca704c 100644 --- a/plugins/git4idea/src/git4idea/stash/GitStashUtils.java +++ b/plugins/git4idea/src/git4idea/stash/GitStashUtils.java @@ -15,48 +15,20 @@ */ package git4idea.stash; -import com.intellij.openapi.application.ModalityState; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.progress.AsynchronousExecution; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.AbstractVcsHelper; -import com.intellij.openapi.vcs.FilePath; -import com.intellij.openapi.vcs.FileStatus; import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.changes.Change; -import com.intellij.openapi.vcs.changes.ChangeListManager; -import com.intellij.openapi.vcs.changes.InvokeAfterUpdateMode; -import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; -import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager; -import com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryFile; -import com.intellij.openapi.vcs.changes.shelf.ShelvedChange; -import com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList; -import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Consumer; -import com.intellij.util.continuation.ContinuationContext; -import com.intellij.util.continuation.TaskDescriptor; -import com.intellij.util.continuation.Where; -import com.intellij.vcsUtil.VcsUtil; -import git4idea.GitUtil; -import git4idea.GitVcs; import git4idea.commands.GitCommand; -import git4idea.commands.GitFileUtils; import git4idea.commands.GitSimpleHandler; import git4idea.commands.StringScanner; import git4idea.config.GitConfigUtil; import git4idea.config.GitVersion; import git4idea.ui.GitUIUtil; import git4idea.ui.StashInfo; -import git4idea.vfs.GitVFSListener; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import javax.swing.event.ChangeEvent; -import java.io.File; -import java.io.IOException; import java.nio.charset.Charset; -import java.util.*; /** * The class contains utilities for creating and removing stashes. @@ -66,7 +38,6 @@ public class GitStashUtils { * The version when quiet stash supported */ private final static GitVersion QUIET_STASH_SUPPORTED = new GitVersion(1, 6, 4, 0); - private static final Logger LOG = Logger.getInstance(GitStashUtils.class.getName()); private GitStashUtils() { } @@ -110,139 +81,4 @@ public class GitStashUtils { consumer.consume(new StashInfo(s.boundedToken(':'), s.boundedToken(':'), s.line().trim())); } } - - /** - * Perform system level unshelve operation - * - * @param project the project - * @param shelvedChangeList the shelved change list - * @param shelveManager the shelve manager - * @param restoreListsRunnable - */ - @AsynchronousExecution - public static void doSystemUnshelve(final Project project, - final ShelvedChangeList shelvedChangeList, - final ShelveChangesManager shelveManager, - @NotNull final Runnable restoreListsRunnable, - final @NotNull ContinuationContext context) { - VirtualFile baseDir = project.getBaseDir(); - assert baseDir != null; - final String projectPath = baseDir.getPath() + "/"; - - context.next(new TaskDescriptor("Refreshing files before unshelve", Where.POOLED) { - @Override - public void run(ContinuationContext context) { - LOG.info("doSystemUnshelve "); - // The changes are temporary copied to the first local change list, the next operation will restore them back - // Refresh files that might be affected by unshelve - refreshFilesBeforeUnshelve(shelvedChangeList, projectPath); - - LOG.info("doSystemUnshelve files refreshed. unshelving in AWT thread."); - } - }, new TaskDescriptor("", Where.AWT) { - @Override - public void run(ContinuationContext context) { - GitVFSListener l = GitVcs.getInstance(project).getVFSListener(); - l.setEventsSuppressed(true); - - LOG.info("Unshelving in UI thread. shelvedChangeList: " + shelvedChangeList); - // we pass null as target change list for Patch Applier to do NOTHING with change lists - shelveManager.scheduleUnshelveChangeList(shelvedChangeList, shelvedChangeList.getChanges(), - shelvedChangeList.getBinaryFiles(), null, false, context); - } - }, new TaskDescriptor("", Where.AWT) { - @Override - public void run(ContinuationContext context) { - GitVcs.getInstance(project).getVFSListener().setEventsSuppressed(false); - addFilesAfterUnshelve(project, shelvedChangeList, projectPath, context); - ChangeListManager.getInstance(project).invokeAfterUpdate(new Runnable() { - @Override - public void run() { - restoreListsRunnable.run(); - } - }, InvokeAfterUpdateMode.BACKGROUND_NOT_CANCELLABLE_NOT_AWT, "Restoring changelists", ModalityState.NON_MODAL); - } - }); - } - - private static void addFilesAfterUnshelve(Project project, - ShelvedChangeList shelvedChangeList, - String projectPath, ContinuationContext context) { - Collection paths = new ArrayList(); - for (ShelvedChange c : shelvedChangeList.getChanges()) { - if (c.getBeforePath() == null || !c.getBeforePath().equals(c.getAfterPath()) || c.getFileStatus() == FileStatus.ADDED) { - paths.add(VcsUtil.getFilePath(projectPath + c.getAfterPath())); - } - } - for (ShelvedBinaryFile f : shelvedChangeList.getBinaryFiles()) { - if (f.BEFORE_PATH == null || !f.BEFORE_PATH.equals(f.AFTER_PATH) || f.getFileStatus() == FileStatus.ADDED) { - paths.add(VcsUtil.getFilePath(projectPath + f.AFTER_PATH)); - } - } - final VcsDirtyScopeManager dsm = VcsDirtyScopeManager.getInstance(project); - Map> map = GitUtil.sortGitFilePathsByGitRoot(paths); - for (Map.Entry> e : map.entrySet()) { - try { - GitFileUtils.addPaths(project, e.getKey(), e.getValue()); - dsm.filePathsDirty(e.getValue(), null); - } - catch (VcsException e1) { - if (! context.handleException(e1)) { - AbstractVcsHelper.getInstance(project).showError(e1, "Can not add file to Git"); - LOG.error("Vcs Exception not handled"); - } - } - } - } - - private static void refreshFilesBeforeUnshelve(ShelvedChangeList shelvedChangeList, String projectPath) { - HashSet filesToRefresh = new HashSet(); - for (ShelvedChange c : shelvedChangeList.getChanges()) { - if (c.getBeforePath() != null) { - filesToRefresh.add(new File(projectPath + c.getBeforePath())); - } - if (c.getAfterPath() != null) { - filesToRefresh.add(new File(projectPath + c.getAfterPath())); - } - } - for (ShelvedBinaryFile f : shelvedChangeList.getBinaryFiles()) { - if (f.BEFORE_PATH != null) { - filesToRefresh.add(new File(projectPath + f.BEFORE_PATH)); - } - if (f.AFTER_PATH != null) { - filesToRefresh.add(new File(projectPath + f.BEFORE_PATH)); - } - } - LocalFileSystem.getInstance().refreshIoFiles(filesToRefresh); - } - - /** - * Shelve changes - * - * @param project the context project - * @param shelveManager the shelve manager - * @param changes the changes to process - * @param description the description of for the shelve - * @param exceptions the generated exceptions - * @return created shelved change list or null in case failure - */ - @Nullable - public static ShelvedChangeList shelveChanges(final Project project, final ShelveChangesManager shelveManager, Collection changes, - final String description, - final List exceptions) { - try { - ShelvedChangeList shelve = shelveManager.shelveChanges(changes, description); - project.getMessageBus().syncPublisher(ShelveChangesManager.SHELF_TOPIC).stateChanged(new ChangeEvent(GitStashUtils.class)); - return shelve; - } - catch (IOException e) { - //noinspection ThrowableInstanceNeverThrown - exceptions.add(new VcsException("Shelving changes failed: " + description, e)); - return null; - } - catch (VcsException e) { - exceptions.add(e); - return null; - } - } } From 015c35b6592995c719faf6a96a4cd2b937a0683d Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 11 May 2011 13:20:53 +0400 Subject: [PATCH 176/250] [Git] dead code --- plugins/git4idea/src/git4idea/stash/GitStashUtils.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugins/git4idea/src/git4idea/stash/GitStashUtils.java b/plugins/git4idea/src/git4idea/stash/GitStashUtils.java index 89b3b8ca704c..e25e764df9f2 100644 --- a/plugins/git4idea/src/git4idea/stash/GitStashUtils.java +++ b/plugins/git4idea/src/git4idea/stash/GitStashUtils.java @@ -23,7 +23,6 @@ import git4idea.commands.GitCommand; import git4idea.commands.GitSimpleHandler; import git4idea.commands.StringScanner; import git4idea.config.GitConfigUtil; -import git4idea.config.GitVersion; import git4idea.ui.GitUIUtil; import git4idea.ui.StashInfo; import org.jetbrains.annotations.NotNull; @@ -34,10 +33,6 @@ import java.nio.charset.Charset; * The class contains utilities for creating and removing stashes. */ public class GitStashUtils { - /** - * The version when quiet stash supported - */ - private final static GitVersion QUIET_STASH_SUPPORTED = new GitVersion(1, 6, 4, 0); private GitStashUtils() { } From ae9c434238d31b6ae7cde7401532ffeb71dbe772 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 11 May 2011 17:19:21 +0400 Subject: [PATCH 177/250] [Git] IDEA-51187 Auto-merge on unstash. * dropStash moved to GitStashUtils. * GitUnstashDialog captures conflicts and uses GitMergeConflictResolver. --- .../merge/GitMergeConflictResolver.java | 2 +- .../git4idea/stash/GitStashChangesSaver.java | 18 +---- .../src/git4idea/stash/GitStashUtils.java | 22 ++++++ .../src/git4idea/ui/GitUnstashDialog.java | 78 ++++++++++++++++++- 4 files changed, 98 insertions(+), 22 deletions(-) diff --git a/plugins/git4idea/src/git4idea/merge/GitMergeConflictResolver.java b/plugins/git4idea/src/git4idea/merge/GitMergeConflictResolver.java index faf90fe1c310..834249d06afc 100644 --- a/plugins/git4idea/src/git4idea/merge/GitMergeConflictResolver.java +++ b/plugins/git4idea/src/git4idea/merge/GitMergeConflictResolver.java @@ -42,7 +42,7 @@ import java.util.Collection; public class GitMergeConflictResolver { private static final Logger LOG = Logger.getInstance(GitMergeConflictResolver.class); - private final @NotNull Project myProject; + protected final @NotNull Project myProject; private final boolean myReverseMerge; private final @NotNull String myErrorNotificationTitle; private final @NotNull String myErrorNotificationAdditionalDescription; diff --git a/plugins/git4idea/src/git4idea/stash/GitStashChangesSaver.java b/plugins/git4idea/src/git4idea/stash/GitStashChangesSaver.java index ca8f4120ed40..736f9c5a8eef 100644 --- a/plugins/git4idea/src/git4idea/stash/GitStashChangesSaver.java +++ b/plugins/git4idea/src/git4idea/stash/GitStashChangesSaver.java @@ -176,7 +176,7 @@ public class GitStashChangesSaver extends GitChangesSaver { boolean conflictsResolved = new UnstashConflictResolver().merge(Collections.singleton(root)); if (conflictsResolved) { LOG.info("loadRoot " + root + " conflicts resolved, dropping stash"); - dropStash(root); + GitStashUtils.dropStash(myProject, root); } } else { LOG.info("unstash failed " + handler.errors()); @@ -185,22 +185,6 @@ public class GitStashChangesSaver extends GitChangesSaver { } } - // drops stash (after completing conflicting merge during unstashing), shows a warning in case of error - private void dropStash(VirtualFile root) { - final GitSimpleHandler handler = new GitSimpleHandler(myProject, root, GitCommand.STASH); - handler.setNoSSH(true); - handler.addParameters("drop"); - String output = null; - try { - output = handler.run(); - } catch (VcsException e) { - LOG.info("dropStash " + output, e); - GitUIUtil.notifyMessage(myProject, "Couldn't drop stash", - "Couldn't drop stash after resolving conflicts.
Please drop stash manually.", - WARNING, false, handler.errors()); - } - } - // Sort changes from myChangesLists by their git roots. // And use only supplied roots, ignoring changes from other roots. private Map> groupChangesByRoots(Collection rootsToSave) { diff --git a/plugins/git4idea/src/git4idea/stash/GitStashUtils.java b/plugins/git4idea/src/git4idea/stash/GitStashUtils.java index e25e764df9f2..53945b065656 100644 --- a/plugins/git4idea/src/git4idea/stash/GitStashUtils.java +++ b/plugins/git4idea/src/git4idea/stash/GitStashUtils.java @@ -15,6 +15,7 @@ */ package git4idea.stash; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; @@ -29,11 +30,15 @@ import org.jetbrains.annotations.NotNull; import java.nio.charset.Charset; +import static com.intellij.notification.NotificationType.WARNING; + /** * The class contains utilities for creating and removing stashes. */ public class GitStashUtils { + private static final Logger LOG = Logger.getInstance(GitStashUtils.class); + private GitStashUtils() { } @@ -76,4 +81,21 @@ public class GitStashUtils { consumer.consume(new StashInfo(s.boundedToken(':'), s.boundedToken(':'), s.line().trim())); } } + + // drops stash (after completing conflicting merge during unstashing), shows a warning in case of error + public static void dropStash(Project project, VirtualFile root) { + final GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.STASH); + handler.setNoSSH(true); + handler.addParameters("drop"); + String output = null; + try { + output = handler.run(); + } catch (VcsException e) { + LOG.info("dropStash " + output, e); + GitUIUtil.notifyMessage(project, "Couldn't drop stash", + "Couldn't drop stash after resolving conflicts.
Please drop stash manually.", + WARNING, false, handler.errors()); + } + } + } diff --git a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java index 820749a286c6..7110aa8c8061 100644 --- a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java +++ b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java @@ -15,6 +15,11 @@ */ package git4idea.ui; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationListener; +import com.intellij.notification.NotificationType; +import com.intellij.notification.Notifications; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; @@ -23,6 +28,8 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Key; import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vcs.history.VcsRevisionNumber; +import com.intellij.openapi.vcs.merge.MergeDialogCustomizer; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.DocumentAdapter; import com.intellij.util.Consumer; @@ -33,19 +40,19 @@ import git4idea.actions.GitShowAllSubmittedFilesAction; import git4idea.commands.*; import git4idea.config.GitVersionSpecialty; import git4idea.i18n.GitBundle; +import git4idea.merge.GitMergeConflictResolver; import git4idea.stash.GitStashUtils; import git4idea.validators.GitBranchNameValidator; import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.DocumentEvent; +import javax.swing.event.HyperlinkEvent; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; /** @@ -102,6 +109,7 @@ public class GitUnstashDialog extends DialogWrapper { */ private final Project myProject; private GitVcs myVcs; + private static final Logger LOG = Logger.getInstance(GitUnstashDialog.class); /** * A constructor @@ -406,10 +414,14 @@ public class GitUnstashDialog extends DialogWrapper { affectedRoots.add(d.getGitRoot()); GitLineHandler h = d.handler(false); final AtomicBoolean needToEscapedBraces = new AtomicBoolean(false); + final AtomicBoolean conflict = new AtomicBoolean(); + h.addLineListener(new GitLineHandlerAdapter() { public void onLineAvailable(String line, Key outputType) { if (line.startsWith("fatal: Needed a single revision")) { needToEscapedBraces.set(true); + } else if (line.contains("Merge conflict")) { + conflict.set(true); } } }); @@ -418,8 +430,66 @@ public class GitUnstashDialog extends DialogWrapper { h = d.handler(true); rc = GitHandlerUtil.doSynchronously(h, GitBundle.getString("unstash.unstashing"), h.printableCommandLine(), false); } - if (rc != 0) { + + if (conflict.get()) { + VirtualFile root = d.getGitRoot(); + boolean conflictsResolved = new UnstashConflictResolver(project, d.getSelectedStash()).merge(Collections.singleton(root)); + if (conflictsResolved) { + LOG.info("loadRoot " + root + " conflicts resolved, dropping stash"); + GitStashUtils.dropStash(project, root); + } + } else if (rc != 0) { GitUIUtil.showOperationErrors(project, h.errors(), h.printableCommandLine()); } } + + private static class UnstashConflictResolver extends GitMergeConflictResolver { + private StashInfo myStashInfo; + + public UnstashConflictResolver(Project project, StashInfo stashInfo) { + super(project, true, new UnstashMergeDialogCustomizer(stashInfo), "Local changes were not restored", ""); + myStashInfo = stashInfo; + } + + @Override + protected void notifyUnresolvedRemain(final Collection roots) { + Notifications.Bus.notify(new Notification(GitVcs.IMPORTANT_ERROR_NOTIFICATION, "Conflicts were not resolved during unstash", + "Unstash is not complete, you have unresolved merges in your working tree
" + + "Resolve conflicts.", + NotificationType.WARNING, new NotificationListener() { + @Override + public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { + if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + if (event.getDescription().equals("resolve")) { + new UnstashConflictResolver(myProject, myStashInfo).justMerge(roots); + } + } + } + })); + } + } + + private static class UnstashMergeDialogCustomizer extends MergeDialogCustomizer { + + private final StashInfo myStashInfo; + + public UnstashMergeDialogCustomizer(StashInfo stashInfo) { + myStashInfo = stashInfo; + } + + @Override + public String getMultipleFileMergeDescription(Collection files) { + return "Conflicts during unstashing " + myStashInfo.getStash() + "\"" + myStashInfo.getMessage() + "\""; + } + + @Override + public String getLeftPanelTitle(VirtualFile file) { + return "Local changes"; + } + + @Override + public String getRightPanelTitle(VirtualFile file, VcsRevisionNumber lastRevisionNumber) { + return "Changes from stash"; + } + } } From 2b3df1d639277f42809ae766aac387963a48c98b Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 11 May 2011 18:40:12 +0400 Subject: [PATCH 178/250] [Git] Fixed message in notification. Relates to IDEA-51187. --- plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java index 7110aa8c8061..fe1313da3816 100644 --- a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java +++ b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java @@ -447,7 +447,7 @@ public class GitUnstashDialog extends DialogWrapper { private StashInfo myStashInfo; public UnstashConflictResolver(Project project, StashInfo stashInfo) { - super(project, true, new UnstashMergeDialogCustomizer(stashInfo), "Local changes were not restored", ""); + super(project, true, new UnstashMergeDialogCustomizer(stashInfo), "Unstashed with conflicts", ""); myStashInfo = stashInfo; } From b5d0004b1a8d32afde7de76dbd5c4bd3e7718762 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 11 May 2011 20:29:38 +0400 Subject: [PATCH 179/250] [Git] Nullable --- .../git4idea/src/git4idea/commands/GitHandler.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/plugins/git4idea/src/git4idea/commands/GitHandler.java b/plugins/git4idea/src/git4idea/commands/GitHandler.java index 2f1b90faec3a..dd00d82b163a 100644 --- a/plugins/git4idea/src/git4idea/commands/GitHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitHandler.java @@ -35,20 +35,14 @@ import git4idea.config.GitVcsSettings; import git4idea.config.GitVersionSpecialty; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.git4idea.ssh.GitSSHHandler; import org.jetbrains.git4idea.ssh.GitSSHService; import java.io.File; import java.io.OutputStream; import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.LinkedBlockingQueue; /** @@ -635,7 +629,7 @@ public abstract class GitHandler { return myCommandLine.getCommandLineString().length() > VcsFileUtil.FILE_PATH_LIMIT; } - public void runInCurrentThread(Runnable postStartAction) { + public void runInCurrentThread(@Nullable Runnable postStartAction) { final GitVcs vcs = GitVcs.getInstance(myProject); if (vcs == null) { return; } From 4a8cb65e7f52d0e03657c7306469064aa8f438f8 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 11 May 2011 20:30:33 +0400 Subject: [PATCH 180/250] [Git] Store Subject in GitCommit. --- plugins/git4idea/src/git4idea/history/GitHistoryUtils.java | 2 +- .../git4idea/src/git4idea/history/browser/GitCommit.java | 7 +++++++ .../src/git4idea/history/wholeTree/DetailsLoaderImpl.java | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java b/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java index 9b9ebca04d64..5760d3b9fd28 100644 --- a/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java +++ b/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java @@ -502,7 +502,7 @@ public class GitHistoryUtils { final String s = parseRefs(refs, currentRefs, locals, remotes, tags); gitCommit = new GitCommit(AbstractHash.create(record.getShortHash()), new SHAHash(record.getHash()), record.getAuthorName(), record.getCommitterName(), - record.getDate(), record.getFullMessage(), + record.getDate(), record.getSubject(), record.getFullMessage(), new HashSet(Arrays.asList(record.getParentsShortHashes())), record.getFilePaths(root), record.getAuthorEmail(), record.getCommitterEmail(), tags, locals, remotes, diff --git a/plugins/git4idea/src/git4idea/history/browser/GitCommit.java b/plugins/git4idea/src/git4idea/history/browser/GitCommit.java index 71f2af4485c7..8ecc14275459 100644 --- a/plugins/git4idea/src/git4idea/history/browser/GitCommit.java +++ b/plugins/git4idea/src/git4idea/history/browser/GitCommit.java @@ -31,6 +31,7 @@ public class GitCommit { private final SHAHash myHash; private final String myAuthor; private final String myCommitter; + private final String mySubject; private final String myDescription; private final Date myDate; @@ -60,6 +61,7 @@ public class GitCommit { final String author, final String committer, final Date date, + final String subject, final String description, final Set parentsHashes, final List pathsList, @@ -74,6 +76,7 @@ public class GitCommit { myAuthor = author; myCommitter = committer; myDate = date; + mySubject = subject; myDescription = description; myHash = hash; myParentsHashes = parentsHashes; @@ -223,4 +226,8 @@ public class GitCommit { } }); } + + public String getSubject() { + return mySubject; + } } diff --git a/plugins/git4idea/src/git4idea/history/wholeTree/DetailsLoaderImpl.java b/plugins/git4idea/src/git4idea/history/wholeTree/DetailsLoaderImpl.java index 0293f3462cb0..a3fbe82972d1 100644 --- a/plugins/git4idea/src/git4idea/history/wholeTree/DetailsLoaderImpl.java +++ b/plugins/git4idea/src/git4idea/history/wholeTree/DetailsLoaderImpl.java @@ -194,7 +194,7 @@ public class DetailsLoaderImpl implements DetailsLoader { private GitCommit createNotLoadedCommit(AbstractHash shortHash) { final String notKnown = "Can not load"; - return new GitCommit(shortHash, SHAHash.emulate(shortHash), notKnown, notKnown, new Date(0), + return new GitCommit(shortHash, SHAHash.emulate(shortHash), notKnown, notKnown, new Date(0), notKnown, "Can not load details", Collections.emptySet(), Collections.emptyList(), notKnown, notKnown, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), 0); From 5304e6f6e3ebd3bb5ec9fdf079e957f9c987d468 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 11 May 2011 20:31:57 +0400 Subject: [PATCH 181/250] [Git] IDEA-51187 Auto-merge for cherry-pick --- .../src/git4idea/commands/GitFileUtils.java | 9 -- .../history/browser/CherryPicker.java | 5 +- .../history/browser/LowLevelAccess.java | 3 +- .../history/browser/LowLevelAccessImpl.java | 105 +++++++++++++++++- 4 files changed, 105 insertions(+), 17 deletions(-) diff --git a/plugins/git4idea/src/git4idea/commands/GitFileUtils.java b/plugins/git4idea/src/git4idea/commands/GitFileUtils.java index 31d09e596a0a..76f1e4a0ca30 100644 --- a/plugins/git4idea/src/git4idea/commands/GitFileUtils.java +++ b/plugins/git4idea/src/git4idea/commands/GitFileUtils.java @@ -60,15 +60,6 @@ public class GitFileUtils { } } - public static void cherryPick(final Project project, final VirtualFile root, final String hash) throws VcsException { - GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.CHERRY_PICK); - handler.addParameters("-x", "-n", hash); - handler.endOptions(); - //handler.addRelativePaths(new FilePathImpl(root)); - handler.setNoSSH(true); - handler.run(); - } - /** * Delete files * diff --git a/plugins/git4idea/src/git4idea/history/browser/CherryPicker.java b/plugins/git4idea/src/git4idea/history/browser/CherryPicker.java index 43c0486ea12a..2146c7ac22c7 100644 --- a/plugins/git4idea/src/git4idea/history/browser/CherryPicker.java +++ b/plugins/git4idea/src/git4idea/history/browser/CherryPicker.java @@ -129,9 +129,8 @@ public class CherryPicker { private void cherryPickStep(CheckinEnvironment ce, int i) { final GitCommit commit = myCommits.get(i); - final SHAHash hash = commit.getHash(); try { - myAccess.cherryPick(hash); + myAccess.cherryPick(commit); } catch (VcsException e) { myExceptions.add(e); @@ -141,7 +140,7 @@ public class CherryPicker { final Collection paths = ChangesUtil.getPaths(changes); String message = ce.getDefaultMessageFor(paths.toArray(new FilePath[paths.size()])); message = (message == null) ? new StringBuilder().append(commit.getDescription()).append("(cherry picked from commit ") - .append(hash.getValue()).append(")").toString() : message; + .append(commit.getShortHash()).append(")").toString() : message; myMessagesInOrder.add(message); myFilesToMove.put(message, paths); diff --git a/plugins/git4idea/src/git4idea/history/browser/LowLevelAccess.java b/plugins/git4idea/src/git4idea/history/browser/LowLevelAccess.java index fe88d733ca3f..be147979b3ce 100644 --- a/plugins/git4idea/src/git4idea/history/browser/LowLevelAccess.java +++ b/plugins/git4idea/src/git4idea/history/browser/LowLevelAccess.java @@ -16,7 +16,6 @@ package git4idea.history.browser; import com.intellij.openapi.util.Getter; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.AsynchConsumer; @@ -57,7 +56,7 @@ public interface LowLevelAccess { void loadAllTags(final Collection sink) throws VcsException; - void cherryPick(SHAHash hash) throws VcsException; + void cherryPick(GitCommit hash) throws VcsException; void loadHashesWithParents(final @NotNull Collection startingPoints, @NotNull final Collection filters, final AsynchConsumer consumer, Getter isCanceled, int useMaxCnt) throws VcsException; List getCommitDetails(final Collection commitIds, SymbolicRefs refs) throws VcsException; diff --git a/plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java b/plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java index b2fe33993ac1..1b88653e0f55 100644 --- a/plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java +++ b/plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java @@ -16,24 +16,38 @@ */ package git4idea.history.browser; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationListener; +import com.intellij.notification.NotificationType; +import com.intellij.notification.Notifications; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Getter; +import com.intellij.openapi.util.Key; import com.intellij.openapi.vcs.FilePathImpl; import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vcs.history.VcsRevisionNumber; +import com.intellij.openapi.vcs.merge.MergeDialogCustomizer; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; import com.intellij.util.AsynchConsumer; import git4idea.GitBranch; +import git4idea.GitRevisionNumber; import git4idea.GitTag; -import git4idea.commands.GitFileUtils; +import git4idea.GitVcs; +import git4idea.commands.GitCommand; +import git4idea.commands.GitLineHandler; +import git4idea.commands.GitLineHandlerAdapter; import git4idea.config.GitConfigUtil; import git4idea.history.GitHistoryUtils; import git4idea.history.wholeTree.CommitHashPlusParents; +import git4idea.merge.GitMergeConflictResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.event.HyperlinkEvent; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; public class LowLevelAccessImpl implements LowLevelAccess { private final static Logger LOG = Logger.getInstance("#git4idea.history.browser.LowLevelAccessImpl"); @@ -181,7 +195,92 @@ public class LowLevelAccessImpl implements LowLevelAccess { GitTag.listAsStrings(myProject, myRoot, sink, null); } - public void cherryPick(SHAHash hash) throws VcsException { - GitFileUtils.cherryPick(myProject, myRoot, hash.getValue()); + public void cherryPick(GitCommit commit) throws VcsException { + final GitLineHandler handler = new GitLineHandler(myProject, myRoot, GitCommand.CHERRY_PICK); + handler.addParameters("-x", "-n", commit.getHash().getValue()); + handler.endOptions(); + handler.setNoSSH(true); + + final AtomicBoolean conflict = new AtomicBoolean(); + + handler.addLineListener(new GitLineHandlerAdapter() { + public void onLineAvailable(String line, Key outputType) { + if (line.contains("after resolving the conflicts, mark the corrected paths")) { + conflict.set(true); + } + } + }); + handler.runInCurrentThread(null); + + if (conflict.get()) { + new CherryPickConflictResolver(myProject, commit.getShortHash().getString(), commit.getAuthor(), commit.getSubject()).merge(Collections.singleton(myRoot)); + } else { + final List errors = handler.errors(); + if (!errors.isEmpty()) { + throw errors.get(0); + } + } + } + + private static class CherryPickConflictResolver extends GitMergeConflictResolver { + + private String myCommitHash; + private String myCommitAuthor; + private String myCommitMessage; + + public CherryPickConflictResolver(Project project, String commitHash, String commitAuthor, String commitMessage) { + super(project, true, new CherryPickMergeDialogCustomizer(commitHash, commitAuthor, commitMessage), "Cherry-picked with conflicts", ""); + myCommitHash = commitHash; + myCommitAuthor = commitAuthor; + myCommitMessage = commitMessage; + } + + @Override + protected void notifyUnresolvedRemain(final Collection roots) { + Notifications.Bus.notify(new Notification(GitVcs.IMPORTANT_ERROR_NOTIFICATION, "Conflicts were not resolved during cherry-pick", + "Cherry-pick is not complete, you have unresolved merges in your working tree
" + + "Resolve conflicts.", + NotificationType.WARNING, new NotificationListener() { + @Override + public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { + if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + if (event.getDescription().equals("resolve")) { + new CherryPickConflictResolver(myProject, myCommitHash, myCommitAuthor, myCommitMessage).justMerge(roots); + } + } + } + })); + } + } + + private static class CherryPickMergeDialogCustomizer extends MergeDialogCustomizer { + + private String myCommitHash; + private String myCommitAuthor; + private String myCommitMessage; + + public CherryPickMergeDialogCustomizer(String commitHash, String commitAuthor, String commitMessage) { + myCommitHash = commitHash; + myCommitAuthor = commitAuthor; + myCommitMessage = commitMessage; + } + + @Override + public String getMultipleFileMergeDescription(Collection files) { + return "Conflicts during cherry-picking commit " + myCommitHash + " made by " + myCommitAuthor + "
" + + "\"" + myCommitMessage + "\""; + } + + @Override + public String getLeftPanelTitle(VirtualFile file) { + return "Local changes"; + } + + @Override + public String getRightPanelTitle(VirtualFile file, VcsRevisionNumber lastRevisionNumber) { + return "Changes from cherry-pick " + ((GitRevisionNumber)lastRevisionNumber).toShortString() + ""; + } + } + } From 1c2dfda2614a2e9fdcae731667d16c2bf74a7e20 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 11 May 2011 20:38:15 +0400 Subject: [PATCH 182/250] [Git] cherryPick returns false if not all conflicts were resolved. --- .../src/git4idea/history/browser/LowLevelAccess.java | 9 ++++++++- .../src/git4idea/history/browser/LowLevelAccessImpl.java | 8 +++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/git4idea/src/git4idea/history/browser/LowLevelAccess.java b/plugins/git4idea/src/git4idea/history/browser/LowLevelAccess.java index be147979b3ce..39959691cf0a 100644 --- a/plugins/git4idea/src/git4idea/history/browser/LowLevelAccess.java +++ b/plugins/git4idea/src/git4idea/history/browser/LowLevelAccess.java @@ -56,7 +56,14 @@ public interface LowLevelAccess { void loadAllTags(final Collection sink) throws VcsException; - void cherryPick(GitCommit hash) throws VcsException; + /** + * Cherry-picks the specified commit. + * Doesn't autocommit - instead puts the changes into a separate changelist. + * In the case of merge conflict provides the Conflict Resolver dialog. + * @return true if all conflicts were resolved or there were no merge conflicts; false if unresolved files remain. + * @throws VcsException + */ + boolean cherryPick(GitCommit hash) throws VcsException; void loadHashesWithParents(final @NotNull Collection startingPoints, @NotNull final Collection filters, final AsynchConsumer consumer, Getter isCanceled, int useMaxCnt) throws VcsException; List getCommitDetails(final Collection commitIds, SymbolicRefs refs) throws VcsException; diff --git a/plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java b/plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java index 1b88653e0f55..6afd6c8e654b 100644 --- a/plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java +++ b/plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java @@ -195,7 +195,7 @@ public class LowLevelAccessImpl implements LowLevelAccess { GitTag.listAsStrings(myProject, myRoot, sink, null); } - public void cherryPick(GitCommit commit) throws VcsException { + public boolean cherryPick(GitCommit commit) throws VcsException { final GitLineHandler handler = new GitLineHandler(myProject, myRoot, GitCommand.CHERRY_PICK); handler.addParameters("-x", "-n", commit.getHash().getValue()); handler.endOptions(); @@ -213,14 +213,16 @@ public class LowLevelAccessImpl implements LowLevelAccess { handler.runInCurrentThread(null); if (conflict.get()) { - new CherryPickConflictResolver(myProject, commit.getShortHash().getString(), commit.getAuthor(), commit.getSubject()).merge(Collections.singleton(myRoot)); + boolean allConflictsResolved = new CherryPickConflictResolver(myProject, commit.getShortHash().getString(), commit.getAuthor(), commit.getSubject()).merge(Collections.singleton(myRoot)); + return allConflictsResolved; } else { final List errors = handler.errors(); if (!errors.isEmpty()) { throw errors.get(0); + } else { // no conflicts, no errors + return true; } } - } private static class CherryPickConflictResolver extends GitMergeConflictResolver { From 30fc60f43c4e2be4c01525eb380c25e22cadad43 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 11 May 2011 20:49:27 +0400 Subject: [PATCH 183/250] [Git] if not all conflicts resolved, notify. Relates to IDEA-51187 --- .../history/browser/CherryPicker.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/plugins/git4idea/src/git4idea/history/browser/CherryPicker.java b/plugins/git4idea/src/git4idea/history/browser/CherryPicker.java index 2146c7ac22c7..9ce3a4615a40 100644 --- a/plugins/git4idea/src/git4idea/history/browser/CherryPicker.java +++ b/plugins/git4idea/src/git4idea/history/browser/CherryPicker.java @@ -17,13 +17,13 @@ package git4idea.history.browser; import com.intellij.lifecycle.PeriodicalTasksCloser; import com.intellij.openapi.application.ModalityState; +import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.vcs.AbstractVcsHelper; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.checkin.CheckinEnvironment; -import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Consumer; @@ -31,6 +31,8 @@ import git4idea.GitVcs; import java.util.*; +import static com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier.showOverChangesView; + public class CherryPicker { private final GitVcs myVcs; private final List myCommits; @@ -41,6 +43,7 @@ public class CherryPicker { private final List myDirtyFiles; private final List myMessagesInOrder; private final Map> myFilesToMove; + private boolean myConflictsExist; public CherryPicker(GitVcs vcs, final List commits, LowLevelAccess access) { myVcs = vcs; @@ -90,15 +93,19 @@ public class CherryPicker { } private void showResults() { - if (myExceptions.isEmpty()) { - VcsBalloonProblemNotifier - .showOverChangesView(myVcs.getProject(), "Successful cherry-pick into working tree, please commit changes", MessageType.INFO); + final Project project = myVcs.getProject(); + if (myExceptions.isEmpty() && !myConflictsExist) { + showOverChangesView(project, "Successful cherry-pick into working tree, please commit changes", MessageType.INFO); } else { - VcsBalloonProblemNotifier.showOverChangesView(myVcs.getProject(), "Errors in cherry-pick", MessageType.ERROR); + if (myExceptions.isEmpty()) { + showOverChangesView(project, "Unresolved conflicts while cherry-picking. Resolve conflicts, then commit changes", MessageType.WARNING); + } else { + showOverChangesView(project, "Errors in cherry-pick", MessageType.ERROR); + } } if ((! myExceptions.isEmpty()) || (! myWarnings.isEmpty())) { myExceptions.addAll(myWarnings); - AbstractVcsHelper.getInstance(myVcs.getProject()).showErrors(myExceptions, "Cherry-pick problems"); + AbstractVcsHelper.getInstance(project).showErrors(myExceptions, "Cherry-pick problems"); } } @@ -130,7 +137,9 @@ public class CherryPicker { private void cherryPickStep(CheckinEnvironment ce, int i) { final GitCommit commit = myCommits.get(i); try { - myAccess.cherryPick(commit); + if (!myAccess.cherryPick(commit)) { + myConflictsExist = true; + } } catch (VcsException e) { myExceptions.add(e); From 3244f117efe7640f0dc4f4bcd0aaef14e016d567 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Tue, 10 May 2011 21:41:09 +0400 Subject: [PATCH 184/250] IDEA-69459 Flex: show suggestion "Create method" on Alt+Enter for "(A as B).method()" casting --- .../daemon/quickFix/LightQuickFixTestCase.java | 14 ++++++++++---- .../daemon/quickFix/QuickFixTestCase.java | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java index e32d3d541523..fb98f7ed9c9b 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java @@ -23,6 +23,7 @@ import com.intellij.lang.Commenter; import com.intellij.lang.LanguageCommenters; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; @@ -61,7 +62,7 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase final String relativePath = quickFixTestCase.getBasePath() + "/" + BEFORE_PREFIX + testName; final String testFullPath = quickFixTestCase.getTestDataPath().replace(File.separatorChar, '/') + relativePath; final File testFile = new File(testFullPath); - CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { + CommandProcessor.getInstance().executeCommand(quickFixTestCase.getProject(), new Runnable() { @Override public void run() { try { @@ -263,17 +264,22 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase @Override public void configureFromFileText(String name, String contents) throws IOException { - LightCodeInsightTestCase.configureFromFileText(name, contents); + LightQuickFixTestCase.configureFromFileText(name, contents); } @Override public PsiFile getFile() { - return LightCodeInsightTestCase.getFile(); + return LightQuickFixTestCase.getFile(); + } + + @Override + public Project getProject() { + return LightQuickFixTestCase.getProject(); } @Override public void bringRealEditorBack() { - LightCodeInsightTestCase.bringRealEditorBack(); + LightQuickFixTestCase.bringRealEditorBack(); } }); } diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/QuickFixTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/QuickFixTestCase.java index 3ea3502a09df..613488732762 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/QuickFixTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/QuickFixTestCase.java @@ -17,6 +17,7 @@ package com.intellij.codeInsight.daemon.quickFix; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiFile; @@ -57,4 +58,6 @@ public interface QuickFixTestCase { void configureFromFileText(String name, String contents) throws Throwable; PsiFile getFile(); + + Project getProject(); } From 10e89d8a3c2b0c908dab491408afad9d10228198 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 12 May 2011 12:24:55 +0400 Subject: [PATCH 185/250] [Git] Fix merge dialog sides for unstash and cherry-pick. Relates to IDEA-51187 --- .../src/git4idea/history/browser/LowLevelAccessImpl.java | 5 ++--- plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java b/plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java index 6afd6c8e654b..8d0ef322c0db 100644 --- a/plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java +++ b/plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java @@ -32,7 +32,6 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; import com.intellij.util.AsynchConsumer; import git4idea.GitBranch; -import git4idea.GitRevisionNumber; import git4idea.GitTag; import git4idea.GitVcs; import git4idea.commands.GitCommand; @@ -232,7 +231,7 @@ public class LowLevelAccessImpl implements LowLevelAccess { private String myCommitMessage; public CherryPickConflictResolver(Project project, String commitHash, String commitAuthor, String commitMessage) { - super(project, true, new CherryPickMergeDialogCustomizer(commitHash, commitAuthor, commitMessage), "Cherry-picked with conflicts", ""); + super(project, false, new CherryPickMergeDialogCustomizer(commitHash, commitAuthor, commitMessage), "Cherry-picked with conflicts", ""); myCommitHash = commitHash; myCommitAuthor = commitAuthor; myCommitMessage = commitMessage; @@ -281,7 +280,7 @@ public class LowLevelAccessImpl implements LowLevelAccess { @Override public String getRightPanelTitle(VirtualFile file, VcsRevisionNumber lastRevisionNumber) { - return "Changes from cherry-pick " + ((GitRevisionNumber)lastRevisionNumber).toShortString() + ""; + return "Changes from cherry-pick " + myCommitHash + ""; } } diff --git a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java index fe1313da3816..ba8d723cdcdc 100644 --- a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java +++ b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java @@ -447,7 +447,7 @@ public class GitUnstashDialog extends DialogWrapper { private StashInfo myStashInfo; public UnstashConflictResolver(Project project, StashInfo stashInfo) { - super(project, true, new UnstashMergeDialogCustomizer(stashInfo), "Unstashed with conflicts", ""); + super(project, false, new UnstashMergeDialogCustomizer(stashInfo), "Unstashed with conflicts", ""); myStashInfo = stashInfo; } From 353b862fb7ba641e945bef6e1e0b3eff34458e01 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Thu, 12 May 2011 13:17:56 +0400 Subject: [PATCH 186/250] [xena] deprecated constructor RelativePoint(screenCooridnates), fixed computing of preferred container [r=anna.kozlova] --- .../src/com/intellij/ui/awt/RelativePoint.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/platform/util/src/com/intellij/ui/awt/RelativePoint.java b/platform/util/src/com/intellij/ui/awt/RelativePoint.java index 0280e56408b1..dcc24baad4b5 100644 --- a/platform/util/src/com/intellij/ui/awt/RelativePoint.java +++ b/platform/util/src/com/intellij/ui/awt/RelativePoint.java @@ -40,9 +40,21 @@ public class RelativePoint { public RelativePoint(Point screenPoint) { Point p = new Point(screenPoint.x, screenPoint.y); - Frame c = JOptionPane.getRootFrame(); - SwingUtilities.convertPointFromScreen(p, c); - init(c, p); + Window[] windows = Frame.getWindows(); + Window targetWindow = null; + for (Window each : windows) { + if (each.isActive()) { + targetWindow = each; + break; + } + } + + if (targetWindow == null) { + targetWindow = JOptionPane.getRootFrame(); + } + + SwingUtilities.convertPointFromScreen(p, targetWindow); + init(targetWindow, p); } private void init(Component aComponent, Point aPointOnComponent) { From 773481a3a453a1d015b46b3b5c3fd6dcbcade642 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:28:37 +0400 Subject: [PATCH 187/250] EA-27709 - NPE EqualsAndHashcode$1 compute --- .../equalsAndHashcode/EqualsAndHashcode.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/equalsAndHashcode/EqualsAndHashcode.java b/java/java-impl/src/com/intellij/codeInspection/equalsAndHashcode/EqualsAndHashcode.java index 599b1b344daf..d20ed00ce671 100644 --- a/java/java-impl/src/com/intellij/codeInspection/equalsAndHashcode/EqualsAndHashcode.java +++ b/java/java-impl/src/com/intellij/codeInspection/equalsAndHashcode/EqualsAndHashcode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -37,21 +37,20 @@ public class EqualsAndHashcode extends BaseJavaLocalInspectionTool { private PsiMethod myHashCode; private PsiMethod myEquals; - private JavaPsiFacade myPsiFacade; private final AtomicBoolean myInitialized = new AtomicBoolean(); public void projectOpened(Project project) { - myPsiFacade = JavaPsiFacade.getInstance(project); } @NotNull public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { if (!myInitialized.getAndSet(true)) { + final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(holder.getProject()); final PsiClass psiObjectClass = ApplicationManager.getApplication().runReadAction( new Computable() { @Nullable public PsiClass compute() { - return myPsiFacade.findClass("java.lang.Object"); + return psiFacade.findClass("java.lang.Object"); } } ); @@ -124,6 +123,5 @@ public class EqualsAndHashcode extends BaseJavaLocalInspectionTool { public void projectClosed(Project project) { myEquals = null; myHashCode = null; - myPsiFacade = null; } } From bc27633d89c63a2ac7f2b514fff30f820783005b Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:28:45 +0400 Subject: [PATCH 188/250] do not reformat the whole file on method generation --- .../intellij/codeInsight/generation/PsiGenerationInfo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/PsiGenerationInfo.java b/java/java-impl/src/com/intellij/codeInsight/generation/PsiGenerationInfo.java index a6a21e6eeebc..ddac6ea27ce8 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/PsiGenerationInfo.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/PsiGenerationInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -46,7 +46,7 @@ public class PsiGenerationInfo extends GenerationInfo { return myMember; } - public void insert(PsiClass aClass, PsiElement anchor, boolean before) throws IncorrectOperationException { + public void insert(final PsiClass aClass, PsiElement anchor, boolean before) throws IncorrectOperationException { final PsiMember existingMember; if (myMember instanceof PsiField) { existingMember = aClass.findFieldByName(myMember.getName(), false); From dde22ea05ec63c1582563f4cd5e01b5838a162ee Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:28:53 +0400 Subject: [PATCH 189/250] do not insert final if final checkbox is disabled --- .../introduceVariable/IntroduceVariableDialog.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java index 52e3d71b2661..07c216f48e1b 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java @@ -104,11 +104,7 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable } public boolean isDeclareFinal() { - if (myCbFinal.isEnabled()) { - return myCbFinalState; - } else { - return true; - } + return myCbFinal.isEnabled() && myCbFinalState; } public boolean isReplaceLValues() { From b2f23f2eb97c0ac5ddb21b6efb16968b8c2ead6b Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:29:00 +0400 Subject: [PATCH 190/250] condition to insert final tweaks --- .../refactoring/introduceVariable/IntroduceVariableBase.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java index 6605d527652c..8bbcae485a23 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java @@ -771,9 +771,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme final String variableName = suggestedName.names[0]; final boolean replaceAll = replaceChoice == OccurrencesChooser.ReplaceChoice.ALL || replaceChoice == OccurrencesChooser.ReplaceChoice.NO_WRITE; - final boolean declareFinal = - !anyAssignmentLHS && (replaceAll && - declareFinalIfAll || createFinals(project)); + final boolean declareFinal = replaceAll && (declareFinalIfAll || !anyAssignmentLHS) || createFinals(project); final boolean replaceWrite = anyAssignmentLHS && replaceChoice == OccurrencesChooser.ReplaceChoice.ALL; return new IntroduceVariableSettings() { @Override From df8a0ecfc34bbd9d3a7d9649b9146ad82e49c32a Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:29:09 +0400 Subject: [PATCH 191/250] cannot modify read only file --- .../codeInspection/javaDoc/JavaDocReferenceInspection.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocReferenceInspection.java b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocReferenceInspection.java index 4cf4d7f9bc6e..cc67b4e8826f 100644 --- a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocReferenceInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocReferenceInspection.java @@ -16,6 +16,7 @@ package com.intellij.codeInspection.javaDoc; import com.intellij.codeHighlighting.HighlightDisplayLevel; +import com.intellij.codeInsight.CodeInsightUtilBase; import com.intellij.codeInsight.daemon.QuickFixBundle; import com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFix; import com.intellij.codeInsight.lookup.LookupElement; @@ -327,6 +328,7 @@ public class JavaDocReferenceInspection extends BaseLocalInspectionTool { public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiDocTag myTag = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiDocTag.class); if (myTag == null) return; + if (!CodeInsightUtilBase.preparePsiElementForWrite(myTag)) return; myTag.delete(); } } From 866db199b8c35051dbe4545464b6170579ef3f92 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:29:16 +0400 Subject: [PATCH 192/250] assertion --- .../src/com/intellij/execution/junit/TestDirectory.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/junit/src/com/intellij/execution/junit/TestDirectory.java b/plugins/junit/src/com/intellij/execution/junit/TestDirectory.java index 9292631300f5..9f616cf59249 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestDirectory.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestDirectory.java @@ -17,10 +17,7 @@ package com.intellij.execution.junit; import com.intellij.execution.CantRunException; import com.intellij.execution.ExecutionBundle; -import com.intellij.execution.configurations.ConfigurationPerRunnerSettings; -import com.intellij.execution.configurations.RunnerSettings; -import com.intellij.execution.configurations.RuntimeConfigurationException; -import com.intellij.execution.configurations.RuntimeConfigurationWarning; +import com.intellij.execution.configurations.*; import com.intellij.execution.testframework.SourceScope; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; @@ -93,7 +90,7 @@ class TestDirectory extends TestPackage { } final String dirName = myConfiguration.getPersistentData().getDirName(); if (dirName == null || dirName.isEmpty()) { - throw new RuntimeConfigurationWarning("Directory is not specified"); + throw new RuntimeConfigurationError("Directory is not specified"); } final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(dirName)); if (file == null) { @@ -101,7 +98,7 @@ class TestDirectory extends TestPackage { } final Module module = myConfiguration.getConfigurationModule().getModule(); if (module == null) { - throw new RuntimeConfigurationWarning("Module to choose classpath from is not specified"); + throw new RuntimeConfigurationError("Module to choose classpath from is not specified"); } } From a7ea388df29c5c68aed5bc71b26f03790b2c99d0 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:29:24 +0400 Subject: [PATCH 193/250] add command to slightly undo --- .../InplaceIntroduceConstantPopup.java | 17 ++++++++----- .../InplaceIntroduceFieldPopup.java | 24 ++++++++++++++----- .../InplaceIntroduceParameterPopup.java | 21 +++++++++------- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java index ac814659dcc8..31ffb0844496 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java @@ -549,12 +549,17 @@ public class InplaceIntroduceConstantPopup { myReplaceAllCb.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { - final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); - if (templateState != null) { - templateState.gotoEnd(true); - myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myExpr, myOccurrences); - startIntroduceTemplate(isReplaceAllOccurrences(), myFieldTypePointer.getType()); - } + Runnable restartTemplateRunnable = new Runnable() { + public void run() { + final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); + if (templateState != null) { + templateState.gotoEnd(true); + myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myExpr, myOccurrences); + startIntroduceTemplate(isReplaceAllOccurrences(), myFieldTypePointer.getType()); + } + } + }; + CommandProcessor.getInstance().executeCommand(myProject, restartTemplateRunnable, IntroduceConstantHandler.REFACTORING_NAME, IntroduceConstantHandler.REFACTORING_NAME); } }); diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java index acf8d5349d7a..9c99c07722a4 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java @@ -15,11 +15,14 @@ */ package com.intellij.refactoring.introduceField; +import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.codeInsight.intention.impl.TypeExpression; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; import com.intellij.codeInsight.template.impl.TemplateState; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.Result; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.editor.ScrollType; @@ -309,12 +312,21 @@ public class InplaceIntroduceFieldPopup { myIntroduceFieldPanel.addOccurrenceListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { - final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); - if (templateState != null) { - templateState.gotoEnd(true); - myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myInitializerExpression, myOccurrences); - startTemplate(myIntroduceFieldPanel.isReplaceAllOccurrences(), myFieldTypePointer.getType()); - } + final Runnable restartTemplate = new Runnable() { + @Override + public void run() { + final TemplateState templateState = + TemplateManagerImpl.getTemplateState(myEditor); + if (templateState != null) { + templateState.gotoEnd(true); + myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myInitializerExpression, myOccurrences); + startTemplate(myIntroduceFieldPanel.isReplaceAllOccurrences(), myFieldTypePointer.getType()); + } + } + }; + CommandProcessor.getInstance().executeCommand(myProject, restartTemplate, + IntroduceFieldHandler.REFACTORING_NAME, + IntroduceFieldHandler.REFACTORING_NAME); } }); } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java index 9761f74e80b1..a5a116df7c12 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java @@ -424,14 +424,19 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { protected void updateControls(JCheckBox[] removeParamsCb) { super.updateControls(removeParamsCb); if (myParameterIndex < 0) return; - final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); - if (templateState != null) { - PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument()); - final PsiParameter parameter = getParameter(); - final boolean hasFinalModifier = parameter.hasModifierProperty(PsiModifier.FINAL); - templateState.gotoEnd(true); - startIntroduceTemplate(isReplaceAllOccurences(), hasFinalModifier); - } + Runnable restartTemplateRunnable = new Runnable() { + public void run() { + final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); + if (templateState != null) { + PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument()); + final PsiParameter parameter = getParameter(); + final boolean hasFinalModifier = parameter.hasModifierProperty(PsiModifier.FINAL); + templateState.gotoEnd(true); + startIntroduceTemplate(isReplaceAllOccurences(), hasFinalModifier); + } + } + }; + CommandProcessor.getInstance().executeCommand(myProject, restartTemplateRunnable, IntroduceParameterHandler.REFACTORING_NAME, IntroduceParameterHandler.REFACTORING_NAME); } From 63c005729e899066648f0d0f621878ca0408111b Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:31:29 +0400 Subject: [PATCH 194/250] NPE (cherry picked from commit 0368e329d4ca1041a43fd07cd168a7e234b7e8f0) --- .../InplaceIntroduceParameterPopup.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java index a5a116df7c12..2bc3a08d026c 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java @@ -257,12 +257,14 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { protected JComponent getComponent() { if (!myInitialized) { myInitialized = true; - myWholePanel.add(myCanBeFinalCb, - new GridBagConstraints(0, myCbReplaceAllOccurences == null ? 2 : 3, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(0, 5, 2, 5), 0, 0)); - if (myHasWriteAccess) { - myCanBeFinalCb.setSelected(false); - myCanBeFinalCb.setEnabled(false); + if (myCanBeFinalCb != null) { + myWholePanel.add(myCanBeFinalCb, + new GridBagConstraints(0, myCbReplaceAllOccurences == null ? 2 : 3, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, + GridBagConstraints.NONE, new Insets(0, 5, 2, 5), 0, 0)); + if (myHasWriteAccess) { + myCanBeFinalCb.setSelected(false); + myCanBeFinalCb.setEnabled(false); + } } } return myWholePanel; @@ -298,7 +300,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { protected void saveSettings(PsiVariable psiVariable) { final JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance(); InplaceIntroduceParameterPopup.super.saveSettings(settings); - if (myCanBeFinalCb.isEnabled()) { + if (myCanBeFinalCb != null && myCanBeFinalCb.isEnabled()) { settings.INTRODUCE_PARAMETER_CREATE_FINALS = psiVariable.hasModifierProperty(PsiModifier.FINAL); } TypeSelectorManagerImpl.typeSelected(psiVariable.getType(), myDefaultParameterTypePointer.getType()); From 75e1f36acad0a8ae35cfd7688d96dc2438893c30 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 May 2011 13:31:37 +0400 Subject: [PATCH 195/250] no need to select current visibility second time (first time null => no selection) (cherry picked from commit cd185298ab590714e319061d7e2d4379b52a8eb5) --- .../introduceField/IntroduceFieldPopupPanel.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java index 5ee70e5b413c..5aa768e45b33 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldPopupPanel.java @@ -52,13 +52,6 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel { occurrences, allowInitInMethod, allowInitInMethodIfAll, typeSelectorManager); } - protected void initializeControls(PsiExpression initializerExpression, BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace) { - super.initializeControls(initializerExpression, ourLastInitializerPlace); - - String ourLastVisibility = JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY; - setVisibility(ourLastVisibility); - } - protected void initializeInitializerPlace(PsiExpression initializerExpression, BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace) { if (initializerExpression != null) { From d849acf84848494d49a6c46e7732034090a6f2ea Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 12:26:14 +0200 Subject: [PATCH 196/250] fix the tests --- .../src/com/intellij/openapi/extensions/Extensions.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java b/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java index ba6e11113c73..593101a33646 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java @@ -68,6 +68,7 @@ public class Extensions { public static void cleanRootArea(@NotNull Disposable parentDisposable) { final ExtensionsAreaImpl oldRootArea = (ExtensionsAreaImpl)getRootArea(); final ExtensionsAreaImpl newArea = createRootArea(); + ourRootArea = newArea; oldRootArea.notifyAreaReplaced(); Disposer.register(parentDisposable, new Disposable() { public void dispose() { From ac4b49dd98691c0204688b22dde20335b1f447ac Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 12:43:14 +0200 Subject: [PATCH 197/250] fail-fast on invalid lookup (EA-26138, EA-24113) --- .../codeInsight/lookup/impl/LookupImpl.java | 21 ++++++++++++------- .../lookup/impl/LookupManagerImpl.java | 6 ++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index 31a78737355f..4dd8f4e8f52a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -336,7 +336,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable void appendPrefix(char c) { checkReused(); - LOG.assertTrue(!myDisposed, disposeTrace); + checkValid(); myAdditionalPrefix += c; myInitialPrefix = null; myFrozenItems.clear(); @@ -378,7 +378,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable if (!ApplicationManager.getApplication().isUnitTestMode()) { ApplicationManager.getApplication().assertIsDispatchThread(); } - assert !myDisposed : disposeTrace; + checkValid(); final Pair,Iterable>> snapshot = myModel.getModelSnapshot(); @@ -756,7 +756,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable } public void performGuardedChange(Runnable change) { - LOG.assertTrue(!myDisposed, disposeTrace); + checkValid(); assert myLookupStartMarker.isValid(); assert !myChangeGuard; @@ -770,13 +770,13 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable marker.trackInvalidation(false); myChangeGuard = false; } - LOG.assertTrue(!myDisposed, disposeTrace); + checkValid(); LOG.assertTrue(myLookupStartMarker.isValid(), "invalid lookup start"); LOG.assertTrue(marker.isValid(), "invalid marker"); if (isVisible()) { updateLookupBounds(); } - LOG.assertTrue(!myDisposed, disposeTrace); + checkValid(); } @Override @@ -791,7 +791,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable public void show(){ ApplicationManager.getApplication().assertIsDispatchThread(); - LOG.assertTrue(!myDisposed, disposeTrace); + checkValid(); LOG.assertTrue(!myShown); myShown = true; myStampShown = System.currentTimeMillis(); @@ -1319,11 +1319,16 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable return myDisposed; } + public void checkValid() { + if (myDisposed) { + throw new AssertionError("Disposed at: " + disposeTrace); + } + } + @Override public void showItemPopup(JBPopup hint) { final Rectangle bounds = getCurrentItemBounds(); - hint.show(new RelativePoint(getComponent(), new Point(bounds.x + bounds.width, - bounds.y))); + hint.show(new RelativePoint(getComponent(), new Point(bounds.x + bounds.width, bounds.y))); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java index 7c9de1ce5125..4c56449b6059 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java @@ -225,6 +225,12 @@ public class LookupManagerImpl extends LookupManager { } public LookupEx getActiveLookup() { + if (myActiveLookup != null && myActiveLookup.isLookupDisposed()) { + LookupImpl lookup = myActiveLookup; + myActiveLookup = null; + lookup.checkValid(); + } + return myActiveLookup; } From e3f8e0553479e23efe2884dc1c5cf768aa8298aa Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 12:55:05 +0200 Subject: [PATCH 198/250] correct matching for final * in some cases --- .../util/src/com/intellij/psi/codeStyle/NameUtil.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java b/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java index 0af1ceaa513d..d28c11119826 100644 --- a/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java +++ b/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java @@ -539,10 +539,12 @@ public class NameUtil { } // there's more in the pattern, but no more words if (nextStart == name.length()) { - if (patternIndex + i == myPattern.length - 1 && - ' ' == myPattern[patternIndex + i] && - (i == 1 && isWordStart(myPattern[patternIndex]) || i + nameIndex == name.length())) { - return FList.emptyList().prepend(TextRange.from(nameIndex, i)); + if (patternIndex + i == myPattern.length - 1) { + char last = myPattern[patternIndex + i]; + if (' ' == last && (i == 1 && isWordStart(myPattern[patternIndex]) || i + nameIndex == name.length()) || + '*' == last) { + return FList.emptyList().prepend(TextRange.from(nameIndex, i)); + } } return null; From 0b314627b39289dad00ab6fd4ad2efa937bffce2 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 13:38:49 +0200 Subject: [PATCH 199/250] constructors, don't return a value, a test for IDEA-69571: Static nested class in Groovy 1.7+: "this" keyword gives inspection 'Cannot reference nonstatic symbol 'a' from static context' --- .../assignment/GroovyResultOfAssignmentUsedInspection.java | 3 ++- .../plugins/groovy/lang/GroovyHighlightingTest.java | 5 +++++ .../testdata/highlighting/InnerClassConstructorThis.groovy | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 plugins/groovy/testdata/highlighting/InnerClassConstructorThis.groovy diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyResultOfAssignmentUsedInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyResultOfAssignmentUsedInspection.java index c50ec4a7e69e..8432754b922e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyResultOfAssignmentUsedInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyResultOfAssignmentUsedInspection.java @@ -69,7 +69,8 @@ public class GroovyResultOfAssignmentUsedInspection extends BaseInspection { //check for method that has void return type. so it does not matter what return statements are. if (flowOwner instanceof GrOpenBlock) { final PsiElement flowParent = flowOwner.getParent(); - if (flowParent instanceof PsiMethod && ((PsiMethod)flowParent).getReturnType() == PsiType.VOID) { + if (flowParent instanceof PsiMethod && + (((PsiMethod)flowParent).getReturnType() == PsiType.VOID || ((PsiMethod)flowParent).isConstructor())) { return; } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java index 6e01beb56b3a..fa1112c49f61 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java @@ -404,6 +404,11 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase { doTest(new GroovyAssignabilityCheckInspection()); } + public void _testInnerClassConstructorThis() { + myFixture.enableInspections(new GroovyResultOfAssignmentUsedInspection()); + myFixture.testHighlighting(true, true, true, getTestName(false) + ".groovy"); + } + public void testCurrying(){ doTest(new GroovyAssignabilityCheckInspection()); } diff --git a/plugins/groovy/testdata/highlighting/InnerClassConstructorThis.groovy b/plugins/groovy/testdata/highlighting/InnerClassConstructorThis.groovy new file mode 100644 index 000000000000..392a9e5ba9f7 --- /dev/null +++ b/plugins/groovy/testdata/highlighting/InnerClassConstructorThis.groovy @@ -0,0 +1,6 @@ +class A { + static private class B { + int i + B () { this.i = 42 } + } +} \ No newline at end of file From 87b67d662462c59d26e10112e541b871bd822ea1 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 12 May 2011 13:38:54 +0200 Subject: [PATCH 200/250] IDEA-69532 (CVS: history view is empty; CompareWith... dialog shows no revisions) --- .../com/intellij/util/WaitForProgressToShow.java | 16 ++++++++++++++++ .../cvsExecution/ModalityContextImpl.java | 3 +-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/util/WaitForProgressToShow.java b/platform/platform-impl/src/com/intellij/util/WaitForProgressToShow.java index 9d2ef62a0a05..1a1bd088b2fa 100644 --- a/platform/platform-impl/src/com/intellij/util/WaitForProgressToShow.java +++ b/platform/platform-impl/src/com/intellij/util/WaitForProgressToShow.java @@ -46,6 +46,22 @@ public class WaitForProgressToShow { } } + public static void runOrInvokeAndWaitAboveProgress(final Runnable command, @Nullable final ModalityState modalityState) { + final Application application = ApplicationManager.getApplication(); + if (application.isDispatchThread()) { + command.run(); + } else { + final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator(); + if (pi != null) { + execute(pi); + application.invokeAndWait(command, pi.getModalityState()); + } else { + final ModalityState notNullModalityState = modalityState == null ? ModalityState.NON_MODAL : modalityState; + application.invokeAndWait(command, notNullModalityState); + } + } + } + public static void runOrInvokeLaterAboveProgress(final Runnable command, @Nullable final ModalityState modalityState, @NotNull final Project project) { final Application application = ApplicationManager.getApplication(); if (application.isDispatchThread()) { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/ModalityContextImpl.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/ModalityContextImpl.java index ca9c2dac949b..b88a34982bdb 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/ModalityContextImpl.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/ModalityContextImpl.java @@ -47,8 +47,7 @@ public class ModalityContextImpl implements ModalityContext { action.run(); } else { - ModalityState modalityState = getCurrentModalityState(); - WaitForProgressToShow.runOrInvokeLaterAboveProgress(action, modalityState, project); + WaitForProgressToShow.runOrInvokeAndWaitAboveProgress(action, getCurrentModalityState()); } } From be32735e2cf94845d4616b0b3825baceac92a21f Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 12 May 2011 13:39:59 +0200 Subject: [PATCH 201/250] cleanup --- .../history/CvsHistoryProvider.java | 32 ++++++------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/history/CvsHistoryProvider.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/history/CvsHistoryProvider.java index 4b6ad47caba7..abb7e08cd20b 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/history/CvsHistoryProvider.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/history/CvsHistoryProvider.java @@ -20,7 +20,6 @@ import com.intellij.cvsSupport2.CvsUtil; import com.intellij.cvsSupport2.application.CvsEntriesManager; import com.intellij.cvsSupport2.changeBrowser.CvsChangeList; import com.intellij.cvsSupport2.connections.CvsConnectionSettings; -import com.intellij.cvsSupport2.connections.CvsEnvironment; import com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutor; import com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutorCallback; import com.intellij.cvsSupport2.cvsExecution.ModalityContext; @@ -37,7 +36,6 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.TreeItem; import com.intellij.util.ui.AbstractTableCellEditor; import com.intellij.util.ui.ColumnInfo; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.netbeans.lib.cvsclient.admin.Entry; import org.netbeans.lib.cvsclient.command.log.LogInformation; @@ -216,24 +214,23 @@ public class CvsHistoryProvider implements VcsHistoryProvider { else { return new CvsRevisionNumber(entryFor.getRevision()); } - } @Nullable public List createRevisions(final FilePath filePath) { final ArrayList result = new ArrayList(); - final VirtualFile root = CvsVfsUtil.refreshAndFindFileByIoFile(filePath.getIOFile().getParentFile()); + final File file = filePath.getIOFile(); + final VirtualFile root = CvsVfsUtil.refreshAndFindFileByIoFile(file.getParentFile()); // check if we have a history pane open for a file in a package which has just been deleted if (root == null) return null; - final LocalPathIndifferentLogOperation logOperation = - new LocalPathIndifferentLogOperation(filePath.getIOFile()); + final LocalPathIndifferentLogOperation logOperation = new LocalPathIndifferentLogOperation(file); CvsOperationExecutor executor = new CvsOperationExecutor(myProject); executor.performActionSync(new CommandCvsHandler(CvsBundle.message("operation.name.load.file.content"), logOperation), new CvsOperationExecutorCallback() { public void executionFinished(boolean successfully) { } - public void executeInProgressAfterAction(ModalityContext modaityContext) { + public void executeInProgressAfterAction(ModalityContext modalityContext) { } public void executionFinishedSuccessfully() { @@ -241,26 +238,15 @@ public class CvsHistoryProvider implements VcsHistoryProvider { .getCvsConnectionSettingsFor(filePath.getVirtualFileParent()); final LogInformation firstLogInformation = logOperation.getFirstLogInformation(); if (firstLogInformation != null) { - result.addAll(createRevisionListOn(CvsUtil.getCvsLightweightFileForFile(filePath.getIOFile()), - firstLogInformation, env, myProject)); + final List revisionList = firstLogInformation.getRevisionList(); + for (Revision revision : revisionList) { + result.add(new CvsFileRevisionImpl(revision, CvsUtil.getCvsLightweightFileForFile(file), + firstLogInformation, env, myProject)); + } } } }); return result; - - } - - private static List createRevisionListOn(File file, - @NotNull LogInformation logInformation, - CvsEnvironment env, - Project project) { - List revisionList = logInformation.getRevisionList(); - ArrayList result = new ArrayList(); - for (final Object aRevisionList : revisionList) { - Revision revision = (Revision)aRevisionList; - result.add(new CvsFileRevisionImpl(revision, file, logInformation, env, project)); - } - return result; } public AnAction[] getAdditionalActions(final Runnable refresher) { From 865c7b0bcc85e402a99b159f6ce8e242e89acb11 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 12 May 2011 15:13:56 +0400 Subject: [PATCH 202/250] EA-27650 - IAE: ChangeSignatureProcessor. --- ...reateConstructorParameterFromFieldFix.java | 10 ++++++-- .../afterVarargs.java | 24 +++++++++++++++++++ .../beforeVarargs.java | 23 ++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterVarargs.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeVarargs.java diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java index fd62c6b0b77e..f5227741f464 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -29,6 +29,7 @@ import com.intellij.psi.*; import com.intellij.psi.impl.source.jsp.jspJava.JspClass; import com.intellij.psi.util.PsiTypesUtil; import com.intellij.refactoring.util.RefactoringUtil; +import com.intellij.util.ArrayUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; @@ -109,11 +110,16 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction { expressions[i] = factory.createExpressionFromText(value, parameter); } expressions[parameters.length] = factory.createExpressionFromText(getField().getName(), constructor); + if (constructor.isVarArgs()) { + ArrayUtil.swap(expressions, expressions.length - 1, expressions.length - 2); + } final SmartPointerManager manager = SmartPointerManager.getInstance(getField().getProject()); final SmartPsiElementPointer constructorPointer = manager.createSmartPsiElementPointer(constructor); final ChangeMethodSignatureFromUsageFix addParamFix = new ChangeMethodSignatureFromUsageFix(constructor, expressions, PsiSubstitutor.EMPTY, constructor, true, 1); - addParamFix.invoke(project, editor, file); + if (addParamFix.isAvailable(project, editor, file)) { + addParamFix.invoke(project, editor, file); + } return ApplicationManager.getApplication().runWriteAction(new Computable() { public Boolean compute() { return doCreate(project, editor, parameters, constructorPointer, addParamFix); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterVarargs.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterVarargs.java new file mode 100644 index 000000000000..e5b4cce48a2c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterVarargs.java @@ -0,0 +1,24 @@ +/* + * Copyright 2000-2011 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. + */ + +// "Add constructor parameter" "true" +class A { + private final int field; + A(int field, String... strs) { + this.field = field; + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeVarargs.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeVarargs.java new file mode 100644 index 000000000000..eeca05c7e8dc --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeVarargs.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2011 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. + */ + +// "Add constructor parameter" "true" +class A { + private final int field; + A(String... strs) { + } + +} \ No newline at end of file From 9df040a6979fc3a3eb41bef5a97c805ba948a480 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 12 May 2011 15:15:19 +0400 Subject: [PATCH 203/250] EA-27730 - AIOOBE: VariableInplaceIntroducer.getVariable --- .../introduceVariable/VariableInplaceIntroducer.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java index 9394c10aabec..5cddf59d6f00 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java @@ -151,7 +151,11 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { @Nullable protected PsiVariable getVariable() { final PsiDeclarationStatement declarationStatement = myPointer.getElement(); - return declarationStatement != null ? (PsiVariable)declarationStatement.getDeclaredElements()[0] : null; + if (declarationStatement != null) { + PsiElement[] declaredElements = declarationStatement.getDeclaredElements(); + return declaredElements.length == 0 ? null : (PsiVariable)declaredElements[0]; + } + return null; } @Override From 68acfaa4f0eef782d21316d4b4c6fdafe97fea17 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 12 May 2011 15:45:51 +0400 Subject: [PATCH 204/250] diagnostics EA-27736 - assert: CopyClassesHandler.doClone --- .../src/com/intellij/refactoring/copy/CopyClassesHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java index 1d33a133626b..50d158d41084 100644 --- a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -158,7 +158,7 @@ public class CopyClassesHandler implements CopyHandlerDelegate { public void doClone(PsiElement element) { FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.copyClass"); PsiClass[] classes = getTopLevelClasses(element); - LOG.assertTrue(classes != null && classes.length == 1); + LOG.assertTrue(classes != null && classes.length == 1, Arrays.toString(classes)); Project project = element.getProject(); CopyClassDialog dialog = new CopyClassDialog(classes[0], null, project, true); From 60ea556c14dcf646d413c7e79077da6aee8cc8aa Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Thu, 12 May 2011 13:52:14 +0200 Subject: [PATCH 205/250] AppCode:Formatter: indent members of @interface/@implementation/@protocol (OC-824) --- .../options/JavaIndentOptionsEditor.java | 8 +--- .../options/IndentOptionsEditor.java | 40 +++++++++---------- .../options/SmartIndentOptionsEditor.java | 10 +---- .../src/com/intellij/formatting/Indent.java | 15 +++++++ .../intellij/formatting/IndentFactory.java | 3 +- .../intellij/formatting/FormatterImpl.java | 11 +++-- 6 files changed, 48 insertions(+), 39 deletions(-) diff --git a/java/java-impl/src/com/intellij/application/options/JavaIndentOptionsEditor.java b/java/java-impl/src/com/intellij/application/options/JavaIndentOptionsEditor.java index 19ae70407ef6..0ffca45d2401 100644 --- a/java/java-impl/src/com/intellij/application/options/JavaIndentOptionsEditor.java +++ b/java/java-impl/src/com/intellij/application/options/JavaIndentOptionsEditor.java @@ -61,12 +61,8 @@ public class JavaIndentOptionsEditor extends SmartIndentOptionsEditor { public void apply(final CodeStyleSettings settings, final CodeStyleSettings.IndentOptions options) { super.apply(settings, options); - try { - options.LABEL_INDENT_SIZE = Integer.parseInt(myLabelIndent.getText()); - } - catch (NumberFormatException e) { - //stay with default - } + options.LABEL_INDENT_SIZE = getFieldValue(myLabelIndent, 0, options.LABEL_INDENT_SIZE); + options.LABEL_INDENT_ABSOLUTE = myLabelIndentAbsolute.isSelected(); settings.DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS = myCbDontIndentTopLevelMembers.isSelected(); options.USE_RELATIVE_INDENTS = myCbUseRelativeIndent.isSelected(); diff --git a/platform/lang-api/src/com/intellij/application/options/IndentOptionsEditor.java b/platform/lang-api/src/com/intellij/application/options/IndentOptionsEditor.java index 040ad4d4f166..d88c79a6d307 100644 --- a/platform/lang-api/src/com/intellij/application/options/IndentOptionsEditor.java +++ b/platform/lang-api/src/com/intellij/application/options/IndentOptionsEditor.java @@ -41,17 +41,21 @@ public class IndentOptionsEditor extends OptionGroup { protected void addComponents() { addTabOptions(); - myTabSizeField = new JTextField(4); - myTabSizeField.setMinimumSize(myTabSizeField.getPreferredSize()); + myTabSizeField = createIndentTextField(); myTabSizeLabel = new JLabel(ApplicationBundle.message("editbox.indent.tab.size")); add(myTabSizeLabel, myTabSizeField); - myIndentField = new JTextField(4); - myIndentField.setMinimumSize(myTabSizeField.getPreferredSize()); + myIndentField = createIndentTextField(); myIndentLabel = new JLabel(ApplicationBundle.message("editbox.indent.indent")); add(myIndentLabel, myIndentField); } + protected JTextField createIndentTextField() { + JTextField field = new JTextField(4); + field.setMinimumSize(field.getPreferredSize()); + return field; + } + protected void addTabOptions() { myCbUseTab = new JCheckBox(ApplicationBundle.message("checkbox.indent.use.tab.character")); add(myCbUseTab); @@ -71,6 +75,15 @@ public class IndentOptionsEditor extends OptionGroup { } } + protected int getFieldValue(JTextField field, int minValue, int defValue) { + try { + return Math.max(Integer.parseInt(field.getText()), minValue); + } + catch (NumberFormatException e) { + return defValue; + } + } + public boolean isModified(final CodeStyleSettings settings, CodeStyleSettings.IndentOptions options) { boolean isModified; isModified = isFieldModified(myTabSizeField, options.TAB_SIZE); @@ -81,26 +94,11 @@ public class IndentOptionsEditor extends OptionGroup { } protected int getUIIndent() { - final String indentText = myIndentField.getText(); - try { - return Math.max(Integer.parseInt(indentText), 1); - } - catch (NumberFormatException e) { - //stay with default - } - - return 4; + return getFieldValue(myIndentField, 1, 4); } protected int getUITabSize() { - try { - return Math.max(Integer.parseInt(myTabSizeField.getText()), 1); - } - catch (NumberFormatException e) { - //stay with default - } - - return 4; + return getFieldValue(myTabSizeField, 1, 4); } public void apply(final CodeStyleSettings settings, CodeStyleSettings.IndentOptions options) { diff --git a/platform/lang-api/src/com/intellij/application/options/SmartIndentOptionsEditor.java b/platform/lang-api/src/com/intellij/application/options/SmartIndentOptionsEditor.java index 927cb3d514c0..a66e270207b1 100644 --- a/platform/lang-api/src/com/intellij/application/options/SmartIndentOptionsEditor.java +++ b/platform/lang-api/src/com/intellij/application/options/SmartIndentOptionsEditor.java @@ -40,8 +40,7 @@ public class SmartIndentOptionsEditor extends IndentOptionsEditor { protected void addComponents() { super.addComponents(); - myContinuationIndentField = new JTextField(4); - myContinuationIndentField.setMinimumSize(myContinuationIndentField.getPreferredSize()); + myContinuationIndentField = createIndentTextField(); myContinuationIndentLabel = new JLabel(ApplicationBundle.message("editbox.indent.continuation.indent")); add(myContinuationIndentLabel, myContinuationIndentField); } @@ -55,12 +54,7 @@ public class SmartIndentOptionsEditor extends IndentOptionsEditor { public void apply(final CodeStyleSettings settings, final CodeStyleSettings.IndentOptions options) { super.apply(settings, options); - try { - options.CONTINUATION_INDENT_SIZE = Math.max(Integer.parseInt(myContinuationIndentField.getText()), 0); - } - catch (NumberFormatException e) { - //stay with default - } + options.CONTINUATION_INDENT_SIZE = getFieldValue(myContinuationIndentField, 0, options.CONTINUATION_INDENT_SIZE); options.SMART_TABS = isSmartTabValid(options.INDENT_SIZE, options.TAB_SIZE) && myCbSmartTabs.isSelected(); } diff --git a/platform/lang-api/src/com/intellij/formatting/Indent.java b/platform/lang-api/src/com/intellij/formatting/Indent.java index a69a47bc08c7..6840af811c61 100644 --- a/platform/lang-api/src/com/intellij/formatting/Indent.java +++ b/platform/lang-api/src/com/intellij/formatting/Indent.java @@ -252,6 +252,21 @@ public abstract class Indent { return myFactory.getIndent(type, relativeToDirectParent, enforceIndentToChildren); } + /** + * Base factory method for {@link Indent} objects construction, i.e. all other methods may be expressed in terms of this method. + * + * @param type indent type + * @param spaces the number of spaces in the indent + * @param relativeToDirectParent flag the indicates if current indent object anchors direct block parent (feel free + * to get more information about that at class-level javadoc) + * @param enforceIndentToChildren flag the indicates if current indent object should be enforced for multiline block children + * (feel free to get more information about that at class-level javadoc) + * @return newly created indent configured in accordance with the given arguments + */ + public static Indent getIndent(@NotNull Type type, int spaces, boolean relativeToDirectParent, boolean enforceIndentToChildren) { + return myFactory.getIndent(type, spaces, relativeToDirectParent, enforceIndentToChildren); + } + public static class Type { private final String myName; diff --git a/platform/lang-api/src/com/intellij/formatting/IndentFactory.java b/platform/lang-api/src/com/intellij/formatting/IndentFactory.java index ff544121235d..b18949adf2bb 100644 --- a/platform/lang-api/src/com/intellij/formatting/IndentFactory.java +++ b/platform/lang-api/src/com/intellij/formatting/IndentFactory.java @@ -32,5 +32,6 @@ interface IndentFactory { Indent getContinuationIndent(boolean relativeToDirectParent); Indent getContinuationWithoutFirstIndent(boolean relativeToDirectParent); Indent getSpaceIndent(final int spaces, boolean relativeToDirectParent); - Indent getIndent(@NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceParentIndent); + Indent getIndent(@NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceIndentToChildren); + Indent getIndent(@NotNull Indent.Type type, int spaces, boolean relativeToDirectParent, boolean enforceIndentToChildren); } diff --git a/platform/lang-impl/src/com/intellij/formatting/FormatterImpl.java b/platform/lang-impl/src/com/intellij/formatting/FormatterImpl.java index 5be50492e66e..1847bca0d027 100644 --- a/platform/lang-impl/src/com/intellij/formatting/FormatterImpl.java +++ b/platform/lang-impl/src/com/intellij/formatting/FormatterImpl.java @@ -656,12 +656,17 @@ public class FormatterImpl extends FormatterEx } public Indent getSpaceIndent(final int spaces, final boolean relative) { - return new IndentImpl(Indent.Type.SPACES, false, spaces, relative, false); + return getIndent(Indent.Type.SPACES, spaces, relative, false); } @Override - public Indent getIndent(@NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceIndent) { - return new IndentImpl(type, false, 0, relativeToDirectParent, enforceIndent); + public Indent getIndent(@NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceIndentToChildren) { + return getIndent(type, 0, relativeToDirectParent, enforceIndentToChildren); + } + + @Override + public Indent getIndent(@NotNull Indent.Type type, int spaces, boolean relativeToDirectParent, boolean enforceIndentToChildren) { + return new IndentImpl(type, false, spaces, relativeToDirectParent, enforceIndentToChildren); } public Indent getAbsoluteLabelIndent() { From 123e3e04ba12d03ad3f2e7425e9e663b91d4fba2 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 12 May 2011 11:21:24 +0400 Subject: [PATCH 206/250] PsiReferenceProviderBean per language --- .../psi/PsiReferenceProviderBean.java | 25 +++++++- .../reference/ReferenceProvidersRegistry.java | 58 +++++++++---------- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/PsiReferenceProviderBean.java b/platform/lang-api/src/com/intellij/psi/PsiReferenceProviderBean.java index 643ff81c622d..a45f911d6c03 100644 --- a/platform/lang-api/src/com/intellij/psi/PsiReferenceProviderBean.java +++ b/platform/lang-api/src/com/intellij/psi/PsiReferenceProviderBean.java @@ -16,6 +16,7 @@ package com.intellij.psi; +import com.intellij.lang.Language; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.AbstractExtensionPointBean; @@ -23,6 +24,7 @@ import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.patterns.ElementPattern; import com.intellij.patterns.ElementPatternBean; import com.intellij.patterns.StandardPatterns; +import com.intellij.util.KeyedLazyInstance; import com.intellij.util.NullableFunction; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.xmlb.annotations.AbstractCollection; @@ -31,13 +33,19 @@ import com.intellij.util.xmlb.annotations.Property; import com.intellij.util.xmlb.annotations.Tag; import org.jetbrains.annotations.Nullable; +import java.util.List; + /** * Registers a {@link PsiReferenceProvider} in plugin.xml */ -public class PsiReferenceProviderBean extends AbstractExtensionPointBean { +public class PsiReferenceProviderBean extends AbstractExtensionPointBean implements KeyedLazyInstance { public static final ExtensionPointName EP_NAME = new ExtensionPointName("com.intellij.psi.referenceProvider"); + + @Attribute("language") + public String language = Language.ANY.getID(); + @Attribute("providerClass") public String className; @@ -74,8 +82,9 @@ public class PsiReferenceProviderBean extends AbstractExtensionPointBean { @Nullable public ElementPattern createElementPattern() { if (patterns.length > 1) { - return StandardPatterns.or(ContainerUtil.mapNotNull(patterns, - PATTERN_NULLABLE_FUNCTION).toArray(new ElementPattern[0])); + List> list = ContainerUtil.mapNotNull(patterns, PATTERN_NULLABLE_FUNCTION); + //noinspection unchecked + return StandardPatterns.or(list.toArray(new ElementPattern[list.size()])); } else if (patterns.length == 1) { return patterns[0].compilePattern(); @@ -85,4 +94,14 @@ public class PsiReferenceProviderBean extends AbstractExtensionPointBean { return null; } } + + @Override + public String getKey() { + return language; + } + + @Override + public PsiReferenceProviderBean getInstance() { + return this; + } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java index b89a486980e7..2ec49f581abb 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistry.java @@ -44,7 +44,8 @@ import java.util.Map; */ public class ReferenceProvidersRegistry { - private static final LanguageExtension EXTENSION = new LanguageExtension(PsiReferenceContributor.EP_NAME.getName()); + private static final LanguageExtension CONTRIBUTOR_EXTENSION = new LanguageExtension(PsiReferenceContributor.EP_NAME.getName()); + private static final LanguageExtension REFERENCE_PROVIDER_EXTENSION = new LanguageExtension(PsiReferenceProviderBean.EP_NAME.getName()); private static final Comparator> PRIORITY_COMPARATOR = new Comparator>() { @@ -66,10 +67,33 @@ public class ReferenceProvidersRegistry { @Override protected PsiReferenceRegistrarImpl create(Language language) { PsiReferenceRegistrarImpl registrar = new PsiReferenceRegistrarImpl(); - List contributors = EXTENSION.allForLanguage(language); - for (PsiReferenceContributor contributor : contributors) { + for (PsiReferenceContributor contributor : CONTRIBUTOR_EXTENSION.allForLanguage(language)) { contributor.registerReferenceProviders(registrar); } + + List referenceProviderBeans = REFERENCE_PROVIDER_EXTENSION.allForLanguage(language); + for (final PsiReferenceProviderBean providerBean : referenceProviderBeans) { + final ElementPattern pattern = providerBean.createElementPattern(); + if (pattern != null) { + registrar.registerReferenceProvider(pattern, new PsiReferenceProvider() { + + PsiReferenceProvider myProvider; + + @NotNull + @Override + public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { + if (myProvider == null) { + + myProvider = providerBean.instantiate(); + if (myProvider == null) { + myProvider = NULL_REFERENCE_PROVIDER; + } + } + return myProvider.getReferencesByElement(element, context); + } + }); + } + } return registrar; } }; @@ -78,34 +102,6 @@ public class ReferenceProvidersRegistry { return ServiceManager.getService(ReferenceProvidersRegistry.class); } - public ReferenceProvidersRegistry() { - - PsiReferenceRegistrarImpl registrar = getRegistrar(Language.ANY); - for (final PsiReferenceProviderBean providerBean : PsiReferenceProviderBean.EP_NAME.getExtensions()) { - final ElementPattern pattern = providerBean.createElementPattern(); - if (pattern != null) { - registrar.registerReferenceProvider(pattern, new PsiReferenceProvider() { - - PsiReferenceProvider myProvider; - - @NotNull - @Override - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { - if (myProvider == null) { - - myProvider = providerBean.instantiate(); - if (myProvider == null) { - myProvider = NULL_REFERENCE_PROVIDER; - } - } - return myProvider.getReferencesByElement(element, context); - } - }); - } - } - - } - public PsiReferenceRegistrarImpl getRegistrar(Language language) { return myRegistrars.get(language); } From 25a02745c4b767698b0be585988ac57e4afe5cc5 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 12 May 2011 11:37:00 +0400 Subject: [PATCH 207/250] CustomActionsSchema converted to service --- .../ui/customization/CustomActionsSchema.java | 20 +++++-------------- .../src/META-INF/PlatformExtensions.xml | 2 ++ .../src/componentSets/Platform.xml | 3 --- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomActionsSchema.java b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomActionsSchema.java index fd2d3d70fca6..0fd6ac8846b8 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomActionsSchema.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomActionsSchema.java @@ -20,9 +20,9 @@ import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.IdeActions; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.components.ExportableApplicationComponent; +import com.intellij.openapi.components.ExportableComponent; +import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.keymap.impl.ui.ActionsTreeUtil; import com.intellij.openapi.keymap.impl.ui.Group; @@ -48,7 +48,8 @@ import java.util.List; * User: anna * Date: Jan 20, 2005 */ -public class CustomActionsSchema implements ExportableApplicationComponent, NamedJDOMExternalizable { +public class CustomActionsSchema implements ExportableComponent, NamedJDOMExternalizable { + @NonNls private static final String ACTIONS_SCHEMA = "custom_actions_schema"; @NonNls private static final String ACTIVE = "active"; @NonNls private static final String ELEMENT_ACTION = "action"; @@ -79,7 +80,7 @@ public class CustomActionsSchema implements ExportableApplicationComponent, Name private static final Logger LOG = Logger.getInstance("#" + CustomActionsSchema.class.getName()); public static CustomActionsSchema getInstance() { - return ApplicationManager.getApplication().getComponent(CustomActionsSchema.class); + return ServiceManager.getService(CustomActionsSchema.class); } public void addAction(ActionUrl url) { @@ -338,17 +339,6 @@ public void removeIconCustomization(String actionId) { return IdeBundle.message("title.custom.actions.schemas"); } - @NotNull - public String getComponentName() { - return "com.intellij.ide.ui.customization.CustomizableActionsSchemas"; - } - - public void initComponent() { - } - - public void disposeComponent() { - } - public String getExternalFileName() { return "customization"; } diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index 3aa7e19f8cc3..415c3390a7b0 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -20,6 +20,8 @@ + + diff --git a/platform/platform-resources/src/componentSets/Platform.xml b/platform/platform-resources/src/componentSets/Platform.xml index d3c8dd3fdf75..5244b44a9b35 100644 --- a/platform/platform-resources/src/componentSets/Platform.xml +++ b/platform/platform-resources/src/componentSets/Platform.xml @@ -75,9 +75,6 @@ com.intellij.ide.TipOfTheDayManager - - com.intellij.ide.ui.customization.CustomActionsSchema - com.intellij.ide.ui.LafManager com.intellij.ide.ui.LafManagerImpl From 7fba0c7ae2b81827732ff6710b8b3b0eb974cfcd Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 12 May 2011 15:41:19 +0400 Subject: [PATCH 208/250] lazy bundle loading --- platform/lang-api/src/com/intellij/facet/FacetType.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/lang-api/src/com/intellij/facet/FacetType.java b/platform/lang-api/src/com/intellij/facet/FacetType.java index e1a96fcc79e7..37b63f3ff272 100644 --- a/platform/lang-api/src/com/intellij/facet/FacetType.java +++ b/platform/lang-api/src/com/intellij/facet/FacetType.java @@ -88,12 +88,12 @@ public abstract class FacetType { } @NotNull - public final String getPresentableName() { + public String getPresentableName() { return myPresentableName; } /** - * Default name wich will be used then user creates a facet of this type + * Default name which will be used then user creates a facet of this type * @return */ @NotNull @NonNls From 38131f60b53fa297d8a83e04a37e2c8676feae14 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 12 May 2011 16:01:05 +0400 Subject: [PATCH 209/250] IDEA-69527: IDEA 10.0.3 hangs when trying to open folder or file [rev. by max] --- .../ide/projectView/impl/ClassesTreeStructureProvider.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/ide/projectView/impl/ClassesTreeStructureProvider.java b/java/java-impl/src/com/intellij/ide/projectView/impl/ClassesTreeStructureProvider.java index d7ba93b430ae..fd5c7aa0085a 100644 --- a/java/java-impl/src/com/intellij/ide/projectView/impl/ClassesTreeStructureProvider.java +++ b/java/java-impl/src/com/intellij/ide/projectView/impl/ClassesTreeStructureProvider.java @@ -27,6 +27,7 @@ import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; +import com.intellij.psi.jsp.JspFile; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -43,7 +44,7 @@ public class ClassesTreeStructureProvider implements SelectableTreeStructureProv ArrayList result = new ArrayList(); for (final AbstractTreeNode child : children) { Object o = child.getValue(); - if (o instanceof PsiClassOwner) { + if (o instanceof PsiClassOwner && !(o instanceof JspFile)) { final ViewSettings settings1 = ((ProjectViewNode)parent).getSettings(); final PsiClassOwner classOwner = (PsiClassOwner)o; final VirtualFile file = classOwner.getVirtualFile(); @@ -64,8 +65,8 @@ public class ClassesTreeStructureProvider implements SelectableTreeStructureProv } } - PsiClass[] classes = classOwner.getClasses(); if (fileInRoots(file)) { + PsiClass[] classes = classOwner.getClasses(); if (classes.length == 1 && !(classes[0] instanceof SyntheticElement) && (file == null || file.getNameWithoutExtension().equals(classes[0].getName()))) { result.add(new ClassTreeNode(myProject, classes[0], settings1)); From 7404e8a526717727ded6e0c27c7de4e504153dfc Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Thu, 12 May 2011 16:09:36 +0400 Subject: [PATCH 210/250] [xena] IDEA-69514 Ctrl-N popup broken [rev=anna.kozlova] --- .../src/com/intellij/ui/popup/AbstractPopup.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java index 773ddcdb6288..8f6664ba10ae 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -147,7 +147,6 @@ public class AbstractPopup implements JBPopup { private JTextField mySpeedSearchPatternField; private boolean myNativePopup; private boolean myMayBeParent; - private JLabel myAdCmp; private AbstractPopup.SpeedSearchKeyListener mySearchKeyListener; private JLabel myAdComponent; @@ -206,8 +205,7 @@ public class AbstractPopup implements JBPopup { myContent.add(component, BorderLayout.CENTER); if (adText != null) { - myAdCmp = HintUtil.createAdComponent(adText, HintUtil.getDefaultAdComponentBorder(), adTextAlignment); - myContent.add(myAdCmp, BorderLayout.SOUTH); + setAdText(adText, adTextAlignment); } myCancelKeyEnabled = cancelKeyEnabled; @@ -1196,6 +1194,9 @@ public class AbstractPopup implements JBPopup { } private Dimension computeWindowSize(Dimension size) { + if (myAdComponent != null && myAdComponent.isShowing()) { + size.height += myAdComponent.getPreferredSize().height + 1; + } return size; } From 4554e30ce7c52f8612dce43464abf0ceb3e970ae Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Thu, 12 May 2011 16:15:25 +0400 Subject: [PATCH 211/250] [xena] choose by name popup is not closed by focus lost by clicking editor for the first time [rev=max] --- .../com/intellij/ide/util/gotoByName/ChooseByNameBase.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index 1164381cdcc6..3d19a55f032e 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -421,13 +421,16 @@ public abstract class ChooseByNameBase { }); } else { - if (e.getOppositeComponent() != null && myList.isShowing() && (e.getOppositeComponent() == myList || SwingUtilities.isDescendingFrom(myList, e.getOppositeComponent()))) { + Component oppositeComponent = e.getOppositeComponent(); + if (oppositeComponent != null && !(oppositeComponent instanceof JFrame) && + myList.isShowing() && + (oppositeComponent == myList || SwingUtilities.isDescendingFrom(myList, oppositeComponent))) { return; } hideHint(); } } - }, 200); + }, 200); } }); } From e5d5e1704833c07a7e83641ecc4c00d14852a378 Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Thu, 12 May 2011 16:16:00 +0400 Subject: [PATCH 212/250] [mac] show window preview for minimized frame --- .../src/com/intellij/openapi/wm/impl/IdeFrameImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java index eacd43b86de8..0ab6b564d752 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java @@ -103,6 +103,10 @@ public class IdeFrameImpl extends JFrame implements IdeFrame, DataProvider { setFocusableWindowState(false); } + // to show window thumbnail under Macs + // http://lists.apple.com/archives/java-dev/2009/Dec/msg00240.html + if (SystemInfo.isMac) setIconImage(null); + MouseGestureManager.getInstance().add(this); } From 4dc5defef0904271d8734cbfaffeef00e496ac82 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Wed, 11 May 2011 19:39:21 +0400 Subject: [PATCH 213/250] IDEA-69153 Editor: Improve performance of caret movement via arrow keys Explicitly added 'sun.java2d.d3d=false' property as our Windows users reported that editor sometimes performs rather bad even with 'sun.java2d.noddraw=true' (see comments to the ticket) --- bin/idea.properties | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/idea.properties b/bin/idea.properties index e91715890671..e431fbdf7b04 100644 --- a/bin/idea.properties +++ b/bin/idea.properties @@ -45,4 +45,9 @@ idea.cycle.buffer.size=1024 # Disabling this property may lead to visual glitches like blinking and fail to repaint # on certain display adapter cards. #---------------------------------------------------------------------- -sun.java2d.noddraw=true \ No newline at end of file +sun.java2d.noddraw=true + +#---------------------------------------------------------------------- +# Removing this property may lead to editor performance degradation under Windows. +#---------------------------------------------------------------------- +sun.java2d.d3d=false \ No newline at end of file From fd3f5e58bbed5e88f0a088c8d91925dc083adb79 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Thu, 12 May 2011 16:20:58 +0400 Subject: [PATCH 214/250] IDEA-69506 Code Wrapping Creates Errors In XML 1. Defined basic class for PSI-aware line wrapping strategy; 2. Created markup-specific line wrapping strategy; 3. Corresponding test is added; --- .../LanguageLineWrapPositionStrategy.java | 6 + ...iAwareDefaultLineWrapPositionStrategy.java | 49 +++++ .../PsiAwareLineWrapPositionStrategy.java | 170 ++++++++++++++++++ .../editorActions/AutoHardWrapHandler.java | 2 +- .../source/codeStyle/CodeFormatterFacade.java | 3 +- .../GenericLineWrapPositionStrategy.java | 3 + .../editor/LineWrapPositionStrategy.java | 5 +- .../DefaultLineWrapPositionStrategyTest.java | 5 +- .../mapping/SoftWrapApplianceManager.java | 2 +- .../src/META-INF/XmlPlugin.xml | 3 + .../intellij/testFramework/TestFileType.java | 2 +- .../MarkupLineWrapPositionStrategy.java | 35 ++++ 12 files changed, 279 insertions(+), 6 deletions(-) create mode 100644 platform/lang-api/src/com/intellij/openapi/editor/PsiAwareDefaultLineWrapPositionStrategy.java create mode 100644 platform/lang-api/src/com/intellij/openapi/editor/PsiAwareLineWrapPositionStrategy.java create mode 100644 xml/impl/src/com/intellij/psi/formatter/MarkupLineWrapPositionStrategy.java diff --git a/platform/lang-api/src/com/intellij/openapi/editor/LanguageLineWrapPositionStrategy.java b/platform/lang-api/src/com/intellij/openapi/editor/LanguageLineWrapPositionStrategy.java index 5a764d64fd28..c60e9996bb53 100644 --- a/platform/lang-api/src/com/intellij/openapi/editor/LanguageLineWrapPositionStrategy.java +++ b/platform/lang-api/src/com/intellij/openapi/editor/LanguageLineWrapPositionStrategy.java @@ -53,4 +53,10 @@ public class LanguageLineWrapPositionStrategy extends LanguageExtensionPsiAwareLineWrapPositionStrategy object. + * + * @param enabledTypes target element/token types where line wrapping is allowed + */ + public PsiAwareLineWrapPositionStrategy(@NotNull IElementType ... enabledTypes) { + myEnabledTypes = TokenSet.create(enabledTypes); + if (enabledTypes.length <= 0) { + LOG.warn(String.format("%s instance is created with empty token/element types. That will lead to inability to perform line wrap", + getClass().getName())); + } + } + + @Override + public int calculateWrapPosition(@NotNull Document document, + @Nullable Project project, + int startOffset, + int endOffset, + int maxPreferredOffset, + boolean allowToBeyondMaxPreferredOffset) { + if (project == null) { + return -1; + } + + PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project); + if (documentManager == null) { + return -1; + } + + PsiFile psiFile = documentManager.getPsiFile(document); + if (psiFile == null) { + return -1; + } + + PsiElement element = psiFile.findElementAt(maxPreferredOffset); + if (element == null) { + return -1; + } + + for (; element != null && element.getTextRange().getEndOffset() > startOffset; element = getPrevious(element)) { + if (allowToWrapInside(element)) { + TextRange textRange = element.getTextRange(); + int start = textRange.getStartOffset(); + int end = textRange.getEndOffset(); + int result = doCalculateWrapPosition(document, project, start, end, end, false); + if (result >= 0) { + return result; + } + + // Assume that it's possible to wrap on token boundary (makes sense at least for the tokens that occupy one symbol only). + if (end <= maxPreferredOffset) { + return end; + } + + if (start > startOffset) { + return start; + } + } + } + return -1; + } + + /** + * Serves for the same purposes as {@link #calculateWrapPosition(Document, Project, int, int, int, boolean)} but ensures that given + * offsets target {@link #PsiAwareLineWrapPositionStrategy(IElementType...) enabled token/element types}. + * + * @param document target document which text is being processed + * @param project target project + * @param startOffset start offset to use with the given text holder (inclusive) + * @param endOffset end offset to use with the given text holder (exclusive) + * @param maxPreferredOffset this method is expected to do its best to return offset that belongs to + * (startOffset; maxPreferredOffset] interval. However, it's allowed + * to return value from (maxPreferredOffset; endOffset] interval + * unless 'allowToBeyondMaxPreferredOffset' if 'false' + * @param allowToBeyondMaxPreferredOffset indicates if it's allowed to return value from + * (maxPreferredOffset; endOffset] interval in case of inability to + * find appropriate offset from (startOffset; maxPreferredOffset] interval + * @return offset from (startOffset; endOffset] interval where + * target line should be wrapped OR -1 if no wrapping should be performed + */ + protected abstract int doCalculateWrapPosition( + @NotNull Document document, @Nullable Project project, int startOffset, int endOffset, int maxPreferredOffset, + boolean allowToBeyondMaxPreferredOffset + ); + + /** + * Allows to check if line wrap at the text range defined by the given element is allowed. + * + * @param element element that defines target text range + * @return true if wrapping at the text range defined by the given element is allowed; + * false otherwise + */ + private boolean allowToWrapInside(@NotNull PsiElement element) { + TextRange textRange = element.getTextRange(); + for (PsiElement parent = element; parent != null && parent.getTextRange().equals(textRange); parent = parent.getParent()) { + ASTNode parentNode = parent.getNode(); + if (parentNode != null && myEnabledTypes.contains(parentNode.getElementType())) { + return true; + } + } + return false; + } + + @Nullable + private static PsiElement getPrevious(@NotNull PsiElement element) { + PsiElement result = element.getPrevSibling(); + if (result != null) { + return result; + } + + PsiElement parent = element.getParent(); + if (parent == null) { + return null; + } + + PsiElement parentSibling = null; + for (; parent != null && parentSibling == null; parent = parent.getParent()) { + parentSibling = parent.getPrevSibling(); + } + + if (parentSibling == null) { + return null; + } + + result = parentSibling.getLastChild(); + return result == null ? parentSibling : result; + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/AutoHardWrapHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/AutoHardWrapHandler.java index 93380dba8fbe..656992640479 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/AutoHardWrapHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/AutoHardWrapHandler.java @@ -150,7 +150,7 @@ public class AutoHardWrapHandler { new VisualPosition(caretModel.getVisualPosition().line, margin - FormatConstants.RESERVED_LINE_WRAP_WIDTH_IN_COLUMNS) )); - int wrapOffset = strategy.calculateWrapPosition(document, startOffset, endOffset, maxPreferredOffset, true); + int wrapOffset = strategy.calculateWrapPosition(document, project, startOffset, endOffset, maxPreferredOffset, true); if (wrapOffset < 0) { return; } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java index 74d194ad300b..c37d5cf16b4a 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java @@ -370,7 +370,8 @@ public class CodeFormatterFacade { // We know that current line exceeds right margin if control flow reaches this place, so, wrap it. int wrapOffset = strategy.calculateWrapPosition( - document, Math.max(startLineOffset, startOffsetToUse), Math.min(endLineOffset, endOffsetToUse), preferredWrapPosition, false + document, editor.getProject(), Math.max(startLineOffset, startOffsetToUse), Math.min(endLineOffset, endOffsetToUse), + preferredWrapPosition, false ); if (wrapOffset < 0) { continue; diff --git a/platform/platform-api/src/com/intellij/openapi/editor/GenericLineWrapPositionStrategy.java b/platform/platform-api/src/com/intellij/openapi/editor/GenericLineWrapPositionStrategy.java index 034752813a19..93289b0caddd 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/GenericLineWrapPositionStrategy.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/GenericLineWrapPositionStrategy.java @@ -15,8 +15,10 @@ */ package com.intellij.openapi.editor; +import com.intellij.openapi.project.Project; import gnu.trove.TIntObjectHashMap; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -42,6 +44,7 @@ public class GenericLineWrapPositionStrategy implements LineWrapPositionStrategy @Override public int calculateWrapPosition(@NotNull Document document, + @Nullable Project project, int startOffset, int endOffset, int maxPreferredOffset, diff --git a/platform/platform-api/src/com/intellij/openapi/editor/LineWrapPositionStrategy.java b/platform/platform-api/src/com/intellij/openapi/editor/LineWrapPositionStrategy.java index 5463c323c295..958db895b793 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/LineWrapPositionStrategy.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/LineWrapPositionStrategy.java @@ -15,7 +15,9 @@ */ package com.intellij.openapi.editor; +import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Defines contract for the strategy that calculates the best place to apply wrap to particular line (sequence of characters). @@ -33,6 +35,7 @@ public interface LineWrapPositionStrategy { * Allows to calculate the most appropriate position to wrap target line. * * @param document target document which text is being processed + * @param project target project * @param startOffset start offset to use with the given text holder (inclusive) * @param endOffset end offset to use with the given text holder (exclusive) * @param maxPreferredOffset this method is expected to do its best to return offset that belongs to @@ -46,7 +49,7 @@ public interface LineWrapPositionStrategy { * target line should be wrapped OR -1 if no wrapping should be performed */ int calculateWrapPosition( - @NotNull Document document, int startOffset, int endOffset, int maxPreferredOffset, + @NotNull Document document, @Nullable Project project, int startOffset, int endOffset, int maxPreferredOffset, boolean allowToBeyondMaxPreferredOffset ); } diff --git a/platform/platform-api/testSrc/com/intellij/openapi/editor/DefaultLineWrapPositionStrategyTest.java b/platform/platform-api/testSrc/com/intellij/openapi/editor/DefaultLineWrapPositionStrategyTest.java index 5039210ba0e0..8d5ba9fa4e19 100644 --- a/platform/platform-api/testSrc/com/intellij/openapi/editor/DefaultLineWrapPositionStrategyTest.java +++ b/platform/platform-api/testSrc/com/intellij/openapi/editor/DefaultLineWrapPositionStrategyTest.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.editor; +import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; import org.jmock.Expectations; import org.jmock.Mockery; @@ -36,6 +37,7 @@ public class DefaultLineWrapPositionStrategyTest { private Mockery myMockery; private DefaultLineWrapPositionStrategy myStrategy; + private Project myProject; @Before public void setUp() { @@ -44,6 +46,7 @@ public class DefaultLineWrapPositionStrategyTest { myMockery = new JUnit4Mockery() {{ setImposteriser(ClassImposteriser.INSTANCE); }}; + myProject = myMockery.mock(Project.class); } @Test @@ -82,7 +85,7 @@ public class DefaultLineWrapPositionStrategyTest { final Context context = new Context(document); context.init(); int actual = myStrategy.calculateWrapPosition( - createMockDocument(context.document), 0, context.document.length(), context.edgeIndex, allowToBeyondMaxPreferredOffset + createMockDocument(context.document), myProject, 0, context.document.length(), context.edgeIndex, allowToBeyondMaxPreferredOffset ); assertSame(context.wrapIndex, actual); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java index 018bd8e86f97..c5b13189cd6f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java @@ -519,7 +519,7 @@ public class SoftWrapApplianceManager implements SoftWrapFoldingListener, Docume myLineWrapPositionStrategy = LanguageLineWrapPositionStrategy.INSTANCE.forEditor(myEditor); } - softWrapOffset = myLineWrapPositionStrategy.calculateWrapPosition(document, minOffset, maxOffset, preferredOffset, true); + softWrapOffset = myLineWrapPositionStrategy.calculateWrapPosition(document, myEditor.getProject(), minOffset, maxOffset, preferredOffset, true); } if (softWrapOffset >= lineData.endLineOffset || softWrapOffset < 0) { diff --git a/platform/platform-resources/src/META-INF/XmlPlugin.xml b/platform/platform-resources/src/META-INF/XmlPlugin.xml index b5ee440d7542..0b7fc46cdafc 100644 --- a/platform/platform-resources/src/META-INF/XmlPlugin.xml +++ b/platform/platform-resources/src/META-INF/XmlPlugin.xml @@ -150,6 +150,9 @@ + + + diff --git a/platform/testFramework/src/com/intellij/testFramework/TestFileType.java b/platform/testFramework/src/com/intellij/testFramework/TestFileType.java index 42f1174cc764..9b4c58cdffcf 100644 --- a/platform/testFramework/src/com/intellij/testFramework/TestFileType.java +++ b/platform/testFramework/src/com/intellij/testFramework/TestFileType.java @@ -23,7 +23,7 @@ package com.intellij.testFramework; */ public enum TestFileType { - JAVA("java"), SQL("sql"), TEXT("txt"); + JAVA("java"), SQL("sql"), TEXT("txt"), XML("xml"), HTML("html"), XHTML("xhtml"); private final String myExtension; diff --git a/xml/impl/src/com/intellij/psi/formatter/MarkupLineWrapPositionStrategy.java b/xml/impl/src/com/intellij/psi/formatter/MarkupLineWrapPositionStrategy.java new file mode 100644 index 000000000000..1f3c21bc9960 --- /dev/null +++ b/xml/impl/src/com/intellij/psi/formatter/MarkupLineWrapPositionStrategy.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2011 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.formatter; + +import com.intellij.openapi.editor.LineWrapPositionStrategy; +import com.intellij.openapi.editor.PsiAwareDefaultLineWrapPositionStrategy; +import com.intellij.psi.TokenType; +import com.intellij.psi.xml.XmlElementType; +import com.intellij.psi.xml.XmlTokenType; + +/** + * {@link LineWrapPositionStrategy} for markup languages like XML, HTML etc. + * + * @author Denis Zhdanov + * @since 5/11/11 7:42 PM + */ +public class MarkupLineWrapPositionStrategy extends PsiAwareDefaultLineWrapPositionStrategy { + + public MarkupLineWrapPositionStrategy() { + super(XmlElementType.XML_TEXT, TokenType.WHITE_SPACE); + } +} From 6b852d8b87762d5f0bd8a344853c39f21a53f453 Mon Sep 17 00:00:00 2001 From: Sascha Weinreuter Date: Thu, 12 May 2011 14:29:51 +0200 Subject: [PATCH 215/250] Trivial: Typo fixed & null checks added (cherry picked from commit 0b11686fa24121522e194ee89409eff40f8be310) --- .../lang/xpath/validation/XPathAnnotator.java | 13 ++++++++----- .../intersectOperatorNotApplicable.xpath2 | 2 +- .../highlighting/plusOperatorNotApplicable.xpath2 | 2 +- .../highlighting/toOperatorNotApplicable.xpath2 | 2 +- .../highlighting/unionOperatorNotApplicable.xpath2 | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/XPathAnnotator.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/XPathAnnotator.java index b87a2505bb6f..073da9f370d2 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/XPathAnnotator.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/XPathAnnotator.java @@ -159,9 +159,9 @@ public final class XPathAnnotator extends XPath2ElementVisitor implements Annota @Override public void visitXPathBinaryExpression(final XPathBinaryExpression o) { - if (o.getXPathVersion() == XPathVersion.V2) { + final XPathExpression operand = o.getLOperand(); + if (operand != null && o.getXPathVersion() == XPathVersion.V2) { final XPathElementType operator = o.getOperator(); - final XPathExpression operand = o.getLOperand(); if (XPath2TokenTypes.COMP_OPS.contains(operator)) { if (operand instanceof XPathBinaryExpression && XPath2TokenTypes.COMP_OPS.contains(((XPathBinaryExpression)operand).getOperator())) { @@ -213,13 +213,16 @@ public final class XPathAnnotator extends XPath2ElementVisitor implements Annota } private void checkApplicability(XPathBinaryExpression o, XPath2Type... applicableTypes) { - final XPathType leftType = XPath2Type.mapType(o.getLOperand().getType()); + final XPathExpression lOperand = o.getLOperand(); + assert lOperand != null; + + final XPathType leftType = XPath2Type.mapType(lOperand.getType()); for (XPath2Type applicableType : applicableTypes) { if (XPathType.isAssignable(applicableType, leftType)) { return; } } - myHolder.createErrorAnnotation(o, "Operator '" + o.getOperationSign() + "' cannot to applied to expressions of type '" + leftType.getName() + "'"); + myHolder.createErrorAnnotation(o, "Operator '" + o.getOperationSign() + "' cannot be applied to expressions of type '" + leftType.getName() + "'"); } @Override @@ -531,7 +534,7 @@ public final class XPathAnnotator extends XPath2ElementVisitor implements Annota final XPathExpression expression = o.getPredicateExpression(); if (expression instanceof XPathLocationPath) { final XPathExpression parentOfType = PsiTreeUtil.getParentOfType(o, XPathExpression.class, true); - if (XPath2Type.ANYATOMICTYPE.isAssignableFrom(parentOfType.getType())) { + if (parentOfType != null && XPath2Type.ANYATOMICTYPE.isAssignableFrom(parentOfType.getType())) { myHolder.createErrorAnnotation(expression, "Axis step cannot be used here: the context item is an atomic value"); } } diff --git a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/intersectOperatorNotApplicable.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/intersectOperatorNotApplicable.xpath2 index 280e24766fae..5f8bffa13bb7 100644 --- a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/intersectOperatorNotApplicable.xpath2 +++ b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/intersectOperatorNotApplicable.xpath2 @@ -1 +1 @@ -'abc' intersect . \ No newline at end of file +'abc' intersect . \ No newline at end of file diff --git a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/plusOperatorNotApplicable.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/plusOperatorNotApplicable.xpath2 index 59e019243479..9e581fe63019 100644 --- a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/plusOperatorNotApplicable.xpath2 +++ b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/plusOperatorNotApplicable.xpath2 @@ -1 +1 @@ -'55' + 1 \ No newline at end of file +'55' + 1 \ No newline at end of file diff --git a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/toOperatorNotApplicable.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/toOperatorNotApplicable.xpath2 index 9ac8395044a9..49cfea182ccc 100644 --- a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/toOperatorNotApplicable.xpath2 +++ b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/toOperatorNotApplicable.xpath2 @@ -1 +1 @@ -'1' to 2 \ No newline at end of file +'1' to 2 \ No newline at end of file diff --git a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/unionOperatorNotApplicable.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/unionOperatorNotApplicable.xpath2 index 0ad22a1a1187..f68544757617 100644 --- a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/unionOperatorNotApplicable.xpath2 +++ b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/unionOperatorNotApplicable.xpath2 @@ -1 +1 @@ -1 union 2 \ No newline at end of file +1 union 2 \ No newline at end of file From a31c6bce7a0b1042f9baa127445c38b6eac86c51 Mon Sep 17 00:00:00 2001 From: Sascha Weinreuter Date: Thu, 12 May 2011 14:30:02 +0200 Subject: [PATCH 216/250] Trivial: Typo fixed (IDEA forgot to commit the file!)(cherry picked from commit a5ef9dd) --- .../xpath2/highlighting/types/durationIDivNumeric.xpath2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/durationIDivNumeric.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/durationIDivNumeric.xpath2 index fe4ef2f6c3f4..4846438418cd 100644 --- a/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/durationIDivNumeric.xpath2 +++ b/plugins/xpath/xpath-lang/testData/xpath2/highlighting/types/durationIDivNumeric.xpath2 @@ -1 +1 @@ -'P0DTOH' cast as xs:dayTimeDuration idiv 4 \ No newline at end of file +'P0DTOH' cast as xs:dayTimeDuration idiv 4 From 6499949b5ccaf1a8a2a05a1a0015a1a8c2f41fb2 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Thu, 12 May 2011 17:38:07 +0400 Subject: [PATCH 217/250] IDEA-69559 Emacs keymap: Ctr+o should insert a new line --- platform/platform-resources/src/idea/Keymap_Emacs.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/platform-resources/src/idea/Keymap_Emacs.xml b/platform/platform-resources/src/idea/Keymap_Emacs.xml index 2f98ae8c8187..e86caaf078da 100644 --- a/platform/platform-resources/src/idea/Keymap_Emacs.xml +++ b/platform/platform-resources/src/idea/Keymap_Emacs.xml @@ -25,6 +25,10 @@ + + + + From d469a37fb791a155004b1b6303edf3d8e4fd49ad Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 12 May 2011 18:01:26 +0400 Subject: [PATCH 218/250] skip copyright for tests --- .../afterVarargs.java | 16 ---------------- .../beforeVarargs.java | 16 ---------------- 2 files changed, 32 deletions(-) diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterVarargs.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterVarargs.java index e5b4cce48a2c..f42c8ed84128 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterVarargs.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterVarargs.java @@ -1,19 +1,3 @@ -/* - * Copyright 2000-2011 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. - */ - // "Add constructor parameter" "true" class A { private final int field; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeVarargs.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeVarargs.java index eeca05c7e8dc..74b76f9c499f 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeVarargs.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeVarargs.java @@ -1,19 +1,3 @@ -/* - * Copyright 2000-2011 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. - */ - // "Add constructor parameter" "true" class A { private final int field; From 4441e79cac29f6cbb9e4b0aa05dbb0eeb17dd6c0 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 15:46:07 +0200 Subject: [PATCH 219/250] matching degree in NameUtil --- .../src/com/intellij/psi/codeStyle/NameUtil.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java b/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java index d28c11119826..6dee1377317b 100644 --- a/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java +++ b/platform/util/src/com/intellij/psi/codeStyle/NameUtil.java @@ -599,6 +599,21 @@ public class NameUtil { return null; } + public int matchingDegree(String name) { + Iterable iterable = matchingFragments(name); + if (iterable == null) return Integer.MIN_VALUE; + + int matchingCaps = 0; + int fragmentCount = 0; + for (TextRange range : iterable) { + matchingCaps += StringUtil.capitalsOnly(name.substring(range.getStartOffset(), range.getEndOffset())).length(); + fragmentCount++; + } + + int patternCaps = StringUtil.capitalsOnly(new String(myPattern)).length(); + return -fragmentCount - Math.max(0, patternCaps - matchingCaps) * 10; + } + private static boolean isWordSeparator(char c) { return Character.isWhitespace(c) || c == '_' || c == '-'; } From c37398c22c3e2e2129c9a13db77fb96d58573f3f Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 15:46:26 +0200 Subject: [PATCH 220/250] thread-safe lookup retrieval in autopopup tests --- .../completion/CompletionAutoPopupTestCase.groovy | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy index a462ec0fff4f..591878f2d9f2 100644 --- a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy +++ b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy @@ -57,7 +57,10 @@ abstract class CompletionAutoPopupTestCase extends LightCodeInsightFixtureTestCa protected void joinCompletion() { for (j in 1..4000) { - LookupImpl l = LookupManager.getInstance(project).activeLookup + LookupImpl l = null + edt { + l = LookupManager.getInstance(project).activeLookup + } if (!l || !l.calculating) { joinAlarm() // for invokeLater in CompletionProgressIndicator.stop() return From 4041c94e80162707bbd09b166cb6c3e3624ec94b Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 16:21:25 +0200 Subject: [PATCH 221/250] [^yole] don't freeze and mark lookup items as preselected when lookup is not shown yet (IDEA-69590, IDEA-69259) --- .../codeInsight/completion/JavaAutoPopupTest.groovy | 11 +++++++++++ .../intellij/codeInsight/lookup/impl/LookupImpl.java | 12 ++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index 97469807117a..2dbaa5f3098e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -761,7 +761,18 @@ public class Bar { assert myFixture.lookupElementStrings.containsAll(['private', 'protected']) } + public void testExactMatchesFirst() { + myFixture.configureByText("a.java", """ +public class UTest { + void nextWord() {} + void foo() { + n + } +}""") + type 'ew' + assert myFixture.lookupElementStrings == ['new', 'nextWord'] + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index 4dd8f4e8f52a..9803e6eb343a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -65,7 +65,6 @@ import com.intellij.util.containers.ConcurrentHashMap; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.AsyncProcessIcon; import com.intellij.util.ui.ButtonlessScrollBarUI; -import gnu.trove.THashSet; import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -384,11 +383,6 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable final List items = matchingItems(snapshot); - List oldItems = getItems(); - if (oldItems.size() == items.size() && new THashSet(items, TObjectHashingStrategy.IDENTITY).containsAll(oldItems)) { - return; - } - checkMinPrefixLengthChanges(items); boolean hasPreselected = !mySelectionTouched && items.contains(myPreselectedItem); @@ -405,7 +399,9 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable myPreferredItemsCount = model.size(); myFrozenItems.clear(); - myFrozenItems.addAll(model); + if (myShown) { + myFrozenItems.addAll(model); + } model.addAll(addRemainingItemsLexicographically(model, items)); @@ -499,7 +495,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable myList.setSelectedIndex(doSelectMostPreferableItem(getItems())); } - if (myPreselectedItem != null) { + if (myPreselectedItem != null && myShown) { myPreselectedItem = getCurrentItem(); } } From 3076b045e834a5f327b266947a79f8dab531665b Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Thu, 12 May 2011 16:49:29 +0200 Subject: [PATCH 222/250] Platform:Formatter: 'Blank Lines' renamed to 'Minimum Blank Lines', 'Keep Blank Lines'->'Keep Maximum Blank Lines' AppCode:Formatter: correctly using 'keep blank lines in declarations' option. --- .../psi/codeStyle/CodeStyleSettingsCustomizable.java | 2 +- .../src/messages/ApplicationBundle.properties | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsCustomizable.java b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsCustomizable.java index 7a3096e219bd..d0138253edfa 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsCustomizable.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsCustomizable.java @@ -27,8 +27,8 @@ public interface CodeStyleSettingsCustomizable { String SPACES_WITHIN_TYPE_ARGUMENTS = ApplicationBundle.message("group.spaces.in.type.arguments"); String SPACES_OTHER = ApplicationBundle.message("group.spaces.other"); - String BLANK_LINES = ApplicationBundle.message("title.blank.lines"); String BLANK_LINES_KEEP = ApplicationBundle.message("title.keep.blank.lines"); + String BLANK_LINES = ApplicationBundle.message("title.minimum.blank.lines"); String WRAPPING_KEEP = ApplicationBundle.message("wrapping.keep.when.reformatting"); String WRAPPING_BRACES = ApplicationBundle.message("wrapping.brace.placement"); diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index 5d02a090b8b8..54eb4960eebe 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -36,7 +36,6 @@ combobox.autocomplete.casesensitive.all=All combobox.autocomplete.casesensitive.none=None combobox.autocomplete.casesensitive.first.letter=First letter combobox.autocomplete.casesensitive.all.uppercase=First letter and all uppercase letters -title.blank.lines=Blank Lines editbox.blanklines.before.package.statement=Before package statement: editbox.blanklines.after.package.statement=After package statement: editbox.blanklines.before.imports=Before imports: @@ -47,7 +46,9 @@ editbox.blanklines.around.method=Around method: editbox.blanklines.before.method.body=Before method body: editbox.blanklines.after.class.header=After class header: editbox.blanklines.after.anonymous.class.header=After anonymous class header: -title.keep.blank.lines=Keep Blank Lines +title.blank.lines=Blank Lines +title.keep.blank.lines=Keep Maximum Blank Lines +title.minimum.blank.lines=Minimum Blank Lines editbox.keep.blanklines.in.declarations=In declarations: editbox.keep.blanklines.in.code=In code: editbox.keep.blanklines.before.rbrace=Before '}': From cc70c3088334402d654337b7f2c19b127344b89e Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 17:42:23 +0200 Subject: [PATCH 223/250] in Go To Class preselect the item with the biggest matching degree (IDEA-69335) --- .../intellij/ide/util/gotoByName/ChooseByNameBase.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index 3d19a55f032e..3ce6cdddb663 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -87,6 +87,7 @@ public abstract class ChooseByNameBase { private boolean myPreselectInitialText; private final Reference myContext; private boolean mySearchInAnyPlace = false; + private NameUtil.Matcher myLastMatcher; protected Component myPreviouslyFocusedComponent; @@ -873,17 +874,23 @@ public abstract class ChooseByNameBase { private int detectBestStatisticalPosition() { int best = 0; int bestPosition = 0; + int bestMatch = Integer.MIN_VALUE; final int count = myListModel.getSize(); + NameUtil.Matcher matcher = buildPatternMatcher(getNamePattern(myTextField.getText())); + final String statContext = statisticsContext(); for (int i = 0; i < count; i++) { final Object modelElement = myListModel.getElementAt(i); String text = EXTRA_ELEM.equals(modelElement) ? null : myModel.getFullName(modelElement); if (text != null) { + String shortName = myModel.getElementName(modelElement); + int match = shortName != null && matcher instanceof NameUtil.MinusculeMatcher ? ((NameUtil.MinusculeMatcher)matcher).matchingDegree(shortName) : Integer.MIN_VALUE; int stats = StatisticsManager.getInstance().getUseCount(new StatisticsInfo(statContext, text)); - if (stats > best) { + if (stats > best || stats == best && match > bestMatch) { best = stats; bestPosition = i; + bestMatch = match; } } } From 296e569942f5fd9f5600d5d35a1b44d3ed6235f1 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 17:59:09 +0200 Subject: [PATCH 224/250] don't print debug info --- .../jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy index 7a62b026b37c..67072be6a034 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy @@ -86,7 +86,7 @@ class GroovyDebuggerTest extends GroovyCompilerTestCase { } private void runDebugger(String mainClass, Closure cl) { - boolean trace = name == 'testClassOutOfSourceRoots' + boolean trace = false//name == 'testClassOutOfSourceRoots' make() edt { ProgramRunner runner = ProgramRunner.PROGRAM_RUNNER_EP.extensions.find { it.class == GenericDebuggerRunner } From 8301cbedaecbd00412b2ce4d14975beefcdda01b Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 18:02:02 +0200 Subject: [PATCH 225/250] IDEA-68698 Elements with exactly same prefix (and same proximity) should be placed at the top of the list --- .../normalSorting/PreferMoreMatching.java | 9 +++++ .../NormalCompletionOrderingTest.java | 4 +++ .../completion/PrefixMatchingWeigher.java | 36 +++++++------------ 3 files changed, 25 insertions(+), 24 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/normalSorting/PreferMoreMatching.java diff --git a/java/java-tests/testData/codeInsight/completion/normalSorting/PreferMoreMatching.java b/java/java-tests/testData/codeInsight/completion/normalSorting/PreferMoreMatching.java new file mode 100644 index 000000000000..a9fa56e86efb --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normalSorting/PreferMoreMatching.java @@ -0,0 +1,9 @@ +class FooOCSomething {} +class FooObjectCollector {} + +class Foo { + { + FooOC + } + +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java index 69de8cb40eaa..d1c73ff0b74f 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java @@ -209,6 +209,10 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase { checkPreferredItems(0, "else", "element"); } + public void testPreferMoreMatching() { + checkPreferredItems(0, "FooOCSomething", "FooObjectCollector"); + } + public void testPreferSamePackageOverImported() { myFixture.addClass("package bar; public class Bar1 {}"); myFixture.addClass("package bar; public class Bar2 {}"); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/PrefixMatchingWeigher.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/PrefixMatchingWeigher.java index a0528315017b..05e452a2fddd 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/PrefixMatchingWeigher.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/PrefixMatchingWeigher.java @@ -15,12 +15,11 @@ */ package com.intellij.codeInsight.completion; +import com.intellij.codeInsight.CodeInsightSettings; import com.intellij.codeInsight.lookup.LookupElement; -import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.codeStyle.NameUtil; import org.jetbrains.annotations.NotNull; -import java.util.Set; - /** * @author peter */ @@ -29,27 +28,16 @@ public class PrefixMatchingWeigher extends CompletionWeigher { public Comparable weigh(@NotNull final LookupElement item, @NotNull final CompletionLocation location) { final String prefix = location.getCompletionParameters().getLookup().itemPattern(item); - if (prefix.isEmpty()) { - return 0; + final int setting = CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE; + final NameUtil.MatchingCaseSensitivity sensitivity = + setting == CodeInsightSettings.NONE ? NameUtil.MatchingCaseSensitivity.NONE : + setting == CodeInsightSettings.FIRST_LETTER ? NameUtil.MatchingCaseSensitivity.FIRST_LETTER : NameUtil.MatchingCaseSensitivity.ALL; + final NameUtil.MinusculeMatcher matcher = new NameUtil.MinusculeMatcher(prefix, sensitivity); + + int max = Integer.MIN_VALUE; + for (String lookupString : item.getAllLookupStrings()) { + max = Math.max(max, matcher.matchingDegree(lookupString)); } - - final Set strings = item.getAllLookupStrings(); - final String prefixHumps = StringUtil.capitalsOnly(prefix); - - if (StringUtil.isNotEmpty(prefixHumps)) { - for (String lookupString : strings) { - if (StringUtil.capitalsOnly(lookupString).startsWith(prefixHumps)) return 100; - } - } - - for (String lookupString : strings) { - if (lookupString.startsWith(prefix)) return 5; - } - for (String lookupString : strings) { - if (StringUtil.startsWithIgnoreCase(lookupString, prefix)) return 1; - } - - - return 0; + return max; } } From 7d674700709dd5cb1e5a5bd93379f740a397e8c4 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 18:39:59 +0200 Subject: [PATCH 226/250] prefix matching should depend on the actual prefix in the editor, not on the one that the completion was invoked with (IDEA-69525) --- .../completion/JavaAutoPopupTest.groovy | 8 +++ .../completion/PrefixMatchingWeigher.java | 7 ++- .../impl/CompletionServiceImpl.java | 37 +++++++++---- .../completion/impl/CompletionSorterImpl.java | 8 +-- .../lookup/CachingComparingClassifier.java | 52 +++++++++++++++++++ .../lookup/ComparingClassifier.java | 16 ++---- 6 files changed, 97 insertions(+), 31 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/codeInsight/lookup/CachingComparingClassifier.java diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index 2dbaa5f3098e..619f98c24566 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -774,5 +774,13 @@ public class UTest { assert myFixture.lookupElementStrings == ['new', 'nextWord'] } + public void testUpdatePrefixMatchingOnTyping() { + myFixture.addClass("class CertificateEncodingException {}") + myFixture.addClass("class CertificateException {}") + myFixture.configureByText 'a.java', 'class Foo {}' + type 'CertificateExce' + assert myFixture.lookupElementStrings == ['CertificateException', 'CertificateEncodingException'] + } + } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/PrefixMatchingWeigher.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/PrefixMatchingWeigher.java index 05e452a2fddd..a688fc1157df 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/PrefixMatchingWeigher.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/PrefixMatchingWeigher.java @@ -25,7 +25,12 @@ import org.jetbrains.annotations.NotNull; */ public class PrefixMatchingWeigher extends CompletionWeigher { - public Comparable weigh(@NotNull final LookupElement item, @NotNull final CompletionLocation location) { + @Override + public Comparable weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) { + throw new UnsupportedOperationException("Not implemented"); + } + + public static int getPrefixMatchingDegree(LookupElement item, CompletionLocation location) { final String prefix = location.getCompletionParameters().getLookup().itemPattern(item); final int setting = CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionServiceImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionServiceImpl.java index a87472cfc4c2..cc9761728e43 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionServiceImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionServiceImpl.java @@ -16,10 +16,7 @@ package com.intellij.codeInsight.completion.impl; import com.intellij.codeInsight.completion.*; -import com.intellij.codeInsight.lookup.Classifier; -import com.intellij.codeInsight.lookup.ClassifierFactory; -import com.intellij.codeInsight.lookup.LookupElement; -import com.intellij.codeInsight.lookup.LookupElementWeigher; +import com.intellij.codeInsight.lookup.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; @@ -262,13 +259,31 @@ public class CompletionServiceImpl extends CompletionService{ } for (final Weigher weigher : WeighingService.getWeighers(CompletionService.RELEVANCE_KEY)) { - sorter = sorter.weigh(new LookupElementWeigher(weigher.toString()) { - @NotNull - @Override - public Comparable weigh(@NotNull LookupElement element) { - return new NegatingComparable(weigher.weigh(element, location)); - } - }); + final String id = weigher.toString(); + if ("prefix".equals(id)) { + sorter = sorter.withClassifier(new ClassifierFactory(id) { + @Override + public Classifier createClassifier(Classifier next) { + return new ComparingClassifier(next, id) { + @NotNull + @Override + public Comparable getWeight(LookupElement element) { + return -PrefixMatchingWeigher.getPrefixMatchingDegree(element, location); + } + }; + } + }); + } + else { + sorter = sorter.weigh(new LookupElementWeigher(id) { + @NotNull + @Override + public Comparable weigh(@NotNull LookupElement element) { + return new NegatingComparable(weigher.weigh(element, location)); + } + }); + } + } return sorter.withClassifier("priority", true, new ClassifierFactory("liftShorter") { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionSorterImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionSorterImpl.java index a82f8b9b40ef..38985e0b0020 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionSorterImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/CompletionSorterImpl.java @@ -39,13 +39,7 @@ public class CompletionSorterImpl extends CompletionSorter { return new ClassifierFactory(id) { @Override public Classifier createClassifier(Classifier next) { - return new ComparingClassifier(next, id) { - @NotNull - @Override - public Comparable getWeight(LookupElement element) { - return weigher.weigh(element); - } - }; + return new CachingComparingClassifier(next, weigher); } }; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/CachingComparingClassifier.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/CachingComparingClassifier.java new file mode 100644 index 000000000000..d87b317e3e5c --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/CachingComparingClassifier.java @@ -0,0 +1,52 @@ +/* + * Copyright 2000-2011 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.codeInsight.lookup; + +import com.intellij.util.containers.StripedLockConcurrentHashMap; +import gnu.trove.TObjectHashingStrategy; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +/** +* @author peter +*/ +public class CachingComparingClassifier extends ComparingClassifier { + private final Map myWeights = new StripedLockConcurrentHashMap(TObjectHashingStrategy.IDENTITY); + private final LookupElementWeigher myWeigher; + + public CachingComparingClassifier(Classifier next, LookupElementWeigher weigher) { + super(next, weigher.toString()); + myWeigher = weigher; + } + + @NotNull + @Override + public final Comparable getWeight(LookupElement t) { + final Comparable weight = myWeights.get(t); + if (weight == null) { + throw new AssertionError(myName + "; " + myWeights.containsKey(t) + "; element=" + t); + } + return weight; + } + + @Override + public void addElement(LookupElement t) { + myWeights.put(t, myWeigher.weigh(t)); + super.addElement(t); + } + +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/ComparingClassifier.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/ComparingClassifier.java index 6f2a0989329a..c0e1630d7d12 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/ComparingClassifier.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/ComparingClassifier.java @@ -18,19 +18,16 @@ package com.intellij.codeInsight.lookup; import com.intellij.openapi.application.ApplicationManager; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.containers.StripedLockConcurrentHashMap; -import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.NotNull; import java.util.*; /** -* @author peter -*/ + * @author peter + */ public abstract class ComparingClassifier extends Classifier { - private final Map myWeights = new StripedLockConcurrentHashMap(TObjectHashingStrategy.IDENTITY); private final Classifier myNext; - private final String myName; + protected final String myName; public ComparingClassifier(Classifier next, String name) { myNext = next; @@ -40,19 +37,14 @@ public abstract class ComparingClassifier extends Classifier { @NotNull public abstract Comparable getWeight(T t); - @Override public void addElement(T t) { - myWeights.put(t, getWeight(t)); myNext.addElement(t); } private TreeMap> groupByWeights(List source) { TreeMap> map = new TreeMap>(); for (T t : source) { - final Comparable weight = myWeights.get(t); - if (weight == null) { - throw new AssertionError(myName + "; " + myWeights.containsKey(t) + "; element=" + t); - } + final Comparable weight = getWeight(t); List list = map.get(weight); if (list == null) { map.put(weight, list = new SmartList()); From d4b9d2b8704cf1f294f30c623c24b6d71d56a66a Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 12 May 2011 18:47:16 +0200 Subject: [PATCH 227/250] remove assertion --- .../com/intellij/lang/ant/dom/AntDomFileReferenceSet.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileReferenceSet.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileReferenceSet.java index 210da1e0d000..0c5dd2f7cbb2 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileReferenceSet.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileReferenceSet.java @@ -129,8 +129,9 @@ public class AntDomFileReferenceSet extends FileReferenceSet { else { basedir = containingProject.getContextAntProject().getProjectBasedirPath(); } - assert basedir != null; - root = LocalFileSystem.getInstance().findFileByPath(basedir); + if (basedir != null) { + root = LocalFileSystem.getInstance().findFileByPath(basedir); + } } } From ec9d787272150c84f81d63429dcf53a742be543b Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 12 May 2011 21:41:52 +0200 Subject: [PATCH 228/250] IDEA-69609 (Unnice handling of single quotes when transforming concatenation to String.format()) --- .../ReplaceConcatenationWithFormatStringIntention.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java index 6527d1725c64..865f3f5db8ba 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java @@ -150,7 +150,8 @@ public class ReplaceConcatenationWithFormatStringIntention type.equalsToText("char"))) { if (length > 2) { formatString.append( - text.substring(1, length - 1).replace("%", "%%")); + text.substring(1, length - 1).replace("%", "%%") + .replace("\\'", "'")); } } else { formatString.append(text); From 4ec18504b14b4ec6d5f3b00267ec8ac64461f157 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 13 May 2011 10:21:56 +0400 Subject: [PATCH 229/250] IDEA-69618 Dir diff window could be closed on pressing Escape --- .../src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java index ef7ce597f6f9..020b3c6e0a45 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java @@ -35,6 +35,7 @@ public class DirDiffFrame extends FrameWrapper { Disposer.register(this, myPanel); setComponent(myPanel.getPanel()); setProject(project); + closeOnEsc(); } From 54cf22bee043a9d32b6620db2fc76329fb8c85eb Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 13 May 2011 11:31:21 +0400 Subject: [PATCH 230/250] presentation for comparison modes --- .../intellij/ide/diff/DirDiffSettings.java | 6 ++- .../dir/actions/ChangeCompareModeAction.java | 3 +- .../dir/actions/ChangeCompareModeGroup.java | 37 +++++++++++++++---- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/diff/DirDiffSettings.java b/platform/platform-api/src/com/intellij/ide/diff/DirDiffSettings.java index 735946932023..6ace126a4ea2 100644 --- a/platform/platform-api/src/com/intellij/ide/diff/DirDiffSettings.java +++ b/platform/platform-api/src/com/intellij/ide/diff/DirDiffSettings.java @@ -55,6 +55,10 @@ public class DirDiffSettings { public static enum CompareMode { CONTENT, // the most honest, the slowest. Compares size, if equal compares contents. Ignores timestamps SIZE, // Compares size only - TIMESTAMP // Compares size, if equal compares timestamps + TIMESTAMP; // Compares size, if equal compares timestamps + + public String getPresentableName() { + return StringUtil.capitalize(name().toLowerCase()); + } } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/ChangeCompareModeAction.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/ChangeCompareModeAction.java index b0bd920963f7..5d6c842bf121 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/ChangeCompareModeAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/ChangeCompareModeAction.java @@ -19,7 +19,6 @@ import com.intellij.ide.diff.DirDiffSettings; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.diff.impl.dir.DirDiffTableModel; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Icons; import com.intellij.util.ui.EmptyIcon; @@ -37,7 +36,7 @@ class ChangeCompareModeAction extends AnAction { private final DirDiffSettings.CompareMode myMode; ChangeCompareModeAction(DirDiffTableModel model, DirDiffSettings.CompareMode mode) { - super(StringUtil.capitalize(mode.name().toLowerCase())); + super(mode.getPresentableName()); myModel = model; myMode = mode; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/ChangeCompareModeGroup.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/ChangeCompareModeGroup.java index d785078ef1de..00386818ebc5 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/ChangeCompareModeGroup.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/ChangeCompareModeGroup.java @@ -16,12 +16,16 @@ package com.intellij.openapi.diff.impl.dir.actions; import com.intellij.ide.diff.DirDiffSettings; +import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.actionSystem.ex.ComboBoxAction; import com.intellij.openapi.diff.impl.dir.DirDiffTableModel; +import com.intellij.ui.IdeBorderFactory; import org.jetbrains.annotations.NotNull; import javax.swing.*; +import java.awt.*; import java.util.ArrayList; /** @@ -29,20 +33,39 @@ import java.util.ArrayList; */ public class ChangeCompareModeGroup extends ComboBoxAction { private final DefaultActionGroup myGroup; + private DirDiffSettings mySettings; public ChangeCompareModeGroup(DirDiffTableModel model) { - getTemplatePresentation().setText("Compare by"); + mySettings = model.getSettings(); + getTemplatePresentation().setText(mySettings.compareMode.getPresentableName()); + final ArrayList actions = new ArrayList(); if (model.getSettings().showCompareModes) { - final ArrayList actions = new ArrayList(); for (DirDiffSettings.CompareMode mode : DirDiffSettings.CompareMode.values()) { actions.add(new ChangeCompareModeAction(model, mode)); } - myGroup = new DefaultActionGroup(actions.toArray(new ChangeCompareModeAction[actions.size()])); - } else { - getTemplatePresentation().setEnabled(false); - getTemplatePresentation().setVisible(false); - myGroup = new DefaultActionGroup(); } + else { + getTemplatePresentation().setVisible(false); + getTemplatePresentation().setEnabled(false); + } + myGroup = new DefaultActionGroup(actions.toArray(new ChangeCompareModeAction[actions.size()])); + } + + @Override + public void update(AnActionEvent e) { + super.update(e); + getTemplatePresentation().setText(mySettings.compareMode.getPresentableName()); + e.getPresentation().setText(mySettings.compareMode.getPresentableName()); + } + + @Override + public JComponent createCustomComponent(Presentation presentation) { + JPanel panel = new JPanel(new BorderLayout()); + final JLabel label = new JLabel("Compare by:"); + panel.add(label, BorderLayout.WEST); + panel.add(super.createCustomComponent(presentation).getComponent(0), BorderLayout.CENTER); + panel.setBorder(IdeBorderFactory.createEmptyBorder(2, 6, 2, 0)); + return panel; } @NotNull From c15863363b858f769e756765bf2e27bec2ad9a27 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 13 May 2011 11:32:47 +0400 Subject: [PATCH 231/250] search component customization --- .../src/com/intellij/ui/FilterComponent.java | 62 +++++++++++--- .../src/com/intellij/ui/SearchTextField.java | 80 ++++++++++++------- 2 files changed, 100 insertions(+), 42 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/FilterComponent.java b/platform/platform-api/src/com/intellij/ui/FilterComponent.java index 7ca76f6918c7..37b5249c1e75 100644 --- a/platform/platform-api/src/com/intellij/ui/FilterComponent.java +++ b/platform/platform-api/src/com/intellij/ui/FilterComponent.java @@ -28,16 +28,39 @@ import java.awt.event.KeyEvent; import java.util.List; /** - * User: anna - * Date: 16-Dec-2005 + * @author Anna Kozlova + * @author Konstantin Bulenkov */ public abstract class FilterComponent extends JPanel { private final SearchTextFieldWithStoredHistory myFilter; private final Alarm myUpdateAlarm = new Alarm(); + private boolean myOnTheFly; public FilterComponent(@NonNls String propertyName, int historySize) { + this(propertyName, historySize, true); + } + + public FilterComponent(@NonNls String propertyName, int historySize, boolean onTheFlyUpdate) { super(new BorderLayout()); - myFilter = new SearchTextFieldWithStoredHistory(propertyName); + myOnTheFly = onTheFlyUpdate; + myFilter = new SearchTextFieldWithStoredHistory(propertyName) { + @Override + protected Runnable createItemChosenCallback(JList list) { + final Runnable callback = super.createItemChosenCallback(list); + return new Runnable() { + @Override + public void run() { + callback.run(); + filter(); + } + }; + } + + @Override + protected Component getPopupLocationComponent() { + return FilterComponent.this.getPopupLocationComponent(); + } + }; myFilter.getTextEditor().addKeyListener(new KeyAdapter() { //to consume enter in combo box - do not process this event by default button from DialogWrapper public void keyPressed(final KeyEvent e) { @@ -45,6 +68,8 @@ public abstract class FilterComponent extends JPanel { e.consume(); myFilter.addCurrentTextToHistory(); filter(); + } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + onEscape(e); } } }); @@ -61,21 +86,31 @@ public abstract class FilterComponent extends JPanel { public void changedUpdate(DocumentEvent e) { onChange(); } - - public void onChange() { - myUpdateAlarm.cancelAllRequests(); - myUpdateAlarm.addRequest(new Runnable(){ - public void run() { - onlineFilter(); - } - }, 100, ModalityState.stateForComponent(myFilter)); - } }); myFilter.setHistorySize(historySize); add(myFilter, BorderLayout.CENTER); } + protected JComponent getPopupLocationComponent() { + return myFilter; + } + + public JTextField getTextEditor() { + return myFilter.getTextEditor(); + } + + private void onChange() { + if (myOnTheFly) { + myUpdateAlarm.cancelAllRequests(); + myUpdateAlarm.addRequest(new Runnable(){ + public void run() { + onlineFilter(); + } + }, 100, ModalityState.stateForComponent(myFilter)); + } + } + public void setHistorySize(int historySize){ myFilter.setHistorySize(historySize); } @@ -84,6 +119,9 @@ public abstract class FilterComponent extends JPanel { myFilter.reset(); } + protected void onEscape(KeyEvent e) { + } + public String getFilter(){ return myFilter.getText(); } diff --git a/platform/platform-api/src/com/intellij/ui/SearchTextField.java b/platform/platform-api/src/com/intellij/ui/SearchTextField.java index f2f477eafb39..facaea970998 100644 --- a/platform/platform-api/src/com/intellij/ui/SearchTextField.java +++ b/platform/platform-api/src/com/intellij/ui/SearchTextField.java @@ -88,6 +88,16 @@ public class SearchTextField extends JPanel { } }); add(myTextField, BorderLayout.CENTER); + myTextField.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_DOWN) { + if (myPopup == null || !myPopup.isVisible()) { + showPopup(); + } + } + } + }); if (hasNativeLeopardSearchControl()) { myTextField.putClientProperty("JTextField.variant", "search"); @@ -318,13 +328,8 @@ public class SearchTextField extends JPanel { } } - protected void showPopup() { - if (myPopup == null) { - final JList list = new JBList(myModel); - if (myListener != null) { - removeKeyListener(myListener); - } - final Runnable chooseRunnable = new Runnable() { + protected Runnable createItemChosenCallback(final JList list) { + return new Runnable() { public void run() { final String value = (String)list.getSelectedValue(); getTextEditor().setText(value != null ? value : ""); @@ -334,35 +339,50 @@ public class SearchTextField extends JPanel { } } }; - myListener = new KeyAdapter() { - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_DOWN) { - if (list.getSelectedIndex() < list.getModel().getSize() - 1) { - list.setSelectedIndex(list.getSelectedIndex() + 1); - } - } - else if (e.getKeyCode() == KeyEvent.VK_UP) { - if (list.getSelectedIndex() > 0) { - list.setSelectedIndex(list.getSelectedIndex() - 1); - } - } - else if (e.getKeyCode() == KeyEvent.VK_ENTER) { - if (list.getSelectedIndex() > -1) { - chooseRunnable.run(); - } - } - } - }; - addKeyboardListener(myListener); + } + + protected void showPopup() { + //removeKeyListener(myListener); + if (myPopup == null) { + final JList list = new JBList(myModel); + //if (myListener != null) { + // removeKeyListener(myListener); + //} + final Runnable chooseRunnable = createItemChosenCallback(list); + //myListener = new KeyAdapter() { + // public void keyPressed(KeyEvent e) { + // if (e.getKeyCode() == KeyEvent.VK_DOWN) { + // if (list.getSelectedIndex() < list.getModel().getSize() - 1) { + // list.setSelectedIndex(list.getSelectedIndex() + 1); + // } + // } + // else if (e.getKeyCode() == KeyEvent.VK_UP) { + // if (list.getSelectedIndex() > 0) { + // list.setSelectedIndex(list.getSelectedIndex() - 1); + // } + // } + // else if (e.getKeyCode() == KeyEvent.VK_ENTER) { + // if (list.getSelectedIndex() > -1) { + // chooseRunnable.run(); + // } + // } + // } + //}; + //addKeyboardListener(myListener); myPopup = JBPopupFactory.getInstance().createListPopupBuilder(list) .setMovable(false) - .setRequestFocus(false) + .setRequestFocus(true) .setItemChoosenCallback(chooseRunnable).createPopup(); - - if (isShowing()) myPopup.showUnderneathOf(this); + if (isShowing()) { + myPopup.showUnderneathOf(getPopupLocationComponent()); + } } } + protected Component getPopupLocationComponent() { + return this; + } + private void togglePopup() { if (myPopup == null) { showPopup(); From 62e3f58b8f9c4a8b6376bf809a62d362ec8fc0e2 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 13 May 2011 11:33:21 +0400 Subject: [PATCH 232/250] fix IDEA-69332 (better search control) --- .../openapi/diff/impl/dir/DirDiffPanel.form | 16 ++---- .../openapi/diff/impl/dir/DirDiffPanel.java | 53 ++++++++++++------- .../diff/impl/dir/DirDiffTableModel.java | 2 +- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.form b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.form index 2acf1935aa0f..594947afb736 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.form +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.form @@ -113,31 +113,21 @@
- + - + - + - - - - - - - - - - diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java index 75ff1b0075f2..a892af632073 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java @@ -28,15 +28,18 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.IdeFocusManager; +import com.intellij.ui.FilterComponent; import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBLoadingPanel; import com.intellij.ui.table.JBTable; +import com.intellij.util.ui.UIUtil; import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; +import javax.swing.text.JTextComponent; import java.awt.*; import java.awt.event.*; import java.util.concurrent.Callable; @@ -58,7 +61,9 @@ public class DirDiffPanel implements Disposable { private JBLabel mySourceDirLabel; private JPanel myToolBarPanel; private JPanel myRootPanel; - private JTextField myFilter; + private JPanel myFilterPanel; + private JBLabel myFilterLabel; + private FilterComponent myFilter; private final DirDiffTableModel myModel; public JLabel myErrorLabel; private final DirDiffWindow myDiffWindow; @@ -199,6 +204,24 @@ public class DirDiffPanel implements Disposable { }); myRootPanel.removeAll(); myRootPanel.add(loadingPanel, BorderLayout.CENTER); + myFilter = new FilterComponent("dir.diff.filter", 15, false) { + @Override + public void filter() { + fireFilterUpdated(); + } + + @Override + protected void onEscape(KeyEvent e) { + e.consume(); + focusTable(); + } + + @Override + protected JComponent getPopupLocationComponent() { + return UIUtil.findComponentOfType(super.getPopupLocationComponent(), JTextComponent.class); + } + }; + myModel.addModelListener(new DirDiffModelListener() { @Override public void updateStarted() { @@ -210,22 +233,12 @@ public class DirDiffPanel implements Disposable { myFilter.setEnabled(true); } }); - - myFilter.setText(settings.getFilter()); - oldFilter = myFilter.getText(); - myFilter.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - e.consume(); - fireFilterUpdated(); - } - else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { - e.consume(); - focusTable(); - } - } - }); + myFilter.getTextEditor().setColumns(10); + myFilter.setFilter(settings.getFilter()); + //oldFilter = myFilter.getText(); + oldFilter = myFilter.getFilter(); + myFilterPanel.add(myFilter, BorderLayout.CENTER); + myFilterLabel.setLabelFor(myFilter); final Callable srcChooser = myModel.getSourceDir().getElementChooser(project); final Callable trgChooser = myModel.getTargetDir().getElementChooser(project); if (srcChooser != null) { @@ -286,12 +299,12 @@ public class DirDiffPanel implements Disposable { }); } - public JTextField getFilter() { - return myFilter; + public String getFilter() { + return myFilter.getFilter(); } private void fireFilterUpdated() { - final String newFilter = myFilter.getText(); + final String newFilter = myFilter.getFilter(); if (!StringUtil.equals(oldFilter, newFilter)) { oldFilter = newFilter; myModel.getSettings().setFilter(newFilter); diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java index 2f47c1d055d9..a74cd9649ef1 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java @@ -128,7 +128,7 @@ public class DirDiffTableModel extends AbstractTableModel implements Disposable } public void updateFromUI() { - getSettings().setFilter(myPanel.getFilter().getText()); + getSettings().setFilter(myPanel.getFilter()); } private static String prepareText(String text) { From 6782d9cbf7b3846ba3bbcaa3da17d1215fa93121 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 13 May 2011 11:49:18 +0400 Subject: [PATCH 233/250] help id --- .../openapi/diff/impl/dir/DirDiffDialog.java | 5 +++++ .../openapi/diff/impl/dir/DirDiffFrame.java | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffDialog.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffDialog.java index c0abf9a99f74..b29f9742b0d5 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffDialog.java @@ -70,4 +70,9 @@ public class DirDiffDialog extends DialogWrapper { protected Action[] createActions() { return new Action[]{}; } + + @Override + protected String getHelpId() { + return "reference.dialogs.diff.folder"; + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java index 020b3c6e0a45..3718056b827f 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java @@ -15,10 +15,14 @@ */ package com.intellij.openapi.diff.impl.dir; +import com.intellij.ide.DataManager; import com.intellij.ide.diff.DirDiffSettings; +import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.FrameWrapper; import com.intellij.openapi.util.Disposer; +import org.jetbrains.annotations.NonNls; import java.awt.*; @@ -36,6 +40,15 @@ public class DirDiffFrame extends FrameWrapper { setComponent(myPanel.getPanel()); setProject(project); closeOnEsc(); + DataManager.registerDataProvider(myPanel.getPanel(), new DataProvider() { + @Override + public Object getData(@NonNls String dataId) { + if (PlatformDataKeys.HELP_ID.is(dataId)) { + return "reference.dialogs.diff.folder"; + } + return null; + } + }); } From a802b858a586d517318a7d8787f153207333de71 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 13 May 2011 12:49:45 +0400 Subject: [PATCH 234/250] fix TC plugin update --- .../src/com/intellij/openapi/util/io/FileUtil.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java index 3690ce20398f..e302ea7edab9 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java @@ -357,13 +357,13 @@ public class FileUtil { return createTempFile(dir, prefix, suffix, create, true); } - public static File createTempFile(@NonNls final File dir, @NotNull @NonNls String prefix, @NonNls String suffix, final boolean create, boolean removeOnExit) throws IOException { + public static File createTempFile(@NonNls final File dir, @NotNull @NonNls String prefix, @NonNls String suffix, final boolean create, boolean deleteOnExit) throws IOException { File file = doCreateTempFile(prefix, suffix, dir); file.delete(); if (create) { file.createNewFile(); } - if (removeOnExit) { + if (deleteOnExit) { file.deleteOnExit(); } return file; @@ -371,10 +371,17 @@ public class FileUtil { @NotNull public static File createTempFile(@NotNull @NonNls String prefix, @NonNls String suffix) throws IOException{ + return createTempFile(prefix, suffix, false); //false until TeamCity fixes its plugin + } + + @NotNull + public static File createTempFile(@NotNull @NonNls String prefix, @NonNls String suffix, boolean deleteOnExit) throws IOException { File file = doCreateTempFile(prefix, suffix); file.delete(); file.createNewFile(); - file.deleteOnExit(); + if (deleteOnExit) { + file.deleteOnExit(); + } return file; } From 7b7bcda775b4060900962f2bb6ae1f8c49b4561c Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 13 May 2011 13:33:59 +0400 Subject: [PATCH 235/250] NavBar is always shown on the top --- .../NavBarRootPaneExtension.java | 93 +++++++++++-------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java index 4b3b06b72ee2..38dbc8daf723 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarRootPaneExtension.java @@ -20,6 +20,7 @@ */ package com.intellij.ide.navigationToolbar; +import com.intellij.ide.ui.LafManager; import com.intellij.ide.ui.UISettings; import com.intellij.ide.ui.UISettingsListener; import com.intellij.openapi.actionSystem.*; @@ -27,6 +28,7 @@ import com.intellij.openapi.actionSystem.ex.ComboBoxAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.IdeRootPaneNorthExtension; import com.intellij.openapi.wm.impl.IdeFrameImpl; @@ -186,48 +188,56 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { } private JComponent buildNavBarPanel() { - final JComponent result = new JPanel(new BorderLayout()) { + final Ref panel = new Ref(null); + final Runnable updater = new Runnable() { + String laf; + @Override + public void run() { + if (LafManager.getInstance().getCurrentLookAndFeel().getName().equals(laf)) return; + laf = LafManager.getInstance().getCurrentLookAndFeel().getName(); + panel.get().removeAll(); + myScrollPane = null; + myCloseIcon = null; + if (myNavigationBar != null && !Disposer.isDisposed(myNavigationBar)) { + Disposer.dispose(myNavigationBar); + } + myNavigationBar = new NavBarPanel(myProject); + myWrapperPanel.putClientProperty("NavBarPanel", myNavigationBar); + myNavigationBar.getModel().setFixedComponent(true); + + myScrollPane = ScrollPaneFactory.createScrollPane(myNavigationBar); + myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); + myScrollPane.setHorizontalScrollBar(null); + myScrollPane.setBorder(null); + + myScrollPane.setOpaque(false); + myScrollPane.getViewport().setOpaque(false); + + panel.get().setBackground(UIUtil.isUnderGTKLookAndFeel() ? Color.WHITE : UIUtil.getListBackground()); + panel.get().setOpaque(!UIUtil.isUnderAquaLookAndFeel() || UISettings.getInstance().SHOW_MAIN_TOOLBAR); + panel.get().setBorder(UIUtil.isUnderAquaLookAndFeel() ? BorderFactory.createEmptyBorder(2, 0, 2, 4) : new NavBarBorder(true, 0)); + myNavigationBar.setBorder(null); + panel.get().add(myScrollPane, BorderLayout.CENTER); + if (!SystemInfo.isMac) { + myCloseIcon = new JLabel(CROSS_ICON); + myCloseIcon.addMouseListener(new MouseAdapter() { + public void mouseClicked(final MouseEvent e) { + UISettings.getInstance().SHOW_NAVIGATION_BAR = false; + uiSettingsChanged(UISettings.getInstance()); + } + }); + panel.get().add(myCloseIcon, BorderLayout.EAST); + } + } + }; + + panel.set(new JPanel(new BorderLayout()) { @Override public void updateUI() { super.updateUI(); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - removeAll(); - myScrollPane = null; - myCloseIcon = null; - if (myNavigationBar != null && !Disposer.isDisposed(myNavigationBar)) { - Disposer.dispose(myNavigationBar); - } - myNavigationBar = new NavBarPanel(myProject); - myWrapperPanel.putClientProperty("NavBarPanel", myNavigationBar); - myNavigationBar.getModel().setFixedComponent(true); - - myScrollPane = ScrollPaneFactory.createScrollPane(myNavigationBar); - myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); - myScrollPane.setHorizontalScrollBar(null); - myScrollPane.setBorder(null); - - myScrollPane.setOpaque(false); - myScrollPane.getViewport().setOpaque(false); - - setBackground(UIUtil.isUnderGTKLookAndFeel() ? Color.WHITE : UIUtil.getListBackground()); - setOpaque(!UIUtil.isUnderAquaLookAndFeel() || UISettings.getInstance().SHOW_MAIN_TOOLBAR); - setBorder(UIUtil.isUnderAquaLookAndFeel() ? BorderFactory.createEmptyBorder(2, 0, 2, 4) : new NavBarBorder(true, 0)); - myNavigationBar.setBorder(null); - add(myScrollPane, BorderLayout.CENTER); - if (!SystemInfo.isMac) { - myCloseIcon = new JLabel(CROSS_ICON); - myCloseIcon.addMouseListener(new MouseAdapter() { - public void mouseClicked(final MouseEvent e) { - UISettings.getInstance().SHOW_NAVIGATION_BAR = false; - uiSettingsChanged(UISettings.getInstance()); - } - }); - add(myCloseIcon, BorderLayout.EAST); - } - } - }); + if (UISettings.getInstance().SHOW_NAVIGATION_BAR) { + SwingUtilities.invokeLater(updater); + } } @Override @@ -292,9 +302,10 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension { closePreferredSize.width, closePreferredSize.height); } } - }; + }); - return result; + updater.run(); + return panel.get(); } public void uiSettingsChanged(final UISettings settings) { From 09753f71d0986823910675310d2883de5f823982 Mon Sep 17 00:00:00 2001 From: andrey zaytsev Date: Fri, 13 May 2011 14:02:53 +0400 Subject: [PATCH 236/250] find: select text in field when it gets focus. Remove any selection in editor after replace-all. --- .../lang-impl/src/com/intellij/find/EditorSearchComponent.java | 2 ++ platform/lang-impl/src/com/intellij/find/FindUtil.java | 1 + 2 files changed, 3 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java b/platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java index d5a9598d4efc..c109c6a4cde7 100644 --- a/platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java +++ b/platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java @@ -625,6 +625,8 @@ public class EditorSearchComponent extends JPanel implements DataProvider, Selec } public void requestFocus() { + mySearchField.setSelectionStart(0); + mySearchField.setSelectionEnd(mySearchField.getText().length()); requestFocus(mySearchField); } diff --git a/platform/lang-impl/src/com/intellij/find/FindUtil.java b/platform/lang-impl/src/com/intellij/find/FindUtil.java index 8f962fdde31b..e571082fa986 100644 --- a/platform/lang-impl/src/com/intellij/find/FindUtil.java +++ b/platform/lang-impl/src/com/intellij/find/FindUtil.java @@ -583,6 +583,7 @@ public class FindUtil { public void run() { document.setText(newText); editor.getCaretModel().moveToOffset(finalCaretOffset); + editor.getSelectionModel().removeSelection(); } }); } From 86f90a87e28e1e318266d6f8f187cc2af637dbc6 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 13 May 2011 12:06:44 +0400 Subject: [PATCH 237/250] http://ea.jetbrains.com/browser/ea_problems/26472 --- .../codeInsight/navigation/NavigationGutterIconBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconBuilder.java b/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconBuilder.java index 633dfa0b619e..60efe1dec69c 100644 --- a/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconBuilder.java +++ b/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconBuilder.java @@ -237,7 +237,7 @@ public class NavigationGutterIconBuilder { final List list = new ArrayList(targets.size()); for (final T target : targets) { for (final PsiElement psiElement : myConverter.fun(target)) { - if (elements.add(psiElement)) { + if (elements.add(psiElement) && psiElement.isValid()) { list.add(manager.createSmartPsiElementPointer(psiElement)); } } From fbc0b7c37306d75a11decc5cb8f0a8720d58d557 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 13 May 2011 12:07:10 +0400 Subject: [PATCH 238/250] http://ea.jetbrains.com/browser/ea_problems/22963 --- .../daemon/impl/GeneralHighlightingPass.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java index 89f0839ea62e..50b973f19aeb 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java @@ -227,22 +227,18 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP myHighlights.addAll(toApplyInside); gotHighlights.clear(); gotHighlights.addAll(outsideResult); - + final long modificationStamp = myDocument.getModificationStamp(); UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { - if (myProject.isDisposed()) return; + if (myProject.isDisposed() || modificationStamp != myDocument.getModificationStamp()) return; MarkupModel markupModel = myDocument.getMarkupModel(myProject); UpdateHighlightersUtil.setHighlightersInRange(myProject, myDocument, priorityIntersection, getColorsScheme(), toApplyInside, (MarkupModelEx)markupModel, Pass.UPDATE_ALL); - } - }); - UIUtil.invokeLaterIfNeeded(new Runnable() { - @Override - public void run() { - if (myProject.isDisposed() || myEditor == null) return; - new ShowAutoImportPass(myProject, myFile, myEditor).applyInformationToEditor(); + if (myEditor != null) { + new ShowAutoImportPass(myProject, myFile, myEditor).applyInformationToEditor(); + } } }); } From 18d8cd3b5d2ee000d6cfbe12fa38657e68eff05c Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 13 May 2011 13:05:49 +0400 Subject: [PATCH 239/250] skip test roots if generate javadoc was disabled for them (IDEA-65736) --- .../javadoc/JavadocConfiguration.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/java/java-impl/src/com/intellij/javadoc/JavadocConfiguration.java b/java/java-impl/src/com/intellij/javadoc/JavadocConfiguration.java index 8b6b91e6673d..f8125312fef4 100644 --- a/java/java-impl/src/com/intellij/javadoc/JavadocConfiguration.java +++ b/java/java-impl/src/com/intellij/javadoc/JavadocConfiguration.java @@ -39,10 +39,7 @@ import com.intellij.openapi.projectRoots.JavaSdkType; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.ex.PathUtilEx; -import com.intellij.openapi.roots.ContentEntry; -import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.roots.OrderEnumerator; -import com.intellij.openapi.roots.SourceFolder; +import com.intellij.openapi.roots.*; import com.intellij.openapi.util.*; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; @@ -62,6 +59,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Collection; +import java.util.List; /** * @author Eugene Zhuravlev @@ -280,13 +278,21 @@ public class JavadocConfiguration implements ModuleRunProfile, JDOMExternalizabl } writer.println("-sourcepath"); final PathsList pathsList = OrderEnumerator.orderEntries(myProject).withoutSdk().withoutLibraries().getSourcePathsList(); - final String sourcePath = StringUtil.join(pathsList.getPathList(), new Function() { - @Override - public String fun(String path) { - return FileUtil.toSystemIndependentName(path); + final List files = pathsList.getRootDirs(); + final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); + final StringBuilder sourcePath = new StringBuilder(); + boolean start = true; + for (VirtualFile file : files) { + if (!myGenerationOptions.isIncludeTestSource() && fileIndex.isInTestSourceContent(file)) continue; + if (start) { + start = false; } - }, File.pathSeparator); - writer.println(GeneralCommandLine.quote(sourcePath)); + else { + sourcePath.append(File.pathSeparator); + } + sourcePath.append(file.getPath()); + } + writer.println(GeneralCommandLine.quote(sourcePath.toString())); } finally { writer.close(); From 861d938bb30506f3ef1ec1a663edc5df027059cf Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 13 May 2011 14:42:22 +0400 Subject: [PATCH 240/250] implementations presentation --- .../codeInsight/hint/ImplementationViewComponent.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewComponent.java index da823c2d2b8d..2d95399c78a0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewComponent.java @@ -41,6 +41,7 @@ import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vcs.FileStatusManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtilBase; import com.intellij.refactoring.util.RefactoringUIUtil; import com.intellij.ui.IdeBorderFactory; @@ -117,7 +118,8 @@ public class ImplementationViewComponent extends JPanel { for (PsiElement element : elements) { PsiFile file = getContainingFile(element); if (file == null) continue; - files.add(new FileDescriptor(file, element.getParent())); + final PsiElement parent = element.getParent(); + files.add(new FileDescriptor(file, parent == file ? element : parent)); candidates.add(element.getNavigationElement()); } myElements = PsiUtilBase.toPsiElementArray(candidates); From 14c4a5f62b5f94380cf373c525b87f133da94fa8 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 13 May 2011 15:24:38 +0400 Subject: [PATCH 241/250] do not restart javadoc parser with the same input stream (IDEA-69558) --- .../codeInsight/documentation/AbstractExternalFilter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java index 2aac13d32b30..f39ec3fa35d8 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java @@ -228,9 +228,9 @@ public abstract class AbstractExternalFilter { String charset = null; do { read = buf.readLine(); - if (read != null && read.contains("charset")) { + /*if (read != null && read.contains("charset")) { charset = read; - } + }*/ } while (read != null && read.toUpperCase().indexOf(startSection) == -1); From 5ed5dc417907b7d28a5ecbb1ed964c38dcf0d1ac Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 13 May 2011 13:28:26 +0200 Subject: [PATCH 242/250] speedup ant execution from IDEA: use only stderr stream to log ant messages --- .../rt/ant/execution/IdeaAntLogger2.java | 10 ++--- .../rt/ant/execution/IdeaInputHandler.java | 40 ++++++++++++------- .../ant/config/execution/OutputParser2.java | 10 +++-- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/java/java-runtime/src/com/intellij/rt/ant/execution/IdeaAntLogger2.java b/java/java-runtime/src/com/intellij/rt/ant/execution/IdeaAntLogger2.java index 843bb9c1b48f..f30025eeb12b 100644 --- a/java/java-runtime/src/com/intellij/rt/ant/execution/IdeaAntLogger2.java +++ b/java/java-runtime/src/com/intellij/rt/ant/execution/IdeaAntLogger2.java @@ -26,7 +26,6 @@ import java.io.PrintWriter; import java.io.StringWriter; public final class IdeaAntLogger2 extends DefaultLogger { - static SegmentedOutputStream ourOut; static SegmentedOutputStream ourErr; public static final char MESSAGE_CONTENT = 'M'; public static final char EXCEPTION_CONTENT = 'X'; @@ -116,19 +115,16 @@ public final class IdeaAntLogger2 extends DefaultLogger { } public static void guardStreams() { - if (ourErr != null && ourOut != null) return; - PrintStream out = System.out; + if (ourErr != null) { + return; + } PrintStream err = System.err; - ourOut = new SegmentedOutputStream(out); ourErr = new SegmentedOutputStream(err); - System.setOut(new PrintStream(ourOut)); System.setErr(new PrintStream(ourErr)); - ourOut.sendStart(); ourErr.sendStart(); } private void send(PacketWriter packet) { - packet.sendThrough(ourOut); packet.sendThrough(ourErr); } diff --git a/java/java-runtime/src/com/intellij/rt/ant/execution/IdeaInputHandler.java b/java/java-runtime/src/com/intellij/rt/ant/execution/IdeaInputHandler.java index 67c3f148ffd8..3a1120acd320 100644 --- a/java/java-runtime/src/com/intellij/rt/ant/execution/IdeaInputHandler.java +++ b/java/java-runtime/src/com/intellij/rt/ant/execution/IdeaInputHandler.java @@ -30,32 +30,42 @@ import java.util.Vector; */ public class IdeaInputHandler implements InputHandler { public void handleInput(InputRequest request) throws BuildException { - String prompt = request.getPrompt(); - if (prompt == null) throw new BuildException("Prompt is null"); - SegmentedOutputStream out = IdeaAntLogger2.ourOut; - SegmentedOutputStream err = IdeaAntLogger2.ourErr; - if (out == null || err == null) + final String prompt = request.getPrompt(); + if (prompt == null) { + throw new BuildException("Prompt is null"); + } + final SegmentedOutputStream err = IdeaAntLogger2.ourErr; + if (err == null) { throw new BuildException("Selected InputHandler should be used by Intellij IDEA"); - PacketWriter packet = PacketFactory.ourInstance.createPacket(IdeaAntLogger2.INPUT_REQUEST); + } + final PacketWriter packet = PacketFactory.ourInstance.createPacket(IdeaAntLogger2.INPUT_REQUEST); packet.appendLimitedString(prompt); if (request instanceof MultipleChoiceInputRequest) { Vector choices = ((MultipleChoiceInputRequest)request).getChoices(); if (choices != null && choices.size() > 0) { int count = choices.size(); packet.appendLong(count); - for (int i = 0; i < count; i++) + for (int i = 0; i < count; i++) { packet.appendLimitedString((String)choices.elementAt(i)); - } else packet.appendLong(0); - } else packet.appendLong(0); - packet.sendThrough(out); + } + } + else { + packet.appendLong(0); + } + } + else { + packet.appendLong(0); + } packet.sendThrough(err); try { - byte[] replayLength = readBytes(4); - int length = ((int)replayLength[0] << 24) | ((int)replayLength[1] << 16) | ((int)replayLength[2] << 8) | replayLength[3]; - byte[] replay = readBytes(length); - String input = new String(replay); + final byte[] replayLength = readBytes(4); + final int length = ((int)replayLength[0] << 24) | ((int)replayLength[1] << 16) | ((int)replayLength[2] << 8) | replayLength[3]; + final byte[] replay = readBytes(length); + final String input = new String(replay); request.setInput(input); - if (!request.isInputValid()) throw new BuildException("Invalid input: " + input); + if (!request.isInputValid()) { + throw new BuildException("Invalid input: " + input); + } } catch (IOException e) { throw new BuildException(e); diff --git a/plugins/ant/src/com/intellij/lang/ant/config/execution/OutputParser2.java b/plugins/ant/src/com/intellij/lang/ant/config/execution/OutputParser2.java index 6b2b629dde2b..700d97b362c0 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/execution/OutputParser2.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/execution/OutputParser2.java @@ -16,7 +16,10 @@ package com.intellij.lang.ant.config.execution; import com.intellij.execution.junit.JUnitProcessHandler; -import com.intellij.execution.junit2.segments.*; +import com.intellij.execution.junit2.segments.DeferredActionsQueue; +import com.intellij.execution.junit2.segments.DeferredActionsQueueImpl; +import com.intellij.execution.junit2.segments.InputConsumer; +import com.intellij.execution.junit2.segments.SegmentReader; import com.intellij.execution.process.OSProcessHandler; import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.lang.ant.config.AntBuildFile; @@ -85,9 +88,8 @@ final class OutputParser2 extends OutputParser implements PacketProcessor, Input final AntBuildMessageView errorView, final ProgressIndicator progress, final AntBuildFile buildFile) { - OutputParser2 parser = new OutputParser2(myProject, handler, errorView, progress, buildFile.getName()); - DeferredActionsQueue queue = new DeferredActionsQueueImpl(); - handler.getOut().setPacketDispatcher(parser, queue); + final OutputParser2 parser = new OutputParser2(myProject, handler, errorView, progress, buildFile.getName()); + final DeferredActionsQueue queue = new DeferredActionsQueueImpl(); handler.getErr().setPacketDispatcher(parser, queue); return parser; } From 64704cb4309052c0bf8a63631c4b17a5c54bba61 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Fri, 13 May 2011 15:09:34 +0400 Subject: [PATCH 243/250] less often isCancelled check (one time in 10ms in ProgressManager) --- .../daemon/impl/LocalInspectionsPass.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java index 1b628d2db4fb..e251fa62fd99 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java @@ -73,7 +73,6 @@ import java.util.concurrent.ConcurrentMap; */ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass implements DumbAware { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.LocalInspectionsPass"); - private static final int NUM_ELEMENTS_PER_CHECK_CANCELLED = 5; public static final TextRange EMPTY_PRIORITY_RANGE = TextRange.EMPTY_RANGE; private final int myStartOffset; private final int myEndOffset; @@ -255,7 +254,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass } } }; - PsiElementVisitor visitor = createVisitorAndAcceptElements(tool, holder, isOnTheFly, session, elements, indicator); + PsiElementVisitor visitor = createVisitorAndAcceptElements(tool, holder, isOnTheFly, session, elements); synchronized (init) { init.add(Trinity.create(tool, holder, visitor)); @@ -277,8 +276,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass @NotNull ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session, - @NotNull List elements, - @NotNull ProgressIndicator indicator) { + @NotNull List elements) { PsiElementVisitor visitor = tool.buildVisitor(holder, isOnTheFly, session); //noinspection ConstantConditions if(visitor == null) { @@ -288,7 +286,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass : "The visitor returned from LocalInspectionTool.buildVisitor() must not be recursive. "+tool; tool.inspectionStarted(session, isOnTheFly); - acceptElements(elements, visitor, indicator); + acceptElements(elements, visitor); return visitor; } @@ -310,7 +308,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass ProblemsHolder holder = trinity.second; PsiElementVisitor elementVisitor = trinity.third; - acceptElements(elements, elementVisitor, indicator); + acceptElements(elements, elementVisitor); advanceProgress(1); @@ -329,11 +327,12 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass inspectInjectedPsi(elements, tools, isOnTheFly, indicator, iManager, false); } - private static void acceptElements(@NotNull List elements, @NotNull PsiElementVisitor elementVisitor, @NotNull ProgressIndicator indicator) { + private static void acceptElements(@NotNull List elements, + @NotNull PsiElementVisitor elementVisitor) { for (int i = 0, elementsSize = elements.size(); i < elementsSize; i++) { PsiElement element = elements.get(i); element.accept(elementVisitor); - if (i % NUM_ELEMENTS_PER_CHECK_CANCELLED == 0) indicator.checkCanceled(); + ProgressManager.checkCanceled(); } } @@ -669,7 +668,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass }; LocalInspectionToolSession injSession = new LocalInspectionToolSession(injectedPsi, 0, injectedPsi.getTextLength()); - createVisitorAndAcceptElements(tool, holder, isOnTheFly, injSession, elements, indicator); + createVisitorAndAcceptElements(tool, holder, isOnTheFly, injSession, elements); tool.inspectionFinished(injSession,holder); List problems = holder.getResults(); if (problems != null && !problems.isEmpty()) { From fed09bd4f2d739d511c2f65f99fb41371ea17f16 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 13 May 2011 16:04:33 +0400 Subject: [PATCH 244/250] restart javadoc parser over new input stream; correct encoding detection (IDEA-69558; IDEA-67183) --- .../documentation/AbstractExternalFilter.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java index f39ec3fa35d8..6c9db5b43234 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/AbstractExternalFilter.java @@ -69,6 +69,7 @@ public abstract class AbstractExternalFilter { @NonNls private static final String DT = "

"; private static final Pattern CHARSET_META_PATTERN = Pattern.compile("", Pattern.CASE_INSENSITIVE); + private final HttpConfigurable myHttpConfigurable = HttpConfigurable.getInstance(); protected static abstract class RefConvertor { private final Pattern mySelector; @@ -209,6 +210,10 @@ public abstract class AbstractExternalFilter { } protected void doBuildFromStream(String surl, Reader input, StringBuffer data) throws IOException { + doBuildFromStream(surl, input, data, true); + } + + protected void doBuildFromStream(String surl, Reader input, StringBuffer data, boolean search4Encoding) throws IOException { BufferedReader buf = new BufferedReader(input); Matcher anchorMatcher = ourAnchorsuffix.matcher(surl); @NonNls String startSection = ""; @@ -225,20 +230,30 @@ public abstract class AbstractExternalFilter { data.append(HTML); String read; - String charset = null; + String contentEncoding = null; do { read = buf.readLine(); - /*if (read != null && read.contains("charset")) { - charset = read; - }*/ + if (read != null && search4Encoding && read.contains("charset")) { + String foundEncoding = parseContentEncoding(read); + if (foundEncoding != null) { + contentEncoding = foundEncoding; + } + } } while (read != null && read.toUpperCase().indexOf(startSection) == -1); - if (input instanceof MyReader && charset != null) { - String contentEncoding = parseContentEncoding(charset); - if (contentEncoding != null) { //restart page parsing with correct encoding - input = new MyReader(((MyReader)input).getInputStream(), contentEncoding); - buf = new BufferedReader(input); + if (input instanceof MyReader && contentEncoding != null) { + if (contentEncoding != null && !contentEncoding.equals("UTF-8") && !contentEncoding.equals(((MyReader)input).getEncoding())) { //restart page parsing with correct encoding + Reader stream; + try { + stream = getReaderByUrl(surl, myHttpConfigurable, new ProgressIndicatorBase()); + } + catch (ProcessCanceledException e) { + return; + } + data.delete(0, data.length()); + doBuildFromStream(surl, new MyReader(((MyReader)stream).getInputStream(), contentEncoding), data, false); + return; } } From 763c3f25046ce884941d186740c3a95bdb6c3a39 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Fri, 13 May 2011 18:20:20 +0400 Subject: [PATCH 245/250] [xena] IDEA-67350 Cant read notifications (white text on yellow background) [rev=anna.kozlova] --- .../com/intellij/ide/IdeTooltipManager.java | 2 +- .../ide/ui/AppearanceConfigurable.java | 28 ------------------- .../com/intellij/ide/ui/AppearancePanel.form | 16 +---------- 3 files changed, 2 insertions(+), 44 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java b/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java index fd407c1f8cc8..a6ed2e366e44 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java @@ -431,7 +431,7 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener } private boolean useGraphite(boolean awtHint) { - return !isUseSystemLook() && awtHint; + return false; } public void hide(IdeTooltip tooltip) { diff --git a/platform/platform-impl/src/com/intellij/ide/ui/AppearanceConfigurable.java b/platform/platform-impl/src/com/intellij/ide/ui/AppearanceConfigurable.java index 196f69314acb..d47529d0defe 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/AppearanceConfigurable.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/AppearanceConfigurable.java @@ -21,7 +21,6 @@ import com.intellij.openapi.options.SearchableConfigurable; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -57,10 +56,6 @@ public class AppearanceConfigurable extends BaseConfigurable implements Searchab myComponent.myLafComboBox.setModel(new DefaultComboBoxModel(LafManager.getInstance().getInstalledLookAndFeels())); myComponent.myLafComboBox.setRenderer(new MyLafComboBoxRenderer(myComponent.myLafComboBox.getRenderer())); - myComponent.myTooltipMode.setModel(new DefaultComboBoxModel(new Object[]{"default", "graphite", "system"})); - myComponent.myTooltipMode.setRenderer(new MyTooltipModeRenderer(myComponent.myTooltipMode.getRenderer())); - myComponent.myTooltipMode.setSelectedItem(Registry.stringValue("ide.tooltip.mode")); - myComponent.myEnableAlphaModeCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean state = myComponent.myEnableAlphaModeCheckBox.isSelected(); @@ -153,10 +148,6 @@ public class AppearanceConfigurable extends BaseConfigurable implements Searchab } } - if (myComponent.myTooltipMode.getSelectedItem() != null && !myComponent.myTooltipMode.getSelectedItem().equals(Registry.stringValue("ide.tooltip.mode"))) { - update = true; - Registry.get("ide.tooltip.mode").setValue(myComponent.myTooltipMode.getSelectedItem().toString()); - } if (shouldUpdateUI) { lafManager.updateUI(); @@ -202,7 +193,6 @@ public class AppearanceConfigurable extends BaseConfigurable implements Searchab myComponent.myLafComboBox.setSelectedItem(LafManager.getInstance().getCurrentLookAndFeel()); myComponent.myOverrideLAFFonts.setSelected(settings.OVERRIDE_NONIDEA_LAF_FONTS); myComponent.myDisableMnemonics.setSelected(settings.DISABLE_MNEMONICS); - myComponent.myTooltipMode.setSelectedItem(Registry.stringValue("ide.tooltip.mode")); boolean alphaModeEnabled = WindowManagerEx.getInstanceEx().isAlphaModeSupported(); if (alphaModeEnabled) { @@ -257,8 +247,6 @@ public class AppearanceConfigurable extends BaseConfigurable implements Searchab isModified |= ratio != settings.ALPHA_MODE_RATIO; } - isModified |= myComponent.myTooltipMode.getSelectedItem() != null && !myComponent.myTooltipMode.getSelectedItem().equals(Registry.stringValue("ide.tooltip.mode")); - return isModified; } @@ -285,21 +273,6 @@ public class AppearanceConfigurable extends BaseConfigurable implements Searchab } } - private static final class MyTooltipModeRenderer extends ListCellRendererWrapper { - public MyTooltipModeRenderer(final ListCellRenderer listCellRenderer) { - super(listCellRenderer); - } - - @Override - public void customize(final JList list, final String value, final int index, final boolean selected, final boolean cellHasFocus) { - String s = value; - if (s != null && s.length() > 1) { - s = s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); - } - setText(s); - } - } - private static class MyComponent { private JPanel myPanel; private JComboBox myFontCombo; @@ -324,7 +297,6 @@ public class AppearanceConfigurable extends BaseConfigurable implements Searchab private JCheckBox myHideIconsInQuickNavigation; private JCheckBox myCbDisplayIconsInMenu; private JCheckBox myDisableMnemonics; - private JComboBox myTooltipMode; public MyComponent() { ActionListener updater = new ActionListener() { diff --git a/platform/platform-impl/src/com/intellij/ide/ui/AppearancePanel.form b/platform/platform-impl/src/com/intellij/ide/ui/AppearancePanel.form index 2d864aa94279..5fd3eade0677 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/AppearancePanel.form +++ b/platform/platform-impl/src/com/intellij/ide/ui/AppearancePanel.form @@ -35,7 +35,7 @@ - + @@ -61,20 +61,6 @@ - - - - - - - - - - - - - - From 5128d8c736fedc9a14120fb54277ebe35b7ec64f Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 13 May 2011 16:37:42 +0200 Subject: [PATCH 246/250] IDEA-13197 ("Convert to MessageFormat.format" / "Convert to String.format" should not run inside annotation parameter) for "Replace + with StringBuffer" and "Replace + with String.format()" --- .../siyeh/IntentionPowerPackBundle.properties | 9 ++++--- ...oncatenatedStringToClipboardIntention.java | 6 ++--- ...oncatenationWithFormatStringIntention.java | 2 +- ...oncatenationWithStringBufferIntention.java | 19 +++++++++++--- .../SimpleStringConcatenationPredicate.java | 26 +++++++++++++++++-- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/plugins/IntentionPowerPak/src/com/siyeh/IntentionPowerPackBundle.properties b/plugins/IntentionPowerPak/src/com/siyeh/IntentionPowerPackBundle.properties index 167383937143..2025851ab4b5 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/IntentionPowerPackBundle.properties +++ b/plugins/IntentionPowerPak/src/com/siyeh/IntentionPowerPackBundle.properties @@ -47,8 +47,9 @@ remove.unnecessary.parentheses.intention.name=Remove unnecessary parentheses remove.unnecessary.parentheses.intention.family.name=Remove Unnecessary Parentheses merge.if.and.intention.name=Merge nested 'if's merge.if.and.intention.family.name=Merge Nested Ifs to ANDed Condition -replace.concatenation.with.string.buffer.intention.name=Replace '+' with '.append()' -replace.concatenation.with.string.buffer.intention.family.name=Replace + with StringBuffer.append() +replace.concatenation.with.string.buffer.intention.name=Replace '+' with 'StringBuffer.append()' +replace.concatenation.with.string.builder.intention.name=Replace '+' with 'StringBuilder.append()' +replace.concatenation.with.string.buffer.intention.family.name=Replace + with StringBuilder.append() remove.conditional.intention.name=Simplify '?:' remove.conditional.intention.family.name=Remove Pointless Conditional move.comment.to.separate.line.intention.name=Move comment to separate line @@ -121,8 +122,8 @@ wrap.vararg.arguments.with.explicit.array.intention.name=Wrap vararg arguments w wrap.vararg.arguments.with.explicit.array.intention.family.name=Wrap Vararg Arguments with Explicit Array Creation extract.while.loop.condition.to.if.statement.intention.name=Extract condition to internal 'if' statement extract.while.loop.condition.to.if.statement.intention.family.name=Extract While Loop Condition to Internal If Statement -replace.concatenation.with.format.string.intention.name=Replace '+' with 'String.format()' call -replace.concatenation.with.format.string.intention.family.name=Replace String Concatenation with String.format() Call +replace.concatenation.with.format.string.intention.name=Replace '+' with 'String.format()' +replace.concatenation.with.format.string.intention.family.name=Replace String Concatenation with String.format() copy.concatenated.string.to.clipboard.intention.name=Copy String concatenation text to the clipboard copy.concatenated.string.to.clipboard.intention.family.name=Copy String Concatenation Text to the Clipboard flip.expression.intention.family.name=Flip Binary Expression diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/CopyConcatenatedStringToClipboardIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/CopyConcatenatedStringToClipboardIntention.java index a79dccd80c04..730cd0649435 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/CopyConcatenatedStringToClipboardIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/CopyConcatenatedStringToClipboardIntention.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2010 Bas Leijdekkers + * Copyright 2008-2011 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ public class CopyConcatenatedStringToClipboardIntention extends Intention { @Override @NotNull protected PsiElementPredicate getElementPredicate() { - return new SimpleStringConcatenationPredicate(); + return new SimpleStringConcatenationPredicate(false); } @Override @@ -85,4 +85,4 @@ public class CopyConcatenatedStringToClipboardIntention extends Intention { } } } -} \ No newline at end of file +} diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java index 865f3f5db8ba..ff4318730190 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java @@ -31,7 +31,7 @@ public class ReplaceConcatenationWithFormatStringIntention @Override @NotNull protected PsiElementPredicate getElementPredicate() { - return new SimpleStringConcatenationPredicate(); + return new SimpleStringConcatenationPredicate(true); } @Override diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithStringBufferIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithStringBufferIntention.java index 3ad5fa884003..8e16a1c2cad4 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithStringBufferIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithStringBufferIntention.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,19 +18,32 @@ package com.siyeh.ipp.concatenation; import com.intellij.psi.*; import com.intellij.psi.util.PsiUtil; import com.intellij.util.IncorrectOperationException; +import com.siyeh.IntentionPowerPackBundle; import com.siyeh.ipp.base.Intention; +import com.siyeh.ipp.base.MutablyNamedIntention; import com.siyeh.ipp.base.PsiElementPredicate; import com.siyeh.ipp.psiutils.ConcatenationUtils; import com.siyeh.ipp.psiutils.ParenthesesUtils; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -public class ReplaceConcatenationWithStringBufferIntention extends Intention { +public class ReplaceConcatenationWithStringBufferIntention extends MutablyNamedIntention { + + @Override + protected String getTextForElement(PsiElement element) { + if (PsiUtil.isLanguageLevel5OrHigher(element)) { + return IntentionPowerPackBundle.message( + "replace.concatenation.with.string.builder.intention.name"); + } else { + return IntentionPowerPackBundle.message( + "replace.concatenation.with.string.buffer.intention.name"); + } + } @Override @NotNull public PsiElementPredicate getElementPredicate() { - return new SimpleStringConcatenationPredicate(); + return new SimpleStringConcatenationPredicate(true); } @Override diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/SimpleStringConcatenationPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/SimpleStringConcatenationPredicate.java index 3549a2807ea6..12b00a3feba2 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/SimpleStringConcatenationPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/SimpleStringConcatenationPredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,8 @@ */ package com.siyeh.ipp.concatenation; -import com.intellij.psi.PsiElement; +import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; import com.siyeh.ipp.base.PsiElementPredicate; import com.siyeh.ipp.psiutils.ConcatenationUtils; import com.siyeh.ipp.psiutils.ErrorUtil; @@ -23,10 +24,31 @@ import com.siyeh.ipp.psiutils.ErrorUtil; class SimpleStringConcatenationPredicate implements PsiElementPredicate{ + private final boolean excludeConcatentationsInsideAnnotations; + + public SimpleStringConcatenationPredicate(boolean excludeConcatentationsInsideAnnotations) { + this.excludeConcatentationsInsideAnnotations = excludeConcatentationsInsideAnnotations; + } + public boolean satisfiedBy(PsiElement element){ if(!ConcatenationUtils.isConcatenation(element)){ return false; } + if (excludeConcatentationsInsideAnnotations && isInsideAnnotation(element)) { + return false; + } return !ErrorUtil.containsError(element); } + + private static boolean isInsideAnnotation(PsiElement element) { + for (int i = 0; i < 20 && element instanceof PsiBinaryExpression; i++) { + // optimization: don't check deep string concatenation more than 20 levels up. + element = element.getParent(); + if (element instanceof PsiNameValuePair || + element instanceof PsiArrayInitializerMemberValue) { + return true; + } + } + return false; + } } From f823bcbc2d9872270eae72e4dc22e1f7d3c55667 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 13 May 2011 17:13:25 +0200 Subject: [PATCH 247/250] disable a plugin silently if it depends on a missing module --- .../intellij/ide/plugins/PluginManager.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/plugins/PluginManager.java b/platform/platform-api/src/com/intellij/ide/plugins/PluginManager.java index 8d932e3094cf..601ea1578984 100644 --- a/platform/platform-api/src/com/intellij/ide/plugins/PluginManager.java +++ b/platform/platform-api/src/com/intellij/ide/plugins/PluginManager.java @@ -674,18 +674,20 @@ public class PluginManager { }, new Condition() { public boolean value(final PluginId pluginId) { if (!idToDescriptorMap.containsKey(pluginId)) { - if (message.length() > 0) { - message.append("
"); - } pluginDescriptor.setEnabled(false); - disabledPluginIds.add(pluginDescriptor.getPluginId().getIdString()); - final String name = pluginDescriptor.getName(); - final IdeaPluginDescriptorImpl descriptor = idToDescriptorMap.get(pluginId); - String pluginName = descriptor == null ? pluginId.getIdString() : descriptor.getName(); + if (!pluginId.getIdString().startsWith(MODULE_DEPENDENCY_PREFIX)) { + disabledPluginIds.add(pluginDescriptor.getPluginId().getIdString()); + if (message.length() > 0) { + message.append("
"); + } + final String name = pluginDescriptor.getName(); + final IdeaPluginDescriptorImpl descriptor = idToDescriptorMap.get(pluginId); + String pluginName = descriptor == null ? pluginId.getIdString() : descriptor.getName(); - message.append(getDisabledPlugins().contains(pluginId.getIdString()) - ? IdeBundle.message("error.required.plugin.disabled", name, pluginName) - : IdeBundle.message("error.required.plugin.not.installed", name, pluginName)); + message.append(getDisabledPlugins().contains(pluginId.getIdString()) + ? IdeBundle.message("error.required.plugin.disabled", name, pluginName) + : IdeBundle.message("error.required.plugin.not.installed", name, pluginName)); + } it.remove(); return false; } From c5d9d030b160c0eb055a36e59b620e7a02a72bf2 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Fri, 13 May 2011 21:06:11 +0400 Subject: [PATCH 248/250] Made instanceOf() public --- .../lang-api/src/com/intellij/psi/util/PsiTreeUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java b/platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java index dc3bb2099d88..b4378bc5c92d 100644 --- a/platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java +++ b/platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java @@ -302,10 +302,10 @@ public class PsiTreeUtil { return result; } - private static boolean instanceOf(final PsiElement child, final Class... classes) { + public static boolean instanceOf(final Object object, final Class... classes) { if (classes != null) { - for (final Class each : classes) { - if (each.isInstance(child)) return true; + for (final Class c : classes) { + if (c.isInstance(object)) return true; } } return false; From 00d55f835750a9ea1e69f5cb4176d4e725581fef Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Fri, 13 May 2011 21:07:17 +0400 Subject: [PATCH 249/250] Added some javadocs --- .../codeInsight/controlflow/ControlFlowBuilder.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/controlflow/ControlFlowBuilder.java b/platform/lang-impl/src/com/intellij/codeInsight/controlflow/ControlFlowBuilder.java index 04ed03f6e355..27a26c306f21 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/controlflow/ControlFlowBuilder.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/controlflow/ControlFlowBuilder.java @@ -115,6 +115,11 @@ public class ControlFlowBuilder { pending.add(i, Pair.create(pendingScope, instruction)); } + /** + * Creates edges from the pending list to the specified instruction. + * + * @param instruction target instruction for pending edges + */ public void checkPending(@NotNull final Instruction instruction) { final PsiElement element = instruction.getElement(); if (element == null) { @@ -125,7 +130,7 @@ public class ControlFlowBuilder { pending.clear(); } else { - // else we just all the pending with scope containing in element + // else we just process all the pending with scope containing in element // reverse order is just an optimization for (int i = pending.size() - 1; i >= 0; i--) { final Pair pair = pending.get(i); From 0491f5cfa1fb7358ebfc33394b394c887c4dc5ea Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Fri, 13 May 2011 21:13:00 +0400 Subject: [PATCH 250/250] since JPS can now read compiler configuration from project files, don't manually set resource patterns --- build/scripts/utils.gant | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/build/scripts/utils.gant b/build/scripts/utils.gant index 6b78c1b93ba6..9faa6267a73b 100644 --- a/build/scripts/utils.gant +++ b/build/scripts/utils.gant @@ -92,16 +92,6 @@ binding.setVariable("loadProject", { } } IdeaProjectLoader.loadFromPath(project, "${home}") - - binding.ant.patternset(id: "idea.compiler.resources") { - exclude(name: "**/*.java") - exclude(name: "**/*.form") - exclude(name: "**/*.class") - exclude(name: "**/*.scala") - exclude(name: "**/*.groovy") - } - - project["compiler.resources.id"] = "idea.compiler.resources" }) boolean hasSourceRoots(Module module) {