Replace UastConverter with UastLanguagePlugin, allow additional checkers

This commit is contained in:
Yan Zhulanow
2016-03-10 16:25:18 +03:00
parent 4ef6016ee8
commit d1939d52bc
16 changed files with 105 additions and 68 deletions
@@ -16,15 +16,15 @@
package org.jetbrains.uast
interface UastContext {
val converters: List<UastConverter>
val languagePlugins: List<UastLanguagePlugin>
fun convert(element: Any?): UElement? {
if (element == null) {
return null
}
for (converter in converters) {
val uelement = converter.convertWithParent(element)
for (plugin in languagePlugins) {
val uelement = plugin.converter.convertWithParent(element)
if (uelement != null) {
return uelement
}
@@ -22,9 +22,18 @@ interface UastConverter {
fun isFileSupported(path: String): Boolean
}
interface UastLanguagePlugin {
val converter: UastConverter
val additionalCheckers: List<UastAdditionalChecker>
}
interface UastAdditionalChecker {
operator fun invoke(element: UElement, handler: UastHandler, context: UastContext)
}
object UastConverterUtils {
@JvmStatic
fun isFileSupported(converters: List<UastConverter>, path: String): Boolean {
return converters.any { it.isFileSupported(path) }
fun isFileSupported(converters: List<UastLanguagePlugin>, path: String): Boolean {
return converters.any { it.converter.isFileSupported(path) }
}
}