PsiJavaFile (final VirtualFile dirFile, @Nullable String className) { if (className != null) { final VirtualFile classFile = dirFile.findChild(StringUtil.getQualifiedName(className, StdFileTypes.CLASS.getDefaultExtension())); if (classFile != null) { final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(classFile); if (psiFile instanceof PsiJavaFile) { return (PsiJavaFile)psiFile; } } } final VirtualFile[] children = dirFile.getChildren(); for (VirtualFile child : children) { if (FileTypeRegistry.getInstance().isFileOfType(child, StdFileTypes.CLASS) && child.isValid()) { final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(child); if (psiFile instanceof PsiJavaFile) { return (PsiJavaFile)psiFile; } } } return null; }