Skip to content

feat: add composable annotation support and meta-annotation processing - #1076

Open
bengbengbalabalabeng wants to merge 12 commits into
apache:mainfrom
bengbengbalabalabeng:feat-composable-annotations-path2
Open

feat: add composable annotation support and meta-annotation processing#1076
bengbengbalabalabeng wants to merge 12 commits into
apache:mainfrom
bengbengbalabalabeng:feat-composable-annotations-path2

Conversation

@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor

Purpose of the pull request

As title.

Related: #918
Closed: #920 (previous development draft)

What's changed?

  1. Introduce two meta-annotations, @FesodMarked and @FesodMarked.AliasFor, to expand the Target - ElementType#ANNOTATION_TYPE restriction scope for other internal annotations except @ExcelIgnore and @ExcelIgnoreUnannotated, making it convenient for users to define custom combined annotations (Included third-party annotations).
  2. Added AnnotatedElementUtils utility class to handle composable-annotations lookup.
  3. Wire the lookups into ClassUtils and ExcelWriteHeadProperty, covering both read and write paths; behavior of directly-declared annotations is unchanged.
  4. Added introduction document.

Example

// Define
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FesodMarked
@ExcelProperty
@ColumnWidth(20)
public @interface TitledColumn {

    @FesodMarked.AliasFor(annotation = ExcelProperty.class, attribute = "value")
    String title() default "";
}

// Use
// Same as:
// @ExcelProperty(value = {"NAME"})
// @ColumnWidth(value = 20)
@TitledColumn(title = "NAME")
private String name;

Precedence and Override Rules

(Detailed examples are provided in annotation.md; only the core rules are listed here.)

  • Annotation Level: Directly declared target annotation > Composed annotation. The directly declared target annotation wins entirely, and any matching target annotation inside composed annotations is completely ignored.
  • Composed Annotation Attribute Level: Within an active composed annotation, @FesodMarked.AliasFor values (including defaults) > Static preset values.

Checklist

  • I have read the Contributor Guide.
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

- Introduce two meta-annotations, @FesodMarked and @FesodMarked.AliasFor, to expand the Target - ElementType#ANNOTATION_TYPE restriction scope for other internal annotations except @ExcelIgnore and @ExcelIgnoreUnannotated, making it convenient for users to define custom combined annotations.
- Define AnnotatedElementUtils to refactor the internal annotation parsing and access.
- Added unit tests for AnnotatedElementUtils, and covering:
  - Merge priority
  - AliasFor semantics
  - Synthesized proxies
  - Fail-fast validation
Simplify the handling of annotation types declared more than once during scanning into a single rule: the first occurrence wins wholesale.
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