/** * Format the given Java source {@link File}, using the built in code format style. * * @param source the file which contains the source to format * @throws FormatterException if the source coudn't be formatted * @throws IOException When the file cannot be read or written */ public static void format(File source) throws IOException { format(null, source); }
@Override public String format(String source) { return Formatter.format(source); }
@Override public String format(String source) { return Formatter.format(source); }
/** * Format the given Java source {@link File}, using the built in code format style. * * @throws IOException When the file cannot be read or written */ public static void format(File source) throws IOException { format(null, source); }
/** * Format the given {@link JavaClassSource}, using the given Eclipse code format {@link Properties}. * * @param prefs the format properties * @param javaClass the class to format * @return the formatted source code * @throws FormatterException if the source coudn't be formatted */ public static String format(Properties prefs, JavaClassSource javaClass) { return format(prefs, javaClass.toString()); }
/** * Format the given {@link JavaClassSource}, using the built in code format style. * * @param javaClass the class to format * @return the formatted source code * @throws FormatterException if the source coudn't be formatted */ public static String format(JavaClassSource javaClass) { return format(javaClass.toString()); }
/** * Format the given {@link JavaClassSource}, using the given Eclipse code format {@link Properties}. */ public static String format(Properties prefs, JavaClassSource javaClass) { return format(prefs, javaClass.toString()); }
/** * Format the given {@link JavaClassSource}, using the built in code format style. */ public static String format(JavaClassSource javaClass) { return format(javaClass.toString()); }
public static String format(JavaClassSource javaClass) { return format(javaClass.toString()); }
/** * @param javaClass * * @return */ protected String formatClass(final JavaClassSource javaClass) { final Properties prefs = new Properties(); try { prefs.load(BeanGenerator.class.getResourceAsStream(FORMATTER_PROPERTIES_FILE)); } catch (final IOException e) { e.printStackTrace(); } final String formattedSource = prefs != null ? Formatter.format(prefs, javaClass) : Formatter.format(javaClass); // System.out.println(formattedSource); return formattedSource; }
@Override public String format(Properties properties, String source) { Properties shadedProperties = Formatter.applyShadedPackageName(properties); return Formatter.format(shadedProperties, source); } }
@Override public String format(Properties properties, String source) { Properties shadedProperties = Formatter.applyShadedPackageName(properties); return Formatter.format(shadedProperties, source); } }
/** * Format the given {@link String} as a Java source file, using the built in code format style. * * @param source the source to format * @return the formatted source code * @throws FormatterException if the source coudn't be formatted */ public static String format(String source) { Properties options = readConfigInternal(); return format(options, source); }
/** * Return this {@link JavaType} file as a String */ @Override public String toString() { return Formatter.format(toUnformattedString()); }
/** * Return this {@link JavaType} file as a String */ @Override public String toString() { return Formatter.format(toUnformattedString()); }
/** * Return this {@link JavaType} file as a String */ @Override public String toString() { return Formatter.format(toUnformattedString()); }
/** * Format the given {@link String} as a Java source file, using the built in code format style. */ public static String format(String source) { Properties options = readConfigInternal(); return format(options, source); }
/** * Format the given Java source {@link File} using the given Eclipse code format properties {@link File}. * * @param prefs the format properties file * @param source the file which contains the source to format * @throws FormatterException if the source coudn't be formatted * @throws IOException When the file cannot be read or written, or the preferences cannot be read. */ public static void format(File prefs, File source) throws IOException { Properties options = readConfig(prefs); if (options == null) options = readConfigInternal(); try (InputStream in = new BufferedInputStream(new FileInputStream(source)); OutputStream out = new BufferedOutputStream(new FileOutputStream(source))) { String content = Streams.toString(in); String formatted = format(options, content); Streams.write(new ByteArrayInputStream(formatted.getBytes()), out); } }
/** * Return this {@link JavaType} file as a String */ @Override public String toString() { Document document = new Document(this.document.get()); try { @SuppressWarnings("rawtypes") Map options = JavaCore.getOptions(); options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_7); options.put(CompilerOptions.OPTION_Encoding, "UTF-8"); TextEdit edit = unit.rewrite(document, options); edit.apply(document); } catch (Exception e) { throw new ParserException("Could not modify source: " + unit.toString(), e); } return Formatter.format(document.get()); }
/** * Return this {@link JavaType} file as a String */ @Override public String toString() { Document document = new Document(this.document.get()); try { TextEdit edit = unit.rewrite(document, null); edit.apply(document); } catch (Exception e) { throw new ParserException("Could not modify source: " + unit.toString(), e); } return Formatter.format(document.get()); }