-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
core/src/main/kotlin/com/toasttab/expediter/types/PolymorphicMethods.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.toasttab.expediter.types | ||
|
||
/** | ||
* This object enumerates signature-polymorphic methods, see the javadoc for MethodHandle. | ||
*/ | ||
object PolymorphicMethods { | ||
private val methods = mapOf( | ||
"java/lang/invoke/MethodHandle" to setOf( | ||
"invoke", | ||
"invokeExact" | ||
), | ||
|
||
"java/lang/invoke/VarHandle" to setOf( | ||
"get", | ||
"set", | ||
"getVolatile", | ||
"setVolatile", | ||
"getOpaque", | ||
"setOpaque", | ||
"getAcquire", | ||
"setRelease", | ||
"compareAndSet", | ||
"compareAndExchange", | ||
"compareAndExchangeAcquire", | ||
"compareAndExchangeRelease", | ||
"weakCompareAndSetPlain", | ||
"weakCompareAndSet", | ||
"weakCompareAndSetAcquire", | ||
"weakCompareAndSetRelease", | ||
"getAndSet", | ||
"getAndSetAcquire", | ||
"getAndSetRelease", | ||
"getAndAdd", | ||
"getAndAddAcquire", | ||
"getAndAddRelease", | ||
"getAndBitwiseOr", | ||
"getAndBitwiseOrAcquire", | ||
"getAndBitwiseOrRelease", | ||
"getAndBitwiseAnd", | ||
"getAndBitwiseAndAcquire", | ||
"getAndBitwiseAndRelease", | ||
"getAndBitwiseXor", | ||
"getAndBitwiseXorAcquire", | ||
"getAndBitwiseXorRelease" | ||
) | ||
) | ||
|
||
fun contains(className: String, methodName: String): Boolean { | ||
return methods[className]?.contains(methodName) ?: false | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
core/src/test/kotlin/com/toasttab/expediter/types/PolymorphicMethodsTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.toasttab.expediter.types | ||
|
||
import org.junit.jupiter.api.Test | ||
import strikt.api.expectThat | ||
import strikt.assertions.isTrue | ||
import java.lang.invoke.MethodHandle | ||
import java.lang.invoke.VarHandle | ||
import java.lang.reflect.Modifier | ||
|
||
class PolymorphicMethodsTest { | ||
@Test | ||
fun `MethodHandle and VarHandle methods annotated with PolymorphicSignature`() { | ||
for (cls in listOf(MethodHandle::class.java, VarHandle::class.java)) { | ||
val name = cls.name.replace('.', '/') | ||
|
||
for (method in polymorphicMethodsOf(cls)) { | ||
expectThat(PolymorphicMethods.contains(name, method.name)).isTrue() | ||
} | ||
} | ||
} | ||
|
||
private fun polymorphicMethodsOf(cls: Class<*>) = cls.methods.filter { m -> | ||
Modifier.isPublic(m.modifiers) && m.annotations.any { | ||
it.annotationClass.java.name == "java.lang.invoke.MethodHandle\$PolymorphicSignature" | ||
} | ||
} | ||
} |
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