Package org.eclipse.m2m.atl.adt.ui.text
Class AtlHeuristicScanner
- java.lang.Object
-
- org.eclipse.m2m.atl.adt.ui.text.AtlHeuristicScanner
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAtlHeuristicScanner.SkippingScopeMatchActs like character match, but skips all scopes introduced by parenthesis, brackets, and braces.static interfaceAtlHeuristicScanner.StopConditionSpecifies the stop condition, upon which thescanXXXmethods will decide whether to keep scanning or not.
-
Field Summary
Fields Modifier and Type Field Description static intNOT_FOUNDReturned by all methods when the requested position could not be found, or if aBadLocationExceptionwas thrown while scanning.static intUNBOUNDSpecial bound parameter that means either -1 (backward scanning) orfDocument.getLength()(forward scanning).-
Fields inherited from interface org.eclipse.m2m.atl.adt.ui.text.Symbols
TOKEN_BREAK, TOKEN_CASE, TOKEN_CATCH, TOKEN_COLON, TOKEN_COMMA, TOKEN_DEFAULT, TOKEN_DO, TOKEN_ELSE, TOKEN_EOF, TOKEN_EQUAL, TOKEN_FINALLY, TOKEN_FOR, TOKEN_GOTO, TOKEN_IDENT, TOKEN_IF, TOKEN_LBRACE, TOKEN_LBRACKET, TOKEN_LPAREN, TOKEN_NEW, TOKEN_OTHER, TOKEN_QUESTIONMARK, TOKEN_RBRACE, TOKEN_RBRACKET, TOKEN_RETURN, TOKEN_RPAREN, TOKEN_SEMICOLON, TOKEN_STATIC, TOKEN_SWITCH, TOKEN_SYNCHRONIZED, TOKEN_TRY, TOKEN_WHILE
-
-
Constructor Summary
Constructors Constructor Description AtlHeuristicScanner(org.eclipse.jface.text.IDocument document)Callsthis(document, IAtlPartitions.Atl_PARTITIONING, IDocument.DEFAULT_CONTENT_TYPE).AtlHeuristicScanner(org.eclipse.jface.text.IDocument document, java.lang.String partitioning, java.lang.String partition)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intfindClosingPeer(int start, char openingPeer, char closingPeer)Returns the position of the closing peer character (forward search).intfindNonWhitespaceBackward(int position, int bound)Finds the highest position infDocumentsuch that the position is <=positionand >boundandCharacter.isWhitespace(fDocument.getChar(pos))evaluates tofalseand the position is in the default partition.intfindNonWhitespaceForward(int position, int bound)Finds the smallest position infDocumentsuch that the position is >=positionand <boundandCharacter.isWhitespace(fDocument.getChar(pos))evaluates tofalseand the position is in the default partition.intfindNonWhitespaceForwardInAnyPartition(int position, int bound)Finds the smallest position infDocumentsuch that the position is >=positionand <boundandCharacter.isWhitespace(fDocument.getChar(pos))evaluates tofalse.intfindOpeningPeer(int start, char openingPeer, char closingPeer)Returns the position of the opening peer character (backward search).org.eclipse.jface.text.IRegionfindSurroundingBlock(int offset)Computes the surrounding block aroundoffset.intgetPosition()Returns the most recent internal scan position.booleanisBracelessBlockStart(int position, int bound)Checks if the line seems to be an open condition not followed by a block (i.e.booleanisDefaultPartition(int position)Checks whetherpositionresides in a default (Atl) partition offDocument.intnextToken(int start, int bound)Returns the next token in forward direction, starting atstart, and not extending further thanbound.intpreviousToken(int start, int bound)Returns the next token in backward direction, starting atstart, and not extending further thanbound.intscanBackward(int position, int bound, char ch)Finds the highest position infDocumentsuch that the position is <=positionand >boundandfDocument.getChar(position) == chevaluates totruefor at least one ch incharsand the position is in the default partition.intscanBackward(int position, int bound, char[] chars)Finds the highest position infDocumentsuch that the position is <=positionand >boundandfDocument.getChar(position) == chevaluates totruefor at least one ch incharsand the position is in the default partition.intscanBackward(int start, int bound, AtlHeuristicScanner.StopCondition condition)Finds the highest positionpinfDocumentsuch thatbound<p<=startandcondition.stop(fDocument.getChar(p), p)evaluates totrue.intscanForward(int position, int bound, char ch)Finds the lowest position infDocumentsuch that the position is >=positionand <boundandfDocument.getChar(position) == chevaluates totrueand the position is in the default partition.intscanForward(int position, int bound, char[] chars)Finds the lowest position infDocumentsuch that the position is >=positionand <boundandfDocument.getChar(position) == chevaluates totruefor at least one ch incharsand the position is in the default partition.intscanForward(int start, int bound, AtlHeuristicScanner.StopCondition condition)Finds the lowest positionpinfDocumentsuch thatstart<= p <boundandcondition.stop(fDocument.getChar(p), p)evaluates totrue.
-
-
-
Field Detail
-
NOT_FOUND
public static final int NOT_FOUND
Returned by all methods when the requested position could not be found, or if aBadLocationExceptionwas thrown while scanning.- See Also:
- Constant Field Values
-
UNBOUND
public static final int UNBOUND
Special bound parameter that means either -1 (backward scanning) orfDocument.getLength()(forward scanning).- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AtlHeuristicScanner
public AtlHeuristicScanner(org.eclipse.jface.text.IDocument document)
Callsthis(document, IAtlPartitions.Atl_PARTITIONING, IDocument.DEFAULT_CONTENT_TYPE).- Parameters:
document- the document to scan.
-
AtlHeuristicScanner
public AtlHeuristicScanner(org.eclipse.jface.text.IDocument document, java.lang.String partitioning, java.lang.String partition)Creates a new instance.- Parameters:
document- the document to scanpartitioning- the partitioning to use for scanningpartition- the partition to scan in
-
-
Method Detail
-
findClosingPeer
public int findClosingPeer(int start, char openingPeer, char closingPeer)Returns the position of the closing peer character (forward search). Any scopes introduced by opening peers are skipped. All peers accounted for must reside in the default partition.Note that
startmust not point to the opening peer, but to the first character being searched.- Parameters:
start- the start positionopeningPeer- the opening peer character (e.g. '{')closingPeer- the closing peer character (e.g. '}')- Returns:
- the matching peer character position, or
NOT_FOUND
-
findNonWhitespaceBackward
public int findNonWhitespaceBackward(int position, int bound)Finds the highest position infDocumentsuch that the position is <=positionand >boundandCharacter.isWhitespace(fDocument.getChar(pos))evaluates tofalseand the position is in the default partition.- Parameters:
position- the first character position infDocumentto be consideredbound- the first position infDocumentto not consider any more, withbound<position, orUNBOUND- Returns:
- the highest position of a non-whitespace character in (
bound,position] that resides in a Atl partition, orNOT_FOUNDif none can be found
-
findNonWhitespaceForward
public int findNonWhitespaceForward(int position, int bound)Finds the smallest position infDocumentsuch that the position is >=positionand <boundandCharacter.isWhitespace(fDocument.getChar(pos))evaluates tofalseand the position is in the default partition.- Parameters:
position- the first character position infDocumentto be consideredbound- the first position infDocumentto not consider any more, withbound>position, orUNBOUND- Returns:
- the smallest position of a non-whitespace character in [
position,bound) that resides in a Atl partition, orNOT_FOUNDif none can be found
-
findNonWhitespaceForwardInAnyPartition
public int findNonWhitespaceForwardInAnyPartition(int position, int bound)Finds the smallest position infDocumentsuch that the position is >=positionand <boundandCharacter.isWhitespace(fDocument.getChar(pos))evaluates tofalse.- Parameters:
position- the first character position infDocumentto be consideredbound- the first position infDocumentto not consider any more, withbound>position, orUNBOUND- Returns:
- the smallest position of a non-whitespace character in [
position,bound), orNOT_FOUNDif none can be found
-
findOpeningPeer
public int findOpeningPeer(int start, char openingPeer, char closingPeer)Returns the position of the opening peer character (backward search). Any scopes introduced by closing peers are skipped. All peers accounted for must reside in the default partition.Note that
startmust not point to the closing peer, but to the first character being searched.- Parameters:
start- the start positionopeningPeer- the opening peer character (e.g. '{')closingPeer- the closing peer character (e.g. '}')- Returns:
- the matching peer character position, or
NOT_FOUND
-
findSurroundingBlock
public org.eclipse.jface.text.IRegion findSurroundingBlock(int offset)
Computes the surrounding block aroundoffset. The search is started at the beginning ofoffset, i.e. an opening brace atoffsetwill not be part of the surrounding block, but a closing brace will.- Parameters:
offset- the offset for which the surrounding block is computed- Returns:
- a region describing the surrounding block, or
nullif none can be found
-
getPosition
public int getPosition()
Returns the most recent internal scan position.- Returns:
- the most recent internal scan position.
-
isBracelessBlockStart
public boolean isBracelessBlockStart(int position, int bound)Checks if the line seems to be an open condition not followed by a block (i.e. an if, while, or for statement with just one following statement, see example below).if (condition) doStuff();Algorithm: if the last non-WS, non-Comment code on the line is an if (condition), while (condition), for( expression), do, else, and there is no statement after that
- Parameters:
position- the insert position of the new characterbound- the lowest position to consider- Returns:
trueif the code is a conditional statement or loop without a block,falseotherwise
-
isDefaultPartition
public boolean isDefaultPartition(int position)
Checks whetherpositionresides in a default (Atl) partition offDocument.- Parameters:
position- the position to be checked- Returns:
trueifpositionis in the default partition offDocument,falseotherwise
-
nextToken
public int nextToken(int start, int bound)Returns the next token in forward direction, starting atstart, and not extending further thanbound. The return value is one of the constants defined inSymbols. After a call,getPosition()will return the position just after the scanned token (i.e. the next position that will be scanned).- Parameters:
start- the first character position in the document to considerbound- the first position not to consider any more- Returns:
- a constant from
Symbolsdescribing the next token
-
previousToken
public int previousToken(int start, int bound)Returns the next token in backward direction, starting atstart, and not extending further thanbound. The return value is one of the constants defined inSymbols. After a call,getPosition()will return the position just before the scanned token starts (i.e. the next position that will be scanned).- Parameters:
start- the first character position in the document to considerbound- the first position not to consider any more- Returns:
- a constant from
Symbolsdescribing the previous token
-
scanBackward
public int scanBackward(int position, int bound, char ch)Finds the highest position infDocumentsuch that the position is <=positionand >boundandfDocument.getChar(position) == chevaluates totruefor at least one ch incharsand the position is in the default partition.- Parameters:
position- the first character position infDocumentto be consideredbound- the first position infDocumentto not consider any more, withbound<position, orUNBOUNDch- thecharto search for- Returns:
- the highest position of one element in
charsin (bound,position] that resides in a Atl partition, orNOT_FOUNDif none can be found
-
scanBackward
public int scanBackward(int position, int bound, char[] chars)Finds the highest position infDocumentsuch that the position is <=positionand >boundandfDocument.getChar(position) == chevaluates totruefor at least one ch incharsand the position is in the default partition.- Parameters:
position- the first character position infDocumentto be consideredbound- the first position infDocumentto not consider any more, withbound<position, orUNBOUNDchars- an array ofcharto search for- Returns:
- the highest position of one element in
charsin (bound,position] that resides in a Atl partition, orNOT_FOUNDif none can be found
-
scanBackward
public int scanBackward(int start, int bound, AtlHeuristicScanner.StopCondition condition)Finds the highest positionpinfDocumentsuch thatbound<p<=startandcondition.stop(fDocument.getChar(p), p)evaluates totrue.- Parameters:
start- the first character position infDocumentto be consideredbound- the first position infDocumentto not consider any more, withbound<start, orUNBOUNDcondition- theStopConditionto check- Returns:
- the highest position in (
bound,startfor whichconditionholds, orNOT_FOUNDif none can be found
-
scanForward
public int scanForward(int position, int bound, char ch)Finds the lowest position infDocumentsuch that the position is >=positionand <boundandfDocument.getChar(position) == chevaluates totrueand the position is in the default partition.- Parameters:
position- the first character position infDocumentto be consideredbound- the first position infDocumentto not consider any more, withbound>position, orUNBOUNDch- thecharto search for- Returns:
- the lowest position of
chin (bound,position] that resides in a Atl partition, orNOT_FOUNDif none can be found
-
scanForward
public int scanForward(int position, int bound, char[] chars)Finds the lowest position infDocumentsuch that the position is >=positionand <boundandfDocument.getChar(position) == chevaluates totruefor at least one ch incharsand the position is in the default partition.- Parameters:
position- the first character position infDocumentto be consideredbound- the first position infDocumentto not consider any more, withbound>position, orUNBOUNDchars- an array ofcharto search for- Returns:
- the lowest position of a non-whitespace character in [
position,bound) that resides in a Atl partition, orNOT_FOUNDif none can be found
-
scanForward
public int scanForward(int start, int bound, AtlHeuristicScanner.StopCondition condition)Finds the lowest positionpinfDocumentsuch thatstart<= p <boundandcondition.stop(fDocument.getChar(p), p)evaluates totrue.- Parameters:
start- the first character position infDocumentto be consideredbound- the first position infDocumentto not consider any more, withbound>start, orUNBOUNDcondition- theStopConditionto check- Returns:
- the lowest position in [
start,bound) for whichconditionholds, orNOT_FOUNDif none can be found
-
-