Introduce utility functions for operations on search scopes
This commit is contained in:
+6
-2
@@ -49,6 +49,11 @@ import com.intellij.refactoring.util.TextOccurrencesUtil
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.plugin.refactoring.move.PackageNameInfo
|
||||
import org.jetbrains.jet.plugin.refactoring.move.updateInternalReferencesOnPackageNameChange
|
||||
import org.jetbrains.jet.plugin.search.projectScope
|
||||
import org.jetbrains.jet.plugin.search.fileScope
|
||||
import org.jetbrains.jet.plugin.search.not
|
||||
import org.jetbrains.jet.plugin.search.and
|
||||
import org.jetbrains.jet.plugin.search.minus
|
||||
|
||||
public class MoveKotlinFileHandler : MoveFileHandler() {
|
||||
class object {
|
||||
@@ -108,8 +113,7 @@ public class MoveKotlinFileHandler : MoveFileHandler() {
|
||||
val project = psiFile.getProject()
|
||||
val newPackageName = newParent.getPackage()?.getQualifiedName() ?: ""
|
||||
|
||||
val searchScope = GlobalSearchScope.projectScope(project) intersectWith
|
||||
GlobalSearchScope.notScope(GlobalSearchScope.fileScope(psiFile))
|
||||
val searchScope = project.projectScope() - psiFile.fileScope()
|
||||
return psiFile.getDeclarations().flatMap { declaration ->
|
||||
val name = (declaration as? JetNamedDeclaration)?.getName()
|
||||
if (name != null) {
|
||||
|
||||
+2
-1
@@ -71,6 +71,7 @@ import com.intellij.util.VisibilityUtil
|
||||
import com.intellij.openapi.util.Ref
|
||||
import org.jetbrains.jet.plugin.refactoring.getKotlinFqName
|
||||
import org.jetbrains.jet.plugin.references.JetSimpleNameReference.ShorteningMode
|
||||
import org.jetbrains.jet.plugin.search.projectScope
|
||||
|
||||
public class MoveKotlinTopLevelDeclarationsOptions(
|
||||
val elementsToMove: Collection<JetNamedDeclaration>,
|
||||
@@ -107,7 +108,7 @@ public class MoveKotlinTopLevelDeclarationsProcessor(project: Project, val optio
|
||||
val newFqName = StringUtil.getQualifiedName(newPackageName, lightElement.getName())
|
||||
|
||||
val foundReferences = HashSet<PsiReference>()
|
||||
val projectScope = GlobalSearchScope.projectScope(lightElement.getProject())
|
||||
val projectScope = lightElement.getProject().projectScope()
|
||||
val results = ReferencesSearch
|
||||
.search(lightElement, projectScope, false)
|
||||
.mapTo(ArrayList<UsageInfo?>()) { ref ->
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.jetbrains.jet.asJava.*
|
||||
import org.jetbrains.jet.lang.psi.JetElement
|
||||
import org.jetbrains.jet.utils.keysToMap
|
||||
import com.intellij.psi.PsiMethod
|
||||
import org.jetbrains.jet.plugin.search.allScope
|
||||
|
||||
public trait JetReference : PsiPolyVariantReference {
|
||||
public fun resolveToDescriptors(): Collection<DeclarationDescriptor>
|
||||
@@ -120,7 +121,7 @@ abstract class AbstractJetReference<T : JetElement>(element: T)
|
||||
val psiFacade = JavaPsiFacade.getInstance(project)
|
||||
val fqName = (targetDescriptor as PackageViewDescriptor).getFqName().asString()
|
||||
ContainerUtil.addIfNotNull(result, psiFacade.findPackage(fqName))
|
||||
ContainerUtil.addIfNotNull(result, psiFacade.findClass(fqName, GlobalSearchScope.allScope(project)))
|
||||
ContainerUtil.addIfNotNull(result, psiFacade.findClass(fqName, project.allScope()))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.intellij.psi.search.searches.DirectClassInheritorsSearch
|
||||
import com.intellij.util.EmptyQuery
|
||||
import com.intellij.util.MergeQuery
|
||||
import org.jetbrains.jet.asJava.toLightMethods
|
||||
import org.jetbrains.jet.plugin.search.allScope
|
||||
|
||||
fun PsiElement.isOverridableElement(): Boolean = when (this) {
|
||||
is PsiMethod -> PsiUtil.canBeOverriden(this)
|
||||
@@ -70,7 +71,7 @@ public object KotlinPsiMethodOverridersSearch : HierarchySearch<PsiMethod>(PsiMe
|
||||
override fun nextElements(current: PsiClass): Iterable<PsiClass> =
|
||||
DirectClassInheritorsSearch.search(
|
||||
current,
|
||||
GlobalSearchScope.allScope(current.getProject()),
|
||||
current.getProject().allScope(),
|
||||
/* checkInheritance = */ true,
|
||||
/* includeAnonymous = */ true
|
||||
)
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@ import org.jetbrains.jet.plugin.libraries.JetSourceNavigationHelper
|
||||
import org.jetbrains.jet.plugin.stubindex.JetSuperClassIndex
|
||||
import org.jetbrains.jet.lang.resolve.*
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.plugin.search.fileScope
|
||||
|
||||
public open class KotlinDirectInheritorsSearcher() : QueryExecutorBase<PsiClass, DirectClassInheritorsSearch.SearchParameters>(true) {
|
||||
public override fun processQuery(queryParameters: DirectClassInheritorsSearch.SearchParameters, consumer: Processor<PsiClass>) {
|
||||
@@ -40,7 +41,7 @@ public open class KotlinDirectInheritorsSearcher() : QueryExecutorBase<PsiClass,
|
||||
val scope = if (originalScope is GlobalSearchScope)
|
||||
originalScope
|
||||
else
|
||||
baseClass.getContainingFile()?.let { file -> GlobalSearchScope.fileScope(file) }
|
||||
baseClass.getContainingFile()?.let { file -> file.fileScope() }
|
||||
|
||||
if (scope == null) return
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.search
|
||||
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.search.SearchScope
|
||||
|
||||
fun SearchScope.and(otherScope: SearchScope): SearchScope = intersectWith(otherScope)
|
||||
fun SearchScope.or(otherScope: SearchScope): SearchScope = union(otherScope)
|
||||
fun SearchScope.minus(otherScope: GlobalSearchScope) = this and !otherScope
|
||||
fun GlobalSearchScope.not(): GlobalSearchScope = GlobalSearchScope.notScope(this)
|
||||
|
||||
fun Project.allScope(): GlobalSearchScope = GlobalSearchScope.allScope(this)
|
||||
|
||||
fun Project.projectScope(): GlobalSearchScope = GlobalSearchScope.projectScope(this)
|
||||
|
||||
fun PsiFile.fileScope(): GlobalSearchScope = GlobalSearchScope.fileScope(this)
|
||||
@@ -46,6 +46,7 @@ import com.intellij.util.EmptyQuery
|
||||
import com.intellij.openapi.project.Project
|
||||
import java.util.ArrayDeque
|
||||
import org.jetbrains.jet.plugin.search.usagesSearch.UsagesSearchFilter.*
|
||||
import org.jetbrains.jet.plugin.search.and
|
||||
|
||||
public data class UsagesSearchLocation(
|
||||
val inCode: Boolean = true,
|
||||
@@ -152,7 +153,7 @@ fun <A: PsiElement, B: PsiElement> UsagesSearchTarget<A>.retarget(element: B) =
|
||||
UsagesSearchTarget<B>(element, scope, location, restrictByTargetScope)
|
||||
|
||||
val <T: PsiElement> UsagesSearchTarget<T>.effectiveScope: SearchScope
|
||||
get() = if (restrictByTargetScope) scope.intersectWith(element.effectiveScope) else scope
|
||||
get() = if (restrictByTargetScope) scope and element.effectiveScope else scope
|
||||
|
||||
val PsiElement.effectiveScope: SearchScope
|
||||
get() = PsiSearchHelper.SERVICE.getInstance(getProject())!!.getUseScope(this)
|
||||
|
||||
+2
-1
@@ -27,11 +27,12 @@ import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFacto
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService
|
||||
import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope
|
||||
import org.jetbrains.jet.storage.StorageManager
|
||||
import org.jetbrains.jet.plugin.search.allScope
|
||||
|
||||
public class PluginDeclarationProviderFactoryService : DeclarationProviderFactoryService() {
|
||||
|
||||
override fun create(project: Project, storageManager: StorageManager, files: Collection<JetFile>): DeclarationProviderFactory {
|
||||
val indexedSourcesScope = JetSourceFilterScope.kotlinSourcesAndLibraries(GlobalSearchScope.allScope(project))
|
||||
val indexedSourcesScope = JetSourceFilterScope.kotlinSourcesAndLibraries(project.allScope())
|
||||
val nonIndexedFiles = files.filter {
|
||||
file ->
|
||||
!file.isPhysical() || !indexedSourcesScope.contains(file.getVirtualFile()!!)
|
||||
|
||||
@@ -57,6 +57,7 @@ import org.jetbrains.jet.plugin.refactoring.move.moveTopLevelDeclarations.MoveDe
|
||||
import org.jetbrains.jet.plugin.refactoring.move.moveTopLevelDeclarations.MoveKotlinTopLevelDeclarationsOptions
|
||||
import org.jetbrains.jet.plugin.refactoring.move.moveTopLevelDeclarations.JetFileKotlinMoveTarget
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import org.jetbrains.jet.plugin.search.allScope
|
||||
|
||||
public abstract class AbstractJetMoveTest : MultiFileTestCase() {
|
||||
protected fun doTest(path: String) {
|
||||
@@ -194,7 +195,7 @@ enum class MoveAction {
|
||||
MoveClassToInnerProcessor(
|
||||
project,
|
||||
array(classToMove),
|
||||
JavaPsiFacade.getInstance(project).findClass(targetClass, GlobalSearchScope.allScope(project))!!,
|
||||
JavaPsiFacade.getInstance(project).findClass(targetClass, project.allScope())!!,
|
||||
/* searchInComments = */ false,
|
||||
/* searchInNonJavaFiles = */ true,
|
||||
/* moveCallback = */ null
|
||||
|
||||
@@ -46,6 +46,7 @@ import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe
|
||||
import org.jetbrains.jet.lang.resolve.name.isSubpackageOf
|
||||
import org.jetbrains.jet.getString
|
||||
import org.jetbrains.jet.getNullableString
|
||||
import org.jetbrains.jet.plugin.search.allScope
|
||||
|
||||
private enum class RenameType {
|
||||
JAVA_CLASS
|
||||
@@ -104,7 +105,7 @@ public abstract class AbstractRenameTest : MultiFileTestCase() {
|
||||
val newName = renameParamsObject.getString("newName")
|
||||
|
||||
doTest { rootDir, rootAfter ->
|
||||
val aClass = context.javaFacade.findClass(classFQN, GlobalSearchScope.allScope(context.project))!!
|
||||
val aClass = context.javaFacade.findClass(classFQN, context.project.allScope())!!
|
||||
val substitution = RenamePsiElementProcessor.forElement(aClass).substituteElementToRename(aClass, null)
|
||||
|
||||
RenameProcessor(context.project, substitution, newName, true, true).run()
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.module.Module
|
||||
import java.io.File
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import org.jetbrains.jet.plugin.search.allScope
|
||||
|
||||
class RunConfigurationTest: CodeInsightTestCase() {
|
||||
private val project: Project get() = myProject!!
|
||||
@@ -82,8 +83,7 @@ class RunConfigurationTest: CodeInsightTestCase() {
|
||||
}
|
||||
|
||||
private fun createConfigurationFromMain(mainFqn: String): JetRunConfiguration {
|
||||
val mainFunction = JetTopLevelFunctionsFqnNameIndex.getInstance()!!.get(
|
||||
mainFqn, project, GlobalSearchScope.allScope(project))!!.first()
|
||||
val mainFunction = JetTopLevelFunctionsFqnNameIndex.getInstance()!!.get(mainFqn, project, project.allScope())!!.first()
|
||||
|
||||
val dataContext = MapDataContext()
|
||||
dataContext.put(Location.DATA_KEY, PsiLocation(project, mainFunction))
|
||||
|
||||
Reference in New Issue
Block a user