Syntax highlighting is changeable.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / formatter / CodeFormatter.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.core.formatter;
12
13 import org.eclipse.text.edits.TextEdit;
14
15 /**
16  * Specification for a generic source code formatter.
17  * 
18  * @since 3.0
19  */
20 public abstract class CodeFormatter {
21
22         /**
23          * Unknown kind
24          */
25         public static final int K_UNKNOWN = 0x00;
26
27         /**
28          * Kind used to format an expression
29          */
30         public static final int K_EXPRESSION = 0x01;
31         
32         /**
33          * Kind used to format a set of statements
34          */
35         public static final int K_STATEMENTS = 0x02;
36         
37         /**
38          * Kind used to format a set of class body declarations
39          */
40         public static final int K_CLASS_BODY_DECLARATIONS = 0x04;
41         
42         /**
43          * Kind used to format a compilation unit
44          */
45         public static final int K_COMPILATION_UNIT = 0x08;
46
47         /** 
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.
51          * 
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.
54          * 
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.
68          */
69         public abstract TextEdit format(int kind, String source, int offset, int length, int indentationLevel, String lineSeparator);
70 }