org.eclipse.mylyn.wikitext.core.parser.markup
Class Block

java.lang.Object
  extended by org.eclipse.mylyn.wikitext.core.parser.markup.Processor
      extended by org.eclipse.mylyn.wikitext.core.parser.markup.Block
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
AbstractHtmlBlock, AbstractTableOfContentsBlock, AbstractTableOfContentsBlock, CodeBlock, DefinitionListBlock, EclipseErrorDetailsBlock, FootnoteBlock, GlossaryBlock, GlossaryBlock, HeadingBlock, HeadingBlock, HeadingBlock, HeadingBlock, HeadingBlock, HorizontalRuleBlock, JavaStackTraceBlock, ListBlock, ListBlock, ListBlock, ListBlock, ListBlock, LiteralBlock, ParagraphBlock, ParagraphBlock, ParagraphBlock, ParagraphBlock, ParagraphBlock, ParameterizedBlock, PreformattedBlock, PreformattedBlock, PreformattedBlock, QuoteBlock, QuoteBlock, QuoteBlock, TableBlock, TableBlock, TableBlock, TableBlock, TableOfContentsBlock, VerbatimBlock

public abstract class Block
extends Processor
implements Cloneable

A markup block that may span multiple lines. Implements Cloneable for the template design pattern.

Author:
David Green

Field Summary
 
Fields inherited from class org.eclipse.mylyn.wikitext.core.parser.markup.Processor
builder, markupLanguage, parser, state
 
Constructor Summary
Block()
           
 
Method Summary
 boolean beginNesting()
          Indicate if block nesting should begin.
abstract  boolean canStart(String line, int lineOffset)
          Indicate if the block can start with the given markup line at the provided offset.
 Block clone()
          Clone the block including its state.
 int findCloseOffset(String line, int lineOffset)
          Indicate if the block can close on the given line at the given offset.
 boolean isClosed()
          Indicate if the current block is closed
 int processLine(String line, int offset)
          Process the given line of markup starting at the provided offset.
protected abstract  int processLineContent(String line, int offset)
          Process the given line of markup starting at the provided offset.
 void setClosed(boolean closed)
          Cause the block to be closed.
 
Methods inherited from class org.eclipse.mylyn.wikitext.core.parser.markup.Processor
getBuilder, getMarkupLanguage, getParser, getState, setParser, setState
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Block

public Block()
Method Detail

processLine

public int processLine(String line,
                       int offset)
Process the given line of markup starting at the provided offset.

Parameters:
line - the markup line to process
offset - the offset at which to start processing
Returns:
a non-negative integer to indicate that processing of the block completed before the end of the line, or -1 if the entire line was processed.

processLineContent

protected abstract int processLineContent(String line,
                                          int offset)
Process the given line of markup starting at the provided offset.

Parameters:
line - the markup line to process
offset - the offset at which to start processing
Returns:
a non-negative integer to indicate that processing of the block completed before the end of the line, or -1 if the entire line was processed.

canStart

public abstract boolean canStart(String line,
                                 int lineOffset)
Indicate if the block can start with the given markup line at the provided offset. Calling this method may cause the block to have state which is propagated when cloning and consumed in #processLine(String, int, int). Calling this method must cause any previous state to be reset. Note that it is valid for block implementations to refuse to start at non-zero offsets. Implementations must be able to handle this method without having the processor state initialized.

Parameters:
line - the line of markup to test
lineOffset - the offset at which the block should start processing
Returns:
true if the provided markup consists of a valid starting point for the block

beginNesting

public boolean beginNesting()
Indicate if block nesting should begin. Called after processLineContent(String, int).

Returns:
true if nesting should start, otherwise false.
Since:
1.1
See Also:
findCloseOffset(String, int)

findCloseOffset

public int findCloseOffset(String line,
                           int lineOffset)
Indicate if the block can close on the given line at the given offset. blocks that implement a nesting protocol must implement this method.

Parameters:
line - the line of content
lineOffset - the 0-based offset into the line
Returns:
the 0-based offset where the close will occur, or -1 if the block should not close on this line.
Since:
1.1
See Also:
beginNesting()

isClosed

public boolean isClosed()
Indicate if the current block is closed


setClosed

public void setClosed(boolean closed)
Cause the block to be closed. If the block is going from the open to the closed state, then the block must cause the closed state to be propagated to the builder if necessary.

Parameters:
closed -

clone

public Block clone()
Clone the block including its state. Cloning is generally used after the canStart(String, int) method is called in order to implement the Template design pattern.

Overrides:
clone in class Processor


Copyright © 2011 FuseSource, Corp.. All Rights Reserved.