export to HTML: take read actions properly (IDEA-136348), remove unnecessary extensio...
authorDmitry Jemerov <yole@jetbrains.com>
Tue, 24 Feb 2015 17:37:50 +0000 (18:37 +0100)
committerDmitry Jemerov <yole@jetbrains.com>
Tue, 24 Feb 2015 19:05:52 +0000 (20:05 +0100)
java/java-impl/src/com/intellij/codeEditor/printing/MethodSeparatorProvider.java [deleted file]
platform/lang-impl/src/com/intellij/codeEditor/printing/ExportToHTMLManager.java
platform/lang-impl/src/com/intellij/codeEditor/printing/FileSeparatorProvider.java
platform/lang-impl/src/com/intellij/codeEditor/printing/HTMLTextPainter.java
platform/lang-impl/src/com/intellij/codeEditor/printing/TextPainter.java
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LineMarkersPass.java
platform/platform-resources/src/META-INF/PlatformLangPlugin.xml
resources/src/META-INF/IdeaPlugin.xml

diff --git a/java/java-impl/src/com/intellij/codeEditor/printing/MethodSeparatorProvider.java b/java/java-impl/src/com/intellij/codeEditor/printing/MethodSeparatorProvider.java
deleted file mode 100644 (file)
index 80aa4d5..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2000-2015 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.
- */
-
-/*
- * User: anna
- * Date: 25-Jan-2008
- */
-package com.intellij.codeEditor.printing;
-
-import com.intellij.codeInsight.daemon.LineMarkerInfo;
-import com.intellij.codeInsight.daemon.impl.LineMarkersPass;
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.psi.PsiFile;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-public class MethodSeparatorProvider extends FileSeparatorProvider {
-  @Override
-  public List<LineMarkerInfo> getFileSeparators(final PsiFile file, final Document document, @Nullable final Editor editor) {
-    final List<LineMarkerInfo> result = new ArrayList<LineMarkerInfo>();
-    LineMarkersPass pass = new LineMarkersPass(file.getProject(), file, editor, document, file.getTextRange());
-    for (LineMarkerInfo lineMarkerInfo : pass.queryLineMarkers()) {
-      if (lineMarkerInfo.separatorColor != null) {
-        result.add(lineMarkerInfo);
-      }
-    }
-
-    Collections.sort(result, new Comparator<LineMarkerInfo>() {
-      public int compare(final LineMarkerInfo i1, final LineMarkerInfo i2) {
-        return i1.startOffset - i2.startOffset;
-      }
-    });
-    return result;
-  }
-}
\ No newline at end of file
index e8fd2235d370848ff09fa8b038f57cc5f43dc5cc..0ee2cd2e5e4618b9b88c1ae8d3f62f9cab4d091b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
@@ -20,6 +20,7 @@ import com.intellij.CommonBundle;
 import com.intellij.ide.BrowserUtil;
 import com.intellij.openapi.actionSystem.CommonDataKeys;
 import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.extensions.Extensions;
@@ -130,32 +131,39 @@ class ExportToHTMLManager {
     }
   }
 
-  private static boolean exportPsiFile(final PsiFile psiFile, String outputDirectoryName, Project project, HashMap<PsiFile, PsiFile> filesMap) {
-    ExportToHTMLSettings exportToHTMLSettings = ExportToHTMLSettings.getInstance(project);
+  private static boolean exportPsiFile(final PsiFile psiFile,
+                                       final String outputDirectoryName,
+                                       final Project project,
+                                       final HashMap<PsiFile, PsiFile> filesMap) {
+    final ExportToHTMLSettings exportToHTMLSettings = ExportToHTMLSettings.getInstance(project);
 
     if (psiFile instanceof PsiBinaryFile) {
       return true;
     }
 
-    TreeMap<Integer, PsiReference> refMap = null;
-    for (PrintOption printOption : Extensions.getExtensions(PrintOption.EP_NAME)) {
-      final TreeMap<Integer, PsiReference> map = printOption.collectReferences(psiFile, filesMap);
-      if (map != null) {
-        refMap = new TreeMap<Integer, PsiReference>();
-        refMap.putAll(map);
-      }
-    }
+    ApplicationManager.getApplication().runReadAction(new Runnable() {
+      @Override
+      public void run() {
+        TreeMap<Integer, PsiReference> refMap = null;
+        for (PrintOption printOption : Extensions.getExtensions(PrintOption.EP_NAME)) {
+          final TreeMap<Integer, PsiReference> map = printOption.collectReferences(psiFile, filesMap);
+          if (map != null) {
+            refMap = new TreeMap<Integer, PsiReference>();
+            refMap.putAll(map);
+          }
+        }
 
-    String dirName = constructOutputDirectory(psiFile, outputDirectoryName);
-    HTMLTextPainter textPainter = new HTMLTextPainter(psiFile, project, dirName, exportToHTMLSettings.PRINT_LINE_NUMBERS);
-    try {
-      textPainter.paint(refMap, psiFile.getFileType());
-    }
-    catch (FileNotFoundException e) {
-      myLastException = e;
-      return false;
-    }
-    return true;
+        String dirName = constructOutputDirectory(psiFile, outputDirectoryName);
+        HTMLTextPainter textPainter = new HTMLTextPainter(psiFile, project, dirName, exportToHTMLSettings.PRINT_LINE_NUMBERS);
+        try {
+          textPainter.paint(refMap, psiFile.getFileType());
+        }
+        catch (FileNotFoundException e) {
+          myLastException = e;
+        }
+      }
+    });
+    return myLastException == null;
   }
 
   private static String constructOutputDirectory(PsiFile psiFile, String outputDirectoryName) {
@@ -241,11 +249,18 @@ class ExportToHTMLManager {
       final ArrayList<PsiFile> filesList = new ArrayList<PsiFile>();
       final boolean isRecursive = myExportToHTMLSettings.isIncludeSubdirectories();
 
-      try {
-        addToPsiFileList(myPsiDirectory, filesList, isRecursive, myOutputDirectoryName);
-      }
-      catch (FileNotFoundException e) {
-        myLastException = e;
+      ApplicationManager.getApplication().runReadAction(new Runnable() {
+        @Override
+        public void run() {
+          try {
+            addToPsiFileList(myPsiDirectory, filesList, isRecursive, myOutputDirectoryName);
+          }
+          catch (FileNotFoundException e) {
+            myLastException = e;
+          }
+        }
+      });
+      if (myLastException != null) {
         return;
       }
       HashMap<PsiFile, PsiFile> filesMap = new HashMap<PsiFile, PsiFile>();
index 1a1d7b0a43c14aa19e3928a7408151d180076379..31ec50c83606c0a41c849930e4b8f03618f31e83 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
 package com.intellij.codeEditor.printing;
 
 import com.intellij.codeInsight.daemon.LineMarkerInfo;
-import com.intellij.openapi.components.ServiceManager;
+import com.intellij.codeInsight.daemon.impl.LineMarkersPass;
 import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.Editor;
 import com.intellij.psi.PsiFile;
 import org.jetbrains.annotations.Nullable;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 public class FileSeparatorProvider {
-  public static FileSeparatorProvider getInstance() {
-    return ServiceManager.getService(FileSeparatorProvider.class);
-  }
-
   @Nullable
-  public List<LineMarkerInfo> getFileSeparators(PsiFile file, final Document document, @Nullable final Editor editor) {
-    return null;
+  public static List<LineMarkerInfo> getFileSeparators(PsiFile file, final Document document) {
+    final List<LineMarkerInfo> result = new ArrayList<LineMarkerInfo>();
+    LineMarkersPass pass = new LineMarkersPass(file.getProject(), file, null, document, file.getTextRange());
+    for (LineMarkerInfo lineMarkerInfo : pass.queryLineMarkers()) {
+      if (lineMarkerInfo.separatorColor != null) {
+        result.add(lineMarkerInfo);
+      }
+    }
+
+    Collections.sort(result, new Comparator<LineMarkerInfo>() {
+      public int compare(final LineMarkerInfo i1, final LineMarkerInfo i2) {
+        return i1.startOffset - i2.startOffset;
+      }
+    });
+    return result;
   }
 }
\ No newline at end of file
index 22e365cc5a4f95e60b545a264344525183e5f94f..ccb474bcadcf821c044a72762396da7f3c9320d6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
@@ -35,7 +35,6 @@ import com.intellij.psi.PsiFile;
 import com.intellij.psi.PsiReference;
 import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
 import com.intellij.psi.impl.file.PsiDirectoryFactory;
-import com.intellij.psi.util.PsiUtilBase;
 import com.intellij.ui.JBColor;
 import org.jetbrains.annotations.NonNls;
 
@@ -86,8 +85,7 @@ class HTMLTextPainter {
 
     ArrayList<LineMarkerInfo> methodSeparators = new ArrayList<LineMarkerInfo>();
     if (document != null) {
-      final List<LineMarkerInfo> separators = FileSeparatorProvider.getInstance().getFileSeparators(psiFile, document,
-                                                                                                    PsiUtilBase.findEditor(psiFile));
+      final List<LineMarkerInfo> separators = FileSeparatorProvider.getFileSeparators(psiFile, document);
       if (separators != null) {
         methodSeparators.addAll(separators);
       }
index 7c84f5e637aad37309be99caf68ebd26ee5f4dd0..801bfdc5f8197ff0bf98e6be6cce449cb52b8fa4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
@@ -100,7 +100,7 @@ class TextPainter extends BasePainter {
                      FileType fileType,
                      Editor editor) {
     this(editorDocument, highlighter, fullFileName, shortFileName, psiFile.getProject(), fileType,
-         FileSeparatorProvider.getInstance().getFileSeparators(psiFile, editorDocument, editor));
+         FileSeparatorProvider.getFileSeparators(psiFile, editorDocument));
   }
 
   public TextPainter(@NotNull DocumentEx editorDocument,
index 6ae363f52f7e3386495e8409e77a0ac17c58ae9d..e67c63bb7a50d54114be12121c967f31b0a4fed9 100644 (file)
@@ -109,7 +109,7 @@ public class LineMarkersPass extends TextEditorHighlightingPass implements LineM
     myMarkers = mergeLineMarkers(lineMarkers, myEditor);
   }
 
-  static List<LineMarkerInfo> mergeLineMarkers(@NotNull List<LineMarkerInfo> markers, Editor editor) {
+  static List<LineMarkerInfo> mergeLineMarkers(@NotNull List<LineMarkerInfo> markers, @Nullable Editor editor) {
     List<MergeableLineMarkerInfo> forMerge = new ArrayList<MergeableLineMarkerInfo>();
     final Iterator<LineMarkerInfo> iterator = markers.iterator();
     while (iterator.hasNext()) {
index 4c2a05ef506b582f7dc66bb67cae8edf1fa8c0d6..62afda53d807b8ea1b507e85f827a20e2c1f67bc 100644 (file)
@@ -71,8 +71,6 @@
 
     <refactoring.copyHandler implementation="com.intellij.refactoring.copy.CopyFilesOrDirectoriesHandler"/>
     <refactoring.moveHandler implementation="com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesHandler" id="moveFileOrDir"/>
-    <applicationService serviceInterface="com.intellij.codeEditor.printing.FileSeparatorProvider"
-                        serviceImplementation="com.intellij.codeEditor.printing.FileSeparatorProvider"/>
 
     <treeStructureProvider implementation="com.intellij.platform.PlatformProjectViewStructureProvider"/>
 
index ded75cc64893fad0b30eb8556d111b22b89a8f08..b9db52d3b9eb594d9f148516f94558ec5e60bcc4 100644 (file)
     <macro implementation="com.intellij.ide.macro.OutputPathMacro"/>
 
     <printOption implementation="com.intellij.codeEditor.printing.HyperlinksToClassesOption"/>
-    <applicationService serviceInterface="com.intellij.codeEditor.printing.FileSeparatorProvider"
-                        serviceImplementation="com.intellij.codeEditor.printing.MethodSeparatorProvider"/>
 
     <indexPatternBuilder implementation="com.intellij.psi.impl.search.JavaIndexPatternBuilder"/>
     <indexPatternBuilder implementation="com.intellij.psi.impl.search.JspIndexPatternBuilder"/>