Idea 138: Add custom kotlin search for kotlin properties
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<root>
|
||||
<item
|
||||
name='com.intellij.psi.impl.search.CustomPropertyScopeProvider com.intellij.psi.search.SearchScope getScope(com.intellij.openapi.project.Project)'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item
|
||||
name='com.intellij.psi.impl.search.CustomPropertyScopeProvider com.intellij.psi.search.SearchScope getScope(com.intellij.openapi.project.Project) 0'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
@@ -387,6 +387,7 @@
|
||||
<definitionsScopedSearch implementation="org.jetbrains.jet.plugin.search.ideaExtensions.KotlinDefinitionsSearcher"/>
|
||||
<annotatedElementsSearch implementation="org.jetbrains.jet.plugin.search.ideaExtensions.KotlinAnnotatedElementsSearcher"/>
|
||||
<methodReferencesSearch implementation="org.jetbrains.jet.plugin.search.ideaExtensions.KotlinLightMethodUsagesSearcher"/>
|
||||
<methodReferencesSearch implementation="org.jetbrains.jet.plugin.search.ideaExtensions.KotlinLightPropertyAccessorsReferenceSearcher"/>
|
||||
|
||||
<exceptionFilter implementation="org.jetbrains.jet.plugin.filters.JetExceptionFilterFactory" order="first"/>
|
||||
|
||||
|
||||
+2
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.hierarchy.calls;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.ide.hierarchy.HierarchyNodeDescriptor;
|
||||
import com.intellij.ide.hierarchy.call.CallerMethodsTreeStructure;
|
||||
import com.intellij.openapi.application.ReadActionProcessor;
|
||||
@@ -105,8 +106,7 @@ public abstract class KotlinCallerMethodsTreeStructure extends KotlinCallTreeStr
|
||||
PsiElement element = getTargetElement(descriptor);
|
||||
|
||||
SearchScope searchScope = getSearchScope(scopeType, basePsiClass);
|
||||
Map<PsiElement, HierarchyNodeDescriptor> methodToDescriptorMap =
|
||||
new HashMap<PsiElement, HierarchyNodeDescriptor>();
|
||||
Map<PsiElement, HierarchyNodeDescriptor> methodToDescriptorMap = Maps.newHashMap();
|
||||
|
||||
Object[] javaCallers = null;
|
||||
if (element instanceof PsiMethod) {
|
||||
|
||||
+1
-3
@@ -32,9 +32,7 @@ public class KotlinLightMethodTextOccurrenceProcessor extends MethodTextOccurren
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean processInexactReference(
|
||||
PsiReference ref, PsiElement refElement, PsiMethod method, Processor<PsiReference> consumer
|
||||
) {
|
||||
protected boolean processInexactReference(PsiReference ref, PsiElement refElement, PsiMethod method, Processor<PsiReference> consumer) {
|
||||
if (refElement instanceof JetNamedFunction) {
|
||||
PsiMethod lightMethod = LightClassUtil.getLightClassMethod((JetNamedFunction) refElement);
|
||||
if (lightMethod != null) return super.processInexactReference(ref, lightMethod, method, consumer);
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.ideaExtensions
|
||||
|
||||
import com.intellij.openapi.application.QueryExecutorBase
|
||||
import com.intellij.psi.PsiReference
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import com.intellij.psi.search.UsageSearchContext
|
||||
import com.intellij.psi.search.searches.MethodReferencesSearch
|
||||
import com.intellij.util.Processor
|
||||
import org.jetbrains.jet.plugin.JetFileType
|
||||
import org.jetbrains.jet.asJava.namedUnwrappedElement
|
||||
import org.jetbrains.jet.lang.psi.JetProperty
|
||||
|
||||
public class KotlinLightPropertyAccessorsReferenceSearcher() : QueryExecutorBase<PsiReference, MethodReferencesSearch.SearchParameters>(true) {
|
||||
override fun processQuery(queryParameters: MethodReferencesSearch.SearchParameters, consumer: Processor<PsiReference>) {
|
||||
val method = queryParameters.getMethod()
|
||||
val unwrapped = method.namedUnwrappedElement
|
||||
|
||||
if (unwrapped !is JetProperty) return
|
||||
|
||||
val propertyName = unwrapped.getName()
|
||||
if (propertyName == null) return
|
||||
|
||||
val onlyKotlinFiles = restrictToKotlinSources(queryParameters.getScope())
|
||||
|
||||
queryParameters.getOptimizer()!!.searchWord(
|
||||
propertyName,
|
||||
onlyKotlinFiles,
|
||||
UsageSearchContext.IN_CODE,
|
||||
true,
|
||||
method)
|
||||
}
|
||||
|
||||
private fun restrictToKotlinSources(originalScope: SearchScope): SearchScope {
|
||||
if (originalScope is GlobalSearchScope) {
|
||||
return GlobalSearchScope.getScopeRestrictedByFileTypes((originalScope as GlobalSearchScope), JetFileType.INSTANCE)
|
||||
}
|
||||
return originalScope
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public object UsagesSearch: QueryFactory<PsiReference, UsagesSearchRequest>() {
|
||||
fun UsagesSearchRequest.search(): Query<PsiReference> = UsagesSearch.search(this)
|
||||
|
||||
fun <A: PsiElement, B: PsiElement> UsagesSearchTarget<A>.retarget(element: B) =
|
||||
UsagesSearchTarget<B>(element, scope, location, restrictByTargetScope)
|
||||
UsagesSearchTarget(element, scope, location, restrictByTargetScope)
|
||||
|
||||
val <T: PsiElement> UsagesSearchTarget<T>.effectiveScope: SearchScope
|
||||
get() = if (restrictByTargetScope) scope and element.effectiveScope else scope
|
||||
|
||||
Reference in New Issue
Block a user