mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
IJPL-156752 JavaEditorTabTitleProvider - implement async API
GitOrigin-RevId: da30728bd1a0c4ba39f7722698eaed7941315d80
This commit is contained in:
committed by
intellij-monorepo-bot
parent
658e90aa5e
commit
84c22b420d
@@ -2,6 +2,8 @@
|
||||
package com.intellij.ui
|
||||
|
||||
import com.intellij.openapi.application.ReadAction
|
||||
import com.intellij.openapi.application.readAction
|
||||
import com.intellij.openapi.components.serviceAsync
|
||||
import com.intellij.openapi.fileEditor.impl.EditorTabTitleProvider
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
@@ -10,20 +12,29 @@ import com.intellij.psi.PsiJavaModule
|
||||
import com.intellij.psi.PsiManager
|
||||
|
||||
private class JavaEditorTabTitleProvider : EditorTabTitleProvider {
|
||||
override suspend fun getEditorTabTitleAsync(project: Project, file: VirtualFile): String? {
|
||||
val fileName = file.name
|
||||
if (PsiJavaModule.MODULE_INFO_FILE != fileName) {
|
||||
return null
|
||||
}
|
||||
|
||||
val psiManager = project.serviceAsync<PsiManager>()
|
||||
return readAction {
|
||||
val moduleDescriptor = (psiManager.findFile(file) as? PsiJavaFile)?.moduleDeclaration ?: return@readAction null
|
||||
"$fileName (${moduleDescriptor.name})"
|
||||
}
|
||||
}
|
||||
|
||||
override fun getEditorTabTitle(project: Project, file: VirtualFile): String? {
|
||||
val fileName = file.name
|
||||
if (PsiJavaModule.MODULE_INFO_FILE != fileName) {
|
||||
return null
|
||||
}
|
||||
|
||||
val psiManager = PsiManager.getInstance(project)
|
||||
return ReadAction.compute<String, RuntimeException> {
|
||||
val obj: Any? = PsiManager.getInstance(project).findFile(file)
|
||||
val javaFile = if (obj is PsiJavaFile) obj else null
|
||||
val moduleDescriptor = javaFile?.moduleDeclaration
|
||||
if (moduleDescriptor == null) {
|
||||
return@compute null
|
||||
}
|
||||
fileName + " (" + moduleDescriptor.name + ")"
|
||||
val moduleDescriptor = (psiManager.findFile(file) as? PsiJavaFile)?.moduleDeclaration ?: return@compute null
|
||||
"$fileName (${moduleDescriptor.name})"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user