A test for the case of finding binary class for a nested Java class
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package test
|
||||
|
||||
class A {
|
||||
class B {
|
||||
class C {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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("<empty-for-test>");
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user