public String apply(String contents) { final TextEdit edit = codeFormatter.format( CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, contents, 0, contents.length(), 0, Constants.LINE_SEPARATOR); if (edit == null) { // TODO log a fatal or warning here. Throwing an exception is causing the actual freemarker error to be lost return contents; } IDocument document = new Document(contents); try { edit.apply(document); } catch (Exception e) { throw new RuntimeException( "Failed to format the generated source code.", e); } return document.get(); } }
/** * Removes the given number of indents from the line. Asserts that the given line * has the requested number of indents. If <code>indentsToRemove <= 0</code> * the line is returned. * * @since 3.1 */ public static String trimIndent(String line, int indentsToRemove, int tabWidth, int indentWidth) { return IndentManipulation.trimIndent(line, indentsToRemove, tabWidth, indentWidth); }
/** * @return Returns the settings for the new eclipse profile. */ public static Map<String, String> getEclipseSettings() { return DefaultCodeFormatterConstants.getEclipseDefaultSettings(); }
/** * Returns the indent of the given string in indentation units. Odd spaces * are not counted. * * @param line the text line * @param tabWidth the width of the '\t' character in space equivalents * @param indentWidth the width of one indentation unit in space equivalents * @since 3.1 */ public static int computeIndentUnits(String line, int tabWidth, int indentWidth) { return IndentManipulation.measureIndentUnits(line, tabWidth, indentWidth); }
/** * Returns that part of the indentation of <code>line</code> that makes up * a multiple of indentation units. * * @param line the line to scan * @param tabWidth the size of one tab in space equivalents * @param indentWidth the size of the indent in space equivalents * @return the indent part of <code>line</code>, but no odd spaces * @since 3.1 */ public static String getIndentString(String line, int tabWidth, int indentWidth) { return IndentManipulation.extractIndentString(line, tabWidth, indentWidth); }
/** * Bind the given message's substitution locations with the given string * values. * * @param message * the message to be manipulated * @return the manipulated String */ public static String bind(String message) { return bind(message, null); }
public ASTRewriteFormatter(NodeInfoStore placeholders, RewriteEventStore eventStore, Map options, String lineDelimiter) { this.placeholders= placeholders; this.eventStore= eventStore; this.options= options; this.lineDelimiter= lineDelimiter; this.tabWidth= IndentManipulation.getTabWidth(options); this.indentWidth= IndentManipulation.getIndentWidth(options); }
/** * Change the indent of, possible muti-line, code range. The current indent is removed, a new indent added. * The first line of the code will not be changed. (It is considered to have no indent as it might start in * the middle of a line) * @since 3.1 */ public static String changeIndent(String code, int codeIndentLevel, int tabWidth, int indentWidth, String newIndent, String lineDelim) { return IndentManipulation.changeIndent(code, codeIndentLevel, tabWidth, indentWidth, newIndent, lineDelim); }
/** * @return Returns the settings for the default profile. */ public static Map<String, String> getEclipse21Settings() { return DefaultCodeFormatterConstants.getEclipse21Settings(); }
/** * @return Returns the settings for the Java Conventions profile. */ public static Map<String, String> getJavaSettings() { return DefaultCodeFormatterConstants.getJavaConventionsSettings(); }
/** * Computes the visual length of the indentation of a * <code>CharSequence</code>, counting a tab character as the size until * the next tab stop and every other whitespace character as one. * * @param line the string to measure the indent of * @param tabSize the visual size of a tab in space equivalents * @return the visual length of the indentation of <code>line</code> * @since 3.1 */ public static int measureIndentLength(CharSequence line, int tabSize) { return IndentManipulation.measureIndentInSpaces(line, tabSize); }
public int computeIndentUnits(String line) { return IndentManipulation.measureIndentUnits(line, this.tabWidth, this.indentWidth); }
/** * Returns that part of the indentation of <code>line</code> that makes up * a multiple of indentation units. * * @param line the line to scan * @param tabWidth the size of one tab in space equivalents * @param indentWidth the size of the indent in space equivalents * @return the indent part of <code>line</code>, but no odd spaces * @since 3.1 */ public static String getIndentString(String line, int tabWidth, int indentWidth) { return IndentManipulation.extractIndentString(line, tabWidth, indentWidth); }
/** * Bind the given message's substitution locations with the given string * values. * * @param message * the message to be manipulated * @return the manipulated String */ public static String bind(String message) { return bind(message, null); }
public int computeIndentUnits(String line) { return IndentManipulation.measureIndentUnits(line, this.tabWidth, this.indentWidth); }
/** * Bind the given message's substitution locations with the given string * values. * * @param message * the message to be manipulated * @return the manipulated String */ public static String bind(String message) { return bind(message, null); }
public int computeIndentUnits(String line) { return IndentManipulation.measureIndentUnits(line, this.tabWidth, this.indentWidth); }
/** * Bind the given message's substitution locations with the given string * values. * * @param message * the message to be manipulated * @return the manipulated String */ public static String bind(String message) { return bind(message, null); }
/** * Bind the given message's substitution locations with the given string * values. * * @param message * the message to be manipulated * @return the manipulated String */ public static String bind(String message) { return bind(message, null); }
/** * Bind the given message's substitution locations with the given string * values. * * @param message * the message to be manipulated * @return the manipulated String */ public static String bind(String message) { return bind(message, null); }