Skip to content

Commit

Permalink
Merge pull request #17 from micronaut-projects/add-docs
Browse files Browse the repository at this point in the history
docs: Add some docs
  • Loading branch information
graemerocher authored Dec 19, 2023
2 parents c4c33a3 + 62e46f6 commit 22535bf
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
projectVersion=1.0.0-SNAPSHOT
projectGroup=io.micronaut.sourcegen

title=Micronaut Sourcegen
projectDesc=Compilation time source code generators
title=Compilation time source code generators
projectDesc=Micronaut SourceGen exposes a language-neutral API for source code generation.
projectUrl=https://micronaut.io
githubSlug=micronaut-projects/micronaut-sourcegen
developers=Denis Stepanov
Expand Down
32 changes: 32 additions & 0 deletions src/main/docs/guide/annotations.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
The module Micronaut SourceGen annotations ships with annotations which you can use in your projects:

To use them, you need the following dependency:

dependency:micronaut-sourcegen-annotations[groupId=io.micronaut.sourcegen]

dependency:micronaut-sourcegen-annotations[groupId=io.micronaut.sourcegen,scope=annotationProcessor]

[options="header"]
|===
| Annotation | Description

| api:sourcegen.annotations.Builder[]
| Create a builder of the annotated type.
|===


If you annotate a Java Record with `@Builder`, a `PersonBuilder` class is generated at compliation-time.

[source,java]
----
include::test-suite-java/src/main/java/io/micronaut/sourcegen/example/Person.java[tags=clazz,indent=0]
----

You can use a https://blogs.oracle.com/javamagazine/post/exploring-joshua-blochs-builder-design-pattern-in-java[builder pattern] to create a `Person` instance:

[source,java]
----
include::test-suite-java/src/test/java/io/micronaut/sourcegen/example/PersonBuilderTest.java[tags=test,indent=0]
----

NOTE: The https://github.com/micronaut-projects/micronaut-sourcegen/blob/master/sourcegen-generator/src/main/java/io/micronaut/sourcegen/generator/visitors/BuilderAnnotationVisitor.java[BuilderAnnotationVisitor] is an example of how to use the Micronaut SourceGen API.
2 changes: 1 addition & 1 deletion src/main/docs/guide/introduction.adoc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TODO
Micronaut SourceGen exposes a language-neutral API for source code generation. It uses https://github.com/square/javapoet[JavaPoet] internally.
1 change: 0 additions & 1 deletion src/main/docs/guide/quickStart.adoc

This file was deleted.

3 changes: 1 addition & 2 deletions src/main/docs/guide/toc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
introduction:
title: Introduction
releaseHistory: Release History
quickStart:
title: Quick Start
annotations: Annotations
repository: Repository

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
package io.micronaut.sourcegen.example;


//tag::clazz[]
import io.micronaut.sourcegen.annotations.Builder;

@Builder
public record Person(Long id, String name) {
}
//end::clazz[]
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

class PersonBuilderTest {

//tag::test[]
@Test
public void buildsPerson() {
var person = PersonBuilder.builder()
Expand All @@ -29,4 +31,5 @@ public void buildsPerson() {
assertEquals("Cédric", person.name());
assertEquals(123L, person.id());
}
//end::test[]
}

0 comments on commit 22535bf

Please sign in to comment.