#2952·ast-grep

outline: Java annotation types and elements are missing from java.yml

Author: michal-michalukCreated Sep 19, 2026Updated Sep 19, 2026

Summary

Java annotation declarations produce no outline elements at all: neither the @interface type (annotation_type_declaration) nor its elements (annotation_type_element_declaration).

Evidence

  • Grammar: tree-sitter-java 0.23.5 src/node-types.json defines both annotation_type_declaration and annotation_type_element_declaration.
  • Schema: schemas/java_rule.json lists both kinds.
  • Rules: crates/outline/src/default_rules/java.yml has no rule for either.

Current behaviour (measured on main)

For:

java
public @interface A {
  String value();
  int count() default 0;
}

the outline is empty - the declaration produces no item and no members.

Proposed fix

Two rules that ship together, because the element rule is scoped to the annotation type item:

yaml
id: java-annotation-type
language: Java
role: item
symbolType: interface
rule:
  all:
    - kind: annotation_type_declaration
    - has:
        field: name
        pattern: $NAME
name: $NAME
isExported:
  has:
    kind: modifiers
    has:
      pattern: public
---
id: java-annotation-element
language: Java
role: member
parentRuleIds: [java-annotation-type]
symbolType: method
rule:
  all:
    - kind: annotation_type_element_declaration
    - has:
        field: name
        pattern: $NAME
name: $NAME
isPublic: true

symbolType: interface for the type mirrors how other languages map their annotation/decorator declarations; method for the elements mirrors how annotation-type members read as callables. Happy to adjust either mapping if you prefer a different one.

I have this prepared with a test; a PR follows.