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

org.hibernate.tool.ide.formatting.DefaultJavaPrettyPrinterStrategy Maven / Gradle / Ivy

There is a newer version: 5.6.15.Final
Show newest version
package org.hibernate.tool.ide.formatting;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Map;

import com.google.googlejavaformat.java.Formatter;
import com.google.googlejavaformat.java.FormatterException;

public class DefaultJavaPrettyPrinterStrategy {
	
	public DefaultJavaPrettyPrinterStrategy(Map settings) {}

	public boolean formatFile(File file) {
		try {
			Formatter formatter = new Formatter();
			String toFormat = new String(Files.readAllBytes(file.toPath()));
			String toWrite = formatter.formatSource(toFormat);
			Files.write(file.toPath(), toWrite.getBytes());
			return true;
		} catch (IOException | FormatterException e) {
			throw new RuntimeException(e);
		}
	}
	
}	




© 2015 - 2024 Weber Informatics LLC | Privacy Policy