remove empty DeclaredReferencedData instance

GitOrigin-RevId: a80a2e3dc34a7b80bceec3b0ef25b4debb7ea7e6
This commit is contained in:
Daniil Ovchinnikov
2021-04-12 12:00:16 +00:00
committed by intellij-monorepo-bot
parent dbb156c0fa
commit 24f710d6b5
3 changed files with 6 additions and 7 deletions
@@ -71,7 +71,7 @@ private fun gotoDeclarationInner(file: PsiFile, offset: Int): GTDActionData? {
}
private fun fromTargetData(file: PsiFile, offset: Int): GTDActionData? {
val (declaredData, referencedData) = declaredReferencedData(file, offset)
val (declaredData, referencedData) = declaredReferencedData(file, offset) ?: return null
val targetData = referencedData // prefer referenced because GTD follows references first
?: declaredData // offer navigation between declarations of the declared symbol
?: return null
@@ -55,7 +55,7 @@ private fun gotoDeclarationOrUsagesInner(file: PsiFile, offset: Int): GTDUAction
}
private fun fromTargetData(file: PsiFile, offset: Int): GTDUActionData? {
val (declaredData, referencedData) = declaredReferencedData(file, offset)
val (declaredData, referencedData) = declaredReferencedData(file, offset) ?: return null
return referencedData?.toGTDActionData(file.project)?.toGTDUActionData() // GTD of referenced symbols
?: (referencedData)?.let { ShowUsagesGTDUActionData(file.project, it) } // SU of referenced symbols if nowhere to navigate
?: declaredData?.let { ShowUsagesGTDUActionData(file.project, it) } // SU of declared symbols
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.ApiStatus.Experimental
@Experimental
fun targetSymbols(file: PsiFile, offset: Int): Collection<Symbol> {
val (declaredData, referencedData) = declaredReferencedData(file, offset)
?: return emptyList()
val data = referencedData
?: declaredData
?: return emptyList()
@@ -33,16 +34,14 @@ fun targetSymbols(file: PsiFile, offset: Int): Collection<Symbol> {
*/
@Experimental
fun targetDeclarationAndReferenceSymbols(file: PsiFile, offset: Int): Pair<Collection<Symbol>, Collection<Symbol>> {
val (declaredData, referencedData) = declaredReferencedData(file, offset)
val (declaredData, referencedData) = declaredReferencedData(file, offset) ?: return Pair(emptyList(), emptyList())
return (declaredData?.targets?.map { it.symbol } ?: emptyList()) to (referencedData?.targets?.map { it.symbol } ?: emptyList())
}
private val emptyData = DeclaredReferencedData(null, null)
internal fun declaredReferencedData(file: PsiFile, offset: Int): DeclaredReferencedData {
internal fun declaredReferencedData(file: PsiFile, offset: Int): DeclaredReferencedData? {
val allDeclarationsOrReferences: List<DeclarationOrReference> = declarationsOrReferences(file, offset)
if (allDeclarationsOrReferences.isEmpty()) {
return emptyData
return null
}
val withMinimalRanges: Collection<DeclarationOrReference> = chooseByRange(