one more case of http://youtrack.jetbrains.net/issue/IDEA-25675 : http://ea.jetbrains...
authorDmitry Jemerov <yole@jetbrains.com>
Tue, 9 Mar 2010 12:45:04 +0000 (15:45 +0300)
committerDmitry Jemerov <yole@jetbrains.com>
Tue, 9 Mar 2010 13:02:08 +0000 (16:02 +0300)
java/java-impl/src/com/intellij/codeInsight/editorActions/CopyPasteReferenceProcessor.java
java/java-impl/src/com/intellij/codeInsight/editorActions/ReferenceTransferableData.java
platform/lang-impl/src/com/intellij/codeInsight/editorActions/TextBlockTransferable.java

index 3f70ed37a9e4593d2cbe3429a54e9a06b63e1320..051a12d73b188951c4a0a77d14fc05a889d04411 100644 (file)
@@ -30,6 +30,7 @@ import com.intellij.util.ArrayUtil;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.Nullable;
 
+import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
 import java.awt.datatransfer.UnsupportedFlavorException;
 import java.io.IOException;
@@ -89,7 +90,10 @@ public class CopyPasteReferenceProcessor implements CopyPastePostProcessor {
     ReferenceTransferableData referenceData = null;
     if (CodeInsightSettings.getInstance().ADD_IMPORTS_ON_PASTE != CodeInsightSettings.NO) {
       try {
-        referenceData = (ReferenceTransferableData)content.getTransferData(ReferenceTransferableData.ReferenceData.FLAVOR);
+        final DataFlavor flavor = ReferenceTransferableData.ReferenceData.getDataFlavor();
+        if (flavor != null) {
+          referenceData = (ReferenceTransferableData)content.getTransferData(flavor);
+        }
       }
       catch (UnsupportedFlavorException ignored) {
       }
index a3dfd6de3e833f13f9dd6abe6d023b74a9930c9e..d5fe437974e3f16b58045c21e20c96bc8e15095e 100644 (file)
@@ -15,7 +15,6 @@
  */
 package com.intellij.codeInsight.editorActions;
 
-import com.intellij.codeInsight.CodeInsightBundle;
 import org.jetbrains.annotations.NonNls;
 
 import java.awt.datatransfer.DataFlavor;
@@ -32,7 +31,7 @@ public class ReferenceTransferableData implements TextBlockTransferableData, Clo
   }
 
   public DataFlavor getFlavor() {
-    return ReferenceData.FLAVOR;
+    return ReferenceData.getDataFlavor();
   }
 
   public int getOffsetCount() {
@@ -68,8 +67,7 @@ public class ReferenceTransferableData implements TextBlockTransferableData, Clo
   }
 
   public static class ReferenceData implements Cloneable, Serializable {
-    public static final @NonNls DataFlavor FLAVOR = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType+";class="+ReferenceData.class.getName(),
-                                                                   CodeInsightBundle.message("paste.dataflavor.referencedata"));
+    public static @NonNls DataFlavor ourFlavor;
 
     public int startOffset;
     public int endOffset;
@@ -91,5 +89,18 @@ public class ReferenceTransferableData implements TextBlockTransferableData, Clo
         throw new RuntimeException();
       }
     }
+
+    public static DataFlavor getDataFlavor() {
+      if (ourFlavor != null) {
+        return ourFlavor;
+      }
+      try {
+        ourFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + ";class=" + ReferenceData.class.getName(), "ReferenceData");
+      }
+      catch (NoClassDefFoundError e) {
+        return null;
+      }
+      return ourFlavor;
+    }
   }
 }
index a39260f26809e9aad237468dfd60b5adba7762d5..3b8f1904dcd13a375c316e03b0bf5167c27e54df 100644 (file)
@@ -48,7 +48,10 @@ class TextBlockTransferable implements Transferable {
       dataFlavors.add(flavor);
     }
     for(TextBlockTransferableData data: extraData) {
-      dataFlavors.add(data.getFlavor());
+      final DataFlavor blockFlavor = data.getFlavor();
+      if (blockFlavor != null) {
+        dataFlavors.add(blockFlavor);
+      }
     }
     myTransferDataFlavors = dataFlavors.toArray(new DataFlavor[dataFlavors.size()]);
   }
@@ -70,7 +73,7 @@ class TextBlockTransferable implements Transferable {
   public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
     try {
       for(TextBlockTransferableData data: myExtraData) {
-        if (data.getFlavor().equals(flavor)) {
+        if (Comparing.equal(data.getFlavor(), flavor)) {
           return data;
         }
       }