javaast

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package javaast provides shared Java AST traversal utilities for test framework parsers.

Index

Constants

View Source
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

View Source
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

func GetAnnotationArgument(annotation *sitter.Node, source []byte) string

GetAnnotationArgument extracts the annotation argument value. For @DisplayName("My Test"), returns "My Test".

func GetAnnotationName

func GetAnnotationName(annotation *sitter.Node, source []byte) string

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

func GetAnnotations(modifiers *sitter.Node) []*sitter.Node

GetAnnotations extracts all annotation nodes from a modifiers node.

func GetClassBody

func GetClassBody(node *sitter.Node) *sitter.Node

GetClassBody returns the class body node from a class_declaration.

func GetClassName

func GetClassName(node *sitter.Node, source []byte) string

GetClassName extracts the class name from a class_declaration node.

func GetMethodName

func GetMethodName(node *sitter.Node, source []byte) string

GetMethodName extracts the method name from a method_declaration node.

func GetModifiers

func GetModifiers(node *sitter.Node) *sitter.Node

GetModifiers returns the modifiers node from a method or class declaration.

func HasAnnotation

func HasAnnotation(modifiers *sitter.Node, source []byte, annotationName string) bool

HasAnnotation checks if the modifiers contain a specific annotation.

func SanitizeSource added in v1.5.0

func SanitizeSource(source []byte) []byte

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

Jump to

Keyboard shortcuts

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