Created
June 18, 2018 11:24
-
-
Save ChristianSchwarz/fccf088e360e2fdd3ce5c30b729861d2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package exploration | |
| import javassist.Modifier.isStatic | |
| import org.junit.Test | |
| import org.reflections.Reflections | |
| import org.reflections.scanners.SubTypesScanner | |
| import java.lang.Exception | |
| import java.lang.reflect.Method | |
| import java.lang.reflect.Modifier.isPrivate | |
| import java.lang.reflect.Modifier.isPublic | |
| class FindConsecutiveTypes { | |
| var found = 0 | |
| @Test | |
| fun run() { | |
| var inspectedMethods = 0 | |
| Reflections(SubTypesScanner(false)).allTypes.forEach { | |
| try { | |
| inspectedMethods += inspectType(it) | |
| } catch (ignore: Error) { | |
| } catch (ignore: Exception) { | |
| } | |
| } | |
| println() | |
| println() | |
| println("$inspectedMethods $found ${found / (inspectedMethods / 100)}%") | |
| } | |
| private fun inspectType(it: String): Int { | |
| var inspectedMethods = 0 | |
| val type = Class.forName(it) | |
| if (isPublic(type.modifiers)) { | |
| type.declaredMethods.forEach { | |
| if (checkMethod(it)) { | |
| paramsAsString(it.parameterTypes) | |
| inspectedMethods++ | |
| } | |
| } | |
| } | |
| return inspectedMethods; | |
| } | |
| private fun checkMethod(it: Method) = | |
| !(it.isBridge || it.isSynthetic || isPrivate(it.modifiers) || isStatic(it.modifiers)) | |
| private fun paramsAsString(parameterTypes: Array<out Class<*>>) { | |
| var lastType: Class<*>? = null | |
| var b = false | |
| parameterTypes.forEach { | |
| if (it == lastType && b == false) { | |
| found++ | |
| b = true | |
| } | |
| lastType = it | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment