diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlighter.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlighter.java index 60bebc0f6fbd..39abb4f97323 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlighter.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlighter.java @@ -16,7 +16,6 @@ package com.intellij.codeInsight.highlighting; -import com.intellij.openapi.Disposable; import com.intellij.openapi.components.AbstractProjectComponent; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; @@ -31,7 +30,6 @@ import com.intellij.openapi.fileEditor.FileEditorManagerEvent; import com.intellij.openapi.project.DumbAwareRunnable; import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupManager; -import com.intellij.openapi.util.Disposer; import com.intellij.util.Alarm; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; @@ -79,7 +77,7 @@ public class BraceHighlighter extends AbstractProjectComponent { } } }; - eventMulticaster.addSelectionListener(mySelectionListener); + eventMulticaster.addSelectionListener(mySelectionListener, myProject); DocumentListener documentListener = new DocumentAdapter() { public void documentChanged(DocumentEvent e) { @@ -101,7 +99,7 @@ public class BraceHighlighter extends AbstractProjectComponent { updateBraces(editor, myAlarm); } }; - ((EditorEventMulticasterEx)eventMulticaster).addFocusChangeListner(myFocusChangeListener); + ((EditorEventMulticasterEx)eventMulticaster).addFocusChangeListner(myFocusChangeListener, myProject); final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject); @@ -110,14 +108,6 @@ public class BraceHighlighter extends AbstractProjectComponent { myAlarm.cancelAllRequests(); } }, myProject); - - Disposer.register(myProject, new Disposable() { - public void dispose() { - EditorEventMulticaster eventMulticaster = EditorFactory.getInstance().getEventMulticaster(); - ((EditorEventMulticasterEx)eventMulticaster).removeFocusChangeListner(myFocusChangeListener); - eventMulticaster.removeSelectionListener(mySelectionListener); - } - }); } static void updateBraces(@NotNull final Editor editor, @NotNull final Alarm alarm) { diff --git a/platform/lang-impl/src/com/intellij/ide/scriptingContext/LangScriptingContextConfigurable.java b/platform/lang-impl/src/com/intellij/ide/scriptingContext/LangScriptingContextConfigurable.java index 10e0aca11405..cffb704ae3a2 100644 --- a/platform/lang-impl/src/com/intellij/ide/scriptingContext/LangScriptingContextConfigurable.java +++ b/platform/lang-impl/src/com/intellij/ide/scriptingContext/LangScriptingContextConfigurable.java @@ -46,12 +46,6 @@ public abstract class LangScriptingContextConfigurable implements Configurable, return project.getPicoContainer().getComponentInstance("com.intellij.openapi.roots.ui.configuration.projectRoot.GlobalLibrariesConfigurable") == null; } - @Nls - @Override - public String getDisplayName() { - return "Libraries"; - } - @Override public JComponent createComponent() { return myPanel.getPanel(); diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java index 4dcc859f131b..141ede0c5a57 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java @@ -603,11 +603,13 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF final IElementType contentElementType = getContentElementType(); if (!(contentElementType instanceof IStubFileElementType)) { + final FileViewProvider viewProvider = getViewProvider(); throw new AssertionError("A stub in a non-stub file '" + vFile +"'; isValid()=" + vFile.isValid() + - " type: "+contentElementType+";" + + "; Type: " + contentElementType + "; " + + "Psi roots: " + viewProvider.getAllFiles() + "; " + " StubUpdatingIndex.canHaveStub(vFile)=" + StubUpdatingIndex.canHaveStub(vFile) + " content:<<<\n"+ - StringUtil.first(getViewProvider().getContents(),200,true)+ + StringUtil.first(viewProvider.getContents(),200,true)+ "\n>>>; stubs=" + stubHolder.getPlainList()); } diff --git a/platform/lang-impl/src/com/intellij/ui/EditorTextFieldProviderImpl.java b/platform/lang-impl/src/com/intellij/ui/EditorTextFieldProviderImpl.java index 95b03534e709..2120756100e0 100644 --- a/platform/lang-impl/src/com/intellij/ui/EditorTextFieldProviderImpl.java +++ b/platform/lang-impl/src/com/intellij/ui/EditorTextFieldProviderImpl.java @@ -89,7 +89,7 @@ public class EditorTextFieldProviderImpl implements EditorTextFieldProvider { for (EditorCustomization.Feature feature : features) { for (EditorCustomization customization : customizations) { if (customization.getSupportedFeatures().contains(feature)) { - customization.customize(ex, feature); + customization.addCustomization(ex, feature); break; } } diff --git a/platform/platform-api/src/com/intellij/openapi/editor/event/EditorEventMulticaster.java b/platform/platform-api/src/com/intellij/openapi/editor/event/EditorEventMulticaster.java index 8a5f52a770fd..d5bcfb2ba228 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/event/EditorEventMulticaster.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/event/EditorEventMulticaster.java @@ -42,6 +42,7 @@ public interface EditorEventMulticaster { void removeCaretListener(@NotNull CaretListener listener); void addSelectionListener(@NotNull SelectionListener listener); + void addSelectionListener(@NotNull SelectionListener listener, @NotNull Disposable parentDisposable); void removeSelectionListener(@NotNull SelectionListener listener); void addVisibleAreaListener(@NotNull VisibleAreaListener listener); 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 099db87f5645..ccb083ee4cd3 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 @@ -88,7 +88,7 @@ public abstract class JBPopupFactory { public abstract ListPopup createConfirmation(String title, String yesText, String noText, Runnable onYes, Runnable onNo, int defaultOptionIndex); public abstract ListPopupStep createActionsStep(ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, boolean showNumbers, boolean showDisabledActions, String title, @@ -96,7 +96,7 @@ public abstract class JBPopupFactory { boolean honorActionMnemonics); public abstract ListPopupStep createActionsStep(ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, boolean showNumbers, boolean showDisabledActions, String title, @@ -157,7 +157,7 @@ public abstract class JBPopupFactory { */ public abstract ListPopup createActionGroupPopup(String title, ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, ActionSelectionAid selectionAidMethod, boolean showDisabledActions); @@ -174,9 +174,9 @@ public abstract class JBPopupFactory { */ public abstract ListPopup createActionGroupPopup(String title, ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, ActionSelectionAid selectionAidMethod, - boolean showDisabledActions, final @Nullable String actionPlace); + boolean showDisabledActions, @Nullable final String actionPlace); /** * Creates a popup allowing to choose one of the actions from the specified action group. @@ -193,7 +193,7 @@ public abstract class JBPopupFactory { */ public abstract ListPopup createActionGroupPopup(String title, ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, ActionSelectionAid selectionAidMethod, boolean showDisabledActions, @Nullable Runnable disposeCallback, @@ -201,7 +201,7 @@ public abstract class JBPopupFactory { public abstract ListPopup createActionGroupPopup(String title, ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, boolean showNumbers, boolean showDisabledActions, boolean honorActionMnemonics, @@ -237,7 +237,7 @@ public abstract class JBPopupFactory { * - current selected node for tree
* - current selected row for list
*/ - public abstract RelativePoint guessBestPopupLocation(DataContext dataContext); + public abstract RelativePoint guessBestPopupLocation(@NotNull DataContext dataContext); /** * Returns the location where a popup invoked from the specified editor should be displayed. diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/VirtualFileListenerBase.java b/platform/platform-api/src/com/intellij/openapi/vfs/VirtualFileListenerBase.java index ef0492884ae5..0c925364ceb2 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/VirtualFileListenerBase.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/VirtualFileListenerBase.java @@ -17,6 +17,9 @@ package com.intellij.openapi.vfs; @Deprecated +/** + * use {@link com.intellij.openapi.vfs.VirtualFileAdapter} instead + */ public class VirtualFileListenerBase implements VirtualFileListener{ public void propertyChanged(VirtualFilePropertyEvent event) {} public void contentsChanged(VirtualFileEvent event) {} diff --git a/platform/platform-impl/src/com/intellij/AbstractUnappliableEditorCustomization.java b/platform/platform-impl/src/com/intellij/AbstractUnappliableEditorCustomization.java new file mode 100644 index 000000000000..65348be2e58f --- /dev/null +++ b/platform/platform-impl/src/com/intellij/AbstractUnappliableEditorCustomization.java @@ -0,0 +1,34 @@ +/* + * 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; + +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.ui.EditorCustomization; +import org.jetbrains.annotations.NotNull; + +/** + * Basic super class for {@link EditorCustomization editor customizations} that don't consider un-applying feature. + * + * @author Denis Zhdanov + * @since 1/14/11 12:52 PM + */ +public abstract class AbstractUnappliableEditorCustomization implements EditorCustomization { + + @Override + public void removeCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { + // Do nothing + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorEventMulticasterEx.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorEventMulticasterEx.java index 047241620a1d..1f0d5a8a366e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorEventMulticasterEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorEventMulticasterEx.java @@ -33,5 +33,6 @@ public interface EditorEventMulticasterEx extends EditorEventMulticaster{ void removePropertyChangeListener(@NotNull PropertyChangeListener listener); void addFocusChangeListner(@NotNull FocusChangeListener listener); + void addFocusChangeListner(@NotNull FocusChangeListener listener, @NotNull Disposable parentDisposable); void removeFocusChangeListner(@NotNull FocusChangeListener listener); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/event/EditorEventMulticasterImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/event/EditorEventMulticasterImpl.java index 0f9352dcb474..f231ec51a838 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/event/EditorEventMulticasterImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/event/EditorEventMulticasterImpl.java @@ -130,6 +130,11 @@ public class EditorEventMulticasterImpl implements EditorEventMulticasterEx { mySelectionMulticaster.addListener(listener); } + @Override + public void addSelectionListener(@NotNull SelectionListener listener, @NotNull Disposable parentDisposable) { + mySelectionMulticaster.addListener(listener, parentDisposable); + } + public void removeSelectionListener(@NotNull SelectionListener listener) { mySelectionMulticaster.removeListener(listener); } @@ -175,6 +180,11 @@ public class EditorEventMulticasterImpl implements EditorEventMulticasterEx { myFocusChangeListenerMulticaster.addListener(listener); } + @Override + public void addFocusChangeListner(@NotNull FocusChangeListener listener, @NotNull Disposable parentDisposable) { + myFocusChangeListenerMulticaster.addListener(listener,parentDisposable); + } + public void removeFocusChangeListner(@NotNull FocusChangeListener listener) { myFocusChangeListenerMulticaster.removeListener(listener); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/EditorBasedWidget.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/EditorBasedWidget.java index e6db275b9d71..4a9b5f56487e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/EditorBasedWidget.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/EditorBasedWidget.java @@ -49,7 +49,6 @@ public abstract class EditorBasedWidget extends FileEditorManagerAdapter impleme @Nullable protected final Editor getEditor() { final Project project = getProject(); - Editor result = null; if (project == null) return null; @@ -59,6 +58,7 @@ public abstract class EditorBasedWidget extends FileEditorManagerAdapter impleme splitters = ((DockableEditorTabbedContainer)c).getSplitters(); } + Editor result = null; if (splitters != null && splitters.getCurrentWindow() != null) { EditorWithProviderComposite editor = splitters.getCurrentWindow().getSelectedEditor(); if (editor != null) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/PositionPanel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/PositionPanel.java index 3c74a11a89d9..43e0e4c66e43 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/PositionPanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/PositionPanel.java @@ -15,9 +15,7 @@ */ package com.intellij.openapi.wm.impl.status; -import com.intellij.ide.DataManager; import com.intellij.ide.util.GotoLineNumberDialog; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; @@ -25,20 +23,15 @@ import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.editor.SelectionModel; import com.intellij.openapi.editor.event.*; import com.intellij.openapi.fileEditor.FileEditorManager; -import com.intellij.openapi.fileEditor.FileEditorManagerAdapter; import com.intellij.openapi.fileEditor.FileEditorManagerEvent; -import com.intellij.openapi.fileEditor.FileEditorManagerListener; import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory; import com.intellij.openapi.project.Project; import com.intellij.openapi.wm.StatusBar; import com.intellij.openapi.wm.StatusBarWidget; -import com.intellij.openapi.wm.WindowManager; import com.intellij.ui.UIBundle; import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import javax.swing.*; import java.awt.*; import java.awt.event.MouseEvent; @@ -80,7 +73,7 @@ public class PositionPanel extends EditorBasedWidget implements StatusBarWidget. @Override public float getAlignment() { - return JComponent.CENTER_ALIGNMENT; + return Component.CENTER_ALIGNMENT; } public String getTooltipText() { @@ -110,18 +103,11 @@ public class PositionPanel extends EditorBasedWidget implements StatusBarWidget. }; } - public void dispose() { - final EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster(); - multicaster.removeCaretListener(this); - multicaster.removeSelectionListener(this); - super.dispose(); - } - public void install(@NotNull StatusBar statusBar) { super.install(statusBar); final EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster(); - multicaster.addCaretListener(this); - multicaster.addSelectionListener(this); + multicaster.addCaretListener(this, this); + multicaster.addSelectionListener(this, this); } private static void appendLogicalPosition(LogicalPosition caret, StringBuilder message) { @@ -150,12 +136,12 @@ public class PositionPanel extends EditorBasedWidget implements StatusBarWidget. private void updatePosition(final Editor editor) { if (editor == null) { myText = ""; - myStatusBar.updateWidget(ID()); - } else { + } + else { if (!isOurEditor(editor)) return; myText = getPositionText(editor); - myStatusBar.updateWidget(ID()); } + myStatusBar.updateWidget(ID()); } private String getPositionText(Editor editor) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/TextPanel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/TextPanel.java index f44066feb8f0..3f3cb282e46f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/TextPanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/TextPanel.java @@ -59,46 +59,45 @@ public class TextPanel extends JComponent { @Override protected void paintComponent(final Graphics g) { String s = getText(); - if (s != null) { - final Rectangle bounds = getBounds(); - final Insets insets = getInsets(); + if (s == null) return; + final Rectangle bounds = getBounds(); + final Insets insets = getInsets(); - final Graphics2D g2 = (Graphics2D)g; - g2.setFont(getFont()); + final Graphics2D g2 = (Graphics2D)g; + g2.setFont(getFont()); - UIUtil.applyRenderingHints(g2); + UIUtil.applyRenderingHints(g2); - final FontMetrics fm = g2.getFontMetrics(); - final int sWidth = fm.stringWidth(s); + final FontMetrics fm = g2.getFontMetrics(); + final int sWidth = fm.stringWidth(s); - int x = insets.left; - if (myAlignment == JComponent.CENTER_ALIGNMENT || myAlignment == JComponent.RIGHT_ALIGNMENT) { - x = myAlignment == JComponent.CENTER_ALIGNMENT ? (bounds.width - sWidth) / 2 : bounds.width - insets.right - sWidth; - } - - final Rectangle textR = new Rectangle(); - final Rectangle iconR = new Rectangle(); - final Rectangle viewR = new Rectangle(bounds); - textR.x = textR.y = textR.width = textR.height = 0; - - viewR.width -= insets.left; - viewR.width -= insets.right; - - if (sWidth > (bounds.width - insets.left - insets.right)) { - s = SwingUtilities - .layoutCompoundLabel(fm, s, null, SwingUtilities.CENTER, SwingUtilities.CENTER, SwingUtilities.CENTER, SwingUtilities.TRAILING, - bounds, iconR, textR, 0); - } - - final int y = UIUtil.getStringY(s, bounds, g2); - if (SystemInfo.isMac && myDecorate) { - g2.setColor(new Color(215, 215, 215)); - g2.drawString(s, x, y + 1); - } - - g2.setColor(getForeground()); - g2.drawString(s, x, y); + int x = insets.left; + if (myAlignment == Component.CENTER_ALIGNMENT || myAlignment == Component.RIGHT_ALIGNMENT) { + x = myAlignment == Component.CENTER_ALIGNMENT ? (bounds.width - sWidth) / 2 : bounds.width - insets.right - sWidth; } + + final Rectangle textR = new Rectangle(); + final Rectangle iconR = new Rectangle(); + final Rectangle viewR = new Rectangle(bounds); + textR.x = textR.y = textR.width = textR.height = 0; + + viewR.width -= insets.left; + viewR.width -= insets.right; + + if (sWidth > bounds.width - insets.left - insets.right) { + s = SwingUtilities + .layoutCompoundLabel(fm, s, null, SwingConstants.CENTER, SwingConstants.CENTER, SwingConstants.CENTER, SwingConstants.TRAILING, + bounds, iconR, textR, 0); + } + + final int y = UIUtil.getStringY(s, bounds, g2); + if (SystemInfo.isMac && myDecorate) { + g2.setColor(new Color(215, 215, 215)); + g2.drawString(s, x, y + 1); + } + + g2.setColor(getForeground()); + g2.drawString(s, x, y); } public void setTextAlignment(final float alignment) { diff --git a/platform/platform-impl/src/com/intellij/ui/EditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/EditorCustomization.java index 24b2f3479de0..9741d70fe058 100644 --- a/platform/platform-impl/src/com/intellij/ui/EditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/EditorCustomization.java @@ -49,5 +49,13 @@ public interface EditorCustomization { * @param editor editor to customize * @param feature feature to apply to the given editor */ - void customize(@NotNull EditorEx editor, @NotNull Feature feature); + void addCustomization(@NotNull EditorEx editor, @NotNull Feature feature); + + /** + * Asks to un-apply customization performed earlier during {@link #addCustomization(EditorEx, Feature)} processing (if any). + * + * @param editor editor to customize + * @param feature feature to un-apply to the given editor + */ + void removeCustomization(@NotNull EditorEx editor, @NotNull Feature feature); } diff --git a/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorCustomization.java index 9150bedb6668..9f9e84b94d33 100644 --- a/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/HorizontalScrollBarEditorCustomization.java @@ -15,6 +15,7 @@ */ package com.intellij.ui; +import com.intellij.AbstractUnappliableEditorCustomization; import com.intellij.openapi.editor.ex.EditorEx; import org.jetbrains.annotations.NotNull; @@ -26,12 +27,12 @@ import java.util.Set; * Date: 12/6/10 * Time: 10:18 AM */ -public class HorizontalScrollBarEditorCustomization implements EditorCustomization { +public class HorizontalScrollBarEditorCustomization extends AbstractUnappliableEditorCustomization { public Set getSupportedFeatures() { return EnumSet.of(Feature.NO_HORIZONTAL_SCROLLBAR); } - public void customize(@NotNull EditorEx editor, @NotNull Feature feature) { + public void addCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { if (Feature.NO_HORIZONTAL_SCROLLBAR.equals(feature)) { editor.setHorizontalScrollbarVisible(false); } diff --git a/platform/platform-impl/src/com/intellij/ui/OneLineEditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/OneLineEditorCustomization.java index ab4d16161049..df719184a920 100644 --- a/platform/platform-impl/src/com/intellij/ui/OneLineEditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/OneLineEditorCustomization.java @@ -15,6 +15,7 @@ */ package com.intellij.ui; +import com.intellij.AbstractUnappliableEditorCustomization; import com.intellij.openapi.editor.ex.EditorEx; import org.jetbrains.annotations.NotNull; @@ -24,12 +25,12 @@ import java.util.Set; /** * @author Kirill Likhodedov */ -public class OneLineEditorCustomization implements EditorCustomization { +public class OneLineEditorCustomization extends AbstractUnappliableEditorCustomization { public Set getSupportedFeatures() { return EnumSet.of(Feature.ONE_LINE); } - public void customize(@NotNull EditorEx editor, @NotNull Feature feature) { + public void addCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { if (Feature.ONE_LINE.equals(feature)) { editor.setOneLineMode(true); } diff --git a/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorCustomization.java b/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorCustomization.java index 60ec41f4c7d0..83d69140e5ad 100644 --- a/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorCustomization.java +++ b/platform/platform-impl/src/com/intellij/ui/SoftWrapsEditorCustomization.java @@ -15,6 +15,7 @@ */ package com.intellij.ui; +import com.intellij.AbstractUnappliableEditorCustomization; import com.intellij.openapi.editor.ex.EditorEx; import org.jetbrains.annotations.NotNull; @@ -29,7 +30,7 @@ import java.util.Set; * @author Denis Zhdanov * @since Aug 20, 2010 4:54:48 PM */ -public class SoftWrapsEditorCustomization implements EditorCustomization { +public class SoftWrapsEditorCustomization extends AbstractUnappliableEditorCustomization { @Override public Set getSupportedFeatures() { @@ -37,7 +38,7 @@ public class SoftWrapsEditorCustomization implements EditorCustomization { } @Override - public void customize(@NotNull EditorEx editor, @NotNull Feature feature) { + public void addCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { editor.getSettings().setUseSoftWraps(true); } } 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 c9acf1c607bb..2a703e962913 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/PopupFactoryImpl.java @@ -24,7 +24,6 @@ import com.intellij.openapi.actionSystem.impl.ActionMenu; import com.intellij.openapi.actionSystem.impl.Utils; import com.intellij.openapi.application.ex.ApplicationEx; import com.intellij.openapi.application.ex.ApplicationManagerEx; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.VisualPosition; import com.intellij.openapi.project.Project; @@ -61,7 +60,6 @@ import java.util.HashMap; import java.util.List; public class PopupFactoryImpl extends JBPopupFactory { - private static final Logger LOG = Logger.getInstance("#com.intellij.ui.popup.PopupFactoryImpl"); private static final Icon QUICK_LIST_ICON = IconLoader.getIcon("/actions/quickList.png"); public ListPopup createConfirmation(String title, final Runnable onYes, int defaultOptionIndex) { @@ -106,7 +104,7 @@ public class PopupFactoryImpl extends JBPopupFactory { private static ListPopup createActionGroupPopup(final String title, final ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, boolean showNumbers, boolean useAlphaAsNumbers, boolean showDisabledActions, @@ -119,7 +117,7 @@ public class PopupFactoryImpl extends JBPopupFactory { public ListPopup createActionGroupPopup(final String title, final ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, boolean showNumbers, boolean showDisabledActions, boolean honorActionMnemonics, @@ -131,7 +129,7 @@ public class PopupFactoryImpl extends JBPopupFactory { private static ListPopup createActionGroupPopup(final String title, final ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, boolean showNumbers, boolean useAlphaAsNumbers, boolean showDisabledActions, @@ -180,7 +178,7 @@ public class PopupFactoryImpl extends JBPopupFactory { AnAction action = actionItem.getAction(); Presentation presentation = new Presentation(); presentation.setDescription(action.getTemplatePresentation().getDescription()); - final String actualActionPlace = (actionPlace == null) ? ActionPlaces.UNKNOWN : actionPlace; + final String actualActionPlace = actionPlace == null ? ActionPlaces.UNKNOWN : actionPlace; action.update(new AnActionEvent(null, DataManager.getInstance().getDataContext(component), actualActionPlace, presentation, ActionManager.getInstance(), 0)); ActionMenu.showDescriptionInStatusBar(true, component, presentation.getDescription()); @@ -190,7 +188,7 @@ public class PopupFactoryImpl extends JBPopupFactory { } public ListPopup createActionGroupPopup(final String title, final ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, boolean showNumbers, boolean showDisabledActions, boolean honorActionMnemonics, @@ -203,7 +201,7 @@ public class PopupFactoryImpl extends JBPopupFactory { public ListPopup createActionGroupPopup(String title, ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, ActionSelectionAid selectionAidMethod, boolean showDisabledActions) { return createActionGroupPopup(title, actionGroup, dataContext, @@ -216,7 +214,7 @@ public class PopupFactoryImpl extends JBPopupFactory { public ListPopup createActionGroupPopup(String title, ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, ActionSelectionAid selectionAidMethod, boolean showDisabledActions, @Nullable String actionPlace) { @@ -230,7 +228,7 @@ public class PopupFactoryImpl extends JBPopupFactory { public ListPopup createActionGroupPopup(String title, ActionGroup actionGroup, - DataContext dataContext, + @NotNull DataContext dataContext, ActionSelectionAid selectionAidMethod, boolean showDisabledActions, Runnable disposeCallback, @@ -245,7 +243,7 @@ public class PopupFactoryImpl extends JBPopupFactory { } public ListPopupStep createActionsStep(final ActionGroup actionGroup, - final DataContext dataContext, + @NotNull DataContext dataContext, final boolean showNumbers, final boolean showDisabledActions, final String title, @@ -254,7 +252,7 @@ public class PopupFactoryImpl extends JBPopupFactory { return createActionsStep(actionGroup, dataContext, showNumbers, showDisabledActions, title, component, honorActionMnemonics, 0, false); } - private static ListPopupStep createActionsStep(ActionGroup actionGroup, DataContext dataContext, boolean showNumbers, boolean useAlphaAsNumbers, boolean showDisabledActions, + private static ListPopupStep createActionsStep(ActionGroup actionGroup, @NotNull DataContext dataContext, boolean showNumbers, boolean useAlphaAsNumbers, boolean showDisabledActions, String title, Component component, boolean honorActionMnemonics, int defaultOptionIndex, final boolean autoSelectionEnabled) { final ActionStepBuilder builder = new ActionStepBuilder(dataContext, showNumbers, useAlphaAsNumbers, showDisabledActions, honorActionMnemonics); @@ -265,7 +263,7 @@ public class PopupFactoryImpl extends JBPopupFactory { autoSelectionEnabled); } - public ListPopupStep createActionsStep(ActionGroup actionGroup, DataContext dataContext, boolean showNumbers, boolean showDisabledActions, + public ListPopupStep createActionsStep(ActionGroup actionGroup, @NotNull DataContext dataContext, boolean showNumbers, boolean showDisabledActions, String title, Component component, boolean honorActionMnemonics, int defaultOptionIndex, final boolean autoSelectionEnabled) { return createActionsStep(actionGroup, dataContext, showNumbers, true, showDisabledActions, title, component, honorActionMnemonics, @@ -301,7 +299,7 @@ public class PopupFactoryImpl extends JBPopupFactory { } - public RelativePoint guessBestPopupLocation(DataContext dataContext) { + public RelativePoint guessBestPopupLocation(@NotNull DataContext dataContext) { KeyboardFocusManager focusManager=KeyboardFocusManager.getCurrentKeyboardFocusManager(); Component component = focusManager.getFocusOwner(); JComponent focusOwner=component instanceof JComponent ? (JComponent)component : null; @@ -573,7 +571,7 @@ public class PopupFactoryImpl extends JBPopupFactory { @NotNull private String myActionPlace; - private ActionStepBuilder(final DataContext dataContext, + private ActionStepBuilder(@NotNull DataContext dataContext, final boolean showNumbers, final boolean useAlphaAsNumbers, final boolean showDisabled, diff --git a/platform/platform-resources-en/src/messages/VcsBundle.properties b/platform/platform-resources-en/src/messages/VcsBundle.properties index 3b33cf95cdf6..a6d3e11aba3b 100644 --- a/platform/platform-resources-en/src/messages/VcsBundle.properties +++ b/platform/platform-resources-en/src/messages/VcsBundle.properties @@ -34,6 +34,7 @@ border.standard.after.checkin.options.group=After {0} checkbox.checkin.options.check.files.up.to.date=Check remote status checkbox.checkin.options.optimize.imports=&Optimize imports checkbox.checkin.options.reformat.code=&Reformat code +checkbox.check.commit.message.spelling=Check commit message spelling progress.text.searching.for.modified.files=Searching for modified files button.text.overwrite.modified.file=&Overwrite Modified File button.text.overwrite.modified.files=&Overwrite Modified Files diff --git a/platform/testFramework/src/com/intellij/mock/MockEditorEventMulticaster.java b/platform/testFramework/src/com/intellij/mock/MockEditorEventMulticaster.java index d956629f3bae..d5806c381038 100644 --- a/platform/testFramework/src/com/intellij/mock/MockEditorEventMulticaster.java +++ b/platform/testFramework/src/com/intellij/mock/MockEditorEventMulticaster.java @@ -75,6 +75,10 @@ public class MockEditorEventMulticaster implements EditorEventMulticaster { public void addSelectionListener(@NotNull SelectionListener listener) { } + @Override + public void addSelectionListener(@NotNull SelectionListener listener, @NotNull Disposable parentDisposable) { + } + @Override public void removeSelectionListener(@NotNull SelectionListener listener) { } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java index b77a064b3e33..aa6c1bee2f41 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java @@ -69,6 +69,7 @@ public final class VcsConfiguration implements PersistentStateComponent public boolean ENABLE_BACKGROUND_PROCESSES = false; public int CHANGED_ON_SERVER_INTERVAL = 60; public boolean SHOW_ONLY_CHANGED_IN_SELECTION_DIFF = true; + public boolean CHECK_COMMIT_MESSAGE_SPELLING = true; public enum StandardOption { ADD(VcsBundle.message("vcs.command.name.add")), 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 efe87f0fcc11..5a5e64283010 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 @@ -38,7 +38,6 @@ import com.intellij.openapi.vcs.checkin.*; import com.intellij.openapi.vcs.ui.CommitMessage; import com.intellij.openapi.vcs.ui.RefreshableOnComponent; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.EditorTextField; import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.SeparatorFactory; import com.intellij.util.Alarm; @@ -49,6 +48,8 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.io.File; import java.util.*; import java.util.List; @@ -94,6 +95,8 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj private final PseudoMap myAdditionalData; private String myHelpId; + + private final JCheckBox myCheckSpellingBox; private static class MyUpdateButtonsRunnable implements Runnable { private CommitChangeListDialog myDialog; @@ -261,6 +264,23 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj } } + myCheckSpellingBox = new JCheckBox(VcsBundle.message("checkbox.check.commit.message.spelling")); + myCheckSpellingBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + VcsConfiguration configuration = VcsConfiguration.getInstance(myProject); + boolean checkSpelling = e.getStateChange() == ItemEvent.SELECTED; + if (configuration != null) { + configuration.CHECK_COMMIT_MESSAGE_SPELLING = checkSpelling; + } + myCommitMessageArea.setCheckSpelling(checkSpelling); + } + }); + VcsConfiguration configuration = VcsConfiguration.getInstance(myProject); + if (configuration != null) { + myCheckSpellingBox.setSelected(configuration.CHECK_COMMIT_MESSAGE_SPELLING); + } + myActionName = VcsBundle.message("commit.dialog.title"); myAdditionalOptionsPanel = new JPanel(); @@ -767,7 +787,10 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj JPanel infoPanel = new JPanel(new BorderLayout()); myChangesInfoCalculator = new CommitLegendPanel.ChangeInfoCalculator(); myLegend = new CommitLegendPanel(myChangesInfoCalculator); - infoPanel.add(myLegend.getComponent(), BorderLayout.NORTH); + JPanel commonPanel = new JPanel(new BorderLayout()); + commonPanel.add(myLegend.getComponent()); + commonPanel.add(myCheckSpellingBox, BorderLayout.SOUTH); + infoPanel.add(commonPanel, BorderLayout.NORTH); infoPanel.add(myAdditionalOptionsPanel, BorderLayout.CENTER); rootPane.add(infoPanel, BorderLayout.EAST); infoPanel.setBorder(IdeBorderFactory.createEmptyBorder(0, 10, 0, 0)); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java index ac4f6e9ee8eb..30d5cc60444c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java @@ -21,9 +21,13 @@ import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.ActionToolbar; import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsBundle; +import com.intellij.openapi.vcs.VcsConfiguration; import com.intellij.ui.EditorCustomization; import com.intellij.ui.EditorTextField; import com.intellij.ui.EditorTextFieldProvider; @@ -32,14 +36,23 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; +import java.util.EnumSet; +import java.util.Set; public class CommitMessage extends JPanel implements Disposable { private final EditorTextField myEditorField; + private final Project myProject; public CommitMessage(Project project) { super(new BorderLayout()); - myEditorField = createEditorField(project); + boolean checkSpelling = true; + VcsConfiguration configuration = VcsConfiguration.getInstance(project); + if (configuration != null) { + checkSpelling = configuration.CHECK_COMMIT_MESSAGE_SPELLING; + } + myEditorField = createEditorField(project, checkSpelling); + myProject = project; // Note that we assume here that editor used for commit message processing uses font family implied by LAF (in contrast, // IJ code editor uses monospaced font). Hence, we don't need any special actions here @@ -64,10 +77,14 @@ public class CommitMessage extends JPanel implements Disposable { setBorder(BorderFactory.createEmptyBorder()); } - private static EditorTextField createEditorField(final Project project) { + private static EditorTextField createEditorField(final Project project, final boolean checkSpelling) { EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class); + Set features = EnumSet.of(EditorCustomization.Feature.SOFT_WRAP); + if (checkSpelling) { + features.add(EditorCustomization.Feature.SPELL_CHECK); + } return service.getEditorField( - FileTypes.PLAIN_TEXT.getLanguage(), project, EditorCustomization.Feature.SOFT_WRAP, EditorCustomization.Feature.SPELL_CHECK + FileTypes.PLAIN_TEXT.getLanguage(), project, features.toArray(new EditorCustomization.Feature[features.size()]) ); } @@ -98,6 +115,26 @@ public class CommitMessage extends JPanel implements Disposable { myEditorField.selectAll(); } + public void setCheckSpelling(boolean check) { + Editor editor = myEditorField.getEditor(); + if (!(editor instanceof EditorEx)) { + return; + } + EditorEx editorEx = (EditorEx)editor; + EditorCustomization[] customizations = Extensions.getExtensions(EditorCustomization.EP_NAME, myProject); + EditorCustomization.Feature feature = EditorCustomization.Feature.SPELL_CHECK; + for (EditorCustomization customization : customizations) { + if (customization.getSupportedFeatures().contains(feature)) { + if (check) { + customization.addCustomization(editorEx, feature); + } + else { + customization.removeCustomization(editorEx, feature); + } + } + } + } + public void dispose() { } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpectedTypeUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpectedTypeUtils.java index 3811539b11cc..b69ffe98016d 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpectedTypeUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpectedTypeUtils.java @@ -160,39 +160,33 @@ public class ExpectedTypeUtils{ final PsiJavaToken sign = binaryExpression.getOperationSign(); final IElementType tokenType = sign.getTokenType(); final PsiType type = binaryExpression.getType(); - if (TypeUtils.isJavaLangString(type)) { + final PsiExpression rhs = binaryExpression.getROperand(); + if (rhs == null) { expectedType = null; - } else if (isArithmeticOperation(tokenType)) { + return; + } + final PsiExpression lhs = binaryExpression.getLOperand(); + PsiType lhsType = lhs.getType(); + if (lhsType == null) { + expectedType = null; + return; + } + PsiType rhsType = rhs.getType(); + if (rhsType == null) { + expectedType = null; + return; + } + if (TypeUtils.isJavaLangString(type) || + isArithmeticOperation(tokenType) || + isBooleanOperation(tokenType)) { expectedType = type; } else if (isShiftOperation(tokenType)) { - final PsiExpression lhs = binaryExpression.getLOperand(); if (wrappedExpression.equals(lhs)) { - expectedType = unaryNumericPromotion(lhs.getType()); + expectedType = unaryNumericPromotion(lhsType); } else { - final PsiExpression rhs = binaryExpression.getROperand(); - if (rhs == null) { - expectedType = null; - } else { - expectedType = unaryNumericPromotion(rhs.getType()); - } + expectedType = unaryNumericPromotion(rhsType); } } else if (ComparisonUtils.isComparisonOperation(tokenType)) { - final PsiExpression rhs = binaryExpression.getROperand(); - if (rhs == null) { - expectedType = null; - return; - } - final PsiExpression lhs = binaryExpression.getLOperand(); - PsiType lhsType = lhs.getType(); - if (lhsType == null) { - expectedType = null; - return; - } - PsiType rhsType = rhs.getType(); - if (rhsType == null) { - expectedType = null; - return; - } if (!ClassUtils.isPrimitive(lhsType)) { lhsType = PsiPrimitiveType.getUnboxedType(lhsType); if (lhsType == null) { @@ -220,8 +214,6 @@ public class ExpectedTypeUtils{ } else { expectedType = PsiType.INT; } - } else if (isBooleanOperation(tokenType)) { - expectedType = type; } else { expectedType = null; } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/AutoBoxing.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/AutoBoxing.java index 0c0d7d4d1ee1..e853a3c93538 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/AutoBoxing.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/AutoBoxing.java @@ -8,9 +8,36 @@ public class AutoBoxing { static { Long someNumber = 0L; Long aLong = someNumber << 2; - someNumber++; + Long other = someNumber++; someNumber = ~someNumber; someNumber = -someNumber; someNumber = +someNumber; } + + public void foo() { + Integer bar = 3; + int baz = new Integer(3); + if (new Integer(3) == 3) { + return; + } + if (new Integer(3) + 3 == 3) { + return; + } + Integer x = 3; + } + + + public void bar(Double value) { + if (value > 0.0) { // this is not found! + return; + } + + bazz(value); + } + + private void bazz(double value) { + System.out.println("value = " + value); + Boolean c = Boolean.TRUE & false; + Long d = Integer.valueOf(2) & 1L; + } } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/expected.xml index 9e222cef8ae6..7d129bcf62b0 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/expected.xml +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/expected.xml @@ -15,4 +15,60 @@ Auto-boxing <code>someNumber << 2</code> #loc + + AutoBoxing.java + 11 + Auto-boxing + Auto-boxing <code>someNumber++</code> #loc + + + + AutoBoxing.java + 12 + Auto-boxing + Auto-boxing <code>~someNumber</code> #loc + + + + AutoBoxing.java + 13 + Auto-boxing + Auto-boxing <code>-someNumber</code> #loc + + + + AutoBoxing.java + 14 + Auto-boxing + Auto-boxing <code>+someNumber</code> #loc + + + + AutoBoxing.java + 18 + Auto-boxing + Auto-boxing <code>3</code> #loc + + + + AutoBoxing.java + 26 + Auto-boxing + Auto-boxing <code>3</code> #loc + + + + AutoBoxing.java + 40 + Auto-boxing + Auto-boxing <code>Boolean.TRUE & false</code> #loc + + + + + AutoBoxing.java + 41 + Auto-boxing + Auto-boxing <code>Integer.valueOf(2) & 1L</code> #loc + \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_unboxing/AutoUnboxing.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_unboxing/AutoUnboxing.java index 2ba970b3b4a1..0349ebc03e6d 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_unboxing/AutoUnboxing.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_unboxing/AutoUnboxing.java @@ -5,8 +5,35 @@ package com.siyeh.igtest.jdk.auto_unboxing; public class AutoUnboxing { { Long someNumber = Long.valueOf(0); - + someNumber++; long l = someNumber + 0; Long aLong = Long.valueOf(someNumber << 2); } + + public void foo() { + Integer bar = 3; + int baz = new Integer(3); + if (new Integer(3) == 3) { + return; + } + if (new Integer(3) + 3 == 3) { + return; + } + Integer x = 3; + } + + + public void bar(Double value) { + if (value > 0.0) { + return; + } + + bazz(value); + } + + private void bazz(double value) { + System.out.println("value = " + value); + Boolean c = Boolean.TRUE & false; + Long d = Integer.valueOf(2) & 1L; + } } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_unboxing/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_unboxing/expected.xml index d598f02785fb..ef9303806410 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_unboxing/expected.xml +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_unboxing/expected.xml @@ -1,6 +1,13 @@ + + AutoUnboxing.java + 8 + Auto-unboxing + Auto-unboxing <code>someNumber</code> #loc + + AutoUnboxing.java 9 @@ -15,4 +22,54 @@ Auto-unboxing <code>someNumber</code> #loc + + AutoUnboxing.java + 15 + Auto-unboxing + Auto-unboxing <code>new Integer(3)</code> #loc + + + + AutoUnboxing.java + 16 + Auto-unboxing + Auto-unboxing <code>new Integer(3)</code> #loc + + + + AutoUnboxing.java + 19 + Auto-unboxing + Auto-unboxing <code>new Integer(3)</code> #loc + + + + AutoUnboxing.java + 27 + Auto-unboxing + Auto-unboxing <code>value</code> #loc + + + + AutoUnboxing.java + 31 + Auto-unboxing + Auto-unboxing <code>value</code> #loc + + + + AutoUnboxing.java + 36 + Auto-unboxing + Auto-unboxing <code>Boolean.TRUE</code> #loc + + + + + AutoUnboxing.java + 37 + Auto-unboxing + Auto-unboxing <code>Integer.valueOf(2)</code> #loc + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/portability/AutoUnboxingInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/portability/AutoUnboxingInspection.java deleted file mode 100644 index 8dc3efd28097..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/portability/AutoUnboxingInspection.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.siyeh.igtest.portability; - -public class AutoUnboxingInspection { - public void foo() { - Integer bar = 3; - int baz = new Integer(3); - if (new Integer(3) == 3) { - return; - } - if (new Integer(3) + 3 == 3) { - return; - } - Integer x = 3; - } - - - public void bar(Double value) { - if (value > 0.0) { // this is not found! - return; - } - - bazz(value); - } - - private void bazz(double value) { - System.out.println("value = " + value); - } -} diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/ui/SpellCheckingEditorCustomization.java b/plugins/spellchecker/src/com/intellij/spellchecker/ui/SpellCheckingEditorCustomization.java index c455a7977b79..8d009ed94c43 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/ui/SpellCheckingEditorCustomization.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/ui/SpellCheckingEditorCustomization.java @@ -16,6 +16,7 @@ package com.intellij.spellchecker.ui; import com.intellij.codeHighlighting.HighlightDisplayLevel; +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInsight.intention.IntentionManager; import com.intellij.codeInspection.InspectionProfile; @@ -120,7 +121,7 @@ public class SpellCheckingEditorCustomization implements EditorCustomization { } @Override - public void customize(@NotNull EditorEx editor, @NotNull Feature feature) { + public void addCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { if (INSPECTION_PROFILE_WRAPPER == null) { return; } @@ -136,5 +137,28 @@ public class SpellCheckingEditorCustomization implements EditorCustomization { } file.putUserData(InspectionProfileWrapper.KEY, INSPECTION_PROFILE_WRAPPER); editor.putUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY, false); + updateRepresentation(project, file); + } + + @Override + public void removeCustomization(@NotNull EditorEx editor, @NotNull Feature feature) { + Project project = editor.getProject(); + if (project == null) { + return; + } + + PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); + if (file == null) { + return; + } + file.putUserData(InspectionProfileWrapper.KEY, null); + updateRepresentation(project, file); + } + + private static void updateRepresentation(@NotNull Project project, @NotNull PsiFile file) { + DaemonCodeAnalyzer analyzer = DaemonCodeAnalyzer.getInstance(project); + if (analyzer != null) { + analyzer.restart(file); + } } }