Eclipse JDT
Release 3.0

org.eclipse.jdt.core.formatter
Class CodeFormatter

java.lang.Object
  extended byorg.eclipse.jdt.core.formatter.CodeFormatter

public abstract class CodeFormatter
extends Object

Specification for a generic source code formatter.

Since:
3.0

Field Summary
static int K_CLASS_BODY_DECLARATIONS
          Kind used to format a set of class body declarations
static int K_COMPILATION_UNIT
          Kind used to format a compilation unit
static int K_EXPRESSION
          Kind used to format an expression
static int K_STATEMENTS
          Kind used to format a set of statements
static int K_UNKNOWN
          Unknown kind
 
Constructor Summary
CodeFormatter()
           
 
Method Summary
abstract  TextEdit format(int kind, String source, int offset, int length, int indentationLevel, String lineSeparator)
          Format source, and returns a text edit that correspond to the difference between the given string and the formatted string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

K_UNKNOWN

public static final int K_UNKNOWN
Unknown kind

See Also:
Constant Field Values

K_EXPRESSION

public static final int K_EXPRESSION
Kind used to format an expression

See Also:
Constant Field Values

K_STATEMENTS

public static final int K_STATEMENTS
Kind used to format a set of statements

See Also:
Constant Field Values

K_CLASS_BODY_DECLARATIONS

public static final int K_CLASS_BODY_DECLARATIONS
Kind used to format a set of class body declarations

See Also:
Constant Field Values

K_COMPILATION_UNIT

public static final int K_COMPILATION_UNIT
Kind used to format a compilation unit

See Also:
Constant Field Values
Constructor Detail

CodeFormatter

public CodeFormatter()
Method Detail

format

public abstract TextEdit format(int kind,
                                String source,
                                int offset,
                                int length,
                                int indentationLevel,
                                String lineSeparator)
Format source, and returns a text edit that correspond to the difference between the given string and the formatted string. It returns null if the given string cannot be formatted. If the offset position is matching a whitespace, the result can include whitespaces. It would be up to the caller to get rid of preceeding whitespaces.

Parameters:
kind - Use to specify the kind of the code snippet to format. It can be any of these: K_EXPRESSION, K_STATEMENTS, K_CLASS_BODY_DECLARATIONS, K_COMPILATION_UNIT, K_UNKNOWN
source - the source to format
offset - the given offset to start recording the edits (inclusive).
length - the given length to stop recording the edits (exclusive).
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.
lineSeparator - the line separator to use in formatted source, if set to null, then the platform default one will be used.
Returns:
the text edit
Throws:
IllegalArgumentException - if offset is lower than 0, length is lower than 0 or length is greater than source length.

Eclipse JDT
Release 3.0

Copyright (c) IBM Corp. and others 2000, 2004. All Rights Reserved.