PsiDirectory (PsiElement[] elements) { PsiDirectory result = null; for (PsiElement element : elements) { PsiDirectory directory; if (element instanceof PsiDirectory) { directory = (PsiDirectory)element; directory = directory.getParentDirectory(); } else if (element instanceof PsiFile) { directory = PlatformPackageUtil.getDirectory(element); } else { throw new IllegalArgumentException("unexpected element " + element); } if (directory == null) continue; if (result == null) { result = directory; } else { if (PsiTreeUtil.isAncestor(directory, result, true)) { result = directory; } } } return result; }