Package org.fife.ui.rsyntaxtextarea
Class ParserManager
- java.lang.Object
-
- org.fife.ui.rsyntaxtextarea.ParserManager
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.beans.PropertyChangeListener
,java.util.EventListener
,javax.swing.event.DocumentListener
,javax.swing.event.HyperlinkListener
class ParserManager extends java.lang.Object implements javax.swing.event.DocumentListener, java.awt.event.ActionListener, javax.swing.event.HyperlinkListener, java.beans.PropertyChangeListener
Manages running a parser object for anRSyntaxTextArea
.- Version:
- 0.9
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ParserManager.NoticeHighlightPair
Mapping of a parser notice to its highlight in the editor.
-
Field Summary
Fields Modifier and Type Field Description private static boolean
DEBUG_PARSING
Whether to print debug messages while running parsers.private static int
DEFAULT_DELAY_MS
The default delay between the last key press and when the document is parsed, in milliseconds.private javax.swing.text.Position
firstOffsetModded
private javax.swing.text.Position
lastOffsetModded
private java.util.List<ParserManager.NoticeHighlightPair>
noticeHighlightPairs
Mapping of notices to their highlights in the editor.private SquiggleUnderlineHighlightPainter
parserErrorHighlightPainter
Painter used to underline errors.private Parser
parserForTip
private java.util.List<Parser>
parsers
private static java.lang.String
PROPERTY_DEBUG_PARSING
If this system property is set totrue
, debug messages will be printed to stdout to help diagnose parsing issues.private boolean
running
private RSyntaxTextArea
textArea
private javax.swing.Timer
timer
-
Constructor Summary
Constructors Constructor Description ParserManager(int delay, RSyntaxTextArea textArea)
Constructor.ParserManager(RSyntaxTextArea textArea)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
Called when the timer fires (e.g.void
addParser(Parser parser)
Adds a parser for the text area.private void
addParserNoticeHighlights(ParseResult res)
Adds highlights for a list of parser notices.void
changedUpdate(javax.swing.event.DocumentEvent e)
Called when the document is modified.private void
clearParserNoticeHighlights()
private void
clearParserNoticeHighlights(Parser parser)
Removes all parser notice highlights for a specific parser.void
clearParsers()
Removes all parsers and any highlights they have created.void
forceReparsing(int parser)
Forces the givenParser
to reparse the content of this text area.int
getDelay()
Returns the delay between the last "concurrent" edit and when the document is reparsed.Parser
getParser(int index)
Returns the specified parser.int
getParserCount()
Returns the number of registered parsers.java.util.List<ParserNotice>
getParserNotices()
Returns a list of the current parser notices for this text area.ToolTipInfo
getToolTipText(java.awt.event.MouseEvent e)
Returns the tool tip to display for a mouse event at the given location.void
handleDocumentEvent(javax.swing.event.DocumentEvent e)
Called when the document is modified.void
hyperlinkUpdate(javax.swing.event.HyperlinkEvent e)
Called when the user clicks a hyperlink in aFocusableTip
.void
insertUpdate(javax.swing.event.DocumentEvent e)
Called when the document is modified.private boolean
noticeContainsPointInView(ParserNotice notice, java.awt.Point p)
SinceviewToModel()
returns the closest model position, and the position doesn't necessarily contain the point passed in as an argument, this method checks whether the point is indeed contained in the view rectangle for the specified offset.private boolean
noticeContainsPosition(ParserNotice notice, int offs)
Returns whether a parser notice contains the specified offset.void
propertyChange(java.beans.PropertyChangeEvent e)
Called when a property we're interested in changes.boolean
removeParser(Parser parser)
Removes a parser.private void
removeParserNotices(Parser parser)
Removes all parser notices (and clears highlights in the editor) from a particular parser.private void
removeParserNotices(ParseResult res)
Removes any currently stored notices (and the corresponding highlights from the editor) from the same Parser, and in the given line range, as in the results.void
removeUpdate(javax.swing.event.DocumentEvent e)
Called when the document is modified.void
restartParsing()
Restarts parsing the document.void
setDelay(int millis)
Sets the delay between the last "concurrent" edit and when the document is reparsed.private boolean
shouldRemoveNotice(ParserNotice notice, ParseResult res)
Returns whether a parser notice should be removed, based on a parse result.void
stopParsing()
Stops parsing the document.
-
-
-
Field Detail
-
textArea
private RSyntaxTextArea textArea
-
parsers
private java.util.List<Parser> parsers
-
timer
private javax.swing.Timer timer
-
running
private boolean running
-
parserForTip
private Parser parserForTip
-
firstOffsetModded
private javax.swing.text.Position firstOffsetModded
-
lastOffsetModded
private javax.swing.text.Position lastOffsetModded
-
noticeHighlightPairs
private java.util.List<ParserManager.NoticeHighlightPair> noticeHighlightPairs
Mapping of notices to their highlights in the editor. Can't use a Map since parsers could return twoParserNotice
s that compare equally viaequals()
. Real-world example: The Perl compiler will return 2+ identical error messages if the same error is committed in a single line more than once.
-
parserErrorHighlightPainter
private SquiggleUnderlineHighlightPainter parserErrorHighlightPainter
Painter used to underline errors.
-
PROPERTY_DEBUG_PARSING
private static final java.lang.String PROPERTY_DEBUG_PARSING
If this system property is set totrue
, debug messages will be printed to stdout to help diagnose parsing issues.- See Also:
- Constant Field Values
-
DEBUG_PARSING
private static final boolean DEBUG_PARSING
Whether to print debug messages while running parsers.
-
DEFAULT_DELAY_MS
private static final int DEFAULT_DELAY_MS
The default delay between the last key press and when the document is parsed, in milliseconds.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ParserManager
ParserManager(RSyntaxTextArea textArea)
Constructor.- Parameters:
textArea
- The text area whose document the parser will be parsing.
-
ParserManager
ParserManager(int delay, RSyntaxTextArea textArea)
Constructor.- Parameters:
delay
- The delay between the last key press and when the document is parsed.textArea
- The text area whose document the parser will be parsing.
-
-
Method Detail
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
Called when the timer fires (e.g. it's time to parse the document).- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
- Parameters:
e
- The event.
-
addParser
public void addParser(Parser parser)
Adds a parser for the text area.- Parameters:
parser
- The new parser. If this isnull
, nothing happens.- See Also:
getParser(int)
,removeParser(Parser)
-
addParserNoticeHighlights
private void addParserNoticeHighlights(ParseResult res)
Adds highlights for a list of parser notices. Any current notices from the same Parser, in the same parsed range, are removed.- Parameters:
res
- The result of a parsing.- See Also:
clearParserNoticeHighlights()
-
changedUpdate
public void changedUpdate(javax.swing.event.DocumentEvent e)
Called when the document is modified.- Specified by:
changedUpdate
in interfacejavax.swing.event.DocumentListener
- Parameters:
e
- The document event.
-
clearParserNoticeHighlights
private void clearParserNoticeHighlights()
-
clearParserNoticeHighlights
private void clearParserNoticeHighlights(Parser parser)
Removes all parser notice highlights for a specific parser.- Parameters:
parser
- The parser whose highlights to remove.
-
clearParsers
public void clearParsers()
Removes all parsers and any highlights they have created.- See Also:
addParser(Parser)
-
forceReparsing
public void forceReparsing(int parser)
Forces the givenParser
to reparse the content of this text area.This method can be useful when a
Parser
can be configured as to what notices it returns. For example, if a Java language parser can be configured to set whether no serialVersionUID is a warning, error, or ignored, this method can be called after changing the expected notice type to have the document reparsed.- Parameters:
parser
- The index of theParser
to re-run.- See Also:
getParser(int)
-
getDelay
public int getDelay()
Returns the delay between the last "concurrent" edit and when the document is reparsed.- Returns:
- The delay, in milliseconds.
- See Also:
setDelay(int)
-
getParser
public Parser getParser(int index)
Returns the specified parser.- Parameters:
index
- The index of the parser.- Returns:
- The parser.
- See Also:
getParserCount()
,addParser(Parser)
,removeParser(Parser)
-
getParserCount
public int getParserCount()
Returns the number of registered parsers.- Returns:
- The number of registered parsers.
-
getParserNotices
public java.util.List<ParserNotice> getParserNotices()
Returns a list of the current parser notices for this text area. This method (like most Swing methods) should only be called on the EDT.- Returns:
- The list of notices. This will be an empty list if there are none.
-
getToolTipText
public ToolTipInfo getToolTipText(java.awt.event.MouseEvent e)
Returns the tool tip to display for a mouse event at the given location. This method is overridden to give a registered parser a chance to display a tool tip (such as an error description when the mouse is over an error highlight).- Parameters:
e
- The mouse event.- Returns:
- The tool tip to display, and possibly a hyperlink event handler.
-
handleDocumentEvent
public void handleDocumentEvent(javax.swing.event.DocumentEvent e)
Called when the document is modified.- Parameters:
e
- The document event.
-
hyperlinkUpdate
public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent e)
Called when the user clicks a hyperlink in aFocusableTip
.- Specified by:
hyperlinkUpdate
in interfacejavax.swing.event.HyperlinkListener
- Parameters:
e
- The event.
-
insertUpdate
public void insertUpdate(javax.swing.event.DocumentEvent e)
Called when the document is modified.- Specified by:
insertUpdate
in interfacejavax.swing.event.DocumentListener
- Parameters:
e
- The document event.
-
noticeContainsPosition
private boolean noticeContainsPosition(ParserNotice notice, int offs)
Returns whether a parser notice contains the specified offset.- Parameters:
notice
- The notice.offs
- The offset.- Returns:
- Whether the notice contains the offset.
-
noticeContainsPointInView
private boolean noticeContainsPointInView(ParserNotice notice, java.awt.Point p)
SinceviewToModel()
returns the closest model position, and the position doesn't necessarily contain the point passed in as an argument, this method checks whether the point is indeed contained in the view rectangle for the specified offset.- Parameters:
notice
- The parser notice.p
- The point possibly contained in the view range of the parser notice.- Returns:
- Whether the parser notice actually contains the specified point in the view.
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
Called when a property we're interested in changes.- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
- Parameters:
e
- The property change event.
-
removeParser
public boolean removeParser(Parser parser)
Removes a parser.- Parameters:
parser
- The parser to remove.- Returns:
- Whether the parser was found.
- See Also:
addParser(Parser)
,getParser(int)
-
removeParserNotices
private void removeParserNotices(Parser parser)
Removes all parser notices (and clears highlights in the editor) from a particular parser.- Parameters:
parser
- The parser.
-
removeParserNotices
private void removeParserNotices(ParseResult res)
Removes any currently stored notices (and the corresponding highlights from the editor) from the same Parser, and in the given line range, as in the results.- Parameters:
res
- The results.
-
removeUpdate
public void removeUpdate(javax.swing.event.DocumentEvent e)
Called when the document is modified.- Specified by:
removeUpdate
in interfacejavax.swing.event.DocumentListener
- Parameters:
e
- The document event.
-
restartParsing
public void restartParsing()
Restarts parsing the document.- See Also:
stopParsing()
-
setDelay
public void setDelay(int millis)
Sets the delay between the last "concurrent" edit and when the document is reparsed.- Parameters:
millis
- The new delay, in milliseconds. This must be greater than0
.- See Also:
getDelay()
-
shouldRemoveNotice
private boolean shouldRemoveNotice(ParserNotice notice, ParseResult res)
Returns whether a parser notice should be removed, based on a parse result.- Parameters:
notice
- The notice in question.res
- The result.- Returns:
- Whether the notice should be removed.
-
stopParsing
public void stopParsing()
Stops parsing the document.- See Also:
restartParsing()
-
-