node: move NodeStackTraceFilter to AbstractFileHyperlinkFilter API
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Wed, 21 Sep 2016 09:58:20 +0000 (12:58 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Wed, 21 Sep 2016 09:58:20 +0000 (12:58 +0300)
platform/lang-impl/src/com/intellij/execution/filters/AbstractFileHyperlinkFilter.java
platform/lang-impl/src/com/intellij/execution/filters/PatternBasedFileHyperlinkRawDataFinder.java

index 843e9b947ae21585211cd163229307c658014c4c..428e61646f6cdacd2f2657f3d3c04d9cb3d097a7 100644 (file)
  */
 package com.intellij.execution.filters;
 
+import com.intellij.openapi.application.ReadAction;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.roots.ProjectFileIndex;
-import com.intellij.openapi.vfs.LocalFileSystem;
+import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
+import org.jetbrains.io.LocalFileFinder;
 
-import java.io.File;
 import java.util.List;
 
 public abstract class AbstractFileHyperlinkFilter implements Filter {
@@ -32,12 +33,24 @@ public abstract class AbstractFileHyperlinkFilter implements Filter {
 
   private final Project myProject;
   private final ProjectFileIndex myFileIndex;
-  private final String myBaseDir;
+  private final VirtualFile myBaseDir;
 
   public AbstractFileHyperlinkFilter(@NotNull Project project, @Nullable String baseDir) {
     myProject = project;
     myFileIndex = ProjectFileIndex.SERVICE.getInstance(project);
-    myBaseDir = baseDir;
+    myBaseDir = findDir(baseDir);
+  }
+
+  @Nullable
+  private static VirtualFile findDir(@Nullable String baseDir) {
+    if (baseDir == null) {
+      return null;
+    }
+    return ReadAction.compute(() -> {
+      String path = FileUtil.toSystemIndependentName(baseDir);
+      VirtualFile dir = LocalFileFinder.findFile(path);
+      return dir != null && dir.isValid() && dir.isDirectory() ? dir : null;
+    });
   }
 
   @Nullable
@@ -53,14 +66,18 @@ public abstract class AbstractFileHyperlinkFilter implements Filter {
     }
     List<Filter.ResultItem> items = ContainerUtil.newArrayList();
     for (FileHyperlinkRawData link : links) {
-      VirtualFile file = findFile(link.getFilePath());
+      VirtualFile file = findFile(FileUtil.toSystemIndependentName(link.getFilePath()));
       if (file != null) {
         OpenFileHyperlinkInfo info = new OpenFileHyperlinkInfo(myProject,
                                                                file,
                                                                link.getDocumentLine(),
                                                                link.getDocumentColumn());
         boolean grayedHyperLink = isGrayedHyperlink(file);
-        items.add(new Filter.ResultItem(link.getHyperlinkStartInd(), link.getHyperlinkEndInd(), info, grayedHyperLink));
+        int offset = entireLength - line.length();
+        items.add(new Filter.ResultItem(offset + link.getHyperlinkStartInd(),
+                                        offset + link.getHyperlinkEndInd(),
+                                        info,
+                                        grayedHyperLink));
       }
     }
     return items.isEmpty() ? null : new Result(items);
@@ -75,25 +92,10 @@ public abstract class AbstractFileHyperlinkFilter implements Filter {
 
   @Nullable
   public VirtualFile findFile(@NotNull String filePath) {
-    File file = findIoFile(filePath);
-    if (file != null) {
-      return LocalFileSystem.getInstance().findFileByIoFile(file);
-    }
-    return null;
-  }
-
-  @Nullable
-  private File findIoFile(@NotNull String filePath) {
-    File file = new File(filePath);
-    if (file.isFile() && file.isAbsolute()) {
-      return file;
-    }
-    if (myBaseDir != null) {
-      file = new File(myBaseDir, filePath);
-      if (file.isFile()) {
-        return file;
-      }
+    VirtualFile file = LocalFileFinder.findFile(filePath);
+    if (file == null && myBaseDir != null) {
+      file = myBaseDir.findFileByRelativePath(filePath);
     }
-    return null;
+    return file;
   }
 }
index b8c5e32299ee536b7bd92dc5bf27a4a7b1716c02..cde5f0918f3adc6cbc2c9dfc335e6ce47db92fb3 100644 (file)
@@ -53,6 +53,9 @@ public class PatternBasedFileHyperlinkRawDataFinder implements FileHyperlinkRawD
     boolean hyperlinkFreezed = false;
     for (int i = 1; i <= groupCount; i++) {
       String value = matcher.group(i);
+      if (value == null) {
+        continue;
+      }
       PatternHyperlinkPart part = linkParts[i - 1];
       if (part == PatternHyperlinkPart.HYPERLINK) {
         hyperlinkStartInd = matcher.start(i);
@@ -74,7 +77,9 @@ public class PatternBasedFileHyperlinkRawDataFinder implements FileHyperlinkRawD
       else if (part == PatternHyperlinkPart.COLUMN) {
         value = StringUtil.trimStart(value, ":");
         columnNumber = StringUtil.parseInt(value, UNKNOWN);
-        hyperlinkEndInd = tryExtendHyperlinkEnd(hyperlinkFreezed, hyperlinkEndInd, matcher.start(i), matcher.end(i));
+        if (columnNumber != UNKNOWN) {
+          hyperlinkEndInd = tryExtendHyperlinkEnd(hyperlinkFreezed, hyperlinkEndInd, matcher.start(i), matcher.end(i));
+        }
       }
     }
     if (path == null || lineNumber == UNKNOWN || hyperlinkStartInd == -1) {