public final class AutomatedIndenting extends Object
The interceptors provided by this class are implementations of Typing Hooks SPI
interfaces that can be registered in MimeLookup
. Typically there are
two factory methods for each interceptor implementation. One factory method creates
the implementated interceptor and is suitable for direct use from java code. The
other factory method creates a factory object that can be registred in an XML layer
as an .instance
file.
Constructor and Description |
---|
AutomatedIndenting() |
Modifier and Type | Method and Description |
---|---|
static TypedTextInterceptor.Factory |
createHotCharsIndenter(Map<Object,Object> fileAttributes)
This is a version of
createHotCharsIndenter(java.util.regex.Pattern[]) method suitable
for XML layers registration. |
static TypedTextInterceptor |
createHotCharsIndenter(Pattern... linePatterns)
Creates
TypedTextInterceptor that automatically
indents a line depending on text typed on that line. |
public static TypedTextInterceptor createHotCharsIndenter(Pattern... linePatterns)
TypedTextInterceptor
that automatically
indents a line depending on text typed on that line.
The text patterns recognized by the intercetor are defined in form
of regular expressions passed to this method. The interceptor will match
all text before the caret on the line where a user is typing (including
the last typed character) against the regular expression patterns. If the text
matches at least one pattern the interceptor will reindent the line by
calling Indent.reindent(int)
method.
linePatterns
- The regular expressions that will be used for matching
text typed on a line. Any matching pattern will trigger the line reindentation.linePatterns
.public static TypedTextInterceptor.Factory createHotCharsIndenter(Map<Object,Object> fileAttributes)
createHotCharsIndenter(java.util.regex.Pattern[])
method suitable
for XML layers registration.
Here is an example of an XML layer registration done
for text/x-java
mime type. The registered interceptor will indent
any line that contains whitespace followed by 'else'. The ending 'e' character is
the last character typed on the line.
<folder name="Editors"> <folder name="text"> <folder name="x-java"> <file name="org-something-AutoIndenter.instance"> <attr name="instanceOf" stringvalue="org.netbeans.spi.editor.typinghooks.TypedTextInterceptor$Factory"/> <attr name="instanceCreate" methodvalue="org.netbeans.modules.editor.indent.spi.support.AutomatedIndenting.createHotCharsIndenter"/> <attr name="regex1" stringvalue="\s*else"/> </file> </folder> </folder> </folder>
fileAttributes
- The map of FileObject
attributes. This method
will recognize any attributes, which name starts with regex
and will
try to interpret their value as a regular expression. These regular expressions
will then be used as linePatterns
when calling createHotCharsIndenter(Pattern...)
method.createHotCharsIndenter(java.util.regex.Pattern[])
method.
The list of line patterns will be recovered from the fileAttributes
.Built on August 30 2023. | Copyright © 2017-2023 Apache Software Foundation. All Rights Reserved.