Test reference resolve from Java to Kotlin
Cases cover the most basic features Sadly it was missing before
This commit is contained in:
@@ -124,6 +124,7 @@ import org.jetbrains.jet.completion.weighers.AbstractBasicCompletionWeigherTest
|
|||||||
import org.jetbrains.jet.completion.weighers.AbstractSmartCompletionWeigherTest
|
import org.jetbrains.jet.completion.weighers.AbstractSmartCompletionWeigherTest
|
||||||
import org.jetbrains.jet.generators.tests.reservedWords.generateTestDataForReservedWords
|
import org.jetbrains.jet.generators.tests.reservedWords.generateTestDataForReservedWords
|
||||||
import org.jetbrains.k2js.test.semantics.AbstractReservedWordTest
|
import org.jetbrains.k2js.test.semantics.AbstractReservedWordTest
|
||||||
|
import org.jetbrains.jet.resolve.AbstractReferenceResolveInJavaTest
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
System.setProperty("java.awt.headless", "true")
|
System.setProperty("java.awt.headless", "true")
|
||||||
@@ -463,6 +464,10 @@ fun main(args: Array<String>) {
|
|||||||
model("resolve/references", pattern = """^([^\.]+)\.kt$""")
|
model("resolve/references", pattern = """^([^\.]+)\.kt$""")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testClass(javaClass<AbstractReferenceResolveInJavaTest>()) {
|
||||||
|
model("resolve/referenceInJava", extension = "java")
|
||||||
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractReferenceResolveWithLibTest>()) {
|
testClass(javaClass<AbstractReferenceResolveWithLibTest>()) {
|
||||||
model("resolve/referenceWithLib", recursive = false)
|
model("resolve/referenceWithLib", recursive = false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
public class Class {
|
||||||
|
public static k.Cla<caret>ss foo() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// REF: (k).Class
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
public class Constructor {
|
||||||
|
public static void foo() {
|
||||||
|
new k.Clas<caret>s();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// REF: (k).Class
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
public class EnumEntry {
|
||||||
|
public static void foo() {
|
||||||
|
k.EnumClass.E<caret>NTRY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// REF: (k.EnumClass).ENTRY
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
public class Getter {
|
||||||
|
public static void foo(k.Class c) {
|
||||||
|
c.get<caret>Prop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// REF: (k.Class).prop
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
public class Method {
|
||||||
|
public static void foo() {
|
||||||
|
(new k.Class()).f<caret>unction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// REF: (in k.Class).function()
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
public class PackageFacade {
|
||||||
|
public static void foo() {
|
||||||
|
k.KP<caret>ackage.topLevelFunction()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// REF: /src/<test dir>/resolve/referenceInJava.dependencies.kt
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package k
|
||||||
|
|
||||||
|
public class Class() {
|
||||||
|
public val prop: Int = 0
|
||||||
|
fun function() = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum class EnumClass {
|
||||||
|
ENTRY
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public fun topLevelFun() {
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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.resolve
|
||||||
|
|
||||||
|
import org.jetbrains.jet.plugin.PluginTestCaseBase
|
||||||
|
|
||||||
|
private val FILE_WITH_KOTLIN_CODE = PluginTestCaseBase.getTestDataPathBase() + "/resolve/referenceInJava/dependencies.kt"
|
||||||
|
|
||||||
|
public abstract class AbstractReferenceResolveInJavaTest : AbstractReferenceResolveTest() {
|
||||||
|
|
||||||
|
protected override fun doTest(path: String) {
|
||||||
|
assert(path.endsWith(".java")) { path }
|
||||||
|
myFixture!!.configureByFile(FILE_WITH_KOTLIN_CODE)
|
||||||
|
myFixture!!.configureByFile(path)
|
||||||
|
performChecks()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -85,7 +85,7 @@ public abstract class AbstractReferenceResolveTest extends LightPlatformCodeInsi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doTest(String path) {
|
protected void doTest(@NotNull String path) {
|
||||||
assert path.endsWith(".kt") : path;
|
assert path.endsWith(".kt") : path;
|
||||||
UtilPackage.configureWithExtraFile(myFixture, path, ".Data");
|
UtilPackage.configureWithExtraFile(myFixture, path, ".Data");
|
||||||
performChecks();
|
performChecks();
|
||||||
@@ -110,7 +110,7 @@ public abstract class AbstractReferenceResolveTest extends LightPlatformCodeInsi
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void doMultiResolveTest() {
|
protected void doMultiResolveTest() {
|
||||||
List<String> expectedReferences = InTextDirectivesUtils.findLinesWithPrefixesRemoved(myFixture.getFile().getText(), "REF:");
|
List<String> expectedReferences = ReferenceUtils.getExpectedReferences(myFixture.getFile().getText());
|
||||||
|
|
||||||
PsiReference psiReference = myFixture.getFile().findReferenceAt(myFixture.getEditor().getCaretModel().getOffset());
|
PsiReference psiReference = myFixture.getFile().findReferenceAt(myFixture.getEditor().getCaretModel().getOffset());
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ public abstract class AbstractReferenceResolveTest extends LightPlatformCodeInsi
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static ExpectedResolveData readResolveData(String fileText) {
|
public static ExpectedResolveData readResolveData(String fileText) {
|
||||||
boolean shouldBeUnresolved = InTextDirectivesUtils.isDirectiveDefined(fileText, REF_EMPTY);
|
boolean shouldBeUnresolved = InTextDirectivesUtils.isDirectiveDefined(fileText, REF_EMPTY);
|
||||||
List<String> refs = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "REF:");
|
List<String> refs = ReferenceUtils.getExpectedReferences(fileText);
|
||||||
|
|
||||||
String referenceToString;
|
String referenceToString;
|
||||||
if (shouldBeUnresolved) {
|
if (shouldBeUnresolved) {
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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.resolve;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.TestDataPath;
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
|
import org.jetbrains.jet.test.InnerTestClasses;
|
||||||
|
import org.jetbrains.jet.test.TestMetadata;
|
||||||
|
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@TestMetadata("idea/testData/resolve/referenceInJava")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
||||||
|
public class ReferenceResolveInJavaTestGenerated extends AbstractReferenceResolveInJavaTest {
|
||||||
|
public void testAllFilesPresentInReferenceInJava() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/resolve/referenceInJava"), Pattern.compile("^(.+)\\.java$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Class.java")
|
||||||
|
public void testClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/referenceInJava/Class.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Constructor.java")
|
||||||
|
public void testConstructor() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/referenceInJava/Constructor.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("EnumEntry.java")
|
||||||
|
public void testEnumEntry() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/referenceInJava/EnumEntry.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Getter.java")
|
||||||
|
public void testGetter() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/referenceInJava/Getter.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Method.java")
|
||||||
|
public void testMethod() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/referenceInJava/Method.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("PackageFacade.java")
|
||||||
|
public void testPackageFacade() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/referenceInJava/PackageFacade.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,26 +20,24 @@ import com.intellij.navigation.ItemPresentation;
|
|||||||
import com.intellij.navigation.NavigationItem;
|
import com.intellij.navigation.NavigationItem;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiPackage;
|
import com.intellij.psi.PsiPackage;
|
||||||
|
import com.intellij.util.PathUtil;
|
||||||
|
import kotlin.Function1;
|
||||||
|
import kotlin.KotlinPackage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.asJava.KotlinLightClass;
|
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||||
import org.jetbrains.jet.plugin.presentation.JetLightClassListCellRenderer;
|
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public final class ReferenceUtils {
|
public final class ReferenceUtils {
|
||||||
private ReferenceUtils() {
|
private ReferenceUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String renderAsGotoImplementation(@NotNull PsiElement element) {
|
public static String renderAsGotoImplementation(@NotNull PsiElement element) {
|
||||||
if (element instanceof KotlinLightClass) {
|
PsiElement navigationElement = element.getNavigationElement();
|
||||||
KotlinLightClass jetLightClass = (KotlinLightClass) element;
|
Assert.assertTrue(navigationElement instanceof NavigationItem);
|
||||||
JetLightClassListCellRenderer renderer = new JetLightClassListCellRenderer();
|
ItemPresentation presentation = ((NavigationItem) navigationElement).getPresentation();
|
||||||
String elementText = renderer.getElementText(jetLightClass);
|
|
||||||
String containerText = JetLightClassListCellRenderer.getContainerTextStatic(jetLightClass);
|
|
||||||
return (containerText != null) ? containerText + "." + elementText : elementText;
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.assertTrue(element instanceof NavigationItem);
|
|
||||||
ItemPresentation presentation = ((NavigationItem) element).getPresentation();
|
|
||||||
|
|
||||||
if (presentation == null) {
|
if (presentation == null) {
|
||||||
return element.getText();
|
return element.getText();
|
||||||
@@ -47,8 +45,23 @@ public final class ReferenceUtils {
|
|||||||
|
|
||||||
String presentableText = presentation.getPresentableText();
|
String presentableText = presentation.getPresentableText();
|
||||||
String locationString = presentation.getLocationString();
|
String locationString = presentation.getLocationString();
|
||||||
return locationString == null || element instanceof PsiPackage // for PsiPackage, presentableText is FQ name of current package
|
return locationString == null || navigationElement instanceof PsiPackage
|
||||||
|
// for PsiPackage, presentableText is FQ name of current package
|
||||||
? presentableText
|
? presentableText
|
||||||
: locationString + "." + presentableText;
|
: locationString + "." + presentableText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// purpose of this helper is to deal with the case when navigation element is a file
|
||||||
|
// see ReferenceResolveInJavaTestGenerated.testPackageFacade()
|
||||||
|
@NotNull
|
||||||
|
public static List<String> getExpectedReferences(@NotNull String text) {
|
||||||
|
List<String> prefixes = InTextDirectivesUtils.findLinesWithPrefixesRemoved(text, "// REF:");
|
||||||
|
return KotlinPackage.map(prefixes, new Function1<String, String>() {
|
||||||
|
@Override
|
||||||
|
public String invoke(String s) {
|
||||||
|
String replaced = s.replace("<test dir>", PluginTestCaseBase.getTestDataPathBase());
|
||||||
|
return PathUtil.toSystemDependentName(replaced).replace("//", "/"); //happens on Unix
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user