Package org.eclipse.m2m.atl.adt.ui.text
Class AtlIndenter
- java.lang.Object
-
- org.eclipse.m2m.atl.adt.ui.text.AtlIndenter
-
public class AtlIndenter extends java.lang.ObjectUses theAtlHeuristicScannerto get the indentation level for a certain position in a document.An instance holds some internal position in the document and is therefore not threadsafe.
-
-
Constructor Summary
Constructors Constructor Description AtlIndenter(org.eclipse.jface.text.IDocument document, AtlHeuristicScanner scanner)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringBuffercomputeIndentation(int offset)Computes the indentation atoffset.java.lang.StringBuffercomputeIndentation(int offset, boolean assumeOpeningBrace)Computes the indentation atoffset.intfindReferencePosition(int offset)Returns the reference position regarding to indentation foroffset, orNOT_FOUND.intfindReferencePosition(int offset, boolean danglingElse, boolean matchBrace, boolean matchParen, boolean matchCase)Returns the reference position regarding to indentation forposition, orNOT_FOUND.fIndentwill contain the relative indentation (in indentation units, not characters) after the call.intfindReferencePosition(int offset, int nextToken)Returns the reference position regarding to indentation forposition, orNOT_FOUND.java.lang.StringBuffergetReferenceIndentation(int offset)Computes the indentation at the reference point ofposition.
-
-
-
Constructor Detail
-
AtlIndenter
public AtlIndenter(org.eclipse.jface.text.IDocument document, AtlHeuristicScanner scanner)Creates a new instance.- Parameters:
document- the document to scanscanner- theAtlHeuristicScannerto be used for scanning the document. It must be installed on the sameIDocument.
-
-
Method Detail
-
computeIndentation
public java.lang.StringBuffer computeIndentation(int offset)
Computes the indentation atoffset.- Parameters:
offset- the offset in the document- Returns:
- a String which reflects the correct indentation for the line in which offset resides, or
nullif it cannot be determined
-
computeIndentation
public java.lang.StringBuffer computeIndentation(int offset, boolean assumeOpeningBrace)Computes the indentation atoffset.- Parameters:
offset- the offset in the documentassumeOpeningBrace-trueif an opening brace should be assumed- Returns:
- a String which reflects the correct indentation for the line in which offset resides, or
nullif it cannot be determined
-
findReferencePosition
public int findReferencePosition(int offset)
Returns the reference position regarding to indentation foroffset, orNOT_FOUND. This method callsfindReferencePosition(offset, nextChar)wherenextCharis the next character afteroffset.- Parameters:
offset- the offset for which the reference is computed- Returns:
- the reference statement relative to which
offsetshould be indented, orAtlHeuristicScanner.NOT_FOUND
-
findReferencePosition
public int findReferencePosition(int offset, boolean danglingElse, boolean matchBrace, boolean matchParen, boolean matchCase)Returns the reference position regarding to indentation forposition, orNOT_FOUND.fIndentwill contain the relative indentation (in indentation units, not characters) after the call. If there is a special alignment (e.g. for a method declaration where parameters should be aligned),fAlignwill contain the absolute position of the alignment reference infDocument, otherwisefAlignis set toAtlHeuristicScanner.NOT_FOUND.- Parameters:
offset- the offset for which the reference is computeddanglingElse- whether a dangling else should be assumed atpositionmatchBrace- whether the position of the matching brace should be returned instead of doing code analysismatchParen- whether the position of the matching parenthesis should be returned instead of doing code analysismatchCase- whether the position of a switch statement reference should be returned (either an earlier case statement or the switch block brace)- Returns:
- the reference statement relative to which
positionshould be indented, orAtlHeuristicScanner.NOT_FOUND
-
findReferencePosition
public int findReferencePosition(int offset, int nextToken)Returns the reference position regarding to indentation forposition, orNOT_FOUND.If
peekNextCharistrue, the next token afteroffsetis read and taken into account when computing the indentation. Currently, if the next token is the first token on the line (i.e. only preceded by whitespace), the following tokens are specially handled:switchlabels are indented relative to the switch block- opening curly braces are aligned correctly with the introducing code
- closing curly braces are aligned properly with the introducing code of the matching opening brace
- closing parenthesis' are aligned with their opening peer
- the
elsekeyword is aligned with itsif, anything else is aligned normally (i.e. with the base of any introducing statements). - if there is no token on the same line after
offset, the indentation is the same as for anelsekeyword
- Parameters:
offset- the offset for which the reference is computednextToken- the next token to assume in the document- Returns:
- the reference statement relative to which
offsetshould be indented, orAtlHeuristicScanner.NOT_FOUND
-
getReferenceIndentation
public java.lang.StringBuffer getReferenceIndentation(int offset)
Computes the indentation at the reference point ofposition.- Parameters:
offset- the offset in the document- Returns:
- a String which reflects the indentation at the line in which the reference position to
offsetresides, ornullif it cannot be determined
-
-