Class TokenManager
java.lang.Object
org.aspectj.org.eclipse.jdt.internal.formatter.TokenManager
A helper class that can be used to easily access source code and find tokens on any position.
It also has some other methods that are useful on multiple stages of formatting.
-
Constructor Summary
ConstructorDescriptionTokenManager(List<Token> tokens, String source, DefaultCodeFormatterOptions options)
TokenManager(List<Token> tokens, TokenManager parent)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDisableFormatTokenPair(Token formatOffTag, Token formatOnTag)
void
addNLSAlignIndex(int index, int align)
char
charAt(int sourcePosition)
int
countLineBreaksBetween(String text, int startPosition, int endPosition)
int
countLineBreaksBetween(Token previous, Token current)
int
findFirstTokenInLine(int startIndex)
int
findFirstTokenInLine(int startIndex, boolean includeWraps, boolean includeIndents)
int
findIndex(int positionInSource, int tokenType, boolean forward)
int
findSourcePositionInLine(int position)
int
firstIndexAfter(ASTNode node, int tokenType)
int
firstIndexBefore(ASTNode node, int tokenType)
int
firstIndexIn(ASTNode node, int tokenType)
firstTokenAfter(ASTNode node, int tokenType)
firstTokenBefore(ASTNode node, int tokenType)
firstTokenIn(ASTNode node, int tokenType)
get(int index)
int
getLength(int originalStart, int originalEnd, int startPosition)
Calculates the length of a source code fragment.int
int
getNLSAlign(int index)
int
getPositionInLine(int tokenIndex)
int
int
void
Adds given token at given index.boolean
isFake(TypeDeclaration node)
boolean
isInHeader(int tokenIndex)
boolean
iterator()
int
lastIndexIn(ASTNode node, int tokenType)
lastTokenIn(ASTNode node, int tokenType)
void
remove(int tokenIndex)
Removes the token at given index.void
setHeaderEndIndex(int headerEndIndex)
int
size()
stream()
int
toIndent(int indent, boolean isWrapped)
toString(int tokenIndex)
Gets token text with characters escaped as HTML entities where necessary.Gets token text with characters escaped as HTML entities where necessary.int
traverse(int startIndex, TokenTraverser traverser)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
TokenManager
-
TokenManager
-
-
Method Details
-
get
-
size
public int size()- Returns:
- total number of tokens
-
remove
public void remove(int tokenIndex)Removes the token at given index.Warning: never call this method after wrap policies have been added to tokens since wrap parent indexes may become invalid.
-
insert
Adds given token at given index.Warning: never call this method after wrap policies have been added to tokens since wrap parent indexes may become invalid.
-
toString
Gets token text with characters escaped as HTML entities where necessary.- Parameters:
tokenIndex
- index of the token to get.
-
toString
Gets token text with characters escaped as HTML entities where necessary. -
toString
- Returns:
- part of the source code defined by given node's position and length.
-
getSource
-
indexOf
-
charAt
public char charAt(int sourcePosition) -
getSourceLength
public int getSourceLength() -
findIndex
public int findIndex(int positionInSource, int tokenType, boolean forward) -
iterator
-
stream
-
firstIndexIn
-
firstTokenIn
-
lastIndexIn
-
lastTokenIn
-
firstIndexAfter
-
firstTokenAfter
-
firstIndexBefore
-
firstTokenBefore
-
countLineBreaksBetween
-
countLineBreaksBetween
-
getPositionInLine
public int getPositionInLine(int tokenIndex) -
findSourcePositionInLine
public int findSourcePositionInLine(int position) -
getLength
- Parameters:
token
- the token to measurestartPosition
- position in line of the first character (affects tabs calculation)- Returns:
- actual length of given token, considering tabs and escaping characters as HTML entities
-
getLength
public int getLength(int originalStart, int originalEnd, int startPosition)Calculates the length of a source code fragment.- Parameters:
originalStart
- the first position of the source code fragmentoriginalEnd
- the last position of the source code fragmentstartPosition
- position in line of the first character (affects tabs calculation)- Returns:
- length, considering tabs and escaping characters as HTML entities
-
toIndent
public int toIndent(int indent, boolean isWrapped)- Parameters:
indent
- desired indentation (in positions, not in levels)isWrapped
- whether indented element is wrapped- Returns:
- actual indentation that can be achieved with current settings
-
traverse
-
findFirstTokenInLine
public int findFirstTokenInLine(int startIndex) -
findFirstTokenInLine
public int findFirstTokenInLine(int startIndex, boolean includeWraps, boolean includeIndents) -
isStringConcatenation
-
isFake
-
addNLSAlignIndex
public void addNLSAlignIndex(int index, int align) -
getNLSAlign
public int getNLSAlign(int index) -
setHeaderEndIndex
public void setHeaderEndIndex(int headerEndIndex) -
isInHeader
public boolean isInHeader(int tokenIndex) -
addDisableFormatTokenPair
-
getDisableFormatTokenPairs
-