Skip to content

feat: add annotation type support to parser and autocomplete#112

Open
abanchev wants to merge 1 commit intobobbylight:masterfrom
abanchev:feat/annotation-support
Open

feat: add annotation type support to parser and autocomplete#112
abanchev wants to merge 1 commit intobobbylight:masterfrom
abanchev:feat/annotation-support

Conversation

@abanchev
Copy link

@abanchev abanchev commented Mar 14, 2026

Summary

  • Parse @interface declarations in ASTFactory — previously the parser threw an IOException when encountering annotation type declarations, preventing the entire source file from being parsed
  • Filter completions after @ to show only annotation types, not methods/fields/local variables
  • Add annotation parameter completion inside @Annotation(...) with element names and Javadoc from source attachments
  • Add isAnnotationType() helper to ClassCompletion using ACC_ANNOTATION access flag

Motivation

The parser had no support for @interface declarations at all. When a source file contained an annotation type definition (e.g. @interface Serialize), the ASTFactory threw an IOException which was caught and treated as a parse error — meaning the entire file couldn't be parsed and no completions were available.

Additionally, typing @ before an annotation name showed all completions (methods, fields, local variables) instead of filtering to just annotation types. And inside annotation parentheses like @Serialize(tooltip=..., readOnly=...), there was no completion for the annotation's element names.

Changes

Parser (ASTFactory.java):

  • getClassOrInterfaceDeclaration: ANNOTATION_START case consumes @ + interface keyword, delegates to getNormalInterfaceDeclaration
  • getInterfaceMemberDecl: tolerates default clauses on annotation elements

Autocomplete (SourceCompletionProvider.java):

  • isAnnotationContext(): detects @ character before entered text
  • Annotation type filtering: when in @ context, removes non-annotation completions
  • getAnnotationClassName(): scans backward through balanced parens to detect @Name(...) context
  • addAnnotationElementCompletions(): resolves annotation ClassFile, iterates element methods, creates completions with Javadoc from source

ClassCompletion.java:

  • isAnnotationType(): checks ACC_ANNOTATION bit on class access flags

Test plan

  • 4 new AnnotationTypeDeclarationTest cases: simple @interface, with defaults, with imports, body elements
  • 2 new SourceCompletionProviderTest cases: @ prefix detection
  • All existing tests pass
  • Manual testing: @Ser shows only annotation types, @Serialize( shows element names with Javadoc

- Parse @interface declarations in ASTFactory (previously threw IOException)
- Filter completions after '@' to show only annotation types
- Add annotation parameter completion inside @annotation(...)
- Resolve annotation element Javadoc from source attachments
@abanchev abanchev force-pushed the feat/annotation-support branch from 3fb428d to cd12700 Compare March 14, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant