Add test for decompiled text
This commit is contained in:
@@ -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<String>) {
|
||||
System.setProperty("java.awt.headless", "true")
|
||||
@@ -507,6 +508,10 @@ fun main(args: Array<String>) {
|
||||
testClass(javaClass<AbstractExpressionSelectionTest>()) {
|
||||
model("expressionSelection", testMethod = "doTestExpressionSelection", pattern = """^([^\.]+)\.kt$""")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractDecompiledTextTest>()) {
|
||||
model("libraries/decompiledText", pattern = """^([^\.]+)$""")
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("j2k/tests/test", "j2k/tests/testData") {
|
||||
|
||||
@@ -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 */ }
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package dependency
|
||||
|
||||
annotation class A(val s: String)
|
||||
annotation class B(val i: Int)
|
||||
annotation class C
|
||||
@@ -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 <T, K, G> 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 */ }
|
||||
}
|
||||
@@ -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 <T, K, G> complexFun(a: T, b: K, c: G): G {
|
||||
throw AssertionError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
}
|
||||
|
||||
class A {
|
||||
}
|
||||
@@ -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<test.Enum>, dependency.Tr {
|
||||
ONE
|
||||
|
||||
THREE
|
||||
|
||||
TWO
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package dependency
|
||||
|
||||
trait Tr {
|
||||
fun f() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package test
|
||||
|
||||
import dependency.*
|
||||
|
||||
public enum class Enum : Tr {
|
||||
ONE
|
||||
TWO
|
||||
THREE {
|
||||
fun g() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 <T, K, G> 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 */ }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package test
|
||||
|
||||
object Object {
|
||||
fun f() {
|
||||
}
|
||||
|
||||
fun Int.f() {
|
||||
}
|
||||
|
||||
private fun privateFun() {
|
||||
}
|
||||
|
||||
val Int.g: Int
|
||||
get() = this + 2
|
||||
|
||||
fun <T, K, G> complexFun(a: T, b: K, c: G): G {
|
||||
throw AssertionError()
|
||||
}
|
||||
}
|
||||
@@ -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.Int>, dependency.Tr, kotlin.List<kotlin.String> {
|
||||
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 <T, K, G> 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.String, dependency.Tr>): kotlin.List<dependency.D<dependency.A, kotlin.Int>> { /* compiled code */ }
|
||||
|
||||
private final fun privateFun(): kotlin.Unit { /* compiled code */ }
|
||||
|
||||
internal final fun kotlin.Int.f(): kotlin.Unit { /* compiled code */ }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package dependency
|
||||
|
||||
class B {
|
||||
}
|
||||
|
||||
class A {
|
||||
}
|
||||
|
||||
open class D<T, G> {
|
||||
}
|
||||
|
||||
trait Tr {
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package test
|
||||
|
||||
import dependency.*
|
||||
|
||||
abstract class SimpleClass: D<Tr, Int>(), Tr, List<String> {
|
||||
fun f() {
|
||||
}
|
||||
|
||||
fun g(d: D<String, Tr>): List<D<A, Int>> {
|
||||
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 <T, K, G> complexFun(a: T, b: K, c: G): G {
|
||||
throw AssertionError()
|
||||
}
|
||||
}
|
||||
@@ -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 */ }
|
||||
|
||||
@@ -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
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+28
-22
@@ -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<String, JetDeclaration> 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<String, JetDeclaration> getRenderedDescriptorToKotlinPsiMap(
|
||||
@NotNull JetFile file, @NotNull Map<String, TextRange> 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user