EA-30535 (no more NPEs around CopyPasteManager.getContents())

This commit is contained in:
Roman Shevchenko
2011-10-17 16:43:04 +02:00
parent d76f44e7c6
commit 2e2a29c48b
8 changed files with 29 additions and 28 deletions
@@ -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.diff.*;
import com.intellij.openapi.ide.CopyPasteManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.SystemInfo;
import org.jetbrains.annotations.Nullable;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
@@ -72,16 +73,16 @@ public class CompareValueWithClipboardAction extends BaseValueAction {
return DebuggerBundle.message("diff.clipboard.vs.value.dialog.title");
}
@Nullable
private static DiffContent createClipboardContent() {
Transferable content = CopyPasteManager.getInstance().getContents();
String text = "";
try {
text = (String) (content.getTransferData(DataFlavor.stringFlavor));
if (content != null) {
try {
String text = (String) (content.getTransferData(DataFlavor.stringFlavor));
return text != null ? new SimpleContent(text) : null;
} catch (Exception ignored) { }
}
catch (Exception e) {
LOG.info(e);
}
return new SimpleContent(text);
return null;
}
}
}
@@ -48,6 +48,7 @@ public class FileListPasteProvider implements PasteProvider {
if (project == null || ideView == null) return;
final Transferable contents = CopyPasteManager.getInstance().getContents();
if (contents == null) return;
final List<File> fileList = FileCopyPasteUtil.getFileList(contents);
if (fileList == null) return;
@@ -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.
@@ -131,7 +131,7 @@ public class EditorModificationUtil {
@Nullable
public static TextRange pasteFromClipboard(Editor editor) {
return pasteFromTransferrable(getClipboardContent(editor), editor);
return pasteFromTransferrable(CopyPasteManager.getInstance().getContents(), editor);
}
@Nullable
@@ -165,19 +165,15 @@ public class EditorModificationUtil {
return s;
}
private static Transferable getClipboardContent(Editor editor) {
return CopyPasteManager.getInstance().getContents();
}
public static void pasteFromClipboardAsBlock(Editor editor) {
pasteTransferableAsBlock(editor, null);
}
public static void pasteTransferableAsBlock(Editor editor, @Nullable Transferable content) {
if (content == null) {
content = getClipboardContent(editor);
content = CopyPasteManager.getInstance().getContents();
}
if (content != null) {
try {
int caretLine = editor.getCaretModel().getLogicalPosition().line;
@@ -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.
@@ -40,6 +40,7 @@ public abstract class CopyPasteManager {
public abstract boolean isDataFlavorAvailable(@NotNull DataFlavor flavor);
@Nullable
public abstract Transferable getContents();
public abstract Transferable[] getAllContents();
@@ -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.
@@ -220,7 +220,6 @@ public class CopyPasteManagerEx extends CopyPasteManager implements ClipboardOwn
}
}
@Nullable
public Transferable getContents() {
return myClipboardSynchronizer.getContents();
}
@@ -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.
@@ -75,11 +75,11 @@ public class CompareClipboardWithSelection extends BaseDiffAction {
SelectionModel selectionModel = myEditor.getSelectionModel();
if (selectionModel.hasSelection()) {
TextRange range = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
myContents[1] = new FragmentContent(DocumentContent.fromDocument(getProject(), getDocument()),
myContents[1] = new FragmentContent(DiffContent.fromDocument(getProject(), getDocument()),
range, getProject(), getDocumentFile(getDocument()));
}
else {
myContents [1] = DocumentContent.fromDocument(getProject(), getDocument());
myContents [1] = DiffContent.fromDocument(getProject(), getDocument());
}
return myContents;
}
@@ -96,15 +96,16 @@ public class CompareClipboardWithSelection extends BaseDiffAction {
}
}
@Nullable
private static DiffContent createClipboardContent() {
Transferable content = CopyPasteManager.getInstance().getContents();
String text;
try {
text = (String) (content.getTransferData(DataFlavor.stringFlavor));
} catch (Exception e) {
return null;
if (content != null) {
try {
String text = (String) (content.getTransferData(DataFlavor.stringFlavor));
return text != null ? new SimpleContent(text) : null;
} catch (Exception ignored) { }
}
return text != null ? new SimpleContent(text) : null;
return null;
}
}
}
@@ -39,6 +39,7 @@ public class KillRegionActionTest extends AbstractRegionToKillRingTest {
killRegion();
if (parseResult.first != null) {
Transferable contents = CopyPasteManager.getInstance().getContents();
assertNotNull(contents);
assertEquals(parseResult.first, contents.getTransferData(DataFlavor.stringFlavor));
}
@@ -43,6 +43,7 @@ public class KillRingSaveActionTest extends AbstractRegionToKillRingTest {
}
Transferable contents = CopyPasteManager.getInstance().getContents();
assertNotNull(contents);
assertEquals(parseResult.first, contents.getTransferData(DataFlavor.stringFlavor));
assertEquals(textBefore, myEditor.getDocument().getText());
}