ast

package
v0.0.0-...-3200512 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNodeType

func GetNodeType(node *sitter.Node) string

GetNodeType returns the type of the Tree-Sitter node

Types

type AccessModifier

type AccessModifier string

AccessModifier represents the access level of class members

const (
	// AccessModifierPublic represents public access (default in most languages)
	AccessModifierPublic AccessModifier = "public"

	// AccessModifierPrivate represents private access
	AccessModifierPrivate AccessModifier = "private"

	// AccessModifierProtected represents protected access (inheritance-accessible)
	AccessModifierProtected AccessModifier = "protected"

	// AccessModifierPackage represents package/internal access
	AccessModifierPackage AccessModifier = "package"

	// AccessModifierUnknown represents unknown or unsupported access level
	AccessModifierUnknown AccessModifier = "unknown"
)

type ClassDeclarationNode

type ClassDeclarationNode struct {
	Node
	// contains filtered or unexported fields
}

ClassDeclarationNode represents a class definition with inheritance support This is a language agnostic representation of a class declaration. Not all attributes may be present in all languages

func NewClassDeclarationNode

func NewClassDeclarationNode(content Content) *ClassDeclarationNode

NewClassDeclarationNode creates a new ClassDeclarationNode instance using the class definition node from the tree-sitter parser

func (*ClassDeclarationNode) AccessModifier

func (c *ClassDeclarationNode) AccessModifier() AccessModifier

AccessModifier returns the access modifier of the class

func (*ClassDeclarationNode) AddBaseClassNode

func (c *ClassDeclarationNode) AddBaseClassNode(node *sitter.Node)

func (*ClassDeclarationNode) AddDecoratorNode

func (c *ClassDeclarationNode) AddDecoratorNode(node *sitter.Node)

func (*ClassDeclarationNode) AddFieldNode

func (c *ClassDeclarationNode) AddFieldNode(node *sitter.Node)

func (*ClassDeclarationNode) AddMethodNode

func (c *ClassDeclarationNode) AddMethodNode(node *sitter.Node)

func (*ClassDeclarationNode) BaseClasses

func (c *ClassDeclarationNode) BaseClasses() []string

BaseClasses returns the names of all base classes this class inherits from

func (*ClassDeclarationNode) ClassName

func (c *ClassDeclarationNode) ClassName() string

ClassName returns the name of the class

func (*ClassDeclarationNode) Constructor

func (c *ClassDeclarationNode) Constructor() string

Constructor returns the content of the constructor method

func (*ClassDeclarationNode) Decorators

func (c *ClassDeclarationNode) Decorators() []string

Decorators returns the content of all decorator nodes

func (*ClassDeclarationNode) Fields

func (c *ClassDeclarationNode) Fields() []string

Fields returns the content of all field nodes

func (*ClassDeclarationNode) GetBaseClassNodes

func (c *ClassDeclarationNode) GetBaseClassNodes() []*sitter.Node

func (*ClassDeclarationNode) GetClassNameNode

func (c *ClassDeclarationNode) GetClassNameNode() *sitter.Node

Getter methods for Tree-Sitter nodes

func (*ClassDeclarationNode) GetConstructorNode

func (c *ClassDeclarationNode) GetConstructorNode() *sitter.Node

func (*ClassDeclarationNode) GetDecoratorNodes

func (c *ClassDeclarationNode) GetDecoratorNodes() []*sitter.Node

func (*ClassDeclarationNode) GetFieldNodes

func (c *ClassDeclarationNode) GetFieldNodes() []*sitter.Node

func (*ClassDeclarationNode) GetMethodNodes

func (c *ClassDeclarationNode) GetMethodNodes() []*sitter.Node

func (*ClassDeclarationNode) HasInheritance

func (c *ClassDeclarationNode) HasInheritance() bool

HasInheritance returns true if this class inherits from one or more base classes

func (*ClassDeclarationNode) IsAbstract

func (c *ClassDeclarationNode) IsAbstract() bool

IsAbstract returns true if this is an abstract class

func (*ClassDeclarationNode) Methods

func (c *ClassDeclarationNode) Methods() []string

Methods returns the content of all method nodes

func (*ClassDeclarationNode) SetAccessModifier

func (c *ClassDeclarationNode) SetAccessModifier(accessModifier AccessModifier)

func (*ClassDeclarationNode) SetBaseClassNodes

func (c *ClassDeclarationNode) SetBaseClassNodes(nodes []*sitter.Node)

func (*ClassDeclarationNode) SetClassNameNode

func (c *ClassDeclarationNode) SetClassNameNode(node *sitter.Node)

Setter methods for Tree-Sitter nodes

func (*ClassDeclarationNode) SetConstructorNode

func (c *ClassDeclarationNode) SetConstructorNode(node *sitter.Node)

func (*ClassDeclarationNode) SetDecoratorNodes

func (c *ClassDeclarationNode) SetDecoratorNodes(nodes []*sitter.Node)

func (*ClassDeclarationNode) SetFieldNodes

func (c *ClassDeclarationNode) SetFieldNodes(nodes []*sitter.Node)

func (*ClassDeclarationNode) SetIsAbstract

func (c *ClassDeclarationNode) SetIsAbstract(isAbstract bool)

func (*ClassDeclarationNode) SetMethodNodes

func (c *ClassDeclarationNode) SetMethodNodes(nodes []*sitter.Node)

func (*ClassDeclarationNode) String

func (c *ClassDeclarationNode) String() string

String returns a string representation of the ClassDeclarationNode for debugging

type Content

type Content *[]byte

TreeSitter requires the content to be available to get the symbols from the source code for a given node

func ToContent

func ToContent(data []byte) Content

type FunctionDeclarationNode

type FunctionDeclarationNode struct {
	Node
	// contains filtered or unexported fields
}

FunctionDeclarationNode represents a function declaration with comprehensive metadata This is a language agnostic representation of a function declaration. Not all attributes may be present in all languages

func NewFunctionDeclarationNode

func NewFunctionDeclarationNode(content Content) *FunctionDeclarationNode

NewFunctionDeclarationNode creates a new FunctionDeclarationNode instance

func (*FunctionDeclarationNode) AddDecoratorNode

func (f *FunctionDeclarationNode) AddDecoratorNode(node *sitter.Node)

AddDecoratorNode adds a decorator/annotation node

func (*FunctionDeclarationNode) AddFunctionParameterNode

func (f *FunctionDeclarationNode) AddFunctionParameterNode(node *sitter.Node)

AddFunctionParameterNode adds a parameter node

func (*FunctionDeclarationNode) Body

func (f *FunctionDeclarationNode) Body() string

Body returns the function body content

func (*FunctionDeclarationNode) Decorators

func (f *FunctionDeclarationNode) Decorators() []string

Decorators returns the content of all decorator/annotation nodes

func (*FunctionDeclarationNode) FunctionName

func (f *FunctionDeclarationNode) FunctionName() string

FunctionName returns the name of the function

func (*FunctionDeclarationNode) GetAccessModifier

func (f *FunctionDeclarationNode) GetAccessModifier() AccessModifier

GetAccessModifier returns the access modifier of the function

func (*FunctionDeclarationNode) GetFunctionNameNode

func (f *FunctionDeclarationNode) GetFunctionNameNode() *sitter.Node

GetFunctionNameNode returns the function name node

func (*FunctionDeclarationNode) GetFunctionType

func (f *FunctionDeclarationNode) GetFunctionType() FunctionType

GetFunctionType returns the type/category of the function

func (*FunctionDeclarationNode) GetParentClassName

func (f *FunctionDeclarationNode) GetParentClassName() string

GetParentClassName returns the name of the parent class (for methods)

func (*FunctionDeclarationNode) HasDecorators

func (f *FunctionDeclarationNode) HasDecorators() bool

HasDecorators returns true if the function has decorators/annotations

func (*FunctionDeclarationNode) IsAbstract

func (f *FunctionDeclarationNode) IsAbstract() bool

IsAbstract returns true if the function is abstract

func (*FunctionDeclarationNode) IsAsync

func (f *FunctionDeclarationNode) IsAsync() bool

IsAsync returns true if the function is async

func (*FunctionDeclarationNode) IsConstructor

func (f *FunctionDeclarationNode) IsConstructor() bool

IsConstructor returns true if this function is a constructor

func (*FunctionDeclarationNode) IsMethod

func (f *FunctionDeclarationNode) IsMethod() bool

IsMethod returns true if this function is a class method

func (*FunctionDeclarationNode) IsStatic

func (f *FunctionDeclarationNode) IsStatic() bool

IsStatic returns true if the function is static

func (*FunctionDeclarationNode) Parameters

func (f *FunctionDeclarationNode) Parameters() []string

Parameters returns the content of all parameter nodes

func (*FunctionDeclarationNode) ReturnType

func (f *FunctionDeclarationNode) ReturnType() string

ReturnType returns the return type of the function if available

func (*FunctionDeclarationNode) SetAccessModifier

func (f *FunctionDeclarationNode) SetAccessModifier(modifier AccessModifier)

SetAccessModifier sets the access modifier

func (*FunctionDeclarationNode) SetFunctionBodyNode

func (f *FunctionDeclarationNode) SetFunctionBodyNode(node *sitter.Node)

SetFunctionBodyNode sets the function body node

func (*FunctionDeclarationNode) SetFunctionNameNode

func (f *FunctionDeclarationNode) SetFunctionNameNode(node *sitter.Node)

SetFunctionNameNode sets the function name node

func (*FunctionDeclarationNode) SetFunctionParameterNodes

func (f *FunctionDeclarationNode) SetFunctionParameterNodes(nodes []*sitter.Node)

SetFunctionParameterNodes sets all parameter nodes

func (*FunctionDeclarationNode) SetFunctionReturnTypeNode

func (f *FunctionDeclarationNode) SetFunctionReturnTypeNode(node *sitter.Node)

SetFunctionReturnTypeNode sets the return type node

func (*FunctionDeclarationNode) SetFunctionType

func (f *FunctionDeclarationNode) SetFunctionType(funcType FunctionType)

SetFunctionType sets the function type/category

func (*FunctionDeclarationNode) SetIsAbstract

func (f *FunctionDeclarationNode) SetIsAbstract(abstract bool)

SetIsAbstract sets the abstract flag

func (*FunctionDeclarationNode) SetIsAsync

func (f *FunctionDeclarationNode) SetIsAsync(async bool)

SetIsAsync sets the async flag

func (*FunctionDeclarationNode) SetIsStatic

func (f *FunctionDeclarationNode) SetIsStatic(static bool)

SetIsStatic sets the static flag

func (*FunctionDeclarationNode) SetParentClassName

func (f *FunctionDeclarationNode) SetParentClassName(className string)

SetParentClassName sets the parent class name (for methods)

type FunctionType

type FunctionType string

FunctionType represents the type/category of function

const (
	// FunctionTypeFunction represents a regular function
	FunctionTypeFunction FunctionType = "function"

	// FunctionTypeMethod represents a class method
	FunctionTypeMethod FunctionType = "method"

	// FunctionTypeConstructor represents a constructor function
	FunctionTypeConstructor FunctionType = "constructor"

	// FunctionTypeStaticMethod represents a static class method
	FunctionTypeStaticMethod FunctionType = "static_method"

	// FunctionTypeAsync represents an async function
	FunctionTypeAsync FunctionType = "async"

	// FunctionTypeArrow represents an arrow function (JavaScript)
	FunctionTypeArrow FunctionType = "arrow"

	// FunctionTypeUnknown represents unknown function type
	FunctionTypeUnknown FunctionType = "unknown"
)

type ImportNode

type ImportNode struct {
	Node
	// contains filtered or unexported fields
}

ImportNode represents an import statement in a source file This is a language agnostic representation of an import statement. Not all attributes may be present in all languages

func NewImportNode

func NewImportNode(content Content) *ImportNode

NewImportNode creates a new ImportNode instance using the import statement node from the tree-sitter parser

func (*ImportNode) GetModuleAliasNode

func (i *ImportNode) GetModuleAliasNode() *sitter.Node

func (*ImportNode) GetModuleItemNode

func (i *ImportNode) GetModuleItemNode() *sitter.Node

func (*ImportNode) GetModuleNameNode

func (i *ImportNode) GetModuleNameNode() *sitter.Node

func (*ImportNode) IsWildcardImport

func (i *ImportNode) IsWildcardImport() bool

func (*ImportNode) ModuleAlias

func (i *ImportNode) ModuleAlias() string

func (*ImportNode) ModuleItem

func (i *ImportNode) ModuleItem() string

func (*ImportNode) ModuleName

func (i *ImportNode) ModuleName() string

func (*ImportNode) SetIsWildcardImport

func (i *ImportNode) SetIsWildcardImport(isWildcardImport bool)

func (*ImportNode) SetModuleAliasNode

func (i *ImportNode) SetModuleAliasNode(node *sitter.Node)

func (*ImportNode) SetModuleItemNode

func (i *ImportNode) SetModuleItemNode(node *sitter.Node)

func (*ImportNode) SetModuleNameNode

func (i *ImportNode) SetModuleNameNode(node *sitter.Node)

func (*ImportNode) String

func (i *ImportNode) String() string

type InheritanceGraph

type InheritanceGraph struct {
	// contains filtered or unexported fields
}

InheritanceGraph manages the complete inheritance hierarchy for a codebase

func BuildInheritanceGraphFromClasses

func BuildInheritanceGraphFromClasses(classes []*ClassDeclarationNode, defaultFile string) *InheritanceGraph

BuildInheritanceGraphFromClasses creates an inheritance graph from ClassDeclarationNode instances

func NewInheritanceGraph

func NewInheritanceGraph() *InheritanceGraph

NewInheritanceGraph creates a new empty inheritance graph

func (*InheritanceGraph) AddRelationship

func (ig *InheritanceGraph) AddRelationship(child, parent string, relType RelationshipType, file string, line uint32) *InheritanceRelationship

AddRelationship adds a direct inheritance relationship to the graph

func (*InheritanceGraph) DetectCircularInheritance

func (ig *InheritanceGraph) DetectCircularInheritance() [][]string

DetectCircularInheritance detects circular inheritance relationships

func (*InheritanceGraph) GetAllClasses

func (ig *InheritanceGraph) GetAllClasses() []string

GetAllClasses returns all classes known to the inheritance graph

func (*InheritanceGraph) GetAncestry

func (ig *InheritanceGraph) GetAncestry(className string) []string

GetAncestry returns all ancestor classes (parents, grandparents, etc.) in breadth-first order

func (*InheritanceGraph) GetDescendants

func (ig *InheritanceGraph) GetDescendants(className string) []string

GetDescendants returns all descendant classes (children, grandchildren, etc.) in breadth-first order

func (*InheritanceGraph) GetDirectChildNames

func (ig *InheritanceGraph) GetDirectChildNames(className string) []string

GetDirectChildNames returns the names of direct child classes

func (*InheritanceGraph) GetDirectChildren

func (ig *InheritanceGraph) GetDirectChildren(className string) []*InheritanceRelationship

GetDirectChildren returns all direct child relationships for a class

func (*InheritanceGraph) GetDirectParentNames

func (ig *InheritanceGraph) GetDirectParentNames(className string) []string

GetDirectParentNames returns the names of direct parent classes

func (*InheritanceGraph) GetDirectParents

func (ig *InheritanceGraph) GetDirectParents(className string) []*InheritanceRelationship

GetDirectParents returns all direct parent relationships for a class

func (*InheritanceGraph) GetInheritanceDepth

func (ig *InheritanceGraph) GetInheritanceDepth(child, ancestor string) int

GetInheritanceDepth returns the minimum depth from child to ancestor Returns -1 if no inheritance relationship exists

func (*InheritanceGraph) GetLeafClasses

func (ig *InheritanceGraph) GetLeafClasses() []string

GetLeafClasses returns classes that have no children (leaves of inheritance hierarchies)

func (*InheritanceGraph) GetMethodResolutionOrder

func (ig *InheritanceGraph) GetMethodResolutionOrder(className string) []string

GetMethodResolutionOrder calculates the Method Resolution Order using C3 linearization This is primarily for Python-style multiple inheritance

func (*InheritanceGraph) GetRootClasses

func (ig *InheritanceGraph) GetRootClasses() []string

GetRootClasses returns classes that have no parents (root of inheritance hierarchies)

func (*InheritanceGraph) GetStatistics

func (ig *InheritanceGraph) GetStatistics() map[string]interface{}

GetStatistics returns statistics about the inheritance graph

func (*InheritanceGraph) IsAncestor

func (ig *InheritanceGraph) IsAncestor(ancestor, descendant string) bool

IsAncestor checks if ancestor is an ancestor of descendant

func (*InheritanceGraph) IsDescendant

func (ig *InheritanceGraph) IsDescendant(descendant, ancestor string) bool

IsDescendant checks if descendant is a descendant of ancestor

func (*InheritanceGraph) MergeFrom

func (ig *InheritanceGraph) MergeFrom(other *InheritanceGraph)

MergeFrom merges inheritance information from another graph

func (*InheritanceGraph) String

func (ig *InheritanceGraph) String() string

String returns a string representation of the inheritance graph

type InheritanceRelationship

type InheritanceRelationship struct {
	// Core relationship information
	ChildClassName   string
	ParentClassName  string
	RelationshipType RelationshipType

	// Source location information
	FileLocation string
	LineNumber   uint32

	// Relationship metadata
	IsDirectInheritance bool // true for immediate parent, false for computed ancestor
	InheritanceDepth    int  // 1 for direct parent, 2 for grandparent, etc.

	// Additional context
	ModuleName string // Module/package where relationship is declared
}

InheritanceRelationship represents a single parent-child class relationship

func NewInheritanceRelationship

func NewInheritanceRelationship(child, parent string, relType RelationshipType, file string, line uint32) *InheritanceRelationship

NewInheritanceRelationship creates a new direct inheritance relationship

func (*InheritanceRelationship) String

func (ir *InheritanceRelationship) String() string

String returns a string representation of the inheritance relationship

type Node

type Node struct {
	// contains filtered or unexported fields
}

type NodePosition

type NodePosition struct {
	StartByte   uint32
	EndByte     uint32
	StartLine   uint32
	EndLine     uint32
	StartColumn uint32
	EndColumn   uint32
}

NodePosition represents position information for a Tree-Sitter node

func GetNodePosition

func GetNodePosition(node *sitter.Node) NodePosition

GetNodePosition extracts position information from a Tree-Sitter node

type RelationshipType

type RelationshipType string

RelationshipType represents the type of inheritance relationship

const (
	// RelationshipTypeExtends represents single inheritance (Go, Java single inheritance)
	RelationshipTypeExtends RelationshipType = "extends"

	// RelationshipTypeImplements represents interface implementation (Go, Java)
	RelationshipTypeImplements RelationshipType = "implements"

	// RelationshipTypeInherits represents general inheritance (Python multiple inheritance)
	RelationshipTypeInherits RelationshipType = "inherits"

	// RelationshipTypeMixin represents mixin inheritance patterns
	RelationshipTypeMixin RelationshipType = "mixin"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL