ModuleInfo (@NotNull File directory) { File file = new File(directory, PsiJavaModule.MODULE_INFO_FILE); @NlsSafe final String name = file.getName(); myProgress.setText2(name); try { String text = FileUtil.loadFile(file); PsiFileFactory factory = PsiFileFactory.getInstance(ProjectManager.getInstance().getDefaultProject()); ModuleInfo moduleInfo = ReadAction.compute(() -> { PsiFile psiFile = factory.createFileFromText(PsiJavaModule.MODULE_INFO_FILE, JavaFileType.INSTANCE, text); PsiJavaModule javaModule = psiFile instanceof PsiJavaFile ? ((PsiJavaFile)psiFile).getModuleDeclaration() : null; if (javaModule == null) { throw new IncorrectOperationException("Incorrect module declaration '" + file.getPath() + "'"); } ModuleInfo info = new ModuleInfo(javaModule.getName()); javaModule.accept(new ModuleInfoVisitor(info)); return info; }); File moduleDirectory = directory; while (!isEntryPointRoot(moduleDirectory) && !moduleInfo.name.equals(moduleDirectory.getName())) { File parent = moduleDirectory.getParentFile(); if (parent == null) break; moduleDirectory = parent; } moduleInfo.directory = moduleDirectory; return moduleInfo; } catch (IOException | IncorrectOperationException e) { LOG.info(e); return null; } }