diff --git a/idea/testData/navigation/implementations/multifile/ImplementJavaClassInKotlin/ImplementJavaClassInKotlin.java b/idea/testData/navigation/implementations/multifile/ImplementJavaClassInKotlin/ImplementJavaClassInKotlin.java new file mode 100644 index 00000000000..345eb1f5fec --- /dev/null +++ b/idea/testData/navigation/implementations/multifile/ImplementJavaClassInKotlin/ImplementJavaClassInKotlin.java @@ -0,0 +1,2 @@ +public class JavaBase { +} \ No newline at end of file diff --git a/idea/testData/navigation/implementations/multifile/ImplementJavaClassInKotlin/ImplementJavaClassInKotlin.kt b/idea/testData/navigation/implementations/multifile/ImplementJavaClassInKotlin/ImplementJavaClassInKotlin.kt new file mode 100644 index 00000000000..7116ff654fa --- /dev/null +++ b/idea/testData/navigation/implementations/multifile/ImplementJavaClassInKotlin/ImplementJavaClassInKotlin.kt @@ -0,0 +1,6 @@ +package testing.kt + +class KotlinImpl : JavaBase() + +// REF: (testing.kt).KotlinImpl +// REF: JavaBase diff --git a/idea/testData/navigation/implementations/multifile/ImplementKotlinClassInJava/ImplementKotlinClassInJava.java b/idea/testData/navigation/implementations/multifile/ImplementKotlinClassInJava/ImplementKotlinClassInJava.java new file mode 100644 index 00000000000..71b33f39812 --- /dev/null +++ b/idea/testData/navigation/implementations/multifile/ImplementKotlinClassInJava/ImplementKotlinClassInJava.java @@ -0,0 +1,4 @@ +package testing.jj; + +class JavaImplementation extends testing.kt.Base { +} \ No newline at end of file diff --git a/idea/testData/navigation/implementations/multifile/ImplementKotlinClassInJava/ImplementKotlinClassInJava.kt b/idea/testData/navigation/implementations/multifile/ImplementKotlinClassInJava/ImplementKotlinClassInJava.kt new file mode 100644 index 00000000000..5718c055691 --- /dev/null +++ b/idea/testData/navigation/implementations/multifile/ImplementKotlinClassInJava/ImplementKotlinClassInJava.kt @@ -0,0 +1,5 @@ +package testing.kt + +open class Base + +// REF: (testing.jj).JavaImplementation \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/navigation/ImplementationTestUtils.java b/idea/tests/org/jetbrains/jet/plugin/navigation/ImplementationTestUtils.java new file mode 100644 index 00000000000..af78a6ec9e5 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/navigation/ImplementationTestUtils.java @@ -0,0 +1,88 @@ +/* + * Copyright 2010-2012 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.plugin.navigation; + +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import com.google.common.collect.Ordering; +import com.intellij.codeInsight.navigation.GotoImplementationHandler; +import com.intellij.codeInsight.navigation.GotoTargetHandler; +import com.intellij.navigation.ItemPresentation; +import com.intellij.navigation.NavigationItem; +import com.intellij.openapi.editor.Editor; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.testFramework.UsefulTestCase; +import junit.framework.Assert; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.asJava.JetLightClass; +import org.jetbrains.jet.plugin.presentation.JetLightClassListCellRenderer; +import org.jetbrains.jet.testing.InTextDirectivesUtils; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * @author Nikolay Krasko + */ +final class ImplementationTestUtils { + private ImplementationTestUtils() { + } + + public static GotoTargetHandler.GotoData invokeGotoImplementations(Editor editor, PsiFile psiFile) { + return new GotoImplementationHandler().getSourceAndTargetElements(editor, psiFile); + } + + public static void assertGotoImplementations(Editor editor, GotoTargetHandler.GotoData gotoData) { + // Get expected references from the tested document + List expectedReferences = Arrays.asList(InTextDirectivesUtils.findListWithPrefix("// REF:", editor.getDocument().getText())); + Collections.sort(expectedReferences); + + if (gotoData != null) { + // Transform given reference result to strings + List psiElements = Lists.transform(Arrays.asList(gotoData.targets), new Function() { + @Override + public String apply(@Nullable PsiElement element) { + Assert.assertNotNull(element); + if (element instanceof JetLightClass) { + JetLightClass jetLightClass = (JetLightClass) element; + JetLightClassListCellRenderer renderer = new JetLightClassListCellRenderer(); + 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(); + + Assert.assertNotNull(presentation); + + String presentableText = presentation.getPresentableText(); + String locationString = presentation.getLocationString(); + return locationString != null ? (locationString + "." + presentableText) : presentableText; + } + }); + + // Compare + UsefulTestCase.assertOrderedEquals(Ordering.natural().sortedCopy(psiElements), expectedReferences); + } + else { + UsefulTestCase.assertEmpty(expectedReferences); + } + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/navigation/JetGotoImplementationMultifileTest.java b/idea/tests/org/jetbrains/jet/plugin/navigation/JetGotoImplementationMultifileTest.java new file mode 100644 index 00000000000..8c8ae7c00e7 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/navigation/JetGotoImplementationMultifileTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2010-2012 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.plugin.navigation; + +import com.intellij.codeInsight.CodeInsightTestCase; +import com.intellij.codeInsight.navigation.GotoTargetHandler; +import org.jetbrains.jet.plugin.PluginTestCaseBase; + +import java.io.File; + +/** + * @author Nikolay Krasko + */ +public class JetGotoImplementationMultifileTest extends CodeInsightTestCase { + public void testImplementKotlinClassInJava() throws Exception { + doKotlinJavaTest(); + } + + public void testImplementJavaClassInKotlin() throws Exception { + doKotlinJavaTest(); + } + + private void doKotlinJavaTest() throws Exception { + doMultifileTest(getTestName(false) + ".kt", getTestName(false) + ".java"); + } + + private void doMultifileTest(String ... fileNames) throws Exception { + configureByFiles(null, fileNames); + GotoTargetHandler.GotoData gotoData = ImplementationTestUtils.invokeGotoImplementations(getEditor(), getFile()); + ImplementationTestUtils.assertGotoImplementations(getEditor(), gotoData); + } + + @Override + protected String getTestDataPath() { + return new File(PluginTestCaseBase.getTestDataPathBase(), + "/navigation/implementations/multifile/" + getTestName(false)).getPath() + File.separator; + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/navigation/JetGotoImplementationTest.java b/idea/tests/org/jetbrains/jet/plugin/navigation/JetGotoImplementationTest.java index 3ba202f21e2..790351e1b04 100644 --- a/idea/tests/org/jetbrains/jet/plugin/navigation/JetGotoImplementationTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/navigation/JetGotoImplementationTest.java @@ -16,26 +16,12 @@ package org.jetbrains.jet.plugin.navigation; -import com.google.common.base.Function; -import com.google.common.collect.Lists; -import com.google.common.collect.Ordering; -import com.intellij.codeInsight.navigation.GotoImplementationHandler; import com.intellij.codeInsight.navigation.GotoTargetHandler; -import com.intellij.navigation.ItemPresentation; -import com.intellij.navigation.NavigationItem; import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.psi.PsiElement; import com.intellij.testFramework.LightCodeInsightTestCase; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.asJava.JetLightClass; import org.jetbrains.jet.plugin.PluginTestCaseBase; -import org.jetbrains.jet.plugin.presentation.JetLightClassListCellRenderer; -import org.jetbrains.jet.testing.InTextDirectivesUtils; import java.io.File; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; /** * @author Nikolay Krasko @@ -62,36 +48,7 @@ public class JetGotoImplementationTest extends LightCodeInsightTestCase { protected void doTest() { configureByFile(getTestName(false) + ".kt"); - - List expectedReferences = Arrays.asList( - InTextDirectivesUtils.findListWithPrefix("// REF:", getEditor().getDocument().getText())); - Collections.sort(expectedReferences); - - final GotoTargetHandler.GotoData gotoData = new GotoImplementationHandler().getSourceAndTargetElements(getEditor(), getFile()); - - if (gotoData != null) { - List psiElements = Lists.transform(Arrays.asList(gotoData.targets), new Function() { - @Override - public String apply(@Nullable PsiElement element) { - assertNotNull(element); - if (element instanceof JetLightClass) { - JetLightClass jetLightClass = (JetLightClass) element; - JetLightClassListCellRenderer renderer = new JetLightClassListCellRenderer(); - return JetLightClassListCellRenderer.getContainerTextStatic(jetLightClass) + "." + - renderer.getElementText(jetLightClass); - } - - assertTrue(element instanceof NavigationItem); - ItemPresentation presentation = ((NavigationItem)element).getPresentation(); - assertNotNull(presentation); - return presentation.getLocationString() + "." + presentation.getPresentableText(); - } - }); - - assertOrderedEquals(Ordering.natural().sortedCopy(psiElements), expectedReferences); - } - else { - assertEmpty(expectedReferences); - } + GotoTargetHandler.GotoData gotoData = ImplementationTestUtils.invokeGotoImplementations(getEditor(), getFile()); + ImplementationTestUtils.assertGotoImplementations(getEditor(), gotoData); } }