From a0641431ac5e5bb33f549cda48dde4fef72d19ac Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Thu, 31 Jan 2019 15:57:26 +0300 Subject: [PATCH] [groovy] speed up constructor resolution by providing name hint --- .../plugins/groovy/lang/resolve/impl/constructors.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/impl/constructors.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/impl/constructors.kt index ce2595bc6b56..d237b3858e43 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/impl/constructors.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/impl/constructors.kt @@ -1,8 +1,9 @@ -// 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 file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.lang.resolve.impl import com.intellij.psi.* import com.intellij.psi.scope.ElementClassHint +import com.intellij.psi.scope.NameHint import com.intellij.psi.scope.ProcessorWithHints import com.intellij.util.SmartList import org.jetbrains.plugins.groovy.lang.psi.util.elementInfo @@ -28,19 +29,23 @@ private fun classConstructors(clazz: PsiClass): List { } private fun runtimeConstructors(clazz: PsiClass, place: PsiElement): List { - val processor = ConstructorProcessor() + val name = clazz.name ?: return emptyList() + val processor = ConstructorProcessor(name) val qualifierType = JavaPsiFacade.getElementFactory(clazz.project).createType(clazz) processNonCodeMembers(qualifierType, processor, place, ResolveState.initial()) return processor.candidates } -private class ConstructorProcessor : ProcessorWithHints(), GroovyResolveKind.Hint, ElementClassHint { +private class ConstructorProcessor(private val name: String) : ProcessorWithHints(), NameHint, GroovyResolveKind.Hint, ElementClassHint { init { + hint(NameHint.KEY, this) hint(GroovyResolveKind.HINT_KEY, this) hint(ElementClassHint.KEY, this) } + override fun getName(state: ResolveState): String? = name + override fun shouldProcess(kind: GroovyResolveKind): Boolean = kind == GroovyResolveKind.METHOD override fun shouldProcess(kind: ElementClassHint.DeclarationKind): Boolean = kind == ElementClassHint.DeclarationKind.METHOD