org.eclipse.cdt.internal.ui.editor
Class IndentUtil

java.lang.Object
  extended by org.eclipse.cdt.internal.ui.editor.IndentUtil

public final class IndentUtil
extends java.lang.Object

Utility that indents a number of lines in a document.


Nested Class Summary
static class IndentUtil.IndentResult
          The result of an indentation operation.
 
Method Summary
static java.lang.String computeCommentIndent(org.eclipse.jface.text.IDocument document, int line, CHeuristicScanner scanner, org.eclipse.jface.text.ITypedRegion partition)
          Computes and returns the indentation for a block comment line.
static java.lang.String computeIndent(org.eclipse.jface.text.IDocument document, int line, CIndenter indenter, CHeuristicScanner scanner)
          Computes and returns the indentation for a source line.
static java.lang.String computePreprocessorIndent(org.eclipse.jface.text.IDocument document, int line, org.eclipse.jface.text.ITypedRegion partition)
          Computes and returns the indentation for a preprocessor line.
static java.lang.String getCurrentIndent(org.eclipse.jface.text.IDocument document, int line, boolean indentInsideLineComments)
          Returns the indentation of the line line in document.
static boolean indentInsideLineComments(org.eclipse.cdt.core.model.ICProject project)
          Returns true if line comments at column 0 should be indented inside, false otherwise.
static IndentUtil.IndentResult indentLines(org.eclipse.jface.text.IDocument document, org.eclipse.jface.text.source.ILineRange lines, org.eclipse.cdt.core.model.ICProject project, IndentUtil.IndentResult result)
          Indents the line range specified by lines in document.
static void indentLines(org.eclipse.jface.text.IDocument document, org.eclipse.jface.text.source.LineRange lines, java.lang.String indent)
          Inserts indent string at the beginning of each line in lines.
static IndentUtil.IndentResult shiftLines(org.eclipse.jface.text.IDocument document, org.eclipse.jface.text.source.ILineRange lines, org.eclipse.cdt.core.model.ICProject project, IndentUtil.IndentResult result)
          Shifts the line range specified by lines in document.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

indentLines

public static IndentUtil.IndentResult indentLines(org.eclipse.jface.text.IDocument document,
                                                  org.eclipse.jface.text.source.ILineRange lines,
                                                  org.eclipse.cdt.core.model.ICProject project,
                                                  IndentUtil.IndentResult result)
                                           throws org.eclipse.jface.text.BadLocationException
Indents the line range specified by lines in document. The passed C project may be null, it is used solely to obtain formatter preferences.

Parameters:
document - the document to be changed
lines - the line range to be indented
project - the C project to get the formatter preferences from, or null if global preferences should be used
result - the result from a previous call to indentLines, in order to maintain comment line properties, or null. Note that the passed result may be changed by the call.
Returns:
an indent result that may be queried for changes and can be reused in subsequent indentation operations
Throws:
org.eclipse.jface.text.BadLocationException - if lines is not a valid line range on document

indentLines

public static void indentLines(org.eclipse.jface.text.IDocument document,
                               org.eclipse.jface.text.source.LineRange lines,
                               java.lang.String indent)
                        throws org.eclipse.jface.text.BadLocationException
Inserts indent string at the beginning of each line in lines.

Parameters:
document - the document to be changed.
lines - the line range to be indented.
indent - the indent string to be inserted.
Throws:
org.eclipse.jface.text.BadLocationException - if lines is not a valid line range on document

indentInsideLineComments

public static boolean indentInsideLineComments(org.eclipse.cdt.core.model.ICProject project)
Returns true if line comments at column 0 should be indented inside, false otherwise.

Parameters:
project - the project to get project specific options from
Returns:
true if line comments at column 0 should be indented inside, false otherwise.

shiftLines

public static IndentUtil.IndentResult shiftLines(org.eclipse.jface.text.IDocument document,
                                                 org.eclipse.jface.text.source.ILineRange lines,
                                                 org.eclipse.cdt.core.model.ICProject project,
                                                 IndentUtil.IndentResult result)
                                          throws org.eclipse.jface.text.BadLocationException
Shifts the line range specified by lines in document. The amount that the lines get shifted are determined by the first line in the range, all subsequent lines are adjusted accordingly. The passed C project may be null, it is used solely to obtain formatter preferences.

Parameters:
document - the document to be changed
lines - the line range to be shifted
project - the C project to get the formatter preferences from, or null if global preferences should be used
result - the result from a previous call to shiftLines, in order to maintain comment line properties, or null. Note that the passed result may be changed by the call.
Returns:
an indent result that may be queried for changes and can be reused in subsequent indentation operations
Throws:
org.eclipse.jface.text.BadLocationException - if lines is not a valid line range on document

getCurrentIndent

public static java.lang.String getCurrentIndent(org.eclipse.jface.text.IDocument document,
                                                int line,
                                                boolean indentInsideLineComments)
                                         throws org.eclipse.jface.text.BadLocationException
Returns the indentation of the line line in document. The returned string may contain pairs of leading slashes that are considered part of the indentation.

Parameters:
document - the document
line - the line
indentInsideLineComments - option whether to indent inside line comments starting at column 0
Returns:
the indentation of line in document
Throws:
org.eclipse.jface.text.BadLocationException - if the document is changed concurrently

computeIndent

public static java.lang.String computeIndent(org.eclipse.jface.text.IDocument document,
                                             int line,
                                             CIndenter indenter,
                                             CHeuristicScanner scanner)
                                      throws org.eclipse.jface.text.BadLocationException
Computes and returns the indentation for a source line.

Parameters:
document - the document
line - the line in document
indenter - the C indenter
scanner - the scanner
Returns:
the indent, never null
Throws:
org.eclipse.jface.text.BadLocationException

computeCommentIndent

public static java.lang.String computeCommentIndent(org.eclipse.jface.text.IDocument document,
                                                    int line,
                                                    CHeuristicScanner scanner,
                                                    org.eclipse.jface.text.ITypedRegion partition)
                                             throws org.eclipse.jface.text.BadLocationException
Computes and returns the indentation for a block comment line.

Parameters:
document - the document
line - the line in document
scanner - the scanner
partition - the comment partition
Returns:
the indent, or null if not computable
Throws:
org.eclipse.jface.text.BadLocationException

computePreprocessorIndent

public static java.lang.String computePreprocessorIndent(org.eclipse.jface.text.IDocument document,
                                                         int line,
                                                         org.eclipse.jface.text.ITypedRegion partition)
                                                  throws org.eclipse.jface.text.BadLocationException
Computes and returns the indentation for a preprocessor line.

Parameters:
document - the document
line - the line in document
partition - the comment partition
Returns:
the indent, or null if not computable
Throws:
org.eclipse.jface.text.BadLocationException