Skip to content

Commit

Permalink
put critter back in main model
Browse files Browse the repository at this point in the history
  • Loading branch information
evanchooly committed Jul 2, 2024
1 parent 1cc3a12 commit 8b8e90d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 62 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ on:
- 'dependabot/**'
tags:
- '*'
paths-ignore:
- 'critter/**'

workflow_dispatch:

jobs:
Expand Down
23 changes: 0 additions & 23 deletions .github/workflows/critter.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package dev.morphia.critter.parser
import dev.morphia.critter.parser.generators.AddFieldAccessorMethods
import dev.morphia.critter.parser.generators.EntityAccessorGenerator
import dev.morphia.critter.parser.java.CritterClassLoader
import dev.morphia.critter.sources.DummyEntity
import dev.morphia.critter.sources.KotlinDummyEntity
import org.bson.codecs.pojo.PropertyAccessor
import org.testng.Assert.assertEquals
import org.testng.Assert.assertTrue
Expand All @@ -15,7 +17,7 @@ class TestAsmGenerator {
}

@Test(dataProvider = "classes")
fun testPropertyAccessors(type: String) {
fun testPropertyAccessors(type: Class<*>) {
val critterClassLoader = CritterClassLoader(Thread.currentThread().contextClassLoader)
val testFields =
listOf(
Expand All @@ -24,13 +26,13 @@ class TestAsmGenerator {
listOf("salary", java.lang.Long::class.java, 100_000L),
)
val bytes =
AddFieldAccessorMethods(type)
AddFieldAccessorMethods(type.name)
.update(testFields.map { l -> l[0] as String to l[1] as Class<*> }.toMap())
critterClassLoader.register(type, bytes)
critterClassLoader.register(type.name, bytes)

critterClassLoader.dump("target")

val entity = critterClassLoader.loadClass(type).getConstructor().newInstance()
val entity = critterClassLoader.loadClass(type.name).getConstructor().newInstance()

testFields.forEach { field ->
testAccessor(
Expand All @@ -45,7 +47,7 @@ class TestAsmGenerator {
}

private fun testAccessor(
type: String,
type: Class<*>,
critterClassLoader: CritterClassLoader,
entity: Any,
fieldName: String,
Expand Down Expand Up @@ -73,10 +75,7 @@ class TestAsmGenerator {
}

@DataProvider(name = "classes")
fun names(): Array<String> {
return arrayOf(
"dev.morphia.critter.sources.DummyEntity",
"dev.morphia.critter.sources.KotlinDummyEntity"
)
fun names(): Array<Class<out Any>> {
return arrayOf(DummyEntity::class.java, KotlinDummyEntity::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,14 @@ import org.objectweb.asm.Label
import org.objectweb.asm.Opcodes.*
import org.objectweb.asm.Type

class EntityAccessorGenerator(entity: String, val fieldName: String, fieldClass: Class<*>) {
val entityType: Type = Type.getType("L${entity.replace('.', '/')};")
class EntityAccessorGenerator(entity: Class<*>, val fieldName: String, fieldClass: Class<*>) {
val entityType: Type = Type.getType(entity)
val fieldType = Type.getType(fieldClass)
val wrapped = wrap(fieldType)
val classWriter = ClassWriter(0)
val accessorName: String

val accessorType: Type

init {
val packageName = entity.substringBeforeLast(".")
val name = entity.substringAfterLast(".")
accessorName =
"${packageName.replace('.', '/')}/__morphia/$name${fieldName.titleCase()}Accessor"

accessorType = Type.getType("L$accessorName;")
}
val accessorName =
"${entity.packageName.replace('.', '/')}/__morphia/${entity.simpleName}${fieldName.titleCase()}Accessor"
val accessorType = Type.getType("L$accessorName;")

fun dump(): ByteArray {
classWriter.visit(
Expand Down
13 changes: 1 addition & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,6 @@
<module>audits</module>
</modules>
</profile>

<profile>
<id>critter</id>
<activation>
<property>
<name>critter</name>
</property>
</activation>
<modules>
<module>critter</module>
</modules>
</profile>
</profiles>

<modules>
Expand All @@ -335,5 +323,6 @@
<module>validation</module>
<module>examples</module>
<module>rewrite</module>
<module>critter</module>
</modules>
</project>

0 comments on commit 8b8e90d

Please sign in to comment.