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

ch.powerunit.extensions.matchers.common.FactoryHelper Maven / Gradle / Ivy

Go to download

This is a test framework for the JDK 1.8 - Extension to provide matchers based on annotation. - Factory Support

There is a newer version: 0.1.6
Show newest version
package ch.powerunit.extensions.matchers.common;

import java.io.PrintWriter;
import java.time.Instant;
import java.util.function.Supplier;
import java.util.stream.Stream;

import javax.annotation.processing.AbstractProcessor;

public final class FactoryHelper {
	private FactoryHelper() {
	}

	public static void generateFactoryClass(PrintWriter wjfo, Class processor,
			String packageName, String className, Supplier> bodyProvider) {
		wjfo.println("package " + packageName + ";");
		wjfo.println();
		wjfo.println(CommonConstants.DEFAULT_JAVADOC_FOR_FACTORY);

		wjfo.println("@javax.annotation.Generated(value=\"" + processor.getName() + "\",date=\""
				+ Instant.now().toString() + "\")");
		wjfo.println("public interface " + className + " {");
		wjfo.println();
		wjfo.println(generateStaticDSL(className));
		wjfo.println();
		bodyProvider.get().forEach(wjfo::println);
		wjfo.println("}");
	}
	
	public static String generateStaticDSL(String className) {
		return new StringBuilder().append("  /**").append("\n")
				.append("   * Use this static field to access all the DSL syntax, without be required to implements this interface.")
				.append("\n").append("  */").append("\n")
				.append("  public static final " + className + " DSL = new " + className + "() {};").append("\n")
				.append("\n").toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy