Making KotlinAnnotatedElementsSearcher able to search for parameters (KT-27794)
This commit is contained in:
+6
-3
@@ -57,14 +57,17 @@ open class KtLightMethodImpl protected constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun buildParametersForList(): List<PsiParameter> =
|
protected open fun buildParametersForList(): List<PsiParameter> {
|
||||||
clsDelegate.parameterList.parameters.mapIndexed { index, clsParameter ->
|
val clsParameters by lazyPub { clsDelegate.parameterList.parameters }
|
||||||
|
return (dummyDelegate?.parameterList?.parameters ?: clsParameters).mapIndexed { index, dummyParameter ->
|
||||||
KtLightParameter(
|
KtLightParameter(
|
||||||
clsParameter,
|
dummyParameter,
|
||||||
|
{ clsParameters.getOrNull(index) },
|
||||||
index,
|
index,
|
||||||
this@KtLightMethodImpl
|
this@KtLightMethodImpl
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val typeParamsList: PsiTypeParameterList? by lazyPub { buildTypeParameterList() }
|
private val typeParamsList: PsiTypeParameterList? by lazyPub { buildTypeParameterList() }
|
||||||
|
|
||||||
|
|||||||
+13
-4
@@ -23,12 +23,21 @@ import org.jetbrains.kotlin.psi.KtPropertyAccessor
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
|
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
|
||||||
|
|
||||||
class KtLightParameter(
|
class KtLightParameter(
|
||||||
override val clsDelegate: PsiParameter,
|
private val dummyDelegate: PsiParameter,
|
||||||
private val index: Int,
|
private val clsDelegateProvider: () -> PsiParameter?,
|
||||||
method: KtLightMethod
|
private val index: Int,
|
||||||
) : LightParameter(clsDelegate.name ?: "p$index", clsDelegate.type, method, KotlinLanguage.INSTANCE),
|
method: KtLightMethod
|
||||||
|
) : LightParameter(dummyDelegate.name ?: "p$index", dummyDelegate.type, method, KotlinLanguage.INSTANCE),
|
||||||
KtLightDeclaration<KtParameter, PsiParameter> {
|
KtLightDeclaration<KtParameter, PsiParameter> {
|
||||||
|
|
||||||
|
private val lazyDelegate by lazyPub { clsDelegateProvider() ?: dummyDelegate }
|
||||||
|
|
||||||
|
override val clsDelegate: PsiParameter get() = lazyDelegate
|
||||||
|
|
||||||
|
override fun getType(): PsiType = lazyDelegate.type
|
||||||
|
|
||||||
|
override fun getName(): String = dummyDelegate.name ?: lazyDelegate.name ?: super.getName()
|
||||||
|
|
||||||
private val lightModifierList by lazyPub { KtLightSimpleModifierList(this, emptySet()) }
|
private val lightModifierList by lazyPub { KtLightSimpleModifierList(this, emptySet()) }
|
||||||
|
|
||||||
private var lightIdentifier: KtLightIdentifier? = null
|
private var lightIdentifier: KtLightIdentifier? = null
|
||||||
|
|||||||
+8
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.asJava.ImpreciseResolveResult.NO_MATCH
|
|||||||
import org.jetbrains.kotlin.asJava.ImpreciseResolveResult.UNSURE
|
import org.jetbrains.kotlin.asJava.ImpreciseResolveResult.UNSURE
|
||||||
import org.jetbrains.kotlin.asJava.LightClassUtil
|
import org.jetbrains.kotlin.asJava.LightClassUtil
|
||||||
import org.jetbrains.kotlin.asJava.toLightClass
|
import org.jetbrains.kotlin.asJava.toLightClass
|
||||||
|
import org.jetbrains.kotlin.asJava.toPsiParameters
|
||||||
import org.jetbrains.kotlin.compatibility.ExecutorProcessor
|
import org.jetbrains.kotlin.compatibility.ExecutorProcessor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.search.PsiBasedClassResolver
|
import org.jetbrains.kotlin.idea.search.PsiBasedClassResolver
|
||||||
@@ -64,6 +65,13 @@ class KotlinAnnotatedElementsSearcher : QueryExecutor<PsiModifierListOwner, Anno
|
|||||||
|
|
||||||
LightClassUtil.getLightClassPropertyMethods(declaration).all { consumer.process(it) }
|
LightClassUtil.getLightClassPropertyMethods(declaration).all { consumer.process(it) }
|
||||||
}
|
}
|
||||||
|
is KtParameter -> {
|
||||||
|
if (!declaration.toPsiParameters().all { consumer.process(it) }) return@processAnnotatedMembers false
|
||||||
|
LightClassUtil.getLightClassBackingField(declaration)?.let {
|
||||||
|
if (!consumer.process(it)) return@processAnnotatedMembers false
|
||||||
|
}
|
||||||
|
LightClassUtil.getLightClassPropertyMethods(declaration).all { consumer.process(it) }
|
||||||
|
}
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
data class TestClass1(@java.lang.Deprecated val pctorfield: Int) {
|
||||||
|
constructor(@java.lang.Deprecated param: Int, param2: String) : this(param)
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestClass2(
|
||||||
|
@param:java.lang.Deprecated val deprecatedParamField: Int,
|
||||||
|
@field:java.lang.Deprecated val deprecatedField: Int,
|
||||||
|
@java.lang.Deprecated constructorParam: Int
|
||||||
|
) {
|
||||||
|
fun foo(@java.lang.Deprecated functionParam) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ANNOTATION: java.lang.Deprecated
|
||||||
|
// SEARCH: field:deprecatedField
|
||||||
|
// SEARCH: field:deprecatedParamField
|
||||||
|
// SEARCH: field:pctorfield
|
||||||
|
// SEARCH: method:component1
|
||||||
|
// SEARCH: method:getDeprecatedField
|
||||||
|
// SEARCH: method:getDeprecatedParamField
|
||||||
|
// SEARCH: method:getPctorfield
|
||||||
|
// SEARCH: param:constructorParam
|
||||||
|
// SEARCH: param:deprecatedField
|
||||||
|
// SEARCH: param:deprecatedParamField
|
||||||
|
// SEARCH: param:pctorfield
|
||||||
|
// SEARCH: param:functionParam
|
||||||
|
// SEARCH: param:param
|
||||||
@@ -6,10 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.search;
|
package org.jetbrains.kotlin.search;
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.psi.JavaPsiFacade;
|
import com.intellij.psi.*;
|
||||||
import com.intellij.psi.PsiClass;
|
|
||||||
import com.intellij.psi.PsiField;
|
|
||||||
import com.intellij.psi.PsiMethod;
|
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||||
import com.intellij.testFramework.LightProjectDescriptor;
|
import com.intellij.testFramework.LightProjectDescriptor;
|
||||||
@@ -98,6 +95,9 @@ public abstract class AbstractSearcherTest extends LightCodeInsightFixtureTestCa
|
|||||||
if (member instanceof PsiField) {
|
if (member instanceof PsiField) {
|
||||||
return "field:" + ((PsiField) member).getName();
|
return "field:" + ((PsiField) member).getName();
|
||||||
}
|
}
|
||||||
|
if (member instanceof PsiParameter) {
|
||||||
|
return "param:" + ((PsiParameter) member).getName();
|
||||||
|
}
|
||||||
throw new IllegalStateException("Do not know how to render member of type: " + member.getClass().getName());
|
throw new IllegalStateException("Do not know how to render member of type: " + member.getClass().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,9 @@
|
|||||||
package org.jetbrains.kotlin.search
|
package org.jetbrains.kotlin.search
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
|
import com.intellij.psi.PsiModifierListOwner
|
||||||
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub
|
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub
|
||||||
import com.intellij.psi.search.searches.AnnotatedMembersSearch
|
import com.intellij.psi.search.searches.AnnotatedElementsSearch
|
||||||
import com.intellij.testFramework.LightProjectDescriptor
|
import com.intellij.testFramework.LightProjectDescriptor
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.asJava.builder.LightClassConstructionContext
|
import org.jetbrains.kotlin.asJava.builder.LightClassConstructionContext
|
||||||
@@ -40,7 +41,14 @@ abstract class AbstractAnnotatedMembersSearchTest : AbstractSearcherTest() {
|
|||||||
PsiBasedClassResolver.trueHits.set(0)
|
PsiBasedClassResolver.trueHits.set(0)
|
||||||
PsiBasedClassResolver.falseHits.set(0)
|
PsiBasedClassResolver.falseHits.set(0)
|
||||||
|
|
||||||
AbstractSearcherTest.checkResult(path, AnnotatedMembersSearch.search(psiClass, projectScope))
|
AbstractSearcherTest.checkResult(
|
||||||
|
path,
|
||||||
|
AnnotatedElementsSearch.searchElements(
|
||||||
|
psiClass,
|
||||||
|
projectScope,
|
||||||
|
PsiModifierListOwner::class.java
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
val optimizedTrue = InTextDirectivesUtils.getPrefixedInt(fileText, "// OPTIMIZED_TRUE:")
|
val optimizedTrue = InTextDirectivesUtils.getPrefixedInt(fileText, "// OPTIMIZED_TRUE:")
|
||||||
if (optimizedTrue != null) {
|
if (optimizedTrue != null) {
|
||||||
|
|||||||
+5
@@ -54,6 +54,11 @@ public class AnnotatedMembersSearchTestGenerated extends AbstractAnnotatedMember
|
|||||||
runTest("idea/testData/search/annotations/testAnnotationsOnFunction.kt");
|
runTest("idea/testData/search/annotations/testAnnotationsOnFunction.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("testAnnotationsOnPropertiesAndParameters.kt")
|
||||||
|
public void testTestAnnotationsOnPropertiesAndParameters() throws Exception {
|
||||||
|
runTest("idea/testData/search/annotations/testAnnotationsOnPropertiesAndParameters.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("testAnnotationsWithParameters.kt")
|
@TestMetadata("testAnnotationsWithParameters.kt")
|
||||||
public void testTestAnnotationsWithParameters() throws Exception {
|
public void testTestAnnotationsWithParameters() throws Exception {
|
||||||
runTest("idea/testData/search/annotations/testAnnotationsWithParameters.kt");
|
runTest("idea/testData/search/annotations/testAnnotationsWithParameters.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user