Skip to content

io microsphere lang model util AnnotationUtils

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

AnnotationUtils

Type: Interface | Module: microsphere-lang-model | Package: io.microsphere.lang.model.util | Since: 1.0.0

Source: microsphere-lang-model/src/main/java/io/microsphere/lang/model/util/AnnotationUtils.java

Overview

A utility interface for working with annotations in the javax.lang.model.* package.

This interface provides methods to retrieve, filter, and check annotations and their attributes from various constructs such as Element, TypeMirror, and others commonly used in annotation processing.

Example Usage

`// Retrieve a specific annotation from an element
AnnotationMirror annotation = AnnotationUtils.getAnnotation(element, MyAnnotation.class);

// Retrieve all annotations from a type
List annotations = AnnotationUtils.getAnnotations(typeMirror);

// Check if an annotation is present on an element
boolean present = AnnotationUtils.isAnnotationPresent(element, MyAnnotation.class);

// Find meta-annotations on an annotation
AnnotationMirror metaAnnotation = AnnotationUtils.findMetaAnnotation(annotation, MyMetaAnnotation.class);
`

This interface is intended to be implemented by classes that provide static utility methods for handling annotations during annotation processing. It helps in organizing and reusing common operations related to annotations.

Declaration

public interface AnnotationUtils extends Utils

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

// Retrieve a specific annotation from an element
AnnotationMirror annotation = AnnotationUtils.getAnnotation(element, MyAnnotation.class);

// Retrieve all annotations from a type
List<AnnotationMirror> annotations = AnnotationUtils.getAnnotations(typeMirror);

// Check if an annotation is present on an element
boolean present = AnnotationUtils.isAnnotationPresent(element, MyAnnotation.class);

// Find meta-annotations on an annotation
AnnotationMirror metaAnnotation = AnnotationUtils.findMetaAnnotation(annotation, MyMetaAnnotation.class);

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-lang-model</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.lang.model.util.AnnotationUtils;

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally