/** * Here we check if a given file belongs to our plugin. We take this road because we need the * actual file and not a filename to check files without extension. * * <p>A file is checked according to the rules defined in the facet settings. A file can be set to * ignored, accepted or auto. Auto means that the content is checked. * * @param file The file to check * @return True if BashSupport wants to take that file */ public boolean isMyFileType(VirtualFile file) { if (file == null) { return false; } if (file.isDirectory()) { return false; } if (extensionList.contains(file.getExtension())) { return true; } else if (!file.isInLocalFileSystem()) { return false; } else if (StringUtils.isEmpty(file.getExtension())) { BashFacet facet = null; try { // no extensions, special checks (looking at the content, etc) // guess project Project project = ProjectUtil.guessProjectForFile(file); if (project == null) { return false; } DumbServiceImpl dumbService = DumbServiceImpl.getInstance(project); if (dumbService == null || dumbService.isDumb()) { return false; } DirectoryIndex directoryIndex = DirectoryIndex.getInstance(project); if (directoryIndex == null || !directoryIndex.isInitialized()) { return false; } Module module = ModuleUtil.findModuleForFile(file, project); if (module == null) { return false; } facet = BashFacet.getInstance(module); if (facet == null) { return false; } BashFacetConfiguration config = facet.getConfiguration(); FileMode mode = config.findMode(file); if (mode == FileMode.accept()) { return true; } else if (mode == FileMode.ignore()) { return false; } else if (mode == FileMode.auto()) { return BashContentUtil.isProbablyBashFile( VfsUtil.virtualToIoFile(file), MIN_FILE_PROBABILIY, ProjectUtil.guessProjectForFile(file)); } } catch (Exception e) { // ignore this LOG.warn("Could not check the file type due to exception", e); } } return false; }