Skip to content

io microsphere lang model util AnnotatedElementJSONElementVisitor

github-actions[bot] edited this page Apr 11, 2026 · 5 revisions

AnnotatedElementJSONElementVisitor

Type: Class | 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/AnnotatedElementJSONElementVisitor.java

Overview

An abstract implementation of ElementVisitor that generates JSON content for elements annotated with a specific annotation.

This class extends io.microsphere.lang.model.util.JSONElementVisitor, providing functionality to filter and process only those elements that are annotated with the specified annotation. It leverages the annotation processing environment to gather information about the annotated elements and constructs JSON representations accordingly.

Example Usage

Suppose you have a custom annotation:

{@code

### Declaration

```java
public abstract class AnnotatedElementJSONElementVisitor extends JSONElementVisitor
```

**Author:** Mercy

## Version Information

- **Introduced in:** `1.0.0`
- **Current Project Version:** `0.2.8-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

### Example 1

```java
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface MyAnnotation {
}
```

### Example 2

```java
public class MyAnnotatedElementVisitor extends AnnotatedElementJSONElementVisitor {

    public MyAnnotatedElementVisitor(ProcessingEnvironment processingEnv, String annotationClassName) {
        super(processingEnv, annotationClassName);
    }

    @Override
    protected boolean doVisitType(TypeElement e, StringBuilder jsonBuilder) {
        // Custom logic to generate JSON for the type element
        jsonBuilder.append("{");
        jsonBuilder.append("\"name\":").append("\"").append(e.getSimpleName()).append("\"");
        jsonBuilder.append("}");
        return true;
    }
}
```

## Usage

### Maven Dependency

Add the following dependency to your `pom.xml`:

```xml

    io.github.microsphere-projects
    microsphere-lang-model
    ${microsphere-java.version}

```

> **Tip:** Use the BOM (`microsphere-java-dependencies`) for consistent version management. See the [Getting Started](https://github.com/microsphere-projects/microsphere-java#getting-started) guide.

### Import

```java
import io.microsphere.lang.model.util.AnnotatedElementJSONElementVisitor;
```

## API Reference

### Public Methods

| Method | Description |
|--------|-------------|
| `getAnnotationClassName` | Get the annotation class name |

## See Also

- `io.microsphere.lang.model.util.JSONElementVisitor`
- `AnnotatedElement`
- `Annotation`
- `ElementType`

---

*This documentation was auto-generated from the source code of [microsphere-java](https://github.com/microsphere-projects/microsphere-java).*

Home

annotation-processor

java-annotations

java-core

java-test

jdk-tools

lang-model

Clone this wiki locally