square/javapoet

How to control indentation of Annotation members

Closed this issue · 6 comments

I generate code like this, but i have not find the way to control the indentation of annotation members

import java.lang.Long;
import java.lang.String;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Generated by javapeot
 */
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(
        name = "user"
)
public class User {
    @Id
    @GeneratedValue(
            strategy = GenerationType.IDENTITY
    )
    @Column(
            name = "id"
    )
    private Long id;

    @Column(
            name = "name"
    )
    private String name;

    @Column(
            name = "created_at"
    )
    private Timestamp createdAt;
}

I want this:

@GeneratedValue(
        strategy = GenerationType.IDENTITY
)

to be

@GeneratedValue(strategy = GenerationType.IDENTITY)

This is the annotation creation method:

    private AnnotationSpec createJpaColumnAnnotation(String columnName) {
        return AnnotationSpec.builder(ClassName.get("javax.persistence", "Column"))
            .addMember("name", "$S", columnName)
            .build();
    }

We don't have APIs to customize indentation. But if there's a change we should make to the defaults please send a pull request!

I think the compact type of annotations is usually preferred. Would you guys be OK with changing the default to that?

Then this issue can be closed or is there a plan to add APIs to customize indentation?