diff --git a/.idea/modules.xml b/.idea/modules.xml index 4fbb42c66d3..3585088a404 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -64,6 +64,7 @@ + diff --git a/build.xml b/build.xml index 3ff430ebb51..dbddee457bf 100644 --- a/build.xml +++ b/build.xml @@ -22,6 +22,9 @@ + + + @@ -56,6 +59,7 @@ + @@ -85,6 +89,7 @@ + @@ -140,6 +145,7 @@ + @@ -235,6 +241,7 @@ + diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java index 1d4d42b6022..58e02f37993 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java @@ -137,6 +137,16 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments { ) public String[] scriptResolverEnvironment; + // Javac options + @Argument(value = "-Xuse-javac", description = "Use javac for Java source and class files analysis") + public boolean useJavac; + + @Argument( + value = "-Xjavac-arguments", + valueDescription = "", + description = "Java compiler arguments") + public String[] javacArguments; + // Paths to output directories for friend modules. public String[] friendPaths; diff --git a/compiler/cli/cli.iml b/compiler/cli/cli.iml index c7a97a3796a..d9040ff4b01 100644 --- a/compiler/cli/cli.iml +++ b/compiler/cli/cli.iml @@ -23,5 +23,6 @@ + \ No newline at end of file diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index 4b8fe318a4a..710882db0ec 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.compiler.plugin.CliOptionProcessingException import org.jetbrains.kotlin.compiler.plugin.PluginCliOptionProcessingException import org.jetbrains.kotlin.compiler.plugin.cliPluginUsageString import org.jetbrains.kotlin.config.* +import org.jetbrains.kotlin.javac.JavacWrapper import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate @@ -158,6 +159,10 @@ class K2JVMCompiler : CLICompiler() { val environment = createEnvironmentWithScriptingSupport(rootDisposable, configuration, arguments, messageCollector) ?: return COMPILATION_ERROR + registerJavacIfNeeded(environment, arguments).let { + if (!it) return COMPILATION_ERROR + } + KotlinToJVMBytecodeCompiler.compileModules(environment, directory) } else if (arguments.script) { @@ -183,6 +188,10 @@ class K2JVMCompiler : CLICompiler() { val environment = createEnvironmentWithScriptingSupport(rootDisposable, configuration, arguments, messageCollector) ?: return COMPILATION_ERROR + registerJavacIfNeeded(environment, arguments).let { + if (!it) return COMPILATION_ERROR + } + if (environment.getSourceFiles().isEmpty()) { if (arguments.version) { return OK @@ -192,6 +201,10 @@ class K2JVMCompiler : CLICompiler() { } KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment) + + compileJavaFilesIfNeeded(environment, arguments).let { + if (!it) return COMPILATION_ERROR + } } if (arguments.reportPerf) { @@ -211,6 +224,23 @@ class K2JVMCompiler : CLICompiler() { } } + private fun registerJavacIfNeeded(environment: KotlinCoreEnvironment, + arguments: K2JVMCompilerArguments): Boolean { + if (arguments.useJavac) { + environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true) + return environment.registerJavac(arguments = arguments.javacArguments) + } + + return true + } + + private fun compileJavaFilesIfNeeded(environment: KotlinCoreEnvironment, + arguments: K2JVMCompilerArguments): Boolean { + if (arguments.useJavac) { + return JavacWrapper.getInstance(environment.project).use { it.compile() } + } + return true + } private fun createEnvironmentWithScriptingSupport(rootDisposable: Disposable, configuration: CompilerConfiguration, diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt index d02ecec08d0..f48824fd12a 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt @@ -25,6 +25,7 @@ import com.intellij.core.CoreApplicationEnvironment import com.intellij.core.CoreJavaFileManager import com.intellij.core.JavaCoreApplicationEnvironment import com.intellij.core.JavaCoreProjectEnvironment +import com.intellij.ide.highlighter.JavaFileType import com.intellij.ide.plugins.PluginManagerCore import com.intellij.lang.MetaLanguage import com.intellij.lang.java.JavaParserDefinition @@ -70,10 +71,7 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.* import org.jetbrains.kotlin.cli.common.toBooleanLenient import org.jetbrains.kotlin.cli.jvm.JvmRuntimeVersionsConsistencyChecker -import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot -import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot -import org.jetbrains.kotlin.cli.jvm.config.JvmContentRoot -import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots +import org.jetbrains.kotlin.cli.jvm.config.* import org.jetbrains.kotlin.cli.jvm.index.JavaRoot import org.jetbrains.kotlin.cli.jvm.index.JvmDependenciesDynamicCompoundIndex import org.jetbrains.kotlin.cli.jvm.index.JvmDependenciesIndex @@ -89,6 +87,7 @@ import org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension import org.jetbrains.kotlin.extensions.PreprocessedVirtualFileFactoryExtension import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor import org.jetbrains.kotlin.idea.KotlinFileType +import org.jetbrains.kotlin.javac.JavacWrapperRegistrar import org.jetbrains.kotlin.load.kotlin.KotlinBinaryClassCache import org.jetbrains.kotlin.load.kotlin.MetadataFinderFactory import org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager @@ -219,6 +218,28 @@ class KotlinCoreEnvironment private constructor( project.registerService(VirtualFileFinderFactory::class.java, finderFactory) } + private val VirtualFile.javaFiles: List + get() = mutableListOf().apply { + VfsUtilCore.processFilesRecursively(this@javaFiles) { file -> + if (file.fileType == JavaFileType.INSTANCE) { + add(file) + } + true + } + } + + private val allJavaFiles: List + get() = configuration.javaSourceRoots + .mapNotNull(this::findLocalDirectory) + .flatMap { it.javaFiles } + .map { File(it.canonicalPath) } + + fun registerJavac(javaFiles: List = allJavaFiles, + kotlinFiles: List = sourceFiles, + arguments: Array? = null): Boolean { + return JavacWrapperRegistrar.registerJavac(this, javaFiles, kotlinFiles, arguments) + } + private val applicationEnvironment: CoreApplicationEnvironment get() = projectEnvironment.environment @@ -327,6 +348,10 @@ class KotlinCoreEnvironment private constructor( } } + fun findLocalFile(path: String) = applicationEnvironment.localFileSystem.findFileByPath(path) + + fun findJarFile(path: String) = applicationEnvironment.jarFileSystem.findFileByPath(path) + private fun findLocalDirectory(root: JvmContentRoot): VirtualFile? { val path = root.file val localFile = findLocalDirectory(path.absolutePath) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt index 9f3f4899eb9..774b13c36ea 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt @@ -33,8 +33,7 @@ import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.common.checkKotlinPackageUsage import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.OUTPUT +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.* import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAll @@ -52,6 +51,7 @@ import org.jetbrains.kotlin.config.JVMConfigurationKeys import org.jetbrains.kotlin.config.addKotlinSourceRoots import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil import org.jetbrains.kotlin.idea.MainFunctionDetector +import org.jetbrains.kotlin.javac.JavacWrapper import org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager import org.jetbrains.kotlin.modules.Module import org.jetbrains.kotlin.modules.TargetId @@ -164,6 +164,22 @@ object KotlinToJVMBytecodeCompiler { ProgressIndicatorAndCompilationCanceledStatus.checkCanceled() writeOutput(state.configuration, state.factory, null) } + + if (projectConfiguration.getBoolean(JVMConfigurationKeys.USE_JAVAC)) { + val singleModule = chunk.singleOrNull() + if (singleModule != null) { + return JavacWrapper.getInstance(environment.project).use { + it.compile(File(singleModule.getOutputDirectory())) + } + } + else { + projectConfiguration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).let { + it.report(WARNING, "A chunk contains multiple modules (${chunk.joinToString { it.getModuleName() }}). -Xuse-javac option couldn't be used to compile java files") + } + JavacWrapper.getInstance(environment.project).close() + } + } + return true } finally { diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/JvmContentRoots.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/JvmContentRoots.kt index a2b9a962db6..d1e17baf230 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/JvmContentRoots.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/JvmContentRoots.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.cli.jvm.config import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.ContentRoot import org.jetbrains.kotlin.config.JVMConfigurationKeys +import org.jetbrains.kotlin.config.KotlinSourceRoot import java.io.File data class JvmClasspathRoot(override val file: File): JvmContentRoot @@ -46,3 +47,10 @@ val CompilerConfiguration.jvmClasspathRoots: List @JvmOverloads fun CompilerConfiguration.addJavaSourceRoots(files: List, packagePrefix: String? = null): Unit = files.forEach { addJavaSourceRoot(it, packagePrefix) } + +val CompilerConfiguration.javaSourceRoots: Set + get() = get(JVMConfigurationKeys.CONTENT_ROOTS) + ?.mapNotNullTo(hashSetOf()) { + (it as? KotlinSourceRoot)?.path ?: (it as? JavaSourceRoot)?.file?.path + } + .orEmpty() \ No newline at end of file diff --git a/compiler/compiler.pro b/compiler/compiler.pro index c84e0a83786..9ad65a1d1bc 100644 --- a/compiler/compiler.pro +++ b/compiler/compiler.pro @@ -57,6 +57,7 @@ messages/**) -libraryjars '' -libraryjars '' -libraryjars '' +-libraryjars '' -dontoptimize -dontobfuscate @@ -199,3 +200,7 @@ messages/**) # for building kotlin-build-common-test -keep class org.jetbrains.kotlin.build.SerializationUtilsKt { *; } + +# for tools.jar +-keep class com.sun.tools.javac.** { *; } +-keep class com.sun.source.** { *; } \ No newline at end of file diff --git a/compiler/frontend.java/frontend.java.iml b/compiler/frontend.java/frontend.java.iml index 38bd69fc475..43286584789 100644 --- a/compiler/frontend.java/frontend.java.iml +++ b/compiler/frontend.java/frontend.java.iml @@ -11,5 +11,6 @@ + \ No newline at end of file diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java b/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java index ae87353713f..30194da8c06 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java @@ -113,4 +113,8 @@ public class JVMConfigurationKeys { public static final CompilerConfigurationKey USE_FAST_CLASS_FILES_READING = CompilerConfigurationKey.create("use fast class files reading implementation [experimental]"); + + public static final CompilerConfigurationKey USE_JAVAC = + CompilerConfigurationKey.create("use javac"); + } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt index 9240f5feb23..c5064d19448 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt @@ -19,6 +19,9 @@ package org.jetbrains.kotlin.frontend.java.di import com.intellij.openapi.project.Project import com.intellij.psi.search.GlobalSearchScope import org.jetbrains.kotlin.builtins.JvmBuiltInsPackageFragmentProvider +import org.jetbrains.kotlin.javac.components.JavacBasedClassFinder +import org.jetbrains.kotlin.javac.components.StubJavaResolverCache +import org.jetbrains.kotlin.javac.components.JavacBasedSourceElementFactory import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings @@ -48,7 +51,8 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory private fun StorageComponentContainer.configureJavaTopDownAnalysis( moduleContentScope: GlobalSearchScope, project: Project, - lookupTracker: LookupTracker + lookupTracker: LookupTracker, + useJavac: Boolean ) { useInstance(moduleContentScope) useInstance(lookupTracker) @@ -60,17 +64,23 @@ private fun StorageComponentContainer.configureJavaTopDownAnalysis( useInstance(VirtualFileFinderFactory.getInstance(project).create(moduleContentScope)) - useImpl() + if (useJavac) { + useImpl() + useImpl() + useImpl() + } else { + useImpl() + useImpl() + useImpl() + } - useImpl() + useImpl() + useImpl() useImpl() - useImpl() useImpl() useImpl() - useImpl() useInstance(SamWithReceiverResolver()) useImpl() - useImpl() useInstance(InternalFlexibleTypeTransformer) useImpl() @@ -88,10 +98,11 @@ fun createContainerForLazyResolveWithJava( jvmTarget: JvmTarget, languageVersionSettings: LanguageVersionSettings, useBuiltInsProvider: Boolean, - useLazyResolve: Boolean + useLazyResolve: Boolean, + useJavac: Boolean = false ): StorageComponentContainer = createContainer("LazyResolveWithJava", JvmPlatform) { configureModule(moduleContext, JvmPlatform, jvmTarget, bindingTrace) - configureJavaTopDownAnalysis(moduleContentScope, moduleContext.project, lookupTracker) + configureJavaTopDownAnalysis(moduleContentScope, moduleContext.project, lookupTracker, useJavac) useInstance(packagePartProvider) useInstance(moduleClassResolver) @@ -110,7 +121,10 @@ fun createContainerForLazyResolveWithJava( useImpl() } }.apply { - get().initialize(bindingTrace, get()) + if (useJavac) + get().initialize(bindingTrace, get()) + else + get().initialize(bindingTrace, get()) } @@ -123,11 +137,12 @@ fun createContainerForTopDownAnalyzerForJvm( packagePartProvider: PackagePartProvider, moduleClassResolver: ModuleClassResolver, jvmTarget: JvmTarget, - languageVersionSettings: LanguageVersionSettings + languageVersionSettings: LanguageVersionSettings, + useJavac: Boolean = false ): ComponentProvider = createContainerForLazyResolveWithJava( moduleContext, bindingTrace, declarationProviderFactory, moduleContentScope, moduleClassResolver, CompilerEnvironment, lookupTracker, packagePartProvider, jvmTarget, languageVersionSettings, - useBuiltInsProvider = true, useLazyResolve = false + useBuiltInsProvider = true, useLazyResolve = false, useJavac = useJavac ) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/TopDownAnalyzerFacadeForJVM.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/TopDownAnalyzerFacadeForJVM.kt index 13cd4e7193e..a32e2ac16a2 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/TopDownAnalyzerFacadeForJVM.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/TopDownAnalyzerFacadeForJVM.kt @@ -41,6 +41,7 @@ import org.jetbrains.kotlin.frontend.java.di.createContainerForTopDownAnalyzerFo import org.jetbrains.kotlin.frontend.java.di.initJvmBuiltInsForTopDownAnalysis import org.jetbrains.kotlin.frontend.java.di.initialize import org.jetbrains.kotlin.incremental.components.LookupTracker +import org.jetbrains.kotlin.javac.MockKotlinClassifier import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolver import org.jetbrains.kotlin.load.java.structure.JavaClass import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl @@ -61,6 +62,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration import org.jetbrains.kotlin.storage.StorageManager +import org.jetbrains.kotlin.javac.wrappers.trees.TreeBasedClass import java.util.* object TopDownAnalyzerFacadeForJVM { @@ -143,6 +145,8 @@ object TopDownAnalyzerFacadeForJVM { } else null + val useJavac = configuration.getBoolean(JVMConfigurationKeys.USE_JAVAC) + val dependencyModule = if (separateModules) { val dependenciesContext = ContextForNewModule( moduleContext, Name.special(""), @@ -154,7 +158,7 @@ object TopDownAnalyzerFacadeForJVM { val dependenciesContainer = createContainerForTopDownAnalyzerForJvm( dependenciesContext, trace, DeclarationProviderFactory.EMPTY, dependencyScope, lookupTracker, - packagePartProvider(dependencyScope), moduleClassResolver, jvmTarget, languageVersionSettings + packagePartProvider(dependencyScope), moduleClassResolver, jvmTarget, languageVersionSettings, useJavac ) StorageComponentContainerContributor.getInstances(project).forEach { it.onContainerComposed(dependenciesContainer, null) } @@ -181,7 +185,7 @@ object TopDownAnalyzerFacadeForJVM { // TODO: get rid of duplicate invocation of CodeAnalyzerInitializer#initialize, or refactor CliLightClassGenerationSupport val container = createContainerForTopDownAnalyzerForJvm( moduleContext, trace, declarationProviderFactory(storageManager, files), sourceScope, lookupTracker, - partProvider, moduleClassResolver, jvmTarget, languageVersionSettings + partProvider, moduleClassResolver, jvmTarget, languageVersionSettings, useJavac ).apply { initJvmBuiltInsForTopDownAnalysis() (partProvider as? IncrementalPackagePartProvider)?.deserializationConfiguration = get() @@ -243,7 +247,8 @@ object TopDownAnalyzerFacadeForJVM { lateinit var sourceCodeResolver: JavaDescriptorResolver override fun resolveClass(javaClass: JavaClass): ClassDescriptor? { - val resolver = if (javaClass is JavaClassImpl && javaClass.psi.containingFile.virtualFile in sourceScope) + val resolver = if (javaClass is JavaClassImpl && javaClass.psi.containingFile.virtualFile in sourceScope + || javaClass is TreeBasedClass || javaClass is MockKotlinClassifier) sourceCodeResolver else compiledCodeResolver diff --git a/compiler/javac-wrapper/javac-wrapper.iml b/compiler/javac-wrapper/javac-wrapper.iml new file mode 100644 index 00000000000..09a861ee296 --- /dev/null +++ b/compiler/javac-wrapper/javac-wrapper.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacLogger.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacLogger.kt new file mode 100644 index 00000000000..d6e61cd7260 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacLogger.kt @@ -0,0 +1,65 @@ +/* + * Copyright 2010-2017 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.javac + +import com.sun.tools.javac.util.Context +import com.sun.tools.javac.util.Log +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.common.messages.GroupingMessageCollector +import org.jetbrains.kotlin.cli.common.messages.MessageCollector +import java.io.PrintWriter +import java.io.Writer + +class JavacLogger(context: Context, + errorWriter: PrintWriter, + warningWriter: PrintWriter, + infoWriter: PrintWriter) : Log(context, errorWriter, warningWriter, infoWriter) { + init { + context.put(Log.outKey, infoWriter) + } + + override fun printLines(kind: WriterKind, message: String, vararg args: Any?) {} + + companion object { + fun preRegister(context: Context, messageCollector: MessageCollector) { + context.put(Log.logKey, Context.Factory { + JavacLogger(it, + PrintWriter(MessageCollectorAdapter(messageCollector, CompilerMessageSeverity.ERROR)), + PrintWriter(MessageCollectorAdapter(messageCollector, CompilerMessageSeverity.WARNING)), + PrintWriter(MessageCollectorAdapter(messageCollector, CompilerMessageSeverity.INFO))) + }) + } + } + +} + +private class MessageCollectorAdapter(private val messageCollector: MessageCollector, + private val severity: CompilerMessageSeverity) : Writer() { + + override fun write(buffer: CharArray, offset: Int, length: Int) { + if (length == 1 && buffer[0] == '\n') return + + messageCollector.report(severity, String(buffer, offset, length)) + } + + override fun flush() { + (messageCollector as? GroupingMessageCollector)?.flush() + } + + override fun close() = flush() + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacOptionsMapper.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacOptionsMapper.kt new file mode 100644 index 00000000000..bdeccd14062 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacOptionsMapper.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2017 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.javac + +import com.sun.tools.javac.util.Options +import java.util.regex.Pattern + +object JavacOptionsMapper { + + fun map(options: Options, arguments: List) { + arguments.forEach { options.putOption(it) } + } + + private val optionPattern = Pattern.compile("\\s+") + + private fun Options.putOption(option: String) = + option.split(optionPattern) + .filter { it.isNotEmpty() } + .let { arg -> + when(arg.size) { + 1 -> put(arg[0], arg[0]) + 2 -> put(arg[0], arg[1]) + } + } + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacWrapper.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacWrapper.kt new file mode 100644 index 00000000000..7f1e52f7867 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacWrapper.kt @@ -0,0 +1,330 @@ +/* + * Copyright 2010-2017 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.javac + +import com.intellij.openapi.components.ServiceManager +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.CommonClassNames +import com.intellij.psi.search.EverythingGlobalScope +import com.intellij.psi.search.GlobalSearchScope +import com.sun.source.tree.CompilationUnitTree +import com.sun.source.util.TreePath +import com.sun.tools.javac.api.JavacTrees +import com.sun.tools.javac.code.Flags +import com.sun.tools.javac.code.Symbol +import com.sun.tools.javac.code.Symtab +import com.sun.tools.javac.file.JavacFileManager +import com.sun.tools.javac.jvm.ClassReader +import com.sun.tools.javac.main.JavaCompiler +import com.sun.tools.javac.model.JavacElements +import com.sun.tools.javac.model.JavacTypes +import com.sun.tools.javac.tree.JCTree +import com.sun.tools.javac.util.Context +import com.sun.tools.javac.util.List as JavacList +import com.sun.tools.javac.util.Names +import com.sun.tools.javac.util.Options +import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots +import org.jetbrains.kotlin.config.JVMConfigurationKeys +import org.jetbrains.kotlin.javac.wrappers.symbols.SymbolBasedClass +import org.jetbrains.kotlin.javac.wrappers.symbols.SymbolBasedClassifierType +import org.jetbrains.kotlin.javac.wrappers.symbols.SymbolBasedPackage +import org.jetbrains.kotlin.load.java.structure.JavaClass +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.isSubpackageOf +import org.jetbrains.kotlin.name.parentOrNull +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.javac.wrappers.trees.TreeBasedClass +import org.jetbrains.kotlin.javac.wrappers.trees.TreeBasedPackage +import org.jetbrains.kotlin.javac.wrappers.trees.TreePathResolverCache +import org.jetbrains.kotlin.javac.wrappers.trees.computeClassId +import org.jetbrains.kotlin.load.java.structure.JavaClassifier +import org.jetbrains.kotlin.load.java.structure.JavaPackage +import org.jetbrains.kotlin.name.ClassId +import java.io.Closeable +import java.io.File +import javax.lang.model.element.Element +import javax.lang.model.type.TypeMirror +import javax.tools.JavaFileManager +import javax.tools.JavaFileObject +import javax.tools.StandardLocation + +class JavacWrapper(javaFiles: Collection, + kotlinFiles: Collection, + arguments: Array?, + private val environment: KotlinCoreEnvironment) : Closeable { + + companion object { + fun getInstance(project: Project): JavacWrapper = ServiceManager.getService(project, JavacWrapper::class.java) + } + + private fun createCommonClassifierType(fqName: String) = + findClassInSymbols(fqName)?.let { + SymbolBasedClassifierType(it.element.asType(), this) + } + + val JAVA_LANG_OBJECT by lazy { + createCommonClassifierType(CommonClassNames.JAVA_LANG_OBJECT) + } + + val JAVA_LANG_ENUM by lazy { + createCommonClassifierType(CommonClassNames.JAVA_LANG_ENUM) + } + + val JAVA_LANG_ANNOTATION_ANNOTATION by lazy { + createCommonClassifierType(CommonClassNames.JAVA_LANG_ANNOTATION_ANNOTATION) + } + + private val messageCollector = environment.configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY] + + private val context = Context() + + init { + messageCollector?.let { JavacLogger.preRegister(context, it) } + arguments?.toList()?.let { JavacOptionsMapper.map(Options.instance(context), it) } + } + + private val javac = object : JavaCompiler(context) { + override fun parseFiles(files: Iterable?) = compilationUnits + } + + private val fileManager = context[JavaFileManager::class.java] as JavacFileManager + + init { + // use rt.jar instead of lib/ct.sym + fileManager.setSymbolFileEnabled(false) + fileManager.setLocation(StandardLocation.CLASS_PATH, environment.configuration.jvmClasspathRoots) + } + + private val names = Names.instance(context) + private val symbols = Symtab.instance(context) + private val trees = JavacTrees.instance(context) + private val elements = JavacElements.instance(context) + private val types = JavacTypes.instance(context) + private val fileObjects = fileManager.getJavaFileObjectsFromFiles(javaFiles).toJavacList() + private val compilationUnits: JavacList = fileObjects.map(javac::parse).toJavacList() + + private val javaClasses = compilationUnits + .flatMap { unit -> + unit.typeDecls.flatMap { classDecl -> + TreeBasedClass(classDecl as JCTree.JCClassDecl, + trees.getPath(unit, classDecl), + this, + unit.sourceFile).withInnerClasses() + } + } + .associateBy(JavaClass::fqName) + + private val javaClassesAssociatedByClassId = + javaClasses.values.associateBy { it.computeClassId() } + + private val javaPackages = compilationUnits + .mapNotNullTo(hashSetOf()) { unit -> + unit.packageName?.toString()?.let { packageName -> + TreeBasedPackage(packageName, this, unit.sourcefile) + } + } + .associateBy(TreeBasedPackage::fqName) + + private val kotlinClassifiersCache = KotlinClassifiersCache(kotlinFiles, this) + private val treePathResolverCache = TreePathResolverCache(this) + private val symbolBasedClassesCache = hashMapOf() + private val symbolBasedPackagesCache = hashMapOf() + + fun compile(outDir: File? = null): Boolean = with(javac) { + if (errorCount() > 0) return false + + fileManager.setClassPathForCompilation(outDir) + messageCollector?.report(CompilerMessageSeverity.INFO, + "Compiling Java sources") + compile(fileObjects) + errorCount() == 0 + } + + override fun close() { + fileManager.close() + javac.close() + } + + fun findClass(fqName: FqName, scope: GlobalSearchScope = EverythingGlobalScope()): JavaClass? { + javaClasses[fqName]?.let { javaClass -> + javaClass.virtualFile?.let { if (it in scope) return javaClass } + } + + findClassInSymbols(fqName.asString())?.let { javaClass -> + javaClass.virtualFile?.let { if (it in scope) return javaClass } + } + + return null + } + + fun findClass(classId: ClassId, scope: GlobalSearchScope = EverythingGlobalScope()): JavaClass? { + javaClassesAssociatedByClassId[classId]?.let { javaClass -> + javaClass.virtualFile?.let { if (it in scope) return javaClass } + } + + findPackageInSymbols(classId.packageFqName.asString())?.let { + (it.element as Symbol.PackageSymbol).findClass(classId.relativeClassName.asString())?.let { javaClass -> + javaClass.virtualFile?.let { file -> + if (file in scope) return javaClass + } + } + + } + + return null + } + + fun findPackage(fqName: FqName, scope: GlobalSearchScope): JavaPackage? { + javaPackages[fqName]?.let { javaPackage -> + javaPackage.virtualFile?.let { file -> + if (file in scope) return javaPackage + } + } + + return findPackageInSymbols(fqName.asString()) + } + + fun findSubPackages(fqName: FqName): List = + symbols.packages + .filterKeys { it.toString().startsWith("$fqName.") } + .map { SymbolBasedPackage(it.value, this) } + + javaPackages + .filterKeys { it.isSubpackageOf(fqName) && it != fqName } + .map { it.value } + + fun findClassesFromPackage(fqName: FqName): List = + javaClasses + .filterKeys { it?.parentOrNull() == fqName } + .flatMap { it.value.withInnerClasses() } + + elements.getPackageElement(fqName.asString()) + ?.members() + ?.elements + ?.filterIsInstance(Symbol.ClassSymbol::class.java) + ?.map { SymbolBasedClass(it, this, it.classfile) } + .orEmpty() + + fun knownClassNamesInPackage(fqName: FqName): Set = + javaClasses.filterKeys { it?.parentOrNull() == fqName } + .mapTo(hashSetOf()) { it.value.name.asString() } + + elements.getPackageElement(fqName.asString()) + ?.members_field + ?.elements + ?.filterIsInstance() + ?.map { it.name.toString() } + .orEmpty() + + fun getTreePath(tree: JCTree, compilationUnit: CompilationUnitTree): TreePath = + trees.getPath(compilationUnit, tree) + + fun getKotlinClassifier(fqName: FqName): JavaClass? = + kotlinClassifiersCache.getKotlinClassifier(fqName) + + fun isDeprecated(element: Element) = elements.isDeprecated(element) + + fun isDeprecated(typeMirror: TypeMirror) = isDeprecated(types.asElement(typeMirror)) + + fun resolve(treePath: TreePath): JavaClassifier? = + treePathResolverCache.resolve(treePath) + + fun toVirtualFile(javaFileObject: JavaFileObject): VirtualFile? = + javaFileObject.toUri().let { uri -> + if (uri.scheme == "jar") { + environment.findJarFile(uri.schemeSpecificPart.substring("file:".length)) + } + else { + environment.findLocalFile(uri.schemeSpecificPart) + } + } + + private inline fun Iterable.toJavacList() = JavacList.from(this) + + private fun findClassInSymbols(fqName: String): SymbolBasedClass? { + if (symbolBasedClassesCache.containsKey(fqName)) return symbolBasedClassesCache[fqName] + + elements.getTypeElement(fqName)?.let { symbol -> + SymbolBasedClass(symbol, this, symbol.classfile) + }.let { symbolBasedClass -> + symbolBasedClassesCache[fqName] = symbolBasedClass + return symbolBasedClass + } + } + + private fun findPackageInSymbols(fqName: String): SymbolBasedPackage? { + if (symbolBasedPackagesCache.containsKey(fqName)) return symbolBasedPackagesCache[fqName] + + elements.getPackageElement(fqName)?.let { symbol -> + SymbolBasedPackage(symbol, this) + }.let { symbolBasedPackage -> + symbolBasedPackagesCache[fqName] = symbolBasedPackage + return symbolBasedPackage + } + } + + private fun JavacFileManager.setClassPathForCompilation(outDir: File?) = apply { + (outDir ?: environment.configuration[JVMConfigurationKeys.OUTPUT_DIRECTORY])?.let { outputDir -> + outputDir.mkdirs() + fileManager.setLocation(StandardLocation.CLASS_OUTPUT, listOf(outputDir)) + } + + val reader = ClassReader.instance(context) + val names = Names.instance(context) + val outDirName = getLocation(StandardLocation.CLASS_OUTPUT)?.firstOrNull()?.path ?: "" + + list(StandardLocation.CLASS_OUTPUT, "", setOf(JavaFileObject.Kind.CLASS), true) + .forEach { fileObject -> + val fqName = fileObject.name + .substringAfter(outDirName) + .substringBefore(".class") + .replace(File.separator, ".") + .let { className -> + if (className.startsWith(".")) className.substring(1) else className + }.let(names::fromString) + + symbols.classes[fqName]?.let { symbols.classes[fqName] = null } + val symbol = reader.enterClass(fqName, fileObject) + + (elements.getPackageOf(symbol) as? Symbol.PackageSymbol)?.let { packageSymbol -> + packageSymbol.members_field.enter(symbol) + packageSymbol.flags_field = packageSymbol.flags_field or Flags.EXISTS.toLong() + } + } + + } + + private fun TreeBasedClass.withInnerClasses(): List = + listOf(this) + innerClasses.values.flatMap { it.withInnerClasses() } + + private fun Symbol.PackageSymbol.findClass(name: String): SymbolBasedClass? { + val nameParts = name.replace("$", ".").split(".") + var symbol = members_field.getElementsByName(names.fromString(nameParts.first())) + ?.firstOrNull() as? Symbol.ClassSymbol ?: return null + if (nameParts.size > 1) { + symbol.complete() + for (it in nameParts.drop(1)) { + symbol = symbol.members_field?.getElementsByName(names.fromString(it))?.firstOrNull() as? Symbol.ClassSymbol ?: return null + symbol.complete() + } + } + + return symbol?.let { SymbolBasedClass(it, this@JavacWrapper, it.classfile) } + } + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacWrapperRegistrar.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacWrapperRegistrar.kt new file mode 100644 index 00000000000..bf916982190 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/JavacWrapperRegistrar.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2017 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.javac + +import com.intellij.mock.MockProject +import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.psi.KtFile +import java.io.File + +object JavacWrapperRegistrar { + + private const val JAVAC_CONTEXT_CLASS = "com.sun.tools.javac.util.Context" + + fun registerJavac(environment: KotlinCoreEnvironment, + javaFiles: List, + kotlinFiles: List, + arguments: Array?): Boolean { + try { + Class.forName(JAVAC_CONTEXT_CLASS) + } catch (e: ClassNotFoundException) { + environment.configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY] + ?.report(CompilerMessageSeverity.STRONG_WARNING, + "'$JAVAC_CONTEXT_CLASS' class can't be found ('tools.jar' is not found). ") + return false + } + + (environment.project as MockProject).registerService(JavacWrapper::class.java, + JavacWrapper(javaFiles, kotlinFiles, arguments, environment)) + + return true + } + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/KotlinClassifiersCache.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/KotlinClassifiersCache.kt new file mode 100644 index 00000000000..225896733a8 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/KotlinClassifiersCache.kt @@ -0,0 +1,255 @@ +/* + * Copyright 2010-2017 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.javac + +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.fileClasses.javaFileFacadeFqName +import org.jetbrains.kotlin.load.java.structure.* +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.psi.KtClassOrObject +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType +import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject +import org.jetbrains.kotlin.javac.wrappers.trees.find +import org.jetbrains.kotlin.javac.wrappers.trees.findInner +import org.jetbrains.kotlin.javac.wrappers.trees.tryToResolveByFqName +import org.jetbrains.kotlin.javac.wrappers.trees.tryToResolveInJavaLang + +class KotlinClassifiersCache(sourceFiles: Collection, + private val javac: JavacWrapper) { + + private val kotlinClasses: Map = sourceFiles.flatMap { ktFile -> + ktFile.collectDescendantsOfType().map { it.fqName to it } + + (ktFile.javaFileFacadeFqName to null) + }.toMap() + + private val classifiers = hashMapOf() + + fun getKotlinClassifier(fqName: FqName) = classifiers[fqName] ?: createClassifier(fqName) + + private fun createClassifier(fqName: FqName): JavaClass? { + if (!kotlinClasses.containsKey(fqName)) return null + val kotlinClassifier = kotlinClasses[fqName] ?: return null + + return MockKotlinClassifier(fqName, + kotlinClassifier, + kotlinClassifier.typeParameters.isNotEmpty(), + javac) + .apply { classifiers[fqName] = this } + } + +} + +class MockKotlinClassifier(override val fqName: FqName, + private val classOrObject: KtClassOrObject, + val hasTypeParameters: Boolean, + private val javac: JavacWrapper) : JavaClass { + + override val isAbstract: Boolean + get() = throw UnsupportedOperationException("Should not be called") + + override val isStatic: Boolean + get() = throw UnsupportedOperationException("Should not be called") + + override val isFinal: Boolean + get() = throw UnsupportedOperationException("Should not be called") + + override val visibility: Visibility + get() = throw UnsupportedOperationException("Should not be called") + + override val typeParameters: List + get() = throw UnsupportedOperationException("Should not be called") + + override val supertypes: Collection + get() = classOrObject.superTypeListEntries + .mapNotNull { superTypeListEntry -> + val userType = superTypeListEntry.typeAsUserType + arrayListOf().apply { + userType?.referencedName?.let { add(it) } + var qualifier = userType?.qualifier + while (qualifier != null) { + qualifier.referencedName?.let { add(it) } + qualifier = qualifier.qualifier + } + }.reversed().joinToString(separator = ".") { it } + } + .mapNotNull { resolveSupertype(it, classOrObject, javac) } + .map { MockKotlinClassifierType(it) } + + val innerClasses: Collection + get() = classOrObject.declarations.filterIsInstance() + .mapNotNull { nestedClassOrObject -> + nestedClassOrObject.fqName?.let { + javac.getKotlinClassifier(it) + } + } + + override val outerClass: JavaClass? + get() = throw UnsupportedOperationException("Should not be called") + + override val isInterface: Boolean + get() = throw UnsupportedOperationException("Should not be called") + + override val isAnnotationType: Boolean + get() = throw UnsupportedOperationException("Should not be called") + + override val isEnum: Boolean + get() = throw UnsupportedOperationException("Should not be called") + + override val lightClassOriginKind + get() = LightClassOriginKind.SOURCE + + override val methods: Collection + get() = throw UnsupportedOperationException("Should not be called") + + override val fields: Collection + get() = throw UnsupportedOperationException("Should not be called") + + override val constructors: Collection + get() = throw UnsupportedOperationException("Should not be called") + + override val name + get() = fqName.shortNameOrSpecial() + + override val annotations + get() = throw UnsupportedOperationException("Should not be called") + + override val isDeprecatedInJavaDoc: Boolean + get() = throw UnsupportedOperationException("Should not be called") + + override fun findAnnotation(fqName: FqName) = + throw UnsupportedOperationException("Should not be called") + + override val innerClassNames + get() = innerClasses.map(JavaClass::name) + + override fun findInnerClass(name: Name) = + innerClasses.find { it.name == name } + +} + +class MockKotlinClassifierType(override val classifier: JavaClassifier) : JavaClassifierType { + + override val typeArguments: List + get() = throw UnsupportedOperationException("Should not be called") + + override val isRaw: Boolean + get() = throw UnsupportedOperationException("Should not be called") + + override val annotations: Collection + get() = throw UnsupportedOperationException("Should not be called") + + override val classifierQualifiedName: String + get() = throw UnsupportedOperationException("Should not be called") + + override val presentableText: String + get() = throw UnsupportedOperationException("Should not be called") + + override fun findAnnotation(fqName: FqName) = + throw UnsupportedOperationException("Should not be called") + + override val isDeprecatedInJavaDoc: Boolean + get() = throw UnsupportedOperationException("Should not be called") + +} + +private fun resolveSupertype(name: String, + classOrObject: KtClassOrObject, + javac: JavacWrapper): JavaClass? { + val nameParts = name.split(".") + val ktFile = classOrObject.containingKtFile + + tryToResolveInner(name, classOrObject, javac, nameParts)?.let { return it } + ktFile.tryToResolvePackageClass(name, javac, nameParts)?.let { return it } + tryToResolveByFqName(name, javac)?.let { return it } + ktFile.tryToResolveSingleTypeImport(name, javac, nameParts)?.let { return it } + ktFile.tryToResolveTypeImportOnDemand(name, javac, nameParts)?.let { return it } + tryToResolveInJavaLang(name, javac)?.let { return it } + + return null +} + +private fun tryToResolveInner(name: String, + classOrObject: KtClassOrObject, + javac: JavacWrapper, + nameParts: List) = + classOrObject.containingClassOrObject?.let { containingClass -> + containingClass.fqName?.let { + javac.findClass(it) ?: javac.getKotlinClassifier(it) + } + }?.findInner(name, javac, nameParts) + +private fun KtFile.tryToResolvePackageClass(name: String, + javac: JavacWrapper, + nameParts: List = emptyList()): JavaClass? { + if (nameParts.size > 1) { + return find(FqName("${packageFqName.asString()}.${nameParts.first()}"), javac, nameParts) + } + else { + return javac.findClass(FqName("${packageFqName.asString()}.$name")) + ?: javac.getKotlinClassifier(FqName("${packageFqName.asString()}.$name")) + } +} + +private fun KtFile.tryToResolveSingleTypeImport(name: String, + javac: JavacWrapper, + nameParts: List = emptyList()): JavaClass? { + if (nameParts.size > 1) { + val foundImports = importDirectives.filter { it.text.endsWith(".${nameParts.first()}") } + foundImports.forEach { importDirective -> + importDirective.importedFqName?.let { importedFqName -> + find(importedFqName, javac, nameParts)?.let { importedClass -> + return importedClass + } + } + } + return null + } + else { + return importDirectives.find { importDirective -> + importDirective.text.endsWith(".$name") + }?.let { importDirective -> + importDirective.importedFqName?.let { fqName -> + javac.findClass(fqName) ?: javac.getKotlinClassifier(fqName) + } + } + } +} + +private fun KtFile.tryToResolveTypeImportOnDemand(name: String, + javac: JavacWrapper, + nameParts: List = emptyList()): JavaClass? { + val packagesWithAsterisk = importDirectives.filter { it.text.endsWith("*") } + + if (nameParts.size > 1) { + packagesWithAsterisk.forEach { importDirective -> + find(FqName("${importDirective.importedFqName?.asString()}.${nameParts.first()}"), + javac, + nameParts)?.let { return it } + } + return null + } + else { + packagesWithAsterisk.forEach { importDirective -> + val fqName = "${importDirective.importedFqName?.asString()}.$name".let(::FqName) + javac.findClass(fqName)?.let { return it } ?: javac.getKotlinClassifier(fqName)?.let { return it } + } + + return null + } +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/components/JavacBasedClassFinder.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/components/JavacBasedClassFinder.kt new file mode 100644 index 00000000000..5e7cf756dd1 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/components/JavacBasedClassFinder.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2017 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.javac.components + +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.AbstractJavaClassFinder +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.resolve.BindingTrace +import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer + +class JavacBasedClassFinder : AbstractJavaClassFinder() { + + private lateinit var javac: JavacWrapper + + override fun initialize(trace: BindingTrace, codeAnalyzer: KotlinCodeAnalyzer) { + javac = JavacWrapper.getInstance(project) + super.initialize(trace, codeAnalyzer) + } + + override fun findClass(classId: ClassId) = javac.findClass(classId, javaSearchScope) + + override fun findPackage(fqName: FqName) = javac.findPackage(fqName, javaSearchScope) + + override fun knownClassNamesInPackage(packageFqName: FqName) = javac.knownClassNamesInPackage(packageFqName) + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/components/JavacBasedSourceElement.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/components/JavacBasedSourceElement.kt new file mode 100644 index 00000000000..ce6c726554e --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/components/JavacBasedSourceElement.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2010-2017 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.javac.components + +import org.jetbrains.kotlin.descriptors.SourceFile +import org.jetbrains.kotlin.load.java.sources.JavaSourceElement +import org.jetbrains.kotlin.load.java.structure.JavaElement + +class JavacBasedSourceElement(override val javaElement: JavaElement) : JavaSourceElement { + + override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/components/JavacBasedSourceElementFactory.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/components/JavacBasedSourceElementFactory.kt new file mode 100644 index 00000000000..851eaffd748 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/components/JavacBasedSourceElementFactory.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2010-2017 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.javac.components + +import org.jetbrains.kotlin.load.java.sources.JavaSourceElementFactory +import org.jetbrains.kotlin.load.java.structure.JavaElement + +class JavacBasedSourceElementFactory : JavaSourceElementFactory { + + override fun source(javaElement: JavaElement) = JavacBasedSourceElement(javaElement) + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/components/StubJavaResolverCache.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/components/StubJavaResolverCache.kt new file mode 100644 index 00000000000..904d7dfa216 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/components/StubJavaResolverCache.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2017 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.javac.components + +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.ConstructorDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor +import org.jetbrains.kotlin.load.java.components.AbstractJavaResolverCache +import org.jetbrains.kotlin.load.java.structure.JavaClass +import org.jetbrains.kotlin.load.java.structure.JavaElement +import org.jetbrains.kotlin.load.java.structure.JavaField +import org.jetbrains.kotlin.load.java.structure.JavaMethod +import org.jetbrains.kotlin.resolve.lazy.ResolveSession + +class StubJavaResolverCache(resolveSession: ResolveSession) : AbstractJavaResolverCache(resolveSession) { + + override fun recordMethod(method: JavaMethod, descriptor: SimpleFunctionDescriptor) {} + + override fun recordConstructor(element: JavaElement, descriptor: ConstructorDescriptor) {} + + override fun recordField(field: JavaField, descriptor: PropertyDescriptor) {} + + override fun recordClass(javaClass: JavaClass, descriptor: ClassDescriptor) {} + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedAnnotation.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedAnnotation.kt new file mode 100644 index 00000000000..33df7123d44 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedAnnotation.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import com.sun.tools.javac.code.Symbol +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaAnnotation +import org.jetbrains.kotlin.load.java.structure.JavaAnnotationArgument +import org.jetbrains.kotlin.load.java.structure.JavaElement +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.Name +import javax.lang.model.element.AnnotationMirror +import javax.lang.model.element.TypeElement + +open class SymbolBasedAnnotation( + val annotationMirror: AnnotationMirror, + val javac: JavacWrapper +) : JavaElement, JavaAnnotation { + + override val arguments: Collection + get() = annotationMirror.elementValues.map { (key, value) -> + SymbolBasedAnnotationArgument.create(value.value, Name.identifier(key.simpleName.toString()), javac) + } + + override val classId: ClassId? + get() = (annotationMirror.annotationType.asElement() as? TypeElement)?.computeClassId() + + override fun resolve() = with(annotationMirror.annotationType.asElement() as Symbol.ClassSymbol) { + SymbolBasedClass(this, javac, classfile) + } + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedClass.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedClass.kt new file mode 100644 index 00000000000..5dbb2c51fa7 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedClass.kt @@ -0,0 +1,121 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.CommonClassNames +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.* +import org.jetbrains.kotlin.load.java.structure.impl.VirtualFileBoundJavaClass +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import javax.lang.model.element.ElementKind +import javax.lang.model.element.ExecutableElement +import javax.lang.model.element.TypeElement +import javax.lang.model.element.VariableElement +import javax.lang.model.type.NoType +import javax.lang.model.type.TypeKind +import javax.tools.JavaFileObject + +class SymbolBasedClass( + element: TypeElement, + javac: JavacWrapper, + val file: JavaFileObject? +) : SymbolBasedClassifier(element, javac), VirtualFileBoundJavaClass { + + override val name: Name + get() = Name.identifier(element.simpleName.toString()) + + override val isAbstract: Boolean + get() = element.isAbstract + + override val isStatic: Boolean + get() = element.isStatic + + override val isFinal: Boolean + get() = element.isFinal + + override val visibility: Visibility + get() = element.getVisibility() + + override val typeParameters: List + get() = element.typeParameters.map { SymbolBasedTypeParameter(it, javac) } + + override val fqName: FqName + get() = FqName(element.qualifiedName.toString()) + + override val supertypes: Collection + get() = element.interfaces.toMutableList() + .apply { + element.superclass.takeIf { it !is NoType }?.let(this::add) + } + .mapTo(arrayListOf()) { SymbolBasedClassifierType(it, javac) } + .apply { + if (isEmpty() && element.qualifiedName.toString() != CommonClassNames.JAVA_LANG_OBJECT) { + javac.JAVA_LANG_OBJECT?.let { add(it) } + } + } + + val innerClasses: Map + get() = element.enclosedElements + .filterIsInstance(TypeElement::class.java) + .map { SymbolBasedClass(it, javac, file) } + .associateBy(JavaClass::name) + + override val outerClass: JavaClass? + get() = element.enclosingElement?.let { + if (it.asType().kind != TypeKind.DECLARED) null else SymbolBasedClass(it as TypeElement, javac, file) + } + + override val isInterface: Boolean + get() = element.kind == ElementKind.INTERFACE + + override val isAnnotationType: Boolean + get() = element.kind == ElementKind.ANNOTATION_TYPE + + override val isEnum: Boolean + get() = element.kind == ElementKind.ENUM + + override val lightClassOriginKind: LightClassOriginKind? + get() = null + + override val methods: Collection + get() = element.enclosedElements + .filter { it.kind == ElementKind.METHOD } + .map { SymbolBasedMethod(it as ExecutableElement, javac) } + + override val fields: Collection + get() = element.enclosedElements + .filter { it.kind.isField && Name.isValidIdentifier(it.simpleName.toString()) } + .map { SymbolBasedField(it as VariableElement, javac) } + + override val constructors: Collection + get() = element.enclosedElements + .filter { it.kind == ElementKind.CONSTRUCTOR } + .map { SymbolBasedConstructor(it as ExecutableElement, javac) } + + override val innerClassNames: Collection + get() = innerClasses.keys + + override val virtualFile: VirtualFile? by lazy { + file?.let { javac.toVirtualFile(it) } + } + + override fun findInnerClass(name: Name) = innerClasses[name] + +} diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedClassifier.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedClassifier.kt new file mode 100644 index 00000000000..2fe03699070 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedClassifier.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaAnnotation +import org.jetbrains.kotlin.load.java.structure.JavaAnnotationOwner +import org.jetbrains.kotlin.load.java.structure.JavaClassifier +import org.jetbrains.kotlin.name.FqName +import javax.lang.model.element.Element + +abstract class SymbolBasedClassifier( + element: T, + javac: JavacWrapper +) : SymbolBasedElement(element, javac), JavaClassifier, JavaAnnotationOwner { + + override val annotations: Collection + get() = element.annotationMirrors.map { SymbolBasedAnnotation(it, javac) } + + override fun findAnnotation(fqName: FqName) = element.findAnnotation(fqName, javac) + + override val isDeprecatedInJavaDoc: Boolean + get() = javac.isDeprecated(element) + +} diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedConstructor.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedConstructor.kt new file mode 100644 index 00000000000..1c500bbe2f1 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedConstructor.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaConstructor +import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter +import org.jetbrains.kotlin.load.java.structure.JavaValueParameter +import javax.lang.model.element.ExecutableElement + +class SymbolBasedConstructor( + element: ExecutableElement, + javac: JavacWrapper +) : SymbolBasedMember(element, javac), JavaConstructor { + + override val typeParameters: List + get() = element.typeParameters.map { SymbolBasedTypeParameter(it, javac) } + + override val valueParameters: List + get() = element.valueParameters(javac) + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedElement.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedElement.kt new file mode 100644 index 00000000000..15646dea0ed --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedElement.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaElement +import javax.lang.model.element.Element + +open class SymbolBasedElement( + val element: T, + val javac: JavacWrapper +) : JavaElement { + + override fun equals(other: Any?) = (other as? SymbolBasedElement<*>)?.element == element + + override fun hashCode() = element.hashCode() + + override fun toString() = element.simpleName.toString() + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedField.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedField.kt new file mode 100644 index 00000000000..7b4f080faf4 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedField.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaField +import org.jetbrains.kotlin.load.java.structure.JavaType +import javax.lang.model.element.ElementKind +import javax.lang.model.element.TypeElement +import javax.lang.model.element.VariableElement +import javax.lang.model.type.DeclaredType + +class SymbolBasedField( + element: VariableElement, + javac: JavacWrapper +) : SymbolBasedMember(element, javac), JavaField { + + override val isEnumEntry: Boolean + get() = element.kind == ElementKind.ENUM_CONSTANT + + override val type: JavaType + get() = SymbolBasedType.create(element.asType(), javac) + + override val initializerValue: Any? + get() = element.constantValue + + override val hasConstantNotNullInitializer: Boolean + get() = element.constantValue != null && element.asType().let { + it.kind.isPrimitive || + ((it as? DeclaredType)?.asElement() as? TypeElement)?.qualifiedName?.toString() == "java.lang.String" + } + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedMember.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedMember.kt new file mode 100644 index 00000000000..b70d3d6ebce --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedMember.kt @@ -0,0 +1,62 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import com.sun.tools.javac.code.Symbol +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaAnnotation +import org.jetbrains.kotlin.load.java.structure.JavaClass +import org.jetbrains.kotlin.load.java.structure.JavaMember +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import javax.lang.model.element.Element + +abstract class SymbolBasedMember( + element: T, + javac: JavacWrapper +) : SymbolBasedElement(element, javac), JavaMember { + + override val containingClass: JavaClass + get() = with(element.enclosingElement as Symbol.ClassSymbol) { + SymbolBasedClass(this, javac, classfile) + } + + override val annotations: Collection + get() = element.annotationMirrors.map { SymbolBasedAnnotation(it, javac) } + + override fun findAnnotation(fqName: FqName) = element.findAnnotation(fqName, javac) + + override val visibility: Visibility + get() = element.getVisibility() + + override val name: Name + get() = Name.identifier(element.simpleName.toString()) + + override val isDeprecatedInJavaDoc: Boolean + get() = javac.isDeprecated(element) + + override val isAbstract: Boolean + get() = element.isAbstract + + override val isStatic: Boolean + get() = element.isStatic + + override val isFinal: Boolean + get() = element.isFinal + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedMethod.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedMethod.kt new file mode 100644 index 00000000000..cdfcc4ec6b7 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedMethod.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.* +import javax.lang.model.element.ExecutableElement + +class SymbolBasedMethod( + element: ExecutableElement, + javac: JavacWrapper +) : SymbolBasedMember(element, javac), JavaMethod { + + override val typeParameters: List + get() = element.typeParameters.map { SymbolBasedTypeParameter(it, javac) } + + override val valueParameters: List + get() = element.valueParameters(javac) + + override val returnType: JavaType + get() = SymbolBasedType.create(element.returnType, javac) + + override val hasAnnotationParameterDefaultValue: Boolean + get() = element.defaultValue != null + +} diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedPackage.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedPackage.kt new file mode 100644 index 00000000000..2ab2d00573d --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedPackage.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaPackage +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import javax.lang.model.element.PackageElement + +class SymbolBasedPackage( + element: PackageElement, + javac: JavacWrapper +) : SymbolBasedElement(element, javac), JavaPackage { + + override val fqName: FqName + get() = FqName(element.qualifiedName.toString()) + + override val subPackages: Collection + get() = javac.findSubPackages(FqName(element.qualifiedName.toString())) + + override fun getClasses(nameFilter: (Name) -> Boolean) = + javac.findClassesFromPackage(fqName).filter { nameFilter(it.name) } + + override fun toString() = element.qualifiedName.toString() + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedTypeParameter.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedTypeParameter.kt new file mode 100644 index 00000000000..417e13886b3 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedTypeParameter.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaClassifierType +import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter +import org.jetbrains.kotlin.name.Name +import javax.lang.model.element.TypeParameterElement + +class SymbolBasedTypeParameter( + element: TypeParameterElement, + javac: JavacWrapper +) : SymbolBasedClassifier(element, javac), JavaTypeParameter { + + override val name: Name + get() = Name.identifier(element.simpleName.toString()) + + override val upperBounds: Collection + get() = element.bounds.map { SymbolBasedClassifierType(it, javac) } + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedValueParameter.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedValueParameter.kt new file mode 100644 index 00000000000..58acf2af8bd --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/SymbolBasedValueParameter.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaAnnotation +import org.jetbrains.kotlin.load.java.structure.JavaType +import org.jetbrains.kotlin.load.java.structure.JavaValueParameter +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import javax.lang.model.element.VariableElement + +class SymbolBasedValueParameter( + element: VariableElement, + private val elementName : String, + override val isVararg : Boolean, + javac: JavacWrapper +) : SymbolBasedElement(element, javac), JavaValueParameter { + + override val annotations: Collection + get() = element.annotationMirrors.map { SymbolBasedAnnotation(it, javac) } + + override fun findAnnotation(fqName: FqName) = + element.findAnnotation(fqName, javac) + + override val isDeprecatedInJavaDoc: Boolean + get() = javac.isDeprecated(element) + + override val name: Name + get() = Name.identifier(elementName) + + override val type: JavaType + get() = SymbolBasedType.create(element.asType(), javac) + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/symbolBasedAnnotationArguments.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/symbolBasedAnnotationArguments.kt new file mode 100644 index 00000000000..61c2da3d179 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/symbolBasedAnnotationArguments.kt @@ -0,0 +1,93 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.* +import org.jetbrains.kotlin.name.Name +import javax.lang.model.element.AnnotationMirror +import javax.lang.model.element.AnnotationValue +import javax.lang.model.element.VariableElement +import javax.lang.model.type.TypeMirror + +sealed class SymbolBasedAnnotationArgument( + override val name: Name, + val javac: JavacWrapper +) : JavaAnnotationArgument, JavaElement { + + companion object { + fun create(value: Any, name: Name, javac: JavacWrapper): JavaAnnotationArgument = when (value) { + is AnnotationMirror -> SymbolBasedAnnotationAsAnnotationArgument(value, name, javac) + is VariableElement -> SymbolBasedReferenceAnnotationArgument(value, javac) + is TypeMirror -> SymbolBasedClassObjectAnnotationArgument(value, name, javac) + is Collection<*> -> arrayAnnotationArguments(value, name, javac) + is AnnotationValue -> create(value.value, name, javac) + else -> SymbolBasedLiteralAnnotationArgument(value, name, javac) + } + + private fun arrayAnnotationArguments(values: Collection<*>, name: Name, javac: JavacWrapper): JavaArrayAnnotationArgument = + values.map { if (it is Collection<*>) arrayAnnotationArguments(it, name, javac) else create(it!!, name, javac) } + .let { argumentList -> SymbolBasedArrayAnnotationArgument(argumentList, name, javac) } + + } + +} + +class SymbolBasedAnnotationAsAnnotationArgument( + val mirror: AnnotationMirror, + name: Name, + javac: JavacWrapper +) : SymbolBasedAnnotationArgument(name, javac), JavaAnnotationAsAnnotationArgument { + + override fun getAnnotation() = SymbolBasedAnnotation(mirror, javac) + +} + +class SymbolBasedReferenceAnnotationArgument( + val element: VariableElement, + javac: JavacWrapper +) : SymbolBasedAnnotationArgument(Name.identifier(element.simpleName.toString()), javac), JavaEnumValueAnnotationArgument { + + override fun resolve() = SymbolBasedField(element, javac) + +} + +class SymbolBasedClassObjectAnnotationArgument( + val type: TypeMirror, + name : Name, + javac: JavacWrapper +) : SymbolBasedAnnotationArgument(name, javac), JavaClassObjectAnnotationArgument { + + override fun getReferencedType() = SymbolBasedType.create(type, javac) + +} + +class SymbolBasedArrayAnnotationArgument( + val args : List, + name : Name, + javac: JavacWrapper +) : SymbolBasedAnnotationArgument(name, javac), JavaArrayAnnotationArgument { + + override fun getElements() = args + +} + +class SymbolBasedLiteralAnnotationArgument( + override val value : Any, + name : Name, + javac: JavacWrapper +) : SymbolBasedAnnotationArgument(name, javac), JavaLiteralAnnotationArgument \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/symbolBasedTypes.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/symbolBasedTypes.kt new file mode 100644 index 00000000000..4a29885d8ee --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/symbolBasedTypes.kt @@ -0,0 +1,131 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import com.sun.tools.javac.code.Symbol +import org.jetbrains.kotlin.builtins.PrimitiveType +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.* +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType +import javax.lang.model.element.TypeElement +import javax.lang.model.element.TypeParameterElement +import javax.lang.model.type.* + +sealed class SymbolBasedType( + val typeMirror: T, + val javac: JavacWrapper +) : JavaType, JavaAnnotationOwner { + + companion object { + fun create(t: T, javac: JavacWrapper) = when { + t.kind.isPrimitive || t.kind == TypeKind.VOID -> SymbolBasedPrimitiveType(t, javac) + t.kind == TypeKind.DECLARED || t.kind == TypeKind.TYPEVAR -> SymbolBasedClassifierType(t, javac) + t.kind == TypeKind.WILDCARD -> SymbolBasedWildcardType(t as WildcardType, javac) + t.kind == TypeKind.ARRAY -> SymbolBasedArrayType(t as ArrayType, javac) + else -> throw UnsupportedOperationException("Unsupported type: $t") + } + } + + override val annotations: Collection + get() = typeMirror.annotationMirrors.map { SymbolBasedAnnotation(it, javac) } + + override val isDeprecatedInJavaDoc: Boolean + get() = javac.isDeprecated(typeMirror) + + override fun findAnnotation(fqName: FqName) = typeMirror.findAnnotation(fqName, javac) + + override fun equals(other: Any?) = (other as? SymbolBasedType<*>)?.typeMirror == typeMirror + + override fun hashCode() = typeMirror.hashCode() + + override fun toString() = typeMirror.toString() + +} + +class SymbolBasedPrimitiveType( + typeMirror: TypeMirror, + javac: JavacWrapper +) : SymbolBasedType(typeMirror, javac), JavaPrimitiveType { + + override val type: PrimitiveType? + get() = if (typeMirror.kind == TypeKind.VOID) null else JvmPrimitiveType.get(typeMirror.toString()).primitiveType + +} + +class SymbolBasedClassifierType( + typeMirror: T, + javac: JavacWrapper +) : SymbolBasedType(typeMirror, javac), JavaClassifierType { + + override val classifier: JavaClassifier? + get() = when (typeMirror.kind) { + TypeKind.DECLARED -> ((typeMirror as DeclaredType).asElement() as Symbol.ClassSymbol).let { symbol -> + SymbolBasedClass(symbol, javac, symbol.classfile) + } + TypeKind.TYPEVAR -> SymbolBasedTypeParameter((typeMirror as TypeVariable).asElement() as TypeParameterElement, javac) + else -> null + } + + override val typeArguments: List + get() = if (typeMirror.kind == TypeKind.DECLARED) { + (typeMirror as DeclaredType).typeArguments.map { create(it, javac) } + } + else { + emptyList() + } + + override val isRaw: Boolean + get() = when { + typeMirror !is DeclaredType -> false + (typeMirror.asElement() as TypeElement).typeParameters.isEmpty() -> false + else -> typeMirror.typeArguments.isEmpty() + } + + override val classifierQualifiedName: String + get() = typeMirror.toString() + + override val presentableText: String + get() = typeMirror.toString() + +} + +class SymbolBasedWildcardType( + typeMirror: WildcardType, + javac: JavacWrapper +) : SymbolBasedType(typeMirror, javac), JavaWildcardType { + + override val bound: JavaType? + get() { + val boundMirror = typeMirror.extendsBound ?: typeMirror.superBound + return boundMirror?.let { create(it, javac) } + } + + override val isExtends: Boolean + get() = typeMirror.extendsBound != null + +} + +class SymbolBasedArrayType( + typeMirror: ArrayType, + javac: JavacWrapper +) : SymbolBasedType(typeMirror, javac), JavaArrayType { + + override val componentType: JavaType + get() = create(typeMirror.componentType, javac) + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/utils.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/utils.kt new file mode 100644 index 00000000000..f2fc7998d16 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/symbols/utils.kt @@ -0,0 +1,74 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.symbols + +import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.JavaVisibilities +import org.jetbrains.kotlin.load.java.structure.JavaValueParameter +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import javax.lang.model.AnnotatedConstruct +import javax.lang.model.element.* + +internal val Element.isAbstract: Boolean + get() = modifiers.contains(Modifier.ABSTRACT) + +internal val Element.isStatic: Boolean + get() = modifiers.contains(Modifier.STATIC) + +internal val Element.isFinal: Boolean + get() = modifiers.contains(Modifier.FINAL) + +internal fun Element.getVisibility(): Visibility = when { + Modifier.PUBLIC in modifiers -> Visibilities.PUBLIC + Modifier.PRIVATE in modifiers -> Visibilities.PRIVATE + Modifier.PROTECTED in modifiers -> { + if (Modifier.STATIC in modifiers) { + JavaVisibilities.PROTECTED_STATIC_VISIBILITY + } + else { + JavaVisibilities.PROTECTED_AND_PACKAGE + } + } + else -> JavaVisibilities.PACKAGE_VISIBILITY +} + +internal fun TypeElement.computeClassId(): ClassId? { + if (enclosingElement.kind != ElementKind.PACKAGE) { + val parentClassId = (enclosingElement as TypeElement).computeClassId() ?: return null + return parentClassId.createNestedClassId(Name.identifier(simpleName.toString())) + } + + return ClassId.topLevel(FqName(qualifiedName.toString())) +} + +internal fun ExecutableElement.valueParameters(javac: JavacWrapper): List = + parameters.mapIndexed { index, parameter -> + SymbolBasedValueParameter(parameter, + parameter.simpleName.toString(), + index == parameters.lastIndex && isVarArgs, + javac) + } + +internal fun AnnotatedConstruct.findAnnotation(fqName: FqName, + javac: JavacWrapper) = + annotationMirrors.find { + (it.annotationType.asElement() as TypeElement).qualifiedName.toString() == fqName.asString() + }?.let { SymbolBasedAnnotation(it, javac) } \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedAnnotation.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedAnnotation.kt new file mode 100644 index 00000000000..293482d01be --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedAnnotation.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.sun.source.util.TreePath +import com.sun.tools.javac.tree.JCTree +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaAnnotation +import org.jetbrains.kotlin.load.java.structure.JavaAnnotationArgument +import org.jetbrains.kotlin.load.java.structure.JavaClass +import org.jetbrains.kotlin.load.java.structure.JavaElement +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.Name + +class TreeBasedAnnotation( + val annotation: JCTree.JCAnnotation, + val treePath: TreePath, + val javac: JavacWrapper +) : JavaElement, JavaAnnotation { + + override val arguments: Collection + get() = annotation.arguments.map { TreeBasedAnnotationArgument(Name.identifier(it.toString())) } + + override val classId: ClassId? + get() = resolve()?.computeClassId() + + override fun resolve() = + javac.resolve(TreePath.getPath(treePath.compilationUnit, annotation.annotationType)) as? JavaClass + +} + +class TreeBasedAnnotationArgument(override val name: Name) : JavaAnnotationArgument, JavaElement \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedClass.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedClass.kt new file mode 100644 index 00000000000..a3f9b4f63b5 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedClass.kt @@ -0,0 +1,153 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.intellij.openapi.vfs.VirtualFile +import com.sun.source.tree.Tree +import com.sun.source.util.TreePath +import com.sun.tools.javac.code.Flags +import com.sun.tools.javac.tree.JCTree +import com.sun.tools.javac.tree.TreeInfo +import org.jetbrains.kotlin.descriptors.Visibilities.PUBLIC +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.* +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import javax.tools.JavaFileObject + +class TreeBasedClass( + tree: JCTree.JCClassDecl, + treePath: TreePath, + javac: JavacWrapper, + val file: JavaFileObject +) : TreeBasedElement(tree, treePath, javac), JavaClass { + + override val name: Name + get() = Name.identifier(tree.simpleName.toString()) + + override val annotations: Collection by lazy { + tree.annotations().map { annotation -> TreeBasedAnnotation(annotation, treePath, javac) } + } + + override fun findAnnotation(fqName: FqName) = + annotations.find { it.classId?.asSingleFqName() == fqName } + + override val isDeprecatedInJavaDoc: Boolean + get() = false + + override val isAbstract: Boolean + get() = tree.modifiers.isAbstract || (isAnnotationType && methods.any { it.isAbstract }) + + override val isStatic: Boolean + get() = (outerClass?.isInterface ?: false) || tree.modifiers.isStatic + + override val isFinal: Boolean + get() = tree.modifiers.isFinal + + override val visibility: Visibility + get() = if (outerClass?.isInterface ?: false) PUBLIC else tree.modifiers.visibility + + override val typeParameters: List + get() = tree.typeParameters.map { parameter -> + TreeBasedTypeParameter(parameter, TreePath(treePath, parameter), javac) + } + + override val fqName: FqName = + treePath.reversed() + .filterIsInstance() + .joinToString( + separator = ".", + prefix = "${treePath.compilationUnit.packageName}.", + transform = JCTree.JCClassDecl::name + ) + .let(::FqName) + + override val supertypes: Collection + get() = arrayListOf().apply { + fun JCTree.mapToJavaClassifierType() = when { + this is JCTree.JCTypeApply -> TreeBasedGenericClassifierType(this, TreePath(treePath, this), javac) + this is JCTree.JCExpression -> TreeBasedNonGenericClassifierType(this, TreePath(treePath, this), javac) + else -> null + } + + if (isEnum) { + javac.JAVA_LANG_ENUM?.let(this::add) + } else if (isAnnotationType) { + javac.JAVA_LANG_ANNOTATION_ANNOTATION?.let(this::add) + } + + tree.implementing?.mapNotNull { it.mapToJavaClassifierType() }?.let(this::addAll) + tree.extending?.let { it.mapToJavaClassifierType()?.let(this::add) } + + if (isEmpty()) { + javac.JAVA_LANG_OBJECT?.let(this::add) + } + } + + val innerClasses: Map by lazy { + tree.members + .filterIsInstance(JCTree.JCClassDecl::class.java) + .map { TreeBasedClass(it, TreePath(treePath, it), javac, file) } + .associateBy(JavaClass::name) + } + + override val outerClass: JavaClass? by lazy { + (treePath.parentPath.leaf as? JCTree.JCClassDecl)?.let { classDecl -> + TreeBasedClass(classDecl, treePath.parentPath, javac, file) + } + } + + override val isInterface: Boolean + get() = tree.modifiers.flags and Flags.INTERFACE.toLong() != 0L + + override val isAnnotationType: Boolean + get() = tree.modifiers.flags and Flags.ANNOTATION.toLong() != 0L + + override val isEnum: Boolean + get() = tree.modifiers.flags and Flags.ENUM.toLong() != 0L + + override val lightClassOriginKind: LightClassOriginKind? + get() = null + + override val methods: Collection + get() = tree.members + .filter { it.kind == Tree.Kind.METHOD && !TreeInfo.isConstructor(it) } + .map { TreeBasedMethod(it as JCTree.JCMethodDecl, TreePath(treePath, it), this, javac) } + + override val fields: Collection + get() = tree.members + .filterIsInstance(JCTree.JCVariableDecl::class.java) + .map { TreeBasedField(it, TreePath(treePath, it), this, javac) } + + override val constructors: Collection + get() = tree.members + .filter { member -> TreeInfo.isConstructor(member) } + .map { constructor -> + TreeBasedConstructor(constructor as JCTree.JCMethodDecl, TreePath(treePath, constructor), this, javac) + } + + override val innerClassNames: Collection + get() = innerClasses.keys + + val virtualFile: VirtualFile? by lazy { + javac.toVirtualFile(file) + } + + override fun findInnerClass(name: Name) = innerClasses[name] + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedConstructor.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedConstructor.kt new file mode 100644 index 00000000000..a678a9d7836 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedConstructor.kt @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.sun.source.util.TreePath +import com.sun.tools.javac.tree.JCTree +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaClass +import org.jetbrains.kotlin.load.java.structure.JavaConstructor +import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter +import org.jetbrains.kotlin.load.java.structure.JavaValueParameter +import org.jetbrains.kotlin.name.Name + +class TreeBasedConstructor( + tree: JCTree.JCMethodDecl, + treePath: TreePath, + containingClass: JavaClass, + javac: JavacWrapper +) : TreeBasedMember(tree, treePath, containingClass, javac), JavaConstructor { + + override val name: Name + get() = Name.identifier(tree.name.toString()) + + override val isAbstract: Boolean + get() = false + + override val isStatic: Boolean + get() = false + + override val isFinal: Boolean + get() = true + + override val visibility: Visibility + get() = tree.modifiers.visibility + + override val typeParameters: List + get() = tree.typeParameters.map { TreeBasedTypeParameter(it, TreePath(treePath, it), javac) } + + override val valueParameters: List + get() = tree.parameters.map { TreeBasedValueParameter(it, TreePath(treePath, it), javac) } + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedElement.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedElement.kt new file mode 100644 index 00000000000..bd1b700ab97 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedElement.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.sun.source.util.TreePath +import com.sun.tools.javac.tree.JCTree +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaElement + +abstract class TreeBasedElement( + val tree: T, + val treePath: TreePath, + val javac: JavacWrapper +) : JavaElement { + + override fun equals(other: Any?) = (other as? TreeBasedElement<*>)?.tree == tree + + override fun hashCode() = tree.hashCode() + + override fun toString() = tree.toString() + +} diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedField.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedField.kt new file mode 100644 index 00000000000..aaf350187a7 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedField.kt @@ -0,0 +1,76 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.sun.source.util.TreePath +import com.sun.tools.javac.code.Flags +import com.sun.tools.javac.tree.JCTree +import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaClass +import org.jetbrains.kotlin.load.java.structure.JavaField +import org.jetbrains.kotlin.load.java.structure.JavaType +import org.jetbrains.kotlin.name.Name + +class TreeBasedField( + tree: JCTree.JCVariableDecl, + treePath: TreePath, + containingClass: JavaClass, + javac: JavacWrapper +) : TreeBasedMember(tree, treePath, containingClass, javac), JavaField { + + override val name: Name + get() = Name.identifier(tree.name.toString()) + + override val isAbstract: Boolean + get() = tree.modifiers.isAbstract + + override val isStatic: Boolean + get() = containingClass.isInterface || tree.modifiers.isStatic + + override val isFinal: Boolean + get() = containingClass.isInterface || tree.modifiers.isFinal + + override val visibility: Visibility + get() = if (containingClass.isInterface) Visibilities.PUBLIC else tree.modifiers.visibility + + override val isEnumEntry: Boolean + get() = tree.modifiers.flags and Flags.ENUM.toLong() != 0L + + override val type: JavaType + get() = TreeBasedType.create(tree.getType(), treePath, javac) + + override val initializerValue: Any? + get() = tree.init?.let { initExpr -> + if (hasConstantNotNullInitializer && initExpr is JCTree.JCLiteral) { + initExpr.value + } else { + null + } + } + + override val hasConstantNotNullInitializer: Boolean + get() = tree.init?.let { + val type = this.type + + isFinal && ((type is TreeBasedPrimitiveType) || + (type is TreeBasedNonGenericClassifierType && + type.classifierQualifiedName == "java.lang.String")) + } ?: false + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedMember.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedMember.kt new file mode 100644 index 00000000000..af24bc238b3 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedMember.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.sun.source.util.TreePath +import com.sun.tools.javac.tree.JCTree +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaAnnotation +import org.jetbrains.kotlin.load.java.structure.JavaClass +import org.jetbrains.kotlin.load.java.structure.JavaMember +import org.jetbrains.kotlin.name.FqName + +abstract class TreeBasedMember( + tree: T, + treePath: TreePath, + override val containingClass: JavaClass, + javac: JavacWrapper +) : TreeBasedElement(tree, treePath, javac), JavaMember { + + override val isDeprecatedInJavaDoc: Boolean + get() = false + + override val annotations: Collection by lazy { + tree.annotations().map { TreeBasedAnnotation(it, treePath, javac) } + } + + override fun findAnnotation(fqName: FqName) = + annotations.find { it.classId?.asSingleFqName() == fqName } + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedMethod.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedMethod.kt new file mode 100644 index 00000000000..0f4147cf1d7 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedMethod.kt @@ -0,0 +1,60 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.sun.source.util.TreePath +import com.sun.tools.javac.tree.JCTree +import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.* +import org.jetbrains.kotlin.name.Name + +class TreeBasedMethod( + tree: JCTree.JCMethodDecl, + treePath: TreePath, + containingClass: JavaClass, + javac: JavacWrapper +) : TreeBasedMember(tree, treePath, containingClass, javac), JavaMethod { + + override val name: Name + get() = Name.identifier(tree.name.toString()) + + override val isAbstract: Boolean + get() = (containingClass.isInterface && !tree.modifiers.hasDefaultModifier) || tree.modifiers.isAbstract + + override val isStatic: Boolean + get() = tree.modifiers.isStatic + + override val isFinal: Boolean + get() = tree.modifiers.isFinal + + override val visibility: Visibility + get() = if (containingClass.isInterface) Visibilities.PUBLIC else tree.modifiers.visibility + + override val typeParameters: List + get() = tree.typeParameters.map { TreeBasedTypeParameter(it, TreePath(treePath, it), javac) } + + override val valueParameters: List + get() = tree.parameters.map { TreeBasedValueParameter(it, TreePath(treePath, it), javac) } + + override val returnType: JavaType + get() = TreeBasedType.create(tree.returnType, treePath, javac) + + override val hasAnnotationParameterDefaultValue: Boolean + get() = tree.defaultValue != null +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedPackage.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedPackage.kt new file mode 100644 index 00000000000..226697ba440 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedPackage.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.intellij.openapi.vfs.VirtualFile +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaPackage +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import javax.tools.JavaFileObject + +class TreeBasedPackage(val name: String, val javac: JavacWrapper, val file: JavaFileObject) : JavaPackage { + + override val fqName: FqName + get() = FqName(name) + + override val subPackages: Collection + get() = javac.findSubPackages(fqName) + + val virtualFile: VirtualFile? by lazy { + javac.toVirtualFile(file) + } + + override fun getClasses(nameFilter: (Name) -> Boolean) = + javac.findClassesFromPackage(fqName).filter { nameFilter(it.fqName!!.shortName()) } + + override fun equals(other: Any?) = (other as? TreeBasedPackage)?.name == name + + override fun hashCode() = name.hashCode() + + override fun toString() = name + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedTypeParameter.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedTypeParameter.kt new file mode 100644 index 00000000000..503bb54627d --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedTypeParameter.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.sun.source.util.TreePath +import com.sun.tools.javac.tree.JCTree +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaAnnotation +import org.jetbrains.kotlin.load.java.structure.JavaClassifierType +import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name + +class TreeBasedTypeParameter( + tree: JCTree.JCTypeParameter, + treePath: TreePath, + javac: JavacWrapper +) : TreeBasedElement(tree, treePath, javac), JavaTypeParameter { + + override val name: Name + get() = Name.identifier(tree.name.toString()) + + override val annotations: Collection by lazy { + tree.annotations().map { TreeBasedAnnotation(it, treePath, javac) } + } + + override fun findAnnotation(fqName: FqName) = + annotations.firstOrNull { it.classId?.asSingleFqName() == fqName } + + override val isDeprecatedInJavaDoc: Boolean + get() = false + + override val upperBounds: Collection + get() = tree.bounds.map { + when (it) { + is JCTree.JCTypeApply -> TreeBasedGenericClassifierType(it, TreePath(treePath, it), javac) + is JCTree.JCIdent -> TreeBasedNonGenericClassifierType(it, TreePath(treePath, it), javac) + else -> null + } + }.filterNotNull() + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedValueParameter.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedValueParameter.kt new file mode 100644 index 00000000000..5c490cae47e --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/TreeBasedValueParameter.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.sun.source.util.TreePath +import com.sun.tools.javac.code.Flags +import com.sun.tools.javac.tree.JCTree +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaAnnotation +import org.jetbrains.kotlin.load.java.structure.JavaType +import org.jetbrains.kotlin.load.java.structure.JavaValueParameter +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name + +class TreeBasedValueParameter( + tree: JCTree.JCVariableDecl, + treePath: TreePath, + javac: JavacWrapper +) : TreeBasedElement(tree, treePath, javac), JavaValueParameter { + + override val annotations: Collection by lazy { + tree.annotations().map { TreeBasedAnnotation(it, treePath, javac) } + } + + override fun findAnnotation(fqName: FqName) = + annotations.find { it.classId?.asSingleFqName() == fqName } + + override val isDeprecatedInJavaDoc: Boolean + get() = false + + override val name: Name + get() = Name.identifier(tree.name.toString()) + + override val type: JavaType + get() = TreeBasedType.create(tree.getType(), treePath, javac) + + override val isVararg: Boolean + get() = tree.modifiers.flags and Flags.VARARGS != 0L +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/resolve.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/resolve.kt new file mode 100644 index 00000000000..620623aad53 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/resolve.kt @@ -0,0 +1,193 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.sun.source.tree.Tree +import com.sun.source.util.TreePath +import com.sun.tools.javac.tree.JCTree +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.load.java.structure.JavaClass +import org.jetbrains.kotlin.load.java.structure.JavaClassifier +import org.jetbrains.kotlin.name.FqName + +class TreePathResolverCache(private val javac: JavacWrapper) { + + private val cache = hashMapOf() + + fun resolve(treePath: TreePath): JavaClassifier? = with(treePath) { + if (cache.containsKey(leaf)) return cache[leaf] + + return tryToGetClassifier().apply { cache[leaf] = this } + } + + private fun TreePath.tryToGetClassifier(): JavaClassifier? { + val name = leaf.toString().substringBefore("<").substringAfter("@") + val nameParts = name.split(".") + + with(compilationUnit as JCTree.JCCompilationUnit) { + tryToResolveInner(name, javac, nameParts)?.let { return it } + tryToResolvePackageClass(name, javac, nameParts)?.let { return it } + tryToResolveByFqName(name, javac)?.let { return it } + tryToResolveSingleTypeImport(name, javac, nameParts)?.let { return it } + tryToResolveTypeImportOnDemand(name, javac, nameParts)?.let { return it } + tryToResolveInJavaLang(name, javac)?.let { return it } + } + + return tryToResolveTypeParameter(javac) + } + + private fun TreePath.tryToResolveInner( + name: String, + javac: JavacWrapper, + nameParts: List = emptyList() + ): JavaClass? = findEnclosingClasses(javac)?.forEach { javaClass -> + javaClass.findInner(name, javac, nameParts)?.let { inner -> return inner } + }.let { return null } + + private fun TreePath.findEnclosingClasses(javac: JavacWrapper) = + filterIsInstance() + .filter { it.extending != leaf && !it.implementing.contains(leaf) } + .reversed() + .joinToString(separator = ".", prefix = "${compilationUnit.packageName}.") { it.simpleName } + .let { javac.findClass(FqName(it)) } + ?.let { + arrayListOf(it).apply { + var enclosingClass = it.outerClass + while (enclosingClass != null) { + add(enclosingClass) + enclosingClass = enclosingClass.outerClass + } + } + } + + private fun JCTree.JCCompilationUnit.tryToResolveSingleTypeImport( + name: String, + javac: JavacWrapper, + nameParts: List = emptyList() + ): JavaClass? { + nameParts.size.takeIf { it > 1 }?.let { + imports.filter { it.qualifiedIdentifier.toString().endsWith(".${nameParts.first()}") } + .forEach { import -> + find(FqName("${import.qualifiedIdentifier}"), javac, nameParts)?.let { javaClass -> + return javaClass + } + } + .let { return null } + } + + return imports + .find { it.qualifiedIdentifier.toString().endsWith(".$name") } + ?.let { import -> + FqName(import.qualifiedIdentifier.toString()).let { fqName -> + javac.findClass(fqName) ?: javac.getKotlinClassifier(fqName) + } + } + } + + private fun JCTree.JCCompilationUnit.tryToResolvePackageClass( + name: String, + javac: JavacWrapper, + nameParts: List = emptyList() + ): JavaClass? { + return nameParts.size.takeIf { it > 1 }?.let { + find(FqName("$packageName.${nameParts.first()}"), javac, nameParts) + } + ?: javac.findClass(FqName("$packageName.$name")) + ?: javac.getKotlinClassifier(FqName("$packageName.$name")) + } + + private fun JCTree.JCCompilationUnit.tryToResolveTypeImportOnDemand( + name: String, + javac: JavacWrapper, + nameParts: List = emptyList() + ): JavaClass? { + with(imports.filter { it.qualifiedIdentifier.toString().endsWith("*") }) { + nameParts.size.takeIf { it > 1 } + ?.let { + forEach { pack -> + find(FqName("${pack.qualifiedIdentifier.toString().substringBefore("*")}${nameParts.first()}"), + javac, + nameParts)?.let { return it } + }.let { return null } + } + + this.forEach { + val fqName = "${it.qualifiedIdentifier.toString().substringBefore("*")}$name".let(::FqName) + (javac.findClass(fqName) ?: javac.getKotlinClassifier(fqName))?.let { return it } + }.let { return null } + } + } + + private fun TreePath.tryToResolveTypeParameter(javac: JavacWrapper) = + flatMap { + when (it) { + is JCTree.JCClassDecl -> it.typarams + is JCTree.JCMethodDecl -> it.typarams + else -> emptyList() + } + } + .find { it.toString().substringBefore(" ") == leaf.toString() } + ?.let { + TreeBasedTypeParameter(it, + javac.getTreePath(it, compilationUnit), + javac) + } + +} + +fun JavaClass.findInner(name: String, + javac: JavacWrapper, + nameParts: List = emptyList()) : JavaClass? { + nameParts.size.takeIf { it > 1 }?.let { + return find(FqName("${fqName!!.asString()}.${nameParts[0]}"), javac, nameParts) + } + + if (name == this.fqName?.shortName()?.asString()) return this + + with(FqName("${fqName!!.asString()}.$name")) { + javac.findClass(this)?.let { return it } + javac.getKotlinClassifier(this)?.let { return it } + } + + supertypes.mapNotNull { it.classifier as? JavaClass } + .forEach { javaClass -> + javaClass.findInner(name, javac)?.let { inner -> return inner } + }.let { return null } +} + +fun tryToResolveByFqName(name: String, + javac: JavacWrapper) = with(FqName(name)) { + javac.findClass(this) ?: javac.getKotlinClassifier(this) +} + +fun tryToResolveInJavaLang(name: String, + javac: JavacWrapper) = javac.findClass(FqName("java.lang.$name")) + + +fun find(fqName: FqName, + javac: JavacWrapper, + nameParts: List): JavaClass? { + val initial = with(fqName) { + javac.findClass(this) + ?: javac.getKotlinClassifier(this) + ?: return null + } + + nameParts.drop(1).fold(initial) { + javaClass, namePart -> javaClass.findInner(namePart, javac) ?: return null + }.let { return it } +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/treeBasedTypes.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/treeBasedTypes.kt new file mode 100644 index 00000000000..588576c3179 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/treeBasedTypes.kt @@ -0,0 +1,159 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.sun.source.util.TreePath +import com.sun.tools.javac.code.BoundKind +import com.sun.tools.javac.tree.JCTree +import org.jetbrains.kotlin.builtins.PrimitiveType +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.javac.MockKotlinClassifier +import org.jetbrains.kotlin.load.java.structure.* +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType +import javax.lang.model.type.TypeKind + +abstract class TreeBasedType( + val tree: T, + val treePath: TreePath, + val javac: JavacWrapper +) : JavaType, JavaAnnotationOwner { + + companion object { + fun create(tree: Type, treePath: TreePath, javac: JavacWrapper) = when (tree) { + is JCTree.JCPrimitiveTypeTree -> TreeBasedPrimitiveType(tree, TreePath(treePath, tree), javac) + is JCTree.JCArrayTypeTree -> TreeBasedArrayType(tree, TreePath(treePath, tree), javac) + is JCTree.JCWildcard -> TreeBasedWildcardType(tree, TreePath(treePath, tree), javac) + is JCTree.JCTypeApply -> TreeBasedGenericClassifierType(tree, TreePath(treePath, tree), javac) + is JCTree.JCExpression -> TreeBasedNonGenericClassifierType(tree, TreePath(treePath, tree), javac) + else -> throw UnsupportedOperationException("Unsupported type: $tree") + } + } + + override val annotations: Collection + get() = emptyList() + + override val isDeprecatedInJavaDoc: Boolean + get() = false + + override fun findAnnotation(fqName: FqName) = annotations.find { it.classId?.asSingleFqName() == fqName } + + override fun equals(other: Any?) = (other as? TreeBasedType<*>)?.tree == tree + + override fun hashCode() = tree.hashCode() + + override fun toString() = tree.toString() + +} + +class TreeBasedPrimitiveType( + tree: JCTree.JCPrimitiveTypeTree, + treePath: TreePath, + javac: JavacWrapper +) : TreeBasedType(tree, treePath, javac), JavaPrimitiveType { + + override val type: PrimitiveType? + get() = if (tree.primitiveTypeKind == TypeKind.VOID) { + null + } + else { + JvmPrimitiveType.get(tree.toString()).primitiveType + } + +} + +class TreeBasedArrayType( + tree: JCTree.JCArrayTypeTree, + treePath: TreePath, + javac: JavacWrapper +) : TreeBasedType(tree, treePath, javac), JavaArrayType { + + override val componentType: JavaType + get() = create(tree.elemtype, treePath, javac) + +} + +class TreeBasedWildcardType( + tree: JCTree.JCWildcard, + treePath: TreePath, + javac: JavacWrapper +) : TreeBasedType(tree, treePath, javac), JavaWildcardType { + + override val bound: JavaType? + get() = tree.bound?.let { create(it, treePath, javac) } + + override val isExtends: Boolean + get() = tree.kind.kind == BoundKind.EXTENDS + +} + +sealed class TreeBasedClassifierType( + tree: T, + treePath: TreePath, + javac: JavacWrapper +) : TreeBasedType(tree, treePath, javac), JavaClassifierType { + + override val classifier: JavaClassifier? + get() = javac.resolve(treePath) + + override val classifierQualifiedName: String + get() = (classifier as? JavaClass)?.fqName?.asString() ?: treePath.leaf.toString() + + override val presentableText: String + get() = classifierQualifiedName + + private val typeParameter: JCTree.JCTypeParameter? + get() = treePath.flatMap { + when (it) { + is JCTree.JCClassDecl -> it.typarams + is JCTree.JCMethodDecl -> it.typarams + else -> emptyList() + } + } + .find { it.toString().substringBefore(" ") == treePath.leaf.toString() } + +} + +class TreeBasedNonGenericClassifierType( + tree: JCTree.JCExpression, + treePath: TreePath, + javac: JavacWrapper +) : TreeBasedClassifierType(tree, treePath, javac) { + + override val typeArguments: List + get() = emptyList() + + override val isRaw: Boolean + get() = (classifier as? MockKotlinClassifier)?.hasTypeParameters + ?: (classifier as? JavaClass)?.typeParameters?.isNotEmpty() + ?: false + +} + +class TreeBasedGenericClassifierType( + tree: JCTree.JCTypeApply, + treePath: TreePath, + javac: JavacWrapper +) : TreeBasedClassifierType(tree, treePath, javac) { + + override val typeArguments: List + get() = tree.arguments.map { create(it, treePath, javac) } + + override val isRaw: Boolean + get() = false + +} \ No newline at end of file diff --git a/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/utils.kt b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/utils.kt new file mode 100644 index 00000000000..54378e0b5c9 --- /dev/null +++ b/compiler/javac-wrapper/src/org/jetbrains/kotlin/javac/wrappers/trees/utils.kt @@ -0,0 +1,61 @@ +/* + * Copyright 2010-2017 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.javac.wrappers.trees + +import com.sun.tools.javac.tree.JCTree +import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.load.java.JavaVisibilities +import org.jetbrains.kotlin.load.java.structure.JavaClass +import org.jetbrains.kotlin.name.ClassId +import javax.lang.model.element.Modifier + +internal val JCTree.JCModifiers.isAbstract: Boolean + get() = Modifier.ABSTRACT in getFlags() + +internal val JCTree.JCModifiers.isFinal: Boolean + get() = Modifier.FINAL in getFlags() + +internal val JCTree.JCModifiers.isStatic: Boolean + get() = Modifier.STATIC in getFlags() + +internal val JCTree.JCModifiers.hasDefaultModifier: Boolean + get() = Modifier.DEFAULT in getFlags() + +internal val JCTree.JCModifiers.visibility: Visibility + get() = getFlags().let { + when { + Modifier.PUBLIC in it -> Visibilities.PUBLIC + Modifier.PRIVATE in it -> Visibilities.PRIVATE + Modifier.PROTECTED in it -> { + if (Modifier.STATIC in it) JavaVisibilities.PROTECTED_STATIC_VISIBILITY + else JavaVisibilities.PROTECTED_AND_PACKAGE + } + else -> JavaVisibilities.PACKAGE_VISIBILITY + } + } + +internal fun JCTree.annotations(): Collection = when (this) { + is JCTree.JCMethodDecl -> mods?.annotations + is JCTree.JCClassDecl -> mods?.annotations + is JCTree.JCVariableDecl -> mods?.annotations + is JCTree.JCTypeParameter -> annotations + else -> null +} ?: emptyList() + +fun JavaClass.computeClassId(): ClassId? = + outerClass?.computeClassId()?.createNestedClassId(name) ?: fqName?.let { ClassId.topLevel(it) } \ No newline at end of file diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 622f8bc9b50..d91e850301a 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -14,6 +14,8 @@ where advanced options include: Load definitions of built-in declarations from module dependencies, instead of from the compiler -Xscript-resolver-environment= Script resolver environment in key-value pairs (the value could be quoted and escaped) + -Xuse-javac Use javac for Java source and class files analysis + -Xjavac-arguments= Java compiler arguments -Xno-inline Disable method inlining -Xrepeat= Repeat compilation (for performance analysis) -Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes) diff --git a/compiler/testData/compileJavaAgainstKotlin/method/Any.kt b/compiler/testData/compileJavaAgainstKotlin/method/Any.kt index b03f51e1c02..75d3c07cf3d 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/Any.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/Any.kt @@ -1,4 +1,4 @@ package test // extra parameter is to preserve generic signature -fun anyany(a: Any, ignore: java.util.List) = a +fun anyany(a: kotlin.Any, ignore: java.util.List) = a diff --git a/compiler/testData/compileJavaAgainstKotlin/method/Int.kt b/compiler/testData/compileJavaAgainstKotlin/method/Int.kt index 856c751fc5a..ee7242c962c 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/Int.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/Int.kt @@ -1,3 +1,3 @@ package test -fun lll(a: Int) = a +fun lll(a: kotlin.Int) = a diff --git a/compiler/testData/compileJavaAgainstKotlin/method/IntArray.kt b/compiler/testData/compileJavaAgainstKotlin/method/IntArray.kt index 9ef1fa09efb..ce2518b9d7f 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/IntArray.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/IntArray.kt @@ -1,4 +1,4 @@ package test // extra parameter is to make sure generic signature is not erased -fun doNothing(array: IntArray, ignore: java.util.List) = array +fun doNothing(array: kotlin.IntArray, ignore: java.util.List) = array diff --git a/compiler/testData/compileKotlinAgainstJava/AbstractClass.java b/compiler/testData/compileKotlinAgainstJava/AbstractClass.java new file mode 100644 index 00000000000..f54a5d08a1c --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AbstractClass.java @@ -0,0 +1,7 @@ +package test; + +public abstract class AbstractClass { + + public abstract void implementMe(); + +} diff --git a/compiler/testData/compileKotlinAgainstJava/AbstractClass.kt b/compiler/testData/compileKotlinAgainstJava/AbstractClass.kt new file mode 100644 index 00000000000..4dec09513e6 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AbstractClass.kt @@ -0,0 +1,7 @@ +package test + +class AbstractClassImpl : AbstractClass() { + + override fun implementMe() {} + +} diff --git a/compiler/testData/compileKotlinAgainstJava/AbstractClass.txt b/compiler/testData/compileKotlinAgainstJava/AbstractClass.txt new file mode 100644 index 00000000000..2dbc7989727 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AbstractClass.txt @@ -0,0 +1,11 @@ +package test + +public abstract class AbstractClass { + public constructor AbstractClass() + public abstract fun implementMe(): kotlin.Unit +} + +public final class AbstractClassImpl : test.AbstractClass { + public constructor AbstractClassImpl() + public open fun implementMe(): kotlin.Unit +} diff --git a/compiler/testData/compileKotlinAgainstJava/AbstractEnum.java b/compiler/testData/compileKotlinAgainstJava/AbstractEnum.java new file mode 100644 index 00000000000..9376f8b69a7 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AbstractEnum.java @@ -0,0 +1,12 @@ +package test; + +public enum AbstractEnum { + + ONE { + @Override + String getString() { return null; } + }; + + abstract String getString(); + +} diff --git a/compiler/testData/compileKotlinAgainstJava/AbstractEnum.kt b/compiler/testData/compileKotlinAgainstJava/AbstractEnum.kt new file mode 100644 index 00000000000..558caefeb5b --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AbstractEnum.kt @@ -0,0 +1,3 @@ +package test + +fun useEnum() = AbstractEnum.ONE.getString() diff --git a/compiler/testData/compileKotlinAgainstJava/AbstractEnum.txt b/compiler/testData/compileKotlinAgainstJava/AbstractEnum.txt new file mode 100644 index 00000000000..29039547669 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AbstractEnum.txt @@ -0,0 +1,22 @@ +package test + +public fun useEnum(): kotlin.String! + +public abstract enum class AbstractEnum : kotlin.Enum { + enum entry ONE + + private constructor AbstractEnum() + public final /*fake_override*/ val name: kotlin.String + public final /*fake_override*/ val ordinal: kotlin.Int + protected final /*fake_override*/ fun clone(): kotlin.Any + public final /*fake_override*/ fun compareTo(/*0*/ test.AbstractEnum!): kotlin.Int + protected/*protected and package*/ final /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + public/*package*/ abstract fun getString(): kotlin.String! + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ kotlin.String): test.AbstractEnum + public open fun valueOf(/*0*/ kotlin.String!): test.AbstractEnum! + public open fun values(): kotlin.Array<(out) test.AbstractEnum!>! + public final /*synthesized*/ fun values(): kotlin.Array +} diff --git a/compiler/testData/compileKotlinAgainstJava/AnnotationWithArguments.java b/compiler/testData/compileKotlinAgainstJava/AnnotationWithArguments.java new file mode 100644 index 00000000000..d695c2af821 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AnnotationWithArguments.java @@ -0,0 +1,12 @@ +package test; + +import java.lang.annotation.*; + +@Target(value=ElementType.TYPE) +public @interface AnnotationWithArguments { + + String name(); + + String arg() default "default"; + +} diff --git a/compiler/testData/compileKotlinAgainstJava/AnnotationWithArguments.kt b/compiler/testData/compileKotlinAgainstJava/AnnotationWithArguments.kt new file mode 100644 index 00000000000..389035d9dbe --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AnnotationWithArguments.kt @@ -0,0 +1,7 @@ +package test + +@AnnotationWithArguments(name="withDefault") +class ClassWithDefault + +@AnnotationWithArguments(name="withoutDefault", arg="non") +class ClassWithoutDefault diff --git a/compiler/testData/compileKotlinAgainstJava/AnnotationWithArguments.txt b/compiler/testData/compileKotlinAgainstJava/AnnotationWithArguments.txt new file mode 100644 index 00000000000..575ee4ce9ff --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AnnotationWithArguments.txt @@ -0,0 +1,15 @@ +package test + +@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS, AnnotationTarget.FILE}) public final annotation class AnnotationWithArguments : kotlin.Annotation { + public constructor AnnotationWithArguments(/*0*/ kotlin.String, /*1*/ kotlin.String = ...) + public final val arg: kotlin.String + public final val name: kotlin.String +} + +@test.AnnotationWithArguments(name = "withDefault") public final class ClassWithDefault { + public constructor ClassWithDefault() +} + +@test.AnnotationWithArguments(arg = "non", name = "withoutDefault") public final class ClassWithoutDefault { + public constructor ClassWithoutDefault() +} diff --git a/compiler/testData/compileKotlinAgainstJava/AnnotationWithField.java b/compiler/testData/compileKotlinAgainstJava/AnnotationWithField.java new file mode 100644 index 00000000000..dda7f0d1140 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AnnotationWithField.java @@ -0,0 +1,9 @@ +package test; + +public @interface AnnotationWithField { + + String text(); + + int ANSWER = 42; + +} diff --git a/compiler/testData/compileKotlinAgainstJava/AnnotationWithField.kt b/compiler/testData/compileKotlinAgainstJava/AnnotationWithField.kt new file mode 100644 index 00000000000..8c7d5418937 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AnnotationWithField.kt @@ -0,0 +1,4 @@ +package test + +@AnnotationWithField(text="desc") +class SomeClass diff --git a/compiler/testData/compileKotlinAgainstJava/AnnotationWithField.txt b/compiler/testData/compileKotlinAgainstJava/AnnotationWithField.txt new file mode 100644 index 00000000000..51b024cabe5 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AnnotationWithField.txt @@ -0,0 +1,13 @@ +package test + +public final annotation class AnnotationWithField : kotlin.Annotation { + public constructor AnnotationWithField(/*0*/ kotlin.String) + public final val text: kotlin.String + + // Static members + public const final val ANSWER: kotlin.Int +} + +@test.AnnotationWithField(text = "desc") public final class SomeClass { + public constructor SomeClass() +} diff --git a/compiler/testData/compileKotlinAgainstJava/AsteriskInImport.java b/compiler/testData/compileKotlinAgainstJava/AsteriskInImport.java new file mode 100644 index 00000000000..afa54b72846 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AsteriskInImport.java @@ -0,0 +1,9 @@ +package test; + +import java.util.*; + +public class AsteriskInImport { + + public static List getStrings() { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/AsteriskInImport.kt b/compiler/testData/compileKotlinAgainstJava/AsteriskInImport.kt new file mode 100644 index 00000000000..24571ce1aaf --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AsteriskInImport.kt @@ -0,0 +1,3 @@ +package test + +fun getStrings() = AsteriskInImport.getStrings() diff --git a/compiler/testData/compileKotlinAgainstJava/AsteriskInImport.txt b/compiler/testData/compileKotlinAgainstJava/AsteriskInImport.txt new file mode 100644 index 00000000000..94c0db3885f --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/AsteriskInImport.txt @@ -0,0 +1,10 @@ +package test + +public fun getStrings(): kotlin.collections.(Mutable)List! + +public open class AsteriskInImport { + public constructor AsteriskInImport() + + // Static members + public open fun getStrings(): kotlin.collections.(Mutable)List! +} diff --git a/compiler/testData/compileKotlinAgainstJava/CheckKotlinStub.java b/compiler/testData/compileKotlinAgainstJava/CheckKotlinStub.java new file mode 100644 index 00000000000..e331a057233 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/CheckKotlinStub.java @@ -0,0 +1,7 @@ +package test; + +import test2.*; + +public class CheckKotlinStub { + public KotlinStub getKotlinStub() { return null; } +} diff --git a/compiler/testData/compileKotlinAgainstJava/CheckKotlinStub.kt b/compiler/testData/compileKotlinAgainstJava/CheckKotlinStub.kt new file mode 100644 index 00000000000..c5b2d0d74de --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/CheckKotlinStub.kt @@ -0,0 +1,7 @@ +package test2 + +import test.* + +class KotlinStub + +fun checkKotlinStub() = CheckKotlinStub().getKotlinStub() diff --git a/compiler/testData/compileKotlinAgainstJava/CheckKotlinStub.txt b/compiler/testData/compileKotlinAgainstJava/CheckKotlinStub.txt new file mode 100644 index 00000000000..48378eb56b6 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/CheckKotlinStub.txt @@ -0,0 +1,6 @@ +package test + +public open class CheckKotlinStub { + public constructor CheckKotlinStub() + public open fun getKotlinStub(): test2.KotlinStub! +} diff --git a/compiler/testData/compileKotlinAgainstJava/CheckNotNull.java b/compiler/testData/compileKotlinAgainstJava/CheckNotNull.java new file mode 100644 index 00000000000..757fdaff9ab --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/CheckNotNull.java @@ -0,0 +1,10 @@ +package test; + +import org.jetbrains.annotations.NotNull; + +public class CheckNotNull { + + @NotNull + public String returnNotNull() { return "42"; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/CheckNotNull.kt b/compiler/testData/compileKotlinAgainstJava/CheckNotNull.kt new file mode 100644 index 00000000000..c070ce3feeb --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/CheckNotNull.kt @@ -0,0 +1,3 @@ +package test + +fun notNullable(): String = CheckNotNull().returnNotNull() diff --git a/compiler/testData/compileKotlinAgainstJava/CheckNotNull.txt b/compiler/testData/compileKotlinAgainstJava/CheckNotNull.txt new file mode 100644 index 00000000000..d71ecd2a616 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/CheckNotNull.txt @@ -0,0 +1,8 @@ +package test + +public fun notNullable(): kotlin.String + +public open class CheckNotNull { + public constructor CheckNotNull() + @org.jetbrains.annotations.NotNull public open fun returnNotNull(): kotlin.String +} diff --git a/compiler/testData/compileKotlinAgainstJava/Class.java b/compiler/testData/compileKotlinAgainstJava/Class.java new file mode 100644 index 00000000000..4e7b8ff7c7d --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Class.java @@ -0,0 +1,11 @@ +package test; + +public class Class { + + private final String str; + + public Class(String str) { + this.str = str; + } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/Class.kt b/compiler/testData/compileKotlinAgainstJava/Class.kt new file mode 100644 index 00000000000..3ad9d3594ee --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Class.kt @@ -0,0 +1,3 @@ +package test + +fun useClass() = Class("Hello") diff --git a/compiler/testData/compileKotlinAgainstJava/Class.txt b/compiler/testData/compileKotlinAgainstJava/Class.txt new file mode 100644 index 00000000000..f8ff1365973 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Class.txt @@ -0,0 +1,8 @@ +package test + +public fun useClass(): test.Class + +public open class Class { + public constructor Class(/*0*/ kotlin.String!) + private final val str: kotlin.String! +} diff --git a/compiler/testData/compileKotlinAgainstJava/ClassWithNestedEnum.java b/compiler/testData/compileKotlinAgainstJava/ClassWithNestedEnum.java new file mode 100644 index 00000000000..aa0d25c0f17 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ClassWithNestedEnum.java @@ -0,0 +1,9 @@ +package test; + +public class ClassWithNestedEnum { + + public enum NestedEnum { + ONE, TWO, THREE; + } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/ClassWithNestedEnum.kt b/compiler/testData/compileKotlinAgainstJava/ClassWithNestedEnum.kt new file mode 100644 index 00000000000..327f0c5230c --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ClassWithNestedEnum.kt @@ -0,0 +1,3 @@ +package test + +fun test() = ClassWithNestedEnum.NestedEnum.ONE diff --git a/compiler/testData/compileKotlinAgainstJava/ClassWithNestedEnum.txt b/compiler/testData/compileKotlinAgainstJava/ClassWithNestedEnum.txt new file mode 100644 index 00000000000..eaec38e02ca --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ClassWithNestedEnum.txt @@ -0,0 +1,29 @@ +package test + +public fun test(): test.ClassWithNestedEnum.NestedEnum + +public open class ClassWithNestedEnum { + public constructor ClassWithNestedEnum() + + public final enum class NestedEnum : kotlin.Enum { + enum entry ONE + + enum entry TWO + + enum entry THREE + + private constructor NestedEnum() + public final /*fake_override*/ val name: kotlin.String + public final /*fake_override*/ val ordinal: kotlin.Int + protected final /*fake_override*/ fun clone(): kotlin.Any + public final /*fake_override*/ fun compareTo(/*0*/ test.ClassWithNestedEnum.NestedEnum!): kotlin.Int + protected/*protected and package*/ final /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ kotlin.String): test.ClassWithNestedEnum.NestedEnum + public open fun valueOf(/*0*/ kotlin.String!): test.ClassWithNestedEnum.NestedEnum! + public open fun values(): kotlin.Array<(out) test.ClassWithNestedEnum.NestedEnum!>! + public final /*synthesized*/ fun values(): kotlin.Array + } +} diff --git a/compiler/testData/compileKotlinAgainstJava/ClassWithTypeParameter.java b/compiler/testData/compileKotlinAgainstJava/ClassWithTypeParameter.java new file mode 100644 index 00000000000..7d5404c6cfc --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ClassWithTypeParameter.java @@ -0,0 +1,7 @@ +package test; + +public class ClassWithTypeParameter { + + public ClassWithTypeParameter(T kotlinInterface) {} + +} diff --git a/compiler/testData/compileKotlinAgainstJava/ClassWithTypeParameter.kt b/compiler/testData/compileKotlinAgainstJava/ClassWithTypeParameter.kt new file mode 100644 index 00000000000..e09023c946a --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ClassWithTypeParameter.kt @@ -0,0 +1,15 @@ +package test + +interface KotlinInterface + +class Impl1 : KotlinInterface + +class Impl2 : KotlinInterface + +class Impl3 : KotlinInterface + +fun getProducer1() = Impl1().let(::ClassWithTypeParameter) + +fun getProducer2() = Impl2().let(::ClassWithTypeParameter) + +fun getProducer3() = Impl3().let(::ClassWithTypeParameter) diff --git a/compiler/testData/compileKotlinAgainstJava/ClassWithTypeParameter.txt b/compiler/testData/compileKotlinAgainstJava/ClassWithTypeParameter.txt new file mode 100644 index 00000000000..18df1a30f07 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ClassWithTypeParameter.txt @@ -0,0 +1,24 @@ +package test + +public fun getProducer1(): test.ClassWithTypeParameter +public fun getProducer2(): test.ClassWithTypeParameter +public fun getProducer3(): test.ClassWithTypeParameter + +public open class ClassWithTypeParameter { + public constructor ClassWithTypeParameter(/*0*/ T!) +} + +public final class Impl1 : test.KotlinInterface { + public constructor Impl1() +} + +public final class Impl2 : test.KotlinInterface { + public constructor Impl2() +} + +public final class Impl3 : test.KotlinInterface { + public constructor Impl3() +} + +public interface KotlinInterface { +} diff --git a/compiler/testData/compileKotlinAgainstJava/CyclicDependencies.java b/compiler/testData/compileKotlinAgainstJava/CyclicDependencies.java new file mode 100644 index 00000000000..1e95a960535 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/CyclicDependencies.java @@ -0,0 +1,13 @@ +package test; + +public class CyclicDependencies { + + public KotlinClass useKotlinClass() { + return new KotlinClass().getKotlinClass(); + } + + public KotlinClass2 useKotlinClass2(KotlinClass kotlinClass) { + return new KotlinClass2(); + } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/CyclicDependencies.kt b/compiler/testData/compileKotlinAgainstJava/CyclicDependencies.kt new file mode 100644 index 00000000000..67b0c2205ac --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/CyclicDependencies.kt @@ -0,0 +1,13 @@ +package test + +class KotlinClass { + fun getKotlinClass() = KotlinClass() +} + +class KotlinClass2 { + val str = "HELLO" +} + +fun useJavaClass() = CyclicDependencies().apply { + useKotlinClass().let { useKotlinClass2(it) } +}.let { it.useKotlinClass2(it.useKotlinClass()) } diff --git a/compiler/testData/compileKotlinAgainstJava/CyclicDependencies.txt b/compiler/testData/compileKotlinAgainstJava/CyclicDependencies.txt new file mode 100644 index 00000000000..06ca51fb78c --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/CyclicDependencies.txt @@ -0,0 +1,19 @@ +package test + +public fun useJavaClass(): test.KotlinClass2! + +public open class CyclicDependencies { + public constructor CyclicDependencies() + public open fun useKotlinClass(): test.KotlinClass! + public open fun useKotlinClass2(/*0*/ test.KotlinClass!): test.KotlinClass2! +} + +public final class KotlinClass { + public constructor KotlinClass() + public final fun getKotlinClass(): test.KotlinClass +} + +public final class KotlinClass2 { + public constructor KotlinClass2() + public final val str: kotlin.String +} diff --git a/compiler/testData/compileKotlinAgainstJava/DefaultModifier.java b/compiler/testData/compileKotlinAgainstJava/DefaultModifier.java new file mode 100644 index 00000000000..17cbb92a3fe --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/DefaultModifier.java @@ -0,0 +1,11 @@ +package test; + +public class DefaultModifier implements WithDefault { + +} + +interface WithDefault { + + default String getString() { return "str"; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/DefaultModifier.kt b/compiler/testData/compileKotlinAgainstJava/DefaultModifier.kt new file mode 100644 index 00000000000..407d7d52433 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/DefaultModifier.kt @@ -0,0 +1,3 @@ +package test + +fun useDefaultMethod() = DefaultModifier().getString() diff --git a/compiler/testData/compileKotlinAgainstJava/DefaultModifier.txt b/compiler/testData/compileKotlinAgainstJava/DefaultModifier.txt new file mode 100644 index 00000000000..de3dd6652dc --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/DefaultModifier.txt @@ -0,0 +1,12 @@ +package test + +public fun useDefaultMethod(): kotlin.String! + +public open class DefaultModifier : test.WithDefault { + public constructor DefaultModifier() + public open /*fake_override*/ fun getString(): kotlin.String! +} + +public/*package*/ interface WithDefault { + public open fun getString(): kotlin.String! +} diff --git a/compiler/testData/compileKotlinAgainstJava/EnclosingClassInner.java b/compiler/testData/compileKotlinAgainstJava/EnclosingClassInner.java new file mode 100644 index 00000000000..291431ea667 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/EnclosingClassInner.java @@ -0,0 +1,22 @@ +package test; + +class InterfaceImpl implements Interface { + + interface BuilderImpl extends Interface.Builder { + @Override + Builder setKind(Kind kind); + } + + Builder getBuilder() { return null; } + +} + +interface Interface { + + enum Kind { DECLARATION; } + + interface Builder { + Builder setKind(Kind kind); + } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/EnclosingClassInner.kt b/compiler/testData/compileKotlinAgainstJava/EnclosingClassInner.kt new file mode 100644 index 00000000000..ec934a751a1 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/EnclosingClassInner.kt @@ -0,0 +1,7 @@ +package test + +private class Impl : InterfaceImpl() { + + private fun kind(kind: Interface.Kind) = getBuilder().setKind(kind) + +} diff --git a/compiler/testData/compileKotlinAgainstJava/EnclosingClassInner.txt b/compiler/testData/compileKotlinAgainstJava/EnclosingClassInner.txt new file mode 100644 index 00000000000..842dc4a9ced --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/EnclosingClassInner.txt @@ -0,0 +1,41 @@ +package test + +private final class Impl : test.InterfaceImpl { + public constructor Impl() + public/*package*/ open /*fake_override*/ fun getBuilder(): test.Interface.Builder! + private final fun kind(/*0*/ test.Interface.Kind): test.Interface.Builder! +} + +public/*package*/ interface Interface { + + public interface Builder { + public abstract fun setKind(/*0*/ test.Interface.Kind!): test.Interface.Builder! + } + + public final enum class Kind : kotlin.Enum { + enum entry DECLARATION + + private constructor Kind() + public final /*fake_override*/ val name: kotlin.String + public final /*fake_override*/ val ordinal: kotlin.Int + protected final /*fake_override*/ fun clone(): kotlin.Any + public final /*fake_override*/ fun compareTo(/*0*/ test.Interface.Kind!): kotlin.Int + protected/*protected and package*/ final /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ kotlin.String): test.Interface.Kind + public open fun valueOf(/*0*/ kotlin.String!): test.Interface.Kind! + public open fun values(): kotlin.Array<(out) test.Interface.Kind!>! + public final /*synthesized*/ fun values(): kotlin.Array + } +} + +public/*package*/ open class InterfaceImpl : test.Interface { + public/*package*/ constructor InterfaceImpl() + public/*package*/ open fun getBuilder(): test.Interface.Builder! + + public/*package*/ interface BuilderImpl : test.Interface.Builder { + public abstract fun setKind(/*0*/ test.Interface.Kind!): test.Interface.Builder! + } +} diff --git a/compiler/testData/compileKotlinAgainstJava/Enum.java b/compiler/testData/compileKotlinAgainstJava/Enum.java new file mode 100644 index 00000000000..fa227f736a7 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Enum.java @@ -0,0 +1,5 @@ +package test; + +public enum Enum { + NORTH, SOUTH, WEST, EAST; +} diff --git a/compiler/testData/compileKotlinAgainstJava/Enum.kt b/compiler/testData/compileKotlinAgainstJava/Enum.kt new file mode 100644 index 00000000000..154237eb5c0 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Enum.kt @@ -0,0 +1,8 @@ +package test + +fun checkEnum(e: Enum) = when(e) { + Enum.SOUTH -> println(1) + Enum.NORTH -> println(2) + Enum.WEST -> println(3) + Enum.EAST -> println(42) +} diff --git a/compiler/testData/compileKotlinAgainstJava/Enum.txt b/compiler/testData/compileKotlinAgainstJava/Enum.txt new file mode 100644 index 00000000000..3a14a997630 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Enum.txt @@ -0,0 +1,27 @@ +package test + +public fun checkEnum(/*0*/ test.Enum): kotlin.Unit + +public final enum class Enum : kotlin.Enum { + enum entry NORTH + + enum entry SOUTH + + enum entry WEST + + enum entry EAST + + private constructor Enum() + public final /*fake_override*/ val name: kotlin.String + public final /*fake_override*/ val ordinal: kotlin.Int + protected final /*fake_override*/ fun clone(): kotlin.Any + public final /*fake_override*/ fun compareTo(/*0*/ test.Enum!): kotlin.Int + protected/*protected and package*/ final /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ kotlin.String): test.Enum + public open fun valueOf(/*0*/ kotlin.String!): test.Enum! + public open fun values(): kotlin.Array<(out) test.Enum!>! + public final /*synthesized*/ fun values(): kotlin.Array +} diff --git a/compiler/testData/compileKotlinAgainstJava/EnumName.java b/compiler/testData/compileKotlinAgainstJava/EnumName.java new file mode 100644 index 00000000000..b2dd99de463 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/EnumName.java @@ -0,0 +1,5 @@ +package test; + +public enum EnumName { + FIRST, SECOND; +} diff --git a/compiler/testData/compileKotlinAgainstJava/EnumName.kt b/compiler/testData/compileKotlinAgainstJava/EnumName.kt new file mode 100644 index 00000000000..d0047e0383a --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/EnumName.kt @@ -0,0 +1,3 @@ +package test + +fun func(enum: EnumName) = enum.name diff --git a/compiler/testData/compileKotlinAgainstJava/EnumName.txt b/compiler/testData/compileKotlinAgainstJava/EnumName.txt new file mode 100644 index 00000000000..026a18a70c2 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/EnumName.txt @@ -0,0 +1,23 @@ +package test + +public fun func(/*0*/ test.EnumName): kotlin.String + +public final enum class EnumName : kotlin.Enum { + enum entry FIRST + + enum entry SECOND + + private constructor EnumName() + public final /*fake_override*/ val name: kotlin.String + public final /*fake_override*/ val ordinal: kotlin.Int + protected final /*fake_override*/ fun clone(): kotlin.Any + public final /*fake_override*/ fun compareTo(/*0*/ test.EnumName!): kotlin.Int + protected/*protected and package*/ final /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ kotlin.String): test.EnumName + public open fun valueOf(/*0*/ kotlin.String!): test.EnumName! + public open fun values(): kotlin.Array<(out) test.EnumName!>! + public final /*synthesized*/ fun values(): kotlin.Array +} diff --git a/compiler/testData/compileKotlinAgainstJava/Inheritance.java b/compiler/testData/compileKotlinAgainstJava/Inheritance.java new file mode 100644 index 00000000000..985c2b3e0df --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Inheritance.java @@ -0,0 +1,25 @@ +package test; + +public class Inheritance extends AbstractInheritance { } + +abstract class AbstractInheritance implements Interface { + + @Override public int getAnswer() { return 42; } + +} + +interface Interface extends I { + @Override + int getAnswer(); +} + +interface I { + int getAnswer(); +} + +interface I2 extends I { + + @Override + int getAnswer(); + +} diff --git a/compiler/testData/compileKotlinAgainstJava/Inheritance.kt b/compiler/testData/compileKotlinAgainstJava/Inheritance.kt new file mode 100644 index 00000000000..3186c89ea13 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Inheritance.kt @@ -0,0 +1,3 @@ +package test + +class InheritanceImpl : Inheritance(), I2 diff --git a/compiler/testData/compileKotlinAgainstJava/Inheritance.txt b/compiler/testData/compileKotlinAgainstJava/Inheritance.txt new file mode 100644 index 00000000000..cc8f9c2b0cd --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Inheritance.txt @@ -0,0 +1,28 @@ +package test + +public/*package*/ abstract class AbstractInheritance : test.Interface { + public/*package*/ constructor AbstractInheritance() + public open fun getAnswer(): kotlin.Int +} + +public/*package*/ interface I { + public abstract fun getAnswer(): kotlin.Int +} + +public/*package*/ interface I2 : test.I { + public abstract fun getAnswer(): kotlin.Int +} + +public open class Inheritance : test.AbstractInheritance { + public constructor Inheritance() + public open /*fake_override*/ fun getAnswer(): kotlin.Int +} + +public final class InheritanceImpl : test.Inheritance, test.I2 { + public constructor InheritanceImpl() + public open /*fake_override*/ fun getAnswer(): kotlin.Int +} + +public/*package*/ interface Interface : test.I { + public abstract fun getAnswer(): kotlin.Int +} diff --git a/compiler/testData/compileKotlinAgainstJava/InheritedInner.java b/compiler/testData/compileKotlinAgainstJava/InheritedInner.java new file mode 100644 index 00000000000..c86d4b9d3e0 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InheritedInner.java @@ -0,0 +1,17 @@ +package test; + +public class InheritedInner { + + public Third.Second getSecond() { return null; } + + public static class First { + + public static class Second {} + + } + + public static class Third extends First { + + } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/InheritedInner.kt b/compiler/testData/compileKotlinAgainstJava/InheritedInner.kt new file mode 100644 index 00000000000..caa15a88b65 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InheritedInner.kt @@ -0,0 +1,3 @@ +package test + +fun getSecond(): InheritedInner.First.Second = InheritedInner().getSecond() diff --git a/compiler/testData/compileKotlinAgainstJava/InheritedInner.txt b/compiler/testData/compileKotlinAgainstJava/InheritedInner.txt new file mode 100644 index 00000000000..3ce65d9abff --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InheritedInner.txt @@ -0,0 +1,20 @@ +package test + +public fun getSecond(): test.InheritedInner.First.Second + +public open class InheritedInner { + public constructor InheritedInner() + public open fun getSecond(): test.InheritedInner.First.Second! + + public open class First { + public constructor First() + + public open class Second { + public constructor Second() + } + } + + public open class Third : test.InheritedInner.First { + public constructor Third() + } +} diff --git a/compiler/testData/compileKotlinAgainstJava/InnerCanonicalName.java b/compiler/testData/compileKotlinAgainstJava/InnerCanonicalName.java new file mode 100644 index 00000000000..e10d2422cb8 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InnerCanonicalName.java @@ -0,0 +1,7 @@ +package test; + +public class InnerCanonicalName { + + public java.util.Map.Entry getEntry() { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/InnerCanonicalName.kt b/compiler/testData/compileKotlinAgainstJava/InnerCanonicalName.kt new file mode 100644 index 00000000000..e7e000e5089 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InnerCanonicalName.kt @@ -0,0 +1,3 @@ +package test + +fun getEntry() = InnerCanonicalName().getEntry() diff --git a/compiler/testData/compileKotlinAgainstJava/InnerCanonicalName.txt b/compiler/testData/compileKotlinAgainstJava/InnerCanonicalName.txt new file mode 100644 index 00000000000..785436e82fb --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InnerCanonicalName.txt @@ -0,0 +1,8 @@ +package test + +public fun getEntry(): kotlin.collections.(Mutable)Map.(Mutable)Entry<(raw) kotlin.Any?, (raw) kotlin.Any?>! + +public open class InnerCanonicalName { + public constructor InnerCanonicalName() + public open fun getEntry(): kotlin.collections.(Mutable)Map.(Mutable)Entry<(raw) kotlin.Any?, (raw) kotlin.Any?>! +} diff --git a/compiler/testData/compileKotlinAgainstJava/InnerClass.java b/compiler/testData/compileKotlinAgainstJava/InnerClass.java new file mode 100644 index 00000000000..0ef46f95542 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InnerClass.java @@ -0,0 +1,9 @@ +package test; + +public class InnerClass { + + class Inner { + public void doNothing() {} + } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/InnerClass.kt b/compiler/testData/compileKotlinAgainstJava/InnerClass.kt new file mode 100644 index 00000000000..012d71ce939 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InnerClass.kt @@ -0,0 +1,3 @@ +package test + +fun useInnerClass() = InnerClass().Inner().doNothing() diff --git a/compiler/testData/compileKotlinAgainstJava/InnerClass.txt b/compiler/testData/compileKotlinAgainstJava/InnerClass.txt new file mode 100644 index 00000000000..6f6907a771e --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InnerClass.txt @@ -0,0 +1,12 @@ +package test + +public fun useInnerClass(): kotlin.Unit + +public open class InnerClass { + public constructor InnerClass() + + public/*package*/ open inner class Inner { + public/*package*/ constructor Inner() + public open fun doNothing(): kotlin.Unit + } +} diff --git a/compiler/testData/compileKotlinAgainstJava/InnerClassFromAsteriskImport.java b/compiler/testData/compileKotlinAgainstJava/InnerClassFromAsteriskImport.java new file mode 100644 index 00000000000..c5e46ad8b87 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InnerClassFromAsteriskImport.java @@ -0,0 +1,9 @@ +package test; + +import java.util.*; + +class InnerClassFromAsteriskImport { + + public HashMap.Entry getEntry() { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/InnerClassFromAsteriskImport.kt b/compiler/testData/compileKotlinAgainstJava/InnerClassFromAsteriskImport.kt new file mode 100644 index 00000000000..66acb50da44 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InnerClassFromAsteriskImport.kt @@ -0,0 +1,3 @@ +package test + +fun getEntry() = InnerClassFromAsteriskImport().getEntry() diff --git a/compiler/testData/compileKotlinAgainstJava/InnerClassFromAsteriskImport.txt b/compiler/testData/compileKotlinAgainstJava/InnerClassFromAsteriskImport.txt new file mode 100644 index 00000000000..f36bf3f9843 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InnerClassFromAsteriskImport.txt @@ -0,0 +1,8 @@ +package test + +public fun getEntry(): kotlin.collections.(Mutable)Map.(Mutable)Entry<(raw) kotlin.Any?, (raw) kotlin.Any?>! + +public/*package*/ open class InnerClassFromAsteriskImport { + public/*package*/ constructor InnerClassFromAsteriskImport() + public open fun getEntry(): kotlin.collections.(Mutable)Map.(Mutable)Entry<(raw) kotlin.Any?, (raw) kotlin.Any?>! +} diff --git a/compiler/testData/compileKotlinAgainstJava/InnerClassFromImport.java b/compiler/testData/compileKotlinAgainstJava/InnerClassFromImport.java new file mode 100644 index 00000000000..89ade4e5468 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InnerClassFromImport.java @@ -0,0 +1,9 @@ +package test; + +import java.util.Map; + +public class InnerClassFromImport { + + public Map.Entry getEntry() { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/InnerClassFromImport.kt b/compiler/testData/compileKotlinAgainstJava/InnerClassFromImport.kt new file mode 100644 index 00000000000..dd88ede62bf --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InnerClassFromImport.kt @@ -0,0 +1,3 @@ +package test + +fun getEntry() = InnerClassFromImport().getEntry() diff --git a/compiler/testData/compileKotlinAgainstJava/InnerClassFromImport.txt b/compiler/testData/compileKotlinAgainstJava/InnerClassFromImport.txt new file mode 100644 index 00000000000..a629ccb4cd7 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InnerClassFromImport.txt @@ -0,0 +1,8 @@ +package test + +public fun getEntry(): kotlin.collections.(Mutable)Map.(Mutable)Entry<(raw) kotlin.Any?, (raw) kotlin.Any?>! + +public open class InnerClassFromImport { + public constructor InnerClassFromImport() + public open fun getEntry(): kotlin.collections.(Mutable)Map.(Mutable)Entry<(raw) kotlin.Any?, (raw) kotlin.Any?>! +} diff --git a/compiler/testData/compileKotlinAgainstJava/Interface.java b/compiler/testData/compileKotlinAgainstJava/Interface.java new file mode 100644 index 00000000000..c0c92b7a06b --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Interface.java @@ -0,0 +1,5 @@ +package test; + +interface Interface { + +} diff --git a/compiler/testData/compileKotlinAgainstJava/Interface.kt b/compiler/testData/compileKotlinAgainstJava/Interface.kt new file mode 100644 index 00000000000..a80d97d9fbd --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Interface.kt @@ -0,0 +1,5 @@ +package test + +class InterfaceImpl : Interface { + +} diff --git a/compiler/testData/compileKotlinAgainstJava/Interface.txt b/compiler/testData/compileKotlinAgainstJava/Interface.txt new file mode 100644 index 00000000000..474785604e8 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Interface.txt @@ -0,0 +1,8 @@ +package test + +public/*package*/ interface Interface { +} + +public final class InterfaceImpl : test.Interface { + public constructor InterfaceImpl() +} diff --git a/compiler/testData/compileKotlinAgainstJava/InterfaceField.java b/compiler/testData/compileKotlinAgainstJava/InterfaceField.java new file mode 100644 index 00000000000..726f6b78a8e --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InterfaceField.java @@ -0,0 +1,9 @@ +package test; + +public interface InterfaceField { + + String STRING = "str"; + + String func(); + +} diff --git a/compiler/testData/compileKotlinAgainstJava/InterfaceField.kt b/compiler/testData/compileKotlinAgainstJava/InterfaceField.kt new file mode 100644 index 00000000000..f821e6b0511 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InterfaceField.kt @@ -0,0 +1,9 @@ +package test + +fun useField() = InterfaceField.STRING + +fun implementInterface() = object : InterfaceField { + override fun func() = "str" +} + +fun useFunc() = implementInterface().func() diff --git a/compiler/testData/compileKotlinAgainstJava/InterfaceField.txt b/compiler/testData/compileKotlinAgainstJava/InterfaceField.txt new file mode 100644 index 00000000000..1146d4f6800 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InterfaceField.txt @@ -0,0 +1,12 @@ +package test + +public fun implementInterface(): test.InterfaceField +public fun useField(): kotlin.String +public fun useFunc(): kotlin.String! + +public interface InterfaceField { + public abstract fun func(): kotlin.String! + + // Static members + public const final val STRING: kotlin.String +} diff --git a/compiler/testData/compileKotlinAgainstJava/InterfaceMemberClass.java b/compiler/testData/compileKotlinAgainstJava/InterfaceMemberClass.java new file mode 100644 index 00000000000..8a3f35d0cb0 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InterfaceMemberClass.java @@ -0,0 +1,9 @@ +package test; + +interface InterfaceMemberClass { + + class MemberClass { + public String func() { return "str"; } + } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/InterfaceMemberClass.kt b/compiler/testData/compileKotlinAgainstJava/InterfaceMemberClass.kt new file mode 100644 index 00000000000..c24bc252f28 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InterfaceMemberClass.kt @@ -0,0 +1,3 @@ +package test + +private fun useInterfaceMemberClass() = InterfaceMemberClass.MemberClass().func() diff --git a/compiler/testData/compileKotlinAgainstJava/InterfaceMemberClass.txt b/compiler/testData/compileKotlinAgainstJava/InterfaceMemberClass.txt new file mode 100644 index 00000000000..2e84e4858a1 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InterfaceMemberClass.txt @@ -0,0 +1,11 @@ +package test + +private fun useInterfaceMemberClass(): kotlin.String! + +public/*package*/ interface InterfaceMemberClass { + + public open class MemberClass { + public constructor MemberClass() + public open fun func(): kotlin.String! + } +} diff --git a/compiler/testData/compileKotlinAgainstJava/InterfaceWithDefault.java b/compiler/testData/compileKotlinAgainstJava/InterfaceWithDefault.java new file mode 100644 index 00000000000..c4b2c813591 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InterfaceWithDefault.java @@ -0,0 +1,7 @@ +package test; + +public interface InterfaceWithDefault { + + default String defaultMethod() { return "str"; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/InterfaceWithDefault.kt b/compiler/testData/compileKotlinAgainstJava/InterfaceWithDefault.kt new file mode 100644 index 00000000000..3a22b131d31 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InterfaceWithDefault.kt @@ -0,0 +1,3 @@ +package test + +class InterfaceWithDefaultImpl : InterfaceWithDefault diff --git a/compiler/testData/compileKotlinAgainstJava/InterfaceWithDefault.txt b/compiler/testData/compileKotlinAgainstJava/InterfaceWithDefault.txt new file mode 100644 index 00000000000..3cf38ad6aed --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/InterfaceWithDefault.txt @@ -0,0 +1,10 @@ +package test + +public interface InterfaceWithDefault { + public open fun defaultMethod(): kotlin.String! +} + +public final class InterfaceWithDefaultImpl : test.InterfaceWithDefault { + public constructor InterfaceWithDefaultImpl() + public open /*fake_override*/ fun defaultMethod(): kotlin.String! +} diff --git a/compiler/testData/compileKotlinAgainstJava/ListImpl.java b/compiler/testData/compileKotlinAgainstJava/ListImpl.java new file mode 100644 index 00000000000..e065aafc39f --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ListImpl.java @@ -0,0 +1,9 @@ +package test; + +import java.util.ArrayList; + +abstract class ListImpl extends ArrayList { + + public abstract int func(); + +} diff --git a/compiler/testData/compileKotlinAgainstJava/ListImpl.kt b/compiler/testData/compileKotlinAgainstJava/ListImpl.kt new file mode 100644 index 00000000000..9a296408d78 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ListImpl.kt @@ -0,0 +1,5 @@ +package test + +fun useListImpl() = object : ListImpl() { + override fun func() = 42 + }.func() diff --git a/compiler/testData/compileKotlinAgainstJava/ListImpl.txt b/compiler/testData/compileKotlinAgainstJava/ListImpl.txt new file mode 100644 index 00000000000..e8efe46b11c --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ListImpl.txt @@ -0,0 +1,66 @@ +package test + +public fun useListImpl(): kotlin.Int + +public/*package*/ abstract class ListImpl : java.util.ArrayList { + public/*package*/ constructor ListImpl() + invisible_fake final /*fake_override*/ var elementData: kotlin.Array<(out) kotlin.Any!>! + protected/*protected and package*/ final /*fake_override*/ var modCount: kotlin.Int + invisible_fake final /*fake_override*/ var size: kotlin.Int + public open /*fake_override*/ val size: kotlin.Int + public open /*fake_override*/ fun add(/*0*/ kotlin.Int, /*1*/ kotlin.String!): kotlin.Unit + public open /*fake_override*/ fun add(/*0*/ kotlin.String!): kotlin.Boolean + public open /*fake_override*/ fun addAll(/*0*/ kotlin.Int, /*1*/ kotlin.collections.Collection): kotlin.Boolean + public open /*fake_override*/ fun addAll(/*0*/ kotlin.collections.Collection): kotlin.Boolean + invisible_fake open /*fake_override*/ fun batchRemove(/*0*/ kotlin.collections.(Mutable)Collection<*>!, /*1*/ kotlin.Boolean): kotlin.Boolean + public open /*fake_override*/ fun clear(): kotlin.Unit + public open /*fake_override*/ fun clone(): kotlin.Any + public open /*fake_override*/ fun contains(/*0*/ kotlin.String!): kotlin.Boolean + public open /*fake_override*/ fun containsAll(/*0*/ kotlin.collections.Collection): kotlin.Boolean + invisible_fake open /*fake_override*/ fun elementData(/*0*/ kotlin.Int): kotlin.String! + public open /*fake_override*/ fun ensureCapacity(/*0*/ kotlin.Int): kotlin.Unit + invisible_fake open /*fake_override*/ fun ensureCapacityInternal(/*0*/ kotlin.Int): kotlin.Unit + invisible_fake open /*fake_override*/ fun ensureExplicitCapacity(/*0*/ kotlin.Int): kotlin.Unit + invisible_fake open /*fake_override*/ fun fastRemove(/*0*/ kotlin.Int): kotlin.Unit + public open /*fake_override*/ fun forEach(/*0*/ java.util.function.Consumer!): kotlin.Unit + public abstract fun func(): kotlin.Int + public open /*fake_override*/ fun get(/*0*/ kotlin.Int): kotlin.String! + invisible_fake open /*fake_override*/ fun grow(/*0*/ kotlin.Int): kotlin.Unit + public open /*fake_override*/ fun indexOf(/*0*/ kotlin.String!): kotlin.Int + public open /*fake_override*/ fun isEmpty(): kotlin.Boolean + public open /*fake_override*/ fun iterator(): kotlin.collections.MutableIterator + public open /*fake_override*/ fun lastIndexOf(/*0*/ kotlin.String!): kotlin.Int + public open /*fake_override*/ fun listIterator(): kotlin.collections.MutableListIterator + public open /*fake_override*/ fun listIterator(/*0*/ kotlin.Int): kotlin.collections.MutableListIterator + invisible_fake open /*fake_override*/ fun outOfBoundsMsg(/*0*/ kotlin.Int): kotlin.String! + public open /*fake_override*/ fun parallelStream(): java.util.stream.Stream + invisible_fake open /*fake_override*/ fun rangeCheck(/*0*/ kotlin.Int): kotlin.Unit + invisible_fake open /*fake_override*/ fun rangeCheckForAdd(/*0*/ kotlin.Int): kotlin.Unit + invisible_fake open /*fake_override*/ fun readObject(/*0*/ java.io.ObjectInputStream!): kotlin.Unit + public open /*fake_override*/ fun remove(/*0*/ kotlin.String!): kotlin.Boolean + public open /*fake_override*/ fun removeAll(/*0*/ kotlin.collections.Collection): kotlin.Boolean + public open /*fake_override*/ fun removeAt(/*0*/ kotlin.Int): kotlin.String! + public open /*fake_override*/ fun removeIf(/*0*/ java.util.function.Predicate): kotlin.Boolean + protected/*protected and package*/ open /*fake_override*/ fun removeRange(/*0*/ kotlin.Int, /*1*/ kotlin.Int): kotlin.Unit + public open /*fake_override*/ fun replaceAll(/*0*/ java.util.function.UnaryOperator): kotlin.Unit + public open /*fake_override*/ fun retainAll(/*0*/ kotlin.collections.Collection): kotlin.Boolean + public open /*fake_override*/ fun set(/*0*/ kotlin.Int, /*1*/ kotlin.String!): kotlin.String! + public open /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun sort(/*0*/ java.util.Comparator!): kotlin.Unit + public open /*fake_override*/ fun spliterator(): java.util.Spliterator + public open /*fake_override*/ fun stream(): java.util.stream.Stream + public open /*fake_override*/ fun subList(/*0*/ kotlin.Int, /*1*/ kotlin.Int): kotlin.collections.MutableList + public open /*fake_override*/ fun toArray(): kotlin.Array<(out) kotlin.Any!>! + public open /*fake_override*/ fun toArray(/*0*/ kotlin.Array<(out) T!>!): kotlin.Array<(out) T!>! + public open /*fake_override*/ fun trimToSize(): kotlin.Unit + invisible_fake open /*fake_override*/ fun writeObject(/*0*/ java.io.ObjectOutputStream!): kotlin.Unit + + // Static members + invisible_fake final /*fake_override*/ val DEFAULTCAPACITY_EMPTY_ELEMENTDATA: kotlin.Array<(out) kotlin.Any!>! + invisible_fake const final /*fake_override*/ val DEFAULT_CAPACITY: kotlin.Int + invisible_fake final /*fake_override*/ val EMPTY_ELEMENTDATA: kotlin.Array<(out) kotlin.Any!>! + invisible_fake const final /*fake_override*/ val MAX_ARRAY_SIZE: kotlin.Int + invisible_fake const final /*fake_override*/ val serialVersionUID: kotlin.Long + invisible_fake open /*fake_override*/ fun finishToArray(/*0*/ kotlin.Array<(out) T!>!, /*1*/ kotlin.collections.(Mutable)Iterator<*>!): kotlin.Array<(out) T!>! + invisible_fake open /*fake_override*/ fun hugeCapacity(/*0*/ kotlin.Int): kotlin.Int + invisible_fake open /*fake_override*/ fun subListRangeCheck(/*0*/ kotlin.Int, /*1*/ kotlin.Int, /*2*/ kotlin.Int): kotlin.Unit +} diff --git a/compiler/testData/compileKotlinAgainstJava/MapExample.java b/compiler/testData/compileKotlinAgainstJava/MapExample.java new file mode 100644 index 00000000000..b7cf9f7067a --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MapExample.java @@ -0,0 +1,7 @@ +package test; + +import java.util.HashMap; + +public class MapExample extends HashMap { + +} diff --git a/compiler/testData/compileKotlinAgainstJava/MapExample.kt b/compiler/testData/compileKotlinAgainstJava/MapExample.kt new file mode 100644 index 00000000000..8b543eb675d --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MapExample.kt @@ -0,0 +1,3 @@ +package test + +class MapImpl : MapExample(), MutableMap diff --git a/compiler/testData/compileKotlinAgainstJava/MapExample.txt b/compiler/testData/compileKotlinAgainstJava/MapExample.txt new file mode 100644 index 00000000000..19a419fece3 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MapExample.txt @@ -0,0 +1,125 @@ +package test + +public open class MapExample : java.util.HashMap { + public constructor MapExample() + public open /*fake_override*/ val entries: kotlin.collections.MutableSet> + invisible_fake final /*fake_override*/ var entrySet: kotlin.collections.(Mutable)Set!>! + invisible_fake final /*fake_override*/ var keySet: kotlin.collections.(Mutable)Set! + public open /*fake_override*/ val keys: kotlin.collections.MutableSet + invisible_fake final /*fake_override*/ val loadFactor: kotlin.Float + invisible_fake final /*fake_override*/ var modCount: kotlin.Int + invisible_fake final /*fake_override*/ var size: kotlin.Int + public open /*fake_override*/ val size: kotlin.Int + invisible_fake final /*fake_override*/ var table: kotlin.Array<(out) java.util.HashMap.Node!>! + invisible_fake final /*fake_override*/ var threshold: kotlin.Int + invisible_fake final /*fake_override*/ var values: kotlin.collections.(Mutable)Collection! + public open /*fake_override*/ val values: kotlin.collections.MutableCollection + invisible_fake open /*fake_override*/ fun afterNodeAccess(/*0*/ java.util.HashMap.Node!): kotlin.Unit + invisible_fake open /*fake_override*/ fun afterNodeInsertion(/*0*/ kotlin.Boolean): kotlin.Unit + invisible_fake open /*fake_override*/ fun afterNodeRemoval(/*0*/ java.util.HashMap.Node!): kotlin.Unit + invisible_fake final /*fake_override*/ fun capacity(): kotlin.Int + public open /*fake_override*/ fun clear(): kotlin.Unit + public open /*fake_override*/ fun clone(): kotlin.Any + public open /*fake_override*/ fun compute(/*0*/ K!, /*1*/ java.util.function.BiFunction): V? + public open /*fake_override*/ fun computeIfAbsent(/*0*/ K!, /*1*/ java.util.function.Function): V! + public open /*fake_override*/ fun computeIfPresent(/*0*/ K!, /*1*/ java.util.function.BiFunction): V? + public open /*fake_override*/ fun containsKey(/*0*/ K!): kotlin.Boolean + public open /*fake_override*/ fun containsValue(/*0*/ V!): kotlin.Boolean + public open /*fake_override*/ fun forEach(/*0*/ java.util.function.BiConsumer): kotlin.Unit + public open /*fake_override*/ fun get(/*0*/ K!): V? + invisible_fake final /*fake_override*/ fun getNode(/*0*/ kotlin.Int, /*1*/ kotlin.Any!): java.util.HashMap.Node! + public open /*fake_override*/ fun getOrDefault(/*0*/ K!, /*1*/ V!): V! + invisible_fake open /*fake_override*/ fun internalWriteEntries(/*0*/ java.io.ObjectOutputStream!): kotlin.Unit + public open /*fake_override*/ fun isEmpty(): kotlin.Boolean + invisible_fake final /*fake_override*/ fun loadFactor(): kotlin.Float + public open /*fake_override*/ fun merge(/*0*/ K!, /*1*/ V, /*2*/ java.util.function.BiFunction): V? + invisible_fake open /*fake_override*/ fun newNode(/*0*/ kotlin.Int, /*1*/ K!, /*2*/ V!, /*3*/ java.util.HashMap.Node!): java.util.HashMap.Node! + invisible_fake open /*fake_override*/ fun newTreeNode(/*0*/ kotlin.Int, /*1*/ K!, /*2*/ V!, /*3*/ java.util.HashMap.Node!): java.util.HashMap.TreeNode! + public open /*fake_override*/ fun put(/*0*/ K!, /*1*/ V!): V? + public open /*fake_override*/ fun putAll(/*0*/ kotlin.collections.Map): kotlin.Unit + public open /*fake_override*/ fun putIfAbsent(/*0*/ K!, /*1*/ V!): V? + invisible_fake final /*fake_override*/ fun putMapEntries(/*0*/ (kotlin.collections.MutableMap..kotlin.collections.Map?), /*1*/ kotlin.Boolean): kotlin.Unit + invisible_fake final /*fake_override*/ fun putVal(/*0*/ kotlin.Int, /*1*/ K!, /*2*/ V!, /*3*/ kotlin.Boolean, /*4*/ kotlin.Boolean): V! + invisible_fake open /*fake_override*/ fun readObject(/*0*/ java.io.ObjectInputStream!): kotlin.Unit + invisible_fake open /*fake_override*/ fun reinitialize(): kotlin.Unit + public open /*fake_override*/ fun remove(/*0*/ K!): V? + public open /*fake_override*/ fun remove(/*0*/ K!, /*1*/ V!): kotlin.Boolean + invisible_fake final /*fake_override*/ fun removeNode(/*0*/ kotlin.Int, /*1*/ kotlin.Any!, /*2*/ kotlin.Any!, /*3*/ kotlin.Boolean, /*4*/ kotlin.Boolean): java.util.HashMap.Node! + public open /*fake_override*/ fun replace(/*0*/ K!, /*1*/ V!): V? + public open /*fake_override*/ fun replace(/*0*/ K!, /*1*/ V!, /*2*/ V!): kotlin.Boolean + public open /*fake_override*/ fun replaceAll(/*0*/ java.util.function.BiFunction): kotlin.Unit + invisible_fake open /*fake_override*/ fun replacementNode(/*0*/ java.util.HashMap.Node!, /*1*/ java.util.HashMap.Node!): java.util.HashMap.Node! + invisible_fake open /*fake_override*/ fun replacementTreeNode(/*0*/ java.util.HashMap.Node!, /*1*/ java.util.HashMap.Node!): java.util.HashMap.TreeNode! + invisible_fake final /*fake_override*/ fun resize(): kotlin.Array<(out) java.util.HashMap.Node!>! + invisible_fake final /*fake_override*/ fun treeifyBin(/*0*/ kotlin.Array<(out) java.util.HashMap.Node!>!, /*1*/ kotlin.Int): kotlin.Unit + invisible_fake open /*fake_override*/ fun writeObject(/*0*/ java.io.ObjectOutputStream!): kotlin.Unit + + // Static members + invisible_fake const final /*fake_override*/ val DEFAULT_INITIAL_CAPACITY: kotlin.Int + invisible_fake const final /*fake_override*/ val DEFAULT_LOAD_FACTOR: kotlin.Float + invisible_fake const final /*fake_override*/ val MAXIMUM_CAPACITY: kotlin.Int + invisible_fake const final /*fake_override*/ val MIN_TREEIFY_CAPACITY: kotlin.Int + invisible_fake const final /*fake_override*/ val TREEIFY_THRESHOLD: kotlin.Int + invisible_fake const final /*fake_override*/ val UNTREEIFY_THRESHOLD: kotlin.Int + invisible_fake const final /*fake_override*/ val serialVersionUID: kotlin.Long + invisible_fake open /*fake_override*/ fun comparableClassFor(/*0*/ kotlin.Any!): java.lang.Class<*>! + invisible_fake open /*fake_override*/ fun compareComparables(/*0*/ java.lang.Class<*>!, /*1*/ kotlin.Any!, /*2*/ kotlin.Any!): kotlin.Int + invisible_fake open /*fake_override*/ fun eq(/*0*/ kotlin.Any!, /*1*/ kotlin.Any!): kotlin.Boolean + invisible_fake final /*fake_override*/ fun hash(/*0*/ kotlin.Any!): kotlin.Int + invisible_fake final /*fake_override*/ fun tableSizeFor(/*0*/ kotlin.Int): kotlin.Int +} + +public final class MapImpl : test.MapExample, kotlin.collections.MutableMap { + public constructor MapImpl() + public open /*fake_override*/ val entries: kotlin.collections.MutableSet> + invisible_fake final /*fake_override*/ var entrySet: kotlin.collections.(Mutable)Set!>! + invisible_fake final /*fake_override*/ var keySet: kotlin.collections.(Mutable)Set! + public open /*fake_override*/ val keys: kotlin.collections.MutableSet + invisible_fake final /*fake_override*/ val loadFactor: kotlin.Float + invisible_fake final /*fake_override*/ var modCount: kotlin.Int + invisible_fake final /*fake_override*/ var size: kotlin.Int + public open /*fake_override*/ val size: kotlin.Int + invisible_fake final /*fake_override*/ var table: kotlin.Array<(out) java.util.HashMap.Node!>! + invisible_fake final /*fake_override*/ var threshold: kotlin.Int + invisible_fake final /*fake_override*/ var values: kotlin.collections.(Mutable)Collection! + public open /*fake_override*/ val values: kotlin.collections.MutableCollection + invisible_fake open /*fake_override*/ fun afterNodeAccess(/*0*/ java.util.HashMap.Node!): kotlin.Unit + invisible_fake open /*fake_override*/ fun afterNodeInsertion(/*0*/ kotlin.Boolean): kotlin.Unit + invisible_fake open /*fake_override*/ fun afterNodeRemoval(/*0*/ java.util.HashMap.Node!): kotlin.Unit + invisible_fake final /*fake_override*/ fun capacity(): kotlin.Int + public open /*fake_override*/ fun clear(): kotlin.Unit + public open /*fake_override*/ fun clone(): kotlin.Any + public open /*fake_override*/ fun compute(/*0*/ kotlin.String!, /*1*/ java.util.function.BiFunction): V? + public open /*fake_override*/ fun computeIfAbsent(/*0*/ kotlin.String, /*1*/ java.util.function.Function): V + public open /*fake_override*/ fun computeIfPresent(/*0*/ kotlin.String!, /*1*/ java.util.function.BiFunction): V? + public open /*fake_override*/ fun containsKey(/*0*/ kotlin.String!): kotlin.Boolean + public open /*fake_override*/ fun containsValue(/*0*/ V!): kotlin.Boolean + public open /*fake_override*/ fun forEach(/*0*/ java.util.function.BiConsumer): kotlin.Unit + public open /*fake_override*/ fun get(/*0*/ kotlin.String!): V? + invisible_fake final /*fake_override*/ fun getNode(/*0*/ kotlin.Int, /*1*/ kotlin.Any!): java.util.HashMap.Node! + @kotlin.SinceKotlin(version = "1.1") @kotlin.internal.PlatformDependent public open /*fake_override*/ fun getOrDefault(/*0*/ kotlin.String, /*1*/ V): V + invisible_fake open /*fake_override*/ fun internalWriteEntries(/*0*/ java.io.ObjectOutputStream!): kotlin.Unit + public open /*fake_override*/ fun isEmpty(): kotlin.Boolean + invisible_fake final /*fake_override*/ fun loadFactor(): kotlin.Float + public open /*fake_override*/ fun merge(/*0*/ kotlin.String!, /*1*/ V, /*2*/ java.util.function.BiFunction): V? + invisible_fake open /*fake_override*/ fun newNode(/*0*/ kotlin.Int, /*1*/ kotlin.String!, /*2*/ V!, /*3*/ java.util.HashMap.Node!): java.util.HashMap.Node! + invisible_fake open /*fake_override*/ fun newTreeNode(/*0*/ kotlin.Int, /*1*/ kotlin.String!, /*2*/ V!, /*3*/ java.util.HashMap.Node!): java.util.HashMap.TreeNode! + public open /*fake_override*/ fun put(/*0*/ kotlin.String!, /*1*/ V!): V? + public open /*fake_override*/ fun putAll(/*0*/ kotlin.collections.Map): kotlin.Unit + public open /*fake_override*/ fun putIfAbsent(/*0*/ kotlin.String!, /*1*/ V!): V? + invisible_fake final /*fake_override*/ fun putMapEntries(/*0*/ (kotlin.collections.MutableMap..kotlin.collections.Map?), /*1*/ kotlin.Boolean): kotlin.Unit + invisible_fake final /*fake_override*/ fun putVal(/*0*/ kotlin.Int, /*1*/ kotlin.String!, /*2*/ V!, /*3*/ kotlin.Boolean, /*4*/ kotlin.Boolean): V! + invisible_fake open /*fake_override*/ fun readObject(/*0*/ java.io.ObjectInputStream!): kotlin.Unit + invisible_fake open /*fake_override*/ fun reinitialize(): kotlin.Unit + public open /*fake_override*/ fun remove(/*0*/ kotlin.String!): V? + public open /*fake_override*/ fun remove(/*0*/ kotlin.String!, /*1*/ V!): kotlin.Boolean + invisible_fake final /*fake_override*/ fun removeNode(/*0*/ kotlin.Int, /*1*/ kotlin.Any!, /*2*/ kotlin.Any!, /*3*/ kotlin.Boolean, /*4*/ kotlin.Boolean): java.util.HashMap.Node! + public open /*fake_override*/ fun replace(/*0*/ kotlin.String!, /*1*/ V!): V? + public open /*fake_override*/ fun replace(/*0*/ kotlin.String!, /*1*/ V!, /*2*/ V!): kotlin.Boolean + public open /*fake_override*/ fun replaceAll(/*0*/ java.util.function.BiFunction): kotlin.Unit + invisible_fake open /*fake_override*/ fun replacementNode(/*0*/ java.util.HashMap.Node!, /*1*/ java.util.HashMap.Node!): java.util.HashMap.Node! + invisible_fake open /*fake_override*/ fun replacementTreeNode(/*0*/ java.util.HashMap.Node!, /*1*/ java.util.HashMap.Node!): java.util.HashMap.TreeNode! + invisible_fake final /*fake_override*/ fun resize(): kotlin.Array<(out) java.util.HashMap.Node!>! + invisible_fake final /*fake_override*/ fun treeifyBin(/*0*/ kotlin.Array<(out) java.util.HashMap.Node!>!, /*1*/ kotlin.Int): kotlin.Unit + invisible_fake open /*fake_override*/ fun writeObject(/*0*/ java.io.ObjectOutputStream!): kotlin.Unit +} diff --git a/compiler/testData/compileKotlinAgainstJava/Method.java b/compiler/testData/compileKotlinAgainstJava/Method.java new file mode 100644 index 00000000000..05d41118e6a --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Method.java @@ -0,0 +1,5 @@ +package test; + +class Method { + public static String method() { return "method()"; } +} diff --git a/compiler/testData/compileKotlinAgainstJava/Method.kt b/compiler/testData/compileKotlinAgainstJava/Method.kt new file mode 100644 index 00000000000..62b416cb770 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Method.kt @@ -0,0 +1,3 @@ +package test + +fun method() = Method.method() diff --git a/compiler/testData/compileKotlinAgainstJava/Method.txt b/compiler/testData/compileKotlinAgainstJava/Method.txt new file mode 100644 index 00000000000..e8bede99892 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Method.txt @@ -0,0 +1,10 @@ +package test + +public fun method(): kotlin.String! + +public/*package*/ open class Method { + public/*package*/ constructor Method() + + // Static members + public open fun method(): kotlin.String! +} diff --git a/compiler/testData/compileKotlinAgainstJava/MethodWithArgument.java b/compiler/testData/compileKotlinAgainstJava/MethodWithArgument.java new file mode 100644 index 00000000000..3727815007e --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MethodWithArgument.java @@ -0,0 +1,7 @@ +package test; + +public class MethodWithArgument { + + public static void method(KotlinClass kotlinClass) {} + +} diff --git a/compiler/testData/compileKotlinAgainstJava/MethodWithArgument.kt b/compiler/testData/compileKotlinAgainstJava/MethodWithArgument.kt new file mode 100644 index 00000000000..86a97ae2548 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MethodWithArgument.kt @@ -0,0 +1,5 @@ +package test + +class KotlinClass + +fun method() = MethodWithArgument.method(KotlinClass()) diff --git a/compiler/testData/compileKotlinAgainstJava/MethodWithArgument.txt b/compiler/testData/compileKotlinAgainstJava/MethodWithArgument.txt new file mode 100644 index 00000000000..930eb5dd1e5 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MethodWithArgument.txt @@ -0,0 +1,14 @@ +package test + +public fun method(): kotlin.Unit + +public final class KotlinClass { + public constructor KotlinClass() +} + +public open class MethodWithArgument { + public constructor MethodWithArgument() + + // Static members + public open fun method(/*0*/ test.KotlinClass!): kotlin.Unit +} diff --git a/compiler/testData/compileKotlinAgainstJava/MethodWithSeveralTypeParameters.java b/compiler/testData/compileKotlinAgainstJava/MethodWithSeveralTypeParameters.java new file mode 100644 index 00000000000..b1dc8b0a4f2 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MethodWithSeveralTypeParameters.java @@ -0,0 +1,7 @@ +package test; + +class MethodWithSeveralTypeParameters { + + public static N method(T str, N number) { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/MethodWithSeveralTypeParameters.kt b/compiler/testData/compileKotlinAgainstJava/MethodWithSeveralTypeParameters.kt new file mode 100644 index 00000000000..541e8e43c2e --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MethodWithSeveralTypeParameters.kt @@ -0,0 +1,3 @@ +package test + +fun func() = MethodWithSeveralTypeParameters.method("str", 15) diff --git a/compiler/testData/compileKotlinAgainstJava/MethodWithSeveralTypeParameters.txt b/compiler/testData/compileKotlinAgainstJava/MethodWithSeveralTypeParameters.txt new file mode 100644 index 00000000000..ec31e94a449 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MethodWithSeveralTypeParameters.txt @@ -0,0 +1,10 @@ +package test + +public fun func(): kotlin.Int! + +public/*package*/ open class MethodWithSeveralTypeParameters { + public/*package*/ constructor MethodWithSeveralTypeParameters() + + // Static members + public open fun method(/*0*/ T!, /*1*/ N!): N! +} diff --git a/compiler/testData/compileKotlinAgainstJava/MethodWithTypeParameter.java b/compiler/testData/compileKotlinAgainstJava/MethodWithTypeParameter.java new file mode 100644 index 00000000000..1c532d26466 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MethodWithTypeParameter.java @@ -0,0 +1,7 @@ +package test; + +public class MethodWithTypeParameter { + + public static void method(T t) {} + +} diff --git a/compiler/testData/compileKotlinAgainstJava/MethodWithTypeParameter.kt b/compiler/testData/compileKotlinAgainstJava/MethodWithTypeParameter.kt new file mode 100644 index 00000000000..76b85855074 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MethodWithTypeParameter.kt @@ -0,0 +1,7 @@ +package test + +interface KotlinInterface + +object Impl : KotlinInterface + +fun useMethod() = MethodWithTypeParameter.method(Impl) diff --git a/compiler/testData/compileKotlinAgainstJava/MethodWithTypeParameter.txt b/compiler/testData/compileKotlinAgainstJava/MethodWithTypeParameter.txt new file mode 100644 index 00000000000..368fa739d72 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MethodWithTypeParameter.txt @@ -0,0 +1,17 @@ +package test + +public fun useMethod(): kotlin.Unit + +public object Impl : test.KotlinInterface { + private constructor Impl() +} + +public interface KotlinInterface { +} + +public open class MethodWithTypeParameter { + public constructor MethodWithTypeParameter() + + // Static members + public open fun method(/*0*/ T!): kotlin.Unit +} diff --git a/compiler/testData/compileKotlinAgainstJava/MethodWithWildcard.java b/compiler/testData/compileKotlinAgainstJava/MethodWithWildcard.java new file mode 100644 index 00000000000..3f7c8d61e6c --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MethodWithWildcard.java @@ -0,0 +1,9 @@ +package test; + +import java.util.Collection; + +public class MethodWithWildcard { + + public Collection method(Collection c) { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/MethodWithWildcard.kt b/compiler/testData/compileKotlinAgainstJava/MethodWithWildcard.kt new file mode 100644 index 00000000000..009e0a401c3 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MethodWithWildcard.kt @@ -0,0 +1,4 @@ +package test + +fun useMethodWithWildcard() = + MethodWithWildcard().method(emptyList()) diff --git a/compiler/testData/compileKotlinAgainstJava/MethodWithWildcard.txt b/compiler/testData/compileKotlinAgainstJava/MethodWithWildcard.txt new file mode 100644 index 00000000000..c46fc7dbc8a --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/MethodWithWildcard.txt @@ -0,0 +1,8 @@ +package test + +public fun useMethodWithWildcard(): kotlin.collections.(Mutable)Collection! + +public open class MethodWithWildcard { + public constructor MethodWithWildcard() + public open fun method(/*0*/ (kotlin.collections.MutableCollection..kotlin.collections.Collection?)): kotlin.collections.(Mutable)Collection! +} diff --git a/compiler/testData/compileKotlinAgainstJava/Nesting.java b/compiler/testData/compileKotlinAgainstJava/Nesting.java new file mode 100644 index 00000000000..4a89e55726d --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Nesting.java @@ -0,0 +1,26 @@ +package test; + +public class Nesting { + + public test.Nesting.Second.Third.FourthImpl getImpl() { return null; } + + public static final class Second { + + public static final class Third { + + public interface Fourth { + public boolean isImplemented(); + } + + public static final class FourthImpl implements Fourth { + + @Override + public boolean isImplemented() { return true; } + + } + + } + + } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/Nesting.kt b/compiler/testData/compileKotlinAgainstJava/Nesting.kt new file mode 100644 index 00000000000..76acdbf1f07 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Nesting.kt @@ -0,0 +1,3 @@ +package test + +fun getImpl(): Nesting.Second.Third.Fourth = Nesting().getImpl() diff --git a/compiler/testData/compileKotlinAgainstJava/Nesting.txt b/compiler/testData/compileKotlinAgainstJava/Nesting.txt new file mode 100644 index 00000000000..7db39bcb46c --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Nesting.txt @@ -0,0 +1,25 @@ +package test + +public fun getImpl(): test.Nesting.Second.Third.Fourth + +public open class Nesting { + public constructor Nesting() + public open fun getImpl(): test.Nesting.Second.Third.FourthImpl! + + public final class Second { + public constructor Second() + + public final class Third { + public constructor Third() + + public interface Fourth { + public abstract fun isImplemented(): kotlin.Boolean + } + + public final class FourthImpl : test.Nesting.Second.Third.Fourth { + public constructor FourthImpl() + public open fun isImplemented(): kotlin.Boolean + } + } + } +} diff --git a/compiler/testData/compileKotlinAgainstJava/RawReturnType.java b/compiler/testData/compileKotlinAgainstJava/RawReturnType.java new file mode 100644 index 00000000000..1bc2a9bea85 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/RawReturnType.java @@ -0,0 +1,9 @@ +package test; + +import java.util.List; + +public class RawReturnType { + + public static List getRawList(List list) { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/RawReturnType.kt b/compiler/testData/compileKotlinAgainstJava/RawReturnType.kt new file mode 100644 index 00000000000..3d281e0371a --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/RawReturnType.kt @@ -0,0 +1,3 @@ +package test + +fun useRawReturnType() = RawReturnType.getRawList(listOf("str")) diff --git a/compiler/testData/compileKotlinAgainstJava/RawReturnType.txt b/compiler/testData/compileKotlinAgainstJava/RawReturnType.txt new file mode 100644 index 00000000000..b0864e9c310 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/RawReturnType.txt @@ -0,0 +1,10 @@ +package test + +public fun useRawReturnType(): kotlin.collections.(Mutable)List<(raw) kotlin.Any?>! + +public open class RawReturnType { + public constructor RawReturnType() + + // Static members + public open fun getRawList(/*0*/ kotlin.collections.(Mutable)List!): kotlin.collections.(Mutable)List<(raw) kotlin.Any?>! +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnEnum.java b/compiler/testData/compileKotlinAgainstJava/ReturnEnum.java new file mode 100644 index 00000000000..bb18691c3fc --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnEnum.java @@ -0,0 +1,11 @@ +package test; + +class ReturnEnum { + + Kind getKind() { return Kind.FIRST; } + +} + +enum Kind { + FIRST, SECOND, THIRD; +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnEnum.kt b/compiler/testData/compileKotlinAgainstJava/ReturnEnum.kt new file mode 100644 index 00000000000..2cc5751ea52 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnEnum.kt @@ -0,0 +1,7 @@ +package test + +private fun getKind() = when(ReturnEnum().getKind()) { + Kind.FIRST -> println(1) + Kind.SECOND -> println(2) + Kind.THIRD -> println(42) +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnEnum.txt b/compiler/testData/compileKotlinAgainstJava/ReturnEnum.txt new file mode 100644 index 00000000000..3f682dd3b4d --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnEnum.txt @@ -0,0 +1,30 @@ +package test + +private fun getKind(): kotlin.Unit + +public/*package*/ final enum class Kind : kotlin.Enum { + enum entry FIRST + + enum entry SECOND + + enum entry THIRD + + private constructor Kind() + public final /*fake_override*/ val name: kotlin.String + public final /*fake_override*/ val ordinal: kotlin.Int + protected final /*fake_override*/ fun clone(): kotlin.Any + public final /*fake_override*/ fun compareTo(/*0*/ test.Kind!): kotlin.Int + protected/*protected and package*/ final /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ kotlin.String): test.Kind + public open fun valueOf(/*0*/ kotlin.String!): test.Kind! + public open fun values(): kotlin.Array<(out) test.Kind!>! + public final /*synthesized*/ fun values(): kotlin.Array +} + +public/*package*/ open class ReturnEnum { + public/*package*/ constructor ReturnEnum() + public/*package*/ open fun getKind(): test.Kind! +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnInnerClass.java b/compiler/testData/compileKotlinAgainstJava/ReturnInnerClass.java new file mode 100644 index 00000000000..eab22212f4c --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnInnerClass.java @@ -0,0 +1,17 @@ +package test; + +class ReturnInnerClass extends ReturnInnerClassImpl { + +} + +class ReturnInnerClassImpl extends AbstractReturnInnerClass { + +} + +abstract class AbstractReturnInnerClass { + + class InnerClass {} + + InnerClass getInnerClass() { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnInnerClass.kt b/compiler/testData/compileKotlinAgainstJava/ReturnInnerClass.kt new file mode 100644 index 00000000000..afa753d0f52 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnInnerClass.kt @@ -0,0 +1,3 @@ +package test + +internal fun getInnerClass() = ReturnInnerClass().getInnerClass() diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnInnerClass.txt b/compiler/testData/compileKotlinAgainstJava/ReturnInnerClass.txt new file mode 100644 index 00000000000..f4bb5336f62 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnInnerClass.txt @@ -0,0 +1,22 @@ +package test + +internal fun getInnerClass(): test.AbstractReturnInnerClass.InnerClass! + +public/*package*/ abstract class AbstractReturnInnerClass { + public/*package*/ constructor AbstractReturnInnerClass() + public/*package*/ open fun getInnerClass(): test.AbstractReturnInnerClass.InnerClass! + + public/*package*/ open inner class InnerClass { + public/*package*/ constructor InnerClass() + } +} + +public/*package*/ open class ReturnInnerClass : test.ReturnInnerClassImpl { + public/*package*/ constructor ReturnInnerClass() + public/*package*/ open /*fake_override*/ fun getInnerClass(): test.AbstractReturnInnerClass.InnerClass! +} + +public/*package*/ open class ReturnInnerClassImpl : test.AbstractReturnInnerClass { + public/*package*/ constructor ReturnInnerClassImpl() + public/*package*/ open /*fake_override*/ fun getInnerClass(): test.AbstractReturnInnerClass.InnerClass! +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnInnerInInner.java b/compiler/testData/compileKotlinAgainstJava/ReturnInnerInInner.java new file mode 100644 index 00000000000..a34bbceb527 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnInnerInInner.java @@ -0,0 +1,13 @@ +package test; + +class ReturnInnerInInner { + + static class Inner { + Inner getInner() { return null; } + + ReturnInnerInInner.Inner getInner2() { return null; } + + test.ReturnInnerInInner.Inner getInner3() { return null; } + } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnInnerInInner.kt b/compiler/testData/compileKotlinAgainstJava/ReturnInnerInInner.kt new file mode 100644 index 00000000000..8b342119ea6 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnInnerInInner.kt @@ -0,0 +1,7 @@ +package test + +private fun getInner() = ReturnInnerInInner.Inner().getInner() + +private fun getInner2() = ReturnInnerInInner.Inner().getInner2() + +private fun getInner3() = ReturnInnerInInner.Inner().getInner3() diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnInnerInInner.txt b/compiler/testData/compileKotlinAgainstJava/ReturnInnerInInner.txt new file mode 100644 index 00000000000..abd6b664dc7 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnInnerInInner.txt @@ -0,0 +1,16 @@ +package test + +private fun getInner(): test.ReturnInnerInInner.Inner! +private fun getInner2(): test.ReturnInnerInInner.Inner! +private fun getInner3(): test.ReturnInnerInInner.Inner! + +public/*package*/ open class ReturnInnerInInner { + public/*package*/ constructor ReturnInnerInInner() + + public/*package*/ open class Inner { + public/*package*/ constructor Inner() + public/*package*/ open fun getInner(): test.ReturnInnerInInner.Inner! + public/*package*/ open fun getInner2(): test.ReturnInnerInInner.Inner! + public/*package*/ open fun getInner3(): test.ReturnInnerInInner.Inner! + } +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnInnerInner.java b/compiler/testData/compileKotlinAgainstJava/ReturnInnerInner.java new file mode 100644 index 00000000000..619cc47e193 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnInnerInner.java @@ -0,0 +1,15 @@ +package test; + +public class ReturnInnerInner { + + public class InnerFirst { + + public class InnerSecond { + + } + + } + + public static InnerFirst.InnerSecond getInnerInner() { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnInnerInner.kt b/compiler/testData/compileKotlinAgainstJava/ReturnInnerInner.kt new file mode 100644 index 00000000000..fd203432a2f --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnInnerInner.kt @@ -0,0 +1,3 @@ +package test + +fun getInnerInner() = ReturnInnerInner.getInnerInner() diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnInnerInner.txt b/compiler/testData/compileKotlinAgainstJava/ReturnInnerInner.txt new file mode 100644 index 00000000000..c57650e173a --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnInnerInner.txt @@ -0,0 +1,18 @@ +package test + +public fun getInnerInner(): test.ReturnInnerInner.InnerFirst.InnerSecond! + +public open class ReturnInnerInner { + public constructor ReturnInnerInner() + + public open inner class InnerFirst { + public constructor InnerFirst() + + public open inner class InnerSecond { + public constructor InnerSecond() + } + } + + // Static members + public open fun getInnerInner(): test.ReturnInnerInner.InnerFirst.InnerSecond! +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnNested.java b/compiler/testData/compileKotlinAgainstJava/ReturnNested.java new file mode 100644 index 00000000000..132ad9bcd84 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnNested.java @@ -0,0 +1,11 @@ +package test; + +public class ReturnNested { + + public static class Nested { + + } + + public Nested getNested() { return new Nested(); } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnNested.kt b/compiler/testData/compileKotlinAgainstJava/ReturnNested.kt new file mode 100644 index 00000000000..145017ac309 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnNested.kt @@ -0,0 +1,3 @@ +package test + +fun getNested() = ReturnNested().getNested() diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnNested.txt b/compiler/testData/compileKotlinAgainstJava/ReturnNested.txt new file mode 100644 index 00000000000..ff0d15bd60f --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnNested.txt @@ -0,0 +1,12 @@ +package test + +public fun getNested(): test.ReturnNested.Nested! + +public open class ReturnNested { + public constructor ReturnNested() + public open fun getNested(): test.ReturnNested.Nested! + + public open class Nested { + public constructor Nested() + } +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnNestedFQ.java b/compiler/testData/compileKotlinAgainstJava/ReturnNestedFQ.java new file mode 100644 index 00000000000..55e18284244 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnNestedFQ.java @@ -0,0 +1,11 @@ +package test; + +public class ReturnNestedFQ { + + public class Nested { + + } + + public static ReturnNestedFQ.Nested getNested() { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnNestedFQ.kt b/compiler/testData/compileKotlinAgainstJava/ReturnNestedFQ.kt new file mode 100644 index 00000000000..8b6724ba84f --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnNestedFQ.kt @@ -0,0 +1,3 @@ +package test + +fun getNested() = ReturnNestedFQ.getNested() diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnNestedFQ.txt b/compiler/testData/compileKotlinAgainstJava/ReturnNestedFQ.txt new file mode 100644 index 00000000000..43ac4535ebe --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnNestedFQ.txt @@ -0,0 +1,14 @@ +package test + +public fun getNested(): test.ReturnNestedFQ.Nested! + +public open class ReturnNestedFQ { + public constructor ReturnNestedFQ() + + public open inner class Nested { + public constructor Nested() + } + + // Static members + public open fun getNested(): test.ReturnNestedFQ.Nested! +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnType.java b/compiler/testData/compileKotlinAgainstJava/ReturnType.java new file mode 100644 index 00000000000..bb6c6f31682 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnType.java @@ -0,0 +1,7 @@ +package test; + +public class ReturnType { + + public static javax.lang.model.element.Element getElement() { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnType.kt b/compiler/testData/compileKotlinAgainstJava/ReturnType.kt new file mode 100644 index 00000000000..60dba86708d --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnType.kt @@ -0,0 +1,3 @@ +package test + +fun getElement() = ReturnType.getElement() diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnType.txt b/compiler/testData/compileKotlinAgainstJava/ReturnType.txt new file mode 100644 index 00000000000..a529c5f2d44 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnType.txt @@ -0,0 +1,10 @@ +package test + +public fun getElement(): javax.lang.model.element.Element! + +public open class ReturnType { + public constructor ReturnType() + + // Static members + public open fun getElement(): javax.lang.model.element.Element! +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnTypeResolution.java b/compiler/testData/compileKotlinAgainstJava/ReturnTypeResolution.java new file mode 100644 index 00000000000..321c477c991 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnTypeResolution.java @@ -0,0 +1,13 @@ +package test; + +public class ReturnTypeResolution { + + public class SomeClass {} + + public SomeClass getSomeClass() { return new SomeClass(); } + +} + +class SomeClass { + +} diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnTypeResolution.kt b/compiler/testData/compileKotlinAgainstJava/ReturnTypeResolution.kt new file mode 100644 index 00000000000..9570f2cfd6e --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnTypeResolution.kt @@ -0,0 +1,3 @@ +package test + +fun checkReturnType() = ReturnTypeResolution().getSomeClass() diff --git a/compiler/testData/compileKotlinAgainstJava/ReturnTypeResolution.txt b/compiler/testData/compileKotlinAgainstJava/ReturnTypeResolution.txt new file mode 100644 index 00000000000..f28da4bc896 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/ReturnTypeResolution.txt @@ -0,0 +1,16 @@ +package test + +public fun checkReturnType(): test.ReturnTypeResolution.SomeClass! + +public open class ReturnTypeResolution { + public constructor ReturnTypeResolution() + public open fun getSomeClass(): test.ReturnTypeResolution.SomeClass! + + public open inner class SomeClass { + public constructor SomeClass() + } +} + +public/*package*/ open class SomeClass { + public/*package*/ constructor SomeClass() +} diff --git a/compiler/testData/compileKotlinAgainstJava/SeveralInnerClasses.java b/compiler/testData/compileKotlinAgainstJava/SeveralInnerClasses.java new file mode 100644 index 00000000000..a0e2f2dd497 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/SeveralInnerClasses.java @@ -0,0 +1,19 @@ +package test; + +public class SeveralInnerClasses { + + public static class NestedFirst { + public static class NestedSecond { + } + } + + public class InnerFirst { + public class InnerSecond { + } + } + + public static NestedFirst.NestedSecond getNested() { return null; } + + public static InnerFirst.InnerSecond getInner() { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/SeveralInnerClasses.kt b/compiler/testData/compileKotlinAgainstJava/SeveralInnerClasses.kt new file mode 100644 index 00000000000..a971c804937 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/SeveralInnerClasses.kt @@ -0,0 +1,5 @@ +package test + +fun getNested() = SeveralInnerClasses.getNested() + +fun getInner() = SeveralInnerClasses.getInner() diff --git a/compiler/testData/compileKotlinAgainstJava/SeveralInnerClasses.txt b/compiler/testData/compileKotlinAgainstJava/SeveralInnerClasses.txt new file mode 100644 index 00000000000..16fda8f5e54 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/SeveralInnerClasses.txt @@ -0,0 +1,28 @@ +package test + +public fun getInner(): test.SeveralInnerClasses.InnerFirst.InnerSecond! +public fun getNested(): test.SeveralInnerClasses.NestedFirst.NestedSecond! + +public open class SeveralInnerClasses { + public constructor SeveralInnerClasses() + + public open inner class InnerFirst { + public constructor InnerFirst() + + public open inner class InnerSecond { + public constructor InnerSecond() + } + } + + public open class NestedFirst { + public constructor NestedFirst() + + public open class NestedSecond { + public constructor NestedSecond() + } + } + + // Static members + public open fun getInner(): test.SeveralInnerClasses.InnerFirst.InnerSecond! + public open fun getNested(): test.SeveralInnerClasses.NestedFirst.NestedSecond! +} diff --git a/compiler/testData/compileKotlinAgainstJava/SimpleAnnotation.java b/compiler/testData/compileKotlinAgainstJava/SimpleAnnotation.java new file mode 100644 index 00000000000..e8af12c7a0d --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/SimpleAnnotation.java @@ -0,0 +1,8 @@ +package test; + +import java.lang.annotation.*; + +@Target(value=ElementType.METHOD) +public @interface SimpleAnnotation { + +} diff --git a/compiler/testData/compileKotlinAgainstJava/SimpleAnnotation.kt b/compiler/testData/compileKotlinAgainstJava/SimpleAnnotation.kt new file mode 100644 index 00000000000..d895cd57b3e --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/SimpleAnnotation.kt @@ -0,0 +1,4 @@ +package test + +@SimpleAnnotation +private fun withSimpleAnnotation() {} diff --git a/compiler/testData/compileKotlinAgainstJava/SimpleAnnotation.txt b/compiler/testData/compileKotlinAgainstJava/SimpleAnnotation.txt new file mode 100644 index 00000000000..16fc3eae18d --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/SimpleAnnotation.txt @@ -0,0 +1,7 @@ +package test + +@test.SimpleAnnotation private fun withSimpleAnnotation(): kotlin.Unit + +@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER}) public final annotation class SimpleAnnotation : kotlin.Annotation { + public constructor SimpleAnnotation() +} diff --git a/compiler/testData/compileKotlinAgainstJava/SimpleWildcard.java b/compiler/testData/compileKotlinAgainstJava/SimpleWildcard.java new file mode 100644 index 00000000000..334b9dba734 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/SimpleWildcard.java @@ -0,0 +1,9 @@ +package test; + +import java.util.Collection; + +class SimpleWildcard { + + public static void simple(Collection c) {} + +} diff --git a/compiler/testData/compileKotlinAgainstJava/SimpleWildcard.kt b/compiler/testData/compileKotlinAgainstJava/SimpleWildcard.kt new file mode 100644 index 00000000000..c920ccadf93 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/SimpleWildcard.kt @@ -0,0 +1,6 @@ +package test + +fun testWildcard() { + SimpleWildcard.simple(listOf("str")) + SimpleWildcard.simple(listOf(1)) +} diff --git a/compiler/testData/compileKotlinAgainstJava/SimpleWildcard.txt b/compiler/testData/compileKotlinAgainstJava/SimpleWildcard.txt new file mode 100644 index 00000000000..c8f0a6fb86e --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/SimpleWildcard.txt @@ -0,0 +1,10 @@ +package test + +public fun testWildcard(): kotlin.Unit + +public/*package*/ open class SimpleWildcard { + public/*package*/ constructor SimpleWildcard() + + // Static members + public open fun simple(/*0*/ kotlin.collections.(Mutable)Collection<*>!): kotlin.Unit +} diff --git a/compiler/testData/compileKotlinAgainstJava/Singleton.java b/compiler/testData/compileKotlinAgainstJava/Singleton.java new file mode 100644 index 00000000000..6f1970c864a --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Singleton.java @@ -0,0 +1,21 @@ +package test; + +public final class Singleton { + + private Singleton() {} + + private static Singleton INSTANCE; + + public static String getString() { + return getInstance().toString(); + } + + public static Singleton getInstance() { + if (INSTANCE == null) { + INSTANCE = new Singleton(); + } + + return INSTANCE; + } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/Singleton.kt b/compiler/testData/compileKotlinAgainstJava/Singleton.kt new file mode 100644 index 00000000000..7754d511d64 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Singleton.kt @@ -0,0 +1,5 @@ +package test + +fun getString() = Singleton.getString() + +fun getSingleton() = Singleton.getInstance() diff --git a/compiler/testData/compileKotlinAgainstJava/Singleton.txt b/compiler/testData/compileKotlinAgainstJava/Singleton.txt new file mode 100644 index 00000000000..ccf7f796a11 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Singleton.txt @@ -0,0 +1,13 @@ +package test + +public fun getSingleton(): test.Singleton! +public fun getString(): kotlin.String! + +public final class Singleton { + private constructor Singleton() + + // Static members + private final var INSTANCE: test.Singleton! + public open fun getInstance(): test.Singleton! + public open fun getString(): kotlin.String! +} diff --git a/compiler/testData/compileKotlinAgainstJava/StaticNestedClass.java b/compiler/testData/compileKotlinAgainstJava/StaticNestedClass.java new file mode 100644 index 00000000000..604a6f69301 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/StaticNestedClass.java @@ -0,0 +1,9 @@ +package test; + +public class StaticNestedClass { + + static class StaticNested { + public static int ULTIMATE_QUESTION = 42; + } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/StaticNestedClass.kt b/compiler/testData/compileKotlinAgainstJava/StaticNestedClass.kt new file mode 100644 index 00000000000..aac63265edd --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/StaticNestedClass.kt @@ -0,0 +1,3 @@ +package test + +fun answer() = StaticNestedClass.StaticNested.ULTIMATE_QUESTION diff --git a/compiler/testData/compileKotlinAgainstJava/StaticNestedClass.txt b/compiler/testData/compileKotlinAgainstJava/StaticNestedClass.txt new file mode 100644 index 00000000000..2306c6acecc --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/StaticNestedClass.txt @@ -0,0 +1,14 @@ +package test + +public fun answer(): kotlin.Int + +public open class StaticNestedClass { + public constructor StaticNestedClass() + + public/*package*/ open class StaticNested { + public/*package*/ constructor StaticNested() + + // Static members + public final var ULTIMATE_QUESTION: kotlin.Int + } +} diff --git a/compiler/testData/compileKotlinAgainstJava/TypeArgumentInSuperType.java b/compiler/testData/compileKotlinAgainstJava/TypeArgumentInSuperType.java new file mode 100644 index 00000000000..914683f5fa9 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/TypeArgumentInSuperType.java @@ -0,0 +1,23 @@ +package test; + +public class TypeArgumentInSuperType { + + + public static final class Impl implements Interface2.InnerInterface { + + } + + +} + +interface Interface1 { + + interface InnerInterface { + + } + +} + +interface Interface2 extends Interface1 { + +} diff --git a/compiler/testData/compileKotlinAgainstJava/TypeArgumentInSuperType.kt b/compiler/testData/compileKotlinAgainstJava/TypeArgumentInSuperType.kt new file mode 100644 index 00000000000..41a8eb50c77 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/TypeArgumentInSuperType.kt @@ -0,0 +1,4 @@ +package test + +internal fun func(): Interface1.InnerInterface = + TypeArgumentInSuperType.Impl() diff --git a/compiler/testData/compileKotlinAgainstJava/TypeArgumentInSuperType.txt b/compiler/testData/compileKotlinAgainstJava/TypeArgumentInSuperType.txt new file mode 100644 index 00000000000..07dfca3a8fc --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/TypeArgumentInSuperType.txt @@ -0,0 +1,20 @@ +package test + +internal fun func(): test.Interface1.InnerInterface + +public/*package*/ interface Interface1 { + + public interface InnerInterface { + } +} + +public/*package*/ interface Interface2 : test.Interface1 { +} + +public open class TypeArgumentInSuperType { + public constructor TypeArgumentInSuperType() + + public final class Impl : test.Interface1.InnerInterface { + public constructor Impl() + } +} diff --git a/compiler/testData/compileKotlinAgainstJava/TypeParameter.java b/compiler/testData/compileKotlinAgainstJava/TypeParameter.java new file mode 100644 index 00000000000..0a6b5c7c562 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/TypeParameter.java @@ -0,0 +1,7 @@ +package test; + +class TypeParameter { + + public static T method(T e) { return null; } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/TypeParameter.kt b/compiler/testData/compileKotlinAgainstJava/TypeParameter.kt new file mode 100644 index 00000000000..1d3a68b593c --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/TypeParameter.kt @@ -0,0 +1,3 @@ +package test + +fun foo() = TypeParameter.method("str") diff --git a/compiler/testData/compileKotlinAgainstJava/TypeParameter.txt b/compiler/testData/compileKotlinAgainstJava/TypeParameter.txt new file mode 100644 index 00000000000..5070302e3f5 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/TypeParameter.txt @@ -0,0 +1,10 @@ +package test + +public fun foo(): kotlin.String! + +public/*package*/ open class TypeParameter { + public/*package*/ constructor TypeParameter() + + // Static members + public open fun method(/*0*/ T!): T! +} diff --git a/compiler/testData/compileKotlinAgainstJava/UseKotlinInner.java b/compiler/testData/compileKotlinAgainstJava/UseKotlinInner.java new file mode 100644 index 00000000000..4b26622c572 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/UseKotlinInner.java @@ -0,0 +1,16 @@ +package test; + +public class UseKotlinInner extends KotlinClass { + + KotlinInner getKotlinInner() { return null; } + + JavaInner getJavaInner() { return null; } + + KotlinInner3 getKotlinInner3() { return null; } +} + +class JavaClass2 { + + static class JavaInner {} + +} diff --git a/compiler/testData/compileKotlinAgainstJava/UseKotlinInner.kt b/compiler/testData/compileKotlinAgainstJava/UseKotlinInner.kt new file mode 100644 index 00000000000..6e4ed5805ca --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/UseKotlinInner.kt @@ -0,0 +1,19 @@ +package test + +private open class KotlinClass : KotlinInterface.KotlinInner2() { + + inner class KotlinInner + +} + +private interface KotlinInterface { + open class KotlinInner2 : JavaClass2() { + class KotlinInner3 + } +} + +private fun getKotlinInner() = UseKotlinInner().kotlinInner + +private fun getJavaInner() = UseKotlinInner().javaInner + +private fun getKotlinInner3() = UseKotlinInner().kotlinInner3 diff --git a/compiler/testData/compileKotlinAgainstJava/UseKotlinInner.txt b/compiler/testData/compileKotlinAgainstJava/UseKotlinInner.txt new file mode 100644 index 00000000000..64dc12aada6 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/UseKotlinInner.txt @@ -0,0 +1,39 @@ +package test + +private fun getJavaInner(): test.JavaClass2.JavaInner! +private fun getKotlinInner(): test.KotlinClass.KotlinInner! +private fun getKotlinInner3(): test.KotlinInterface.KotlinInner2.KotlinInner3! + +public/*package*/ open class JavaClass2 { + public/*package*/ constructor JavaClass2() + + public/*package*/ open class JavaInner { + public/*package*/ constructor JavaInner() + } +} + +private open class KotlinClass : test.KotlinInterface.KotlinInner2 { + public constructor KotlinClass() + + public final inner class KotlinInner { + public constructor KotlinInner() + } +} + +private interface KotlinInterface { + + public open class KotlinInner2 : test.JavaClass2 { + public constructor KotlinInner2() + + public final class KotlinInner3 { + public constructor KotlinInner3() + } + } +} + +public open class UseKotlinInner : test.KotlinClass { + public constructor UseKotlinInner() + public/*package*/ open fun getJavaInner(): test.JavaClass2.JavaInner! + public/*package*/ open fun getKotlinInner(): test.KotlinClass.KotlinInner! + public/*package*/ open fun getKotlinInner3(): test.KotlinInterface.KotlinInner2.KotlinInner3! +} diff --git a/compiler/testData/compileKotlinAgainstJava/UseKtClass.java b/compiler/testData/compileKotlinAgainstJava/UseKtClass.java new file mode 100644 index 00000000000..dfe7103c8c6 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/UseKtClass.java @@ -0,0 +1,9 @@ +package test; + +public class UseKtClass { + + public int use() { + return UseKtClassKt.func(); + } + +} diff --git a/compiler/testData/compileKotlinAgainstJava/UseKtClass.kt b/compiler/testData/compileKotlinAgainstJava/UseKtClass.kt new file mode 100644 index 00000000000..5b52995e557 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/UseKtClass.kt @@ -0,0 +1,5 @@ +package test + +fun func() = 42 + +fun func2() = UseKtClass().use() diff --git a/compiler/testData/compileKotlinAgainstJava/UseKtClass.txt b/compiler/testData/compileKotlinAgainstJava/UseKtClass.txt new file mode 100644 index 00000000000..1b3602b244f --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/UseKtClass.txt @@ -0,0 +1,9 @@ +package test + +public fun func(): kotlin.Int +public fun func2(): kotlin.Int + +public open class UseKtClass { + public constructor UseKtClass() + public open fun use(): kotlin.Int +} diff --git a/compiler/testData/compileKotlinAgainstJava/Vararg.java b/compiler/testData/compileKotlinAgainstJava/Vararg.java new file mode 100644 index 00000000000..8798012c249 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Vararg.java @@ -0,0 +1,7 @@ +package test; + +public class Vararg { + + public static void method(String... args) {} + +} diff --git a/compiler/testData/compileKotlinAgainstJava/Vararg.kt b/compiler/testData/compileKotlinAgainstJava/Vararg.kt new file mode 100644 index 00000000000..be25d712060 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Vararg.kt @@ -0,0 +1,7 @@ +package test + +fun useVarargs() { + Vararg.method() + Vararg.method("str") + Vararg.method("str", "str2", "str3") +} diff --git a/compiler/testData/compileKotlinAgainstJava/Vararg.txt b/compiler/testData/compileKotlinAgainstJava/Vararg.txt new file mode 100644 index 00000000000..b6d495b502c --- /dev/null +++ b/compiler/testData/compileKotlinAgainstJava/Vararg.txt @@ -0,0 +1,10 @@ +package test + +public fun useVarargs(): kotlin.Unit + +public open class Vararg { + public constructor Vararg() + + // Static members + public open fun method(/*0*/ vararg kotlin.String! /*kotlin.Array<(out) kotlin.String!>!*/): kotlin.Unit +} diff --git a/compiler/tests/compiler-tests.iml b/compiler/tests/compiler-tests.iml index 4a834f8f64c..b778363feeb 100644 --- a/compiler/tests/compiler-tests.iml +++ b/compiler/tests/compiler-tests.iml @@ -34,6 +34,7 @@ + diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileJavaAgainstKotlinTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileJavaAgainstKotlinTest.kt index f0e7aedc206..d9cbaedd08f 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileJavaAgainstKotlinTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileJavaAgainstKotlinTest.kt @@ -16,36 +16,61 @@ package org.jetbrains.kotlin.jvm.compiler +import com.intellij.openapi.Disposable +import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys +import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.config.JVMConfigurationKeys +import org.jetbrains.kotlin.javac.JavacWrapper import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.renderer.AnnotationArgumentsRenderingPolicy -import org.jetbrains.kotlin.renderer.DescriptorRenderer -import org.jetbrains.kotlin.renderer.DescriptorRendererModifier -import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy +import org.jetbrains.kotlin.renderer.* import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil import org.jetbrains.kotlin.test.ConfigurationKind -import org.jetbrains.kotlin.test.KotlinTestUtils.* +import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.TestCaseWithTmpdir import org.jetbrains.kotlin.test.TestJdkKind -import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile -import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.junit.Assert + import java.io.File import java.io.IOException import java.lang.annotation.Retention +import org.jetbrains.kotlin.test.KotlinTestUtils.* +import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile + abstract class AbstractCompileJavaAgainstKotlinTest : TestCaseWithTmpdir() { @Throws(IOException::class) - protected fun doTest(ktFilePath: String) { + protected fun doTestWithJavac(ktFilePath: String) { + doTest(ktFilePath, true) + } + + @Throws(IOException::class) + protected fun doTestWithoutJavac(ktFilePath: String) { + doTest(ktFilePath, false) + } + + @Throws(IOException::class) + protected fun doTest(ktFilePath: String, useJavac: Boolean) { Assert.assertTrue(ktFilePath.endsWith(".kt")) val ktFile = File(ktFilePath) val javaFile = File(ktFilePath.replaceFirst("\\.kt$".toRegex(), ".java")) + val javaErrorFile = File(ktFilePath.replaceFirst("\\.kt$".toRegex(), ".javaerr.txt")) val out = File(tmpdir, "out") - val compiledSuccessfully = compileKotlinWithJava(listOf(javaFile), listOf(ktFile), - out, testRootDisposable, javaErrorFile) + + val compiledSuccessfully = if (useJavac) { + compileKotlinWithJava(listOf(javaFile), + listOf(ktFile), + out, testRootDisposable) + } else { + KotlinTestUtils.compileKotlinWithJava(listOf(javaFile), + listOf(ktFile), + out, testRootDisposable, javaErrorFile) + } + if (!compiledSuccessfully) return val environment = KotlinCoreEnvironment.createForTests( @@ -56,12 +81,35 @@ abstract class AbstractCompileJavaAgainstKotlinTest : TestCaseWithTmpdir() { val analysisResult = JvmResolveUtil.analyze(environment) val packageView = analysisResult.moduleDescriptor.getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME) - assertFalse("Nothing found in package " + LoadDescriptorUtil.TEST_PACKAGE_FQNAME, packageView.isEmpty()) + assertFalse("Nothing found in package ${LoadDescriptorUtil.TEST_PACKAGE_FQNAME}", packageView.isEmpty()) val expectedFile = File(ktFilePath.replaceFirst("\\.kt$".toRegex(), ".txt")) validateAndCompareDescriptorWithFile(packageView, CONFIGURATION, expectedFile) } + @Throws(IOException::class) + fun compileKotlinWithJava( + javaFiles: List, + ktFiles: List, + outDir: File, + disposable: Disposable + ): Boolean { + val environment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable) + environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true) + environment.configuration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, outDir) + environment.configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE) + environment.registerJavac(javaFiles, kotlinFiles = listOf(KotlinTestUtils.loadJetFile(environment.project, ktFiles.first()))) + if (!ktFiles.isEmpty()) { + LoadDescriptorUtil.compileKotlinToDirAndGetModule(ktFiles, outDir, environment) + } + else { + val mkdirs = outDir.mkdirs() + assert(mkdirs) { "Not created: $outDir" } + } + + return JavacWrapper.getInstance(environment.project).use { it.compile() } + } + companion object { // Do not render parameter names because there are test cases where classes inherit from JDK collections, // and some versions of JDK have debug information in the class files (including parameter names), and some don't diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstJavaTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstJavaTest.kt new file mode 100644 index 00000000000..8d6f83de024 --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstJavaTest.kt @@ -0,0 +1,108 @@ +/* + * Copyright 2010-2017 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.jvm.compiler + +import com.intellij.openapi.Disposable +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.config.JVMConfigurationKeys +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.renderer.* +import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil +import org.jetbrains.kotlin.test.ConfigurationKind +import org.jetbrains.kotlin.test.KotlinTestUtils +import org.jetbrains.kotlin.test.TestCaseWithTmpdir +import org.jetbrains.kotlin.test.TestJdkKind +import org.junit.Assert + +import java.io.File +import java.io.IOException +import java.lang.annotation.Retention + +import org.jetbrains.kotlin.test.KotlinTestUtils.* +import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile + +abstract class AbstractCompileKotlinAgainstJavaTest : TestCaseWithTmpdir() { + + @Throws(IOException::class) + protected fun doTest(ktFilePath: String) { + Assert.assertTrue(ktFilePath.endsWith(".kt")) + val ktFile = File(ktFilePath) + val javaFile = File(ktFilePath.replaceFirst("\\.kt$".toRegex(), ".java")) + val out = File(tmpdir, "out") + + val compiledSuccessfully = compileKotlinWithJava(listOf(javaFile), + listOf(ktFile), + out, testRootDisposable) + if (!compiledSuccessfully) return + + val environment = KotlinCoreEnvironment.createForTests( + testRootDisposable, + newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, getAnnotationsJar(), out), + EnvironmentConfigFiles.JVM_CONFIG_FILES + ) + + environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true) + environment.configuration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, out) + environment.registerJavac(emptyList()) + + val analysisResult = JvmResolveUtil.analyze(environment) + val packageView = analysisResult.moduleDescriptor.getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME) + assertFalse("Nothing found in package ${LoadDescriptorUtil.TEST_PACKAGE_FQNAME}", packageView.isEmpty()) + + val expectedFile = File(ktFilePath.replaceFirst("\\.kt$".toRegex(), ".txt")) + validateAndCompareDescriptorWithFile(packageView, CONFIGURATION, expectedFile) + } + + @Throws(IOException::class) + fun compileKotlinWithJava( + javaFiles: List, + ktFiles: List, + outDir: File, + disposable: Disposable + ): Boolean { + val environment = createEnvironmentWithMockJdkAndIdeaAnnotations(disposable) + environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true) + environment.configuration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, outDir) + environment.registerJavac(javaFiles, kotlinFiles = listOf(KotlinTestUtils.loadJetFile(environment.project, ktFiles.first()))) + if (!ktFiles.isEmpty()) { + LoadDescriptorUtil.compileKotlinToDirAndGetModule(ktFiles, outDir, environment) + } + else { + val mkdirs = outDir.mkdirs() + assert(mkdirs) { "Not created: $outDir" } + } + + return JavacWrapper.getInstance(environment.project).use { it.compile() } + } + + companion object { + // Do not render parameter names because there are test cases where classes inherit from JDK collections, + // and some versions of JDK have debug information in the class files (including parameter names), and some don't + private val CONFIGURATION = AbstractLoadJavaTest.COMPARATOR_CONFIGURATION.withRenderer( + DescriptorRenderer.withOptions { + withDefinedIn = false + parameterNameRenderingPolicy = ParameterNameRenderingPolicy.NONE + verbose = true + annotationArgumentsRenderingPolicy = AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY + excludedAnnotationClasses = setOf(FqName(Retention::class.java.name)) + modifiers = DescriptorRendererModifier.ALL + } + ) + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileJavaAgainstKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileJavaAgainstKotlinTestGenerated.java index 546b1c0d6e6..0b1d7c2d9b1 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileJavaAgainstKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileJavaAgainstKotlinTestGenerated.java @@ -28,638 +28,1277 @@ import java.util.regex.Pattern; /** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") -@TestMetadata("compiler/testData/compileJavaAgainstKotlin") -@TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInCompileJavaAgainstKotlin() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/callableReference") + @TestMetadata("compiler/testData/compileJavaAgainstKotlin") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) - public static class CallableReference extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInCallableReference() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/callableReference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + public static class WithoutJavac extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInWithoutJavac() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } - @TestMetadata("GenericSignature.kt") - public void testGenericSignature() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/callableReference/GenericSignature.kt"); - doTest(fileName); - } - } - - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/class") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Class extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInClass() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/class"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("ClassObject.kt") - public void testClassObject() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/ClassObject.kt"); - doTest(fileName); - } - - @TestMetadata("DefaultConstructor.kt") - public void testDefaultConstructor() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/DefaultConstructor.kt"); - doTest(fileName); - } - - @TestMetadata("DefaultConstructorWithTwoArgs.kt") - public void testDefaultConstructorWithTwoArgs() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/DefaultConstructorWithTwoArgs.kt"); - doTest(fileName); - } - - @TestMetadata("ExtendsAbstractListT.kt") - public void testExtendsAbstractListT() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/ExtendsAbstractListT.kt"); - doTest(fileName); - } - - @TestMetadata("ImplementsListString.kt") - public void testImplementsListString() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/ImplementsListString.kt"); - doTest(fileName); - } - - @TestMetadata("ImplementsMapPP.kt") - public void testImplementsMapPP() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/ImplementsMapPP.kt"); - doTest(fileName); - } - - @TestMetadata("InnerClass.kt") - public void testInnerClass() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/InnerClass.kt"); - doTest(fileName); - } - - @TestMetadata("InnerClassConstructors.kt") - public void testInnerClassConstructors() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/InnerClassConstructors.kt"); - doTest(fileName); - } - - @TestMetadata("InnerClassOfGeneric.kt") - public void testInnerClassOfGeneric() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/InnerClassOfGeneric.kt"); - doTest(fileName); - } - - @TestMetadata("kt3561.kt") - public void testKt3561() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/kt3561.kt"); - doTest(fileName); - } - - @TestMetadata("kt4050.kt") - public void testKt4050() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/kt4050.kt"); - doTest(fileName); - } - - @TestMetadata("Simple.kt") - public void testSimple() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/Simple.kt"); - doTest(fileName); - } - - @TestMetadata("StarProjection.kt") - public void testStarProjection() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/StarProjection.kt"); - doTest(fileName); - } - } - - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/enum") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Enum extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInEnum() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/enum"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("DefaultArgumentInEnumConstructor.kt") - public void testDefaultArgumentInEnumConstructor() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/enum/DefaultArgumentInEnumConstructor.kt"); - doTest(fileName); - } - } - - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class JvmStatic extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInJvmStatic() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/jvmStatic"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("simpleCompanionObject.kt") - public void testSimpleCompanionObject() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic/simpleCompanionObject.kt"); - doTest(fileName); - } - - @TestMetadata("simpleCompanionObjectProperty.kt") - public void testSimpleCompanionObjectProperty() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic/simpleCompanionObjectProperty.kt"); - doTest(fileName); - } - - @TestMetadata("simpleObject.kt") - public void testSimpleObject() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic/simpleObject.kt"); - doTest(fileName); - } - - @TestMetadata("simpleObjectProperty.kt") - public void testSimpleObjectProperty() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic/simpleObjectProperty.kt"); - doTest(fileName); - } - } - - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/method") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Method extends AbstractCompileJavaAgainstKotlinTest { - @TestMetadata("AccessorGenericSignature.kt") - public void testAccessorGenericSignature() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/AccessorGenericSignature.kt"); - doTest(fileName); - } - - public void testAllFilesPresentInMethod() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/method"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("Any.kt") - public void testAny() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Any.kt"); - doTest(fileName); - } - - @TestMetadata("ArrayOfIntArray.kt") - public void testArrayOfIntArray() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ArrayOfIntArray.kt"); - doTest(fileName); - } - - @TestMetadata("ArrayOfIntegerArray.kt") - public void testArrayOfIntegerArray() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ArrayOfIntegerArray.kt"); - doTest(fileName); - } - - @TestMetadata("ClashingSignaturesWithoutReturnType.kt") - public void testClashingSignaturesWithoutReturnType() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ClashingSignaturesWithoutReturnType.kt"); - doTest(fileName); - } - - @TestMetadata("Delegation.kt") - public void testDelegation() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Delegation.kt"); - doTest(fileName); - } - - @TestMetadata("Extensions.kt") - public void testExtensions() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Extensions.kt"); - doTest(fileName); - } - - @TestMetadata("GenericArray.kt") - public void testGenericArray() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/GenericArray.kt"); - doTest(fileName); - } - - @TestMetadata("Hello.kt") - public void testHello() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Hello.kt"); - doTest(fileName); - } - - @TestMetadata("Int.kt") - public void testInt() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Int.kt"); - doTest(fileName); - } - - @TestMetadata("IntArray.kt") - public void testIntArray() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/IntArray.kt"); - doTest(fileName); - } - - @TestMetadata("IntWithDefault.kt") - public void testIntWithDefault() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/IntWithDefault.kt"); - doTest(fileName); - } - - @TestMetadata("IntegerArray.kt") - public void testIntegerArray() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/IntegerArray.kt"); - doTest(fileName); - } - - @TestMetadata("ListOfInt.kt") - public void testListOfInt() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ListOfInt.kt"); - doTest(fileName); - } - - @TestMetadata("ListOfString.kt") - public void testListOfString() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ListOfString.kt"); - doTest(fileName); - } - - @TestMetadata("ListOfT.kt") - public void testListOfT() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ListOfT.kt"); - doTest(fileName); - } - - @TestMetadata("MapOfKString.kt") - public void testMapOfKString() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/MapOfKString.kt"); - doTest(fileName); - } - - @TestMetadata("MapOfStringIntQ.kt") - public void testMapOfStringIntQ() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/MapOfStringIntQ.kt"); - doTest(fileName); - } - - @TestMetadata("QExtendsListString.kt") - public void testQExtendsListString() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/QExtendsListString.kt"); - doTest(fileName); - } - - @TestMetadata("QExtendsString.kt") - public void testQExtendsString() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/QExtendsString.kt"); - doTest(fileName); - } - - @TestMetadata("TraitImpl.kt") - public void testTraitImpl() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/TraitImpl.kt"); - doTest(fileName); - } - - @TestMetadata("Vararg.kt") - public void testVararg() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Vararg.kt"); - doTest(fileName); - } - - @TestMetadata("Void.kt") - public void testVoid() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Void.kt"); - doTest(fileName); - } - - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/method/platformName") + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/callableReference") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) - public static class PlatformName extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInPlatformName() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/method/platformName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + public static class CallableReference extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInCallableReference() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/callableReference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } - @TestMetadata("PlatformName.kt") - public void testPlatformName() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/platformName/PlatformName.kt"); - doTest(fileName); + @TestMetadata("GenericSignature.kt") + public void testGenericSignature() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/callableReference/GenericSignature.kt"); + doTestWithoutJavac(fileName); } } - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride") + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/class") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) - public static class PrimitiveOverride extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInPrimitiveOverride() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + public static class Class extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInClass() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/class"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } - @TestMetadata("ByteOverridesObject.kt") - public void testByteOverridesObject() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/ByteOverridesObject.kt"); - doTest(fileName); + @TestMetadata("ClassObject.kt") + public void testClassObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/ClassObject.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("CallFinalNotInSubclass.kt") - public void testCallFinalNotInSubclass() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/CallFinalNotInSubclass.kt"); - doTest(fileName); + @TestMetadata("DefaultConstructor.kt") + public void testDefaultConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/DefaultConstructor.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("CallNotInSubclass.kt") - public void testCallNotInSubclass() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/CallNotInSubclass.kt"); - doTest(fileName); + @TestMetadata("DefaultConstructorWithTwoArgs.kt") + public void testDefaultConstructorWithTwoArgs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/DefaultConstructorWithTwoArgs.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("CovariantReturnTypeOverride.kt") - public void testCovariantReturnTypeOverride() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/CovariantReturnTypeOverride.kt"); - doTest(fileName); + @TestMetadata("ExtendsAbstractListT.kt") + public void testExtendsAbstractListT() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/ExtendsAbstractListT.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("FinalOverride.kt") - public void testFinalOverride() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/FinalOverride.kt"); - doTest(fileName); + @TestMetadata("ImplementsListString.kt") + public void testImplementsListString() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/ImplementsListString.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("IntOverridesComparable.kt") - public void testIntOverridesComparable() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/IntOverridesComparable.kt"); - doTest(fileName); + @TestMetadata("ImplementsMapPP.kt") + public void testImplementsMapPP() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/ImplementsMapPP.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("IntOverridesNumber.kt") - public void testIntOverridesNumber() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/IntOverridesNumber.kt"); - doTest(fileName); + @TestMetadata("InnerClass.kt") + public void testInnerClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/InnerClass.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("IntOverridesObject.kt") - public void testIntOverridesObject() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/IntOverridesObject.kt"); - doTest(fileName); + @TestMetadata("InnerClassConstructors.kt") + public void testInnerClassConstructors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/InnerClassConstructors.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("ManyClassesHierarchy.kt") - public void testManyClassesHierarchy() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/ManyClassesHierarchy.kt"); - doTest(fileName); + @TestMetadata("InnerClassOfGeneric.kt") + public void testInnerClassOfGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/InnerClassOfGeneric.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("NullableIntOverridesObject.kt") - public void testNullableIntOverridesObject() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/NullableIntOverridesObject.kt"); - doTest(fileName); + @TestMetadata("kt3561.kt") + public void testKt3561() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/kt3561.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("OverrideInJava.kt") - public void testOverrideInJava() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/OverrideInJava.kt"); - doTest(fileName); + @TestMetadata("kt4050.kt") + public void testKt4050() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/kt4050.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("Simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/Simple.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("StarProjection.kt") + public void testStarProjection() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/StarProjection.kt"); + doTestWithoutJavac(fileName); } } - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws") + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/enum") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) - public static class Throws extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInThrows() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/method/throws"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + public static class Enum extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInEnum() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/enum"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } - @TestMetadata("ClassMembers.kt") - public void testClassMembers() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.kt"); - doTest(fileName); + @TestMetadata("DefaultArgumentInEnumConstructor.kt") + public void testDefaultArgumentInEnumConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/enum/DefaultArgumentInEnumConstructor.kt"); + doTestWithoutJavac(fileName); + } + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmStatic extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInJvmStatic() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/jvmStatic"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } - @TestMetadata("Constructor.kt") - public void testConstructor() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.kt"); - doTest(fileName); + @TestMetadata("simpleCompanionObject.kt") + public void testSimpleCompanionObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic/simpleCompanionObject.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("DefaultArgs.kt") - public void testDefaultArgs() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.kt"); - doTest(fileName); + @TestMetadata("simpleCompanionObjectProperty.kt") + public void testSimpleCompanionObjectProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic/simpleCompanionObjectProperty.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("simpleObject.kt") + public void testSimpleObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic/simpleObject.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("simpleObjectProperty.kt") + public void testSimpleObjectProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic/simpleObjectProperty.kt"); + doTestWithoutJavac(fileName); + } + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/method") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Method extends AbstractCompileJavaAgainstKotlinTest { + @TestMetadata("AccessorGenericSignature.kt") + public void testAccessorGenericSignature() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/AccessorGenericSignature.kt"); + doTestWithoutJavac(fileName); + } + + public void testAllFilesPresentInMethod() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/method"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("Any.kt") + public void testAny() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Any.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("ArrayOfIntArray.kt") + public void testArrayOfIntArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ArrayOfIntArray.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("ArrayOfIntegerArray.kt") + public void testArrayOfIntegerArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ArrayOfIntegerArray.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("ClashingSignaturesWithoutReturnType.kt") + public void testClashingSignaturesWithoutReturnType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ClashingSignaturesWithoutReturnType.kt"); + doTestWithoutJavac(fileName); } @TestMetadata("Delegation.kt") public void testDelegation() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.kt"); - doTest(fileName); + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Delegation.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("GenericSubstitution.kt") - public void testGenericSubstitution() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.kt"); - doTest(fileName); + @TestMetadata("Extensions.kt") + public void testExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Extensions.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("TopLevel.kt") - public void testTopLevel() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.kt"); - doTest(fileName); + @TestMetadata("GenericArray.kt") + public void testGenericArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/GenericArray.kt"); + doTestWithoutJavac(fileName); } - @TestMetadata("TraitMembers.kt") - public void testTraitMembers() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.kt"); - doTest(fileName); + @TestMetadata("Hello.kt") + public void testHello() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Hello.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("Int.kt") + public void testInt() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Int.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("IntArray.kt") + public void testIntArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/IntArray.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("IntWithDefault.kt") + public void testIntWithDefault() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/IntWithDefault.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("IntegerArray.kt") + public void testIntegerArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/IntegerArray.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("ListOfInt.kt") + public void testListOfInt() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ListOfInt.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("ListOfString.kt") + public void testListOfString() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ListOfString.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("ListOfT.kt") + public void testListOfT() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ListOfT.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("MapOfKString.kt") + public void testMapOfKString() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/MapOfKString.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("MapOfStringIntQ.kt") + public void testMapOfStringIntQ() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/MapOfStringIntQ.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("QExtendsListString.kt") + public void testQExtendsListString() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/QExtendsListString.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("QExtendsString.kt") + public void testQExtendsString() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/QExtendsString.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("TraitImpl.kt") + public void testTraitImpl() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/TraitImpl.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("Vararg.kt") + public void testVararg() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Vararg.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("Void.kt") + public void testVoid() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Void.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/method/platformName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class PlatformName extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInPlatformName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/method/platformName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("PlatformName.kt") + public void testPlatformName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/platformName/PlatformName.kt"); + doTestWithoutJavac(fileName); + } + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class PrimitiveOverride extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInPrimitiveOverride() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("ByteOverridesObject.kt") + public void testByteOverridesObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/ByteOverridesObject.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("CallFinalNotInSubclass.kt") + public void testCallFinalNotInSubclass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/CallFinalNotInSubclass.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("CallNotInSubclass.kt") + public void testCallNotInSubclass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/CallNotInSubclass.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("CovariantReturnTypeOverride.kt") + public void testCovariantReturnTypeOverride() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/CovariantReturnTypeOverride.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("FinalOverride.kt") + public void testFinalOverride() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/FinalOverride.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("IntOverridesComparable.kt") + public void testIntOverridesComparable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/IntOverridesComparable.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("IntOverridesNumber.kt") + public void testIntOverridesNumber() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/IntOverridesNumber.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("IntOverridesObject.kt") + public void testIntOverridesObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/IntOverridesObject.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("ManyClassesHierarchy.kt") + public void testManyClassesHierarchy() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/ManyClassesHierarchy.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("NullableIntOverridesObject.kt") + public void testNullableIntOverridesObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/NullableIntOverridesObject.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("OverrideInJava.kt") + public void testOverrideInJava() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/OverrideInJava.kt"); + doTestWithoutJavac(fileName); + } + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Throws extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInThrows() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/method/throws"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("ClassMembers.kt") + public void testClassMembers() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("Constructor.kt") + public void testConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("DefaultArgs.kt") + public void testDefaultArgs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("Delegation.kt") + public void testDelegation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("GenericSubstitution.kt") + public void testGenericSubstitution() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("TopLevel.kt") + public void testTopLevel() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("TraitMembers.kt") + public void testTraitMembers() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.kt"); + doTestWithoutJavac(fileName); + } } } - } - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/property") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Property extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInProperty() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/property"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("ConstVal.kt") - public void testConstVal() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/property/ConstVal.kt"); - doTest(fileName); - } - - @TestMetadata("Extensions.kt") - public void testExtensions() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/property/Extensions.kt"); - doTest(fileName); - } - - @TestMetadata("GenericProperty.kt") - public void testGenericProperty() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/property/GenericProperty.kt"); - doTest(fileName); - } - - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/property/platformName") + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/property") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) - public static class PlatformName extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInPlatformName() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/property/platformName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + public static class Property extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInProperty() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/property"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } - @TestMetadata("PlatformName.kt") - public void testPlatformName() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/property/platformName/PlatformName.kt"); - doTest(fileName); + @TestMetadata("ConstVal.kt") + public void testConstVal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/property/ConstVal.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("Extensions.kt") + public void testExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/property/Extensions.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("GenericProperty.kt") + public void testGenericProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/property/GenericProperty.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/property/platformName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class PlatformName extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInPlatformName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/property/platformName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("PlatformName.kt") + public void testPlatformName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/property/platformName/PlatformName.kt"); + doTestWithoutJavac(fileName); + } + } + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/sealed") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Sealed extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInSealed() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/sealed"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("Derived.kt") + public void testDerived() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/sealed/Derived.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("Instance.kt") + public void testInstance() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/sealed/Instance.kt"); + doTestWithoutJavac(fileName); + } + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class StaticFields extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInStaticFields() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/staticFields"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("AnnotationClass.kt") + public void testAnnotationClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/AnnotationClass.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("AnnotationTrait.kt") + public void testAnnotationTrait() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/AnnotationTrait.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("kt3698.kt") + public void testKt3698() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/kt3698.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("staticClassProperty.kt") + public void testStaticClassProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/staticClassProperty.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("staticTraitProperty.kt") + public void testStaticTraitProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/staticTraitProperty.kt"); + doTestWithoutJavac(fileName); + } + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/targets") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Targets extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInTargets() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/targets"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("annotation.kt") + public void testAnnotation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/annotation.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("base.kt") + public void testBase() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/base.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("classifier.kt") + public void testClassifier() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/classifier.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("constructor.kt") + public void testConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/constructor.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("empty.kt") + public void testEmpty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/empty.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("field.kt") + public void testField() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/field.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("function.kt") + public void testFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/function.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("getter.kt") + public void testGetter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/getter.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("local.kt") + public void testLocal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/local.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("multiple.kt") + public void testMultiple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/multiple.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("parameter.kt") + public void testParameter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/parameter.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("property.kt") + public void testProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/property.kt"); + doTestWithoutJavac(fileName); + } + + @TestMetadata("setter.kt") + public void testSetter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/setter.kt"); + doTestWithoutJavac(fileName); } } } - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/sealed") + @TestMetadata("compiler/testData/compileJavaAgainstKotlin") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) - public static class Sealed extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInSealed() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/sealed"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + public static class WithJavac extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInWithJavac() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } - @TestMetadata("Derived.kt") - public void testDerived() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/sealed/Derived.kt"); - doTest(fileName); + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/callableReference") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CallableReference extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInCallableReference() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/callableReference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("GenericSignature.kt") + public void testGenericSignature() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/callableReference/GenericSignature.kt"); + doTestWithJavac(fileName); + } } - @TestMetadata("Instance.kt") - public void testInstance() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/sealed/Instance.kt"); - doTest(fileName); - } - } + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/class") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Class extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInClass() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/class"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class StaticFields extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInStaticFields() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/staticFields"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + @TestMetadata("ClassObject.kt") + public void testClassObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/ClassObject.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("DefaultConstructor.kt") + public void testDefaultConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/DefaultConstructor.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("DefaultConstructorWithTwoArgs.kt") + public void testDefaultConstructorWithTwoArgs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/DefaultConstructorWithTwoArgs.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("ExtendsAbstractListT.kt") + public void testExtendsAbstractListT() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/ExtendsAbstractListT.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("ImplementsListString.kt") + public void testImplementsListString() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/ImplementsListString.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("ImplementsMapPP.kt") + public void testImplementsMapPP() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/ImplementsMapPP.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("InnerClass.kt") + public void testInnerClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/InnerClass.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("InnerClassConstructors.kt") + public void testInnerClassConstructors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/InnerClassConstructors.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("InnerClassOfGeneric.kt") + public void testInnerClassOfGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/InnerClassOfGeneric.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("kt3561.kt") + public void testKt3561() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/kt3561.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("kt4050.kt") + public void testKt4050() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/kt4050.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("Simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/Simple.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("StarProjection.kt") + public void testStarProjection() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/class/StarProjection.kt"); + doTestWithJavac(fileName); + } } - @TestMetadata("AnnotationClass.kt") - public void testAnnotationClass() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/AnnotationClass.kt"); - doTest(fileName); + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/enum") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Enum extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInEnum() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/enum"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("DefaultArgumentInEnumConstructor.kt") + public void testDefaultArgumentInEnumConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/enum/DefaultArgumentInEnumConstructor.kt"); + doTestWithJavac(fileName); + } } - @TestMetadata("AnnotationTrait.kt") - public void testAnnotationTrait() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/AnnotationTrait.kt"); - doTest(fileName); + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmStatic extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInJvmStatic() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/jvmStatic"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("simpleCompanionObject.kt") + public void testSimpleCompanionObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic/simpleCompanionObject.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("simpleCompanionObjectProperty.kt") + public void testSimpleCompanionObjectProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic/simpleCompanionObjectProperty.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("simpleObject.kt") + public void testSimpleObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic/simpleObject.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("simpleObjectProperty.kt") + public void testSimpleObjectProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/jvmStatic/simpleObjectProperty.kt"); + doTestWithJavac(fileName); + } } - @TestMetadata("kt3698.kt") - public void testKt3698() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/kt3698.kt"); - doTest(fileName); + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/method") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Method extends AbstractCompileJavaAgainstKotlinTest { + @TestMetadata("AccessorGenericSignature.kt") + public void testAccessorGenericSignature() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/AccessorGenericSignature.kt"); + doTestWithJavac(fileName); + } + + public void testAllFilesPresentInMethod() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/method"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("Any.kt") + public void testAny() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Any.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("ArrayOfIntArray.kt") + public void testArrayOfIntArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ArrayOfIntArray.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("ArrayOfIntegerArray.kt") + public void testArrayOfIntegerArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ArrayOfIntegerArray.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("ClashingSignaturesWithoutReturnType.kt") + public void testClashingSignaturesWithoutReturnType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ClashingSignaturesWithoutReturnType.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("Delegation.kt") + public void testDelegation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Delegation.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("Extensions.kt") + public void testExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Extensions.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("GenericArray.kt") + public void testGenericArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/GenericArray.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("Hello.kt") + public void testHello() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Hello.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("Int.kt") + public void testInt() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Int.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("IntArray.kt") + public void testIntArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/IntArray.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("IntWithDefault.kt") + public void testIntWithDefault() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/IntWithDefault.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("IntegerArray.kt") + public void testIntegerArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/IntegerArray.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("ListOfInt.kt") + public void testListOfInt() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ListOfInt.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("ListOfString.kt") + public void testListOfString() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ListOfString.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("ListOfT.kt") + public void testListOfT() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/ListOfT.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("MapOfKString.kt") + public void testMapOfKString() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/MapOfKString.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("MapOfStringIntQ.kt") + public void testMapOfStringIntQ() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/MapOfStringIntQ.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("QExtendsListString.kt") + public void testQExtendsListString() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/QExtendsListString.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("QExtendsString.kt") + public void testQExtendsString() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/QExtendsString.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("TraitImpl.kt") + public void testTraitImpl() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/TraitImpl.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("Vararg.kt") + public void testVararg() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Vararg.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("Void.kt") + public void testVoid() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/Void.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/method/platformName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class PlatformName extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInPlatformName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/method/platformName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("PlatformName.kt") + public void testPlatformName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/platformName/PlatformName.kt"); + doTestWithJavac(fileName); + } + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class PrimitiveOverride extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInPrimitiveOverride() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("ByteOverridesObject.kt") + public void testByteOverridesObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/ByteOverridesObject.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("CallFinalNotInSubclass.kt") + public void testCallFinalNotInSubclass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/CallFinalNotInSubclass.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("CallNotInSubclass.kt") + public void testCallNotInSubclass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/CallNotInSubclass.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("CovariantReturnTypeOverride.kt") + public void testCovariantReturnTypeOverride() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/CovariantReturnTypeOverride.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("FinalOverride.kt") + public void testFinalOverride() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/FinalOverride.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("IntOverridesComparable.kt") + public void testIntOverridesComparable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/IntOverridesComparable.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("IntOverridesNumber.kt") + public void testIntOverridesNumber() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/IntOverridesNumber.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("IntOverridesObject.kt") + public void testIntOverridesObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/IntOverridesObject.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("ManyClassesHierarchy.kt") + public void testManyClassesHierarchy() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/ManyClassesHierarchy.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("NullableIntOverridesObject.kt") + public void testNullableIntOverridesObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/NullableIntOverridesObject.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("OverrideInJava.kt") + public void testOverrideInJava() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/primitiveOverride/OverrideInJava.kt"); + doTestWithJavac(fileName); + } + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Throws extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInThrows() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/method/throws"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("ClassMembers.kt") + public void testClassMembers() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("Constructor.kt") + public void testConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("DefaultArgs.kt") + public void testDefaultArgs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("Delegation.kt") + public void testDelegation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("GenericSubstitution.kt") + public void testGenericSubstitution() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("TopLevel.kt") + public void testTopLevel() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("TraitMembers.kt") + public void testTraitMembers() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.kt"); + doTestWithJavac(fileName); + } + } } - @TestMetadata("staticClassProperty.kt") - public void testStaticClassProperty() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/staticClassProperty.kt"); - doTest(fileName); + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/property") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Property extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInProperty() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/property"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("ConstVal.kt") + public void testConstVal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/property/ConstVal.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("Extensions.kt") + public void testExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/property/Extensions.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("GenericProperty.kt") + public void testGenericProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/property/GenericProperty.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/property/platformName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class PlatformName extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInPlatformName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/property/platformName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("PlatformName.kt") + public void testPlatformName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/property/platformName/PlatformName.kt"); + doTestWithJavac(fileName); + } + } } - @TestMetadata("staticTraitProperty.kt") - public void testStaticTraitProperty() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/staticTraitProperty.kt"); - doTest(fileName); - } - } + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/sealed") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Sealed extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInSealed() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/sealed"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } - @TestMetadata("compiler/testData/compileJavaAgainstKotlin/targets") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Targets extends AbstractCompileJavaAgainstKotlinTest { - public void testAllFilesPresentInTargets() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/targets"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + @TestMetadata("Derived.kt") + public void testDerived() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/sealed/Derived.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("Instance.kt") + public void testInstance() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/sealed/Instance.kt"); + doTestWithJavac(fileName); + } } - @TestMetadata("annotation.kt") - public void testAnnotation() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/annotation.kt"); - doTest(fileName); + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class StaticFields extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInStaticFields() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/staticFields"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("AnnotationClass.kt") + public void testAnnotationClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/AnnotationClass.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("AnnotationTrait.kt") + public void testAnnotationTrait() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/AnnotationTrait.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("kt3698.kt") + public void testKt3698() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/kt3698.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("staticClassProperty.kt") + public void testStaticClassProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/staticClassProperty.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("staticTraitProperty.kt") + public void testStaticTraitProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields/staticTraitProperty.kt"); + doTestWithJavac(fileName); + } } - @TestMetadata("base.kt") - public void testBase() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/base.kt"); - doTest(fileName); - } + @TestMetadata("compiler/testData/compileJavaAgainstKotlin/targets") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Targets extends AbstractCompileJavaAgainstKotlinTest { + public void testAllFilesPresentInTargets() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/targets"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } - @TestMetadata("classifier.kt") - public void testClassifier() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/classifier.kt"); - doTest(fileName); - } + @TestMetadata("annotation.kt") + public void testAnnotation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/annotation.kt"); + doTestWithJavac(fileName); + } - @TestMetadata("constructor.kt") - public void testConstructor() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/constructor.kt"); - doTest(fileName); - } + @TestMetadata("base.kt") + public void testBase() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/base.kt"); + doTestWithJavac(fileName); + } - @TestMetadata("empty.kt") - public void testEmpty() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/empty.kt"); - doTest(fileName); - } + @TestMetadata("classifier.kt") + public void testClassifier() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/classifier.kt"); + doTestWithJavac(fileName); + } - @TestMetadata("field.kt") - public void testField() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/field.kt"); - doTest(fileName); - } + @TestMetadata("constructor.kt") + public void testConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/constructor.kt"); + doTestWithJavac(fileName); + } - @TestMetadata("function.kt") - public void testFunction() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/function.kt"); - doTest(fileName); - } + @TestMetadata("empty.kt") + public void testEmpty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/empty.kt"); + doTestWithJavac(fileName); + } - @TestMetadata("getter.kt") - public void testGetter() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/getter.kt"); - doTest(fileName); - } + @TestMetadata("field.kt") + public void testField() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/field.kt"); + doTestWithJavac(fileName); + } - @TestMetadata("local.kt") - public void testLocal() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/local.kt"); - doTest(fileName); - } + @TestMetadata("function.kt") + public void testFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/function.kt"); + doTestWithJavac(fileName); + } - @TestMetadata("multiple.kt") - public void testMultiple() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/multiple.kt"); - doTest(fileName); - } + @TestMetadata("getter.kt") + public void testGetter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/getter.kt"); + doTestWithJavac(fileName); + } - @TestMetadata("parameter.kt") - public void testParameter() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/parameter.kt"); - doTest(fileName); - } + @TestMetadata("local.kt") + public void testLocal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/local.kt"); + doTestWithJavac(fileName); + } - @TestMetadata("property.kt") - public void testProperty() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/property.kt"); - doTest(fileName); - } + @TestMetadata("multiple.kt") + public void testMultiple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/multiple.kt"); + doTestWithJavac(fileName); + } - @TestMetadata("setter.kt") - public void testSetter() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/setter.kt"); - doTest(fileName); + @TestMetadata("parameter.kt") + public void testParameter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/parameter.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("property.kt") + public void testProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/property.kt"); + doTestWithJavac(fileName); + } + + @TestMetadata("setter.kt") + public void testSetter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/targets/setter.kt"); + doTestWithJavac(fileName); + } } } } diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstJavaTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstJavaTestGenerated.java new file mode 100644 index 00000000000..9bb6d2c69af --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstJavaTestGenerated.java @@ -0,0 +1,350 @@ +/* + * Copyright 2010-2017 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.jvm.compiler; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TargetBackend; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/testData/compileKotlinAgainstJava") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class CompileKotlinAgainstJavaTestGenerated extends AbstractCompileKotlinAgainstJavaTest { + @TestMetadata("AbstractClass.kt") + public void testAbstractClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/AbstractClass.kt"); + doTest(fileName); + } + + @TestMetadata("AbstractEnum.kt") + public void testAbstractEnum() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/AbstractEnum.kt"); + doTest(fileName); + } + + public void testAllFilesPresentInCompileKotlinAgainstJava() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileKotlinAgainstJava"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("AnnotationWithArguments.kt") + public void testAnnotationWithArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/AnnotationWithArguments.kt"); + doTest(fileName); + } + + @TestMetadata("AnnotationWithField.kt") + public void testAnnotationWithField() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/AnnotationWithField.kt"); + doTest(fileName); + } + + @TestMetadata("AsteriskInImport.kt") + public void testAsteriskInImport() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/AsteriskInImport.kt"); + doTest(fileName); + } + + @TestMetadata("CheckKotlinStub.kt") + public void testCheckKotlinStub() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/CheckKotlinStub.kt"); + doTest(fileName); + } + + @TestMetadata("CheckNotNull.kt") + public void testCheckNotNull() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/CheckNotNull.kt"); + doTest(fileName); + } + + @TestMetadata("Class.kt") + public void testClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/Class.kt"); + doTest(fileName); + } + + @TestMetadata("ClassWithNestedEnum.kt") + public void testClassWithNestedEnum() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/ClassWithNestedEnum.kt"); + doTest(fileName); + } + + @TestMetadata("ClassWithTypeParameter.kt") + public void testClassWithTypeParameter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/ClassWithTypeParameter.kt"); + doTest(fileName); + } + + @TestMetadata("CyclicDependencies.kt") + public void testCyclicDependencies() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/CyclicDependencies.kt"); + doTest(fileName); + } + + @TestMetadata("DefaultModifier.kt") + public void testDefaultModifier() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/DefaultModifier.kt"); + doTest(fileName); + } + + @TestMetadata("EnclosingClassInner.kt") + public void testEnclosingClassInner() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/EnclosingClassInner.kt"); + doTest(fileName); + } + + @TestMetadata("Enum.kt") + public void testEnum() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/Enum.kt"); + doTest(fileName); + } + + @TestMetadata("EnumName.kt") + public void testEnumName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/EnumName.kt"); + doTest(fileName); + } + + @TestMetadata("Inheritance.kt") + public void testInheritance() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/Inheritance.kt"); + doTest(fileName); + } + + @TestMetadata("InheritedInner.kt") + public void testInheritedInner() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/InheritedInner.kt"); + doTest(fileName); + } + + @TestMetadata("InnerCanonicalName.kt") + public void testInnerCanonicalName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/InnerCanonicalName.kt"); + doTest(fileName); + } + + @TestMetadata("InnerClass.kt") + public void testInnerClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/InnerClass.kt"); + doTest(fileName); + } + + @TestMetadata("InnerClassFromAsteriskImport.kt") + public void testInnerClassFromAsteriskImport() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/InnerClassFromAsteriskImport.kt"); + doTest(fileName); + } + + @TestMetadata("InnerClassFromImport.kt") + public void testInnerClassFromImport() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/InnerClassFromImport.kt"); + doTest(fileName); + } + + @TestMetadata("Interface.kt") + public void testInterface() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/Interface.kt"); + doTest(fileName); + } + + @TestMetadata("InterfaceField.kt") + public void testInterfaceField() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/InterfaceField.kt"); + doTest(fileName); + } + + @TestMetadata("InterfaceMemberClass.kt") + public void testInterfaceMemberClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/InterfaceMemberClass.kt"); + doTest(fileName); + } + + @TestMetadata("InterfaceWithDefault.kt") + public void testInterfaceWithDefault() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/InterfaceWithDefault.kt"); + doTest(fileName); + } + + @TestMetadata("ListImpl.kt") + public void testListImpl() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/ListImpl.kt"); + doTest(fileName); + } + + @TestMetadata("MapExample.kt") + public void testMapExample() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/MapExample.kt"); + doTest(fileName); + } + + @TestMetadata("Method.kt") + public void testMethod() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/Method.kt"); + doTest(fileName); + } + + @TestMetadata("MethodWithArgument.kt") + public void testMethodWithArgument() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/MethodWithArgument.kt"); + doTest(fileName); + } + + @TestMetadata("MethodWithSeveralTypeParameters.kt") + public void testMethodWithSeveralTypeParameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/MethodWithSeveralTypeParameters.kt"); + doTest(fileName); + } + + @TestMetadata("MethodWithTypeParameter.kt") + public void testMethodWithTypeParameter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/MethodWithTypeParameter.kt"); + doTest(fileName); + } + + @TestMetadata("MethodWithWildcard.kt") + public void testMethodWithWildcard() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/MethodWithWildcard.kt"); + doTest(fileName); + } + + @TestMetadata("Nesting.kt") + public void testNesting() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/Nesting.kt"); + doTest(fileName); + } + + @TestMetadata("RawReturnType.kt") + public void testRawReturnType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/RawReturnType.kt"); + doTest(fileName); + } + + @TestMetadata("ReturnEnum.kt") + public void testReturnEnum() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/ReturnEnum.kt"); + doTest(fileName); + } + + @TestMetadata("ReturnInnerClass.kt") + public void testReturnInnerClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/ReturnInnerClass.kt"); + doTest(fileName); + } + + @TestMetadata("ReturnInnerInInner.kt") + public void testReturnInnerInInner() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/ReturnInnerInInner.kt"); + doTest(fileName); + } + + @TestMetadata("ReturnInnerInner.kt") + public void testReturnInnerInner() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/ReturnInnerInner.kt"); + doTest(fileName); + } + + @TestMetadata("ReturnNested.kt") + public void testReturnNested() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/ReturnNested.kt"); + doTest(fileName); + } + + @TestMetadata("ReturnNestedFQ.kt") + public void testReturnNestedFQ() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/ReturnNestedFQ.kt"); + doTest(fileName); + } + + @TestMetadata("ReturnType.kt") + public void testReturnType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/ReturnType.kt"); + doTest(fileName); + } + + @TestMetadata("ReturnTypeResolution.kt") + public void testReturnTypeResolution() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/ReturnTypeResolution.kt"); + doTest(fileName); + } + + @TestMetadata("SeveralInnerClasses.kt") + public void testSeveralInnerClasses() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/SeveralInnerClasses.kt"); + doTest(fileName); + } + + @TestMetadata("SimpleAnnotation.kt") + public void testSimpleAnnotation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/SimpleAnnotation.kt"); + doTest(fileName); + } + + @TestMetadata("SimpleWildcard.kt") + public void testSimpleWildcard() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/SimpleWildcard.kt"); + doTest(fileName); + } + + @TestMetadata("Singleton.kt") + public void testSingleton() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/Singleton.kt"); + doTest(fileName); + } + + @TestMetadata("StaticNestedClass.kt") + public void testStaticNestedClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/StaticNestedClass.kt"); + doTest(fileName); + } + + @TestMetadata("TypeArgumentInSuperType.kt") + public void testTypeArgumentInSuperType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/TypeArgumentInSuperType.kt"); + doTest(fileName); + } + + @TestMetadata("TypeParameter.kt") + public void testTypeParameter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/TypeParameter.kt"); + doTest(fileName); + } + + @TestMetadata("UseKotlinInner.kt") + public void testUseKotlinInner() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/UseKotlinInner.kt"); + doTest(fileName); + } + + @TestMetadata("UseKtClass.kt") + public void testUseKtClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/UseKtClass.kt"); + doTest(fileName); + } + + @TestMetadata("Vararg.kt") + public void testVararg() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstJava/Vararg.kt"); + doTest(fileName); + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/KotlinJavacBasedClassFinderTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/KotlinJavacBasedClassFinderTest.kt new file mode 100644 index 00000000000..51e0eb45770 --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/KotlinJavacBasedClassFinderTest.kt @@ -0,0 +1,101 @@ +/* + * Copyright 2010-2017 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.jvm.compiler + +import com.intellij.openapi.project.Project +import com.intellij.psi.search.GlobalSearchScope +import org.jetbrains.kotlin.javac.JavacWrapper +import org.jetbrains.kotlin.javac.components.JavacBasedClassFinder +import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil +import org.jetbrains.kotlin.test.ConfigurationKind +import org.jetbrains.kotlin.test.KotlinTestUtils +import org.jetbrains.kotlin.test.KotlinTestWithEnvironmentManagement +import org.jetbrains.kotlin.test.TestJdkKind +import java.io.File +import kotlin.test.assertNotNull +import kotlin.test.assertNull + +class KotlinJavacBasedClassFinderTest : KotlinTestWithEnvironmentManagement() { + fun testAbsentClass() { + val tmpdir = KotlinTestUtils.tmpDirForTest(this) + + val environment = createEnvironment(tmpdir) + val project = environment.project + + val classFinder = createClassFinder(project) + + val className = "test.A.B.D" + + val found = classFinder.findClass(ClassId.topLevel(FqName(className))) + assertNull(found, "Class is expected to be null, there should be no exceptions too.") + } + + fun testNestedClass() { + val tmpdir = KotlinTestUtils.tmpDirForTest(this) + KotlinTestUtils.compileKotlinWithJava( + listOf(), listOf(File("compiler/testData/kotlinClassFinder/nestedClass.kt")), tmpdir, testRootDisposable, null + ) + + val environment = createEnvironment(tmpdir) + val project = environment.project + + val classFinder = createClassFinder(project) + + val className = "test.A.B.C" + val classId = ClassId(FqName("test"), FqName("A.B.C"), false) + val found = classFinder.findClass(classId) + assertNotNull(found, "Class not found for $className") + + val binaryClass = VirtualFileFinder.SERVICE.getInstance(project).findKotlinClass(found!!) + assertNotNull(binaryClass, "No binary class for $className") + + assertEquals("test/A.B.C", binaryClass?.classId?.toString()) + } + + private fun createClassFinder(project: Project) = JavacBasedClassFinder().apply { + this::class.java.superclass.getDeclaredField("project")?.let { + it.isAccessible = true + it.set(this, project) + } + setScope(GlobalSearchScope.allScope(project)) + + val javacField = this::class.java.getDeclaredField("javac") + javacField.isAccessible = true + javacField.set(this, JavacWrapper.getInstance(project)) + + val javaSearchScopeField = this::class.java.superclass.getDeclaredField("javaSearchScope") + javaSearchScopeField.isAccessible = true + javaSearchScopeField.set(this, GlobalSearchScope.allScope(project)) + } + + private fun createEnvironment(tmpdir: File?, files: List = emptyList()): KotlinCoreEnvironment { + return KotlinCoreEnvironment.createForTests( + testRootDisposable, + KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, tmpdir), + EnvironmentConfigFiles.JVM_CONFIG_FILES + ).apply { + registerJavac(files) + // Activate Kotlin light class finder + JvmResolveUtil.analyze(this) + } + } +} diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index b89a281fea6..5e7cc69bc4d 100755 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -345,7 +345,12 @@ fun main(args: Array) { } testClass { - model("compileJavaAgainstKotlin") + model("compileJavaAgainstKotlin", testClassName = "WithoutJavac", testMethod = "doTestWithoutJavac") + model("compileJavaAgainstKotlin", testClassName = "WithJavac", testMethod = "doTestWithJavac") + } + + testClass { + model("compileKotlinAgainstJava") } testClass {