Class EscapeTranslator
- java.lang.Object
-
- net.sourceforge.pmd.lang.ast.impl.javacc.EscapeTranslator
-
- Direct Known Subclasses:
BackslashEscapeTranslator
public abstract class EscapeTranslator extends Object
An object that can translate an input document into an output document, typically by replacing escape sequences with the character they represent.This is an abstract class because the default implementation does not perform any escape processing. Subclasses refine this behavior.
-
-
Constructor Summary
Constructors Constructor Description EscapeTranslator(TextDocument original)
Create a translator that will read from the given document.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
ensureOpen()
Check to make sure that the stream has not been closedprotected int
gobbleMaxWithoutEscape(int maxOff)
Returns the max offset, EXclusive, up to which we can cut the input array from the bufpos to dump it into the output array.protected FileLocation
locationAt(int indexInInput)
protected int
recordEscape(int startOffsetInclusive, int endOffsetExclusive, Chars translation)
TextDocument
translateDocument()
Translate all the input in the buffer.
-
-
-
Field Detail
-
input
protected Chars input
Source characters. When there is an escape, eg \ u00a0, the first backslash is replaced with the translated value of the escape. The bufpos is updated so that we read the next char after the escape.
-
bufpos
protected int bufpos
Position of the next char to read in the input.
-
-
Constructor Detail
-
EscapeTranslator
public EscapeTranslator(TextDocument original)
Create a translator that will read from the given document.- Parameters:
original
- Original document- Throws:
NullPointerException
- If the parameter is null
-
-
Method Detail
-
translateDocument
public TextDocument translateDocument() throws MalformedSourceException
Translate all the input in the buffer. This consumes this object.- Returns:
- The translated text document. If there is no escape, returns the original text
- Throws:
IllegalStateException
- If this method is called more than once on the same objectMalformedSourceException
- If there are invalid escapes in the source
-
gobbleMaxWithoutEscape
protected int gobbleMaxWithoutEscape(int maxOff) throws MalformedSourceException
Returns the max offset, EXclusive, up to which we can cut the input array from the bufpos to dump it into the output array.- Parameters:
maxOff
- Max offset up to which to read ahead- Throws:
MalformedSourceException
-
recordEscape
protected int recordEscape(int startOffsetInclusive, int endOffsetExclusive, Chars translation)
-
ensureOpen
protected final void ensureOpen()
Check to make sure that the stream has not been closed
-
locationAt
protected FileLocation locationAt(int indexInInput)
-
-