Minor: add Javadoc for UastContext/UastLanguagePlugin

This commit is contained in:
Yan Zhulanow
2016-04-13 18:05:02 +03:00
parent 82946437d8
commit 76e5657a99
2 changed files with 68 additions and 0 deletions
@@ -15,9 +15,25 @@
*/
package org.jetbrains.uast
/**
* Interface for the Uast context.
*
* Context is needed for resolution, cause the reference can point to the element of the different language.
*/
interface UastContext {
/**
* Returns all active language plugins.
*/
val languagePlugins: List<UastLanguagePlugin>
/**
* Convert an element of some language-specific AST to Uast element.
* If two or more language plugins can convert the given [element] type,
* the first converter in the [languagePlugins] list will be chosen.
*
* @param element the language-specific AST element
* @return [UElement] instance, or null if [element] type is not supported by any of the provided language plugins.
*/
fun convert(element: Any?): UElement? {
if (element == null) {
return null
@@ -17,19 +17,71 @@ package org.jetbrains.uast
import org.jetbrains.uast.visitor.UastVisitor
/**
* Interface for the Uast element converter.
* Each [UastLanguagePlugin] should implement a proper [UastContext],
* which translates language-specific AST elements to Uast elements.
*/
interface UastConverter {
/**
* Convert a language-specific AST element to the [UElement] implementation with the given parent.
*
* @param element the element of the supported language-specific AST.
* @param parent the parent of the newly created [UElement].
* @return a [UElement], or null if the given [element] is not supported by this converter.
*
* No exceptions should be thrown during conversion, return `null` instead.
*/
fun convert(element: Any?, parent: UElement): UElement?
/**
* Convert [element] to the [UElement] with the given parent.
*/
fun convertWithParent(element: Any?): UElement?
/**
* Checks if the file with the given [name] is supported.
*
* @param name the source file name.
* @return true, if the file is supported by this converter, false otherwise.
*/
fun isFileSupported(name: String): Boolean
}
/**
* Interface for the Uast language plugin.
*
* [UElement] implementations are loaded using language plugins provided in [UastContext].
* Each plugin must have a language-specific AST -> Uast (e.g. PsiElement -> UElement) converter.
*/
interface UastLanguagePlugin {
/**
* Returns converter for the specific language AST.
*/
val converter: UastConverter
/**
* Returns list of visitor extensions for the specific language AST.
*/
val visitorExtensions: List<UastVisitorExtension>
}
/**
* Interface for the Uast visitor extension.
*
* A language plugin could provide a number of visitor extensions, which transforms some [UElement] into another.
* For example, Java accessors (getters/setters) are expressed in Kotlin as properties,
* but it can be useful to see them as functions in diagnostics, so the visitor extension
* can convert such property accessor calls to the ordinary function calls.
*/
interface UastVisitorExtension {
/**
* Invoke extension on an element.
*
* @param element a [UElement] to process.
* @param visitor current visitor.
* @param context current context.
*/
operator fun invoke(element: UElement, visitor: UastVisitor, context: UastContext)
}