org.inferred.freebuilder.processor.source.Excerpts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of freebuilder Show documentation
Show all versions of freebuilder Show documentation
Automatic generation of the Builder pattern for Java 1.6+
package org.inferred.freebuilder.processor.source;
import org.inferred.freebuilder.processor.source.feature.JavaxPackage;
public class Excerpts {
public static final Excerpt EMPTY = code -> { };
public static Excerpt add(String fmt, Object... args) {
return code -> code.add(fmt, args);
}
/**
* Returns an excerpt of the {@link javax.annotation.Generated} annotation, if available,
* with value set to the full name of the {@code generator} class as recommended.
*/
public static Excerpt generated(Class> generator) {
return code -> {
code.feature(JavaxPackage.JAVAX).generated().ifPresent(generated -> {
code.addLine("@%s(\"%s\")", generated, generator.getName());
});
};
}
public static Excerpt join(String separator, Iterable> excerpts) {
return code -> appendJoined(code, separator, excerpts);
}
private static void appendJoined(SourceBuilder source, String separator, Iterable> excerpts) {
String itemPrefix = "";
for (Object object : excerpts) {
source.add("%s%s", itemPrefix, object);
itemPrefix = separator;
}
}
private Excerpts() {}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy