NavigateToLibrarySourceTest -> NavigateToLibrarySourceTestGenerated

This commit is contained in:
Michael Nedzelsky
2015-04-02 23:33:25 +03:00
parent 039b9a8e16
commit c0e6fa62a0
4 changed files with 215 additions and 161 deletions
@@ -59,6 +59,7 @@ import org.jetbrains.kotlin.idea.debugger.AbstractJetPositionManagerTest
import org.jetbrains.kotlin.idea.debugger.AbstractKotlinSteppingTest
import org.jetbrains.kotlin.idea.debugger.AbstractSmartStepIntoTest
import org.jetbrains.kotlin.idea.debugger.evaluate.*
import org.jetbrains.kotlin.idea.decompiler.navigation.AbstractNavigateToLibrarySourceTest
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.AbstractClsStubBuilderTest
import org.jetbrains.kotlin.idea.decompiler.textBuilder.AbstractDecompiledTextTest
import org.jetbrains.kotlin.idea.editor.quickDoc.AbstractJetQuickDocProviderTest
@@ -408,6 +409,10 @@ fun main(args: Array<String>) {
model("navigation/gotoSymbol", testMethod = "doSymbolTest")
}
testClass(javaClass<AbstractNavigateToLibrarySourceTest>()) {
model("decompiler/navigation/usercode")
}
testClass(javaClass<AbstractKotlinGotoImplementationTest>()) {
model("navigation/implementations", recursive = false)
}
@@ -0,0 +1,88 @@
/*
* Copyright 2010-2015 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.kotlin.idea.decompiler.navigation
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.psi.PsiElement
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.UsefulTestCase
import junit.framework.TestCase
import org.jetbrains.kotlin.idea.JdkAndMockLibraryProjectDescriptor
import org.jetbrains.kotlin.idea.navigation.NavigationTestUtils
import org.jetbrains.kotlin.idea.references.JetReference
import org.jetbrains.kotlin.test.JetTestUtils
import java.util.LinkedHashMap
public abstract class AbstractNavigateToLibrarySourceTest : AbstractNavigateToLibraryTest() {
protected fun doTest(path: String) {
myFixture.configureByFile(path)
checkAnnotatedLibraryCode(false)
checkAnnotatedLibraryCode(true)
}
override fun tearDown() {
JetSourceNavigationHelper.setForceResolve(false)
super.tearDown()
}
private fun checkAnnotatedLibraryCode(forceResolve: Boolean) {
JetSourceNavigationHelper.setForceResolve(forceResolve)
val actualCode = NavigationTestUtils.getNavigateElementsText(myFixture.getProject(), collectInterestingNavigationElements())
val expectedCode = getExpectedAnnotatedLibraryCode()
UsefulTestCase.assertSameLines(expectedCode, actualCode)
}
private fun collectInterestingReferences(): Collection<JetReference> {
val psiFile = myFixture.getFile()
val referenceContainersToReferences = LinkedHashMap<PsiElement, JetReference>()
for (offset in 0..psiFile.getTextLength() - 1) {
val ref = psiFile.findReferenceAt(offset)
if (ref is JetReference && !referenceContainersToReferences.containsKey(ref.getElement())) {
val target = ref.resolve()
if (target == null) continue
val targetNavPsiFile = target.getNavigationElement().getContainingFile()
if (targetNavPsiFile == null) continue
val targetNavFile = targetNavPsiFile.getVirtualFile()
if (targetNavFile == null) continue
if (ProjectFileIndex.SERVICE.getInstance(getProject()).isInLibrarySource(targetNavFile)) {
referenceContainersToReferences.put(ref.getElement(), ref)
}
}
}
return referenceContainersToReferences.values()
}
private fun collectInterestingNavigationElements() =
collectInterestingReferences().map {
val target = it.resolve()
TestCase.assertNotNull(target)
target!!.getNavigationElement()
}
private fun getExpectedAnnotatedLibraryCode(): String {
val document = myFixture.getDocument(myFixture.getFile())
TestCase.assertNotNull(document)
return JetTestUtils.getLastCommentedLines(document)
}
override fun getProjectDescriptor(): LightProjectDescriptor =
JdkAndMockLibraryProjectDescriptor(AbstractNavigateToLibraryTest.TEST_DATA_PATH + "/library", true)
}
@@ -1,161 +0,0 @@
/*
* Copyright 2010-2015 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.kotlin.idea.decompiler.navigation;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiReference;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.idea.JdkAndMockLibraryProjectDescriptor;
import org.jetbrains.kotlin.idea.navigation.NavigationTestUtils;
import org.jetbrains.kotlin.idea.references.JetReference;
import org.jetbrains.kotlin.test.JetTestUtils;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Attaching library with sources, and trying to navigate to its entities from source code.
*/
public class NavigateToLibrarySourceTest extends AbstractNavigateToLibraryTest {
public void testEnum() {
doTest();
}
public void testProperty() {
doTest();
}
public void testGlobalProperty() {
doTest();
}
public void testExtensionProperty() {
doTest();
}
public void testGlobalFunction() {
doTest();
}
public void testClassObject() {
doTest();
}
public void testExtensionFunction() {
doTest();
}
public void testSameNameInDifferentSources() {
doTest();
}
public void testConstructor() {
doTest();
}
public void testNamedObject() {
doTest();
}
public void testTypeWithSameShortName() {
doTest();
}
public void testOverloadedFunWithTypeParam() {
doTest();
}
public void testGenericFunctionWithInferredTypeArguments() {
doTest();
}
public void testGenericFunctionWithExplicitlyDeclaredTypeArguments() {
doTest();
}
private void doTest() {
myFixture.configureByFile(TEST_DATA_PATH + "/usercode/" + getTestName(false) + ".kt");
checkAnnotatedLibraryCode(false);
checkAnnotatedLibraryCode(true);
}
@Override
protected void tearDown() throws Exception {
JetSourceNavigationHelper.setForceResolve(false);
super.tearDown();
}
private void checkAnnotatedLibraryCode(boolean forceResolve) {
JetSourceNavigationHelper.setForceResolve(forceResolve);
String actualCode = NavigationTestUtils
.getNavigateElementsText(myFixture.getProject(), collectInterestingNavigationElements());
String expectedCode = getExpectedAnnotatedLibraryCode();
assertSameLines(expectedCode, actualCode);
}
private Collection<JetReference> collectInterestingReferences() {
PsiFile psiFile = myFixture.getFile();
Map<PsiElement, JetReference> referenceContainersToReferences = new LinkedHashMap<PsiElement, JetReference>();
for (int offset = 0; offset < psiFile.getTextLength(); offset++) {
PsiReference ref = psiFile.findReferenceAt(offset);
if (ref instanceof JetReference && !referenceContainersToReferences.containsKey(ref.getElement())) {
PsiElement target = ref.resolve();
if (target == null) continue;
PsiFile targetNavPsiFile = target.getNavigationElement().getContainingFile();
if (targetNavPsiFile == null) continue;
VirtualFile targetNavFile = targetNavPsiFile.getVirtualFile();
if (targetNavFile == null) continue;
if (ProjectFileIndex.SERVICE.getInstance(getProject()).isInLibrarySource(targetNavFile)) {
referenceContainersToReferences.put(ref.getElement(), (JetReference)ref);
}
}
}
return referenceContainersToReferences.values();
}
private Collection<PsiElement> collectInterestingNavigationElements() {
return ContainerUtil.map(collectInterestingReferences(), new Function<JetReference, PsiElement>() {
@Override
public PsiElement fun(JetReference reference) {
PsiElement target = reference.resolve();
assertNotNull(target);
return target.getNavigationElement();
}
});
}
private String getExpectedAnnotatedLibraryCode() {
Document document = myFixture.getDocument(myFixture.getFile());
assertNotNull(document);
return JetTestUtils.getLastCommentedLines(document);
}
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return new JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/library", true);
}
}
@@ -0,0 +1,122 @@
/*
* Copyright 2010-2015 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.kotlin.idea.decompiler.navigation;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.InnerTestClasses;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/decompiler/navigation/usercode")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class NavigateToLibrarySourceTestGenerated extends AbstractNavigateToLibrarySourceTest {
public void testAllFilesPresentInUsercode() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/decompiler/navigation/usercode"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("ClassObject.kt")
public void testClassObject() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/ClassObject.kt");
doTest(fileName);
}
@TestMetadata("Constructor.kt")
public void testConstructor() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/Constructor.kt");
doTest(fileName);
}
@TestMetadata("Enum.kt")
public void testEnum() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/Enum.kt");
doTest(fileName);
}
@TestMetadata("ExtensionFunction.kt")
public void testExtensionFunction() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/ExtensionFunction.kt");
doTest(fileName);
}
@TestMetadata("ExtensionProperty.kt")
public void testExtensionProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/ExtensionProperty.kt");
doTest(fileName);
}
@TestMetadata("GenericFunctionWithExplicitlyDeclaredTypeArguments.kt")
public void testGenericFunctionWithExplicitlyDeclaredTypeArguments() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/GenericFunctionWithExplicitlyDeclaredTypeArguments.kt");
doTest(fileName);
}
@TestMetadata("GenericFunctionWithInferredTypeArguments.kt")
public void testGenericFunctionWithInferredTypeArguments() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/GenericFunctionWithInferredTypeArguments.kt");
doTest(fileName);
}
@TestMetadata("GlobalFunction.kt")
public void testGlobalFunction() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/GlobalFunction.kt");
doTest(fileName);
}
@TestMetadata("GlobalProperty.kt")
public void testGlobalProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/GlobalProperty.kt");
doTest(fileName);
}
@TestMetadata("NamedObject.kt")
public void testNamedObject() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/NamedObject.kt");
doTest(fileName);
}
@TestMetadata("OverloadedFunWithTypeParam.kt")
public void testOverloadedFunWithTypeParam() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/OverloadedFunWithTypeParam.kt");
doTest(fileName);
}
@TestMetadata("Property.kt")
public void testProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/Property.kt");
doTest(fileName);
}
@TestMetadata("SameNameInDifferentSources.kt")
public void testSameNameInDifferentSources() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/SameNameInDifferentSources.kt");
doTest(fileName);
}
@TestMetadata("TypeWithSameShortName.kt")
public void testTypeWithSameShortName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/navigation/usercode/TypeWithSameShortName.kt");
doTest(fileName);
}
}