Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object ClassCollector {
- private val KINDS = setOf(JavaFileObject.Kind.CLASS)
- private val fileManager: JavaFileManager
- init {
- val compiler = ToolProvider.getSystemJavaCompiler()
- fileManager = compiler.getStandardFileManager(DiagnosticCollector<JavaFileObject>(), null, null)
- }
- fun collect(vararg pkgs: String): Collection<Class<*>> {
- return pkgs.map { collect(it) }.flatten()
- }
- fun collect(pkg: String): Collection<Class<*>> {
- return fileManager.list(StandardLocation.CLASS_PATH, pkg, KINDS, true).map {
- val path = it.toUri().path.replace(".class", "").replace("/", ".")
- val p = path.lastIndexOf(pkg)
- Class.forName(if (p > 0) path.substring(p, path.length) else path)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement