diff --git a/compiler/testData/kotlinClassFinder/nestedClass.kt b/compiler/testData/kotlinClassFinder/nestedClass.kt new file mode 100644 index 00000000000..f490cddee17 --- /dev/null +++ b/compiler/testData/kotlinClassFinder/nestedClass.kt @@ -0,0 +1,8 @@ +package test + +class A { + class B { + class C { + } + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/JetTestUtils.java b/compiler/tests/org/jetbrains/jet/JetTestUtils.java index 96d2e189cf0..667dabd3179 100644 --- a/compiler/tests/org/jetbrains/jet/JetTestUtils.java +++ b/compiler/tests/org/jetbrains/jet/JetTestUtils.java @@ -307,6 +307,7 @@ public class JetTestUtils { } } + @NotNull public static File tmpDirForTest(TestCase test) throws IOException { File answer = FileUtil.createTempDirectory(test.getClass().getSimpleName(), test.getName()); deleteOnShutdown(answer); @@ -782,6 +783,7 @@ public class JetTestUtils { return jetFiles; } + @NotNull public static ModuleDescriptorImpl createEmptyModule() { return createEmptyModule(""); } diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/KotlinClassFinderTest.kt b/compiler/tests/org/jetbrains/jet/jvm/compiler/KotlinClassFinderTest.kt new file mode 100644 index 00000000000..0bbf0f5043c --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/KotlinClassFinderTest.kt @@ -0,0 +1,54 @@ +/* + * 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.jvm.compiler + +import org.jetbrains.jet.KotlinTestWithEnvironmentManagement +import org.jetbrains.jet.JetTestUtils +import java.io.File +import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment +import org.jetbrains.jet.ConfigurationKind +import org.jetbrains.jet.TestJdkKind +import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder +import com.intellij.psi.JavaPsiFacade +import com.intellij.psi.search.GlobalSearchScope +import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaClassImpl +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +public class KotlinClassFinderTest : KotlinTestWithEnvironmentManagement() { + fun testNestedClass() { + val tmpdir = JetTestUtils.tmpDirForTest(this) + JetTestUtils.compileKotlinWithJava( + listOf(), listOf(File("compiler/testData/kotlinClassFinder/nestedClass.kt")), tmpdir, getTestRootDisposable()!! + ) + + val environment = JetCoreEnvironment.createForTests(getTestRootDisposable()!!, + JetTestUtils.compilerConfigurationForTests( + ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, tmpdir)) + + val project = environment.getProject() + val className = "test.A.B.C" + val psiClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project)) + assertNotNull(psiClass, "Psi class not found for $className") + + val binaryClass = VirtualFileFinder.SERVICE.getInstance(project).findKotlinClass(JavaClassImpl(psiClass!!)) + assertNotNull(binaryClass, "No binary class for $className") + + assertEquals("test/A\$B\$C", binaryClass?.getClassName()?.getInternalName()) + } +} +