All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mapstruct.ap.spi.BuilderInfo Maven / Gradle / Ivy

/*
 * Copyright MapStruct Authors.
 *
 * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
 */
package org.mapstruct.ap.spi;

import java.util.Collection;
import javax.lang.model.element.ExecutableElement;

/**
 * Holder for the builder information.
 *
 * @author Filip Hrisafov
 *
 * @since 1.3
 */
public class BuilderInfo {

    private final ExecutableElement builderCreationMethod;
    private final Collection buildMethods;

    private BuilderInfo(ExecutableElement builderCreationMethod, Collection buildMethods) {
        this.builderCreationMethod = builderCreationMethod;
        this.buildMethods = buildMethods;
    }

    /**
     * The method that can be used for instantiating a builder. This can be:
     * 
    *
  • A {@code public static} method in the type being build
  • *
  • A {@code public static} method in the builder itself
  • *
  • The default constructor of the builder
  • *
* * @return the creation method for the builder */ public ExecutableElement getBuilderCreationMethod() { return builderCreationMethod; } /** * The methods that can be used to build the type being built. * This should be {@code public} methods within the builder itself * * @return the build method for the type */ public Collection getBuildMethods() { return buildMethods; } public static class Builder { private ExecutableElement builderCreationMethod; private Collection buildMethods; /** * @param method The creation method for the builder * * @return the builder for chaining * * @see BuilderInfo#getBuilderCreationMethod() */ public Builder builderCreationMethod(ExecutableElement method) { this.builderCreationMethod = method; return this; } /** * @param methods the build methods for the type * * @return the builder for chaining * * @see BuilderInfo#getBuildMethods() */ public Builder buildMethod(Collection methods) { this.buildMethods = methods; return this; } /** * Create the {@link BuilderInfo}. * * @return the created {@link BuilderInfo} * * @throws IllegalArgumentException if the builder creation or build methods are {@code null} */ public BuilderInfo build() { if ( builderCreationMethod == null ) { throw new IllegalArgumentException( "Builder creation method is mandatory" ); } else if ( buildMethods == null ) { throw new IllegalArgumentException( "Build methods are mandatory" ); } else if ( buildMethods.isEmpty() ) { throw new IllegalArgumentException( "Build methods must not be empty" ); } return new BuilderInfo( builderCreationMethod, buildMethods ); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy