diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index 2fd7d21162a..83e49433457 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -97,6 +97,7 @@ import org.jetbrains.jet.resolve.AbstractReferenceToJavaWithWrongFileStructureTe import org.jetbrains.jet.plugin.navigation.AbstractKotlinGotoTest import org.jetbrains.jet.plugin.AbstractExpressionSelectionTest import org.jetbrains.jet.plugin.refactoring.move.AbstractJetMoveTest +import org.jetbrains.jet.plugin.libraries.AbstractDecompiledTextTest fun main(args: Array) { System.setProperty("java.awt.headless", "true") @@ -507,6 +508,10 @@ fun main(args: Array) { testClass(javaClass()) { model("expressionSelection", testMethod = "doTestExpressionSelection", pattern = """^([^\.]+)\.kt$""") } + + testClass(javaClass()) { + model("libraries/decompiledText", pattern = """^([^\.]+)$""") + } } testGroup("j2k/tests/test", "j2k/tests/testData") { diff --git a/idea/testData/libraries/decompiledText/Annotations.expected.kt b/idea/testData/libraries/decompiledText/Annotations.expected.kt new file mode 100644 index 00000000000..122ea1053fb --- /dev/null +++ b/idea/testData/libraries/decompiledText/Annotations.expected.kt @@ -0,0 +1,10 @@ +// IntelliJ API Decompiler stub source generated from a class file +// Implementation of methods is not available + +package test + +kotlin.data dependency.A dependency.B dependency.C internal final class Annotations() { + kotlin.inline dependency.A dependency.B dependency.C internal final val p: kotlin.Int /* compiled code */ + + kotlin.inline dependency.A dependency.B dependency.C internal final fun f(dependency.A dependency.B dependency.C kotlin.deprecated i: kotlin.Int): kotlin.Unit { /* compiled code */ } +} diff --git a/idea/testData/libraries/decompiledText/Annotations/Annotations.kt b/idea/testData/libraries/decompiledText/Annotations/Annotations.kt new file mode 100644 index 00000000000..245b6dcbfa6 --- /dev/null +++ b/idea/testData/libraries/decompiledText/Annotations/Annotations.kt @@ -0,0 +1,11 @@ +package test + +import dependency.* + +data A("a") B(1) C class Annotations { + + inline A("f") B(2) C fun f(A("i") B(3) C deprecated("1") i: Int) { + } + + inline A("p") B(3) C val p: Int = 2 +} diff --git a/idea/testData/libraries/decompiledText/Annotations/Dependency.kt b/idea/testData/libraries/decompiledText/Annotations/Dependency.kt new file mode 100644 index 00000000000..2142cdf131e --- /dev/null +++ b/idea/testData/libraries/decompiledText/Annotations/Dependency.kt @@ -0,0 +1,5 @@ +package dependency + +annotation class A(val s: String) +annotation class B(val i: Int) +annotation class C diff --git a/idea/testData/libraries/decompiledText/ClassWithClassObject.expected.kt b/idea/testData/libraries/decompiledText/ClassWithClassObject.expected.kt new file mode 100644 index 00000000000..da625e6e2b8 --- /dev/null +++ b/idea/testData/libraries/decompiledText/ClassWithClassObject.expected.kt @@ -0,0 +1,24 @@ +// IntelliJ API Decompiler stub source generated from a class file +// Implementation of methods is not available + +package test + +internal final class ClassWithClassObject() { + internal class object { + internal final val a: test.A /* compiled code */ + + public final var b: test.B /* compiled code */ + + internal final val kotlin.Int.g: kotlin.Int /* compiled code */ + + internal final fun complexFun(a: T, b: K, c: G): G { /* compiled code */ } + + internal final fun f(): kotlin.Unit { /* compiled code */ } + + private final fun privateFun(): kotlin.Unit { /* compiled code */ } + + internal final fun kotlin.Int.f(): kotlin.Unit { /* compiled code */ } + } + + internal final fun f(): kotlin.Unit { /* compiled code */ } +} diff --git a/idea/testData/libraries/decompiledText/ClassWithClassObject/ClassWithClassObject.kt b/idea/testData/libraries/decompiledText/ClassWithClassObject/ClassWithClassObject.kt new file mode 100644 index 00000000000..40a40cd6aa2 --- /dev/null +++ b/idea/testData/libraries/decompiledText/ClassWithClassObject/ClassWithClassObject.kt @@ -0,0 +1,34 @@ +package test + +class ClassWithClassObject { + fun f() { + } + + class object { + fun f() { + } + + fun Int.f() { + } + + private fun privateFun() { + } + + val a: A = A() + + public var b: B = B() + + val Int.g: Int + get() = this + 2 + + fun complexFun(a: T, b: K, c: G): G { + throw AssertionError() + } + } +} + +class B { +} + +class A { +} diff --git a/idea/testData/libraries/decompiledText/Enum.expected.kt b/idea/testData/libraries/decompiledText/Enum.expected.kt new file mode 100644 index 00000000000..04cc19a3255 --- /dev/null +++ b/idea/testData/libraries/decompiledText/Enum.expected.kt @@ -0,0 +1,12 @@ +// IntelliJ API Decompiler stub source generated from a class file +// Implementation of methods is not available + +package test + +public final enum class Enum() : kotlin.Enum, dependency.Tr { + ONE + + THREE + + TWO +} diff --git a/idea/testData/libraries/decompiledText/Enum/Dependency.kt b/idea/testData/libraries/decompiledText/Enum/Dependency.kt new file mode 100644 index 00000000000..1a3c2a306f0 --- /dev/null +++ b/idea/testData/libraries/decompiledText/Enum/Dependency.kt @@ -0,0 +1,6 @@ +package dependency + +trait Tr { + fun f() { + } +} diff --git a/idea/testData/libraries/decompiledText/Enum/Enum.kt b/idea/testData/libraries/decompiledText/Enum/Enum.kt new file mode 100644 index 00000000000..2594d74c45b --- /dev/null +++ b/idea/testData/libraries/decompiledText/Enum/Enum.kt @@ -0,0 +1,12 @@ +package test + +import dependency.* + +public enum class Enum : Tr { + ONE + TWO + THREE { + fun g() { + } + } +} diff --git a/idea/testData/libraries/decompiledText/NestedClasses.expected.kt b/idea/testData/libraries/decompiledText/NestedClasses.expected.kt new file mode 100644 index 00000000000..d987b06ba7f --- /dev/null +++ b/idea/testData/libraries/decompiledText/NestedClasses.expected.kt @@ -0,0 +1,28 @@ +// IntelliJ API Decompiler stub source generated from a class file +// Implementation of methods is not available + +package test + +internal final class NestedClasses() { + internal final fun f(): kotlin.Unit { /* compiled code */ } + + public final inner class Inner() { + internal final fun f(): kotlin.Unit { /* compiled code */ } + + private final inner class II() { + internal final fun f(): kotlin.Unit { /* compiled code */ } + } + } + + private final class Nested() { + internal final fun f(): kotlin.Unit { /* compiled code */ } + + internal final inner class NI() { + internal final fun f(): kotlin.Unit { /* compiled code */ } + } + + public final class NN() { + internal final fun f(): kotlin.Unit { /* compiled code */ } + } + } +} diff --git a/idea/testData/libraries/decompiledText/NestedClasses/NestedClasses.kt b/idea/testData/libraries/decompiledText/NestedClasses/NestedClasses.kt new file mode 100644 index 00000000000..695cf9ce6bb --- /dev/null +++ b/idea/testData/libraries/decompiledText/NestedClasses/NestedClasses.kt @@ -0,0 +1,31 @@ +package test + +class NestedClasses { + fun f() { + } + + private class Nested { + fun f() { + } + + public class NN { + fun f() { + } + } + + inner class NI { + fun f() { + } + } + } + + public inner class Inner { + fun f() { + } + + private inner class II { + fun f() { + } + } + } +} diff --git a/idea/testData/libraries/decompiledText/Object.expected.kt b/idea/testData/libraries/decompiledText/Object.expected.kt new file mode 100644 index 00000000000..1b82367657f --- /dev/null +++ b/idea/testData/libraries/decompiledText/Object.expected.kt @@ -0,0 +1,16 @@ +// IntelliJ API Decompiler stub source generated from a class file +// Implementation of methods is not available + +package test + +internal object Object { + internal final val kotlin.Int.g: kotlin.Int /* compiled code */ + + internal final fun complexFun(a: T, b: K, c: G): G { /* compiled code */ } + + internal final fun f(): kotlin.Unit { /* compiled code */ } + + private final fun privateFun(): kotlin.Unit { /* compiled code */ } + + internal final fun kotlin.Int.f(): kotlin.Unit { /* compiled code */ } +} diff --git a/idea/testData/libraries/decompiledText/Object/Object.kt b/idea/testData/libraries/decompiledText/Object/Object.kt new file mode 100644 index 00000000000..b9908005c71 --- /dev/null +++ b/idea/testData/libraries/decompiledText/Object/Object.kt @@ -0,0 +1,19 @@ +package test + +object Object { + fun f() { + } + + fun Int.f() { + } + + private fun privateFun() { + } + + val Int.g: Int + get() = this + 2 + + fun complexFun(a: T, b: K, c: G): G { + throw AssertionError() + } +} diff --git a/idea/testData/libraries/decompiledText/SimpleClass.expected.kt b/idea/testData/libraries/decompiledText/SimpleClass.expected.kt new file mode 100644 index 00000000000..30b5116a6a6 --- /dev/null +++ b/idea/testData/libraries/decompiledText/SimpleClass.expected.kt @@ -0,0 +1,22 @@ +// IntelliJ API Decompiler stub source generated from a class file +// Implementation of methods is not available + +package test + +internal abstract class SimpleClass() : dependency.D, dependency.Tr, kotlin.List { + internal final val a: dependency.A /* compiled code */ + + public final var b: dependency.B /* compiled code */ + + internal final val kotlin.Int.g: kotlin.Int /* compiled code */ + + internal final fun complexFun(a: T, b: K, c: G): G { /* compiled code */ } + + internal final fun f(): kotlin.Unit { /* compiled code */ } + + internal final fun g(d: dependency.D): kotlin.List> { /* compiled code */ } + + private final fun privateFun(): kotlin.Unit { /* compiled code */ } + + internal final fun kotlin.Int.f(): kotlin.Unit { /* compiled code */ } +} \ No newline at end of file diff --git a/idea/testData/libraries/decompiledText/SimpleClass/Dependency.kt b/idea/testData/libraries/decompiledText/SimpleClass/Dependency.kt new file mode 100644 index 00000000000..56b902d82e9 --- /dev/null +++ b/idea/testData/libraries/decompiledText/SimpleClass/Dependency.kt @@ -0,0 +1,13 @@ +package dependency + +class B { +} + +class A { +} + +open class D { +} + +trait Tr { +} diff --git a/idea/testData/libraries/decompiledText/SimpleClass/SimpleClass.kt b/idea/testData/libraries/decompiledText/SimpleClass/SimpleClass.kt new file mode 100644 index 00000000000..88c60204bb4 --- /dev/null +++ b/idea/testData/libraries/decompiledText/SimpleClass/SimpleClass.kt @@ -0,0 +1,29 @@ +package test + +import dependency.* + +abstract class SimpleClass: D(), Tr, List { + fun f() { + } + + fun g(d: D): List> { + throw AssertionError() + } + + fun Int.f() { + } + + private fun privateFun() { + } + + val a: A = A() + + public var b: B = B() + + val Int.g: Int + get() = this + 2 + + fun complexFun(a: T, b: K, c: G): G { + throw AssertionError() + } +} diff --git a/idea/testData/libraries/decompiledText/TestPackage.expected.kt b/idea/testData/libraries/decompiledText/TestPackage.expected.kt new file mode 100644 index 00000000000..3b804df0791 --- /dev/null +++ b/idea/testData/libraries/decompiledText/TestPackage.expected.kt @@ -0,0 +1,13 @@ +// IntelliJ API Decompiler stub source generated from a class file +// Implementation of methods is not available + +package test + +private var i: kotlin.Int /* compiled code */ + +internal val p: kotlin.Int /* compiled code */ + +internal fun f(): kotlin.Unit { /* compiled code */ } + +internal fun kotlin.Int.plus(i: kotlin.Int): kotlin.Int { /* compiled code */ } + diff --git a/idea/testData/libraries/decompiledText/TestPackage/TestPackage.kt b/idea/testData/libraries/decompiledText/TestPackage/TestPackage.kt new file mode 100644 index 00000000000..8517a8330c9 --- /dev/null +++ b/idea/testData/libraries/decompiledText/TestPackage/TestPackage.kt @@ -0,0 +1,10 @@ +package test + +fun f() {} +val p = 3 +private var i = 2 + +fun Int.plus(i: Int) = this + i + +class ShouldNotBeVisible1 +trait ShouldNotBeVisible2 diff --git a/idea/tests/org/jetbrains/jet/plugin/JetLightCodeInsightFixtureTestCase.java b/idea/tests/org/jetbrains/jet/plugin/JetLightCodeInsightFixtureTestCase.java index 1dc44929210..b21ac2ed938 100644 --- a/idea/tests/org/jetbrains/jet/plugin/JetLightCodeInsightFixtureTestCase.java +++ b/idea/tests/org/jetbrains/jet/plugin/JetLightCodeInsightFixtureTestCase.java @@ -46,7 +46,7 @@ public abstract class JetLightCodeInsightFixtureTestCase extends LightCodeInsigh } protected LightProjectDescriptor getProjectDescriptorFromFileDirective() { - if (!getTestName(false).startsWith("AllFilesPresentIn")) { + if (!isAllFilesPresentInTest()) { try { String fileText = FileUtil.loadFile(new File(getTestDataPath(), fileName())); @@ -69,6 +69,10 @@ public abstract class JetLightCodeInsightFixtureTestCase extends LightCodeInsigh return JetLightProjectDescriptor.INSTANCE; } + protected boolean isAllFilesPresentInTest() { + return getTestName(false).startsWith("AllFilesPresentIn"); + } + protected String fileName() { return getTestName(false) + ".kt"; } diff --git a/idea/tests/org/jetbrains/jet/plugin/libraries/AbstractDecompiledTextTest.kt b/idea/tests/org/jetbrains/jet/plugin/libraries/AbstractDecompiledTextTest.kt new file mode 100644 index 00000000000..1b53753df28 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/libraries/AbstractDecompiledTextTest.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2014 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.libraries + +import com.intellij.psi.PsiManager +import com.intellij.psi.impl.compiled.ClsFileImpl +import com.intellij.testFramework.LightProjectDescriptor +import org.jetbrains.jet.plugin.JdkAndMockLibraryProjectDescriptor +import org.jetbrains.jet.plugin.PluginTestCaseBase +import com.intellij.testFramework.UsefulTestCase.* +import junit.framework.Assert.* +import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase +import org.jetbrains.jet.plugin.JetLightProjectDescriptor + +public abstract class AbstractDecompiledTextTest() : JetLightCodeInsightFixtureTestCase() { + + private val TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/libraries/decompiledText" + + public fun doTest(path: String) { + val classFile = NavigateToDecompiledLibraryTest.getClassFile("test", getTestName(false), myModule!!) + val clsFileForClassFile = PsiManager.getInstance(getProject()!!).findFile(classFile) + assertNotNull(clsFileForClassFile) + assertTrue("Expecting java class file, was: " + clsFileForClassFile!!.getClass(), clsFileForClassFile is ClsFileImpl) + val decompiledPsiFile = (clsFileForClassFile as ClsFileImpl).getDecompiledPsiFile() + assertNotNull(decompiledPsiFile) + assertSameLinesWithFile(path + ".expected.kt", decompiledPsiFile!!.getText()) + } + + override fun getProjectDescriptor(): LightProjectDescriptor { + if (isAllFilesPresentInTest()) { + return JetLightProjectDescriptor.INSTANCE + } + return JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/" + getTestName(false), false) + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/libraries/DecompiledTextTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/libraries/DecompiledTextTestGenerated.java new file mode 100644 index 00000000000..cf7fe938db2 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/libraries/DecompiledTextTestGenerated.java @@ -0,0 +1,80 @@ +/* + * Copyright 2010-2014 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.libraries; + +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestSuite; + +import java.io.File; +import java.util.regex.Pattern; +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.InnerTestClasses; +import org.jetbrains.jet.test.TestMetadata; + +import org.jetbrains.jet.plugin.libraries.AbstractDecompiledTextTest; + +/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("idea/testData/libraries/decompiledText") +@InnerTestClasses({}) +public class DecompiledTextTestGenerated extends AbstractDecompiledTextTest { + public void testAllFilesPresentInDecompiledText() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/libraries/decompiledText"), Pattern.compile("^([^\\.]+)$"), true); + } + + @TestMetadata("Annotations") + public void testAnnotations() throws Exception { + doTest("idea/testData/libraries/decompiledText/Annotations"); + } + + @TestMetadata("ClassWithClassObject") + public void testClassWithClassObject() throws Exception { + doTest("idea/testData/libraries/decompiledText/ClassWithClassObject"); + } + + @TestMetadata("Enum") + public void testEnum() throws Exception { + doTest("idea/testData/libraries/decompiledText/Enum"); + } + + @TestMetadata("NestedClasses") + public void testNestedClasses() throws Exception { + doTest("idea/testData/libraries/decompiledText/NestedClasses"); + } + + @TestMetadata("Object") + public void testObject() throws Exception { + doTest("idea/testData/libraries/decompiledText/Object"); + } + + @TestMetadata("SimpleClass") + public void testSimpleClass() throws Exception { + doTest("idea/testData/libraries/decompiledText/SimpleClass"); + } + + @TestMetadata("TestPackage") + public void testTestPackage() throws Exception { + doTest("idea/testData/libraries/decompiledText/TestPackage"); + } + + public static Test suite() { + TestSuite suite = new TestSuite("DecompiledTextTestGenerated"); + suite.addTestSuite(DecompiledTextTestGenerated.class); + return suite; + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToDecompiledLibraryTest.java b/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToDecompiledLibraryTest.java index d26f18fdc43..76f6442e68e 100644 --- a/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToDecompiledLibraryTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToDecompiledLibraryTest.java @@ -19,6 +19,7 @@ package org.jetbrains.jet.plugin.libraries; 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; @@ -84,7 +85,7 @@ public class NavigateToDecompiledLibraryTest extends AbstractNavigateToLibraryTe } private void doTest() { - classFile = getClassFile(); + classFile = getClassFile(PACKAGE, getTestName(false), myModule); JetDecompiledData decompiledData = JetDecompiledData.getDecompiledData(classFile, getProject()); Map map = getRenderedDescriptorToKotlinPsiMap(decompiledData.getFile(), decompiledData.getRenderedDescriptorsToRanges()); @@ -121,27 +122,6 @@ public class NavigateToDecompiledLibraryTest extends AbstractNavigateToLibraryTe return document.getText(); } - @Nullable - private LibraryOrderEntry findOurTestLibrary() { - for (OrderEntry orderEntry : ModuleRootManager.getInstance(myModule).getOrderEntries()) { - if (orderEntry instanceof LibraryOrderEntry) { - return (LibraryOrderEntry) orderEntry; - } - } - return null; - } - - private VirtualFile getClassFile() { - LibraryOrderEntry library = findOurTestLibrary(); - assertNotNull(library); - - VirtualFile packageDir = library.getFiles(OrderRootType.CLASSES)[0].findFileByRelativePath(PACKAGE.replace(".", "/")); - assertNotNull(packageDir); - VirtualFile classFile = packageDir.findChild(getTestName(false) + ".class"); - assertNotNull(classFile); - return classFile; - } - @NotNull private static Map getRenderedDescriptorToKotlinPsiMap( @NotNull JetFile file, @NotNull Map renderedDescriptorsToRanges @@ -164,4 +144,30 @@ public class NavigateToDecompiledLibraryTest extends AbstractNavigateToLibraryTe protected LightProjectDescriptor getProjectDescriptor() { return new JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/library", false); } + + @Nullable + private static LibraryOrderEntry findOurTestLibrary(@NotNull Module module) { + for (OrderEntry orderEntry : ModuleRootManager.getInstance(module).getOrderEntries()) { + if (orderEntry instanceof LibraryOrderEntry) { + return (LibraryOrderEntry) orderEntry; + } + } + return null; + } + + @NotNull + /*package*/ static VirtualFile getClassFile( + @NotNull String packageName, + @NotNull String className, + @NotNull Module module + ) { + LibraryOrderEntry library = findOurTestLibrary(module); + assertNotNull(library); + + VirtualFile packageDir = library.getFiles(OrderRootType.CLASSES)[0].findFileByRelativePath(packageName.replace(".", "/")); + assertNotNull(packageDir); + VirtualFile classFile = packageDir.findChild(className + ".class"); + assertNotNull(classFile); + return classFile; + } } \ No newline at end of file