From a1d0ffceca00da98d6fb8bafe02b192fe9c458a0 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 7 Feb 2012 17:49:11 +0100 Subject: [PATCH] EA-33558 (ensure no more NPEs of that kind) --- .../CompareValueWithClipboardAction.java | 11 +++++------ .../diff/impl/settings/DiffPreviewPanel.java | 1 + .../intellij/openapi/diff/DiffRequest.java | 8 +++++--- .../intellij/openapi/diff/SimpleContent.java | 6 ++++-- .../openapi/diff/SimpleDiffRequest.java | 12 +++++++----- .../CompareClipboardWithSelection.java | 7 ++++--- .../diff/actions/CompareFileWithEditor.java | 8 +++++--- .../diff/impl/mergeTool/MergeRequestImpl.java | 5 ++++- .../diff/impl/external/DiffManagerTest.java | 19 ++++++++++++++++++- .../vcs/ex/ShowLineStatusRangeDiffAction.java | 7 ++++++- 10 files changed, 59 insertions(+), 25 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/CompareValueWithClipboardAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/CompareValueWithClipboardAction.java index e415e08eacd4..4f9f6cbdf741 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/CompareValueWithClipboardAction.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/CompareValueWithClipboardAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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,22 +16,20 @@ package com.intellij.debugger.actions; import com.intellij.debugger.DebuggerBundle; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diff.*; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.SystemInfo; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; -/* - * Class SetValueAction +/** * @author Jeka */ public class CompareValueWithClipboardAction extends BaseValueAction { - private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.actions.CompareValueWithClipboardAction"); protected void processText(final Project project, final String text) { DiffManager.getInstance().getDiffTool().show(new ClipboardSelectionContents(text, project)); } @@ -57,10 +55,11 @@ public class CompareValueWithClipboardAction extends BaseValueAction { return !SystemInfo.isMac; } + @NotNull public DiffContent[] getContents() { if (myContents != null) return myContents; DiffContent clipboardContent = createClipboardContent(); - if (clipboardContent == null) return null; + if (clipboardContent == null) clipboardContent = new SimpleContent(""); myContents = new DiffContent[2]; myContents[0] = clipboardContent; diff --git a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewPanel.java b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewPanel.java index e274135f8133..76a3f35cd3b6 100644 --- a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewPanel.java +++ b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewPanel.java @@ -123,6 +123,7 @@ public class DiffPreviewPanel implements PreviewPanel { super(project); } + @NotNull public DiffContent[] getContents() { return DiffPreviewProvider.getContents(); } diff --git a/platform/platform-api/src/com/intellij/openapi/diff/DiffRequest.java b/platform/platform-api/src/com/intellij/openapi/diff/DiffRequest.java index 388f25f7fc68..0f78e7a4e38a 100644 --- a/platform/platform-api/src/com/intellij/openapi/diff/DiffRequest.java +++ b/platform/platform-api/src/com/intellij/openapi/diff/DiffRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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,10 +30,11 @@ import java.util.*; * A request for a diff or merge operation. */ public abstract class DiffRequest { + @NonNls private static final String COMMON_DIFF_GROUP_KEY = "DiffWindow"; + private String myGroupKey = COMMON_DIFF_GROUP_KEY; private final Project myProject; private ToolbarAddons myToolbarAddons = ToolbarAddons.NOTHING; - @NonNls private static final String COMMON_DIFF_GROUP_KEY = "DiffWindow"; private Factory myBottomComponentFactory = null; private final HashSet myHints = new HashSet(); private final Map myGenericData; @@ -59,6 +60,7 @@ public abstract class DiffRequest { /** * @return contents to compare */ + @NotNull public abstract DiffContent[] getContents(); /** @@ -79,7 +81,7 @@ public abstract class DiffRequest { } /** - * Work in progess. Don't rely on this functionality
+ * Work in progress. Don't rely on this functionality
* @return not null (possibly empty) collection of hints for diff tool. */ public Collection getHints() { diff --git a/platform/platform-api/src/com/intellij/openapi/diff/SimpleContent.java b/platform/platform-api/src/com/intellij/openapi/diff/SimpleContent.java index fe6157574020..42e812a2f3c0 100644 --- a/platform/platform-api/src/com/intellij/openapi/diff/SimpleContent.java +++ b/platform/platform-api/src/com/intellij/openapi/diff/SimpleContent.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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,6 +25,7 @@ import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.SystemProperties; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.*; import java.nio.charset.Charset; @@ -38,6 +39,7 @@ import java.nio.ByteBuffer; */ public class SimpleContent extends DiffContent { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.diff.SimpleContent"); + private final byte[] myOriginalBytes; private final String myOriginalText; private final LineSeparators myLineSeparators = new LineSeparators(); @@ -53,7 +55,7 @@ public class SimpleContent extends DiffContent { this(text, null); } - public SimpleContent(@NotNull String text, FileType type) { + public SimpleContent(@NotNull String text, @Nullable FileType type) { this(text, type, EditorFactory.getInstance()); } diff --git a/platform/platform-api/src/com/intellij/openapi/diff/SimpleDiffRequest.java b/platform/platform-api/src/com/intellij/openapi/diff/SimpleDiffRequest.java index 0d0171c06971..2f82543a52a8 100644 --- a/platform/platform-api/src/com/intellij/openapi/diff/SimpleDiffRequest.java +++ b/platform/platform-api/src/com/intellij/openapi/diff/SimpleDiffRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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,6 @@ */ package com.intellij.openapi.diff; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; @@ -24,18 +23,20 @@ import org.jetbrains.annotations.NotNull; * Two contents for general diff */ public class SimpleDiffRequest extends DiffRequest { - private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.diff.SimpleDiffRequest"); private final DiffContent[] myContents = new DiffContent[2]; private final String[] myContentTitles = new String[2]; private String myWindowTitle; - public SimpleDiffRequest(Project project, String windowtitle) { + public SimpleDiffRequest(Project project, String windowTitle) { super(project); - myWindowTitle = windowtitle; + myWindowTitle = windowTitle; } + @NotNull public DiffContent[] getContents() { return myContents; } + public String[] getContentTitles() { return myContentTitles; } + public String getWindowTitle() { return myWindowTitle; } public void setContents(@NotNull DiffContent content1, @NotNull DiffContent content2) { @@ -75,6 +76,7 @@ public class SimpleDiffRequest extends DiffRequest { super(project, title); } + @NotNull public DiffContent[] getContents() { return new DiffContent[]{ DiffContent.fromFile(getProject(), myVirtualFiles[0]), diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/actions/CompareClipboardWithSelection.java b/platform/platform-impl/src/com/intellij/openapi/diff/actions/CompareClipboardWithSelection.java index 57c2cbae7bbf..230c58b55d50 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/actions/CompareClipboardWithSelection.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/actions/CompareClipboardWithSelection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -26,13 +26,13 @@ import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.TextRange; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; public class CompareClipboardWithSelection extends BaseDiffAction { - @Nullable protected DiffRequest getDiffData(DataContext dataContext) { Project project = PlatformDataKeys.PROJECT.getData(dataContext); @@ -65,10 +65,11 @@ public class CompareClipboardWithSelection extends BaseDiffAction { return !SystemInfo.isMac; } + @NotNull public DiffContent[] getContents() { if (myContents != null) return myContents; DiffContent clipboardContent = createClipboardContent(); - if (clipboardContent == null) return null; + if (clipboardContent == null) clipboardContent = new SimpleContent(""); myContents = new DiffContent[2]; myContents[0] = clipboardContent; diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/actions/CompareFileWithEditor.java b/platform/platform-impl/src/com/intellij/openapi/diff/actions/CompareFileWithEditor.java index 38a8c0e60445..85d005879f8c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/actions/CompareFileWithEditor.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/actions/CompareFileWithEditor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -23,6 +23,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.NonNls; @@ -109,10 +110,11 @@ public class CompareFileWithEditor extends BaseDiffAction { return new String[]{getVirtualFileContentTitle(myFile), documentTitle}; } + @NotNull public DiffContent[] getContents() { return new DiffContent[]{ - DocumentContent.fromFile(getProject(), myFile), - DocumentContent.fromDocument(getProject(), myDocument) + DiffContent.fromFile(getProject(), myFile), + DiffContent.fromDocument(getProject(), myDocument) }; } diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/mergeTool/MergeRequestImpl.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/mergeTool/MergeRequestImpl.java index 9e171439601e..6798ec93fbca 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/impl/mergeTool/MergeRequestImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/impl/mergeTool/MergeRequestImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -36,6 +37,7 @@ import java.io.IOException; public class MergeRequestImpl extends MergeRequest { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.diff.impl.mergeTool.MergeRequestImpl"); + private final DiffContent[] myDiffContents = new DiffContent[3]; private String myWindowTitle = null; private String[] myVersionTitles = null; @@ -87,6 +89,7 @@ public class MergeRequestImpl extends MergeRequest { myDiffContents[2] = right; } + @NotNull public DiffContent[] getContents() { return myDiffContents; } public String[] getContentTitles() { return myVersionTitles; } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/diff/impl/external/DiffManagerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/diff/impl/external/DiffManagerTest.java index e3d532d2aabe..525bcac7b374 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/diff/impl/external/DiffManagerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/diff/impl/external/DiffManagerTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2012 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.diff.impl.external; import com.intellij.openapi.diff.BinaryContent; @@ -7,6 +22,7 @@ import com.intellij.openapi.diff.DiffTool; import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.util.ArrayUtil; import junit.framework.TestCase; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -37,7 +53,7 @@ public class DiffManagerTest extends TestCase { return canShowImpl(request); } - private boolean canShowImpl(DiffRequest request) { + private static boolean canShowImpl(DiffRequest request) { return request.getContents().length == 4; } @@ -66,6 +82,7 @@ public class DiffManagerTest extends TestCase { return ArrayUtil.toStringArray(myContentTitles); } + @NotNull @Override public DiffContent[] getContents() { return myDiffContents.toArray(new DiffContent[myDiffContents.size()]); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ShowLineStatusRangeDiffAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ShowLineStatusRangeDiffAction.java index 8f9fee4eab25..675d50396695 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ShowLineStatusRangeDiffAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/ShowLineStatusRangeDiffAction.java @@ -1,9 +1,12 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -21,6 +24,7 @@ import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; /** * @author irengrig @@ -48,6 +52,7 @@ public class ShowLineStatusRangeDiffAction extends BaseLineStatusRangeAction { private DiffRequest createDiffData() { return new DiffRequest(myLineStatusTracker.getProject()) { + @NotNull public DiffContent[] getContents() { return new DiffContent[]{createDiffContent(myLineStatusTracker.getUpToDateDocument(), myLineStatusTracker.getUpToDateRangeWithEndSymbol(myRange), null),