Package org.apache.sis.internal.book
Class CodeColorizer
java.lang.Object
org.apache.sis.internal.book.CodeColorizer
Apply syntax colorization on Java code. This class is different than most other colorization tools
since its apply different colors depending on whether a word is known to be defined in an OGC/ISO
standard, in GeoAPI or in Apache SIS.
- Since:
- 0.7
- Version:
- 1.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumThe specifier of an identifier. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DocumentThe object to use for creating nodes.private final Map<String,CodeColorizer.Specifier> Map of predefined identifiers and the authority who defined them.Lists of Java keywords. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate CodeColorizer.SpecifiergetSpecifier(String word) Returns the re-defined identifiers and authority who defined it for the given word.voidApplies emphasing on the words found in all text node of the given node.private static booleanisJavaIdentifier(String identifier, int i, int upper) Returnstrueif the given string fromiinclusive toupperexclusive is a Java identifier.private static booleanstartsWithWord(String string, String prefix) Returnstrueif the given string starts with the given prefix, and the character following the prefix is not an identifier character.(package private) final StringReturns the value to put inside inclassattribute of a<code>element encompassing the given identifier.(package private) static Node[]Returns all nodes in the given list as an array.
-
Field Details
-
JAVA_KEYWORDS
Lists of Java keywords. -
identifierSpecifiers
Map of predefined identifiers and the authority who defined them. -
document
The object to use for creating nodes.
-
-
Constructor Details
-
CodeColorizer
Creates a new color colorizer.- Parameters:
document- the object to use for creating nodes.- Throws:
IOException- if an error occurred while reading the list of predefined identifiers.BookException- if an identifier is defined twice.
-
-
Method Details
-
toArray
Returns all nodes in the given list as an array. This method is used for getting a snapshot of the list before to modify it (for example before the elements are moved to another node). -
getSpecifier
Returns the re-defined identifiers and authority who defined it for the given word.- Parameters:
word- the word for which to get a specifier.- Returns:
- the specifier for the given word, or
nullif none.
-
startsWithWord
Returnstrueif the given string starts with the given prefix, and the character following the prefix is not an identifier character. -
isJavaIdentifier
Returnstrueif the given string fromiinclusive toupperexclusive is a Java identifier. Ignore zero-width space and soft hyphen. -
styleForSingleIdentifier
Returns the value to put inside inclassattribute of a<code>element encompassing the given identifier.This method differs from
highlight(Node, String)in that it is used for applying a single style on the whole string. By contrast,highlight(…)parses the text and may apply different styles for different words. -
highlight
Applies emphasing on the words found in all text node of the given node.- Parameters:
parent- the root element where to put Java keywords in bold characters. This is typically a<samp>or<code>element.type-"xml"if the element to process is XML rather than Java code.- Throws:
BookException- if an element cannot be processed.
-