String (Project project, String packageName, GlobalSearchScope scope) { final PsiManager manager = PsiManager.getInstance(project); String nameToMatch = packageName; while (true) { Query<VirtualFile> vFiles = getDirectoriesByPackageName(nameToMatch, false, project); PsiDirectory directory = getWritableModuleDirectory(vFiles, scope, manager); if (directory != null) return getPackageName(directory.getVirtualFile(), project); int lastDotIndex = nameToMatch.lastIndexOf('.'); if (lastDotIndex >= 0) { nameToMatch = nameToMatch.substring(0, lastDotIndex); } else { return null; } } }