Move everything under kotlin-native folder
I was forced to manually do update the following files, because otherwise they would be ignored according .gitignore settings. Probably they should be deleted from repo. Interop/.idea/compiler.xml Interop/.idea/gradle.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml Interop/.idea/modules.xml Interop/.idea/modules/Indexer/Indexer.iml Interop/.idea/modules/Runtime/Runtime.iml Interop/.idea/modules/StubGenerator/StubGenerator.iml backend.native/backend.native.iml backend.native/bc.frontend/bc.frontend.iml backend.native/cli.bc/cli.bc.iml backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt backend.native/tests/link/lib/foo.kt backend.native/tests/link/lib/foo2.kt backend.native/tests/teamcity-test.property
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
package org.jetbrains.kotlin.cli.klib
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
|
||||
interface DeclarationHeaderRenderer {
|
||||
fun render(descriptor: DeclarationDescriptor): String
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
package org.jetbrains.kotlin.cli.klib
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getPackageFragments
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
class DeclarationPrinter(
|
||||
out: Appendable,
|
||||
private val headerRenderer: DeclarationHeaderRenderer,
|
||||
private val signatureRenderer: IdSignatureRenderer
|
||||
) {
|
||||
private val printer = Printer(out, 1, " ")
|
||||
|
||||
private val DeclarationDescriptorWithVisibility.isPublicOrProtected: Boolean
|
||||
get() = visibility == DescriptorVisibilities.PUBLIC || visibility == DescriptorVisibilities.PROTECTED
|
||||
|
||||
private val CallableMemberDescriptor.isFakeOverride: Boolean
|
||||
get() = kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE
|
||||
|
||||
private val DeclarationDescriptor.shouldBePrinted: Boolean
|
||||
get() = this is ClassifierDescriptorWithTypeParameters && isPublicOrProtected
|
||||
|| this is CallableMemberDescriptor && isPublicOrProtected && !isFakeOverride
|
||||
|
||||
fun print(module: ModuleDescriptor) {
|
||||
module.accept(PrinterVisitor(), Unit)
|
||||
}
|
||||
|
||||
private fun Printer.printWithBody(header: String, signature: String? = null, body: () -> Unit) {
|
||||
println()
|
||||
printPlain(header, signature, suffix = " {")
|
||||
pushIndent()
|
||||
body()
|
||||
popIndent()
|
||||
println("}")
|
||||
println()
|
||||
}
|
||||
|
||||
private fun Printer.printPlain(header: String, signature: String? = null, suffix: String? = null) {
|
||||
if (signature != null) println(signature)
|
||||
println(if (suffix != null ) header + suffix else header)
|
||||
}
|
||||
|
||||
private inner class PrinterVisitor : DeclarationDescriptorVisitorEmptyBodies<Unit, Unit>() {
|
||||
override fun visitModuleDeclaration(descriptor: ModuleDescriptor, data: Unit) {
|
||||
descriptor.getPackageFragments().forEach { it.accept(this, data) }
|
||||
}
|
||||
|
||||
override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor, data: Unit) {
|
||||
val children = descriptor.getMemberScope().getContributedDescriptors().filter { it.shouldBePrinted }
|
||||
if (children.isNotEmpty()) {
|
||||
printer.printWithBody(header = headerRenderer.render(descriptor)) {
|
||||
children.forEach { it.accept(this, data) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitClassDescriptor(descriptor: ClassDescriptor, data: Unit) {
|
||||
val header = headerRenderer.render(descriptor)
|
||||
val signature = signatureRenderer.render(descriptor)
|
||||
|
||||
val children = descriptor.unsubstitutedMemberScope.getContributedDescriptors().filter { it.shouldBePrinted }
|
||||
val constructors = descriptor.constructors.filter { !it.isPrimary && it.shouldBePrinted }
|
||||
if (children.isNotEmpty() || constructors.isNotEmpty()) {
|
||||
printer.printWithBody(header, signature) {
|
||||
constructors.forEach { it.accept(this, data) }
|
||||
children.forEach { it.accept(this, data) }
|
||||
}
|
||||
} else {
|
||||
printer.printPlain(header, signature)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, data: Unit) {
|
||||
printer.printPlain(header = headerRenderer.render(descriptor), signature = signatureRenderer.render(descriptor))
|
||||
}
|
||||
|
||||
override fun visitPropertyDescriptor(descriptor: PropertyDescriptor, data: Unit) {
|
||||
printer.printPlain(header = headerRenderer.render(descriptor), signature = signatureRenderer.render(descriptor))
|
||||
descriptor.getter?.takeIf { !it.annotations.isEmpty() }?.let { getter ->
|
||||
printer.pushIndent()
|
||||
printer.printPlain(header = headerRenderer.render(getter), signature = signatureRenderer.render(getter))
|
||||
printer.popIndent()
|
||||
}
|
||||
descriptor.setter?.takeIf { !it.annotations.isEmpty() || it.visibility != descriptor.visibility }?.let { setter ->
|
||||
printer.pushIndent()
|
||||
printer.printPlain(header = headerRenderer.render(setter), signature = signatureRenderer.render(setter))
|
||||
printer.popIndent()
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor, data: Unit) {
|
||||
printer.printPlain(header = headerRenderer.render(descriptor), signature = signatureRenderer.render(descriptor))
|
||||
}
|
||||
|
||||
override fun visitTypeAliasDescriptor(descriptor: TypeAliasDescriptor, data: Unit) {
|
||||
printer.printPlain(header = headerRenderer.render(descriptor), signature = signatureRenderer.render(descriptor))
|
||||
}
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package org.jetbrains.kotlin.cli.klib
|
||||
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.renderer.AnnotationArgumentsRenderingPolicy
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
|
||||
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy
|
||||
|
||||
object DefaultDeclarationHeaderRenderer : DeclarationHeaderRenderer {
|
||||
override fun render(descriptor: DeclarationDescriptor): String = when (descriptor) {
|
||||
is PackageFragmentDescriptor -> render(descriptor)
|
||||
is ClassifierDescriptorWithTypeParameters -> render(descriptor)
|
||||
is PropertyAccessorDescriptor -> render(descriptor)
|
||||
is CallableMemberDescriptor -> render(descriptor)
|
||||
else -> throw AssertionError("Unknown declaration descriptor type: $descriptor")
|
||||
}
|
||||
|
||||
private fun render(descriptor: PackageFragmentDescriptor): String {
|
||||
val packageName = descriptor.fqName.let { if (it.isRoot) "<root>" else it.asString() }
|
||||
return "package $packageName"
|
||||
}
|
||||
|
||||
private fun render(descriptor: ClassifierDescriptorWithTypeParameters): String {
|
||||
val renderer = when (descriptor.modality) {
|
||||
// Don't render 'final' modality
|
||||
Modality.FINAL -> Renderers.WITHOUT_MODALITY
|
||||
else -> Renderers.DEFAULT
|
||||
}
|
||||
return renderer.render(descriptor)
|
||||
}
|
||||
|
||||
private fun render(descriptor: CallableMemberDescriptor): String {
|
||||
val containingDeclaration = descriptor.containingDeclaration
|
||||
val renderer = when {
|
||||
// Don't render modality for non-override final methods and interface methods.
|
||||
containingDeclaration is ClassDescriptor && containingDeclaration.kind == ClassKind.INTERFACE ||
|
||||
descriptor.modality == Modality.FINAL && descriptor.overriddenDescriptors.isEmpty() -> Renderers.WITHOUT_MODALITY
|
||||
else -> Renderers.DEFAULT
|
||||
}
|
||||
return renderer.render(descriptor)
|
||||
}
|
||||
|
||||
private fun render(descriptor: PropertyAccessorDescriptor) = buildString {
|
||||
descriptor.annotations.forEach {
|
||||
append(Renderers.DEFAULT.renderAnnotation(it)).append(" ")
|
||||
}
|
||||
if (descriptor.visibility != DescriptorVisibilities.DEFAULT_VISIBILITY) {
|
||||
append(descriptor.visibility.internalDisplayName).append(" ")
|
||||
}
|
||||
when (descriptor) {
|
||||
is PropertyGetterDescriptor -> append("get")
|
||||
is PropertySetterDescriptor -> append("set")
|
||||
else -> throw AssertionError("Unknown accessor descriptor type: $descriptor")
|
||||
}
|
||||
}
|
||||
|
||||
private object Renderers {
|
||||
val DEFAULT = DescriptorRenderer.COMPACT_WITH_SHORT_TYPES.withOptions {
|
||||
modifiers = DescriptorRendererModifier.ALL
|
||||
overrideRenderingPolicy = OverrideRenderingPolicy.RENDER_OVERRIDE
|
||||
annotationArgumentsRenderingPolicy = AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY
|
||||
excludedAnnotationClasses += StandardNames.FqNames.suppress
|
||||
|
||||
classWithPrimaryConstructor = true
|
||||
renderConstructorKeyword = true
|
||||
includePropertyConstant = true
|
||||
|
||||
unitReturnType = false
|
||||
withDefinedIn = false
|
||||
renderDefaultVisibility = false
|
||||
secondaryConstructorsAsPrimary = false
|
||||
}
|
||||
|
||||
val WITHOUT_MODALITY = DEFAULT.withOptions {
|
||||
modifiers -= DescriptorRendererModifier.MODALITY
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package org.jetbrains.kotlin.cli.klib
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.serialization.KonanIdSignaturer
|
||||
import org.jetbrains.kotlin.backend.konan.serialization.KonanManglerDesc
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
|
||||
class DefaultIdSignatureRenderer(private val prefix: String? = null) : IdSignatureRenderer {
|
||||
private val idSignaturer = KonanIdSignaturer(KonanManglerDesc)
|
||||
|
||||
override fun render(descriptor: DeclarationDescriptor): String? {
|
||||
val idSignature = if (descriptor is ClassDescriptor && descriptor.kind == ClassKind.ENUM_ENTRY) {
|
||||
idSignaturer.composeEnumEntrySignature(descriptor)
|
||||
} else {
|
||||
idSignaturer.composeSignature(descriptor)
|
||||
} ?: return null
|
||||
|
||||
return if (prefix != null)
|
||||
prefix + idSignature.render()
|
||||
else
|
||||
idSignature.render()
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package org.jetbrains.kotlin.cli.klib
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
|
||||
interface IdSignatureRenderer {
|
||||
fun render(descriptor: DeclarationDescriptor): String?
|
||||
|
||||
companion object {
|
||||
val NO_SIGNATURE = object : IdSignatureRenderer {
|
||||
override fun render(descriptor: DeclarationDescriptor): String? = null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.jetbrains.kotlin.cli.klib
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getPackageFragments
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
class SignaturePrinter(
|
||||
out: Appendable,
|
||||
private val signatureRenderer: IdSignatureRenderer
|
||||
) {
|
||||
private val printer = Printer(out)
|
||||
|
||||
fun print(module: ModuleDescriptor) {
|
||||
module.accept(PrinterVisitor(), Unit)
|
||||
}
|
||||
|
||||
private fun Printer.printlnIfNotNull(line: String?) {
|
||||
if (line != null) println(line)
|
||||
}
|
||||
|
||||
private inner class PrinterVisitor : DeclarationDescriptorVisitorEmptyBodies<Unit, Unit>() {
|
||||
override fun visitModuleDeclaration(descriptor: ModuleDescriptor, data: Unit) {
|
||||
descriptor.getPackageFragments().forEach { it.accept(this, data) }
|
||||
}
|
||||
|
||||
override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor, data: Unit) {
|
||||
descriptor.getMemberScope().getContributedDescriptors().forEach { it.accept(this, data) }
|
||||
}
|
||||
|
||||
override fun visitClassDescriptor(descriptor: ClassDescriptor, data: Unit) {
|
||||
printer.printlnIfNotNull(signatureRenderer.render(descriptor))
|
||||
descriptor.constructors.forEach { it.accept(this, data) }
|
||||
descriptor.unsubstitutedMemberScope.getContributedDescriptors().forEach { it.accept(this, data) }
|
||||
}
|
||||
|
||||
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, data: Unit) {
|
||||
printer.printlnIfNotNull(signatureRenderer.render(descriptor))
|
||||
}
|
||||
|
||||
override fun visitPropertyDescriptor(descriptor: PropertyDescriptor, data: Unit) {
|
||||
printer.printlnIfNotNull(signatureRenderer.render(descriptor))
|
||||
descriptor.getter?.let { printer.printlnIfNotNull(signatureRenderer.render(it)) }
|
||||
descriptor.setter?.let { printer.printlnIfNotNull(signatureRenderer.render(it)) }
|
||||
}
|
||||
|
||||
override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor, data: Unit) {
|
||||
printer.printlnIfNotNull(signatureRenderer.render(descriptor))
|
||||
}
|
||||
|
||||
override fun visitTypeAliasDescriptor(descriptor: TypeAliasDescriptor, data: Unit) {
|
||||
printer.printlnIfNotNull(signatureRenderer.render(descriptor))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.klib
|
||||
|
||||
// TODO: Extract `library` package as a shared jar?
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.library.KLIB_FILE_EXTENSION_WITH_DOT
|
||||
import org.jetbrains.kotlin.konan.target.Distribution
|
||||
import org.jetbrains.kotlin.konan.target.PlatformManager
|
||||
import org.jetbrains.kotlin.konan.util.DependencyProcessor
|
||||
import org.jetbrains.kotlin.library.unpackZippedKonanLibraryTo
|
||||
import org.jetbrains.kotlin.konan.util.KlibMetadataFactories
|
||||
import org.jetbrains.kotlin.backend.common.serialization.metadata.DynamicTypeDeserializer
|
||||
import org.jetbrains.kotlin.descriptors.konan.isNativeStdlib
|
||||
import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.deserialization.PlatformDependentTypeTransformer
|
||||
import org.jetbrains.kotlin.util.Logger
|
||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf
|
||||
import org.jetbrains.kotlin.konan.library.KonanLibrary
|
||||
import org.jetbrains.kotlin.konan.library.resolverByName
|
||||
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
||||
import org.jetbrains.kotlin.library.metadata.parseModuleHeader
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
internal val KlibFactories = KlibMetadataFactories(::KonanBuiltIns, DynamicTypeDeserializer, PlatformDependentTypeTransformer.None)
|
||||
|
||||
fun printUsage() {
|
||||
println("Usage: klib <command> <library> <options>")
|
||||
println("where the commands are:")
|
||||
println("\tinfo\tgeneral information about the library")
|
||||
println("\tinstall\tinstall the library to the local repository")
|
||||
println("\tcontents\tlist contents of the library")
|
||||
println("\tsignatures\tlist of ID signatures in the library")
|
||||
println("\tremove\tremove the library from the local repository")
|
||||
println("and the options are:")
|
||||
println("\t-repository <path>\twork with the specified repository")
|
||||
println("\t-target <name>\tinspect specifics of the given target")
|
||||
println("\t-print-signatures [true|false]\tprint ID signature for every declaration (only for \"contents\" command)")
|
||||
}
|
||||
|
||||
private fun parseArgs(args: Array<String>): Map<String, List<String>> {
|
||||
val commandLine = mutableMapOf<String, MutableList<String>>()
|
||||
for (index in args.indices step 2) {
|
||||
val key = args[index]
|
||||
if (key[0] != '-') {
|
||||
throw IllegalArgumentException("Expected a flag with initial dash: $key")
|
||||
}
|
||||
if (index + 1 == args.size) {
|
||||
throw IllegalArgumentException("Expected an value after $key")
|
||||
}
|
||||
val value = listOf(args[index + 1])
|
||||
commandLine[key]?.addAll(value) ?: commandLine.put(key, value.toMutableList())
|
||||
}
|
||||
return commandLine
|
||||
}
|
||||
|
||||
|
||||
class Command(args: Array<String>) {
|
||||
init {
|
||||
if (args.size < 2) {
|
||||
printUsage()
|
||||
exitProcess(0)
|
||||
}
|
||||
}
|
||||
|
||||
val verb = args[0]
|
||||
val library = args[1]
|
||||
val options = parseArgs(args.drop(2).toTypedArray())
|
||||
}
|
||||
|
||||
fun warn(text: String) {
|
||||
println("warning: $text")
|
||||
}
|
||||
|
||||
fun error(text: String): Nothing {
|
||||
kotlin.error("error: $text")
|
||||
}
|
||||
|
||||
object KlibToolLogger : Logger {
|
||||
override fun warning(message: String) = org.jetbrains.kotlin.cli.klib.warn(message)
|
||||
override fun error(message: String) = org.jetbrains.kotlin.cli.klib.warn(message)
|
||||
override fun fatal(message: String) = org.jetbrains.kotlin.cli.klib.error(message)
|
||||
override fun log(message: String) = println(message)
|
||||
}
|
||||
|
||||
val defaultRepository = File(DependencyProcessor.localKonanDir.resolve("klib").absolutePath)
|
||||
|
||||
open class ModuleDeserializer(val library: ByteArray) {
|
||||
protected val moduleHeader: KlibMetadataProtoBuf.Header
|
||||
get() = parseModuleHeader(library)
|
||||
|
||||
val moduleName: String
|
||||
get() = moduleHeader.moduleName
|
||||
|
||||
val packageFragmentNameList: List<String>
|
||||
get() = moduleHeader.packageFragmentNameList
|
||||
|
||||
}
|
||||
|
||||
class Library(val name: String, val requestedRepository: String?, val target: String) {
|
||||
|
||||
val repository = requestedRepository?.File() ?: defaultRepository
|
||||
fun info() {
|
||||
val library = libraryInRepoOrCurrentDir(repository, name)
|
||||
val headerAbiVersion = library.versions.abiVersion
|
||||
val headerCompilerVersion = library.versions.compilerVersion
|
||||
val headerLibraryVersion = library.versions.libraryVersion
|
||||
val headerMetadataVersion = library.versions.metadataVersion
|
||||
val headerIrVersion = library.versions.irVersion
|
||||
val moduleName = ModuleDeserializer(library.moduleHeaderData).moduleName
|
||||
|
||||
println("")
|
||||
println("Resolved to: ${library.libraryName.File().absolutePath}")
|
||||
println("Module name: $moduleName")
|
||||
println("ABI version: $headerAbiVersion")
|
||||
println("Compiler version: ${headerCompilerVersion}")
|
||||
println("Library version: $headerLibraryVersion")
|
||||
println("Metadata version: $headerMetadataVersion")
|
||||
println("IR version: $headerIrVersion")
|
||||
|
||||
if (library is KonanLibrary) {
|
||||
val targets = library.targetList.joinToString(", ")
|
||||
print("Available targets: $targets\n")
|
||||
}
|
||||
}
|
||||
|
||||
fun install() {
|
||||
if (!repository.exists) {
|
||||
warn("Repository does not exist: $repository. Creating.")
|
||||
repository.mkdirs()
|
||||
}
|
||||
|
||||
Library(File(name).name.removeSuffix(KLIB_FILE_EXTENSION_WITH_DOT), requestedRepository, target).remove(true)
|
||||
|
||||
val library = libraryInCurrentDir(name)
|
||||
val newLibDir = File(repository, library.libraryFile.name.removeSuffix(KLIB_FILE_EXTENSION_WITH_DOT))
|
||||
|
||||
library.libraryFile.unpackZippedKonanLibraryTo(newLibDir)
|
||||
}
|
||||
|
||||
fun remove(blind: Boolean = false) {
|
||||
if (!repository.exists) error("Repository does not exist: $repository")
|
||||
|
||||
val library = try {
|
||||
val library = libraryInRepo(repository, name)
|
||||
if (blind) warn("Removing The previously installed $name from $repository.")
|
||||
library
|
||||
|
||||
} catch (e: Throwable) {
|
||||
if (!blind) println(e.message)
|
||||
null
|
||||
|
||||
}
|
||||
library?.libraryFile?.deleteRecursively()
|
||||
}
|
||||
|
||||
fun contents(output: Appendable, printSignatures: Boolean) {
|
||||
val module = loadModule()
|
||||
val signatureRenderer = if (printSignatures) DefaultIdSignatureRenderer("// ID signature: ") else IdSignatureRenderer.NO_SIGNATURE
|
||||
val printer = DeclarationPrinter(output, DefaultDeclarationHeaderRenderer, signatureRenderer)
|
||||
|
||||
printer.print(module)
|
||||
}
|
||||
|
||||
fun signatures(output: Appendable) {
|
||||
val module = loadModule()
|
||||
val printer = SignaturePrinter(output, DefaultIdSignatureRenderer())
|
||||
|
||||
printer.print(module)
|
||||
}
|
||||
|
||||
private fun loadModule(): ModuleDescriptor {
|
||||
val storageManager = LockBasedStorageManager("klib")
|
||||
val library = libraryInRepoOrCurrentDir(repository, name)
|
||||
val versionSpec = LanguageVersionSettingsImpl(currentLanguageVersion, currentApiVersion)
|
||||
val module = KlibFactories.DefaultDeserializedDescriptorFactory.createDescriptorAndNewBuiltIns(library, versionSpec, storageManager, null)
|
||||
|
||||
val defaultModules = mutableListOf<ModuleDescriptorImpl>()
|
||||
if (!module.isNativeStdlib()) {
|
||||
val resolver = resolverByName(
|
||||
emptyList(),
|
||||
distributionKlib = Distribution(KonanHomeProvider.determineKonanHome()).klib,
|
||||
skipCurrentDir = true,
|
||||
logger = KlibToolLogger
|
||||
)
|
||||
resolver.defaultLinks(false, true, true).mapTo(defaultModules) {
|
||||
KlibFactories.DefaultDeserializedDescriptorFactory.createDescriptor(it, versionSpec, storageManager, module.builtIns, null)
|
||||
}
|
||||
}
|
||||
|
||||
(defaultModules + module).let { allModules ->
|
||||
allModules.forEach { it.setDependencies(allModules) }
|
||||
}
|
||||
|
||||
return module
|
||||
}
|
||||
}
|
||||
|
||||
val currentLanguageVersion = LanguageVersion.LATEST_STABLE
|
||||
val currentApiVersion = ApiVersion.LATEST_STABLE
|
||||
|
||||
fun libraryInRepo(repository: File, name: String) =
|
||||
resolverByName(listOf(repository.absolutePath), skipCurrentDir = true, logger = KlibToolLogger).resolve(name)
|
||||
|
||||
fun libraryInCurrentDir(name: String) = resolverByName(emptyList(), logger = KlibToolLogger).resolve(name)
|
||||
|
||||
fun libraryInRepoOrCurrentDir(repository: File, name: String) =
|
||||
resolverByName(listOf(repository.absolutePath), logger = KlibToolLogger).resolve(name)
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val command = Command(args)
|
||||
|
||||
val targetManager = PlatformManager(KonanHomeProvider.determineKonanHome())
|
||||
.targetManager(command.options["-target"]?.last())
|
||||
val target = targetManager.targetName
|
||||
|
||||
val repository = command.options["-repository"]?.last()
|
||||
val printSignatures = command.options["-print-signatures"]?.last()?.toBoolean() == true
|
||||
|
||||
val library = Library(command.library, repository, target)
|
||||
|
||||
when (command.verb) {
|
||||
"contents" -> library.contents(System.out, printSignatures)
|
||||
"signatures" -> library.signatures(System.out)
|
||||
"info" -> library.info()
|
||||
"install" -> library.install()
|
||||
"remove" -> library.remove()
|
||||
else -> error("Unknown command ${command.verb}.")
|
||||
}
|
||||
}
|
||||
|
||||
+363
@@ -0,0 +1,363 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.klib.test
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import kotlin.test.*
|
||||
import org.jetbrains.kotlin.cli.klib.*
|
||||
import org.jetbrains.kotlin.konan.target.Distribution
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import java.nio.file.Paths
|
||||
|
||||
class ContentsTest {
|
||||
|
||||
private fun testLibrary(name: String) = LIBRARY_DIRECTORY.resolve("$name.klib").toFile().absolutePath
|
||||
|
||||
private fun klibContents(library: String, printOutput: Boolean = false, expected: () -> String) {
|
||||
val output = StringBuilder()
|
||||
val lib = Library(library, null, "host")
|
||||
lib.contents(output, false)
|
||||
if (printOutput) {
|
||||
println(output.trim().toString())
|
||||
}
|
||||
assertEquals(
|
||||
StringUtil.convertLineSeparators(expected()),
|
||||
StringUtil.convertLineSeparators(output.trim().toString()),
|
||||
"klib contents test failed for library: $library"
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Stdlib content should be printed without exceptions`() {
|
||||
val output = StringBuilder()
|
||||
val distributionPath = System.getProperty("konan.home")
|
||||
Library(Distribution(distributionPath).stdlib, null, "host").contents(output, false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun topLevelFunctions() = klibContents(testLibrary("TopLevelFunctions")) {
|
||||
"""
|
||||
package <root> {
|
||||
annotation class A constructor() : Annotation
|
||||
annotation class B constructor() : Annotation
|
||||
class Foo constructor()
|
||||
}
|
||||
|
||||
package <root> {
|
||||
@A @B fun a()
|
||||
fun f1(x: Foo)
|
||||
fun f2(x: Foo, y: Foo): Int
|
||||
inline fun i1(block: () -> Foo)
|
||||
inline fun i2(noinline block: () -> Foo)
|
||||
inline fun i3(crossinline block: () -> Foo)
|
||||
fun i4(block: (Foo) -> Int)
|
||||
fun i5(block: (Foo, Foo) -> Int)
|
||||
fun i6(block: Foo.() -> Int)
|
||||
fun i7(block: Foo.(Foo) -> Int)
|
||||
fun <T> t1(x: Foo)
|
||||
fun <T> t2(x: T)
|
||||
fun <T, F> t3(x: T, y: F)
|
||||
inline fun <reified T> t4(x: T)
|
||||
fun <T : Number> t5(x: T)
|
||||
fun Foo.e()
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun constructors() = klibContents(testLibrary("Constructors")) {
|
||||
"""
|
||||
package <root> {
|
||||
annotation class A constructor() : Annotation
|
||||
class Bar @A constructor(x: Int)
|
||||
class Baz private constructor(x: Int)
|
||||
|
||||
class Foo constructor(x: Int) {
|
||||
constructor()
|
||||
constructor(x: Double)
|
||||
constructor(x: Double, y: Int)
|
||||
protected constructor(x: String)
|
||||
@A constructor(x: Foo)
|
||||
}
|
||||
|
||||
class Qux protected constructor(x: Int)
|
||||
|
||||
class Typed<T> constructor(x: Int) {
|
||||
constructor()
|
||||
constructor(x: Double)
|
||||
constructor(x: Double, y: Int)
|
||||
protected constructor(x: String)
|
||||
@A constructor(x: Foo)
|
||||
}
|
||||
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun objects() = klibContents(testLibrary("Objects")) {
|
||||
"""
|
||||
package <root> {
|
||||
|
||||
object A {
|
||||
fun a()
|
||||
}
|
||||
|
||||
class B constructor() {
|
||||
|
||||
object C {
|
||||
fun c()
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun b()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class D constructor() {
|
||||
|
||||
companion object E {
|
||||
fun e()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun classes() = klibContents(testLibrary("Classes")) {
|
||||
"""
|
||||
package <root> {
|
||||
|
||||
class A constructor() {
|
||||
val aVal: Int = 0
|
||||
var aVar: String
|
||||
fun aFun()
|
||||
|
||||
inner class B constructor() {
|
||||
val bVal: Int = 0
|
||||
var bVar: String
|
||||
fun bFun()
|
||||
|
||||
inner class C constructor() {
|
||||
val cVal: Int = 0
|
||||
var cVar: String
|
||||
fun cFun()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class E constructor() {
|
||||
val eVal: Int = 0
|
||||
var eVar: String
|
||||
fun eFun()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class F constructor(fVal: Int, fVar: String) {
|
||||
val fVal: Int
|
||||
var fVar: String
|
||||
operator fun component1(): Int
|
||||
operator fun component2(): String
|
||||
fun copy(fVal: Int = ..., fVar: String = ...): F
|
||||
override fun equals(other: Any?): Boolean
|
||||
fun fFun()
|
||||
override fun hashCode(): Int
|
||||
override fun toString(): String
|
||||
}
|
||||
|
||||
class FinalImpl constructor() : OpenImpl {
|
||||
override val iVal: Int = 0
|
||||
override var iVar: String
|
||||
override fun iFun()
|
||||
}
|
||||
|
||||
interface Interface {
|
||||
val iVal: Int
|
||||
var iVar: String
|
||||
fun iFun()
|
||||
}
|
||||
|
||||
open class OpenImpl constructor() : Interface {
|
||||
override val iVal: Int = 0
|
||||
override var iVar: String
|
||||
override fun iFun()
|
||||
}
|
||||
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun methodModality() = klibContents(testLibrary("MethodModality")) {
|
||||
"""
|
||||
package <root> {
|
||||
|
||||
abstract class AbstractClass constructor() : Interface {
|
||||
abstract fun abstractFun()
|
||||
override fun interfaceFun()
|
||||
}
|
||||
|
||||
class FinalClass constructor() : OpenClass {
|
||||
override fun openFun1()
|
||||
final override fun openFun2()
|
||||
}
|
||||
|
||||
interface Interface {
|
||||
fun interfaceFun()
|
||||
}
|
||||
|
||||
open class OpenClass constructor() : AbstractClass {
|
||||
override fun abstractFun()
|
||||
fun finalFun()
|
||||
open fun openFun1()
|
||||
open fun openFun2()
|
||||
}
|
||||
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun functionModifiers() = klibContents(testLibrary("FunctionModifiers")) {
|
||||
"""
|
||||
package <root> {
|
||||
|
||||
class Foo constructor() {
|
||||
fun f1()
|
||||
infix fun f2(x: Int)
|
||||
suspend fun f3()
|
||||
tailrec fun f4()
|
||||
fun f5(vararg x: Int)
|
||||
operator fun plus(x: Int)
|
||||
}
|
||||
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@Test
|
||||
// TODO: Support enum entry methods in serialization/deserialization.
|
||||
fun enum() = klibContents(testLibrary("Enum")) {
|
||||
"""
|
||||
package <root> {
|
||||
|
||||
enum class E private constructor(x: Int = ...) : Enum<E> {
|
||||
enum entry A
|
||||
enum entry B
|
||||
enum entry C
|
||||
val enumVal: Int = 0
|
||||
var enumVar: String
|
||||
val x: Int
|
||||
open fun enumFun(): Int
|
||||
}
|
||||
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@Test
|
||||
// TODO: Support getter/setter annotations in serialization/deserialization.
|
||||
fun accessors() = klibContents(testLibrary("Accessors")) {
|
||||
"""
|
||||
package custom.pkg {
|
||||
annotation class A constructor() : Annotation
|
||||
|
||||
class Foo constructor() {
|
||||
@A val annotated: Int = 0
|
||||
var annotatedAccessors: Int
|
||||
@A get
|
||||
@A set
|
||||
val annotatedGetter: Int = 0
|
||||
@A get
|
||||
var annotatedSetter: Int
|
||||
@A set
|
||||
var privateSetter: Int
|
||||
private set
|
||||
protected val protectedSimple: Int = 0
|
||||
val simple: Int = 0
|
||||
}
|
||||
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun topLevelPropertiesCustomPackage() = klibContents(testLibrary("TopLevelPropertiesCustomPackage")) {
|
||||
"""
|
||||
package custom.pkg {
|
||||
typealias MyTransformer = (String) -> Int
|
||||
}
|
||||
|
||||
package custom.pkg {
|
||||
val v1: Int = 1
|
||||
val v2: String = "hello"
|
||||
val v3: (String) -> Int
|
||||
val v4: MyTransformer /* = (String) -> Int */
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun topLevelPropertiesRootPackage() = klibContents(testLibrary("TopLevelPropertiesRootPackage")) {
|
||||
"""
|
||||
package <root> {
|
||||
typealias MyTransformer = (String) -> Int
|
||||
}
|
||||
|
||||
package <root> {
|
||||
val v1: Int = 1
|
||||
val v2: String = "hello"
|
||||
val v3: (String) -> Int
|
||||
val v4: MyTransformer /* = (String) -> Int */
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun topLevelPropertiesWithClassesCustomPackage() = klibContents(testLibrary("TopLevelPropertiesWithClassesCustomPackage")) {
|
||||
"""
|
||||
package custom.pkg {
|
||||
typealias MyTransformer = (String) -> Int
|
||||
object Bar
|
||||
class Foo constructor()
|
||||
}
|
||||
|
||||
package custom.pkg {
|
||||
val v1: Int = 1
|
||||
val v2: String = "hello"
|
||||
val v3: (String) -> Int
|
||||
val v4: MyTransformer /* = (String) -> Int */
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun topLevelPropertiesWithClassesRootPackage() = klibContents(testLibrary("TopLevelPropertiesWithClassesRootPackage")) {
|
||||
"""
|
||||
package <root> {
|
||||
typealias MyTransformer = (String) -> Int
|
||||
object Bar
|
||||
class Foo constructor()
|
||||
}
|
||||
|
||||
package <root> {
|
||||
val v1: Int = 1
|
||||
val v2: String = "hello"
|
||||
val v3: (String) -> Int
|
||||
val v4: MyTransformer /* = (String) -> Int */
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
companion object {
|
||||
val LIBRARY_DIRECTORY = Paths.get("build/konan/libs").resolve(HostManager.hostName)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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 custom.pkg
|
||||
|
||||
annotation class A
|
||||
|
||||
class Foo {
|
||||
val simple = 0
|
||||
|
||||
private val privateSimple = 0
|
||||
|
||||
protected val protectedSimple = 0
|
||||
|
||||
var privateSetter = 0
|
||||
private set
|
||||
|
||||
@A val annotated = 0
|
||||
|
||||
val annotatedGetter = 0
|
||||
@A get
|
||||
|
||||
var annotatedSetter = 0
|
||||
@A set
|
||||
|
||||
var annotatedAccessors = 0
|
||||
@A set
|
||||
@A get
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
class A {
|
||||
fun aFun() {}
|
||||
val aVal = 0
|
||||
var aVar = ""
|
||||
|
||||
inner class B {
|
||||
fun bFun() {}
|
||||
val bVal = 0
|
||||
var bVar = ""
|
||||
|
||||
inner class C {
|
||||
fun cFun() {}
|
||||
val cVal = 0
|
||||
var cVar = ""
|
||||
}
|
||||
|
||||
private inner class D {
|
||||
fun dFun() {}
|
||||
val dVal = 0
|
||||
var dVar = ""
|
||||
}
|
||||
}
|
||||
|
||||
class E {
|
||||
fun eFun() {}
|
||||
val eVal = 0
|
||||
var eVar = ""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class F(val fVal: Int, var fVar: String) {
|
||||
fun fFun() {}
|
||||
}
|
||||
|
||||
interface Interface {
|
||||
fun iFun()
|
||||
val iVal: Int
|
||||
var iVar: String
|
||||
}
|
||||
|
||||
open class OpenImpl: Interface {
|
||||
override fun iFun() {}
|
||||
override val iVal = 0
|
||||
override var iVar = ""
|
||||
}
|
||||
|
||||
class FinalImpl: OpenImpl() {
|
||||
override fun iFun() {}
|
||||
override val iVal = 0
|
||||
override var iVar = ""
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED_PARAMETER")
|
||||
|
||||
annotation class A
|
||||
|
||||
class Foo(x: Int) {
|
||||
constructor(): this(0)
|
||||
constructor(x: Double): this(x.toInt())
|
||||
constructor(x: Double, y: Int): this(y)
|
||||
|
||||
private constructor(x: Long): this(0)
|
||||
protected constructor(x: String): this(0)
|
||||
@A constructor(x: Foo) : this(0)
|
||||
}
|
||||
|
||||
class Bar @A constructor(x: Int)
|
||||
class Baz private constructor(x: Int)
|
||||
class Qux protected constructor(x: Int)
|
||||
|
||||
class Typed<T>(x: Int) {
|
||||
constructor(): this(0)
|
||||
constructor(x: Double): this(x.toInt())
|
||||
constructor(x: Double, y: Int): this(y)
|
||||
|
||||
private constructor(x: Long): this(0)
|
||||
protected constructor(x: String): this(0)
|
||||
@A constructor(x: Foo) : this(0)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
enum class E(val x: Int = 0) {
|
||||
A,
|
||||
B,
|
||||
C(1) {
|
||||
override fun enumFun() = 42
|
||||
};
|
||||
|
||||
open fun enumFun(): Int = 0
|
||||
val enumVal = 0
|
||||
var enumVar = ""
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
class Foo {
|
||||
fun f1() {}
|
||||
infix fun f2(x: Int) {}
|
||||
suspend fun f3() {}
|
||||
operator fun plus(x: Int) {}
|
||||
tailrec fun f4() {}
|
||||
fun f5(vararg x: Int) {}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
interface Interface {
|
||||
fun interfaceFun()
|
||||
}
|
||||
|
||||
abstract class AbstractClass: Interface {
|
||||
override fun interfaceFun() {}
|
||||
abstract fun abstractFun()
|
||||
}
|
||||
|
||||
open class OpenClass: AbstractClass() {
|
||||
override fun abstractFun() {}
|
||||
open fun openFun1() {}
|
||||
open fun openFun2() {}
|
||||
fun finalFun() {}
|
||||
}
|
||||
|
||||
class FinalClass: OpenClass() {
|
||||
override fun openFun1() {}
|
||||
final override fun openFun2() {}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
object A {
|
||||
fun a() {}
|
||||
}
|
||||
|
||||
class B {
|
||||
companion object {
|
||||
fun b() {}
|
||||
}
|
||||
|
||||
object C {
|
||||
fun c() {}
|
||||
}
|
||||
}
|
||||
|
||||
class D {
|
||||
companion object E {
|
||||
fun e() {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED_PARAMETER")
|
||||
|
||||
annotation class A
|
||||
annotation class B
|
||||
|
||||
class Foo
|
||||
|
||||
fun f1(x: Foo): Unit {}
|
||||
fun f2(x: Foo, y: Foo) = 0
|
||||
|
||||
// inline
|
||||
inline fun i1(block: () -> Foo) {}
|
||||
inline fun i2(noinline block: () -> Foo) {}
|
||||
inline fun i3(crossinline block: () -> Foo) {}
|
||||
|
||||
// callable args
|
||||
fun i4(block: (Foo) -> Int) {}
|
||||
fun i5(block: (Foo, Foo) -> Int) {}
|
||||
fun i6(block: Foo.() -> Int) {}
|
||||
fun i7(block: Foo.(Foo) -> Int) {}
|
||||
|
||||
// type parameters
|
||||
fun <T> t1(x: Foo) {}
|
||||
fun <T> t2(x: T) {}
|
||||
fun <T, F> t3(x: T, y: F) {}
|
||||
inline fun <reified T> t4(x: T) {}
|
||||
fun <T: Number> t5(x: T) {}
|
||||
|
||||
// extension
|
||||
fun Foo.e() {}
|
||||
|
||||
// annotations
|
||||
@A @B fun a() {}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED_PARAMETER")
|
||||
|
||||
package custom.pkg
|
||||
|
||||
typealias MyTransformer = (String) -> Int
|
||||
|
||||
// top-level properties
|
||||
val v1 = 1
|
||||
val v2 = "hello"
|
||||
val v3: (String) -> Int = { it.length }
|
||||
val v4: MyTransformer = v3
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED_PARAMETER")
|
||||
|
||||
typealias MyTransformer = (String) -> Int
|
||||
|
||||
// top-level properties
|
||||
val v1 = 1
|
||||
val v2 = "hello"
|
||||
val v3: (String) -> Int = { it.length }
|
||||
val v4: MyTransformer = v3
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED_PARAMETER")
|
||||
|
||||
package custom.pkg
|
||||
|
||||
class Foo
|
||||
|
||||
typealias MyTransformer = (String) -> Int
|
||||
|
||||
// top-level properties
|
||||
val v1 = 1
|
||||
val v2 = "hello"
|
||||
val v3: (String) -> Int = { it.length }
|
||||
val v4: MyTransformer = v3
|
||||
|
||||
object Bar
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED_PARAMETER")
|
||||
|
||||
class Foo
|
||||
|
||||
typealias MyTransformer = (String) -> Int
|
||||
|
||||
// top-level properties
|
||||
val v1 = 1
|
||||
val v2 = "hello"
|
||||
val v3: (String) -> Int = { it.length }
|
||||
val v4: MyTransformer = v3
|
||||
|
||||
object Bar
|
||||
Reference in New Issue
Block a user