org.tinyjee.maven.dim.sources
Class TokenAndBraceSnippetSelector
java.lang.Object
org.tinyjee.maven.dim.sources.AbstractSnippetSelector
org.tinyjee.maven.dim.sources.AbstractStreamingSnippetSelector
org.tinyjee.maven.dim.sources.TokenAndBraceSnippetSelector
- All Implemented Interfaces:
- SnippetSelector
public class TokenAndBraceSnippetSelector
- extends AbstractStreamingSnippetSelector
Selects snippets using an activation token and open/close brace counting, using the expression prefix "TB:".
This selector works with any C based language constructs of the form Activation-TOKEN .. { ... content ... }
as well as
other content that uses hierarchical braces of one of the supported formats (see below).
Expression samples:
tb:methodName{
tb:activationToken[
tb:activationToken(
tb:activationToken<
tb:XmlCommentNextToThisToken<!--
tb:<!--
tb:/*
tb:#*
If the brace is omitted, the selector defaults to the braces {}
.
In case of only a brace but no token is specified, the selector matches all content that is surrounded by the given brace.
E.g. <!--
matches all comments of an XML/HTML file.
Activation tokens of the format [line-number]
(e.g. [132]
) activate the brace matching algorithm when
the given line number is reached instead of a string-match of the token is found.
By default this selector works case-insensitive, unless "case-sensitive=true"
is set.
- Author:
- Juergen_Kellerer, 2011-10-16
BRACES
public static final Map<String,String> BRACES
TokenAndBraceSnippetSelector
public TokenAndBraceSnippetSelector()
TokenAndBraceSnippetSelector
protected TokenAndBraceSnippetSelector(String expressionPrefix)
selectSnippets
public Iterator<Integer> selectSnippets(String expression,
URL contentUrl,
LineNumberReader content,
Map<String,Object> macroParameters)
throws IOException
- Description copied from interface:
SnippetSelector
- Selects snippets in the given content and returns an iterator over selected line numbers.
Note: The caller reads the returned iterator fully before closing the content stream.
This way snippet selectors can truly implement streaming selection (in difference to the provided example).
- Parameters:
expression
- a single snippet expression.contentUrl
- the resolved URL of the content to include (might be 'null' if the source does not provide a Url).content
- a reader providing the content. Implementations must read content from this reader as the Url
may point to an outdated static source that does not reflect the content to include.macroParameters
- the parameters used with the macro call.
- Returns:
- an iterator containing all selected line numbers.
- Throws:
IOException
- In case of reading the URL failed.
extractFixedLineNumber
protected int extractFixedLineNumber(String expression)
countTokens
protected int countTokens(String line,
String token)
findBraceStyle
protected Map.Entry<String,String> findBraceStyle(String expression)