Package ca.cgjennings.ui.textedit
Class RegexNavigatorBase
- java.lang.Object
-
- ca.cgjennings.ui.textedit.RegexNavigatorBase
-
- All Implemented Interfaces:
Navigator
- Direct Known Subclasses:
HtmlCodeSupport.HtmlNavigator
,MarkdownSupport.MarkdownNavigator
,PropertyFileCodeSupport.PropertyNavigator
,TileSetCodeSupport.TileSetNavigator
public class RegexNavigatorBase extends java.lang.Object implements Navigator
A base class for creating a navigator that finds navigation points using a regular expression.- Since:
- 3.4
- Author:
- Chris Jennings
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.regex.Pattern
pattern
-
Fields inherited from interface ca.cgjennings.ui.textedit.Navigator
ASYNC_RETRY
-
-
Constructor Summary
Constructors Constructor Description RegexNavigatorBase(java.util.regex.Pattern pattern)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected NavigationPoint
createNavigationPoint(java.util.regex.Matcher m, java.lang.String sourceText, boolean initialize)
Called with each match result to create a navigation point based on the match.protected void
dumpRegexThrowable(java.lang.Throwable t, java.lang.String text, java.util.regex.Matcher m)
Logs a description of an exception that occurs during the matching process.java.util.List<NavigationPoint>
getNavigationPoints(java.lang.String sourceText)
Returns a list of navigation points.protected void
match(java.lang.String sourceText, java.util.List<NavigationPoint> results)
Searches the source text for matches of the regular expression, collecting the resulting navigation points.
-
-
-
Method Detail
-
getNavigationPoints
public java.util.List<NavigationPoint> getNavigationPoints(java.lang.String sourceText)
Returns a list of navigation points. If thepattern
is currently null, an empty list is returned. Otherwise,match(java.lang.String, java.util.List<ca.cgjennings.ui.textedit.NavigationPoint>)
is called to create the list of points.- Specified by:
getNavigationPoints
in interfaceNavigator
- Parameters:
sourceText
- the source text to determine navigation points for- Returns:
- a (possibly empty) list of the extracted points
-
match
protected void match(java.lang.String sourceText, java.util.List<NavigationPoint> results)
Searches the source text for matches of the regular expression, collecting the resulting navigation points.- Parameters:
sourceText
- the source text to determine navigation points fora
- list to use to collect extracted points
-
createNavigationPoint
protected NavigationPoint createNavigationPoint(java.util.regex.Matcher m, java.lang.String sourceText, boolean initialize)
Called with each match result to create a navigation point based on the match. May return null to indicate that no point should be added for the match. The base class returns a simple point based on the text and location of the match.- Parameters:
m
- the match informationsourceText
- the source textinitialize
- if true, this is the first match of a new pass- Returns:
- a navigation point for the match, or null
-
dumpRegexThrowable
protected void dumpRegexThrowable(java.lang.Throwable t, java.lang.String text, java.util.regex.Matcher m)
Logs a description of an exception that occurs during the matching process.- Parameters:
t
- the exception that was throwntext
- the source text being matched againstm
- the matcher that threwt
-
-