Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #25 #26

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import com.intellij.navigation.ItemPresentation
import com.intellij.navigation.NavigationItem
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.Computable
import com.intellij.pom.Navigatable
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMethod
import java.util.concurrent.atomic.AtomicReference

class RequestMappingItem(val psiElement: PsiElement, private val urlPath: String, private val requestMethod: String) : NavigationItem {
class RequestMappingItem(val psiElement: PsiElement, private val urlPath: String, private val requestMethod: String) :
NavigationItem {

private val navigationElement = psiElement.navigationElement as? Navigatable

Expand All @@ -33,13 +34,16 @@ class RequestMappingItem(val psiElement: PsiElement, private val urlPath: String
override fun getPresentableText() = [email protected] + " " + [email protected]

override fun getLocationString(): String {
val psiElement = [email protected]
val fileName = psiElement.containingFile?.name
return when (psiElement) {
is PsiMethod -> (psiElement.containingClass?.name ?: fileName ?: "unknownFile") + "." + psiElement.name + getPresentModuleName()
is PsiClass -> psiElement.name ?: fileName ?: "unknownFile" + getPresentModuleName()
else -> "unknownLocation"
}

return ApplicationManager.getApplication().runReadAction(Computable {
val psiElement = [email protected]
val fileName = psiElement.containingFile?.name
when (psiElement) {
is PsiMethod -> (psiElement.containingClass?.name ?: fileName ?: "unknownFile") + "." + psiElement.name + getPresentModuleName()
is PsiClass -> psiElement.name ?: fileName ?: "unknownFile" + getPresentModuleName()
else -> "unknownLocation"
}
})
}

override fun getIcon(b: Boolean) = RequestMapperIcons.SEARCH
Expand All @@ -54,16 +58,13 @@ class RequestMappingItem(val psiElement: PsiElement, private val urlPath: String
}

private fun getModuleName(): String {
val result: AtomicReference<String> = AtomicReference()

ApplicationManager.getApplication().runReadAction {
return ApplicationManager.getApplication().runReadAction(Computable {
val element = [email protected]
val file = element.containingFile.originalFile.virtualFile
val module = ProjectRootManager.getInstance(element.project).fileIndex.getModuleForFile(file)
result.set(module?.name ?: "")
}

return result.get()
module?.name ?: ""
})
}
}
}
Loading