The Ast interface represents the parsed text document. Currently, this interface is implemented by the JavaAst and Python3Ast classes.
| Property | Description |
|---|---|
tree: ParseTree |
The parse tree that was generated by ANTLR. |
document: TextDocument |
The current VSCode Text document that is used for parsing the code. |
classDeclarations: ClassDeclaration[] |
An array holding all the class declarations of the current text document. |
methodDeclarations: MethodDeclaration[] |
An array holding all the methods declarations of the current text document. |
methodCalls: MethodCall[] |
An array holding all the method calls of the current text document. |
JavaAst implements Ast
The JavaAst class represents the parsed text document and implements the Ast interface. This class is used for parsing Java code.
See Ast.
parse(source: string)
Parse the file from the given source code and return. This function is called in the constructor.
init()
Initialize this classes. This means walking the parse tree using a custom listener and collecting the relevant data accordingly. This function is called in the constructor.
Python3Ast implements Ast
The Python3Ast class represents the parsed text document and implements the Ast interface. This class is used for parsing Python3 code.
See Ast.
parse(source: string)
Parse the file from the given source code and return. This function is called in the constructor.
init()
Initialize this classes. This means walking the parse tree using a custom listener and collecting the relevant data accordingly. This function is called in the constructor.
The Target class is used to represent a target in the editor. E.g. a target could be a class declaration or a method declaration. It is possible to annotate and highlight target objects.
| Property | Description |
|---|---|
identifier: Range | undefined |
Saves the Range of the identifier of the target. This can be the the whole target range. |
start: Position |
The Position where the target range starts. |
end: Position |
The Position where the target range ends. |
readonly document: TextDocument |
The TextDocument of this is associated with. |
readonly decorationOptions: DecorationOptions |
The DecorationOptions that save the text decoration options. |
applyStyle(decorationType: TextEditorDecorationType, identifier: boolean = false)
Applies the given decorationType to this.
| Parameters | |
|---|---|
identifier?: boolean |
Default value false. If true, the decoration is applied only to the identifier Range. |
setHoverMessage(hoverMessage: MarkdownString | Array)
Sets the hoverMessage for this. It will only appear, if a decoration is active on this.
applyTextDecoration(textDecoration: ThemableDecorationAttachmentRenderOptions, position: string, identifier: boolean = false): TextEditorDecorationType
Applies the given textDecoration to this. The textDecoration contains the string to display.
| Parameters | |
|---|---|
position: string |
Should be 'before' or 'after'. This indicates if the text decoration should pe placed before or after this range. |
identifier?: boolean |
Default value false. If true, the decoration is applied only to the identifier Range. |
| Returns | |
|---|---|
| TextEditorDecorationType | The newly created TextEditorDecorationType. To remove the text decoration later, this TextEditorDecorationType is needed. See removeTextDecoration(...). |
applyCodelens(command: Command, identifier: boolean = false): void
Applies a CodeLens to this. This Codelens can be clicked to execute the command. The CodeLens will always be positioned on top of the first row of the range.
| Parameters | |
|---|---|
command: Command |
The command to be executed on click. |
identifier?: boolean |
Default value false. If true, the codeLens is applied only to the identifier Range. |
removeStyle(decorationType: TextEditorDecorationType, identifier: boolean = false)
Removes the given decorationType from the editor.
| Parameters | |
|---|---|
identifier?: boolean |
Default value false. If true, the decoration is applied only to the identifier Range. |
removeTextDecoration(decorationType: TextEditorDecorationType)
Alias for removeStyle(decorationType).
removeHoverMessage(identifier: boolean = false)
Removes the hover message from this.
removeCodeLenses(identifier: boolean = false)
Removes the first CodeLens on this range.
| Parameters | |
|---|---|
identifier?: boolean |
Default value false. If true, the codeLens is removed only for the identifier Range. |
getText(): string
Returns the text for this range.
getIdentifierText(): string
Returns the text for the identifier range.
isEqual(other: Target): boolean
Returns true if other has the same identifier, start and end. Otherwise returns false.
ClassDeclaration extends Target
This class represents a class declaration and stores all the relevant properties of a class such as methods, fields, interfaces and more.
| Property | Description |
|---|---|
typeParams: Target[] |
An Target array holding all type parameters for the class. |
superClasses: Target[] |
An Target array holding all superclasses of the class. |
interfaces: Target[] |
An Target array holding all interfaces of the class. |
classBody: Target |
The class body saved as Target object. |
contructorDeclarations: ContructorDeclaration[] |
An ConstructorDeclaration array holding all constructors of the class. |
fields: Variable[] |
An Variable array holding all the field variables of the class. |
methodDeclarations: MethodDeclaration[] |
An MethodDeclaration array holding all the method declarations of class. |
See Target.
ConstructorDeclaration extends Target
| Property | Description |
|---|---|
classDeclaration: ClassDeclaration | null |
The class to which the constructor belongs to. |
params: Variable[] |
An Variable array holding all the parameters of the constructor. |
body: Target |
The body of the constructor. |
See Target.
MethodCall extends Target
This class represents a method call and inherits from Target.
| Property | Description |
|---|---|
args: Target[] |
The arguments passed on to the method call. |
MethodDeclaration extends Target
This class represents a method declaration where the class (if any) of the method is stored as well as other information such as the return type, parameters and the body.
| Property | Description |
|---|---|
classDeclaration: ClassDeclaration | null |
The class to which the method belongs to. Can be null if it belongs to no class. |
returnType: Target | null |
The return type of the method. Can be null if the method doesn't have a return type (e.g., in python) |
params: Variable[] |
An array holding all the parameters of the method. |
methodBody: Target |
The method body. |
See Target.
Variable extends Target
This class represents a variable and stores the type (if any) and the value (if specified).
| Property | Description |
|---|---|
type: Target | undefined |
The type of the variable. Can be undefined (e.g., python does not need types) |
value: Target | undefined |
The initial value of the variable. When not specified, the value is undefined. |
getTypeText(): string
Returns the type as a string. An empty string is returned when the type is undefined.
getValueText(): string
Returns the value as a string. An empty string is returned when the value is undefined.
findTargets(document: vscode.TextDocument, regex: string | RegExp): Target[]
Find all Ranges that match the regex. They are returned as Targets.
| Parameters | |
|---|---|
document: TextDocument |
The TextDocument in which to search for targets |
regex: string | RegExp |
The regex to search for in the document. The search can also find exact strings. |
| Returns | |
|---|---|
| Target[] | The results of the regex search formatted as targets. |
registerTextEditor(editor: TextEditor)
Registers a text editor for the controllers. If no controllers exists for the file, new ones are created. Otherwise, the controllers are updated. Should be called, when a new editor comes into view in vscode. Old editors will be overridden for each file.
removeAllDecorations(editor: TextEditor)
Helper function to remove all decorations for one editor (file).
removeAllCodeLenses(editor: TextEditor)
Helper function to remove all codeLenses for one editor (file).
unregisterTextEditor(editor: TextEditor)
Removes a controllers associated with a specific file. Also reemoves all decorations and codeLenses. The editor Parameter holds the file name.
unregisterAllTextEditors()
Removes all controller. Also disposes of all decorations and codeLenses.
unregisterCodeLensControllers()
Removes all codeLensControllers and their codeLenses.