Documentation
¶
Overview ¶
Package javaast provides shared Java AST traversal utilities for test framework parsers.
Index ¶
- Constants
- Variables
- func GetAnnotationArgument(annotation *sitter.Node, source []byte) string
- func GetAnnotationName(annotation *sitter.Node, source []byte) string
- func GetAnnotations(modifiers *sitter.Node) []*sitter.Node
- func GetClassBody(node *sitter.Node) *sitter.Node
- func GetClassName(node *sitter.Node, source []byte) string
- func GetMethodName(node *sitter.Node, source []byte) string
- func GetModifiers(node *sitter.Node) *sitter.Node
- func HasAnnotation(modifiers *sitter.Node, source []byte, annotationName string) bool
- func SanitizeSource(source []byte) []byte
- type JavaTestFileMatcher
Constants ¶
const ( NodeClassDeclaration = "class_declaration" NodeMethodDeclaration = "method_declaration" NodeAnnotation = "annotation" NodeMarkerAnnotation = "marker_annotation" NodeModifiers = "modifiers" NodeIdentifier = "identifier" NodeFormalParameters = "formal_parameters" NodeClassBody = "class_body" NodeAnnotationArgumentList = "annotation_argument_list" )
Java AST node types.
Variables ¶
var ( // JUnit4ImportPattern detects JUnit 4 imports (org.junit.Test, org.junit.Assert, org.junit.*, etc.) // Matches: org.junit.Test, org.junit.Assert, org.junit.* (wildcard) // Does NOT match: org.junit.jupiter (handled by JUnit5ImportPattern) JUnit4ImportPattern = regexp.MustCompile(`import\s+(?:static\s+)?org\.junit\.(?:\*|[A-Z])`) // JUnit5ImportPattern detects JUnit 5 (Jupiter) imports JUnit5ImportPattern = regexp.MustCompile(`import\s+(?:static\s+)?org\.junit\.jupiter`) )
Import patterns for JUnit version detection.
Functions ¶
func GetAnnotationArgument ¶
GetAnnotationArgument extracts the annotation argument value. For @DisplayName("My Test"), returns "My Test".
func GetAnnotationName ¶
GetAnnotationName extracts the simple annotation name (e.g., "Test" from @Test or @org.junit.jupiter.api.Test). For scoped identifiers, returns only the simple name (last segment).
func GetAnnotations ¶
GetAnnotations extracts all annotation nodes from a modifiers node.
func GetClassBody ¶
GetClassBody returns the class body node from a class_declaration.
func GetClassName ¶
GetClassName extracts the class name from a class_declaration node.
func GetMethodName ¶
GetMethodName extracts the method name from a method_declaration node.
func GetModifiers ¶
GetModifiers returns the modifiers node from a method or class declaration.
func HasAnnotation ¶
HasAnnotation checks if the modifiers contain a specific annotation.
func SanitizeSource ¶ added in v1.5.0
SanitizeSource removes NULL bytes from source code that would cause tree-sitter parsing failures. Some files (e.g., OSS-Fuzz test data) contain NULL bytes in string literals which cause tree-sitter to produce ERROR nodes instead of valid AST.
Types ¶
type JavaTestFileMatcher ¶ added in v1.5.0
type JavaTestFileMatcher struct{}
JavaTestFileMatcher matches common Java test file naming patterns. Supports: *Test.java, *Tests.java, Test*.java Excludes: src/main/ (production code in Maven/Gradle structure)
func (*JavaTestFileMatcher) Match ¶ added in v1.5.0
func (m *JavaTestFileMatcher) Match(ctx context.Context, signal framework.Signal) framework.MatchResult