-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add KotlinAndJavaCompositeArbitraryIntrospector for supporting instantiating kotlin class with java reference Type #948
Add KotlinAndJavaCompositeArbitraryIntrospector for supporting instantiating kotlin class with java reference Type #948
Conversation
private val javaIntrospector: ArbitraryIntrospector, | ||
) : ArbitraryIntrospector { | ||
override fun introspect(context: ArbitraryGeneratorContext): ArbitraryIntrospectorResult { | ||
val type = Types.getActualType(context.resolvedType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the extension method .actualType()
would be better.
@jinia91 Your approach seems to be a good intermediate step in Can you add a new benchmark for |
class KotlinPlugin( | ||
private val kotlinIntrospector: ArbitraryIntrospector = PrimaryConstructorArbitraryIntrospector.INSTANCE, | ||
private val javaIntrospector: ArbitraryIntrospector = BeanArbitraryIntrospector.INSTANCE, | ||
) : Plugin { | ||
override fun accept(optionsBuilder: FixtureMonkeyOptionsBuilder) { | ||
optionsBuilder.objectIntrospector { PrimaryConstructorArbitraryIntrospector.INSTANCE } | ||
optionsBuilder.objectIntrospector { | ||
KotlinAndJavaCompositeArbitraryIntrospector( | ||
kotlinIntrospector = kotlinIntrospector, | ||
javaIntrospector = javaIntrospector | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that javaIntrospector
is not concern of KotlinPlugin
.
It may cause a breaking change in the near future.
It is better to use objectInrospector
option to apply new KotlinAndJavaCompositeArbitraryIntrospector
with desired javaIntrospector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also feel that it's excessive for the KotlinPlugin
to be setting up the JavaIntrospector
. However, it seems good for objects to be smoothly created with the KotlinPlugin
alone(dont use other api), regardless of whether Java reference types are used internally.
If a design is planned for a future version (1.1.x) that allows for such behavior,
then in the current PR, I plan to exclude changes to the KotlinPlugin
and only keep the implementation of KotlinAndJavaCompositeArbitraryIntrospector
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then in the current PR, I plan to exclude changes to the KotlinPlugin and only keep the implementation of KotlinAndJavaCompositeArbitraryIntrospector.
👍 It is good idea.
private val kotlinIntrospector: ArbitraryIntrospector, | ||
private val javaIntrospector: ArbitraryIntrospector, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about kotlinArbitraryIntrospector
and javaArbitraryIntrospector
?
import java.lang.reflect.Modifier | ||
import org.apiguardian.api.API | ||
import org.apiguardian.api.API.Status.MAINTAINED | ||
import java.lang.reflect.Modifier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import ordering is not valid
val sut: FixtureMonkey = FixtureMonkey.builder() | ||
.plugin(KotlinPlugin()) | ||
.objectIntrospector( | ||
KotlinAndJavaCompositeArbitraryIntrospector( | ||
kotlinArbitraryIntrospector = PrimaryConstructorArbitraryIntrospector.INSTANCE, | ||
javaArbitraryIntrospector = ConstructorPropertiesArbitraryIntrospector.INSTANCE | ||
) | ||
) | ||
.build() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is not aligned with given
.
@@ -180,7 +180,7 @@ fun sampleOrder() { | |||
* @[sangy515](https://github.com/sangy515) | |||
* @[yunseok-jeong0](https://github.com/yunseok-jeong0) | |||
* @[wicksome](https://github.com/wicksome) | |||
* @[Wonjin Choi](https://github.com/jinia91) | |||
* @[jinia91](https://github.com/jinia91) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it okay to change my nickname? 🥲
@@ -48,4 +49,16 @@ open class KotlinObjectGenerationBenchMark { | |||
|
|||
private fun generateKotlinOrderSheet(fixtureMonkey: FixtureMonkey): List<KotlinOrderSheet> = | |||
List(COUNT) { fixtureMonkey.giveMeOne(KotlinOrderSheet::class.java) } | |||
|
|||
@Benchmark |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add benchmark for KotlinAndJavaCompositeArbitraryIntrospector
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This is a pr regarding the issue at
#946
I have implemented the
KotlinAndJavaCompositeArbitraryIntrospector
to facilitate the smooth creation of objects for Kotlin classes that have Java classes as properties.The default Kotlin plugin uses this ArbitraryIntrospector but has been modified to accept other Introspector as a plugin argument.additionaly added a corresponding test case.
I personally feel that modifying the behavior of the default kotlin plugin is a bit excessive, so I hope the maintainer will make an appropriate judgment and edit.🙏=> only imple
KotlinAndJavaCompositeArbitraryIntrospector
add KotlinAndJavaCompositeArbitraryIntrospector benchmark
How Has This Been Tested?
check through test case
Is the Document updated?
add
KotlinAndJavaCompositeArbitraryIntrospector
in introspectors-for-kotlin