diff options
| author | Ahmed El Khazari <ahmed.el.khazari@qt.io> | 2025-01-31 16:46:09 +0200 |
|---|---|---|
| committer | Ville Voutilainen <ville.voutilainen@qt.io> | 2025-04-15 05:59:01 +0000 |
| commit | 0c4f42b5a301b5bba1ce30d13edbf58f848981a4 (patch) | |
| tree | 72ff3a71dce0d3a1db9570453c73302610461349 | |
| parent | 2eeaf0eae69a9eb01367dc29c4ff40eecee1e8c0 (diff) | |
Introduce processor module to orchestrate generation workflow
- Added the NativeGlueProcessor, which coordinates the generation of
native glue code by leveraging the NativeGlueGenerator components.
- Implemented the NativeProxyProcessor to handle the generation of
proxy-related code, delegating to the appropriate ProxyGenerator
sub-components
Task-number: QTTA-271
Change-Id: Id0fd49e17f7245111a9c203af4fc552b052d8c2e
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
3 files changed, 113 insertions, 0 deletions
diff --git a/compiler/src/main/java/io/github/landerlyoung/jenny/processor/NativeGlueProcessor.kt b/compiler/src/main/java/io/github/landerlyoung/jenny/processor/NativeGlueProcessor.kt new file mode 100644 index 0000000..b0ae766 --- /dev/null +++ b/compiler/src/main/java/io/github/landerlyoung/jenny/processor/NativeGlueProcessor.kt @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2025 The Qt Company Ltd. + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.github.landerlyoung.jenny.processor + +import io.github.landerlyoung.jenny.element.clazz.JennyClassElement +import io.github.landerlyoung.jenny.element.clazz.JennyClassTypeElement +import io.github.landerlyoung.jenny.element.clazz.JennyClazzElement +import io.github.landerlyoung.jenny.generator.glue.NativeGlueGenerator +import io.github.landerlyoung.jenny.utils.CppFileHelper + +import javax.lang.model.element.TypeElement + +import kotlin.reflect.KClass + +internal class NativeGlueProcessor( + outputDirectory: String, + private val cppFileHelper: CppFileHelper = CppFileHelper() +) : Processor { + private val nativeGlueGenerator = NativeGlueGenerator(cppFileHelper, outputDirectory) + + override fun process(input: Any) { + nativeGlueGenerator.generate(makeJennyClazz(input)) + } + + override fun setOutputTargetPath(outputPath: String) { + nativeGlueGenerator.setOutputTargetPath(outputPath) + } + + fun setNamespace(namespace: String) { + cppFileHelper.setNamespace(namespace) + } + + // TODO: Support Collections (of KClass<*>, Class<*>,TypeElement) here + private fun makeJennyClazz(input: Any): JennyClazzElement { + return when (input) { + is KClass<*> -> JennyClassElement(input.java) + is Class<*> -> JennyClassElement(input) + is TypeElement -> JennyClassTypeElement(input) + else -> throw IllegalArgumentException("${input.javaClass.name} input type is not supported") + } + } +} diff --git a/compiler/src/main/java/io/github/landerlyoung/jenny/processor/NativeProxyProcessor.kt b/compiler/src/main/java/io/github/landerlyoung/jenny/processor/NativeProxyProcessor.kt new file mode 100644 index 0000000..69bf31d --- /dev/null +++ b/compiler/src/main/java/io/github/landerlyoung/jenny/processor/NativeProxyProcessor.kt @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2025 The Qt Company Ltd. + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.github.landerlyoung.jenny.processor + +import io.github.landerlyoung.jenny.element.clazz.JennyClassElement +import io.github.landerlyoung.jenny.element.clazz.JennyClassTypeElement +import io.github.landerlyoung.jenny.element.clazz.JennyClazzElement +import io.github.landerlyoung.jenny.generator.Configurator +import io.github.landerlyoung.jenny.generator.proxy.NativeProxyGenerator +import io.github.landerlyoung.jenny.model.JennyProxyConfiguration +import io.github.landerlyoung.jenny.provider.ProviderConfiguration +import io.github.landerlyoung.jenny.provider.proxy.factory.ProxyProviderTypeFactory +import io.github.landerlyoung.jenny.utils.CppFileHelper + +import javax.lang.model.element.TypeElement + +import kotlin.reflect.KClass + +internal class NativeProxyProcessor( + outputDirectory: String, + providerConfiguration: ProviderConfiguration, + private val cppFileHelper: CppFileHelper = CppFileHelper(), + proxyConfiguration: JennyProxyConfiguration +) : Processor, Configurator<JennyProxyConfiguration> { + + private val nativeProxyGenerator = NativeProxyGenerator( + providerType = ProxyProviderTypeFactory.createProviderType(providerConfiguration), + cppFileHelper = cppFileHelper, + outputDirectory = outputDirectory, + proxyConfiguration = proxyConfiguration + ) + + override fun setOutputTargetPath(outputPath: String) { + nativeProxyGenerator.setOutputTargetPath(outputPath) + } + + override fun process(input: Any) = nativeProxyGenerator.generate(makeJennyClazz(input)) + + override fun applyConfiguration(configuration: JennyProxyConfiguration) { + cppFileHelper.setNamespace(configuration.namespace) + nativeProxyGenerator.applyConfiguration(configuration) + } + + // TODO: Support Collections (of KClass<*>, Class<*>,TypeElement) here + private fun makeJennyClazz(input: Any): JennyClazzElement { + return when (input) { + is KClass<*> -> JennyClassElement(input.java) + is Class<*> -> JennyClassElement(input) + is TypeElement -> JennyClassTypeElement(input) + else -> throw IllegalArgumentException("${input.javaClass.name} input type is not supported") + } + } +} diff --git a/compiler/src/main/java/io/github/landerlyoung/jenny/processor/Processor.kt b/compiler/src/main/java/io/github/landerlyoung/jenny/processor/Processor.kt new file mode 100644 index 0000000..ea1064d --- /dev/null +++ b/compiler/src/main/java/io/github/landerlyoung/jenny/processor/Processor.kt @@ -0,0 +1,12 @@ +/* + * Copyright (C) 2025 The Qt Company Ltd. + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.github.landerlyoung.jenny.processor + +import io.github.landerlyoung.jenny.generator.OutputTargetConfigurator + +internal interface Processor : OutputTargetConfigurator { + fun process(input: Any) +} |
