From c0e6fa62a02b50e160cfa3dad2a4a5f0192e3668 Mon Sep 17 00:00:00 2001 From: Michael Nedzelsky Date: Thu, 2 Apr 2015 23:33:25 +0300 Subject: [PATCH] NavigateToLibrarySourceTest -> NavigateToLibrarySourceTestGenerated --- .../kotlin/generators/tests/GenerateTests.kt | 5 + .../AbstractNavigateToLibrarySourceTest.kt | 88 ++++++++++ .../NavigateToLibrarySourceTest.java | 161 ------------------ .../NavigateToLibrarySourceTestGenerated.java | 122 +++++++++++++ 4 files changed, 215 insertions(+), 161 deletions(-) create mode 100644 idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/AbstractNavigateToLibrarySourceTest.kt delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateToLibrarySourceTest.java create mode 100644 idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateToLibrarySourceTestGenerated.java diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index a6e82c15559..ebd89ab0750 100644 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -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) { model("navigation/gotoSymbol", testMethod = "doSymbolTest") } + testClass(javaClass()) { + model("decompiler/navigation/usercode") + } + testClass(javaClass()) { model("navigation/implementations", recursive = false) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/AbstractNavigateToLibrarySourceTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/AbstractNavigateToLibrarySourceTest.kt new file mode 100644 index 00000000000..d2ab79aba8e --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/AbstractNavigateToLibrarySourceTest.kt @@ -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 { + val psiFile = myFixture.getFile() + val referenceContainersToReferences = LinkedHashMap() + 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) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateToLibrarySourceTest.java b/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateToLibrarySourceTest.java deleted file mode 100644 index 493c47273bb..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateToLibrarySourceTest.java +++ /dev/null @@ -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 collectInterestingReferences() { - PsiFile psiFile = myFixture.getFile(); - Map referenceContainersToReferences = new LinkedHashMap(); - 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 collectInterestingNavigationElements() { - return ContainerUtil.map(collectInterestingReferences(), new Function() { - @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); - } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateToLibrarySourceTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateToLibrarySourceTestGenerated.java new file mode 100644 index 00000000000..430283a8ea4 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateToLibrarySourceTestGenerated.java @@ -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); + } +}