public static TextEdit format2(int kind, String string, int indentationLevel, String lineSeparator, Map options) { return format2(kind, string, 0, string.length(), indentationLevel, lineSeparator, options); }
/** * 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. * * @param kind * Use to specify the kind of the code snippet to format. * It can be any of the kind constants defined in {@link CodeFormatter} * @param source * The source to format * @param indentationLevel * The initial indentation level, used to shift left/right the entire source fragment. * An initial indentation level of zero or below has no effect. * @param lineSeparator * The line separator to use in formatted source, * if set to <code>null</code>, then the platform default one will be used. * @param options * The options map to use for formatting with the default code formatter. * Recognized options are documented on {@link JavaCore#getDefaultOptions()}. * If set to <code>null</code>, then use the current settings from {@link JavaCore#getOptions()}. * @return an TextEdit describing the changes required to format source * @throws IllegalArgumentException * If the offset and length are not inside the string, a IllegalArgumentException is thrown. */ public static TextEdit format2(int kind, String source, int indentationLevel, String lineSeparator, Map<String, String> options) { return format2(kind, source, 0, source.length(), indentationLevel, lineSeparator, options); }
/** * 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. * * @param kind * Use to specify the kind of the code snippet to format. * It can be any of the kind constants defined in {@link CodeFormatter} * @param source * The source to format * @param indentationLevel * The initial indentation level, used to shift left/right the entire source fragment. * An initial indentation level of zero or below has no effect. * @param lineSeparator * The line separator to use in formatted source, * if set to <code>null</code>, then the platform default one will be used. * @param options * The options map to use for formatting with the default code formatter. * Recognized options are documented on {@link JavaCore#getDefaultOptions()}. * If set to <code>null</code>, then use the current settings from {@link JavaCore#getOptions()}. * @return an TextEdit describing the changes required to format source * @throws IllegalArgumentException * If the offset and length are not inside the string, a IllegalArgumentException is thrown. */ public static TextEdit format2(int kind, String source, int indentationLevel, String lineSeparator, Map<String, String> options) { return format2(kind, source, 0, source.length(), indentationLevel, lineSeparator, options); }
/** * Old API. Consider to use format2 (TextEdit) */ public static String format(ASTNode node, String string, int indentationLevel, int[] positions, String lineSeparator, Map options) { TextEdit edit= format2(node, string, indentationLevel, lineSeparator, options); if (edit == null) { //JavaPlugin.logErrorMessage("formatter failed to format (no edit returned). Will use unformatted text instead. node: " + node.getNodeType() + ", string: " + string); //$NON-NLS-1$ //$NON-NLS-2$ return string; } return getOldAPICompatibleResult(string, edit, indentationLevel, positions, lineSeparator, options); }
/** * Old API. Consider to use format2 (TextEdit) */ public static String format(int kind, String string, int offset, int length, int indentationLevel, int[] positions, String lineSeparator, Map options) { TextEdit edit= format2(kind, string, offset, length, indentationLevel, lineSeparator, options); if (edit == null) { //JavaPlugin.logErrorMessage("formatter failed to format (no edit returned). Will use unformatted text instead. kind: " + kind + ", string: " + string); //$NON-NLS-1$ //$NON-NLS-2$ return string.substring(offset, offset + length); } String formatted= getOldAPICompatibleResult(string, edit, indentationLevel, positions, lineSeparator, options); return formatted.substring(offset, formatted.length() - (string.length() - (offset + length))); }
public static String asFormattedString(ASTNode node, int indent, String lineDelim, Map options) { String unformatted= asString(node); TextEdit edit= CodeFormatterUtil.format2(node, unformatted, indent, lineDelim, options); if (edit != null) { return CodeFormatterUtil.evaluateFormatterEdit(unformatted, edit, null); } return unformatted; // unknown node }
public static String asFormattedString(ASTNode node, int indent, String lineDelim, Map<String, String> options) { String unformatted= asString(node); TextEdit edit= CodeFormatterUtil.format2(node, unformatted, indent, lineDelim, options); if (edit != null) { Document document= new Document(unformatted); try { edit.apply(document, TextEdit.NONE); } catch (BadLocationException e) { JavaPlugin.log(e); } return document.get(); } return unformatted; // unknown node }
public static String asFormattedString(ASTNode node, int indent, String lineDelim, Map<String, String> options) { String unformatted= asString(node); TextEdit edit= CodeFormatterUtil.format2(node, unformatted, indent, lineDelim, options); if (edit != null) { Document document= new Document(unformatted); try { edit.apply(document, TextEdit.NONE); } catch (BadLocationException e) { // bug in the formatter JavaManipulationPlugin.log(e); } return document.get(); } return unformatted; // unknown node }
private void format(IDocument doc, CompilationUnitContext context) throws BadLocationException { Map<String, String> options; IJavaProject project= context.getJavaProject(); if (project != null) options= FormatterProfileManager.getProjectSettings(project); else options= JavaCore.getOptions(); String contents= doc.get(); int[] kinds= { CodeFormatter.K_EXPRESSION, CodeFormatter.K_STATEMENTS, CodeFormatter.K_UNKNOWN}; TextEdit edit= null; for (int i= 0; i < kinds.length && edit == null; i++) { edit= CodeFormatterUtil.format2(kinds[i], contents, fInitialIndentLevel, fLineDelimiter, options); } if (edit == null) throw new BadLocationException(); // fall back to indenting edit.apply(doc, TextEdit.UPDATE_REGIONS); }
private void format(IDocument doc, CompilationUnitContext context) throws BadLocationException { Map options; IJavaProject project= context.getJavaProject(); if (project != null) options= project.getOptions(true); else options= JavaCore.getOptions(); String contents= doc.get(); int[] kinds= { CodeFormatter.K_EXPRESSION, CodeFormatter.K_STATEMENTS, CodeFormatter.K_UNKNOWN}; TextEdit edit= null; for (int i= 0; i < kinds.length && edit == null; i++) { edit= CodeFormatterUtil.format2(kinds[i], contents, fInitialIndentLevel, fLineDelimiter, options); } if (edit == null) throw new BadLocationException(); // fall back to indenting edit.apply(doc, TextEdit.UPDATE_REGIONS); }
private void format(IDocument doc, CompilationUnitContext context) throws BadLocationException { Map<String, String> options; IJavaProject project= context.getJavaProject(); if (project != null) options= project.getOptions(true); else options= JavaCore.getOptions(); String contents= doc.get(); int[] kinds= { CodeFormatter.K_EXPRESSION, CodeFormatter.K_STATEMENTS, CodeFormatter.K_UNKNOWN}; TextEdit edit= null; for (int i= 0; i < kinds.length && edit == null; i++) { edit= CodeFormatterUtil.format2(kinds[i], contents, fInitialIndentLevel, fLineDelimiter, options); } if (edit == null) throw new BadLocationException(); // fall back to indenting edit.apply(doc, TextEdit.UPDATE_REGIONS); }
final TextEdit edit= CodeFormatterUtil.format2(CodeFormatter.K_COMPILATION_UNIT, source, 0, delimiter, copy.getJavaProject().getOptions(true)); if (edit != null) { try {
final TextEdit edit= CodeFormatterUtil.format2(CodeFormatter.K_COMPILATION_UNIT, source, 0, delimiter, FormatterProfileManager.getProjectSettings(copy.getJavaProject())); if (edit != null) { try {
final TextEdit edit= CodeFormatterUtil.format2(CodeFormatter.K_COMPILATION_UNIT, source, 0, delimiter, copy.getJavaProject().getOptions(true)); if (edit != null) { try {
final TextEdit edit= CodeFormatterUtil.format2(CodeFormatter.K_COMPILATION_UNIT, source, 0, delimiter, extractedWorkingCopy.getJavaProject().getOptions(true)); if (edit != null) { try {
TextEdit edit= format2(kind, source, indentationLevel, lineSeparator, options); if (edit == null) { return source;
final TextEdit edit= CodeFormatterUtil.format2(CodeFormatter.K_COMPILATION_UNIT, source, 0, delimiter, FormatterProfileManager.getProjectSettings(extractedWorkingCopy.getJavaProject())); if (edit != null) { try {
final TextEdit edit= CodeFormatterUtil.format2(CodeFormatter.K_COMPILATION_UNIT, source, 0, delimiter, extractedWorkingCopy.getJavaProject().getOptions(true)); if (edit != null) { try {
TextEdit edit= format2(kind, source, indentationLevel, lineSeparator, options); if (edit == null) { return source;
ArrayList changes = pars.convert(ConversionOptions.CONSTANT_SIZE); content = new String(pars.content); final TextEdit edit = CodeFormatterUtil.format2( CodeFormatter.K_COMPILATION_UNIT, content, partition .getOffset(), partition.getLength(), 0,