Filter usages in import directives
This commit is contained in:
+8
-7
@@ -24,8 +24,9 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ReadActionProcessor;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.search.PsiElementProcessor;
|
||||
import com.intellij.psi.search.PsiElementProcessorAdapter;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
@@ -35,7 +36,10 @@ import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.asJava.LightClassUtil;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.plugin.findUsages.FindUsagesUtils;
|
||||
import org.jetbrains.jet.plugin.findUsages.KotlinFindUsagesHandlerFactory;
|
||||
import org.jetbrains.jet.plugin.findUsages.dialogs.KotlinFindClassUsagesDialog;
|
||||
@@ -80,10 +84,7 @@ public class KotlinFindClassUsagesHandler extends KotlinFindUsagesHandler<JetCla
|
||||
if ((constructorUsage && !kotlinOptions.searchConstructorUsages)
|
||||
|| (!constructorUsage && !kotlinOptions.isUsages)) continue;
|
||||
|
||||
TextRange rangeInElement = ref.getRangeInElement();
|
||||
processor.process(
|
||||
new UsageInfo(ref.getElement(), rangeInElement.getStartOffset(), rangeInElement.getEndOffset(), false)
|
||||
);
|
||||
processUsage(processor, ref, kotlinOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetClass
|
||||
// OPTIONS: usages, constructorUsages, skipImports
|
||||
package server
|
||||
|
||||
open class <caret>Server {
|
||||
open fun work() {
|
||||
println("Server")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package client
|
||||
|
||||
import server.Server
|
||||
|
||||
class Client(): Server() {
|
||||
override fun work() {
|
||||
super<Server>.work()
|
||||
println("Client")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Super type qualifier (7: 15) super<Server>.work()
|
||||
Supertype (5: 17) class Client(): Server() {
|
||||
@@ -0,0 +1,6 @@
|
||||
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetNamedFunction
|
||||
// OPTIONS: usages, skipImports
|
||||
package server;
|
||||
|
||||
fun <caret>processRequest() = "foo"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package client
|
||||
|
||||
import server.processRequest
|
||||
|
||||
class Client {
|
||||
val methodRef = ::processRequest()
|
||||
|
||||
fun doProcessRequest() {
|
||||
println("Process...")
|
||||
processRequest()
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
Callable reference (6: 23) val methodRef = ::processRequest()
|
||||
Function call (10: 9) processRequest()
|
||||
@@ -24,6 +24,7 @@ import com.google.common.collect.Ordering;
|
||||
import com.intellij.find.FindManager;
|
||||
import com.intellij.find.findUsages.FindUsagesHandler;
|
||||
import com.intellij.find.findUsages.FindUsagesOptions;
|
||||
import com.intellij.find.findUsages.JavaFindUsagesOptions;
|
||||
import com.intellij.find.impl.FindManagerImpl;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -68,10 +69,9 @@ public abstract class AbstractJetFindUsagesTest extends LightCodeInsightFixtureT
|
||||
options.isUsages = false;
|
||||
options.searchConstructorUsages = false;
|
||||
for (String s : InTextDirectivesUtils.findListWithPrefixes(text, "// OPTIONS: ")) {
|
||||
if (s.equals("usages")) {
|
||||
options.isUsages = true;
|
||||
}
|
||||
else if (s.equals("constructorUsages")) {
|
||||
if (parseCommonOptions(options, s)) continue;
|
||||
|
||||
if (s.equals("constructorUsages")) {
|
||||
options.searchConstructorUsages = true;
|
||||
}
|
||||
else if (s.equals("derivedInterfaces")) {
|
||||
@@ -99,10 +99,9 @@ public abstract class AbstractJetFindUsagesTest extends LightCodeInsightFixtureT
|
||||
KotlinMethodFindUsagesOptions options = new KotlinMethodFindUsagesOptions(project);
|
||||
options.isUsages = false;
|
||||
for (String s : InTextDirectivesUtils.findListWithPrefixes(text, "// OPTIONS: ")) {
|
||||
if (s.equals("usages")) {
|
||||
options.isUsages = true;
|
||||
}
|
||||
else if (s.equals("overrides")) {
|
||||
if (parseCommonOptions(options, s)) continue;
|
||||
|
||||
if (s.equals("overrides")) {
|
||||
options.isOverridingMethods = true;
|
||||
options.isImplementingMethods = true;
|
||||
}
|
||||
@@ -117,6 +116,20 @@ public abstract class AbstractJetFindUsagesTest extends LightCodeInsightFixtureT
|
||||
}
|
||||
};
|
||||
|
||||
protected static boolean parseCommonOptions(JavaFindUsagesOptions options, String s) {
|
||||
if (s.equals("usages")) {
|
||||
options.isUsages = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (s.equals("skipImports")) {
|
||||
options.isSkipImportStatements = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract FindUsagesOptions parse(@NotNull String text, @NotNull Project project);
|
||||
|
||||
@@ -172,7 +185,7 @@ public abstract class AbstractJetFindUsagesTest extends LightCodeInsightFixtureT
|
||||
File[] extraFiles = rootDir.listFiles(
|
||||
new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
public boolean accept(@NotNull File dir, @NotNull String name) {
|
||||
if (!name.startsWith(prefix) || name.equals(mainFileName)) return false;
|
||||
|
||||
String ext = name.substring(name.lastIndexOf('.') + 1);
|
||||
|
||||
@@ -113,6 +113,11 @@ public class JetFindUsagesTest extends AbstractJetFindUsagesTest {
|
||||
doTest("idea/testData/findUsages/findClassUsages/kotlinClassAllUsages3.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinClassAllUsagesNoImport.0.kt")
|
||||
public void testKotlinClassAllUsagesNoImport() throws Exception {
|
||||
doTest("idea/testData/findUsages/findClassUsages/kotlinClassAllUsagesNoImport.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinClassConstructorUsages.0.kt")
|
||||
public void testKotlinClassConstructorUsages() throws Exception {
|
||||
doTest("idea/testData/findUsages/findClassUsages/kotlinClassConstructorUsages.0.kt");
|
||||
@@ -226,6 +231,11 @@ public class JetFindUsagesTest extends AbstractJetFindUsagesTest {
|
||||
doTest("idea/testData/findUsages/findMethodUsages/kotlinTopLevelMethodUsages.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinTopLevelMethodUsagesNoImport.0.kt")
|
||||
public void testKotlinTopLevelMethodUsagesNoImport() throws Exception {
|
||||
doTest("idea/testData/findUsages/findMethodUsages/kotlinTopLevelMethodUsagesNoImport.0.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/findObjectUsages")
|
||||
|
||||
Reference in New Issue
Block a user