Class DefaultBuilderProvider

  • All Implemented Interfaces:
    BuilderProvider
    Direct Known Subclasses:
    ImmutablesBuilderProvider

    public class DefaultBuilderProvider
    extends Object
    implements BuilderProvider
    Default implementation of BuilderProvider. The default builder provider considers all public static parameterless methods of a TypeMirror as potential builder creation methods. For each potential builder creation method checks in the return type of the method if there exists a method that returns the initial TypeMirror if such a combination is found the BuilderInfo is created with those 2 methods. Example:
    
     public class Person {
    
         private final String firstName;
         private final String lastName;
    
         private Person(String firstName, String lastName) {
             this.firstName = firstName;
             this.lastName = lastName;
         }
    
         //getters
    
         public static Builder builder() {
             return new Builder();
         }
    
         public static class Builder {
    
             private String firstName;
             private String lastName;
    
             private Builder() {}
    
             //fluent setters
    
             public Person create() {
                 return new Person( firstName, lastName );
             }
         }
     }
     
    In the example above, when searching for a builder for the Person type. The Person#builder method would be a builder creation candidate. Then the return type of Person#builder, Builder, is investigated for a parameterless method that returns Person. When Builder#create is found the BuilderInfo is created with the Person#builder as a builder creation method and Builder#create as a build method.

    IMPORTANT: Types from the java and javax packages are excluded from inspection

    Author:
    Filip Hrisafov