From ef25b14eabe5cd1221e118f57b887e6523ca20dd Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Fri, 18 Mar 2016 20:16:25 +0300 Subject: [PATCH] Drop non-generated NavigateToDecompiledLibraryTest It relies on internal data structure --- .../navigation/decompiled/AbstractClass.kt | 7 - .../ClassWithAbstractAndOpenMembers.kt | 22 -- .../decompiled/ClassWithConstructor.kt | 10 - .../decompiler/navigation/decompiled/Color.kt | 14 -- .../navigation/decompiled/ExtraKt.kt | 6 - .../navigation/decompiled/LibrariesPackage.kt | 4 - .../navigation/decompiled/MainKt.kt | 36 --- .../navigation/decompiled/NamedObject.kt | 8 - .../navigation/decompiled/SimpleClass.kt | 7 - .../navigation/decompiled/SimpleTrait.kt | 7 - .../navigation/decompiled/SimpleTraitImpl.kt | 7 - .../decompiled/WithInnerAndObject.kt | 16 -- .../decompiled/WithTraitClassObject.kt | 9 - .../AbstractInternalCompiledClassesTest.kt | 6 +- .../NavigateToDecompiledLibraryTest.java | 208 ------------------ .../ClsStubForWrongAbiVersionTest.kt | 8 +- ...bstractDecompiledTextFromJsMetadataTest.kt | 19 +- .../textBuilder/AbstractDecompiledTextTest.kt | 29 ++- .../DecompiledTextForWrongAbiVersionTest.kt | 5 +- 19 files changed, 49 insertions(+), 379 deletions(-) delete mode 100644 idea/testData/decompiler/navigation/decompiled/AbstractClass.kt delete mode 100644 idea/testData/decompiler/navigation/decompiled/ClassWithAbstractAndOpenMembers.kt delete mode 100644 idea/testData/decompiler/navigation/decompiled/ClassWithConstructor.kt delete mode 100644 idea/testData/decompiler/navigation/decompiled/Color.kt delete mode 100644 idea/testData/decompiler/navigation/decompiled/ExtraKt.kt delete mode 100644 idea/testData/decompiler/navigation/decompiled/LibrariesPackage.kt delete mode 100644 idea/testData/decompiler/navigation/decompiled/MainKt.kt delete mode 100644 idea/testData/decompiler/navigation/decompiled/NamedObject.kt delete mode 100644 idea/testData/decompiler/navigation/decompiled/SimpleClass.kt delete mode 100644 idea/testData/decompiler/navigation/decompiled/SimpleTrait.kt delete mode 100644 idea/testData/decompiler/navigation/decompiled/SimpleTraitImpl.kt delete mode 100644 idea/testData/decompiler/navigation/decompiled/WithInnerAndObject.kt delete mode 100644 idea/testData/decompiler/navigation/decompiled/WithTraitClassObject.kt delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateToDecompiledLibraryTest.java diff --git a/idea/testData/decompiler/navigation/decompiled/AbstractClass.kt b/idea/testData/decompiler/navigation/decompiled/AbstractClass.kt deleted file mode 100644 index 6fe609de08d..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/AbstractClass.kt +++ /dev/null @@ -1,7 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries - -[[public abstract class AbstractClass public constructor() { -}]] \ No newline at end of file diff --git a/idea/testData/decompiler/navigation/decompiled/ClassWithAbstractAndOpenMembers.kt b/idea/testData/decompiler/navigation/decompiled/ClassWithAbstractAndOpenMembers.kt deleted file mode 100644 index 7f94de21088..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/ClassWithAbstractAndOpenMembers.kt +++ /dev/null @@ -1,22 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries - -[[public abstract class ClassWithAbstractAndOpenMembers public constructor() { - [public abstract val abstractVal: kotlin.String] - - [public abstract var abstractVar: kotlin.String] - - [public open val openVal: kotlin.String /* compiled code */] - - [public open val openValWithGetter: kotlin.String /* compiled code */] - - [public open var openVar: kotlin.String /* compiled code */] - - [public open var openVarWithGetter: kotlin.String /* compiled code */] - - [public abstract fun abstractFun(): kotlin.Unit] - - [public open fun openFun(): kotlin.Unit { /* compiled code */ }] -}]] \ No newline at end of file diff --git a/idea/testData/decompiler/navigation/decompiled/ClassWithConstructor.kt b/idea/testData/decompiler/navigation/decompiled/ClassWithConstructor.kt deleted file mode 100644 index 586ff14e935..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/ClassWithConstructor.kt +++ /dev/null @@ -1,10 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries - -[[public final class ClassWithConstructor public constructor(a: kotlin.String, b: kotlin.Any) { - [public constructor(a: kotlin.String) { /* compiled code */ }] - - [public final val a: kotlin.String /* compiled code */] -}]] \ No newline at end of file diff --git a/idea/testData/decompiler/navigation/decompiled/Color.kt b/idea/testData/decompiler/navigation/decompiled/Color.kt deleted file mode 100644 index db00cd43aec..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/Color.kt +++ /dev/null @@ -1,14 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries - -[[public final enum class Color private constructor(rgb: kotlin.Int) : kotlin.Enum { - [[RED,]] - - [[GREEN,]] - - [[BLUE;]] - - [public final val rgb: kotlin.Int /* compiled code */] -}]] \ No newline at end of file diff --git a/idea/testData/decompiler/navigation/decompiled/ExtraKt.kt b/idea/testData/decompiler/navigation/decompiled/ExtraKt.kt deleted file mode 100644 index 2b724092467..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/ExtraKt.kt +++ /dev/null @@ -1,6 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries - -[public fun func(str: kotlin.String): kotlin.Unit { /* compiled code */ }] \ No newline at end of file diff --git a/idea/testData/decompiler/navigation/decompiled/LibrariesPackage.kt b/idea/testData/decompiler/navigation/decompiled/LibrariesPackage.kt deleted file mode 100644 index f19c0eabc34..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/LibrariesPackage.kt +++ /dev/null @@ -1,4 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries \ No newline at end of file diff --git a/idea/testData/decompiler/navigation/decompiled/MainKt.kt b/idea/testData/decompiler/navigation/decompiled/MainKt.kt deleted file mode 100644 index 1ba7ee3ff70..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/MainKt.kt +++ /dev/null @@ -1,36 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries - -[public val globalVal: testData.libraries.Pair /* compiled code */] - -[public val globalValWithGetter: kotlin.Long /* compiled code */] - -[public val kotlin.Int.exProp: kotlin.Int /* compiled code */] - -[public val kotlin.String.exProp: kotlin.String /* compiled code */] - -[public val testData.libraries.Pair.exProp: kotlin.String /* compiled code */] - -[public fun funWithTypeParam(t: T): kotlin.Unit { /* compiled code */ }] - -[public fun funWithTypeParam(t: T): kotlin.Unit { /* compiled code */ }] - -[public fun func(): kotlin.Unit { /* compiled code */ }] - -[public fun func(cs: kotlin.CharSequence): kotlin.Unit { /* compiled code */ }] - -[public fun func(a: kotlin.Int, b: kotlin.Int): kotlin.Unit { /* compiled code */ }] - -[public fun func(a: kotlin.Int, b: kotlin.String /* = compiled code */): kotlin.Unit { /* compiled code */ }] - -[public fun genericFunc(): T { /* compiled code */ }] - -[public fun main(args: kotlin.Array): kotlin.Unit { /* compiled code */ }] - -[public fun processDouble(d: kotlin.Double): kotlin.Unit { /* compiled code */ }] - -[public fun processDouble(d: testData.libraries.Double): kotlin.Unit { /* compiled code */ }] - -[public inline fun T.filter(predicate: (T) -> kotlin.Boolean): T? { /* compiled code */ }] \ No newline at end of file diff --git a/idea/testData/decompiler/navigation/decompiled/NamedObject.kt b/idea/testData/decompiler/navigation/decompiled/NamedObject.kt deleted file mode 100644 index 9113220742a..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/NamedObject.kt +++ /dev/null @@ -1,8 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries - -[[public object NamedObject { - [public final val objectMember: kotlin.Int /* compiled code */] -}]] \ No newline at end of file diff --git a/idea/testData/decompiler/navigation/decompiled/SimpleClass.kt b/idea/testData/decompiler/navigation/decompiled/SimpleClass.kt deleted file mode 100644 index 197aa96b057..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/SimpleClass.kt +++ /dev/null @@ -1,7 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries - -[[public final class SimpleClass public constructor() { -}]] diff --git a/idea/testData/decompiler/navigation/decompiled/SimpleTrait.kt b/idea/testData/decompiler/navigation/decompiled/SimpleTrait.kt deleted file mode 100644 index 0fe88452321..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/SimpleTrait.kt +++ /dev/null @@ -1,7 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries - -[public interface SimpleTrait { -}] diff --git a/idea/testData/decompiler/navigation/decompiled/SimpleTraitImpl.kt b/idea/testData/decompiler/navigation/decompiled/SimpleTraitImpl.kt deleted file mode 100644 index 31b27d1940f..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/SimpleTraitImpl.kt +++ /dev/null @@ -1,7 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries - -[[public final class SimpleTraitImpl public constructor() : testData.libraries.SimpleTrait { -}]] diff --git a/idea/testData/decompiler/navigation/decompiled/WithInnerAndObject.kt b/idea/testData/decompiler/navigation/decompiled/WithInnerAndObject.kt deleted file mode 100644 index 66f16fe39ad..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/WithInnerAndObject.kt +++ /dev/null @@ -1,16 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries - -[[public final class WithInnerAndObject public constructor() { - [[public companion object { - [public final fun foo(): kotlin.Unit { /* compiled code */ }] - }]] - - [[public final class MyInner public constructor() { - [public interface MyInnerInner { - [public abstract fun innerInnerMethod(): kotlin.Unit] - }] - }]] -}]] \ No newline at end of file diff --git a/idea/testData/decompiler/navigation/decompiled/WithTraitClassObject.kt b/idea/testData/decompiler/navigation/decompiled/WithTraitClassObject.kt deleted file mode 100644 index 60461ace207..00000000000 --- a/idea/testData/decompiler/navigation/decompiled/WithTraitClassObject.kt +++ /dev/null @@ -1,9 +0,0 @@ -// IntelliJ API Decompiler stub source generated from a class file -// Implementation of methods is not available - -package testData.libraries - -[[public final class WithTraitClassObject public constructor() { - [[public companion object : testData.libraries.SimpleTrait { - }]] -}]] diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/AbstractInternalCompiledClassesTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/AbstractInternalCompiledClassesTest.kt index e0654682ace..1175c81aef0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/AbstractInternalCompiledClassesTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/AbstractInternalCompiledClassesTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.decompiler import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiManager import org.jetbrains.kotlin.idea.caches.IDEKotlinBinaryClassCache -import org.jetbrains.kotlin.idea.decompiler.navigation.NavigateToDecompiledLibraryTest +import org.jetbrains.kotlin.idea.decompiler.textBuilder.findTestLibraryRoot import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader import org.jetbrains.kotlin.name.ClassId @@ -50,7 +50,7 @@ abstract class AbstractInternalCompiledClassesTest : KotlinLightCodeInsightFixtu } protected fun doTest(fileKind: String, acceptFile: VirtualFile.() -> Boolean, performTest: VirtualFile.() -> Unit) { - val root = NavigateToDecompiledLibraryTest.findTestLibraryRoot(myModule!!)!! + val root = findTestLibraryRoot(myModule!!)!! var foundAtLeastOneFile = false root.checkRecursively { if (acceptFile()) { diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateToDecompiledLibraryTest.java b/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateToDecompiledLibraryTest.java deleted file mode 100644 index 3882c1dd9cc..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/navigation/NavigateToDecompiledLibraryTest.java +++ /dev/null @@ -1,208 +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.google.common.collect.Maps; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.roots.LibraryOrderEntry; -import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.roots.OrderEntry; -import com.intellij.openapi.roots.OrderRootType; -import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.testFramework.LightProjectDescriptor; -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.idea.decompiler.classFile.KtClsFile; -import org.jetbrains.kotlin.idea.test.JdkAndMockLibraryProjectDescriptor; -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; -import org.jetbrains.kotlin.psi.KtDeclaration; -import org.jetbrains.kotlin.psi.KtFile; - -import java.util.Map; - -public class NavigateToDecompiledLibraryTest extends LightCodeInsightFixtureTestCase { - protected static final String PACKAGE = "testData.libraries"; - protected static final String TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/decompiler/navigation"; - - private VirtualFile classFile; - - public void testAbstractClass() { - doTest(); - } - - public void testClassWithAbstractAndOpenMembers() { - doTest(); - } - - public void testColor() { - doTest(); - } - - public void testSimpleClass() { - doTest(); - } - - public void testSimpleTrait() { - doTest(); - } - - public void testSimpleTraitImpl() { - doTest(); - } - - public void testWithInnerAndObject() { - doTest(); - } - - public void testWithTraitClassObject() { - doTest(); - } - - public void testClassWithConstructor() { - doTest(); - } - - public void testNamedObject() { - doTest(); - } - - public void testMainKt() { - doTest(); - } - - public void testExtraKt() { - doTest(); - } - - private void doTest() { - classFile = getClassFile(PACKAGE, getTestName(false), myModule); - PsiFile decompiledPsiFile = PsiManager.getInstance(getProject()).findFile(classFile); - assertNotNull(decompiledPsiFile); - assertTrue("Expecting kotlin class file, was: " + decompiledPsiFile.getClass(), decompiledPsiFile instanceof KtClsFile); - Map map = getRenderedDescriptorToKotlinPsiMap( - (KtFile) decompiledPsiFile, ((KtClsFile) decompiledPsiFile).getRenderedDescriptorsToRange() - ); - String decompiledTextWithMarks = getDecompiledTextWithMarks(map); - - assertSameLinesWithFile(TEST_DATA_PATH + "/decompiled/" + getTestName(false) + ".kt", decompiledTextWithMarks); - } - - private String getDecompiledTextWithMarks(Map map) { - String decompiledText = getDecompiledText(); - - int[] openings = new int[decompiledText.length() + 1]; - int[] closings = new int[decompiledText.length() + 1]; - for (KtDeclaration ktDeclaration : map.values()) { - TextRange textRange = ktDeclaration.getTextRange(); - openings[textRange.getStartOffset()]++; - closings[textRange.getEndOffset()]++; - } - - StringBuilder result = new StringBuilder(); - for (int i = 0; i <= decompiledText.length(); i++) { - result.append(StringUtil.repeat("]", closings[i])); - result.append(StringUtil.repeat("[", openings[i])); - if (i < decompiledText.length()) { - result.append(decompiledText.charAt(i)); - } - } - return result.toString(); - } - - private String getDecompiledText() { - Document document = FileDocumentManager.getInstance().getDocument(classFile); - assertNotNull(document); - return document.getText(); - } - - @NotNull - private static Map getRenderedDescriptorToKotlinPsiMap( - @NotNull KtFile file, @NotNull Map renderedDescriptorsToRanges - ) { - Map renderedDescriptorsToJetDeclarations = Maps.newHashMap(); - for (Map.Entry renderedDescriptorToRange : renderedDescriptorsToRanges.entrySet()) { - String renderedDescriptor = renderedDescriptorToRange.getKey(); - TextRange range = renderedDescriptorToRange.getValue(); - KtDeclaration ktDeclaration = PsiTreeUtil.findElementOfClassAtRange(file, range.getStartOffset(), range.getEndOffset(), - KtDeclaration.class); - assert ktDeclaration != null : "Can't find declaration at " + range + ": " - + file.getText().substring(range.getStartOffset(), range.getEndOffset()); - renderedDescriptorsToJetDeclarations.put(renderedDescriptor, ktDeclaration); - } - return renderedDescriptorsToJetDeclarations; - } - - @NotNull - @Override - protected LightProjectDescriptor getProjectDescriptor() { - return new JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/library", false); - } - - @NotNull - public static VirtualFile getClassFile( - @NotNull String packageName, - @NotNull String className, - @NotNull Module module - ) { - VirtualFile root = findTestLibraryRoot(module); - assertNotNull(root); - VirtualFile packageDir = root.findFileByRelativePath(packageName.replace(".", "/")); - assertNotNull(packageDir); - VirtualFile classFile = packageDir.findChild(className + ".class"); - assertNotNull(classFile); - return classFile; - } - - @NotNull - public static VirtualFile getKjsmFile( - @NotNull String packageName, - @NotNull String className, - @NotNull Module module - ) { - VirtualFile root = findTestLibraryRoot(module); - assertNotNull(root); - root.refresh(false, true); - VirtualFile packageDir = root.findFileByRelativePath(JdkAndMockLibraryProjectDescriptor.LIBRARY_NAME + "/" + packageName.replace(".", "/")); - assertNotNull(packageDir); - VirtualFile classFile = packageDir.findChild(className + ".kjsm"); - assertNotNull(classFile); - return classFile; - } - - @Nullable - public static VirtualFile findTestLibraryRoot(@NotNull Module module) { - for (OrderEntry orderEntry : ModuleRootManager.getInstance(module).getOrderEntries()) { - if (orderEntry instanceof LibraryOrderEntry) { - return findTestLibraryRoot((LibraryOrderEntry) orderEntry); - } - } - return null; - } - - @NotNull - private static VirtualFile findTestLibraryRoot(@NotNull LibraryOrderEntry library) { - return library.getFiles(OrderRootType.CLASSES)[0]; - } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubForWrongAbiVersionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubForWrongAbiVersionTest.kt index 846cb814f12..161114b1eed 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubForWrongAbiVersionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubForWrongAbiVersionTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -17,10 +17,10 @@ package org.jetbrains.kotlin.idea.decompiler.stubBuilder import com.intellij.testFramework.LightProjectDescriptor +import org.jetbrains.kotlin.idea.decompiler.textBuilder.findTestLibraryRoot import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor -import java.io.File -import org.jetbrains.kotlin.idea.decompiler.navigation.NavigateToDecompiledLibraryTest import org.jetbrains.kotlin.test.KotlinTestUtils +import java.io.File class ClsStubBuilderForWrongAbiVersionTest : AbstractClsStubBuilderTest() { @@ -29,7 +29,7 @@ class ClsStubBuilderForWrongAbiVersionTest : AbstractClsStubBuilderTest() { fun testClass() = testStubsForFileWithWrongAbiVersion("ClassWithWrongAbiVersion") private fun testStubsForFileWithWrongAbiVersion(className: String) { - val root = NavigateToDecompiledLibraryTest.findTestLibraryRoot(myModule!!)!! + val root = findTestLibraryRoot(myModule!!)!! val result = root.findClassFileByName(className) testClsStubsForFile(result, null) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/AbstractDecompiledTextFromJsMetadataTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/AbstractDecompiledTextFromJsMetadataTest.kt index b5acf0683fd..a26031316b0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/AbstractDecompiledTextFromJsMetadataTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/AbstractDecompiledTextFromJsMetadataTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -16,17 +16,17 @@ package org.jetbrains.kotlin.idea.decompiler.textBuilder +import com.intellij.openapi.module.Module import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiFile import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile -import org.jetbrains.kotlin.idea.decompiler.navigation.NavigateToDecompiledLibraryTest +import org.jetbrains.kotlin.idea.test.JdkAndMockLibraryProjectDescriptor import org.jetbrains.kotlin.idea.test.ModuleKind import org.jetbrains.kotlin.idea.test.configureAs import kotlin.test.assertTrue abstract class AbstractDecompiledTextFromJsMetadataTest(baseDirectory: String) : AbstractDecompiledTextBaseTest(baseDirectory, true) { - override fun getFileToDecompile(): VirtualFile = - NavigateToDecompiledLibraryTest.getKjsmFile(TEST_PACKAGE, getTestName(false), myModule!!) + override fun getFileToDecompile(): VirtualFile = getKjsmFile(TEST_PACKAGE, getTestName(false), myModule!!) override fun checkPsiFile(psiFile: PsiFile) = assertTrue(psiFile is KtDecompiledFile, "Expecting decompiled kotlin javascript file, was: " + psiFile.javaClass) @@ -40,3 +40,14 @@ abstract class AbstractDecompiledTextFromJsMetadataTest(baseDirectory: String) : abstract class AbstractCommonDecompiledTextFromJsMetadataTest : AbstractDecompiledTextFromJsMetadataTest("/decompiler/decompiledText") abstract class AbstractJsDecompiledTextFromJsMetadataTest : AbstractDecompiledTextFromJsMetadataTest("/decompiler/decompiledTextJs") + +fun getKjsmFile( + packageName: String, + className: String, + module: Module +): VirtualFile { + val root = findTestLibraryRoot(module)!! + root.refresh(false, true) + val packageDir = root.findFileByRelativePath(JdkAndMockLibraryProjectDescriptor.LIBRARY_NAME + "/" + packageName.replace(".", "/"))!! + return packageDir.findChild(className + ".kjsm")!! +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/AbstractDecompiledTextTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/AbstractDecompiledTextTest.kt index 4c371e2ec06..9c7abcb8311 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/AbstractDecompiledTextTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/AbstractDecompiledTextTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -16,16 +16,18 @@ package org.jetbrains.kotlin.idea.decompiler.textBuilder +import com.intellij.openapi.module.Module +import com.intellij.openapi.roots.LibraryOrderEntry +import com.intellij.openapi.roots.ModuleRootManager +import com.intellij.openapi.roots.OrderRootType import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiFile import org.jetbrains.kotlin.idea.decompiler.classFile.KtClsFile -import org.jetbrains.kotlin.idea.decompiler.navigation.NavigateToDecompiledLibraryTest import kotlin.test.assertTrue abstract class AbstractDecompiledTextTest(baseDirectory: String, allowKotlinPackage: Boolean) : AbstractDecompiledTextBaseTest(baseDirectory, allowKotlinPackage = allowKotlinPackage) { - override fun getFileToDecompile(): VirtualFile = - NavigateToDecompiledLibraryTest.getClassFile(TEST_PACKAGE, getTestName(false), myModule!!) + override fun getFileToDecompile(): VirtualFile = getClassFile(TEST_PACKAGE, getTestName(false), myModule!!) override fun checkPsiFile(psiFile: PsiFile) = assertTrue(psiFile is KtClsFile, "Expecting decompiled kotlin file, was: " + psiFile.javaClass) @@ -34,3 +36,22 @@ abstract class AbstractDecompiledTextTest(baseDirectory: String, allowKotlinPack abstract class AbstractCommonDecompiledTextTest : AbstractDecompiledTextTest("/decompiler/decompiledText", true) abstract class AbstractJvmDecompiledTextTest : AbstractDecompiledTextTest("/decompiler/decompiledTextJvm", false) + +fun findTestLibraryRoot(module: Module): VirtualFile? { + for (orderEntry in ModuleRootManager.getInstance(module).orderEntries) { + if (orderEntry is LibraryOrderEntry) { + return orderEntry.getFiles(OrderRootType.CLASSES)[0] + } + } + return null +} + +fun getClassFile( + packageName: String, + className: String, + module: Module +): VirtualFile { + val root = findTestLibraryRoot(module)!! + val packageDir = root.findFileByRelativePath(packageName.replace(".", "/"))!! + return packageDir.findChild(className + ".class")!! +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextForWrongAbiVersionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextForWrongAbiVersionTest.kt index 2b9755b380b..c293f78824a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextForWrongAbiVersionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextForWrongAbiVersionTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -22,7 +22,6 @@ import com.intellij.testFramework.LightProjectDescriptor import org.jetbrains.kotlin.idea.decompiler.AbstractInternalCompiledClassesTest import org.jetbrains.kotlin.idea.decompiler.classFile.KtClsFile import org.jetbrains.kotlin.idea.decompiler.common.INCOMPATIBLE_ABI_VERSION_GENERAL_COMMENT -import org.jetbrains.kotlin.idea.decompiler.navigation.NavigateToDecompiledLibraryTest import org.jetbrains.kotlin.idea.decompiler.stubBuilder.findClassFileByName import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor import org.jetbrains.kotlin.test.KotlinTestUtils @@ -42,7 +41,7 @@ class DecompiledTextForWrongAbiVersionTest : AbstractInternalCompiledClassesTest fun testPackagePartWithWrongAbiVersion() = doTest("Wrong_packageKt") fun doTest(name: String) { - val root = NavigateToDecompiledLibraryTest.findTestLibraryRoot(myModule!!)!! + val root = findTestLibraryRoot(myModule!!)!! checkFileWithWrongAbiVersion(root.findClassFileByName(name)) }