Class CurlyFoldParser
- All Implemented Interfaces:
FoldParser
- Direct Known Subclasses:
LispFoldParser
/* ... */
") and make them
foldable as well.
This parser knows nothing about language semantics; it uses
RSyntaxTextArea
's syntax highlighting tokens to identify
curly braces. By default, it looks for single-char tokens of type
TokenTypes.SEPARATOR
, with lexemes '{
' or '}
'.
If your TokenMaker
uses a different token
type for curly braces, you should override the isLeftCurly(Token)
and
isRightCurly(Token)
methods with your own definitions. In theory,
you could extend this fold parser to parse languages that use completely
different tokens than curly braces to denote foldable regions by overriding
those two methods.
Note also that this class may impose somewhat of a performance penalty on large source files, since it reparses the entire document each time folds are reevaluated.
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final char[]
Ending of a multi-line comment in C, C++, Java, etc.private boolean
Whether to scan for C-style multi-line comments and make them foldable.private final boolean
Whether this parser is folding Java.private static final char[]
Used to find import statements when folding Java code. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a fold parser that identifies foldable regions via curly braces as well as C-style multi-line comments.CurlyFoldParser
(boolean cStyleMultiLineComments, boolean java) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether multi-line comments are foldable with this parser.getFolds
(RSyntaxTextArea textArea) Returns a list of all folds in the text area.boolean
isLeftCurly
(Token t) Returns whether the token is a left curly brace.boolean
Returns whether the token is a right curly brace.void
setFoldableMultiLineComments
(boolean foldable) Sets whether multi-line comments are foldable with this parser.
-
Field Details
-
foldableMultiLineComments
private boolean foldableMultiLineCommentsWhether to scan for C-style multi-line comments and make them foldable. -
java
private final boolean javaWhether this parser is folding Java. -
KEYWORD_IMPORT
private static final char[] KEYWORD_IMPORTUsed to find import statements when folding Java code. -
C_MLC_END
protected static final char[] C_MLC_ENDEnding of a multi-line comment in C, C++, Java, etc.
-
-
Constructor Details
-
CurlyFoldParser
public CurlyFoldParser()Creates a fold parser that identifies foldable regions via curly braces as well as C-style multi-line comments. -
CurlyFoldParser
public CurlyFoldParser(boolean cStyleMultiLineComments, boolean java) Constructor.- Parameters:
cStyleMultiLineComments
- Whether to scan for C-style multi-line comments and make them foldable.java
- Whether this parser is folding Java. This adds extra parsing rules, such as grouping all import statements into a fold section.
-
-
Method Details
-
getFoldableMultiLineComments
public boolean getFoldableMultiLineComments()Returns whether multi-line comments are foldable with this parser.- Returns:
- Whether multi-line comments are foldable.
- See Also:
-
getFolds
Description copied from interface:FoldParser
Returns a list of all folds in the text area.- Specified by:
getFolds
in interfaceFoldParser
- Parameters:
textArea
- The text area whose contents should be analyzed.- Returns:
- The list of folds. If this method returns
null
, it is treated as if no folds were found.
-
isLeftCurly
Returns whether the token is a left curly brace. This method exists so subclasses can provide their own curly brace definition.- Parameters:
t
- The token.- Returns:
- Whether it is a left curly brace.
- See Also:
-
isRightCurly
Returns whether the token is a right curly brace. This method exists so subclasses can provide their own curly brace definition.- Parameters:
t
- The token.- Returns:
- Whether it is a right curly brace.
- See Also:
-
setFoldableMultiLineComments
public void setFoldableMultiLineComments(boolean foldable) Sets whether multi-line comments are foldable with this parser.- Parameters:
foldable
- Whether multi-line comments are foldable.- See Also:
-