use withAlternativeResolveEnabled
authorpeter <peter@jetbrains.com>
Wed, 18 Feb 2015 12:00:57 +0000 (13:00 +0100)
committerpeter <peter@jetbrains.com>
Wed, 18 Feb 2015 15:18:44 +0000 (16:18 +0100)
platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyHandler.java
platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java
platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java

index e1628464ff343c4c6ff5938849983bfcbb9abbcd..7e25790ea6c12ae0d4d9d52cc770d205a3f69bc7 100644 (file)
@@ -87,17 +87,16 @@ public class CopyHandler extends EditorActionHandler {
     final int[] startOffsets = selectionModel.getBlockSelectionStarts();
     final int[] endOffsets = selectionModel.getBlockSelectionEnds();
 
-    List<TextBlockTransferableData> transferableDatas = new ArrayList<TextBlockTransferableData>();
+    final List<TextBlockTransferableData> transferableDatas = new ArrayList<TextBlockTransferableData>();
     
-    DumbService.getInstance(project).setAlternativeResolveEnabled(true);
-    try {
-      for (CopyPastePostProcessor<? extends TextBlockTransferableData> processor : Extensions.getExtensions(CopyPastePostProcessor.EP_NAME)) {
-        transferableDatas.addAll(processor.collectTransferableData(file, editor, startOffsets, endOffsets));
+    DumbService.getInstance(project).withAlternativeResolveEnabled(new Runnable() {
+      @Override
+      public void run() {
+        for (CopyPastePostProcessor<? extends TextBlockTransferableData> processor : Extensions.getExtensions(CopyPastePostProcessor.EP_NAME)) {
+          transferableDatas.addAll(processor.collectTransferableData(file, editor, startOffsets, endOffsets));
+        }
       }
-    }
-    finally {
-      DumbService.getInstance(project).setAlternativeResolveEnabled(false);
-    }
+    });
 
     String text = editor.getCaretModel().supportsMultipleCarets()
                   ? EditorCopyPasteHelperImpl.getSelectedTextForClipboard(editor, transferableDatas)
index cf841294dc27e8fbb89e8dac409906bd00e223a7..be5e0250adb41cd8b3d48ea79cd83cc4bc051826 100644 (file)
@@ -155,21 +155,20 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser
     final CodeInsightSettings settings = CodeInsightSettings.getInstance();
 
     final Map<CopyPastePostProcessor, List<? extends TextBlockTransferableData>> extraData = new HashMap<CopyPastePostProcessor, List<? extends TextBlockTransferableData>>();
-    Collection<TextBlockTransferableData> allValues = new ArrayList<TextBlockTransferableData>();
+    final Collection<TextBlockTransferableData> allValues = new ArrayList<TextBlockTransferableData>();
 
-    DumbService.getInstance(project).setAlternativeResolveEnabled(true);
-    try {
-      for (CopyPastePostProcessor<? extends TextBlockTransferableData> processor : Extensions.getExtensions(CopyPastePostProcessor.EP_NAME)) {
-        List<? extends TextBlockTransferableData> data = processor.extractTransferableData(content);
-        if (!data.isEmpty()) {
-          extraData.put(processor, data);
-          allValues.addAll(data);
+    DumbService.getInstance(project).withAlternativeResolveEnabled(new Runnable() {
+      @Override
+      public void run() {
+        for (CopyPastePostProcessor<? extends TextBlockTransferableData> processor : Extensions.getExtensions(CopyPastePostProcessor.EP_NAME)) {
+          List<? extends TextBlockTransferableData> data = processor.extractTransferableData(content);
+          if (!data.isEmpty()) {
+            extraData.put(processor, data);
+            allValues.addAll(data);
+          }
         }
       }
-    }
-    finally {
-      DumbService.getInstance(project).setAlternativeResolveEnabled(false);
-    }
+    });
 
     text = TextBlockTransferable.convertLineSeparators(editor, text, allValues);
 
index 4ccd5b0cefa49101f46f6bad3baa15bae7247b5a..23b90f295752ce0f2479dfad0daae891524f1d2c 100644 (file)
@@ -1105,15 +1105,14 @@ public class TemplateState implements Disposable {
     final PsiFile file = getPsiFile();
     if (file != null) {
       CodeStyleManager style = CodeStyleManager.getInstance(myProject);
-      DumbService.getInstance(myProject).setAlternativeResolveEnabled(true);
-      try {
-        for (TemplateOptionalProcessor optionalProcessor : Extensions.getExtensions(TemplateOptionalProcessor.EP_NAME)) {
-          optionalProcessor.processText(myProject, myTemplate, myDocument, myTemplateRange, myEditor);
+      DumbService.getInstance(myProject).withAlternativeResolveEnabled(new Runnable() {
+        @Override
+        public void run() {
+          for (TemplateOptionalProcessor optionalProcessor : Extensions.getExtensions(TemplateOptionalProcessor.EP_NAME)) {
+            optionalProcessor.processText(myProject, myTemplate, myDocument, myTemplateRange, myEditor);
+          }
         }
-      }
-      finally {
-        DumbService.getInstance(myProject).setAlternativeResolveEnabled(false);
-      }
+      });
       PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(myDocument);
       // for Python, we need to indent the template even if reformatting is enabled, because otherwise indents would be broken
       // and reformat wouldn't be able to fix them