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(); } }
public String createIndentString(int indentationUnits) { return ToolFactory.createCodeFormatter(this.options).createIndentationString(indentationUnits); }
if (execExt instanceof CodeFormatter) { CodeFormatter formatter = (CodeFormatter) execExt; formatter.setOptions(currentOptions); return formatter;
public String createIndentString(int indentationUnits) { return ToolFactory.createCodeFormatter(this.options).createIndentationString(indentationUnits); }
if (execExt instanceof CodeFormatter) { CodeFormatter formatter = (CodeFormatter) execExt; formatter.setOptions(currentOptions); return formatter;
/** * Creates edits that describe how to format the given string. Returns <code>null</code> if the code could not be formatted for the given kind. * @throws IllegalArgumentException If the offset and length are not inside the string, a * IllegalArgumentException is thrown. */ public static TextEdit format2(int kind, String string, int offset, int length, int indentationLevel, String lineSeparator, Map options) { if (offset < 0 || length < 0 || offset + length > string.length()) { throw new IllegalArgumentException("offset or length outside of string. offset: " + offset + ", length: " + length + ", string size: " + string.length()); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ } return ToolFactory.createCodeFormatter(options).format(kind, string, offset, length, indentationLevel, lineSeparator); }
public String createIndentString(int indentationUnits) { return ToolFactory.createCodeFormatter(this.options).createIndentationString(indentationUnits); }
if (execExt instanceof CodeFormatter) { CodeFormatter formatter = (CodeFormatter) execExt; formatter.setOptions(currentOptions); return formatter;
public static TextEdit reformat(int kind, String string, int offset, int length, int indentationLevel, String lineSeparator, Map options) { if (offset < 0 || length < 0 || offset + length > string.length()) { throw new IllegalArgumentException("offset or length outside of string. offset: " + offset + ", length: " + length + ", string size: " + string.length()); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ } return ToolFactory.createCodeFormatter(options, ToolFactory.M_FORMAT_EXISTING).format(kind, string, offset, length, indentationLevel, lineSeparator); }
public String createIndentString(int indentationUnits) { return ToolFactory.createCodeFormatter(this.options).createIndentationString(indentationUnits); }
public TextEdit formatString(int kind, String string, int offset, int length, int indentationLevel) { return ToolFactory.createCodeFormatter(this.options).format(kind, string, offset, length, indentationLevel, this.lineDelimiter); }
public String createIndentString(int indentationUnits) { return ToolFactory.createCodeFormatter(this.options).createIndentationString(indentationUnits); }
public TextEdit formatString(int kind, String string, int offset, int length, int indentationLevel) { return ToolFactory.createCodeFormatter(this.options).format(kind, string, offset, length, indentationLevel, this.lineDelimiter); }
public String createIndentString(int indentationUnits) { return ToolFactory.createCodeFormatter(this.options).createIndentationString(indentationUnits); }
public TextEdit formatString(int kind, String string, int offset, int length, int indentationLevel) { return ToolFactory.createCodeFormatter(this.options).format(kind, string, offset, length, indentationLevel, this.lineDelimiter); }
private String getInitialIndent(String result) { // BUG188636 - just get initial indent from code formatter String indent = getCodeFormatter().createIndentationString(1); // // get indent after 2nd line break // String indent = ""; //$NON-NLS-1$ // StringTokenizer st = new StringTokenizer(result, "\r\n", false); // //$NON-NLS-1$ // if (st.countTokens() > 1) { // String tok = st.nextToken(); // tok = st.nextToken(); // int index = 0; // if (tok != null) { // while (tok.charAt(index) == ' ' || tok.charAt(index) == '\t') { // indent += tok.charAt(index); // index++; // } // } // } return indent; }
public TextEdit formatString(int kind, String string, int offset, int length, int indentationLevel) { return ToolFactory.createCodeFormatter(this.options).format(kind, string, offset, length, indentationLevel, this.lineDelimiter); }
String level1 = getCodeFormatter().createIndentationString(1); String level3 = getCodeFormatter().createIndentationString(3); String theOld = "\n" + level3; //$NON-NLS-1$ String theNew = "\n" + level1; //$NON-NLS-1$
public TextEdit formatString(int kind, String string, int offset, int length, int indentationLevel) { return ToolFactory.createCodeFormatter(this.options).format(kind, string, offset, length, indentationLevel, this.lineDelimiter); }
/** * Creates a string that represents the given number of indentation units. * The returned string can contain tabs and/or spaces depending on the core * formatter preferences. * * @param indentationUnits the number of indentation units to generate * @param project the project from which to get the formatter settings, * <code>null</code> if the workspace default should be used * @return the indent string */ public static String createIndentString(int indentationUnits, IJavaProject project) { Map options= project != null ? project.getOptions(true) : JavaCore.getOptions(); return ToolFactory.createCodeFormatter(options).createIndentationString(indentationUnits); }