private static THashSet<String> collectFoldersToExclude(
      final Module module, final VirtualFile pubspecYamlFile) {
    final THashSet<String> newExcludedPackagesUrls = new THashSet<String>();
    final ProjectFileIndex fileIndex =
        ProjectRootManager.getInstance(module.getProject()).getFileIndex();
    final VirtualFile root = pubspecYamlFile.getParent();

    final VirtualFile binFolder = root.findChild("bin");
    if (binFolder != null && binFolder.isDirectory() && fileIndex.isInContent(binFolder)) {
      newExcludedPackagesUrls.add(binFolder.getUrl() + "/packages");
    }

    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("benchmark"), fileIndex);
    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("example"), fileIndex);
    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("test"), fileIndex);
    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("tool"), fileIndex);
    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("web"), fileIndex);

    // Folder packages/ThisProject (where ThisProject is the name specified in pubspec.yaml) is a
    // symlink to local 'lib' folder. Exclude it in order not to have duplicates. Resolve goes to
    // local 'lib' folder.
    // Empty 'ThisProject (link to 'lib' folder)' node is added to Project Structure by
    // DartTreeStructureProvider
    final VirtualFile libFolder = root.findChild("lib");
    if (libFolder != null && libFolder.isDirectory()) {
      final String pubspecName = PubspecYamlUtil.getPubspecName(pubspecYamlFile);
      if (pubspecName != null) {
        newExcludedPackagesUrls.add(root.getUrl() + "/packages/" + pubspecName);
      }
    }

    return newExcludedPackagesUrls;
  }
 private static void addPathCompletions(
     @NotNull CompletionResultSet result,
     @NotNull BipartiteString caretBipartiteElementText,
     @NotNull VirtualFile basePath,
     boolean directoryExpected) {
   ParentDirWithLastComponentPrefix parentWithLastComponentPrefix =
       findParentDirWithLastComponentPrefix(basePath, caretBipartiteElementText.getPrefix());
   if (parentWithLastComponentPrefix != null) {
     PrefixMatcher matcher =
         new StrictPrefixMatcher(parentWithLastComponentPrefix.getLastComponentPrefix(), false);
     result = result.withPrefixMatcher(matcher);
     VirtualFile parentFile = parentWithLastComponentPrefix.getParent();
     VirtualFile[] children = parentFile.getChildren();
     Character dirSeparatorSuffix =
         extractDirectoryTrailingFileSeparator(caretBipartiteElementText);
     if (parentFile.isDirectory()) {
       result.addElement(LookupItem.fromString(".."));
     }
     for (VirtualFile child : children) {
       if (child.isDirectory() || !directoryExpected) {
         String name = child.getName();
         if (child.isDirectory() && dirSeparatorSuffix != null) {
           name += dirSeparatorSuffix;
         }
         result.addElement(LookupItem.fromString(name));
       }
     }
   }
 }
  @Nullable
  public static VirtualFile getDirectory(@NotNull final FindModel findModel) {
    String directoryName = findModel.getDirectoryName();
    if (findModel.isProjectScope() || StringUtil.isEmpty(directoryName)) {
      return null;
    }

    String path = directoryName.replace(File.separatorChar, '/');
    VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(path);
    if (virtualFile == null || !virtualFile.isDirectory()) {
      virtualFile = null;
      for (LocalFileProvider provider :
          ((VirtualFileManagerEx) VirtualFileManager.getInstance()).getLocalFileProviders()) {
        VirtualFile file = provider.findLocalVirtualFileByPath(path);
        if (file != null && file.isDirectory()) {
          if (file.getChildren().length > 0) {
            virtualFile = file;
            break;
          }
          if (virtualFile == null) {
            virtualFile = file;
          }
        }
      }
    }
    return virtualFile;
  }
  /**
   * @param path project file path
   * @param projectToClose currently active project
   * @param forceOpenInNewFrame forces opening in new frame
   * @return project by path if the path was recognized as IDEA project file or one of the project
   *     formats supported by installed importers (regardless of opening/import result) null
   *     otherwise
   */
  @Nullable
  public static Project openOrImport(
      @NotNull String path, Project projectToClose, boolean forceOpenInNewFrame) {
    VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
    if (virtualFile == null) return null;
    virtualFile.refresh(false, false);

    ProjectOpenProcessor strong = ProjectOpenProcessor.getStrongImportProvider(virtualFile);
    if (strong != null) {
      return strong.doOpenProject(virtualFile, projectToClose, forceOpenInNewFrame);
    }

    if (path.endsWith(ProjectFileType.DOT_DEFAULT_EXTENSION)
        || virtualFile.isDirectory()
            && virtualFile.findChild(Project.DIRECTORY_STORE_FOLDER) != null) {
      return openProject(path, projectToClose, forceOpenInNewFrame);
    }

    if (virtualFile.isDirectory()) {
      for (VirtualFile child : virtualFile.getChildren()) {
        final String childPath = child.getPath();
        if (childPath.endsWith(ProjectFileType.DOT_DEFAULT_EXTENSION)) {
          return openProject(childPath, projectToClose, forceOpenInNewFrame);
        }
      }
    }

    ProjectOpenProcessor provider = ProjectOpenProcessor.getImportProvider(virtualFile);
    if (provider != null) {
      final Project project =
          provider.doOpenProject(virtualFile, projectToClose, forceOpenInNewFrame);

      if (project != null) {
        ApplicationManager.getApplication()
            .invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    if (!project.isDisposed()) {
                      final ToolWindow toolWindow =
                          ToolWindowManager.getInstance(project)
                              .getToolWindow(ToolWindowId.PROJECT_VIEW);
                      if (toolWindow != null) {
                        toolWindow.activate(null);
                      }
                    }
                  }
                },
                ModalityState.NON_MODAL);
      }

      return project;
    }

    return null;
  }
Example #5
0
 public static void refreshFiles(Project project, HashSet<FilePath> paths) {
   for (FilePath path : paths) {
     VirtualFile vFile = path.getVirtualFile();
     if (vFile != null) {
       if (vFile.isDirectory()) {
         markFileAsDirty(project, vFile);
       } else {
         vFile.refresh(true, vFile.isDirectory());
       }
     }
   }
 }
    /**
     * For the given VirtualFile constructs a FilePathImpl object without referring to the initial
     * VirtualFile object and adds this FilePathImpl to the set of files for proper
     * VcsDirtyScopeManager - to mark these files dirty when the set will be populated.
     *
     * @param file file which path is to be added.
     * @param addToFiles If true, then add to dirty files even if it is a directory. Otherwise add
     *     to the proper set.
     */
    private void add(VirtualFile file, boolean addToFiles, final boolean forDelete) {
      if (file == null) {
        return;
      }
      final boolean isDirectory = file.isDirectory();
      // need to create FilePath explicitly without referring to VirtualFile because the path of
      // VirtualFile may change
      final FilePathImpl path =
          forDelete
              ? new FilePathImpl(new File(file.getPath()), isDirectory)
              : new FilePathImpl(file);

      final Collection<VcsDirtyScopeManager> managers = getManagers(file);
      for (VcsDirtyScopeManager manager : managers) {
        Couple<HashSet<FilePath>> filesAndDirs = map.get(manager);
        if (filesAndDirs == null) {
          filesAndDirs = Couple.of(new HashSet<FilePath>(), new HashSet<FilePath>());
          map.put(manager, filesAndDirs);
        }

        if (addToFiles || !isDirectory) {
          filesAndDirs.first.add(path);
        } else {
          filesAndDirs.second.add(path);
        }
      }
    }
  @Nullable
  public SVNPropertyValue getPropertyWithCaching(final VirtualFile file, final String propName)
      throws SVNException {
    Map<String, Pair<SVNPropertyValue, Trinity<Long, Long, Long>>> cachedMap =
        myPropertyCache.get(keyForVf(file));
    final Pair<SVNPropertyValue, Trinity<Long, Long, Long>> cachedValue =
        cachedMap == null ? null : cachedMap.get(propName);

    final File ioFile = new File(file.getPath());
    final Trinity<Long, Long, Long> tsTrinity =
        getTimestampForPropertiesChange(ioFile, file.isDirectory());

    if (cachedValue != null) {
      // zero means that a file was not found
      if (trinitiesEqual(cachedValue.getSecond(), tsTrinity)) {
        return cachedValue.getFirst();
      }
    }

    final SVNPropertyData value =
        createWCClient().doGetProperty(ioFile, propName, SVNRevision.WORKING, SVNRevision.WORKING);
    final SVNPropertyValue propValue = value == null ? null : value.getValue();

    if (cachedMap == null) {
      cachedMap = new HashMap<String, Pair<SVNPropertyValue, Trinity<Long, Long, Long>>>();
      myPropertyCache.put(keyForVf(file), cachedMap);
    }

    cachedMap.put(
        propName, new Pair<SVNPropertyValue, Trinity<Long, Long, Long>>(propValue, tsTrinity));

    return propValue;
  }
Example #8
0
 public static void addLibraryChildren(
     final LibraryOrSdkOrderEntry entry,
     final List<AbstractTreeNode> children,
     Project project,
     ProjectViewNode node) {
   final PsiManager psiManager = PsiManager.getInstance(project);
   VirtualFile[] files =
       entry instanceof LibraryOrderEntry
           ? getLibraryRoots((LibraryOrderEntry) entry)
           : entry.getRootFiles(OrderRootType.CLASSES);
   for (final VirtualFile file : files) {
     if (!file.isValid()) continue;
     if (file.isDirectory()) {
       final PsiDirectory psiDir = psiManager.findDirectory(file);
       if (psiDir == null) {
         continue;
       }
       children.add(new PsiDirectoryNode(project, psiDir, node.getSettings()));
     } else {
       final PsiFile psiFile = psiManager.findFile(file);
       if (psiFile == null) continue;
       children.add(new PsiFileNode(project, psiFile, node.getSettings()));
     }
   }
 }
  private void createNodesGroupedByDirectory(
      CheckedTreeNode root, final List<? extends DetectedFrameworkDescription> frameworks) {
    Map<VirtualFile, FrameworkDirectoryNode> nodes = new HashMap<>();
    List<DetectedFrameworkNode> externalNodes = new ArrayList<>();
    for (DetectedFrameworkDescription framework : frameworks) {
      VirtualFile parent = VfsUtil.getCommonAncestor(framework.getRelatedFiles());
      if (parent != null && !parent.isDirectory()) {
        parent = parent.getParent();
      }

      final DetectedFrameworkNode frameworkNode = new DetectedFrameworkNode(framework, myContext);
      if (parent != null) {
        createDirectoryNodes(parent, nodes).add(frameworkNode);
      } else {
        externalNodes.add(frameworkNode);
      }
    }
    List<FrameworkDirectoryNode> rootDirs = new ArrayList<>();
    for (FrameworkDirectoryNode directoryNode : nodes.values()) {
      if (directoryNode.getParent() == null) {
        rootDirs.add(directoryNode);
      }
    }
    for (FrameworkDirectoryNode dir : rootDirs) {
      root.add(collapseDirectoryNode(dir));
    }
    for (DetectedFrameworkNode node : externalNodes) {
      root.add(node);
    }
  }
Example #10
0
  /**
   * Collects all files which are located in the passed directory.
   *
   * @throws IllegalArgumentException if <code>dir</code> isn't a directory.
   */
  public static void collectFiles(
      final VirtualFile dir,
      final List<VirtualFile> files,
      final boolean recursive,
      final boolean addDirectories) {
    if (!dir.isDirectory()) {
      throw new IllegalArgumentException(
          VcsBundle.message("exception.text.file.should.be.directory", dir.getPresentableUrl()));
    }

    final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    VfsUtilCore.visitChildrenRecursively(
        dir,
        new VirtualFileVisitor() {
          @Override
          public boolean visitFile(@NotNull VirtualFile file) {
            if (file.isDirectory()) {
              if (addDirectories) {
                files.add(file);
              }
              if (!recursive && !Comparing.equal(file, dir)) {
                return false;
              }
            } else if (fileTypeManager == null || file.getFileType() != FileTypes.UNKNOWN) {
              files.add(file);
            }
            return true;
          }
        });
  }
  private void refreshFiles(final Project project) {
    final List<VirtualFile> toRefreshFiles = new ArrayList<VirtualFile>();
    final List<VirtualFile> toRefreshDirs = new ArrayList<VirtualFile>();
    for (VirtualFile file : myFilesToRefresh) {
      if (file == null) continue;
      if (file.isDirectory()) {
        toRefreshDirs.add(file);
      } else {
        toRefreshFiles.add(file);
      }
    }
    // if refresh asynchronously, local changes would also be notified that they are dirty
    // asynchronously,
    // and commit could be executed while not all changes are visible
    filterOutInvalid(myFilesToRefresh);
    RefreshQueue.getInstance()
        .refresh(
            true,
            true,
            new Runnable() {
              public void run() {
                if (project.isDisposed()) return;
                filterOutInvalid(toRefreshFiles);
                filterOutInvalid(toRefreshDirs);

                final VcsDirtyScopeManager vcsDirtyScopeManager =
                    VcsDirtyScopeManager.getInstance(project);
                vcsDirtyScopeManager.filesDirty(toRefreshFiles, toRefreshDirs);
              }
            },
            myFilesToRefresh);
    myFilesToRefresh.clear();
  }
 @NotNull
 private Trinity<String[], VirtualFile[], VirtualFile[]> cacheThings() {
   Trinity<String[], VirtualFile[], VirtualFile[]> result;
   if (myList.isEmpty()) {
     result = EMPTY;
   } else {
     VirtualFilePointer[] vf = myList.toArray(new VirtualFilePointer[myList.size()]);
     List<VirtualFile> cachedFiles = new ArrayList<VirtualFile>(vf.length);
     List<String> cachedUrls = new ArrayList<String>(vf.length);
     List<VirtualFile> cachedDirectories = new ArrayList<VirtualFile>(vf.length / 3);
     boolean allFilesAreDirs = true;
     for (VirtualFilePointer v : vf) {
       VirtualFile file = v.getFile();
       String url = v.getUrl();
       cachedUrls.add(url);
       if (file != null) {
         cachedFiles.add(file);
         if (file.isDirectory()) {
           cachedDirectories.add(file);
         } else {
           allFilesAreDirs = false;
         }
       }
     }
     VirtualFile[] directories = VfsUtilCore.toVirtualFileArray(cachedDirectories);
     VirtualFile[] files =
         allFilesAreDirs ? directories : VfsUtilCore.toVirtualFileArray(cachedFiles);
     String[] urlsArray = ArrayUtil.toStringArray(cachedUrls);
     result = Trinity.create(urlsArray, files, directories);
   }
   myCachedThings = result;
   myTimeStampOfCachedThings = myVirtualFilePointerManager.getModificationCount();
   return result;
 }
Example #13
0
  @Nullable
  public static VirtualFile findGitDir(@NotNull VirtualFile rootDir) {
    VirtualFile child = rootDir.findChild(DOT_GIT);
    if (child == null) {
      return null;
    }
    if (child.isDirectory()) {
      return child;
    }

    // this is standard for submodules, although probably it can
    String content;
    try {
      content = readFile(child);
    } catch (IOException e) {
      throw new RuntimeException("Couldn't read " + child, e);
    }
    String pathToDir;
    String prefix = "gitdir:";
    if (content.startsWith(prefix)) {
      pathToDir = content.substring(prefix.length()).trim();
    } else {
      pathToDir = content;
    }

    if (!FileUtil.isAbsolute(pathToDir)) {
      String canonicalPath = FileUtil.toCanonicalPath(FileUtil.join(rootDir.getPath(), pathToDir));
      if (canonicalPath == null) {
        return null;
      }
      pathToDir = FileUtil.toSystemIndependentName(canonicalPath);
    }
    return VcsUtil.getVirtualFileWithRefresh(new File(pathToDir));
  }
 @Override
 public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
   if (!super.isFileVisible(file, showHiddenFiles)) {
     return false;
   }
   return file.isDirectory() || GradleConstants.DEFAULT_SCRIPT_NAME.equals(file.getName());
 }
  @NotNull
  private static DartLibInfo collectPackagesLibraryRoots(
      @NotNull final Project project, @NotNull final DartSdk sdk) {
    final DartLibInfo libInfo = new DartLibInfo(false);

    final Collection<VirtualFile> pubspecYamlFiles =
        FilenameIndex.getVirtualFilesByName(
            project, PUBSPEC_YAML, GlobalSearchScope.projectScope(project));
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();

    for (VirtualFile pubspecFile : pubspecYamlFiles) {
      final VirtualFile dotPackagesFile =
          pubspecFile.getParent().findChild(DotPackagesFileUtil.DOT_PACKAGES);
      final Module module =
          dotPackagesFile == null ? null : fileIndex.getModuleForFile(dotPackagesFile);

      if (dotPackagesFile != null
          && !dotPackagesFile.isDirectory()
          && module != null
          && DartSdkGlobalLibUtil.isDartSdkEnabled(module)) {
        final Map<String, String> packagesMap = DotPackagesFileUtil.getPackagesMap(dotPackagesFile);
        if (packagesMap != null) {
          for (Map.Entry<String, String> entry : packagesMap.entrySet()) {
            final String packageName = entry.getKey();
            final String packagePath = entry.getValue();
            if (isPathOutsideProjectContent(fileIndex, packagePath)) {
              libInfo.addPackage(packageName, packagePath);
            }
          }
        }
      }
    }

    return libInfo;
  }
 public boolean isLibraryClassFile(@NotNull VirtualFile file) {
   if (file.isDirectory()) return false;
   if (myFileTypeRegistry.isFileIgnored(file)) return false;
   VirtualFile parent = file.getParent();
   DirectoryInfo parentInfo = getInfoForDirectory(parent);
   return parentInfo != null && parentInfo.libraryClassRoot != null;
 }
 @NotNull
 private static Collection<VirtualFile> gatherIncludeRoots(
     Collection<VirtualFile> goPathSourcesRoots, Set<VirtualFile> excludeRoots) {
   Collection<VirtualFile> includeRoots = ContainerUtil.newHashSet();
   for (VirtualFile goPathSourcesDirectory : goPathSourcesRoots) {
     ProgressIndicatorProvider.checkCanceled();
     boolean excludedRootIsAncestor = false;
     for (VirtualFile excludeRoot : excludeRoots) {
       ProgressIndicatorProvider.checkCanceled();
       if (VfsUtilCore.isAncestor(excludeRoot, goPathSourcesDirectory, false)) {
         excludedRootIsAncestor = true;
         break;
       }
     }
     if (excludedRootIsAncestor) {
       continue;
     }
     for (VirtualFile file : goPathSourcesDirectory.getChildren()) {
       ProgressIndicatorProvider.checkCanceled();
       if (file.isDirectory() && !excludeRoots.contains(file)) {
         includeRoots.add(file);
       }
     }
   }
   return includeRoots;
 }
Example #18
0
 public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
   final boolean isVisible = super.isFileVisible(file, showHiddenFiles);
   if (!isVisible || file.isDirectory()) {
     return isVisible;
   }
   return StdFileTypes.IDEA_MODULE.equals(FileTypeManager.getInstance().getFileTypeByFile(file));
 }
Example #19
0
 private static void retainOnlyJarsAndDirectories(List<VirtualFile> woSdk) {
   for (Iterator<VirtualFile> iterator = woSdk.iterator(); iterator.hasNext(); ) {
     VirtualFile file = iterator.next();
     final VirtualFile local = ArchiveVfsUtil.getVirtualFileForJar(file);
     final boolean dir = file.isDirectory();
     final String name = file.getName();
     if (LOG.isDebugEnabled()) {
       LOG.debug(
           "Considering: "
               + file.getPath()
               + "; local="
               + local
               + "; dir="
               + dir
               + "; name="
               + name);
     }
     if (dir || local != null) {
       continue;
     }
     if (name.endsWith(".jar")) {
       continue;
     }
     LOG.debug("Removing");
     iterator.remove();
   }
 }
 public VirtualFile getContentRootForFile(@NotNull VirtualFile file) {
   VirtualFile dir = file.isDirectory() ? file : file.getParent();
   if (dir == null) return null;
   final DirectoryInfo info = getInfoForDirectory(dir);
   if (info == null) return null;
   return info.contentRoot;
 }
  private void initLivePackageNameToDirMap() {
    final VirtualFile baseDir = myPubspecYamlFile == null ? null : myPubspecYamlFile.getParent();
    if (myPubspecYamlFile == null || baseDir == null) return;

    final String name = PubspecYamlUtil.getDartProjectName(myPubspecYamlFile);
    final VirtualFile libFolder = baseDir.findChild(PubspecYamlUtil.LIB_DIR_NAME);

    if (name != null && libFolder != null && libFolder.isDirectory()) {
      myLivePackageNameToDirMap.put(name, libFolder);
    }

    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();

    PubspecYamlUtil.processPathPackages(
        myPubspecYamlFile,
        new PairConsumer<String, VirtualFile>() {
          @Override
          public void consume(
              @NotNull final String packageName, @NotNull final VirtualFile packageDir) {
            if (fileIndex.isInContent(packageDir)) {
              myLivePackageNameToDirMap.put(packageName, packageDir);
            }
          }
        });
  }
Example #22
0
  public void update(AnActionEvent e) {
    super.update(e);

    final Project project = e.getData(DataKeys.PROJECT);
    final VirtualFile file = e.getData(DataKeys.VIRTUAL_FILE);

    boolean visible =
        project != null
            && file != null
            && !file.isDirectory()
            && file.getFileType() == CppSupportLoader.CPP_FILETYPE
            && !Communicator.isHeaderFile(file);
    boolean enabled = visible;

    if (!visible) {
      visible = ActionPlaces.MAIN_MENU.equals(e.getPlace());
    }

    e.getPresentation().setEnabled(enabled);
    e.getPresentation().setVisible(visible);

    if (visible) {
      final String s =
          "Do c&ompile for " + (file != null ? file.getName() : "selected c/c++ fileToCompile");
      e.getPresentation().setText(s);
      e.getPresentation().setDescription(s);
    }
  }
  public boolean move(VirtualFile file, VirtualFile toDir) throws IOException {
    File srcFile = getIOFile(file);
    File dstFile = new File(getIOFile(toDir), file.getName());

    final SvnVcs vcs = getVCS(toDir);
    final SvnVcs sourceVcs = getVCS(file);
    if (vcs == null && sourceVcs == null) return false;

    if (vcs == null) {
      return false;
    }

    FileDocumentManager.getInstance().saveAllDocuments();
    if (sourceVcs == null) {
      return createItem(toDir, file.getName(), file.isDirectory(), true);
    }

    if (isPendingAdd(vcs.getProject(), toDir)) {

      myMovedFiles.add(new MovedFileInfo(sourceVcs.getProject(), srcFile, dstFile));
      return true;
    } else {
      final VirtualFile oldParent = file.getParent();
      myFilesToRefresh.add(oldParent);
      myFilesToRefresh.add(toDir);
      return doMove(sourceVcs, srcFile, dstFile);
    }
  }
Example #24
0
 public static boolean iterateRecursively(
     @Nullable final VirtualFile root, @NotNull final ContentIterator processor) {
   if (root != null) {
     if (root.isDirectory()) {
       for (VirtualFile file : root.getChildren()) {
         if (file.isDirectory()) {
           if (!iterateRecursively(file, processor)) return false;
         } else {
           if (!processor.processFile(file)) return false;
         }
       }
     } else {
       if (!processor.processFile(root)) return false;
     }
   }
   return true;
 }
 @NotNull
 public List<OrderEntry> getOrderEntriesForFile(@NotNull VirtualFile file) {
   VirtualFile dir = file.isDirectory() ? file : file.getParent();
   if (dir == null) return Collections.emptyList();
   final DirectoryInfo info = getInfoForDirectory(dir);
   if (info == null) return Collections.emptyList();
   return Collections.unmodifiableList(info.getOrderEntries());
 }
 public Module getModuleForFile(@NotNull VirtualFile file) {
   if (file instanceof VirtualFileWindow) file = ((VirtualFileWindow) file).getDelegate();
   VirtualFile dir = file.isDirectory() ? file : file.getParent();
   if (dir == null) return null;
   DirectoryInfo info = getInfoForDirectory(dir);
   if (info == null) return null;
   return info.module;
 }
 private void processFileOrDirectoryChange(final VirtualFile file) {
   if (!ProjectFileIndex.SERVICE.getInstance(myProject).isInContent(file)) return;
   if (!file.isDirectory()) {
     processFileChange(file);
   } else {
     processDirectoryChange(file);
   }
 }
 @Nullable
 public final <T extends DomElement> DomFileElementImpl<T> getFileElement(XmlFile file) {
   if (file == null) return null;
   if (!(file.getFileType() instanceof DomSupportEnabled)) return null;
   final VirtualFile virtualFile = file.getVirtualFile();
   if (virtualFile != null && virtualFile.isDirectory()) return null;
   return this.<T>getOrCreateCachedValueProvider(file).getFileElement();
 }
Example #29
0
 @NotNull
 public static String fileOrFolder(@NotNull VirtualFile file) {
   if (file.isDirectory()) {
     return "Folder";
   } else {
     return "File";
   }
 }
 public static boolean isSupportedFileType(@NotNull VirtualFile virtualFile) {
   if (virtualFile.isDirectory()) return true;
   if (virtualFile.getFileType() == StdFileTypes.JAVA) return true;
   if (virtualFile.getFileType() == StdFileTypes.XML
       && !ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) return true;
   if ("groovy".equals(virtualFile.getExtension())) return true;
   return false;
 }