KT-1389 Ctrl-Alt-B on class declaration does not work - Multifile tests

#KT-1389 Fixed
This commit is contained in:
Nikolay Krasko
2012-08-16 21:20:15 +04:00
parent 60b20374da
commit 2fd5e01da8
7 changed files with 159 additions and 45 deletions
@@ -0,0 +1,6 @@
package testing.kt
class KotlinImpl : <caret>JavaBase()
// REF: (testing.kt).KotlinImpl
// REF: JavaBase
@@ -0,0 +1,4 @@
package testing.jj;
class JavaImplementation extends testing.kt.Base {
}
@@ -0,0 +1,5 @@
package testing.kt
open class <caret>Base
// REF: (testing.jj).JavaImplementation
@@ -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<String> expectedReferences = Arrays.asList(InTextDirectivesUtils.findListWithPrefix("// REF:", editor.getDocument().getText()));
Collections.sort(expectedReferences);
if (gotoData != null) {
// Transform given reference result to strings
List<String> psiElements = Lists.transform(Arrays.asList(gotoData.targets), new Function<PsiElement, String>() {
@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);
}
}
}
@@ -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;
}
}
@@ -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<String> 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<String> psiElements = Lists.transform(Arrays.asList(gotoData.targets), new Function<PsiElement, String>() {
@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);
}
}