Find Usages: Support text-file search of Kotlin declarations
This commit is contained in:
+2
@@ -72,4 +72,6 @@ class DelegatingFindMemberUsagesHandler(
|
|||||||
}
|
}
|
||||||
return handler.processElementUsages(element, processor, handlerOptions)
|
return handler.processElementUsages(element, processor, handlerOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isSearchForTextOccurencesAvailable(psiElement: PsiElement, isSingleFile: Boolean): Boolean = !isSingleFile
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-4
@@ -37,6 +37,10 @@ import org.jetbrains.jet.plugin.findUsages.toClassHelper
|
|||||||
import org.jetbrains.jet.plugin.findUsages.toClassDeclarationsHelper
|
import org.jetbrains.jet.plugin.findUsages.toClassDeclarationsHelper
|
||||||
import org.jetbrains.jet.plugin.search.usagesSearch.search
|
import org.jetbrains.jet.plugin.search.usagesSearch.search
|
||||||
import org.jetbrains.jet.plugin.util.application.runReadAction
|
import org.jetbrains.jet.plugin.util.application.runReadAction
|
||||||
|
import org.jetbrains.jet.asJava.namedUnwrappedElement
|
||||||
|
import java.util.Collections
|
||||||
|
import com.intellij.find.findUsages.JavaFindUsagesHandler
|
||||||
|
import com.intellij.find.findUsages.JavaFindUsagesHandlerFactory
|
||||||
|
|
||||||
public class KotlinFindClassUsagesHandler(
|
public class KotlinFindClassUsagesHandler(
|
||||||
jetClass: JetClassOrObject,
|
jetClass: JetClassOrObject,
|
||||||
@@ -84,11 +88,26 @@ public class KotlinFindClassUsagesHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override fun isSearchForTextOccurencesAvailable(psiElement: PsiElement, isSingleFile: Boolean): Boolean {
|
protected override fun getStringsToSearch(element: PsiElement): Collection<String> {
|
||||||
if (isSingleFile)
|
val psiClass = when (element) {
|
||||||
return false
|
is PsiClass -> element
|
||||||
|
is JetClassOrObject -> LightClassUtil.getPsiClass(getElement())
|
||||||
|
else -> null
|
||||||
|
} ?: return Collections.emptyList()
|
||||||
|
|
||||||
return psiElement is JetClassOrObject
|
// Work around the protected method in JavaFindUsagesHandler
|
||||||
|
// todo: Use JavaFindUsagesHelper.getElementNames() when it becomes public in IDEA
|
||||||
|
var stringsToSearch: Collection<String>
|
||||||
|
object: JavaFindUsagesHandler(psiClass, JavaFindUsagesHandlerFactory.getInstance(element.getProject())) {
|
||||||
|
{
|
||||||
|
stringsToSearch = getStringsToSearch(psiClass)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stringsToSearch
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override fun isSearchForTextOccurencesAvailable(psiElement: PsiElement, isSingleFile: Boolean): Boolean {
|
||||||
|
return !isSingleFile
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun getFindUsagesOptions(dataContext: DataContext?): FindUsagesOptions {
|
public override fun getFindUsagesOptions(dataContext: DataContext?): FindUsagesOptions {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetClass
|
||||||
|
// OPTIONS: textOccurrences
|
||||||
|
package test
|
||||||
|
|
||||||
|
class <caret>Foo {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
test.Foo
|
||||||
|
Foo
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Unclassified usage (1: 1) test.Foo
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetNamedFunction
|
||||||
|
// OPTIONS: textOccurrences
|
||||||
|
package test
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
fun <caret>foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Function foo is defined in class Foo
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Unclassified usage (1: 10) Function foo is defined in class Foo
|
||||||
@@ -231,6 +231,11 @@ public abstract class AbstractJetFindUsagesTest extends JetLightCodeInsightFixtu
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (s.equals("textOccurrences")) {
|
||||||
|
options.isSearchForTextOccurrences = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,7 +309,7 @@ public abstract class AbstractJetFindUsagesTest extends JetLightCodeInsightFixtu
|
|||||||
if (!name.startsWith(prefix) || name.equals(mainFileName)) return false;
|
if (!name.startsWith(prefix) || name.equals(mainFileName)) return false;
|
||||||
|
|
||||||
String ext = name.substring(name.lastIndexOf('.') + 1);
|
String ext = name.substring(name.lastIndexOf('.') + 1);
|
||||||
return ext.equals("kt") || ext.equals("java") || ext.equals("xml");
|
return ext.equals("kt") || ext.equals("java") || ext.equals("xml") || ext.equals("text");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -141,6 +141,12 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/kotlin/findClassUsages"), Pattern.compile("^(.+)\\.0\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/kotlin/findClassUsages"), Pattern.compile("^(.+)\\.0\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("classUsedInPlainText.0.kt")
|
||||||
|
public void testClassUsedInPlainText() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findClassUsages/classUsedInPlainText.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("classUsedInTextAsRef.0.kt")
|
@TestMetadata("classUsedInTextAsRef.0.kt")
|
||||||
public void testClassUsedInTextAsRef() throws Exception {
|
public void testClassUsedInTextAsRef() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findClassUsages/classUsedInTextAsRef.0.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findClassUsages/classUsedInTextAsRef.0.kt");
|
||||||
@@ -456,6 +462,12 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("functionUsedInPlainText.0.kt")
|
||||||
|
public void testFunctionUsedInPlainText() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findFunctionUsages/functionUsedInPlainText.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("javaAndKotlinOverrides.0.kt")
|
@TestMetadata("javaAndKotlinOverrides.0.kt")
|
||||||
public void testJavaAndKotlinOverrides() throws Exception {
|
public void testJavaAndKotlinOverrides() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findFunctionUsages/javaAndKotlinOverrides.0.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findFunctionUsages/javaAndKotlinOverrides.0.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user