From 075541da21211f7d05657e7b49c4e4e4d1398985 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 12 Jan 2018 12:26:30 +0100 Subject: [PATCH] Show location info for members defined in object literals #KT-22179 Fixed --- .../presentation/DeclarationPresenters.kt | 45 ++++++++++--------- .../resolve/references/ValueParameter.kt | 2 +- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/presentation/DeclarationPresenters.kt b/idea/src/org/jetbrains/kotlin/idea/presentation/DeclarationPresenters.kt index bb752f6f45a..83b89086771 100644 --- a/idea/src/org/jetbrains/kotlin/idea/presentation/DeclarationPresenters.kt +++ b/idea/src/org/jetbrains/kotlin/idea/presentation/DeclarationPresenters.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.presentation @@ -44,15 +33,20 @@ open class KotlinDefaultNamedDeclarationPresentation(private val declaration: Kt val containerName = containingDeclaration.fqName ?: containingDeclaration.name return "(in $containerName)" } - val name = declaration.fqName ?: return null - val qualifiedContainer = name.parent().toString() + + val name = declaration.fqName val parent = declaration.parent - val containerText = if (parent is KtFile && declaration.hasModifier(KtTokens.PRIVATE_KEYWORD)) { - "${parent.name} in $qualifiedContainer" - } - else { - qualifiedContainer + val containerText = if (name != null) { + val qualifiedContainer = name.parent().toString() + if (parent is KtFile && declaration.hasModifier(KtTokens.PRIVATE_KEYWORD)) { + "${parent.name} in $qualifiedContainer" + } else { + qualifiedContainer + } + } else { + getNameForContainingObjectLiteral() ?: return null } + val receiverTypeRef = (declaration as? KtCallableDeclaration)?.receiverTypeReference return when { receiverTypeRef != null -> "(for " + receiverTypeRef.text + " in " + containerText + ")" @@ -61,8 +55,15 @@ open class KotlinDefaultNamedDeclarationPresentation(private val declaration: Kt } } - override fun getIcon(unused: Boolean) - = KotlinIconProvider.INSTANCE.getIcon(declaration, Iconable.ICON_FLAG_VISIBILITY or Iconable.ICON_FLAG_READ_STATUS) + private fun getNameForContainingObjectLiteral(): String? { + val objectLiteral = declaration.getStrictParentOfType() ?: return null + val container = objectLiteral.getStrictParentOfType() ?: return null + val containerFqName = container.fqName?.asString() ?: return null + return "object in $containerFqName" + } + + override fun getIcon(unused: Boolean) = + KotlinIconProvider.INSTANCE.getIcon(declaration, Iconable.ICON_FLAG_VISIBILITY or Iconable.ICON_FLAG_READ_STATUS) } class KtDefaultDeclarationPresenter : ItemPresentationProvider { diff --git a/idea/testData/resolve/references/ValueParameter.kt b/idea/testData/resolve/references/ValueParameter.kt index dce9d88589a..c4ac7927962 100644 --- a/idea/testData/resolve/references/ValueParameter.kt +++ b/idea/testData/resolve/references/ValueParameter.kt @@ -6,4 +6,4 @@ val prop = object : B() { } } -// REF: x +// REF: (in object in prop).x