|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.m2m.atl.adt.ui.text.AtlHeuristicScanner
public class AtlHeuristicScanner
Utility methods for heuristic based manipulations in an incomplete source file.
An instance holds some internal position in the document and is therefore not threadsafe.
Nested Class Summary | |
---|---|
protected class |
AtlHeuristicScanner.SkippingScopeMatch
Acts like character match, but skips all scopes introduced by parenthesis, brackets, and braces. |
static interface |
AtlHeuristicScanner.StopCondition
Specifies the stop condition, upon which the scanXXX methods will decide whether to keep
scanning or not. |
Field Summary | |
---|---|
static int |
NOT_FOUND
Returned by all methods when the requested position could not be found, or if a BadLocationException was thrown while scanning. |
static int |
UNBOUND
Special bound parameter that means either -1 (backward scanning) or fDocument.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 | |
---|---|
AtlHeuristicScanner(org.eclipse.jface.text.IDocument document)
Calls this(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 | |
---|---|
int |
findClosingPeer(int start,
char openingPeer,
char closingPeer)
Returns the position of the closing peer character (forward search). |
int |
findNonWhitespaceBackward(int position,
int bound)
Finds the highest position in fDocument such that the position is <=
position and > bound and
Character.isWhitespace(fDocument.getChar(pos)) evaluates to false and the
position is in the default partition. |
int |
findNonWhitespaceForward(int position,
int bound)
Finds the smallest position in fDocument such that the position is >=
position and < bound and
Character.isWhitespace(fDocument.getChar(pos)) evaluates to false and the
position is in the default partition. |
int |
findNonWhitespaceForwardInAnyPartition(int position,
int bound)
Finds the smallest position in fDocument such that the position is >=
position and < bound and
Character.isWhitespace(fDocument.getChar(pos)) evaluates to false . |
int |
findOpeningPeer(int start,
char openingPeer,
char closingPeer)
Returns the position of the opening peer character (backward search). |
org.eclipse.jface.text.IRegion |
findSurroundingBlock(int offset)
Computes the surrounding block around offset . |
int |
getPosition()
Returns the most recent internal scan position. |
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). |
boolean |
isDefaultPartition(int position)
Checks whether position resides in a default (Atl) partition of fDocument . |
int |
nextToken(int start,
int bound)
Returns the next token in forward direction, starting at start , and not extending further
than bound . |
int |
previousToken(int start,
int bound)
Returns the next token in backward direction, starting at start , and not extending further
than bound . |
int |
scanBackward(int start,
int bound,
AtlHeuristicScanner.StopCondition condition)
Finds the highest position p in fDocument such that bound <
p <= start and condition.stop(fDocument.getChar(p), p)
evaluates to true . |
int |
scanBackward(int position,
int bound,
char ch)
Finds the highest position in fDocument such that the position is <=
position and > bound and fDocument.getChar(position) == ch
evaluates to true for at least one ch in chars and the position is in the
default partition. |
int |
scanBackward(int position,
int bound,
char[] chars)
Finds the highest position in fDocument such that the position is <=
position and > bound and fDocument.getChar(position) == ch
evaluates to true for at least one ch in chars and the position is in the
default partition. |
int |
scanForward(int start,
int bound,
AtlHeuristicScanner.StopCondition condition)
Finds the lowest position p in fDocument such that start <= p
< bound and condition.stop(fDocument.getChar(p), p) evaluates to
true . |
int |
scanForward(int position,
int bound,
char ch)
Finds the lowest position in fDocument such that the position is >=
position and < bound and fDocument.getChar(position) == ch
evaluates to true and the position is in the default partition. |
int |
scanForward(int position,
int bound,
char[] chars)
Finds the lowest position in fDocument such that the position is >=
position and < bound and fDocument.getChar(position) == ch
evaluates to true for at least one ch in chars and the position is in the
default partition. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NOT_FOUND
BadLocationException
was thrown while scanning.
public static final int UNBOUND
fDocument.getLength()
(forward scanning).
Constructor Detail |
---|
public AtlHeuristicScanner(org.eclipse.jface.text.IDocument document)
this(document, IAtlPartitions.Atl_PARTITIONING, IDocument.DEFAULT_CONTENT_TYPE)
.
document
- the document to scan.public AtlHeuristicScanner(org.eclipse.jface.text.IDocument document, java.lang.String partitioning, java.lang.String partition)
document
- the document to scanpartitioning
- the partitioning to use for scanningpartition
- the partition to scan inMethod Detail |
---|
public int findClosingPeer(int start, char openingPeer, char closingPeer)
Note that start
must not point to the opening peer, but to the first character being
searched.
start
- the start positionopeningPeer
- the opening peer character (e.g. '{')closingPeer
- the closing peer character (e.g. '}')
NOT_FOUND
public int findNonWhitespaceBackward(int position, int bound)
fDocument
such that the position is <=
position
and > bound
and
Character.isWhitespace(fDocument.getChar(pos))
evaluates to false
and the
position is in the default partition.
position
- the first character position in fDocument
to be consideredbound
- the first position in fDocument
to not consider any more, with
bound
< position
, or UNBOUND
bound
,
position
] that resides in a Atl partition, or NOT_FOUND
if none can
be foundpublic int findNonWhitespaceForward(int position, int bound)
fDocument
such that the position is >=
position
and < bound
and
Character.isWhitespace(fDocument.getChar(pos))
evaluates to false
and the
position is in the default partition.
position
- the first character position in fDocument
to be consideredbound
- the first position in fDocument
to not consider any more, with
bound
> position
, or UNBOUND
position
,
bound
) that resides in a Atl partition, or NOT_FOUND
if none can be
foundpublic int findNonWhitespaceForwardInAnyPartition(int position, int bound)
fDocument
such that the position is >=
position
and < bound
and
Character.isWhitespace(fDocument.getChar(pos))
evaluates to false
.
position
- the first character position in fDocument
to be consideredbound
- the first position in fDocument
to not consider any more, with
bound
> position
, or UNBOUND
position
,
bound
), or NOT_FOUND
if none can be foundpublic int findOpeningPeer(int start, char openingPeer, char closingPeer)
Note that start
must not point to the closing peer, but to the first character being
searched.
start
- the start positionopeningPeer
- the opening peer character (e.g. '{')closingPeer
- the closing peer character (e.g. '}')
NOT_FOUND
public org.eclipse.jface.text.IRegion findSurroundingBlock(int offset)
offset
. The search is started at the beginning of
offset
, i.e. an opening brace at offset
will not be part of the surrounding
block, but a closing brace will.
offset
- the offset for which the surrounding block is computed
null
if none can be foundpublic int getPosition()
public boolean isBracelessBlockStart(int position, int bound)
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
position
- the insert position of the new characterbound
- the lowest position to consider
true
if the code is a conditional statement or loop without a block,
false
otherwisepublic boolean isDefaultPartition(int position)
position
resides in a default (Atl) partition of fDocument
.
position
- the position to be checked
true
if position
is in the default partition of
fDocument
, false
otherwisepublic int nextToken(int start, int bound)
start
, and not extending further
than bound
. The return value is one of the constants defined in Symbols
. After a
call, getPosition()
will return the position just after the scanned token (i.e. the next
position that will be scanned).
start
- the first character position in the document to considerbound
- the first position not to consider any more
Symbols
describing the next tokenpublic int previousToken(int start, int bound)
start
, and not extending further
than bound
. The return value is one of the constants defined in Symbols
. After a
call, getPosition()
will return the position just before the scanned token starts (i.e. the
next position that will be scanned).
start
- the first character position in the document to considerbound
- the first position not to consider any more
Symbols
describing the previous tokenpublic int scanBackward(int position, int bound, char ch)
fDocument
such that the position is <=
position
and > bound
and fDocument.getChar(position) == ch
evaluates to true
for at least one ch in chars
and the position is in the
default partition.
position
- the first character position in fDocument
to be consideredbound
- the first position in fDocument
to not consider any more, with
bound
< position
, or UNBOUND
ch
- the char
to search for
chars
in (bound
,
position
] that resides in a Atl partition, or NOT_FOUND
if none can
be foundpublic int scanBackward(int position, int bound, char[] chars)
fDocument
such that the position is <=
position
and > bound
and fDocument.getChar(position) == ch
evaluates to true
for at least one ch in chars
and the position is in the
default partition.
position
- the first character position in fDocument
to be consideredbound
- the first position in fDocument
to not consider any more, with
bound
< position
, or UNBOUND
chars
- an array of char
to search for
chars
in (bound
,
position
] that resides in a Atl partition, or NOT_FOUND
if none can
be foundpublic int scanBackward(int start, int bound, AtlHeuristicScanner.StopCondition condition)
p
in fDocument
such that bound
<
p
<= start
and condition.stop(fDocument.getChar(p), p)
evaluates to true
.
start
- the first character position in fDocument
to be consideredbound
- the first position in fDocument
to not consider any more, with
bound
< start
, or UNBOUND
condition
- the StopCondition
to check
bound
, start
for which
condition
holds, or NOT_FOUND
if none can be foundpublic int scanForward(int position, int bound, char ch)
fDocument
such that the position is >=
position
and < bound
and fDocument.getChar(position) == ch
evaluates to true
and the position is in the default partition.
position
- the first character position in fDocument
to be consideredbound
- the first position in fDocument
to not consider any more, with
bound
> position
, or UNBOUND
ch
- the char
to search for
ch
in (bound
, position
] that
resides in a Atl partition, or NOT_FOUND
if none can be foundpublic int scanForward(int position, int bound, char[] chars)
fDocument
such that the position is >=
position
and < bound
and fDocument.getChar(position) == ch
evaluates to true
for at least one ch in chars
and the position is in the
default partition.
position
- the first character position in fDocument
to be consideredbound
- the first position in fDocument
to not consider any more, with
bound
> position
, or UNBOUND
chars
- an array of char
to search for
position
, bound
) that resides in a Atl partition, or NOT_FOUND
if none can be foundpublic int scanForward(int start, int bound, AtlHeuristicScanner.StopCondition condition)
p
in fDocument
such that start
<= p
< bound
and condition.stop(fDocument.getChar(p), p)
evaluates to
true
.
start
- the first character position in fDocument
to be consideredbound
- the first position in fDocument
to not consider any more, with
bound
> start
, or UNBOUND
condition
- the StopCondition
to check
start
, bound
) for which
condition
holds, or NOT_FOUND
if none can be found
|
Copyright 2007 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |