Find usages test: Move test data out of code
This commit is contained in:
@@ -32,6 +32,7 @@ import org.jetbrains.jet.completion.AbstractJavaWithLibCompletionTest;
|
||||
import org.jetbrains.jet.completion.AbstractJetJSCompletionTest;
|
||||
import org.jetbrains.jet.completion.AbstractKeywordCompletionTest;
|
||||
import org.jetbrains.jet.editor.quickDoc.AbstractJetQuickDocProviderTest;
|
||||
import org.jetbrains.jet.findUsages.AbstractJetFindUsagesTest;
|
||||
import org.jetbrains.jet.jvm.compiler.*;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveDescriptorRendererTest;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest;
|
||||
@@ -430,6 +431,48 @@ public class GenerateTests {
|
||||
AbstractResolveBaseTest.class,
|
||||
testModel("idea/testData/resolve/references", "doTest")
|
||||
);
|
||||
|
||||
generateTest(
|
||||
"idea/tests/",
|
||||
"JetFindUsagesTest",
|
||||
AbstractJetFindUsagesTest.class,
|
||||
testModelWithFileName(
|
||||
"idea/testData/findUsages/findClassUsages/javaClassUsages", "Server.kt", "testFindClassJavaUsages"
|
||||
),
|
||||
testModelWithFileName(
|
||||
"idea/testData/findUsages/findClassUsages/kotlinClassUsages1", "Server.kt", "testFindClassKotlinUsages"
|
||||
),
|
||||
testModelWithFileName(
|
||||
"idea/testData/findUsages/findClassUsages/kotlinClassUsages2", "Server.kt", "testFindClassKotlinUsages"
|
||||
),
|
||||
testModelWithFileName(
|
||||
"idea/testData/findUsages/findClassUsages/kotlinClassUsages3", "Server.kt", "testFindClassKotlinUsages"
|
||||
),
|
||||
testModelWithFileName(
|
||||
"idea/testData/findUsages/findObjectUsages/javaObjectUsages", "Server.kt", "testFindObjectJavaUsages"
|
||||
),
|
||||
testModelWithFileName(
|
||||
"idea/testData/findUsages/findObjectUsages/kotlinObjectUsages", "Server.kt", "testFindObjectKotlinUsages"
|
||||
),
|
||||
testModelWithFileName(
|
||||
"idea/testData/findUsages/findMethodUsages/javaMethodUsages", "Server.kt", "testFindMethodJavaUsages"
|
||||
),
|
||||
testModelWithFileName(
|
||||
"idea/testData/findUsages/findMethodUsages/kotlinMethodUsages", "Server.kt", "testFindMethodKotlinUsages"
|
||||
),
|
||||
testModelWithFileName(
|
||||
"idea/testData/findUsages/findPropertyUsages/javaPropertyUsages", "Server.kt", "testFindPropertyJavaUsages"
|
||||
),
|
||||
testModelWithFileName(
|
||||
"idea/testData/findUsages/findPropertyUsages/kotlinPropertyUsages", "Server.kt", "testFindPropertyKotlinUsages"
|
||||
),
|
||||
testModelWithFileName(
|
||||
"idea/testData/findUsages/findWithFilteringImports", "Server.kt", "testFindWithFilteringImports"
|
||||
),
|
||||
testModelWithFileName(
|
||||
"idea/testData/findUsages/unresolvedAnnotation", "Server.kt", "testFindUsagesUnresolvedAnnotation"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static SimpleTestClassModel testModel(@NotNull String rootPath) {
|
||||
@@ -448,6 +491,10 @@ public class GenerateTests {
|
||||
return new SimpleTestClassModel(new File(rootPath), false, Pattern.compile("^(.+)$"), methodName);
|
||||
}
|
||||
|
||||
private static SimpleTestClassModel testModelWithFileName(@NotNull String rootPath, @NotNull String fileName, @NotNull String methodName) {
|
||||
return new SimpleTestClassModel(new File(rootPath), true, Pattern.compile("^(.*)" + fileName + "$"), methodName);
|
||||
}
|
||||
|
||||
private static SimpleTestClassModel testModel(
|
||||
@NotNull String rootPath,
|
||||
boolean recursive,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Field declaration (4: 13) private Server myServer;
|
||||
@@ -0,0 +1,12 @@
|
||||
Class/object property type (6: 21) var nextServer: Server? = null
|
||||
Function return types (14: 26) fun getNextServer(): Server? {
|
||||
Function return types (32: 21) fun Any.asServer(): Server? {
|
||||
Import directive (3: 15) import server.Server
|
||||
Local variable type (10: 21) val server: Server = s
|
||||
Nested class/object (7: 16) val name = Server.NAME
|
||||
Parameter type (24: 19) fun Client.bar(s: Server) {
|
||||
Parameter type (9: 16) fun foo(s: Server) {
|
||||
Super type qualifier (19: 15) super<Server>.work()
|
||||
Supertype (5: 15) class Client: Server {
|
||||
Target type of 'as' operation (33: 40) return if (this is Server) this as Server else null
|
||||
Target type of 'is' operation (33: 24) return if (this is Server) this as Server else null
|
||||
@@ -0,0 +1,2 @@
|
||||
Annotation (5: 1) X("")
|
||||
Import directive (3: 15) import server.X
|
||||
@@ -0,0 +1,4 @@
|
||||
Import directive (3: 15) import server.Data
|
||||
Type argument (9: 16) val c = Client<Data>()
|
||||
Type constraint (5: 17) class Client<T: Data, X> where X: Data {
|
||||
Type constraint (5: 35) class Client<T: Data, X> where X: Data {
|
||||
@@ -0,0 +1 @@
|
||||
Unclassified usage (6: 16) server.processRequest();
|
||||
@@ -0,0 +1,3 @@
|
||||
Callable reference (6: 23) val methodRef = ::processRequest()
|
||||
Function call (10: 9) processRequest()
|
||||
Import directive (3: 15) import server.processRequest
|
||||
@@ -0,0 +1,2 @@
|
||||
Class static member access (7: 28) println("foo = " + O.instance$.getFoo())
|
||||
Usage in import (3: 15) import server.O
|
||||
@@ -0,0 +1,3 @@
|
||||
Import directive (3: 15) import server.O
|
||||
Receiver (7: 26) println("foo = ${O.foo}")
|
||||
Value read (8: 19) val obj = O
|
||||
@@ -0,0 +1 @@
|
||||
Unclassified usage (7: 40) println("foo = " + O.instance$.getFoo())
|
||||
@@ -0,0 +1,3 @@
|
||||
Import directive (3: 15) import server.foo
|
||||
Receiver (8: 35) println("length: ${server.foo.length()}")
|
||||
Selector (7: 33) println("foo = ${server.foo}")
|
||||
@@ -0,0 +1 @@
|
||||
Instantiation (5: 9) val a = Test()
|
||||
@@ -0,0 +1 @@
|
||||
Usage in extends/implements clause (1: 29) public class Client extends Foo {}
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.findUsages;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usages.UsageInfo2UsageAdapter;
|
||||
import com.intellij.usages.impl.rules.UsageType;
|
||||
import com.intellij.usages.impl.rules.UsageTypeProvider;
|
||||
import com.intellij.usages.rules.UsageFilteringRule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclarationName;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.plugin.JetLightProjectDescriptor;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.plugin.findUsages.JetImportFilteringRule;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public abstract class AbstractJetFindUsagesTest extends LightCodeInsightFixtureTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JetLightProjectDescriptor.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.setTestDataPath(PluginTestCaseBase.getTestDataPathBase() + "/findUsages");
|
||||
}
|
||||
|
||||
public void testFindClassJavaUsages(@NotNull String path) throws Exception {
|
||||
doTestWithoutFiltering(path, true, JetClass.class);
|
||||
}
|
||||
|
||||
public void testFindClassKotlinUsages(@NotNull String path) throws Exception {
|
||||
doTestWithoutFiltering(path, false, JetClass.class);
|
||||
}
|
||||
|
||||
public void testFindUsagesUnresolvedAnnotation(@NotNull String path) throws Exception {
|
||||
doTestWithoutFiltering(path, true, JetClass.class);
|
||||
}
|
||||
|
||||
public void testFindMethodJavaUsages(@NotNull String path) throws Exception {
|
||||
doTestWithoutFiltering(path, true, JetFunction.class);
|
||||
}
|
||||
|
||||
public void testFindMethodKotlinUsages(@NotNull String path) throws Exception {
|
||||
doTestWithoutFiltering(path, false, JetFunction.class);
|
||||
}
|
||||
|
||||
public void testFindPropertyJavaUsages(@NotNull String path) throws Exception {
|
||||
doTestWithoutFiltering(path, true, JetProperty.class);
|
||||
}
|
||||
|
||||
public void testFindPropertyKotlinUsages(@NotNull String path) throws Exception {
|
||||
doTestWithoutFiltering(path, false, JetProperty.class);
|
||||
}
|
||||
|
||||
public void testFindObjectJavaUsages(@NotNull String path) throws Exception {
|
||||
doTestWithoutFiltering(path, true, JetObjectDeclarationName.class);
|
||||
}
|
||||
|
||||
public void testFindObjectKotlinUsages(@NotNull String path) throws Exception {
|
||||
doTestWithoutFiltering(path, false, JetObjectDeclarationName.class);
|
||||
}
|
||||
|
||||
public void testFindWithFilteringImports(@NotNull String path) throws Exception {
|
||||
doTest(path, false, JetClass.class, Lists.newArrayList(new JetImportFilteringRule()));
|
||||
}
|
||||
|
||||
private <T extends PsiElement> void doTestWithoutFiltering(
|
||||
String path,
|
||||
boolean searchInJava,
|
||||
Class<T> caretElementClass
|
||||
) throws Exception {
|
||||
doTest(path, searchInJava, caretElementClass, Collections.<UsageFilteringRule>emptyList());
|
||||
}
|
||||
|
||||
private <T extends PsiElement> void doTest(
|
||||
String path,
|
||||
boolean searchInJava,
|
||||
Class<T> caretElementClass,
|
||||
Collection<? extends UsageFilteringRule> filters
|
||||
) throws IOException {
|
||||
String rootPath = path.substring(0, path.lastIndexOf("/") + 1);
|
||||
|
||||
myFixture.configureByFiles(path, rootPath + "Client." + (searchInJava ? "java" : "kt"));
|
||||
T caretElement = PsiTreeUtil.getParentOfType(myFixture.getElementAtCaret(), caretElementClass, false);
|
||||
assertNotNull(String.format("Element with type '%s' wasn't found at caret position", caretElementClass), caretElement);
|
||||
|
||||
Collection<UsageInfo> usageInfos = myFixture.findUsages(caretElement);
|
||||
|
||||
Collection<UsageInfo2UsageAdapter> filteredUsages = getUsageAdapters(filters, usageInfos);
|
||||
|
||||
Function<UsageInfo2UsageAdapter, String> convertToString = new Function<UsageInfo2UsageAdapter, String>() {
|
||||
@Override
|
||||
public String apply(@Nullable UsageInfo2UsageAdapter usageAdapter) {
|
||||
assert usageAdapter != null;
|
||||
return getUsageType(usageAdapter.getElement())
|
||||
+ " " + Joiner.on("").join(Arrays.asList(usageAdapter.getPresentation().getText()));
|
||||
}
|
||||
};
|
||||
|
||||
Collection<String> finalUsages = Ordering.natural().sortedCopy(Collections2.transform(filteredUsages, convertToString));
|
||||
String expectedText = FileUtil.loadFile(new File(rootPath + "results.txt"));
|
||||
assertOrderedEquals(finalUsages, Ordering.natural().sortedCopy(StringUtil.split(expectedText, "\n")));
|
||||
}
|
||||
|
||||
private static Collection<UsageInfo2UsageAdapter> getUsageAdapters(
|
||||
final Collection<? extends UsageFilteringRule> filters,
|
||||
Collection<UsageInfo> usageInfos
|
||||
) {
|
||||
return Collections2.filter(
|
||||
Collections2.transform(usageInfos, new Function<UsageInfo, UsageInfo2UsageAdapter>() {
|
||||
@Override
|
||||
public UsageInfo2UsageAdapter apply(@Nullable UsageInfo usageInfo) {
|
||||
assert (usageInfo != null);
|
||||
|
||||
UsageInfo2UsageAdapter usageAdapter = new UsageInfo2UsageAdapter(usageInfo);
|
||||
for (UsageFilteringRule filter : filters) {
|
||||
if (!filter.isVisible(usageAdapter)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return usageAdapter;
|
||||
}
|
||||
}),
|
||||
Predicates.notNull());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static UsageType getUsageType(PsiElement element) {
|
||||
if (element == null) return null;
|
||||
|
||||
if (PsiTreeUtil.getParentOfType(element, PsiComment.class, false) != null) {
|
||||
return UsageType.COMMENT_USAGE;
|
||||
}
|
||||
|
||||
UsageTypeProvider[] providers = Extensions.getExtensions(UsageTypeProvider.EP_NAME);
|
||||
for (UsageTypeProvider provider : providers) {
|
||||
UsageType usageType = provider.getUsageType(element);
|
||||
if (usageType != null) {
|
||||
return usageType;
|
||||
}
|
||||
}
|
||||
|
||||
return UsageType.UNCLASSIFIED;
|
||||
}
|
||||
}
|
||||
@@ -16,251 +16,192 @@
|
||||
|
||||
package org.jetbrains.jet.findUsages;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usages.UsageInfo2UsageAdapter;
|
||||
import com.intellij.usages.impl.rules.UsageType;
|
||||
import com.intellij.usages.impl.rules.UsageTypeProvider;
|
||||
import com.intellij.usages.rules.UsageFilteringRule;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclarationName;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.plugin.JetLightProjectDescriptor;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.plugin.findUsages.JetImportFilteringRule;
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
public class JetFindUsagesTest extends LightCodeInsightFixtureTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JetLightProjectDescriptor.INSTANCE;
|
||||
}
|
||||
import org.jetbrains.jet.findUsages.AbstractJetFindUsagesTest;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.setTestDataPath(PluginTestCaseBase.getTestDataPathBase() + "/findUsages");
|
||||
}
|
||||
|
||||
public void testFindClassJavaUsages() {
|
||||
doTestWithoutFiltering(
|
||||
Lists.newArrayList("findClassUsages/javaUsages/Server.kt", "findClassUsages/javaUsages/Client.java"),
|
||||
JetClass.class,
|
||||
Lists.newArrayList("Field declaration (4: 13) private Server myServer;"));
|
||||
}
|
||||
|
||||
public void testFindClassKotlinUsages1() {
|
||||
doTestWithoutFiltering(
|
||||
Lists.newArrayList("findClassUsages/kotlinUsages1/Server.kt", "findClassUsages/kotlinUsages1/Client.kt"),
|
||||
JetClass.class,
|
||||
Lists.newArrayList(
|
||||
"Class/object property type (6: 21) var nextServer: Server? = null",
|
||||
"Function return types (14: 26) fun getNextServer(): Server? {",
|
||||
"Function return types (32: 21) fun Any.asServer(): Server? {",
|
||||
"Import directive (3: 15) import server.Server",
|
||||
"Local variable type (10: 21) val server: Server = s",
|
||||
"Nested class/object (7: 16) val name = Server.NAME",
|
||||
"Parameter type (24: 19) fun Client.bar(s: Server) {",
|
||||
"Parameter type (9: 16) fun foo(s: Server) {",
|
||||
"Super type qualifier (19: 15) super<Server>.work()",
|
||||
"Supertype (5: 15) class Client: Server {",
|
||||
"Target type of 'as' operation (33: 40) return if (this is Server) this as Server else null",
|
||||
"Target type of 'is' operation (33: 24) return if (this is Server) this as Server else null"
|
||||
));
|
||||
}
|
||||
|
||||
public void testFindClassKotlinUsages2() {
|
||||
doTestWithoutFiltering(
|
||||
Lists.newArrayList("findClassUsages/kotlinUsages2/Server.kt", "findClassUsages/kotlinUsages2/Client.kt"),
|
||||
JetClass.class,
|
||||
Lists.newArrayList(
|
||||
"Annotation (5: 1) X(\"\")",
|
||||
"Import directive (3: 15) import server.X"
|
||||
));
|
||||
}
|
||||
|
||||
public void testFindClassKotlinUsages3() {
|
||||
doTestWithoutFiltering(
|
||||
Lists.newArrayList("findClassUsages/kotlinUsages3/Server.kt", "findClassUsages/kotlinUsages3/Client.kt"),
|
||||
JetClass.class,
|
||||
Lists.newArrayList(
|
||||
"Import directive (3: 15) import server.Data",
|
||||
"Type argument (9: 16) val c = Client<Data>()",
|
||||
"Type constraint (5: 17) class Client<T: Data, X> where X: Data {",
|
||||
"Type constraint (5: 35) class Client<T: Data, X> where X: Data {"
|
||||
));
|
||||
}
|
||||
|
||||
public void testFindUsagesUnresolvedAnnotation() {
|
||||
doTestWithoutFiltering(
|
||||
Lists.newArrayList("unresolvedAnnotation/Server.kt", "unresolvedAnnotation/Client.java"),
|
||||
JetClass.class,
|
||||
Lists.newArrayList("Usage in extends/implements clause (1: 29) public class Client extends Foo {}"));
|
||||
}
|
||||
|
||||
public void testFindMethodJavaUsages() {
|
||||
doTestWithoutFiltering(
|
||||
Lists.newArrayList("findMethodUsages/javaUsages/Server.kt", "findMethodUsages/javaUsages/Client.java"),
|
||||
JetFunction.class,
|
||||
Lists.newArrayList("Unclassified usage (6: 16) server.processRequest();"));
|
||||
}
|
||||
|
||||
public void testFindMethodKotlinUsages() {
|
||||
doTestWithoutFiltering(
|
||||
Lists.newArrayList("findMethodUsages/kotlinUsages/Server.kt", "findMethodUsages/kotlinUsages/Client.kt"),
|
||||
JetFunction.class,
|
||||
Lists.newArrayList(
|
||||
"Callable reference (6: 23) val methodRef = ::processRequest()",
|
||||
"Function call (10: 9) processRequest()",
|
||||
"Import directive (3: 15) import server.processRequest"
|
||||
));
|
||||
}
|
||||
|
||||
public void testFindPropertyJavaUsages() {
|
||||
doTestWithoutFiltering(
|
||||
Lists.newArrayList("findPropertyUsages/javaUsages/Server.kt", "findPropertyUsages/javaUsages/Client.java"),
|
||||
JetProperty.class,
|
||||
Lists.newArrayList(
|
||||
"Unclassified usage (7: 40) println(\"foo = \" + O.instance$.getFoo())"
|
||||
));
|
||||
}
|
||||
|
||||
public void testFindPropertyKotlinUsages() {
|
||||
doTestWithoutFiltering(
|
||||
Lists.newArrayList("findPropertyUsages/kotlinUsages/Server.kt", "findPropertyUsages/kotlinUsages/Client.kt"),
|
||||
JetProperty.class,
|
||||
Lists.newArrayList(
|
||||
"Import directive (3: 15) import server.foo",
|
||||
"Receiver (8: 35) println(\"length: ${server.foo.length()}\")",
|
||||
"Selector (7: 33) println(\"foo = ${server.foo}\")"
|
||||
));
|
||||
}
|
||||
|
||||
public void testFindObjectJavaUsages() {
|
||||
doTestWithoutFiltering(
|
||||
Lists.newArrayList("findObjectUsages/javaUsages/Server.kt", "findObjectUsages/javaUsages/Client.java"),
|
||||
JetObjectDeclarationName.class,
|
||||
Lists.newArrayList(
|
||||
"Class static member access (7: 28) println(\"foo = \" + O.instance$.getFoo())",
|
||||
"Usage in import (3: 15) import server.O"
|
||||
));
|
||||
}
|
||||
|
||||
public void testFindObjectKotlinUsages() {
|
||||
doTestWithoutFiltering(
|
||||
Lists.newArrayList("findObjectUsages/kotlinUsages/Server.kt", "findObjectUsages/kotlinUsages/Client.kt"),
|
||||
JetObjectDeclarationName.class,
|
||||
Lists.newArrayList(
|
||||
"Import directive (3: 15) import server.O",
|
||||
"Receiver (7: 26) println(\"foo = ${O.foo}\")",
|
||||
"Value read (8: 19) val obj = O"
|
||||
));
|
||||
}
|
||||
|
||||
public void testFindWithFilteringImports() {
|
||||
doTest(Lists.newArrayList("findWithFilteringImports/Test.kt", "findWithFilteringImports/Usages.kt"),
|
||||
JetClass.class,
|
||||
2,
|
||||
Lists.newArrayList(new JetImportFilteringRule()),
|
||||
Lists.newArrayList("Instantiation (5: 9) val a = Test()"));
|
||||
}
|
||||
|
||||
private <T extends PsiElement> void doTestWithoutFiltering(
|
||||
Collection<String> files,
|
||||
Class<T> caretElementClass,
|
||||
Collection<String> expectedUsages
|
||||
) {
|
||||
doTest(files, caretElementClass, expectedUsages.size(), Collections.<UsageFilteringRule>emptyList(), expectedUsages);
|
||||
}
|
||||
|
||||
private <T extends PsiElement> void doTest(
|
||||
Collection<String> files,
|
||||
Class<T> caretElementClass,
|
||||
int numberOfNotFilteredUsages,
|
||||
Collection<? extends UsageFilteringRule> filters,
|
||||
Collection<String> expectedUsages
|
||||
) {
|
||||
myFixture.configureByFiles(ArrayUtil.toObjectArray(files, String.class));
|
||||
T caretElement = PsiTreeUtil.getParentOfType(myFixture.getElementAtCaret(), caretElementClass, false);
|
||||
assertNotNull(String.format("Element with type '%s' wasn't found at caret position", caretElementClass), caretElement);
|
||||
|
||||
Collection<UsageInfo> usageInfos = myFixture.findUsages(caretElement);
|
||||
|
||||
assertEquals(numberOfNotFilteredUsages, usageInfos.size());
|
||||
|
||||
Collection<UsageInfo2UsageAdapter> filteredUsages = getUsageAdapters(filters, usageInfos);
|
||||
|
||||
Function<UsageInfo2UsageAdapter, String> convertToString = new Function<UsageInfo2UsageAdapter, String>() {
|
||||
@Override
|
||||
public String apply(@Nullable UsageInfo2UsageAdapter usageAdapter) {
|
||||
assert usageAdapter != null;
|
||||
return getUsageType(usageAdapter.getElement())
|
||||
+ " " + Joiner.on("").join(Arrays.asList(usageAdapter.getPresentation().getText()));
|
||||
}
|
||||
};
|
||||
|
||||
Collection<String> finalUsages = Ordering.natural().sortedCopy(Collections2.transform(filteredUsages, convertToString));
|
||||
assertOrderedEquals(finalUsages, Ordering.natural().sortedCopy(expectedUsages));
|
||||
}
|
||||
|
||||
private static Collection<UsageInfo2UsageAdapter> getUsageAdapters(
|
||||
final Collection<? extends UsageFilteringRule> filters,
|
||||
Collection<UsageInfo> usageInfos
|
||||
) {
|
||||
return Collections2.filter(
|
||||
Collections2.transform(usageInfos, new Function<UsageInfo, UsageInfo2UsageAdapter>() {
|
||||
@Override
|
||||
public UsageInfo2UsageAdapter apply(@Nullable UsageInfo usageInfo) {
|
||||
assert (usageInfo != null);
|
||||
|
||||
UsageInfo2UsageAdapter usageAdapter = new UsageInfo2UsageAdapter(usageInfo);
|
||||
for (UsageFilteringRule filter : filters) {
|
||||
if (!filter.isVisible(usageAdapter)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return usageAdapter;
|
||||
}
|
||||
}),
|
||||
Predicates.notNull());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static UsageType getUsageType(PsiElement element) {
|
||||
if (element == null) return null;
|
||||
|
||||
if (PsiTreeUtil.getParentOfType(element, PsiComment.class, false) != null) {
|
||||
return UsageType.COMMENT_USAGE;
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@InnerTestClasses({JetFindUsagesTest.JavaClassUsages.class, JetFindUsagesTest.KotlinClassUsages1.class, JetFindUsagesTest.KotlinClassUsages2.class, JetFindUsagesTest.KotlinClassUsages3.class, JetFindUsagesTest.JavaObjectUsages.class, JetFindUsagesTest.KotlinObjectUsages.class, JetFindUsagesTest.JavaMethodUsages.class, JetFindUsagesTest.KotlinMethodUsages.class, JetFindUsagesTest.JavaPropertyUsages.class, JetFindUsagesTest.KotlinPropertyUsages.class, JetFindUsagesTest.FindWithFilteringImports.class, JetFindUsagesTest.UnresolvedAnnotation.class})
|
||||
public class JetFindUsagesTest extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("idea/testData/findUsages/findClassUsages/javaClassUsages")
|
||||
public static class JavaClassUsages extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("Server.kt")
|
||||
public void test() throws Exception {
|
||||
testFindClassJavaUsages("idea/testData/findUsages/findClassUsages/javaClassUsages/Server.kt");
|
||||
}
|
||||
|
||||
UsageTypeProvider[] providers = Extensions.getExtensions(UsageTypeProvider.EP_NAME);
|
||||
for (UsageTypeProvider provider : providers) {
|
||||
UsageType usageType = provider.getUsageType(element);
|
||||
if (usageType != null) {
|
||||
return usageType;
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInJavaClassUsages() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/findUsages/findClassUsages/javaClassUsages"), Pattern.compile("^(.*)Server.kt$"), true);
|
||||
}
|
||||
|
||||
return UsageType.UNCLASSIFIED;
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/findClassUsages/kotlinClassUsages1")
|
||||
public static class KotlinClassUsages1 extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("Server.kt")
|
||||
public void test() throws Exception {
|
||||
testFindClassKotlinUsages("idea/testData/findUsages/findClassUsages/kotlinClassUsages1/Server.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInKotlinClassUsages1() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/findUsages/findClassUsages/kotlinClassUsages1"), Pattern.compile("^(.*)Server.kt$"), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/findClassUsages/kotlinClassUsages2")
|
||||
public static class KotlinClassUsages2 extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("Server.kt")
|
||||
public void test() throws Exception {
|
||||
testFindClassKotlinUsages("idea/testData/findUsages/findClassUsages/kotlinClassUsages2/Server.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInKotlinClassUsages2() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/findUsages/findClassUsages/kotlinClassUsages2"), Pattern.compile("^(.*)Server.kt$"), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/findClassUsages/kotlinClassUsages3")
|
||||
public static class KotlinClassUsages3 extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("Server.kt")
|
||||
public void test() throws Exception {
|
||||
testFindClassKotlinUsages("idea/testData/findUsages/findClassUsages/kotlinClassUsages3/Server.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInKotlinClassUsages3() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/findUsages/findClassUsages/kotlinClassUsages3"), Pattern.compile("^(.*)Server.kt$"), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/findObjectUsages/javaObjectUsages")
|
||||
public static class JavaObjectUsages extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("Server.kt")
|
||||
public void test() throws Exception {
|
||||
testFindObjectJavaUsages("idea/testData/findUsages/findObjectUsages/javaObjectUsages/Server.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInJavaObjectUsages() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/findUsages/findObjectUsages/javaObjectUsages"), Pattern.compile("^(.*)Server.kt$"), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/findObjectUsages/kotlinObjectUsages")
|
||||
public static class KotlinObjectUsages extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("Server.kt")
|
||||
public void test() throws Exception {
|
||||
testFindObjectKotlinUsages("idea/testData/findUsages/findObjectUsages/kotlinObjectUsages/Server.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInKotlinObjectUsages() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/findUsages/findObjectUsages/kotlinObjectUsages"), Pattern.compile("^(.*)Server.kt$"), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/findMethodUsages/javaMethodUsages")
|
||||
public static class JavaMethodUsages extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("Server.kt")
|
||||
public void test() throws Exception {
|
||||
testFindMethodJavaUsages("idea/testData/findUsages/findMethodUsages/javaMethodUsages/Server.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInJavaMethodUsages() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/findUsages/findMethodUsages/javaMethodUsages"), Pattern.compile("^(.*)Server.kt$"), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/findMethodUsages/kotlinMethodUsages")
|
||||
public static class KotlinMethodUsages extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("Server.kt")
|
||||
public void test() throws Exception {
|
||||
testFindMethodKotlinUsages("idea/testData/findUsages/findMethodUsages/kotlinMethodUsages/Server.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInKotlinMethodUsages() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/findUsages/findMethodUsages/kotlinMethodUsages"), Pattern.compile("^(.*)Server.kt$"), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/findPropertyUsages/javaPropertyUsages")
|
||||
public static class JavaPropertyUsages extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("Server.kt")
|
||||
public void test() throws Exception {
|
||||
testFindPropertyJavaUsages("idea/testData/findUsages/findPropertyUsages/javaPropertyUsages/Server.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInJavaPropertyUsages() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/findUsages/findPropertyUsages/javaPropertyUsages"), Pattern.compile("^(.*)Server.kt$"), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/findPropertyUsages/kotlinPropertyUsages")
|
||||
public static class KotlinPropertyUsages extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("Server.kt")
|
||||
public void test() throws Exception {
|
||||
testFindPropertyKotlinUsages("idea/testData/findUsages/findPropertyUsages/kotlinPropertyUsages/Server.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInKotlinPropertyUsages() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/findUsages/findPropertyUsages/kotlinPropertyUsages"), Pattern.compile("^(.*)Server.kt$"), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/findWithFilteringImports")
|
||||
public static class FindWithFilteringImports extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("Server.kt")
|
||||
public void test() throws Exception {
|
||||
testFindWithFilteringImports("idea/testData/findUsages/findWithFilteringImports/Server.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInFindWithFilteringImports() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/findUsages/findWithFilteringImports"), Pattern.compile("^(.*)Server.kt$"), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/unresolvedAnnotation")
|
||||
public static class UnresolvedAnnotation extends AbstractJetFindUsagesTest {
|
||||
@TestMetadata("Server.kt")
|
||||
public void test() throws Exception {
|
||||
testFindUsagesUnresolvedAnnotation("idea/testData/findUsages/unresolvedAnnotation/Server.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInUnresolvedAnnotation() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/findUsages/unresolvedAnnotation"), Pattern.compile("^(.*)Server.kt$"), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("JetFindUsagesTest");
|
||||
suite.addTestSuite(JavaClassUsages.class);
|
||||
suite.addTestSuite(KotlinClassUsages1.class);
|
||||
suite.addTestSuite(KotlinClassUsages2.class);
|
||||
suite.addTestSuite(KotlinClassUsages3.class);
|
||||
suite.addTestSuite(JavaObjectUsages.class);
|
||||
suite.addTestSuite(KotlinObjectUsages.class);
|
||||
suite.addTestSuite(JavaMethodUsages.class);
|
||||
suite.addTestSuite(KotlinMethodUsages.class);
|
||||
suite.addTestSuite(JavaPropertyUsages.class);
|
||||
suite.addTestSuite(KotlinPropertyUsages.class);
|
||||
suite.addTestSuite(FindWithFilteringImports.class);
|
||||
suite.addTestSuite(UnresolvedAnnotation.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user