@Override public String format(String source) { return Formatter.format(source); }
public static String format(String source) { // TODO locate user's eclipse project settings, use those if we can. Properties options = readConfig("org.eclipse.jdt.core.prefs"); final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options); return ensureCorrectNewLines(formatFile(source, codeFormatter)); }
@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); }
/** * 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); } }
private static Properties readConfig(File prefs) throws IOException { if (prefs != null) { try (InputStream stream = new BufferedInputStream(new FileInputStream(prefs))) { Properties config; if (prefs.getName().toLowerCase().endsWith(".xml")) { config = parseXmlConfig(stream); } else { config = parseConfig(stream); } return applyShadedPackageName(config); } catch (IOException e) { throw new IOException("Error reading preferences file: [" + prefs.getAbsolutePath() + "]", e); } } return null; }
/** * Format the given {@link String} as a Java source type, using the given Eclipse code format {@link Properties}. */ public static String format(Properties prefs, String source) { CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(prefs); IDocument doc = new Document(source); try { TextEdit edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, source, 0, source.length(), 0, null); if (edit != null) { edit.apply(doc); } else { throw new FormatterException(source, null); } } catch (BadLocationException e) { throw new FormatterException(source, e); } return ensureCorrectNewLines(doc.get()); }
/** * Format the given Java source {@link File} using the given Eclipse code format properties {@link File}. * * @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(); InputStream in = null; OutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(source)); String content = Streams.toString(in); String formatted = format(options, content); out = new BufferedOutputStream(new FileOutputStream(source)); Streams.write(new ByteArrayInputStream(formatted.getBytes()), out); } finally { Streams.closeQuietly(in); Streams.closeQuietly(out); } }
/** * 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); }
private static Properties readConfig(File prefs) throws IOException { if (prefs != null) { InputStream stream = new BufferedInputStream(new FileInputStream(prefs)); try { Properties config; if (prefs.getName().toLowerCase().endsWith(".xml")) { config = parseXmlConfig(stream); } else { config = parseConfig(stream); } return applyShadedPackageName(config); } catch (IOException e) { throw new IOException("Error reading preferences file: [" + prefs.getAbsolutePath() + "]", e); } finally { Streams.closeQuietly(stream); } } return null; }
/** * 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(Properties properties, String source) { Properties shadedProperties = Formatter.applyShadedPackageName(properties); return Formatter.format(shadedProperties, 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 built in code format style. */ 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()); }
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; }