PsiFile (@NotNull ReferenceType refType, @NotNull final String runtimeName, @NotNull final Project project, @NotNull GlobalSearchScope scope) { try { final String fileName = StringUtil.getShortName(runtimeName); PsiFile[] files = FilenameIndex.getFilesByName(project, fileName + "." + GantScriptType.DEFAULT_EXTENSION, scope); if (files.length == 0) files = FilenameIndex.getFilesByName(project, fileName + "." + GantScriptType.DEFAULT_EXTENSION, GlobalSearchScope.allScope(project)); if (files.length == 1) return files[0]; if (files.length == 0) { files = FilenameIndex.getFilesByName(project, fileName + ".groovy", scope); if (files.length == 0) files = FilenameIndex.getFilesByName(project, fileName + "." + GantScriptType.DEFAULT_EXTENSION, GlobalSearchScope.allScope(project)); PsiFile candidate = null; for (PsiFile file : files) { if (GroovyScriptUtil.isSpecificScriptFile(file, GantScriptType.INSTANCE)) { if (candidate != null) return null; candidate = file; } } return candidate; } } catch (ProcessCanceledException | IndexNotReadyException ignored) { } return null; }