Minor: add Javadoc for UastContext/UastLanguagePlugin
This commit is contained in:
@@ -15,9 +15,25 @@
|
|||||||
*/
|
*/
|
||||||
package org.jetbrains.uast
|
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 {
|
interface UastContext {
|
||||||
|
/**
|
||||||
|
* Returns all active language plugins.
|
||||||
|
*/
|
||||||
val languagePlugins: List<UastLanguagePlugin>
|
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? {
|
fun convert(element: Any?): UElement? {
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -17,19 +17,71 @@ package org.jetbrains.uast
|
|||||||
|
|
||||||
import org.jetbrains.uast.visitor.UastVisitor
|
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 {
|
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?
|
fun convert(element: Any?, parent: UElement): UElement?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert [element] to the [UElement] with the given parent.
|
||||||
|
*/
|
||||||
fun convertWithParent(element: Any?): UElement?
|
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
|
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 {
|
interface UastLanguagePlugin {
|
||||||
|
/**
|
||||||
|
* Returns converter for the specific language AST.
|
||||||
|
*/
|
||||||
val converter: UastConverter
|
val converter: UastConverter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns list of visitor extensions for the specific language AST.
|
||||||
|
*/
|
||||||
val visitorExtensions: List<UastVisitorExtension>
|
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 {
|
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)
|
operator fun invoke(element: UElement, visitor: UastVisitor, context: UastContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user