Set<String> (final Project project, final Pair<String, String> position, final String changeList, byte frameworkId) { final Set<String> patterns = new LinkedHashSet<>(); if (position != null) { collectPatterns(project, patterns, position.first, position.second, frameworkId); } final List<VirtualFile> files = getAffectedFiles(changeList, project); final PsiManager psiManager = PsiManager.getInstance(project); final TestDiscoveryIndex discoveryIndex = TestDiscoveryIndex.getInstance(project); for (final VirtualFile file : files) { ApplicationManager.getApplication().runReadAction(() -> { final PsiFile psiFile = psiManager.findFile(file); if (psiFile instanceof PsiClassOwner) { if (position != null) { final PsiClass[] classes = ((PsiClassOwner)psiFile).getClasses(); if (classes.length == 0 || TestFrameworks.detectFramework(classes[0]) == null) return; } final List<TextRange> changedTextRanges = VcsFacade.getInstance().getChangedTextRanges(project, psiFile); for (TextRange textRange : changedTextRanges) { final PsiElement start = psiFile.findElementAt(textRange.getStartOffset()); final PsiElement end = psiFile.findElementAt(textRange.getEndOffset()); final PsiElement parent = PsiTreeUtil.findCommonParent(new PsiElement[]{start, end}); final Collection<PsiMethod> methods = new ArrayList<>(PsiTreeUtil.findChildrenOfType(parent, PsiMethod.class)); final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(parent, PsiMethod.class); if (containingMethod != null) { methods.add(containingMethod); } for (PsiMethod changedMethod : methods) { final LinkedHashSet<String> detectedPatterns = position == null ? collectPatterns(changedMethod, frameworkId) : null; if (detectedPatterns != null) { patterns.addAll(detectedPatterns); } final PsiClass containingClass = changedMethod.getContainingClass(); if (containingClass != null && containingClass.getParent() == psiFile) { final String classQualifiedName = containingClass.getQualifiedName(); final String changedMethodName = changedMethod.getName(); if (classQualifiedName != null && (position == null && TestFrameworks.detectFramework(containingClass) != null || position != null && !discoveryIndex.hasTestTrace(classQualifiedName, changedMethodName, frameworkId))) { patterns.add(classQualifiedName + "," + changedMethodName); } } } } } }); } final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project); return new HashSet<>(ContainerUtil.filter(patterns, fqn -> ReadAction.compute(() -> psiFacade.findClass(StringUtil.getPackageName(fqn, ','), searchScope) != null))); }