Build stubs for local functions; show them in Goto Symbol

#KT-14161 Fixed
This commit is contained in:
Dmitry Jemerov
2017-05-16 17:52:08 +02:00
parent f72dd75127
commit 4dd3f30f2d
8 changed files with 42 additions and 16 deletions
@@ -23,12 +23,12 @@ object KotlinStubVersions {
// Though only kotlin declarations (no code in the bodies) are stubbed, please do increase this version
// if you are not 100% sure it can be avoided.
// Increasing this version will lead to reindexing of all kotlin source files on the first IDE startup with the new version.
const val SOURCE_STUB_VERSION = 122
const val SOURCE_STUB_VERSION = 123
// Binary stub version should be increased if stub format (org.jetbrains.kotlin.psi.stubs.impl) is changed
// or changes are made to the core stub building code (org.jetbrains.kotlin.idea.decompiler.stubBuilder).
// Increasing this version will lead to reindexing of all binary files that are potentially kotlin binaries (including all class files).
private const val BINARY_STUB_VERSION = 59
private const val BINARY_STUB_VERSION = 60
// Classfile stub version should be increased if changes are made to classfile stub building subsystem (org.jetbrains.kotlin.idea.decompiler.classFile)
// Increasing this version will lead to reindexing of all classfiles.
@@ -87,12 +87,9 @@ public abstract class KtStubElementType<StubT extends StubElement, PsiT extends
@Override
public boolean shouldCreateStub(ASTNode node) {
PsiElement psi = node.getPsi();
if (psi instanceof KtClassOrObject) {
if (psi instanceof KtClassOrObject || psi instanceof KtFunction) {
return true;
}
if (psi instanceof KtFunction) {
return !((KtFunction) psi).isLocal();
}
if (psi instanceof KtProperty) {
return !((KtProperty) psi).isLocal();
}
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.Iconable
import org.jetbrains.kotlin.idea.KotlinIconProvider
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
open class KotlinDefaultNamedDeclarationPresentation(private val declaration: KtNamedDeclaration) : ColoredItemPresentation {
@@ -38,6 +39,10 @@ open class KotlinDefaultNamedDeclarationPresentation(private val declaration: Kt
override fun getPresentableText() = declaration.name
override fun getLocationString(): String? {
if (declaration is KtFunction && declaration.isLocal) {
val containingDeclaration = declaration.getStrictParentOfType<KtDeclaration>() ?: return null
return "(in ${containingDeclaration.name})"
}
val name = declaration.fqName ?: return null
val qualifiedContainer = name.parent().toString()
val parent = declaration.parent
+8
View File
@@ -0,0 +1,8 @@
fun main(args: Array<String>) {
fun myFoo() {
}
}
// SEARCH_TEXT: myFoo
// REF: (in main).myFoo()
+1 -1
View File
@@ -5,4 +5,4 @@ val tl = <caret>topLevel()
// CONTEXT: return <ref-caret>local()
// WITH_LIBRARY: /resolve/referenceInLib/inLibrarySource
// REF: local()
// REF: (in inlibrary.test.topLevel).local()
@@ -3,3 +3,11 @@ PsiJetFileStubImpl[package=]
IMPORT_LIST
FUN[fqName=foo, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=true, name=foo]
VALUE_PARAMETER_LIST
FUN[fqName=null, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=innerFoo]
MODIFIER_LIST[]
ANNOTATION_ENTRY[hasValueArguments=false, shortName=Deprecated]
CONSTRUCTOR_CALLEE
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION[referencedName=Deprecated]
VALUE_PARAMETER_LIST
+11 -9
View File
@@ -5,14 +5,16 @@ PsiJetFileStubImpl[package=]
CLASS[fqName=T, isEnumEntry=false, isInterface=true, isLocal=false, isTopLevel=true, name=T, superNames=[]]
FUN[fqName=foo, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=true, name=foo]
VALUE_PARAMETER_LIST
CLASS[fqName=null, isEnumEntry=false, isInterface=false, isLocal=true, isTopLevel=false, name=Test, superNames=[A, T]]
SUPER_TYPE_LIST
SUPER_TYPE_CALL_ENTRY
CONSTRUCTOR_CALLEE
FUN[fqName=null, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=bar]
VALUE_PARAMETER_LIST
CLASS[fqName=null, isEnumEntry=false, isInterface=false, isLocal=true, isTopLevel=false, name=Test, superNames=[A, T]]
SUPER_TYPE_LIST
SUPER_TYPE_CALL_ENTRY
CONSTRUCTOR_CALLEE
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION[referencedName=A]
SUPER_TYPE_ENTRY
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION[referencedName=A]
SUPER_TYPE_ENTRY
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION[referencedName=T]
REFERENCE_EXPRESSION[referencedName=T]
@@ -143,6 +143,12 @@ public class KotlinGotoTestGenerated extends AbstractKotlinGotoTest {
doSymbolTest(fileName);
}
@TestMetadata("localFunction.kt")
public void testLocalFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSymbol/localFunction.kt");
doSymbolTest(fileName);
}
@TestMetadata("privateTopLevelDeclarations.kt")
public void testPrivateTopLevelDeclarations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSymbol/privateTopLevelDeclarations.kt");