boolean (@NotNull TestLocationDescriptor candidate, @NotNull TestLocationDescriptor current, @NotNull PsiClass psiClass) { final String className = psiClass.getQualifiedName(); if (className == null) { return false; } boolean candidateMatched; boolean currentMatched; // By package. int lastDotIndex = className.lastIndexOf("."); String candidateLcDir = StringUtil.toLowerCase(candidate.pathPrefix); String currentLcDir = StringUtil.toLowerCase(current.pathPrefix); if (lastDotIndex >= 0) { String packageAsPath = StringUtil.toLowerCase(className.substring(0, lastDotIndex).replace('.', '/')); candidateMatched = candidateLcDir.contains(packageAsPath); currentMatched = currentLcDir.contains(packageAsPath); if (candidateMatched ^ currentMatched) { return candidateMatched; } } // By class name. String simpleName = getSimpleClassName(psiClass); if (simpleName == null) { return false; } String pattern = StringUtil.toLowerCase(simpleName); candidateMatched = candidateLcDir.contains(pattern); currentMatched = currentLcDir.contains(pattern); if (candidateMatched ^ currentMatched) { return candidateMatched; } // By class name words and their position. More words + greater position = better. String[] words = NameUtil.nameToWords(simpleName); int candidateWordsMatched = 0; int currentWordsMatched = 0; int candidateMatchPosition = -1; int currentMatchPosition = -1; StringBuilder currentNameSubstringSb = new StringBuilder(); for (int i = 0; i < words.length; i++) { currentNameSubstringSb.append(words[i]); String currentNameLcSubstring = StringUtil.toLowerCase(currentNameSubstringSb.toString()); int candidateWordsIndex = candidateLcDir.lastIndexOf(currentNameLcSubstring); if (candidateWordsIndex > 0) { candidateWordsMatched = i + 1; candidateMatchPosition = candidateWordsIndex; } int currentWordsIndex = currentLcDir.lastIndexOf(currentNameLcSubstring); if (currentWordsIndex > 0) { currentWordsMatched = i + 1; currentMatchPosition = currentWordsIndex; } if (candidateWordsMatched != currentWordsMatched) { break; // no need to continue } } if (candidateWordsMatched != currentWordsMatched) { return candidateWordsMatched > currentWordsMatched; } return candidateMatchPosition > currentMatchPosition; }