This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IrPluginTest { | |
@Test | |
fun `IR plugin success`() { | |
val result = compile( | |
sourceFile = SourceFile.kotlin( | |
"main.kt", """ | |
fun main() { | |
println(debug()) | |
} | |
fun debug() = "Hello, World!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tasks.named("compileKotlin") { dependsOn("syncSource") } | |
tasks.register<Sync>("syncSource") { | |
from(project(":kotlin-ir-plugin").sourceSets.main.get().allSource) | |
into("src/main/kotlin") | |
filter { | |
// Replace shadowed imports from plugin module | |
when (it) { | |
"import org.jetbrains.kotlin.com.intellij.mock.MockProject" -> "import com.intellij.mock.MockProject" | |
else -> it | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TemplateIrGenerationExtension( | |
private val messageCollector: MessageCollector, | |
private val string: String, | |
private val file: String | |
) : IrGenerationExtension { | |
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) { | |
messageCollector.report(CompilerMessageSeverity.INFO, "Argument 'string' = $string") | |
messageCollector.report(CompilerMessageSeverity.INFO, "Argument 'file' = $file") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AutoService(ComponentRegistrar::class) | |
class TemplateComponentRegistrar( | |
private val defaultString: String, | |
private val defaultFile: String, | |
) : ComponentRegistrar { | |
@Suppress("unused") // Used by service loader | |
constructor() : this( | |
defaultString = "Hello, World!", | |
defaultFile = "file.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AutoService(CommandLineProcessor::class) | |
class TemplateCommandLineProcessor : CommandLineProcessor { | |
companion object { | |
private const val OPTION_STRING = "string" | |
private const val OPTION_FILE = "file" | |
val ARG_STRING = CompilerConfigurationKey<String>(OPTION_STRING) | |
val ARG_FILE = CompilerConfigurationKey<String>(OPTION_FILE) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TemplateGradlePlugin : KotlinCompilerPluginSupportPlugin { | |
override fun apply(target: Project): Unit = with(target) { | |
extensions.create("template", TemplateGradleExtension::class.java) | |
} | |
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true | |
override fun getCompilerPluginId(): String = BuildConfig.KOTLIN_PLUGIN_ID | |
override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildConfig { | |
val project = project(":kotlin-ir-plugin") | |
packageName(project.group.toString()) | |
buildConfigField("String", "KOTLIN_PLUGIN_ID", "\"${rootProject.extra["kotlin_plugin_id"]}\"") | |
buildConfigField("String", "KOTLIN_PLUGIN_GROUP", "\"${project.group}\"") | |
buildConfigField("String", "KOTLIN_PLUGIN_NAME", "\"${project.name}\"") | |
buildConfigField("String", "KOTLIN_PLUGIN_VERSION", "\"${project.version}\"") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface WebSocketSession { | |
val incoming: ReceiveChannel<String> | |
val outgoing: SendChannel<String> | |
} | |
suspend fun <R> OkHttpClient.newWebSocket( | |
request: Request, | |
block: suspend WebSocketSession.() -> R | |
): R = coroutineScope { | |
val incoming = Channel<String>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.experimental.nio.aRead | |
import kotlinx.coroutines.experimental.nio.aWrite | |
import okio.Buffer | |
import java.nio.ByteBuffer | |
import java.nio.channels.AsynchronousFileChannel | |
import java.nio.channels.AsynchronousSocketChannel | |
import java.util.concurrent.TimeUnit | |
suspend fun AsynchronousSocketChannel.aRead( | |
buffer: Buffer, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.net.ProtocolException; | |
import java.security.GeneralSecurityException; | |
import java.util.Random; | |
import javax.crypto.Cipher; | |
import javax.crypto.ShortBufferException; | |
import javax.crypto.spec.IvParameterSpec; | |
import javax.crypto.spec.SecretKeySpec; | |
import okio.Buffer; | |
import okio.BufferedSink; |
NewerOlder