Reformat: search\ideaExtensions package

This commit is contained in:
Nikolay Krasko
2018-05-30 13:48:46 +03:00
parent 6d29e14a33
commit 9fbb7c5d14
9 changed files with 70 additions and 51 deletions
@@ -34,7 +34,8 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import org.jetbrains.kotlin.idea.references.KotlinDefaultAnnotationMethodImplicitReferenceContributor.ReferenceImpl as ImplicitReference
class DefaultAnnotationMethodKotlinImplicitReferenceSearcher : QueryExecutorBase<PsiReference, MethodReferencesSearch.SearchParameters>(true) {
class DefaultAnnotationMethodKotlinImplicitReferenceSearcher :
QueryExecutorBase<PsiReference, MethodReferencesSearch.SearchParameters>(true) {
private val PsiMethod.isDefaultAnnotationMethod: Boolean
get() = PsiUtil.isAnnotationMethod(this) && name == PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME && parameterList.parametersCount == 0
@@ -72,10 +72,12 @@ class KotlinAnnotatedElementsSearcher : QueryExecutor<PsiModifierListOwner, Anno
companion object {
private val LOG = Logger.getInstance("#com.intellij.psi.impl.search.AnnotatedMembersSearcher")
fun processAnnotatedMembers(annClass: PsiClass,
useScope: SearchScope,
preFilter: (KtAnnotationEntry) -> Boolean = { true },
consumer: (KtDeclaration) -> Boolean): Boolean {
fun processAnnotatedMembers(
annClass: PsiClass,
useScope: SearchScope,
preFilter: (KtAnnotationEntry) -> Boolean = { true },
consumer: (KtDeclaration) -> Boolean
): Boolean {
assert(annClass.isAnnotationType) { "Annotation type should be passed to annotated members search" }
val psiBasedClassResolver = PsiBasedClassResolver.getInstance(annClass)
@@ -36,13 +36,12 @@ class KotlinClassesWithAnnotatedMembersSearcher : ScopedQueryExecutor<PsiClass,
val processed = hashSetOf<KtClassOrObject>()
return KotlinAnnotatedElementsSearcher.processAnnotatedMembers(queryParameters.annotationClass,
queryParameters.scope,
{ it.getNonStrictParentOfType<KtClassOrObject>() !in processed}) { declaration ->
{ it.getNonStrictParentOfType<KtClassOrObject>() !in processed }) { declaration ->
val ktClass = declaration.getNonStrictParentOfType<KtClassOrObject>()
if (ktClass != null && processed.add(ktClass)) {
val lightClass = ktClass.toLightClass()
if (lightClass != null) consumer.process(lightClass) else true
}
else
} else
true
}
}
@@ -25,11 +25,11 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.operators.OperatorReference
class KotlinConventionMethodReferencesSearcher : QueryExecutorBase<PsiReference, MethodReferencesSearch.SearchParameters>(true) {
override fun processQuery(queryParameters: MethodReferencesSearch.SearchParameters, consumer: ExecutorProcessor<PsiReference>) {
val operatorSearcher = OperatorReferenceSearcher.create(
queryParameters.method,
queryParameters.effectiveSearchScope,
consumer,
queryParameters.optimizer,
KotlinReferencesSearchOptions(acceptCallableOverrides = true)
queryParameters.method,
queryParameters.effectiveSearchScope,
consumer,
queryParameters.optimizer,
KotlinReferencesSearchOptions(acceptCallableOverrides = true)
)
operatorSearcher?.run()
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.idea.search.ideaExtensions
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMethod
import com.intellij.psi.search.GlobalSearchScope
@@ -110,21 +109,22 @@ class KotlinDefinitionsSearcher : QueryExecutor<PsiElement, DefinitionsScopedSea
return ContainerUtil.process(ClassInheritorsSearch.search(psiClass, true), consumer)
}
private fun processLightClassLocalImplementations(psiClass: KtLightClass,
searchScope: LocalSearchScope,
consumer: Processor<PsiElement>): Boolean {
private fun processLightClassLocalImplementations(
psiClass: KtLightClass,
searchScope: LocalSearchScope,
consumer: Processor<PsiElement>
): Boolean {
// workaround for IDEA optimization that uses Java PSI traversal to locate inheritors in local search scope
val virtualFiles = searchScope.scope.mapTo(HashSet()) { it.containingFile.virtualFile }
val globalScope = GlobalSearchScope.filesScope(psiClass.project, virtualFiles)
return ContainerUtil.process(ClassInheritorsSearch.search(psiClass, globalScope, true), Processor<PsiClass> { candidate ->
return ContainerUtil.process(ClassInheritorsSearch.search(psiClass, globalScope, true)) { candidate ->
val candidateOrigin = candidate.unwrapped ?: candidate
if (candidateOrigin in searchScope) {
consumer.process(candidate)
}
else {
} else {
true
}
})
}
}
private fun processFunctionImplementations(function: KtFunction, scope: SearchScope, consumer: Processor<PsiElement>): Boolean {
@@ -133,7 +133,11 @@ class KotlinDefinitionsSearcher : QueryExecutor<PsiElement, DefinitionsScopedSea
}
}
private fun processPropertyImplementations(declaration: KtNamedDeclaration, scope: SearchScope, consumer: Processor<PsiElement>): Boolean {
private fun processPropertyImplementations(
declaration: KtNamedDeclaration,
scope: SearchScope,
consumer: Processor<PsiElement>
): Boolean {
return runReadAction {
processPropertyImplementationsMethods(declaration.toPossiblyFakeLightMethods(), scope, consumer)
}
@@ -146,7 +150,11 @@ class KotlinDefinitionsSearcher : QueryExecutor<PsiElement, DefinitionsScopedSea
}
}
fun processPropertyImplementationsMethods(accessors: Iterable<PsiMethod>, scope: SearchScope, consumer: Processor<PsiElement>): Boolean {
fun processPropertyImplementationsMethods(
accessors: Iterable<PsiMethod>,
scope: SearchScope,
consumer: Processor<PsiElement>
): Boolean {
return accessors.all { method ->
method.forEachOverridingMethod(scope) { implementation ->
if (isDelegated(implementation)) return@forEachOverridingMethod true
@@ -49,11 +49,11 @@ open class KotlinDirectInheritorsSearcher : QueryExecutorBase<PsiClass, DirectCl
fun searchForTypeAliasesRecursively(typeName: String) {
ProgressManager.checkCanceled()
typeAliasIndex[typeName, project, scope].asSequence()
.map { it.name }
.filterNotNull()
.filter { it !in names }
.onEach { names.add(it) }
.forEach(::searchForTypeAliasesRecursively)
.map { it.name }
.filterNotNull()
.filter { it !in names }
.onEach { names.add(it) }
.forEach(::searchForTypeAliasesRecursively)
}
searchForTypeAliasesRecursively(name)
@@ -63,10 +63,10 @@ open class KotlinDirectInheritorsSearcher : QueryExecutorBase<PsiClass, DirectCl
names.forEach { name ->
KotlinSuperClassIndex.getInstance()
.get(name, baseClass.project, noLibrarySourceScope).asSequence()
.mapNotNull { candidate -> candidate.toLightClassWithBuiltinMapping() ?: KtFakeLightClass(candidate) }
.filter { candidate -> candidate.isInheritor(baseClass, false) }
.forEach { candidate -> consumer.process(candidate) }
.get(name, baseClass.project, noLibrarySourceScope).asSequence()
.mapNotNull { candidate -> candidate.toLightClassWithBuiltinMapping() ?: KtFakeLightClass(candidate) }
.filter { candidate -> candidate.isInheritor(baseClass, false) }
.forEach { candidate -> consumer.process(candidate) }
}
}
}
@@ -63,22 +63,29 @@ class KotlinOverridingMethodReferenceSearcher : MethodUsagesSearcher() {
val nameCandidates = getPropertyNamesCandidatesByAccessorName(Name.identifier(method.name))
for (name in nameCandidates) {
p.optimizer.searchWord(
name.asString(),
searchScope,
UsageSearchContext.IN_CODE,
true,
method,
getTextOccurrenceProcessor(arrayOf(method), containingClass, false)
name.asString(),
searchScope,
UsageSearchContext.IN_CODE,
true,
method,
getTextOccurrenceProcessor(arrayOf(method), containingClass, false)
)
}
}
}
override fun getTextOccurrenceProcessor(methods: Array<out PsiMethod>,
aClass: PsiClass,
strictSignatureSearch: Boolean): MethodTextOccurrenceProcessor {
return object: MethodTextOccurrenceProcessor(aClass, strictSignatureSearch, *methods) {
override fun processInexactReference(ref: PsiReference, refElement: PsiElement?, method: PsiMethod, consumer: ExecutorProcessor<PsiReference>): Boolean {
override fun getTextOccurrenceProcessor(
methods: Array<out PsiMethod>,
aClass: PsiClass,
strictSignatureSearch: Boolean
): MethodTextOccurrenceProcessor {
return object : MethodTextOccurrenceProcessor(aClass, strictSignatureSearch, *methods) {
override fun processInexactReference(
ref: PsiReference,
refElement: PsiElement?,
method: PsiMethod,
consumer: ExecutorProcessor<PsiReference>
): Boolean {
val isGetter = JvmAbi.isGetterName(method.name)
fun isWrongAccessorReference(): Boolean {
@@ -42,11 +42,12 @@ class KotlinPropertyAccessorsReferenceSearcher : QueryExecutorBase<PsiReference,
val propertyName = propertyName(method) ?: return
queryParameters.optimizer!!.searchWord(
propertyName,
onlyKotlinFiles,
UsageSearchContext.IN_CODE,
true,
method)
propertyName,
onlyKotlinFiles,
UsageSearchContext.IN_CODE,
true,
method
)
}
private fun propertyName(method: PsiMethod): String? {
@@ -27,7 +27,8 @@ import org.jetbrains.kotlin.compatibility.ExecutorProcessor
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtTreeVisitorVoid
data class KotlinTodoOccurrence(private val _file: PsiFile, private val _textRange: TextRange, private val _pattern: IndexPattern) : IndexPatternOccurrence {
data class KotlinTodoOccurrence(private val _file: PsiFile, private val _textRange: TextRange, private val _pattern: IndexPattern) :
IndexPatternOccurrence {
override fun getFile() = _file
override fun getPattern() = _pattern
override fun getTextRange() = _textRange
@@ -46,8 +47,8 @@ class KotlinTodoSearcher : QueryExecutorBase<IndexPatternOccurrence, IndexPatter
val cacheManager = TodoCacheManager.SERVICE.getInstance(file.project)
val patternProvider = queryParameters.patternProvider
val count = if (patternProvider != null) {
cacheManager.getTodoCount(file.virtualFile, patternProvider)}
else
cacheManager.getTodoCount(file.virtualFile, patternProvider)
} else
cacheManager.getTodoCount(file.virtualFile, pattern)
if (count == 0) return