1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.core.formatter;
13 import org.eclipse.text.edits.TextEdit;
16 * Specification for a generic source code formatter.
20 public abstract class CodeFormatter {
25 public static final int K_UNKNOWN = 0x00;
28 * Kind used to format an expression
30 public static final int K_EXPRESSION = 0x01;
33 * Kind used to format a set of statements
35 public static final int K_STATEMENTS = 0x02;
38 * Kind used to format a set of class body declarations
40 public static final int K_CLASS_BODY_DECLARATIONS = 0x04;
43 * Kind used to format a compilation unit
45 public static final int K_COMPILATION_UNIT = 0x08;
48 * Format <code>source</code>,
49 * and returns a text edit that correspond to the difference between the given string and the formatted string.
50 * It returns null if the given string cannot be formatted.
52 * If the offset position is matching a whitespace, the result can include whitespaces. It would be up to the
53 * caller to get rid of preceeding whitespaces.
55 * @param kind Use to specify the kind of the code snippet to format. It can be any of these:
56 * K_EXPRESSION, K_STATEMENTS, K_CLASS_BODY_DECLARATIONS, K_COMPILATION_UNIT, K_UNKNOWN
57 * @param source the source to format
58 * @param offset the given offset to start recording the edits (inclusive).
59 * @param length the given length to stop recording the edits (exclusive).
60 * @param indentationLevel the initial indentation level, used
61 * to shift left/right the entire source fragment. An initial indentation
62 * level of zero or below has no effect.
63 * @param lineSeparator the line separator to use in formatted source,
64 * if set to <code>null</code>, then the platform default one will be used.
65 * @return the text edit
66 * @throws IllegalArgumentException if offset is lower than 0, length is lower than 0 or
67 * length is greater than source length.
69 public abstract TextEdit format(int kind, String source, int offset, int length, int indentationLevel, String lineSeparator);